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. * \return The number of elements pushed on stack.
* \luastack * \luastack
* \lparam A table with modifiers keys, or a button to clone. * \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 click events.
* \lparam A function to execute on release events. * \lparam A function to execute on release events.
* \lreturn A mouse button binding. * \lreturn A mouse button binding.

50
event.c
View File

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