Commit 59ff297c authored by Tim Janik's avatar Tim Janik

implementations of gtk_invoke_key_snoopers(), gtk_key_snooper_install()

implementations of
gtk_invoke_key_snoopers(),
gtk_key_snooper_install() and
gtk_key_snooper_remove()
-timj
parent f424cd83
......@@ -35,10 +35,11 @@
/* Private type definitions
*/
typedef struct _GtkInitFunction GtkInitFunction;
typedef struct _GtkTimeoutFunction GtkTimeoutFunction;
typedef struct _GtkIdleFunction GtkIdleFunction;
typedef struct _GtkInputFunction GtkInputFunction;
typedef struct _GtkInitFunction GtkInitFunction;
typedef struct _GtkTimeoutFunction GtkTimeoutFunction;
typedef struct _GtkIdleFunction GtkIdleFunction;
typedef struct _GtkInputFunction GtkInputFunction;
typedef struct _GtkKeySnooperData GtkKeySnooperData;
struct _GtkInitFunction
{
......@@ -74,10 +75,19 @@ struct _GtkInputFunction
GtkDestroyNotify destroy;
};
struct _GtkKeySnooperData
{
GtkKeySnoopFunc func;
gpointer func_data;
gint id;
};
static void gtk_exit_func (void);
static void gtk_timeout_insert (GtkTimeoutFunction *timeoutf);
static void gtk_handle_current_timeouts (guint32 the_time);
static void gtk_handle_current_idles (void);
static gint gtk_invoke_key_snoopers (GtkWidget *grab_widget,
GdkEvent *event);
static void gtk_handle_timeouts (void);
static void gtk_handle_idle (void);
static void gtk_handle_timer (void);
......@@ -116,6 +126,8 @@ static GList *current_timeouts = NULL;
static GMemChunk *timeout_mem_chunk = NULL;
static GMemChunk *idle_mem_chunk = NULL;
static GSList *key_snoopers = NULL;
static GdkVisual *gtk_visual; /* The visual to be used in creating new
* widgets.
*/
......@@ -407,13 +419,19 @@ gtk_main_iteration_do (gboolean blocking)
gtk_widget_event (event_widget, event);
break;
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
if (key_snoopers)
{
if (gtk_invoke_key_snoopers (grab_widget, event))
break;
}
/* else fall through */
case GDK_MOTION_NOTIFY:
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
case GDK_PROXIMITY_IN:
case GDK_PROXIMITY_OUT:
case GDK_OTHER_EVENT:
......@@ -491,6 +509,64 @@ gtk_init_add (GtkFunction function,
init_functions = g_list_prepend (init_functions, init);
}
gint
gtk_key_snooper_install (GtkKeySnoopFunc snooper,
gpointer func_data)
{
GtkKeySnooperData *data;
static guint snooper_id = 1;
g_return_val_if_fail (snooper != NULL, 0);
data = g_new (GtkKeySnooperData, 1);
data->func = snooper;
data->func_data = func_data;
data->id = snooper_id++;
key_snoopers = g_slist_prepend (key_snoopers, data);
return data->id;
}
void
gtk_key_snooper_remove (gint snooper_id)
{
GtkKeySnooperData *data = NULL;
GSList *slist;
slist = key_snoopers;
while (slist)
{
data = slist->data;
if (data->id == snooper_id)
break;
slist = slist->next;
data = NULL;
}
if (data)
key_snoopers = g_slist_remove (key_snoopers, data);
}
static gint
gtk_invoke_key_snoopers (GtkWidget *grab_widget,
GdkEvent *event)
{
GSList *slist;
gint return_val = FALSE;
slist = key_snoopers;
while (slist && !return_val)
{
GtkKeySnooperData *data;
data = slist->data;
slist = slist->next;
return_val = (*data->func) (grab_widget, (GdkEventKey*) event, data->func_data);
}
return return_val;
}
static gint
gtk_timeout_add_internal (guint32 interval,
gint interp,
......
......@@ -28,6 +28,11 @@ extern "C" {
#endif /* __cplusplus */
typedef gint (*GtkKeySnoopFunc) (GtkWidget *grab_widget,
GdkEventKey *event,
gpointer func_data);
/* Initialization, exit, mainloop and miscellaneous routines
*/
void gtk_init (int *argc,
......@@ -67,7 +72,10 @@ gint gtk_idle_add_interp (GtkCallbackMarshal function,
GtkDestroyNotify destroy);
void gtk_idle_remove (gint tag);
void gtk_idle_remove_by_data (gpointer data);
gint gtk_key_snooper_install (GtkKeySnoopFunc snooper,
gpointer func_data);
void gtk_key_snooper_remove (gint snooper_id);
GdkEvent* gtk_get_current_event (void);
GtkWidget* gtk_get_event_widget (GdkEvent *event);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment