[lua] Add object as argument to mouse click function
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
c5237444a9
commit
4c41361d6c
|
@ -44,7 +44,7 @@ mytaglist = widget.new({ type = "taglist", name = "mytaglist" })
|
||||||
mytaglist:mouse({}, 1, awful.tag.viewonly)
|
mytaglist:mouse({}, 1, awful.tag.viewonly)
|
||||||
mytaglist:mouse({ modkey }, 1, awful.client.toggletag)
|
mytaglist:mouse({ modkey }, 1, awful.client.toggletag)
|
||||||
mytaglist:mouse({}, 3,
|
mytaglist:mouse({}, 3,
|
||||||
function (tag)
|
function (object, tag)
|
||||||
tag:view(not tag:isselected())
|
tag:view(not tag:isselected())
|
||||||
end)
|
end)
|
||||||
mytaglist:mouse({ modkey }, 3, awful.client.toggletag)
|
mytaglist:mouse({ modkey }, 3, awful.client.toggletag)
|
||||||
|
@ -54,7 +54,7 @@ mytaglist:set("text_focus", "<bg color=\"#555555\"/> <title/> ")
|
||||||
|
|
||||||
-- Create a tasklist widget
|
-- Create a tasklist widget
|
||||||
mytasklist = widget.new({ type = "tasklist", name = "mytasklist" })
|
mytasklist = widget.new({ type = "tasklist", name = "mytasklist" })
|
||||||
mytasklist:mouse({ }, 1, function (c) c:focus_set(); c:raise() end)
|
mytasklist:mouse({ }, 1, function (object, c) c:focus_set(); c:raise() end)
|
||||||
mytasklist:mouse({ }, 4, function () awful.client.focus(1) end)
|
mytasklist:mouse({ }, 4, function () awful.client.focus(1) end)
|
||||||
mytasklist:mouse({ }, 5, function () awful.client.focus(-1) end)
|
mytasklist:mouse({ }, 5, function () awful.client.focus(-1) end)
|
||||||
mytasklist:set("text_focus", "<bg color=\"#555555\"/> <title/> ")
|
mytasklist:set("text_focus", "<bg color=\"#555555\"/> <title/> ")
|
||||||
|
|
6
event.c
6
event.c
|
@ -115,7 +115,8 @@ event_handle_buttonpress(void *data __attribute__ ((unused)),
|
||||||
if(ev->event_x >= w->area.x && ev->event_x < w->area.x + w->area.width
|
if(ev->event_x >= w->area.x && ev->event_x < w->area.x + w->area.width
|
||||||
&& ev->event_y >= w->area.y && ev->event_y < w->area.y + w->area.height)
|
&& ev->event_y >= w->area.y && ev->event_y < w->area.y + w->area.height)
|
||||||
{
|
{
|
||||||
w->widget->button_press(w, ev, statusbar->screen, statusbar);
|
w->widget->button_press(w, ev, statusbar->screen,
|
||||||
|
statusbar, AWESOME_TYPE_STATUSBAR);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* return if no widget match */
|
/* return if no widget match */
|
||||||
|
@ -145,7 +146,8 @@ event_handle_buttonpress(void *data __attribute__ ((unused)),
|
||||||
if(ev->event_x >= w->area.x && ev->event_x < w->area.x + w->area.width
|
if(ev->event_x >= w->area.x && ev->event_x < w->area.x + w->area.width
|
||||||
&& ev->event_y >= w->area.y && ev->event_y < w->area.y + w->area.height)
|
&& ev->event_y >= w->area.y && ev->event_y < w->area.y + w->area.height)
|
||||||
{
|
{
|
||||||
w->widget->button_press(w, ev, c->screen, c->titlebar);
|
w->widget->button_press(w, ev, c->screen,
|
||||||
|
c->titlebar, AWESOME_TYPE_TITLEBAR);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* return if no widget match */
|
/* return if no widget match */
|
||||||
|
|
21
lua.c
21
lua.c
|
@ -35,6 +35,8 @@
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "statusbar.h"
|
||||||
|
#include "titlebar.h"
|
||||||
#include "layouts/tile.h"
|
#include "layouts/tile.h"
|
||||||
|
|
||||||
extern awesome_t globalconf;
|
extern awesome_t globalconf;
|
||||||
|
@ -367,6 +369,25 @@ luaA_colors_set(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Push a pointer onto the stack according to its type.
|
||||||
|
* \param L The Lua state.
|
||||||
|
* \param p The pointer.
|
||||||
|
* \param type Its type.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
luaA_pushpointer(void *p, awesome_type_t type)
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case AWESOME_TYPE_STATUSBAR:
|
||||||
|
luaA_statusbar_userdata_new(p);
|
||||||
|
break;
|
||||||
|
case AWESOME_TYPE_TITLEBAR:
|
||||||
|
luaA_titlebar_userdata_new(p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
luaA_openlib(lua_State *L, const char *name,
|
luaA_openlib(lua_State *L, const char *name,
|
||||||
const struct luaL_reg methods[],
|
const struct luaL_reg methods[],
|
||||||
|
|
10
lua.h
10
lua.h
|
@ -27,6 +27,13 @@
|
||||||
|
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
|
|
||||||
|
/** Object types */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
AWESOME_TYPE_STATUSBAR = 1,
|
||||||
|
AWESOME_TYPE_TITLEBAR
|
||||||
|
} awesome_type_t;
|
||||||
|
|
||||||
/** Type for Lua function */
|
/** Type for Lua function */
|
||||||
typedef int luaA_function;
|
typedef int luaA_function;
|
||||||
|
|
||||||
|
@ -126,8 +133,9 @@ luaA_checkboolean(lua_State *L, int n)
|
||||||
return lua_toboolean(L, n);
|
return lua_toboolean(L, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool luaA_parserc(const char *);
|
bool luaA_parserc(const char *);
|
||||||
void luaA_docmd(char *);
|
void luaA_docmd(char *);
|
||||||
|
void luaA_pushpointer(void *, awesome_type_t);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
12
statusbar.c
12
statusbar.c
|
@ -473,6 +473,18 @@ luaA_statusbar_new(lua_State *L)
|
||||||
return luaA_settype(L, "statusbar");
|
return luaA_settype(L, "statusbar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Create a new statusbar userdata.
|
||||||
|
* \param t The statusbar.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
luaA_statusbar_userdata_new(statusbar_t *t)
|
||||||
|
{
|
||||||
|
statusbar_t **sb = lua_newuserdata(globalconf.L, sizeof(statusbar_t *));
|
||||||
|
*sb = t;
|
||||||
|
statusbar_ref(sb);
|
||||||
|
return luaA_settype(globalconf.L, "statusbar");
|
||||||
|
}
|
||||||
|
|
||||||
/** Get all widget from a statusbar.
|
/** Get all widget from a statusbar.
|
||||||
* \return A table with all widgets from the statusbar.
|
* \return A table with all widgets from the statusbar.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -37,6 +37,8 @@ statusbar_delete(statusbar_t **statusbar)
|
||||||
|
|
||||||
void statusbar_refresh(void);
|
void statusbar_refresh(void);
|
||||||
|
|
||||||
|
int luaA_statusbar_userdata_new(statusbar_t *);
|
||||||
|
|
||||||
DO_RCNT(statusbar_t, statusbar, statusbar_delete)
|
DO_RCNT(statusbar_t, statusbar, statusbar_delete)
|
||||||
DO_SLIST(statusbar_t, statusbar, statusbar_delete)
|
DO_SLIST(statusbar_t, statusbar, statusbar_delete)
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ struct widget_t
|
||||||
/** Update function */
|
/** Update function */
|
||||||
widget_tell_status_t (*tell)(widget_t *, const char *, const char *);
|
widget_tell_status_t (*tell)(widget_t *, const char *, const char *);
|
||||||
/** ButtonPressedEvent handler */
|
/** ButtonPressedEvent handler */
|
||||||
void (*button_press)(widget_node_t *, xcb_button_press_event_t *, int, void *);
|
void (*button_press)(widget_node_t *, xcb_button_press_event_t *, int, void *, awesome_type_t);
|
||||||
/** Alignement */
|
/** Alignement */
|
||||||
alignment_t align;
|
alignment_t align;
|
||||||
/** Misc private data */
|
/** Misc private data */
|
||||||
|
|
32
titlebar.c
32
titlebar.c
|
@ -406,44 +406,38 @@ titlebar_init(client_t *c)
|
||||||
static int
|
static int
|
||||||
luaA_titlebar_new(lua_State *L)
|
luaA_titlebar_new(lua_State *L)
|
||||||
{
|
{
|
||||||
titlebar_t **tb;
|
titlebar_t *tb;
|
||||||
int objpos;
|
|
||||||
const char *color;
|
const char *color;
|
||||||
|
|
||||||
luaA_checktable(L, 1);
|
luaA_checktable(L, 1);
|
||||||
|
|
||||||
tb = lua_newuserdata(L, sizeof(titlebar_t *));
|
tb = p_new(titlebar_t, 1);
|
||||||
*tb = p_new(titlebar_t, 1);
|
|
||||||
objpos = lua_gettop(L);
|
|
||||||
|
|
||||||
(*tb)->align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
tb->align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
||||||
|
|
||||||
(*tb)->width = luaA_getopt_number(L, 1, "width", 0);
|
tb->width = luaA_getopt_number(L, 1, "width", 0);
|
||||||
(*tb)->height = luaA_getopt_number(L, 1, "height", 0);
|
tb->height = luaA_getopt_number(L, 1, "height", 0);
|
||||||
if((*tb)->height <= 0)
|
if(tb->height <= 0)
|
||||||
/* 1.5 as default factor, it fits nice but no one knows why */
|
/* 1.5 as default factor, it fits nice but no one knows why */
|
||||||
(*tb)->height = 1.5 * globalconf.font->height;
|
tb->height = 1.5 * globalconf.font->height;
|
||||||
|
|
||||||
(*tb)->position = position_get_from_str(luaA_getopt_string(L, 1, "position", "top"));
|
tb->position = position_get_from_str(luaA_getopt_string(L, 1, "position", "top"));
|
||||||
|
|
||||||
lua_getfield(L, 1, "fg");
|
lua_getfield(L, 1, "fg");
|
||||||
if((color = luaL_optstring(L, -1, NULL)))
|
if((color = luaL_optstring(L, -1, NULL)))
|
||||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||||
color, &(*tb)->colors.fg);
|
color, &tb->colors.fg);
|
||||||
else
|
else
|
||||||
(*tb)->colors.fg = globalconf.colors.fg;
|
tb->colors.fg = globalconf.colors.fg;
|
||||||
|
|
||||||
lua_getfield(L, 1, "bg");
|
lua_getfield(L, 1, "bg");
|
||||||
if((color = luaL_optstring(L, -1, NULL)))
|
if((color = luaL_optstring(L, -1, NULL)))
|
||||||
xcolor_new(globalconf.connection, globalconf.default_screen,
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
||||||
color, &(*tb)->colors.bg);
|
color, &tb->colors.bg);
|
||||||
else
|
else
|
||||||
(*tb)->colors.bg = globalconf.colors.bg;
|
tb->colors.bg = globalconf.colors.bg;
|
||||||
|
|
||||||
titlebar_ref(tb);
|
return luaA_titlebar_userdata_new(tb);
|
||||||
|
|
||||||
lua_pushvalue(L, objpos);
|
|
||||||
return luaA_settype(L, "titlebar");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a widget to a titlebar.
|
/** Add a widget to a titlebar.
|
||||||
|
|
11
widget.c
11
widget.c
|
@ -80,18 +80,23 @@ widget_getbyname(const char *name)
|
||||||
* \param ev The button press event the widget received.
|
* \param ev The button press event the widget received.
|
||||||
* \param screen The screen number.
|
* \param screen The screen number.
|
||||||
* \param p The object where user clicked.
|
* \param p The object where user clicked.
|
||||||
|
* \param type The object type.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
widget_common_button_press(widget_node_t *w,
|
widget_common_button_press(widget_node_t *w,
|
||||||
xcb_button_press_event_t *ev,
|
xcb_button_press_event_t *ev,
|
||||||
int screen __attribute__ ((unused)),
|
int screen __attribute__ ((unused)),
|
||||||
void *p __attribute__ ((unused)))
|
void *p,
|
||||||
|
awesome_type_t type)
|
||||||
{
|
{
|
||||||
button_t *b;
|
button_t *b;
|
||||||
|
|
||||||
for(b = w->widget->buttons; b; b = b->next)
|
for(b = w->widget->buttons; b; b = b->next)
|
||||||
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
|
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
|
||||||
luaA_dofunction(globalconf.L, b->fct, 0);
|
{
|
||||||
|
luaA_pushpointer(p, type);
|
||||||
|
luaA_dofunction(globalconf.L, b->fct, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Common tell function for widget, which only warn user that widget
|
/** Common tell function for widget, which only warn user that widget
|
||||||
|
|
|
@ -190,11 +190,19 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w,
|
||||||
return w->area.width;
|
return w->area.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Handle button click on tasklist.
|
||||||
|
* \param w The widget node.
|
||||||
|
* \param ev The button press event.
|
||||||
|
* \param screen The screen where the click was.
|
||||||
|
* \param object The object we're onto.
|
||||||
|
* \param type The type object.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
taglist_button_press(widget_node_t *w,
|
taglist_button_press(widget_node_t *w,
|
||||||
xcb_button_press_event_t *ev,
|
xcb_button_press_event_t *ev,
|
||||||
int screen,
|
int screen,
|
||||||
void *object)
|
void *object,
|
||||||
|
awesome_type_t type)
|
||||||
{
|
{
|
||||||
screen_t *vscreen = &globalconf.screens[screen];
|
screen_t *vscreen = &globalconf.screens[screen];
|
||||||
button_t *b;
|
button_t *b;
|
||||||
|
@ -213,8 +221,9 @@ taglist_button_press(widget_node_t *w,
|
||||||
if(ev->event_x >= AREA_LEFT(*area)
|
if(ev->event_x >= AREA_LEFT(*area)
|
||||||
&& ev->event_x < AREA_RIGHT(*area))
|
&& ev->event_x < AREA_RIGHT(*area))
|
||||||
{
|
{
|
||||||
|
luaA_pushpointer(object, type);
|
||||||
luaA_tag_userdata_new(tag);
|
luaA_tag_userdata_new(tag);
|
||||||
luaA_dofunction(globalconf.L, b->fct, 1);
|
luaA_dofunction(globalconf.L, b->fct, 2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,11 +171,19 @@ tasklist_draw(draw_context_t *ctx, int screen,
|
||||||
return w->area.width;
|
return w->area.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Handle button click on tasklist.
|
||||||
|
* \param w The widget node.
|
||||||
|
* \param ev The button press event.
|
||||||
|
* \param screen The screen where the click was.
|
||||||
|
* \param object The object we're onto.
|
||||||
|
* \param type The type object.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
tasklist_button_press(widget_node_t *w,
|
tasklist_button_press(widget_node_t *w,
|
||||||
xcb_button_press_event_t *ev,
|
xcb_button_press_event_t *ev,
|
||||||
int screen,
|
int screen,
|
||||||
void *p __attribute__ ((unused)))
|
void *object,
|
||||||
|
awesome_type_t type)
|
||||||
{
|
{
|
||||||
button_t *b;
|
button_t *b;
|
||||||
client_t *c;
|
client_t *c;
|
||||||
|
@ -207,8 +215,9 @@ tasklist_button_press(widget_node_t *w,
|
||||||
for(b = w->widget->buttons; b; b = b->next)
|
for(b = w->widget->buttons; b; b = b->next)
|
||||||
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
|
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
|
||||||
{
|
{
|
||||||
|
luaA_pushpointer(object, type);
|
||||||
luaA_client_userdata_new(c);
|
luaA_client_userdata_new(c);
|
||||||
luaA_dofunction(globalconf.L, b->fct, 1);
|
luaA_dofunction(globalconf.L, b->fct, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue