Window associated with GdkEvent is invalid sometimes
- From: Siddharth Uppal <siddharthuppal yahoo co in>
- To: gtk-app-devel-list gnome org
- Subject: Window associated with GdkEvent is invalid sometimes
- Date: Wed, 17 Mar 2004 06:58:43 +0000 (GMT)
Hi,
I have written a simple module for use with Gtk
applications. In my module, I set up my own main event
handler, and add a filter for the root window's
events.
In each of main_event_handler function, and root
window's filter function, when I receive a GdkEvent, I
simply check whether the window associated with the
event (event->any.window) is valid, using
GDK_IS_WINDOW().
The window associated with the event in root window's
event filter function is always valid, but the problem
is that sometimes the window associated with the same
event in main_event_handler is found as invalid
(acutually is NULL).
I feel there is some kind of a race condition
somewhere. I would appreciate if someone could suggest
some solution or a suitable way around the problem.
I am using Gtk+-2.0.
Here's the code of my GTK module:
--code start "my_module.c"--
#include <gdk/gdkx.h>
#include <gdk/gdk.h>
#include <gmodule.h>
#include <gtk/gtk.h>
// Global variables
static GModule *g_module = NULL;
static void
gdk_root_add_watch (guint events,
GdkFilterFunc function,
gpointer data)
{
GdkWindow *root;
g_return_if_fail (function != NULL);
root = gdk_window_lookup (GDK_ROOT_WINDOW ());
gdk_window_set_events (root, events |
gdk_window_get_events (root));
gdk_window_add_filter (root, function, data);
}
static void
main_event_handler (GdkEvent *event,
gpointer data)
{
if (!GDK_IS_WINDOW(event->any.window))
g_message("In main_event_handler, event->any.window
didn't return \
a valid window!\n");
else
g_message("In main_event_handler, event->any.window
returned a valid window!\n");
}
static GdkFilterReturn
root_event_monitor (GdkXEvent *gdkxevent,
GdkEvent *event,
gpointer ptr)
{
if (!GDK_IS_WINDOW(event->any.window))
g_message("In root_event_monitor, event->any.window
didn't return \
a valid window!\n");
else
g_message("In root_event_monitor, event->any.window
returned a valid window!\n");
return FALSE;
}
void
events_init (void)
{
static gboolean initialized = FALSE;
if (!initialized)
{
initialized = TRUE;
gdk_event_handler_set (main_event_handler, NULL,
NULL);
gdk_root_add_watch (GDK_POINTER_MOTION_MASK,
root_event_monitor, NULL);
}
}
G_MODULE_EXPORT const gchar* g_module_check_init
(GModule *module);
const gchar*
g_module_check_init (GModule *module)
{
GModule *main_module;
gchar *version_check = NULL;
main_module = g_module_open (NULL, 0);
if (!main_module)
return "no main handle";
if (!g_module_symbol (main_module,
"gtk_major_version", (gpointer*) &version_check) &&
version_check)
return "no gtk library?";
version_check = gtk_check_version
(GTK_MAJOR_VERSION,
GTK_MINOR_VERSION,
GTK_MICRO_VERSION - GTK_INTERFACE_AGE);
if (version_check)
return version_check;
g_module = module;
/* make ourselves resident */
g_module_open (g_module_name (module),
G_MODULE_BIND_LAZY);
return NULL;
}
G_MODULE_EXPORT void gtk_module_init (gint *argc,
gchar ***argv);
void
gtk_module_init (int *argc, char ***argvp)
{
events_init();
}
static gboolean
quit_loop (gpointer data)
{
gtk_main_quit ();
return FALSE;
}
--code end "my_module.c"--
I built the module in the following manner:
libtool --mode=compile gcc -c -fPIC `pkg-config
--cflags gtk+-2.0` my_module.c
libtool --mode=link gcc -rpath /usr/local/lib -o
libmy_module.la my_module.lo
libtool --mode=install cp libmy_module.la
/usr/local/lib
And, I invoke a GTK 2.0 application to load my module,
in the following manner:
LD_LIBRARY_PATH="/usr/local/lib"
GTK_MODULES=$GTK_MODULES:my_module
LD_PRELOAD=/usr/local/lib/libmy_module.so
export GTK_MODULES LD_LIBRARY_PATH LD_PRELOAD
some_gtk_2.0_program
Thanks,
Siddharth
=====
Siddharth Uppal
Scientist 'B'
Artificial Intelligence and Neural Networks Division (AI & NN)
Center for Artificial Intelligence and Robotics (CAIR)
Defense R&D Organisation (DRDO)
High Grounds
Bangalore - 560093
India
Office: (+91) (080) 2265496 Extn. 225
Mobile: (+91) 9880055780
Blog: http://upster.blogspot.com
----------------------------------------------------
43rd Law of Computing:
Anything that can go wr
ERROR: Segmentation violation -- Core dumped
----------------------------------------------------
________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more.
Go to: http://in.insurance.yahoo.com/licspecial/index.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]