Revert "key, button: use as simple table"
This reverts commit d7454f4307
.
Conflicts:
button.h
key.h
lib/awful/titlebar.lua.in
lib/naughty.lua.in
wibox.c
wibox.h
widget.c
This commit is contained in:
parent
0cc5d85111
commit
073e0377dd
|
@ -158,11 +158,11 @@ for s = 1, screen.count() do
|
|||
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
|
||||
-- We need one layoutbox per screen.
|
||||
mylayoutbox[s] = awful.widget.layoutbox(s)
|
||||
mylayoutbox[s].buttons = awful.util.table.join(
|
||||
mylayoutbox[s]:buttons(awful.util.table.join(
|
||||
awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
|
||||
awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
|
||||
awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
|
||||
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end))
|
||||
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
|
||||
-- Create a taglist widget
|
||||
mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
|
||||
|
||||
|
@ -191,10 +191,11 @@ end
|
|||
-- }}}
|
||||
|
||||
-- {{{ Mouse bindings
|
||||
root.buttons = awful.util.table.join(
|
||||
root.buttons(awful.util.table.join(
|
||||
awful.button({ }, 3, function () mymainmenu:toggle() end),
|
||||
awful.button({ }, 4, awful.tag.viewnext),
|
||||
awful.button({ }, 5, awful.tag.viewprev))
|
||||
awful.button({ }, 5, awful.tag.viewprev)
|
||||
))
|
||||
-- }}}
|
||||
|
||||
-- {{{ Key bindings
|
||||
|
@ -317,7 +318,7 @@ for i = 1, keynumber do
|
|||
end
|
||||
|
||||
-- Set keys
|
||||
root.keys = globalkeys
|
||||
root.keys(globalkeys)
|
||||
-- }}}
|
||||
|
||||
-- {{{ Hooks
|
||||
|
@ -368,10 +369,11 @@ awful.hooks.manage.register(function (c, startup)
|
|||
awful.titlebar.add(c, { modkey = modkey })
|
||||
end
|
||||
-- Add mouse bindings
|
||||
c.buttons = awful.util.table.join(
|
||||
c:buttons(awful.util.table.join(
|
||||
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
|
||||
awful.button({ modkey }, 1, awful.mouse.client.move),
|
||||
awful.button({ modkey }, 3, awful.mouse.client.resize))
|
||||
awful.button({ modkey }, 3, awful.mouse.client.resize)
|
||||
))
|
||||
-- New client may not receive focus
|
||||
-- if they're not focusable, so set border anyway.
|
||||
c.border_width = beautiful.border_width
|
||||
|
@ -402,7 +404,7 @@ awful.hooks.manage.register(function (c, startup)
|
|||
client.focus = c
|
||||
|
||||
-- Set key bindings
|
||||
c.keys = clientkeys
|
||||
c:keys(clientkeys)
|
||||
|
||||
-- Set the windows at the slave,
|
||||
-- i.e. put it at the end of others instead of setting it master.
|
||||
|
|
43
button.c
43
button.c
|
@ -61,6 +61,49 @@ luaA_button_new(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/** Set a button array with a Lua table.
|
||||
* \param L The Lua VM state.
|
||||
* \param oidx The index of the object to store items into.
|
||||
* \param idx The index of the Lua table.
|
||||
* \param buttons The array button to fill.
|
||||
*/
|
||||
void
|
||||
luaA_button_array_set(lua_State *L, int oidx, int idx, button_array_t *buttons)
|
||||
{
|
||||
luaA_checktable(L, idx);
|
||||
|
||||
foreach(button, *buttons)
|
||||
luaA_object_unref_item(L, oidx, *button);
|
||||
|
||||
button_array_wipe(buttons);
|
||||
button_array_init(buttons);
|
||||
|
||||
lua_pushnil(L);
|
||||
while(lua_next(L, idx))
|
||||
if(luaA_toudata(L, -1, "button"))
|
||||
button_array_append(buttons, luaA_object_ref_item(L, oidx, -1));
|
||||
else
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
/** Push an array of button as an Lua table onto the stack.
|
||||
* \param L The Lua VM state.
|
||||
* \param oidx The index of the object to get items from.
|
||||
* \param buttons The button array to push.
|
||||
* \return The number of elements pushed on stack.
|
||||
*/
|
||||
int
|
||||
luaA_button_array_get(lua_State *L, int oidx, button_array_t *buttons)
|
||||
{
|
||||
lua_createtable(L, buttons->len, 0);
|
||||
for(int i = 0; i < buttons->len; i++)
|
||||
{
|
||||
luaA_object_push_item(L, oidx, buttons->tab[i]);
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Button object.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of elements pushed on stack.
|
||||
|
|
4
button.h
4
button.h
|
@ -40,6 +40,10 @@ struct button_t
|
|||
|
||||
lua_class_t button_class;
|
||||
LUA_OBJECT_FUNCS(button_class, button_t, button, "button")
|
||||
ARRAY_FUNCS(button_t *, button, DO_NOTHING)
|
||||
|
||||
int luaA_button_array_get(lua_State *, int, button_array_t *);
|
||||
void luaA_button_array_set(lua_State *, int, int, button_array_t *);
|
||||
|
||||
#endif
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
56
client.c
56
client.c
|
@ -49,6 +49,8 @@ static int
|
|||
luaA_client_gc(lua_State *L)
|
||||
{
|
||||
client_t *c = luaL_checkudata(L, 1, "client");
|
||||
button_array_wipe(&c->buttons);
|
||||
key_array_wipe(&c->keys);
|
||||
xcb_get_wm_protocols_reply_wipe(&c->protocols);
|
||||
p_delete(&c->class);
|
||||
p_delete(&c->startup_id);
|
||||
|
@ -1582,14 +1584,6 @@ luaA_client_newindex(lua_State *L)
|
|||
c->skiptb = luaA_checkboolean(L, 3);
|
||||
hook_property(client, c, "skip_taskbar");
|
||||
break;
|
||||
case A_TK_KEYS:
|
||||
luaA_object_unref_item(L, 1, c->keys);
|
||||
c->keys = luaA_object_ref_item(L, 1, 3);
|
||||
break;
|
||||
case A_TK_BUTTONS:
|
||||
luaA_object_unref_item(L, 1, c->buttons);
|
||||
c->buttons = luaA_object_ref_item(L, 1, 3);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -1905,10 +1899,6 @@ luaA_client_index(lua_State *L)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case A_TK_KEYS:
|
||||
return luaA_object_push_item(L, 1, c->keys);
|
||||
case A_TK_BUTTONS:
|
||||
return luaA_object_push_item(L, 1, c->buttons);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -1916,6 +1906,46 @@ luaA_client_index(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/** Get or set mouse buttons bindings for a client.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of element pushed on stack.
|
||||
* \luastack
|
||||
* \lvalue A client.
|
||||
* \lparam An array of mouse button bindings objects, or nothing.
|
||||
* \return The array of mouse button bindings objects of this client.
|
||||
*/
|
||||
static int
|
||||
luaA_client_buttons(lua_State *L)
|
||||
{
|
||||
client_t *client = luaA_client_checkudata(L, 1);
|
||||
button_array_t *buttons = &client->buttons;
|
||||
|
||||
if(lua_gettop(L) == 2)
|
||||
luaA_button_array_set(L, 1, 2, buttons);
|
||||
|
||||
return luaA_button_array_get(L, 1, buttons);
|
||||
}
|
||||
|
||||
/** Get or set keys bindings for a client.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of element pushed on stack.
|
||||
* \luastack
|
||||
* \lvalue A client.
|
||||
* \lparam An array of key bindings objects, or nothing.
|
||||
* \return The array of key bindings objects of this client.
|
||||
*/
|
||||
static int
|
||||
luaA_client_keys(lua_State *L)
|
||||
{
|
||||
client_t *c = luaA_client_checkudata(L, 1);
|
||||
key_array_t *keys = &c->keys;
|
||||
|
||||
if(lua_gettop(L) == 2)
|
||||
luaA_key_array_set(L, 1, 2, keys);
|
||||
|
||||
return luaA_key_array_get(L, 1, keys);
|
||||
}
|
||||
|
||||
/* Client module.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of pushed elements.
|
||||
|
@ -1974,6 +2004,8 @@ const struct luaL_reg awesome_client_meta[] =
|
|||
{ "isvisible", luaA_client_isvisible },
|
||||
{ "geometry", luaA_client_geometry },
|
||||
{ "struts", luaA_client_struts },
|
||||
{ "buttons", luaA_client_buttons },
|
||||
{ "keys", luaA_client_keys },
|
||||
{ "tags", luaA_client_tags },
|
||||
{ "kill", luaA_client_kill },
|
||||
{ "swap", luaA_client_swap },
|
||||
|
|
4
client.h
4
client.h
|
@ -140,9 +140,9 @@ struct client_t
|
|||
/** Titlebar */
|
||||
wibox_t *titlebar;
|
||||
/** Button bindings */
|
||||
void *buttons;
|
||||
button_array_t buttons;
|
||||
/** Key bindings */
|
||||
void *keys;
|
||||
key_array_t keys;
|
||||
/** Icon */
|
||||
image_t *icon;
|
||||
/** Size hints */
|
||||
|
|
|
@ -14,7 +14,6 @@ border_padding
|
|||
border_width
|
||||
bottom
|
||||
button
|
||||
buttons
|
||||
button_press
|
||||
button_release
|
||||
center
|
||||
|
@ -49,7 +48,6 @@ image
|
|||
imagebox
|
||||
instance
|
||||
key
|
||||
keys
|
||||
key_press
|
||||
key_release
|
||||
keysym
|
||||
|
|
59
event.c
59
event.c
|
@ -42,34 +42,25 @@
|
|||
#include "common/atoms.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
#define DO_EVENT_HOOK_CALLBACK(type, prefix, xcbtype, xcbeventprefix, match) \
|
||||
#define DO_EVENT_HOOK_CALLBACK(type, prefix, xcbtype, xcbeventprefix, arraytype, match) \
|
||||
static int \
|
||||
event_##xcbtype##_callback(xcb_##xcbtype##_press_event_t *ev, \
|
||||
void *arr, \
|
||||
arraytype *arr, \
|
||||
int oud, \
|
||||
int nargs, \
|
||||
void *data) \
|
||||
{ \
|
||||
int abs_oud = oud < 0 ? ((lua_gettop(globalconf.L) + 1) + oud) : oud; \
|
||||
int item_matching = 0, item_matched = 0; \
|
||||
foreach(item, *arr) \
|
||||
if(match(ev, *item, data)) \
|
||||
{ \
|
||||
if(oud) \
|
||||
luaA_object_push_item(globalconf.L, abs_oud, arr); \
|
||||
luaA_object_push_item(globalconf.L, abs_oud, *item); \
|
||||
else \
|
||||
luaA_object_push(globalconf.L, arr); \
|
||||
lua_pushnil(globalconf.L); \
|
||||
while(luaA_next(globalconf.L, -2)) \
|
||||
{ \
|
||||
type *item = luaA_toudata(globalconf.L, -1, #prefix); \
|
||||
if(item && match(ev, item, data)) \
|
||||
{ \
|
||||
lua_insert(globalconf.L, -3); \
|
||||
prefix##_push(globalconf.L, *item); \
|
||||
item_matching++; \
|
||||
} \
|
||||
else \
|
||||
lua_pop(globalconf.L, 1); \
|
||||
} \
|
||||
/* remove the table */ \
|
||||
lua_pop(globalconf.L, 1); \
|
||||
for(item_matched = item_matching; item_matching > 0; item_matching--) \
|
||||
{ \
|
||||
type *item = luaL_checkudata(globalconf.L, -1, #prefix); \
|
||||
|
@ -80,7 +71,14 @@
|
|||
{ \
|
||||
for(int i = 0; i < nargs; i++) \
|
||||
lua_pushvalue(globalconf.L, - nargs - item_matching); \
|
||||
luaA_object_push_item(globalconf.L, - nargs - 1, item->press); \
|
||||
if(oud) \
|
||||
{ \
|
||||
luaA_object_push_item(globalconf.L, abs_oud, item); \
|
||||
luaA_object_push_item(globalconf.L, -1, item->press); \
|
||||
lua_remove(globalconf.L, -2); \
|
||||
} \
|
||||
else \
|
||||
prefix##_push_item(globalconf.L, item, item->press); \
|
||||
luaA_dofunction(globalconf.L, nargs, 0); \
|
||||
} \
|
||||
break; \
|
||||
|
@ -89,7 +87,14 @@
|
|||
{ \
|
||||
for(int i = 0; i < nargs; i++) \
|
||||
lua_pushvalue(globalconf.L, - nargs - item_matching); \
|
||||
luaA_object_push_item(globalconf.L, - nargs - 1, item->release); \
|
||||
if(oud) \
|
||||
{ \
|
||||
luaA_object_push_item(globalconf.L, abs_oud, item); \
|
||||
luaA_object_push_item(globalconf.L, -1, item->release); \
|
||||
lua_remove(globalconf.L, -2); \
|
||||
} \
|
||||
else \
|
||||
prefix##_push_item(globalconf.L, item, item->release); \
|
||||
luaA_dofunction(globalconf.L, nargs, 0); \
|
||||
} \
|
||||
break; \
|
||||
|
@ -117,8 +122,8 @@ event_key_match(xcb_key_press_event_t *ev, keyb_t *k, void *data)
|
|||
&& (k->mod == XCB_BUTTON_MASK_ANY || k->mod == ev->state));
|
||||
}
|
||||
|
||||
DO_EVENT_HOOK_CALLBACK(button_t, button, button, XCB_BUTTON, event_button_match)
|
||||
DO_EVENT_HOOK_CALLBACK(keyb_t, key, key, XCB_KEY, event_key_match)
|
||||
DO_EVENT_HOOK_CALLBACK(button_t, button, button, XCB_BUTTON, button_array_t, event_button_match)
|
||||
DO_EVENT_HOOK_CALLBACK(keyb_t, key, key, XCB_KEY, key_array_t, event_key_match)
|
||||
|
||||
/** Handle an event with mouse grabber if needed
|
||||
* \param x The x coordinate.
|
||||
|
@ -180,7 +185,7 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
|
|||
}
|
||||
|
||||
wibox_push(globalconf.L, wibox);
|
||||
event_button_callback(ev, wibox->buttons, -1, 1, NULL);
|
||||
event_button_callback(ev, &wibox->buttons, -1, 1, NULL);
|
||||
|
||||
/* then try to match a widget binding */
|
||||
widget_t *w = widget_getbycoords(wibox->orientation, &wibox->widgets,
|
||||
|
@ -191,13 +196,13 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
|
|||
{
|
||||
widget_push(globalconf.L, w);
|
||||
wibox_push(globalconf.L, wibox);
|
||||
event_button_callback(ev, w->buttons, -2, 2, NULL);
|
||||
event_button_callback(ev, &w->buttons, -2, 2, NULL);
|
||||
}
|
||||
}
|
||||
else if((c = client_getbywin(ev->event)))
|
||||
{
|
||||
client_push(globalconf.L, c);
|
||||
event_button_callback(ev, c->buttons, -1, 1, NULL);
|
||||
event_button_callback(ev, &c->buttons, -1, 1, NULL);
|
||||
xcb_allow_events(globalconf.connection,
|
||||
XCB_ALLOW_REPLAY_POINTER,
|
||||
XCB_CURRENT_TIME);
|
||||
|
@ -206,7 +211,7 @@ event_handle_button(void *data, xcb_connection_t *connection, xcb_button_press_e
|
|||
for(screen = 0; screen < nb_screen; screen++)
|
||||
if(xutil_screen_get(connection, screen)->root == ev->event)
|
||||
{
|
||||
event_button_callback(ev, globalconf.buttons, 0, 0, NULL);
|
||||
event_button_callback(ev, &globalconf.buttons, 0, 0, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -598,15 +603,15 @@ event_handle_key(void *data __attribute__ ((unused)),
|
|||
if((c = client_getbywin(ev->event)))
|
||||
{
|
||||
client_push(globalconf.L, c);
|
||||
if(!event_key_callback(ev, c->keys, -1, 1, &keysym))
|
||||
if(!event_key_callback(ev, globalconf.keys, 0, 0, &keysym))
|
||||
if(!event_key_callback(ev, &c->keys, -1, 1, &keysym))
|
||||
if(!event_key_callback(ev, &globalconf.keys, 0, 0, &keysym))
|
||||
xcb_allow_events(globalconf.connection,
|
||||
XCB_ALLOW_REPLAY_KEYBOARD,
|
||||
XCB_CURRENT_TIME);
|
||||
|
||||
}
|
||||
else
|
||||
event_key_callback(ev, globalconf.keys, 0, 0, &keysym);
|
||||
event_key_callback(ev, &globalconf.keys, 0, 0, &keysym);
|
||||
|
||||
xcb_allow_events(globalconf.connection,
|
||||
XCB_ALLOW_SYNC_KEYBOARD,
|
||||
|
|
43
key.c
43
key.c
|
@ -997,6 +997,49 @@ luaA_key_new(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/** Set a key array with a Lua table.
|
||||
* \param L The Lua VM state.
|
||||
* \param oidx The index of the object to store items into.
|
||||
* \param idx The index of the Lua table.
|
||||
* \param keys The array key to fill.
|
||||
*/
|
||||
void
|
||||
luaA_key_array_set(lua_State *L, int oidx, int idx, key_array_t *keys)
|
||||
{
|
||||
luaA_checktable(L, idx);
|
||||
|
||||
foreach(key, *keys)
|
||||
luaA_object_unref_item(L, oidx, *key);
|
||||
|
||||
key_array_wipe(keys);
|
||||
key_array_init(keys);
|
||||
|
||||
lua_pushnil(L);
|
||||
while(lua_next(L, idx))
|
||||
if(luaA_toudata(L, -1, "key"))
|
||||
key_array_append(keys, luaA_object_ref_item(L, oidx, -1));
|
||||
else
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
/** Push an array of key as an Lua table onto the stack.
|
||||
* \param L The Lua VM state.
|
||||
* \param oidx The index of the object to get items from.
|
||||
* \param keys The key array to push.
|
||||
* \return The number of elements pushed on stack.
|
||||
*/
|
||||
int
|
||||
luaA_key_array_get(lua_State *L, int oidx, key_array_t *keys)
|
||||
{
|
||||
lua_createtable(L, keys->len, 0);
|
||||
for(int i = 0; i < keys->len; i++)
|
||||
{
|
||||
luaA_object_push_item(L, oidx, keys->tab[i]);
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Push a modifier set to a Lua table.
|
||||
* \param L The Lua VM state.
|
||||
* \param modifiers The modifier.
|
||||
|
|
4
key.h
4
key.h
|
@ -41,10 +41,14 @@ typedef struct keyb_t
|
|||
|
||||
lua_class_t key_class;
|
||||
LUA_OBJECT_FUNCS(key_class, keyb_t, key, "key")
|
||||
DO_ARRAY(keyb_t *, key, DO_NOTHING)
|
||||
|
||||
bool key_press_lookup_string(xcb_keysym_t, char *, ssize_t);
|
||||
xcb_keysym_t key_getkeysym(xcb_keycode_t, uint16_t);
|
||||
|
||||
void luaA_key_array_set(lua_State *, int, int, key_array_t *);
|
||||
int luaA_key_array_get(lua_State *, int, key_array_t *);
|
||||
|
||||
int luaA_pushmodifiers(lua_State *, uint16_t);
|
||||
uint16_t luaA_tomodifiers(lua_State *L, int ud);
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ local function add_item(data, num, item_info)
|
|||
label.bg_image = icon
|
||||
end
|
||||
|
||||
item.buttons = bindings
|
||||
item:buttons(bindings)
|
||||
|
||||
function label.mouse_enter() item_enter(data, num, true) end
|
||||
function item.mouse_enter() item_enter(data, num, true) end
|
||||
|
@ -210,7 +210,7 @@ local function add_item(data, num, item_info)
|
|||
if type(item_info[2]) == "table" then
|
||||
submenu = widget({ type = "imagebox" })
|
||||
submenu.image = data.theme.submenu_icon and image(data.theme.submenu_icon)
|
||||
submenu.buttons = bindings
|
||||
submenu:buttons(bindings)
|
||||
|
||||
function submenu.mouse_enter() item_enter(data, num, true) end
|
||||
end
|
||||
|
|
|
@ -80,10 +80,11 @@ function add(c, args)
|
|||
end
|
||||
|
||||
-- Redirect relevant events to the client the titlebar belongs to
|
||||
title.buttons = util.table.join(
|
||||
local bts = util.table.join(
|
||||
abutton({ }, 1, button_callback_focus_raise_move),
|
||||
abutton({ args.modkey }, 1, button_callback_move),
|
||||
abutton({ args.modkey }, 3, button_callback_resize))
|
||||
title:buttons(bts)
|
||||
|
||||
local appicon = capi.widget({ type = "imagebox" })
|
||||
appicon.image = c.icon
|
||||
|
@ -172,6 +173,8 @@ end
|
|||
-- @param theme The theme from beautifull. Used to get the image paths
|
||||
-- @param state The state the button is associated to. Containse path the action and info about the image
|
||||
local function button_new(c, name, modkey, theme, state)
|
||||
local bts = abutton({ }, 1, nil, state.action)
|
||||
|
||||
-- get the image path from the theme. Only return a button if we find an image
|
||||
local img
|
||||
img = "titlebar_" .. name .. "_button_" .. state.img
|
||||
|
@ -184,9 +187,13 @@ local function button_new(c, name, modkey, theme, state)
|
|||
local bname = name .. "_" .. state.idx
|
||||
local button = widget.button({ image = img })
|
||||
if not button then return end
|
||||
local rbts = button:buttons()
|
||||
|
||||
button.buttons = util.table.join(button.buttons, abutton({ }, 1, nil, state.action))
|
||||
for k, v in pairs(rbts) do
|
||||
bts[#bts + 1] = v
|
||||
end
|
||||
|
||||
button:buttons(bts)
|
||||
button.visible = false
|
||||
return button
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ function new(args)
|
|||
args.type = "imagebox"
|
||||
local w = capi.widget(args)
|
||||
w.image = img_release
|
||||
w.buttons = button({}, 1, function () w.image = img_press end, function () w.image = img_release end)
|
||||
w:buttons(button({}, 1, function () w.image = img_press end, function () w.image = img_release end))
|
||||
function w.mouse_leave(s) w.image = img_release end
|
||||
function w.mouse_enter(s) if capi.mouse.coords().buttons[1] then w.image = img_press end end
|
||||
return w
|
||||
|
|
|
@ -65,8 +65,8 @@ function list_update(w, buttons, label, data, widgets, objects)
|
|||
data[o][kb] = capi.button(b.modifiers, b.button, press, release)
|
||||
end
|
||||
end
|
||||
w[k].buttons = data[o]
|
||||
w[k + 1].buttons = data[o]
|
||||
w[k]:buttons(data[o])
|
||||
w[k + 1]:buttons(data[o])
|
||||
end
|
||||
|
||||
local text, bg, bg_image, icon = label(o)
|
||||
|
|
|
@ -21,11 +21,12 @@ function new(args)
|
|||
if not w then return end
|
||||
|
||||
if args.command then
|
||||
w.buttons = util.table.join(w.buttons, button({}, 1, nil, function () util.spawn(args.command) end))
|
||||
b = util.table.join(w:buttons(), button({}, 1, nil, function () util.spawn(args.command) end))
|
||||
elseif args.menu then
|
||||
w.buttons = util.table.join(w.buttons, button({}, 1, nil, function () args.menu:toggle() end))
|
||||
b = util.table.join(w:buttons(), button({}, 1, nil, function () args.menu:toggle() end))
|
||||
end
|
||||
|
||||
w:buttons(b)
|
||||
return w
|
||||
end
|
||||
|
||||
|
|
|
@ -312,7 +312,7 @@ function notify(args)
|
|||
|
||||
-- create textbox
|
||||
local textbox = capi.widget({ type = "textbox", align = "flex" })
|
||||
textbox.buttons = util.table.join(button({ }, 1, run), button({ }, 3, die))
|
||||
textbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
||||
textbox:margin({ right = margin, left = margin, bottom = margin, top = margin })
|
||||
textbox.text = string.format('<span font_desc="%s"><b>%s</b>%s</span>', font, title, text)
|
||||
if hover_timeout then textbox.mouse_enter = hover_destroy end
|
||||
|
@ -328,7 +328,7 @@ function notify(args)
|
|||
-- if we have an icon, use it
|
||||
if icon then
|
||||
iconbox = capi.widget({ type = "imagebox", align = "left" })
|
||||
iconbox.buttons = util.table.join(button({ }, 1, run), button({ }, 3, die))
|
||||
iconbox:buttons(util.table.join(button({ }, 1, run), button({ }, 3, die)))
|
||||
local img
|
||||
if type(icon) == "string" then
|
||||
img = capi.image(icon)
|
||||
|
|
8
luaa.c
8
luaa.c
|
@ -49,8 +49,7 @@ extern const struct luaL_reg awesome_dbus_lib[];
|
|||
extern const struct luaL_reg awesome_hooks_lib[];
|
||||
extern const struct luaL_reg awesome_keygrabber_lib[];
|
||||
extern const struct luaL_reg awesome_mousegrabber_lib[];
|
||||
extern const struct luaL_reg awesome_root_methods[];
|
||||
extern const struct luaL_reg awesome_root_meta[];
|
||||
extern const struct luaL_reg awesome_root_lib[];
|
||||
extern const struct luaL_reg awesome_button_methods[];
|
||||
extern const struct luaL_reg awesome_button_meta[];
|
||||
extern const struct luaL_reg awesome_image_methods[];
|
||||
|
@ -649,8 +648,9 @@ luaA_init(xdgHandle* xdg)
|
|||
/* Export awesome lib */
|
||||
luaA_openlib(L, "awesome", awesome_lib, awesome_lib);
|
||||
|
||||
/* Export root */
|
||||
luaA_openlib(L, "root", awesome_root_methods, awesome_root_meta);
|
||||
/* Export root lib */
|
||||
luaL_register(L, "root", awesome_root_lib);
|
||||
lua_pop(L, 1); /* luaL_register() leaves the table on stack */
|
||||
|
||||
/* Export hooks lib */
|
||||
luaL_register(L, "hooks", awesome_hooks_lib);
|
||||
|
|
128
root.c
128
root.c
|
@ -22,6 +22,7 @@
|
|||
#include <xcb/xtest.h>
|
||||
|
||||
#include "structs.h"
|
||||
#include "button.h"
|
||||
#include "wibox.h"
|
||||
#include "common/xcursor.h"
|
||||
#include "common/tokenize.h"
|
||||
|
@ -100,6 +101,82 @@ luaA_root_fake_input(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** Get or set global key bindings.
|
||||
* This binding will be available when you'll press keys on root window.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of element pushed on stack.
|
||||
* \luastack
|
||||
* \lparam An array of key bindings objects, or nothing.
|
||||
* \lreturn The array of key bindings objects of this client.
|
||||
*/
|
||||
static int
|
||||
luaA_root_keys(lua_State *L)
|
||||
{
|
||||
if(lua_gettop(L) == 1)
|
||||
{
|
||||
luaA_checktable(L, 1);
|
||||
|
||||
foreach(key, globalconf.keys)
|
||||
key_unref(globalconf.L, *key);
|
||||
|
||||
key_array_wipe(&globalconf.keys);
|
||||
key_array_init(&globalconf.keys);
|
||||
|
||||
lua_pushnil(L);
|
||||
while(lua_next(L, 1))
|
||||
key_array_append(&globalconf.keys, key_ref(L, -1));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_createtable(L, globalconf.keys.len, 0);
|
||||
for(int i = 0; i < globalconf.keys.len; i++)
|
||||
{
|
||||
key_push(L, globalconf.keys.tab[i]);
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Get or set global mouse bindings.
|
||||
* This binding will be available when you'll click on root window.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of element pushed on stack.
|
||||
* \luastack
|
||||
* \lparam An array of mouse button bindings objects, or nothing.
|
||||
* \lreturn The array of mouse button bindings objects.
|
||||
*/
|
||||
static int
|
||||
luaA_root_buttons(lua_State *L)
|
||||
{
|
||||
if(lua_gettop(L) == 1)
|
||||
{
|
||||
luaA_checktable(L, 1);
|
||||
|
||||
foreach(button, globalconf.buttons)
|
||||
button_unref(globalconf.L, *button);
|
||||
|
||||
button_array_wipe(&globalconf.buttons);
|
||||
button_array_init(&globalconf.buttons);
|
||||
|
||||
lua_pushnil(L);
|
||||
while(lua_next(L, 1))
|
||||
button_array_append(&globalconf.buttons, button_ref(L, -1));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_createtable(L, globalconf.buttons.len, 0);
|
||||
for(int i = 0; i < globalconf.buttons.len; i++)
|
||||
{
|
||||
button_push(L, globalconf.buttons.tab[i]);
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Set the root cursor.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of element pushed on stack.
|
||||
|
@ -150,58 +227,13 @@ luaA_root_wiboxes(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
luaA_root_index(lua_State *L)
|
||||
{
|
||||
size_t len;
|
||||
const char *attr = luaL_checklstring(L, 2, &len);
|
||||
|
||||
switch(a_tokenize(attr, len))
|
||||
{
|
||||
case A_TK_KEYS:
|
||||
return luaA_object_push(L, globalconf.keys);
|
||||
case A_TK_BUTTONS:
|
||||
return luaA_object_push(L, globalconf.buttons);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
luaA_root_newindex(lua_State *L)
|
||||
{
|
||||
size_t len;
|
||||
const char *attr = luaL_checklstring(L, 2, &len);
|
||||
|
||||
switch(a_tokenize(attr, len))
|
||||
{
|
||||
case A_TK_KEYS:
|
||||
luaA_object_unref(L, globalconf.keys);
|
||||
globalconf.keys = luaA_object_ref(L, 3);
|
||||
break;
|
||||
case A_TK_BUTTONS:
|
||||
luaA_object_unref(L, globalconf.buttons);
|
||||
globalconf.buttons = luaA_object_ref(L, 3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct luaL_reg awesome_root_methods[] =
|
||||
const struct luaL_reg awesome_root_lib[] =
|
||||
{
|
||||
{ "buttons", luaA_root_buttons },
|
||||
{ "keys", luaA_root_keys },
|
||||
{ "cursor", luaA_root_cursor },
|
||||
{ "fake_input", luaA_root_fake_input },
|
||||
{ "wiboxes", luaA_root_wiboxes },
|
||||
{ "__index", luaA_root_index },
|
||||
{ "__newindex", luaA_root_newindex },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
const struct luaL_reg awesome_root_meta[] =
|
||||
{
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -68,9 +68,9 @@ struct awesome_t
|
|||
/** True if xinerama is active */
|
||||
bool xinerama_is_active;
|
||||
/** Root window key bindings */
|
||||
void *keys;
|
||||
key_array_t keys;
|
||||
/** Root window mouse bindings */
|
||||
void *buttons;
|
||||
button_array_t buttons;
|
||||
/** Modifiers masks */
|
||||
uint16_t numlockmask, shiftlockmask, capslockmask, modeswitchmask;
|
||||
/** Check for XTest extension */
|
||||
|
|
28
wibox.c
28
wibox.c
|
@ -40,6 +40,7 @@ luaA_wibox_gc(lua_State *L)
|
|||
wibox_t *wibox = luaL_checkudata(L, 1, "wibox");
|
||||
p_delete(&wibox->cursor);
|
||||
wibox_wipe(wibox);
|
||||
button_array_wipe(&wibox->buttons);
|
||||
widget_node_array_wipe(&wibox->widgets);
|
||||
return luaA_object_gc(L);
|
||||
}
|
||||
|
@ -906,8 +907,6 @@ luaA_wibox_index(lua_State *L)
|
|||
return luaA_object_push_item(L, 1, wibox->shape.bounding);
|
||||
case A_TK_SHAPE_CLIP:
|
||||
return luaA_object_push_item(L, 1, wibox->shape.clip);
|
||||
case A_TK_BUTTONS:
|
||||
return luaA_object_push_item(L, 1, wibox->buttons);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
@ -1130,9 +1129,6 @@ luaA_wibox_newindex(lua_State *L)
|
|||
luaA_object_unref_item(L, 1, wibox->shape.clip);
|
||||
wibox->shape.clip = luaA_object_ref_item(L, 1, 3);
|
||||
wibox->need_shape_update = true;
|
||||
case A_TK_BUTTONS:
|
||||
luaA_object_unref_item(L, 1, wibox->buttons);
|
||||
wibox->buttons = luaA_object_ref_item(L, 1, 3);
|
||||
break;
|
||||
default:
|
||||
switch(wibox->type)
|
||||
|
@ -1147,6 +1143,27 @@ 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 = luaL_checkudata(L, 1, "wibox");
|
||||
|
||||
if(lua_gettop(L) == 2)
|
||||
{
|
||||
luaA_button_array_set(L, 1, 2, &wibox->buttons);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return luaA_button_array_get(L, 1, &wibox->buttons);
|
||||
}
|
||||
|
||||
const struct luaL_reg awesome_wibox_methods[] =
|
||||
{
|
||||
LUA_CLASS_METHODS(wibox)
|
||||
|
@ -1156,6 +1173,7 @@ const struct luaL_reg awesome_wibox_methods[] =
|
|||
const struct luaL_reg awesome_wibox_meta[] =
|
||||
{
|
||||
LUA_OBJECT_META(wibox)
|
||||
{ "buttons", luaA_wibox_buttons },
|
||||
{ "geometry", luaA_wibox_geometry },
|
||||
{ "__index", luaA_wibox_index },
|
||||
{ "__newindex", luaA_wibox_newindex },
|
||||
|
|
2
wibox.h
2
wibox.h
|
@ -65,7 +65,7 @@ struct wibox_t
|
|||
/* Banned? used for titlebars */
|
||||
bool isbanned;
|
||||
/** Button bindings */
|
||||
void *buttons;
|
||||
button_array_t buttons;
|
||||
/** The window object. */
|
||||
xcb_window_t window;
|
||||
/** The pixmap copied to the window object. */
|
||||
|
|
30
widget.c
30
widget.c
|
@ -42,6 +42,7 @@ luaA_widget_gc(lua_State *L)
|
|||
widget_t *widget = luaL_checkudata(L, 1, "widget");
|
||||
if(widget->destructor)
|
||||
widget->destructor(widget);
|
||||
button_array_wipe(&widget->buttons);
|
||||
return luaA_object_gc(L);
|
||||
}
|
||||
|
||||
|
@ -448,6 +449,28 @@ luaA_widget_new(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/** Get or set mouse buttons bindings to a widget.
|
||||
* \param L The Lua VM state.
|
||||
*
|
||||
* \luastack
|
||||
* \lvalue A widget.
|
||||
* \lparam An array of mouse button bindings objects, or nothing.
|
||||
* \return The array of mouse button bindings objects of this widget.
|
||||
*/
|
||||
static int
|
||||
luaA_widget_buttons(lua_State *L)
|
||||
{
|
||||
widget_t *widget = luaL_checkudata(L, 1, "widget");
|
||||
|
||||
if(lua_gettop(L) == 2)
|
||||
{
|
||||
luaA_button_array_set(L, 1, 2, &widget->buttons);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return luaA_button_array_get(L, 1, &widget->buttons);
|
||||
}
|
||||
|
||||
/** Generic widget.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of elements pushed on stack.
|
||||
|
@ -476,8 +499,6 @@ luaA_widget_index(lua_State *L)
|
|||
return luaA_object_push_item(L, 1, widget->mouse_enter);
|
||||
case A_TK_MOUSE_LEAVE:
|
||||
return luaA_object_push_item(L, 1, widget->mouse_leave);
|
||||
case A_TK_BUTTONS:
|
||||
return luaA_object_push_item(L, 1, widget->buttons);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -512,10 +533,6 @@ luaA_widget_newindex(lua_State *L)
|
|||
luaA_object_unref_item(L, 1, widget->mouse_leave);
|
||||
widget->mouse_leave = luaA_object_ref_item(L, 1, 3);
|
||||
return 0;
|
||||
case A_TK_BUTTONS:
|
||||
luaA_object_unref_item(L, 1, widget->buttons);
|
||||
widget->buttons = luaA_object_ref_item(L, 1, 3);
|
||||
break;
|
||||
default:
|
||||
return widget->newindex ? widget->newindex(L, token) : 0;
|
||||
}
|
||||
|
@ -557,6 +574,7 @@ const struct luaL_reg awesome_widget_methods[] =
|
|||
const struct luaL_reg awesome_widget_meta[] =
|
||||
{
|
||||
LUA_OBJECT_META(widget)
|
||||
{ "buttons", luaA_widget_buttons },
|
||||
{ "extents", luaA_widget_extents },
|
||||
{ "__index", luaA_widget_index },
|
||||
{ "__newindex", luaA_widget_newindex },
|
||||
|
|
Loading…
Reference in New Issue