wibox: add mouse_enter and mouse_leave for wibox

Signed-off-by: Gregor Best <farhaven@googlemail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Gregor Best 2009-02-13 21:19:14 +01:00 committed by Julien Danjou
parent d2fc646590
commit 10bfb36d4b
3 changed files with 43 additions and 9 deletions

26
event.c
View File

@ -472,6 +472,9 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
}
wibox->mouse_over = NULL;
}
if(wibox->mouse_leave != LUA_REFNIL)
luaA_dofunction(globalconf.L, wibox->mouse_leave, 0, 0);
}
return 0;
@ -489,7 +492,6 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
{
client_t *c;
xembed_window_t *emwin;
wibox_t *wibox;
widget_t *w;
if(ev->mode != XCB_NOTIFY_MODE_NORMAL
@ -497,16 +499,22 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
&& ev->root_y == globalconf.pointer_y))
return 0;
wibox_t *wibox = wibox_getbywin(ev->event);
if((wibox = wibox_getbywin(ev->event))
&& (w = widget_getbycoords(wibox->position, &wibox->widgets,
wibox->sw.geometry.width,
wibox->sw.geometry.height,
&ev->event_x, &ev->event_y)))
if(wibox)
{
globalconf.pointer_x = ev->root_x;
globalconf.pointer_y = ev->root_y;
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
if((w = widget_getbycoords(wibox->position, &wibox->widgets,
wibox->sw.geometry.width,
wibox->sw.geometry.height,
&ev->event_x, &ev->event_y)))
{
globalconf.pointer_x = ev->root_x;
globalconf.pointer_y = ev->root_y;
event_handle_widget_motionnotify(wibox, &wibox->mouse_over, w);
}
if(wibox->mouse_enter != LUA_REFNIL)
luaA_dofunction(globalconf.L, wibox->mouse_enter, 0, 0);
}
else if((c = client_getbytitlebarwin(ev->event))
|| (c = client_getbywin(ev->event)))

View File

@ -102,6 +102,8 @@ typedef struct
luaA_ref widgets_table;
/** Widget the mouse is over */
widget_t *mouse_over;
/** Mouse over event handler */
luaA_ref mouse_enter, mouse_leave;
/** Need update */
bool need_update;
/** Cursor */

24
wibox.c
View File

@ -467,6 +467,8 @@ wibox_delete(wibox_t **wibox)
simplewindow_wipe(&(*wibox)->sw);
button_array_wipe(&(*wibox)->buttons);
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->widgets_table);
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->mouse_enter);
luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->mouse_leave);
widget_node_array_wipe(&(*wibox)->widgets);
p_delete(wibox);
}
@ -736,6 +738,8 @@ luaA_wibox_new(lua_State *L)
w->isvisible = true;
w->cursor = a_strdup("left_ptr");
w->mouse_enter = w->mouse_leave = LUA_REFNIL;
for(i = 0; i <= reqs_nbr; i++)
xcolor_init_reply(reqs[i]);
@ -816,6 +820,8 @@ luaA_wibox_invalidate_byitem(lua_State *L, const void *item)
* \lfield position The position.
* \lfield ontop On top of other windows.
* \lfield cursor The mouse cursor.
* \lfield mouse_enter A function to execute when the mouse enter the widget.
* \lfield mouse_leave A function to execute when the mouse leave the widget.
*/
static int
luaA_wibox_index(lua_State *L)
@ -886,6 +892,18 @@ luaA_wibox_index(lua_State *L)
return 0;
}
break;
case A_TK_MOUSE_ENTER:
if((*wibox)->mouse_enter != LUA_REFNIL)
lua_rawgeti(L, LUA_REGISTRYINDEX, (*wibox)->mouse_enter);
else
return 0;
return 1;
case A_TK_MOUSE_LEAVE:
if((*wibox)->mouse_leave != LUA_REFNIL)
lua_rawgeti(L, LUA_REGISTRYINDEX, (*wibox)->mouse_leave);
else
return 0;
return 1;
default:
return 0;
}
@ -1082,6 +1100,12 @@ luaA_wibox_newindex(lua_State *L)
window_opacity_set((*wibox)->sw.window, d);
}
break;
case A_TK_MOUSE_ENTER:
luaA_registerfct(L, 3, &(*wibox)->mouse_enter);
return 0;
case A_TK_MOUSE_LEAVE:
luaA_registerfct(L, 3, &(*wibox)->mouse_leave);
return 0;
default:
switch((*wibox)->type)
{