Fix mouse::leave signal emit on widgets (FS#774)

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2010-06-09 16:08:48 +02:00
parent 6e6a07b660
commit 688b9f7af0
1 changed files with 16 additions and 13 deletions

29
event.c
View File

@ -344,18 +344,19 @@ event_handle_destroynotify(void *data __attribute__ ((unused)),
*/ */
static void static void
event_handle_widget_motionnotify(wibox_t *wibox, event_handle_widget_motionnotify(wibox_t *wibox,
widget_t **mouse_over,
widget_t *widget) widget_t *widget)
{ {
if(widget != *mouse_over) if(widget != wibox->mouse_over)
{ {
if(*mouse_over) if(wibox->mouse_over)
{ {
/* Emit mouse leave signal on old widget: /* Emit mouse leave signal on old widget:
* - Push wibox.*/ * - Push wibox.*/
luaA_object_push(globalconf.L, wibox); luaA_object_push(globalconf.L, wibox);
/* - Push the widget the mouse was on */ /* - Push the widget the mouse was on */
luaA_object_push_item(globalconf.L, -1, *mouse_over); luaA_object_push_item(globalconf.L, -1, wibox->mouse_over);
/* - Invert wibox/widget */
lua_insert(globalconf.L, -2);
/* - Emit the signal mouse::leave with the wibox as argument */ /* - Emit the signal mouse::leave with the wibox as argument */
luaA_object_emit_signal(globalconf.L, -2, "mouse::leave", 1); luaA_object_emit_signal(globalconf.L, -2, "mouse::leave", 1);
/* - Remove the widget */ /* - Remove the widget */
@ -363,8 +364,7 @@ event_handle_widget_motionnotify(wibox_t *wibox,
/* Re-push wibox */ /* Re-push wibox */
luaA_object_push(globalconf.L, wibox); luaA_object_push(globalconf.L, wibox);
luaA_object_unref_item(globalconf.L, -1, *mouse_over); luaA_object_unref_item(globalconf.L, -1, wibox->mouse_over);
*mouse_over = NULL;
/* Remove the wibox */ /* Remove the wibox */
lua_pop(globalconf.L, 1); lua_pop(globalconf.L, 1);
} }
@ -379,9 +379,6 @@ event_handle_widget_motionnotify(wibox_t *wibox,
/* - Reference the widget into the wibox */ /* - Reference the widget into the wibox */
luaA_object_ref_item(globalconf.L, -2, -1); luaA_object_ref_item(globalconf.L, -2, -1);
/* Store that this widget was the one with the mouse over */
*mouse_over = widget;
/* Emit mouse::enter signal on new widget: /* Emit mouse::enter signal on new widget:
* - Push the widget */ * - Push the widget */
luaA_object_push_item(globalconf.L, -1, widget); luaA_object_push_item(globalconf.L, -1, widget);
@ -393,6 +390,10 @@ event_handle_widget_motionnotify(wibox_t *wibox,
/* - Remove the widget from the stack */ /* - Remove the widget from the stack */
lua_pop(globalconf.L, 1); lua_pop(globalconf.L, 1);
} }
/* Store that this widget was the one with the mouse over */
wibox->mouse_over = widget;
} }
} }
@ -417,8 +418,8 @@ event_handle_motionnotify(void *data __attribute__ ((unused)),
wibox->geometry.width, wibox->geometry.width,
wibox->geometry.height, wibox->geometry.height,
&ev->event_x, &ev->event_y); &ev->event_x, &ev->event_y);
if(w)
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w); event_handle_widget_motionnotify(wibox, w);
} }
return 0; return 0;
@ -455,6 +456,8 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
luaA_object_push(globalconf.L, wibox); luaA_object_push(globalconf.L, wibox);
/* Push the widget the mouse is over in this wibox */ /* Push the widget the mouse is over in this wibox */
luaA_object_push_item(globalconf.L, -1, wibox->mouse_over); luaA_object_push_item(globalconf.L, -1, wibox->mouse_over);
/* Move the widget before the wibox */
lua_insert(globalconf.L, -2);
/* Emit mouse::leave signal on widget the mouse was over with /* Emit mouse::leave signal on widget the mouse was over with
* its wibox as argument */ * its wibox as argument */
luaA_object_emit_signal(globalconf.L, -2, "mouse::leave", 1); luaA_object_emit_signal(globalconf.L, -2, "mouse::leave", 1);
@ -493,8 +496,8 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
wibox->geometry.width, wibox->geometry.width,
wibox->geometry.height, wibox->geometry.height,
&ev->event_x, &ev->event_y); &ev->event_x, &ev->event_y);
if(w)
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w); event_handle_widget_motionnotify(wibox, w);
luaA_object_push(globalconf.L, wibox); luaA_object_push(globalconf.L, wibox);
luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 0); luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 0);