button: add support for AnyButton

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-26 12:34:30 +02:00
parent cbcbb68f7e
commit 21e8c0c89e
2 changed files with 22 additions and 30 deletions

View File

@ -51,7 +51,7 @@ luaA_button_gc(lua_State *L)
* \return The number of elements pushed on stack.
* \luastack
* \lparam A table with modifiers keys, or a button to clone.
* \lparam A mouse button number.
* \lparam A mouse button number, or 0 to match any button.
* \lparam A function to execute on click events.
* \lparam A function to execute on release events.
* \lreturn A mouse button binding.

50
event.c
View File

@ -56,33 +56,32 @@ event_handle_mouse_button(client_t *c,
uint16_t state,
button_array_t *buttons)
{
for(int i = 0; i < buttons->len; i++)
if(button == buttons->tab[i]->button
&& state == buttons->tab[i]->mod)
foreach(b, *buttons)
if((!(*b)->button || button == (*b)->button) && state == (*b)->mod)
switch(type)
{
case XCB_BUTTON_PRESS:
if(buttons->tab[i]->press != LUA_REFNIL)
if((*b)->press != LUA_REFNIL)
{
if(c)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, buttons->tab[i]->press, 1, 0);
luaA_dofunction(globalconf.L, (*b)->press, 1, 0);
}
else
luaA_dofunction(globalconf.L, buttons->tab[i]->press, 0, 0);
luaA_dofunction(globalconf.L, (*b)->press, 0, 0);
}
break;
case XCB_BUTTON_RELEASE:
if(buttons->tab[i]->release != LUA_REFNIL)
if((*b)->release != LUA_REFNIL)
{
if(c)
{
client_push(globalconf.L, c);
luaA_dofunction(globalconf.L, buttons->tab[i]->release, 1, 0);
luaA_dofunction(globalconf.L, (*b)->release, 1, 0);
}
else
luaA_dofunction(globalconf.L, buttons->tab[i]->release, 0, 0);
luaA_dofunction(globalconf.L, (*b)->release, 0, 0);
}
break;
}
@ -144,25 +143,22 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
}
/* check if we match a binding on the wibox */
button_array_t *b = &wibox->buttons;
for(int i = 0; i < b->len; i++)
if(ev->detail == b->tab[i]->button
&& ev->state == b->tab[i]->mod)
foreach(b, wibox->buttons)
if((!(*b)->button || ev->detail == (*b)->button) && ev->state == (*b)->mod)
switch(ev->response_type)
{
case XCB_BUTTON_PRESS:
if(b->tab[i]->press != LUA_REFNIL)
if((*b)->press != LUA_REFNIL)
{
wibox_push(globalconf.L, wibox);
luaA_dofunction(globalconf.L, b->tab[i]->press, 1, 0);
luaA_dofunction(globalconf.L, (*b)->press, 1, 0);
}
break;
case XCB_BUTTON_RELEASE:
if(b->tab[i]->release != LUA_REFNIL)
if((*b)->release != LUA_REFNIL)
{
wibox_push(globalconf.L, wibox);
luaA_dofunction(globalconf.L, b->tab[i]->release, 1, 0);
luaA_dofunction(globalconf.L, (*b)->release, 1, 0);
}
break;
}
@ -173,30 +169,26 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
wibox->sw.geometry.height,
&ev->event_x, &ev->event_y);
if(w)
{
b = &w->buttons;
for(int i = 0; i < b->len; i++)
if(ev->detail == b->tab[i]->button
&& ev->state == b->tab[i]->mod)
foreach(b, w->buttons)
if((!(*b)->button || ev->detail == (*b)->button) && ev->state == (*b)->mod)
switch(ev->response_type)
{
case XCB_BUTTON_PRESS:
if(b->tab[i]->press != LUA_REFNIL)
if((*b)->press != LUA_REFNIL)
{
wibox_push(globalconf.L, wibox);
luaA_dofunction(globalconf.L, b->tab[i]->press, 1, 0);
luaA_dofunction(globalconf.L, (*b)->press, 1, 0);
}
break;
case XCB_BUTTON_RELEASE:
if(b->tab[i]->release != LUA_REFNIL)
if((*b)->release != LUA_REFNIL)
{
wibox_push(globalconf.L, wibox);
luaA_dofunction(globalconf.L, b->tab[i]->release, 1, 0);
luaA_dofunction(globalconf.L, (*b)->release, 1, 0);
}
break;
}
}
/* return even if no widget match */
return 0;
}