diff --git a/event.c b/event.c index f9ed0f14..fcce67e1 100644 --- a/event.c +++ b/event.c @@ -144,12 +144,38 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e ev->event_x -= wibox->sw.geometry.x; ev->event_y -= wibox->sw.geometry.y; } + + /* 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 + && XUTIL_MASK_CLEAN(ev->state) == b->tab[i]->mod) + switch(ev->response_type) + { + case XCB_BUTTON_PRESS: + if(b->tab[i]->press != LUA_REFNIL) + { + luaA_wibox_userdata_new(globalconf.L, wibox); + luaA_dofunction(globalconf.L, b->tab[i]->press, 1, 0); + } + break; + case XCB_BUTTON_RELEASE: + if(b->tab[i]->release != LUA_REFNIL) + { + luaA_wibox_userdata_new(globalconf.L, wibox); + luaA_dofunction(globalconf.L, b->tab[i]->release, 1, 0); + } + break; + } + + /* then try to match a widget binding */ if((w = widget_getbycoords(wibox->position, &wibox->widgets, wibox->sw.geometry.width, wibox->sw.geometry.height, &ev->event_x, &ev->event_y))) { - button_array_t *b = &w->buttons; + b = &w->buttons; for(int i = 0; i < b->len; i++) if(ev->detail == b->tab[i]->button diff --git a/structs.h b/structs.h index 3c685cec..13ef6dd3 100644 --- a/structs.h +++ b/structs.h @@ -99,6 +99,8 @@ typedef struct bool need_update; /** Cursor */ char *cursor; + /** Button bindings */ + button_array_t buttons; } wibox_t; ARRAY_TYPE(wibox_t *, wibox) diff --git a/wibox.c b/wibox.c index a1a6df1b..9a460deb 100644 --- a/wibox.c +++ b/wibox.c @@ -455,6 +455,7 @@ void wibox_delete(wibox_t **wibox) { simplewindow_wipe(&(*wibox)->sw); + button_array_wipe(&(*wibox)->buttons); luaL_unref(globalconf.L, LUA_REGISTRYINDEX, (*wibox)->widgets_table); widget_node_array_wipe(&(*wibox)->widgets); p_delete(wibox); @@ -1053,6 +1054,28 @@ luaA_wibox_newindex(lua_State *L) return 0; } +/** Get or set mouse buttons bindings to a wibox. + * \param L The Lua VM state. + * \luastack + * \lvalue A wibox. + * \lparam An array of mouse button bindings objects, or nothing. + * \return The array of mouse button bindings objects of this wibox. + */ +static int +luaA_wibox_buttons(lua_State *L) +{ + wibox_t **wibox = luaA_checkudata(L, 1, "wibox"); + button_array_t *buttons = &(*wibox)->buttons; + + if(lua_gettop(L) == 2) + { + luaA_button_array_set(L, 2, buttons); + return 1; + } + + return luaA_button_array_get(L, buttons); +} + const struct luaL_reg awesome_wibox_methods[] = { { "__call", luaA_wibox_new }, @@ -1060,6 +1083,7 @@ const struct luaL_reg awesome_wibox_methods[] = }; const struct luaL_reg awesome_wibox_meta[] = { + { "buttons", luaA_wibox_buttons }, { "geometry", luaA_wibox_geometry }, { "__index", luaA_wibox_index }, { "__newindex", luaA_wibox_newindex },