2007-12-22 15:46:57 +01:00
|
|
|
/*
|
|
|
|
* widget.c - widget managing
|
|
|
|
*
|
2008-03-06 11:41:26 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-12-22 15:46:57 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-06-03 16:32:23 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
2008-06-17 21:23:38 +02:00
|
|
|
#include <xcb/xcb_atom.h>
|
2008-06-03 16:32:23 +02:00
|
|
|
|
2007-12-15 07:53:53 +01:00
|
|
|
#include "widget.h"
|
2008-06-03 18:41:54 +02:00
|
|
|
#include "titlebar.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2007-12-16 10:25:13 +01:00
|
|
|
|
2008-06-18 18:31:35 +02:00
|
|
|
DO_LUA_NEW(extern, widget_t, widget, "widget", widget_ref)
|
|
|
|
DO_LUA_GC(widget_t, widget, "widget", widget_unref)
|
|
|
|
DO_LUA_EQ(widget_t, widget, "widget")
|
|
|
|
|
2008-01-16 08:06:59 +01:00
|
|
|
#include "widgetgen.h"
|
2007-12-15 18:21:02 +01:00
|
|
|
|
2008-03-06 11:41:26 +01:00
|
|
|
/** Compute offset for drawing the first pixel of a widget.
|
2008-04-29 09:09:25 +02:00
|
|
|
* \param barwidth The statusbar width.
|
|
|
|
* \param widgetwidth The widget width.
|
|
|
|
* \param alignment The widget alignment on statusbar.
|
|
|
|
* \return The x coordinate to draw at.
|
2008-03-06 11:41:26 +01:00
|
|
|
*/
|
2007-12-15 07:53:53 +01:00
|
|
|
int
|
2007-12-22 20:55:17 +01:00
|
|
|
widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment)
|
2007-12-15 07:53:53 +01:00
|
|
|
{
|
2008-01-04 19:17:20 +01:00
|
|
|
switch(alignment)
|
|
|
|
{
|
|
|
|
case AlignLeft:
|
|
|
|
case AlignFlex:
|
2007-12-15 07:53:53 +01:00
|
|
|
return offset;
|
2008-01-04 19:17:20 +01:00
|
|
|
}
|
2007-12-15 13:37:34 +01:00
|
|
|
return barwidth - offset - widgetwidth;
|
2007-12-15 07:53:53 +01:00
|
|
|
}
|
|
|
|
|
2008-03-06 11:41:26 +01:00
|
|
|
/** Common function for button press event on widget.
|
|
|
|
* It will look into configuration to find the callback function to call.
|
2008-05-20 15:39:47 +02:00
|
|
|
* \param w The widget node.
|
2008-04-29 09:09:25 +02:00
|
|
|
* \param ev The button press event the widget received.
|
2008-06-03 11:40:50 +02:00
|
|
|
* \param screen The screen number.
|
|
|
|
* \param p The object where user clicked.
|
2008-06-04 19:21:21 +02:00
|
|
|
* \param type The object type.
|
2008-03-06 11:41:26 +01:00
|
|
|
*/
|
2007-12-27 15:49:00 +01:00
|
|
|
static void
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_common_button_press(widget_node_t *w,
|
2008-06-03 11:40:50 +02:00
|
|
|
xcb_button_press_event_t *ev,
|
|
|
|
int screen __attribute__ ((unused)),
|
2008-06-04 19:21:21 +02:00
|
|
|
void *p,
|
|
|
|
awesome_type_t type)
|
2007-12-27 15:49:00 +01:00
|
|
|
{
|
2008-05-23 13:35:46 +02:00
|
|
|
button_t *b;
|
2008-06-04 19:21:21 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
for(b = w->widget->buttons; b; b = b->next)
|
|
|
|
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
|
2008-06-04 19:21:21 +02:00
|
|
|
{
|
2008-06-18 18:31:35 +02:00
|
|
|
luaA_pushpointer(globalconf.L, p, type);
|
2008-06-04 19:21:21 +02:00
|
|
|
luaA_dofunction(globalconf.L, b->fct, 1);
|
|
|
|
}
|
2007-12-27 15:49:00 +01:00
|
|
|
}
|
|
|
|
|
2008-06-03 16:32:23 +02:00
|
|
|
/** Render a list of widgets.
|
|
|
|
* \param wnode The list of widgets.
|
|
|
|
* \param ctx The draw context where to render.
|
2008-06-08 15:27:05 +02:00
|
|
|
* \param rotate_px The rotate pixmap: where to rotate and render the final
|
2008-06-03 16:32:23 +02:00
|
|
|
* \param screen The logical screen used to render.
|
|
|
|
* \param position The object position.
|
|
|
|
* \param x The x coordinates of the object.
|
|
|
|
* \param y The y coordinates of the object.
|
2008-06-04 16:13:41 +02:00
|
|
|
* pixmap when the object position is right or left.
|
2008-06-03 16:32:23 +02:00
|
|
|
* \param object The object pointer.
|
2008-06-03 18:41:54 +02:00
|
|
|
* \todo Remove GC.
|
2008-06-03 16:32:23 +02:00
|
|
|
*/
|
|
|
|
void
|
2008-06-04 16:13:41 +02:00
|
|
|
widget_render(widget_node_t *wnode, draw_context_t *ctx, xcb_gcontext_t gc, xcb_pixmap_t rotate_px,
|
2008-06-03 16:32:23 +02:00
|
|
|
int screen, position_t position,
|
|
|
|
int x, int y, void *object)
|
|
|
|
{
|
|
|
|
xcb_pixmap_t rootpix;
|
2008-06-08 10:59:13 +02:00
|
|
|
xcb_screen_t *s;
|
2008-06-03 16:32:23 +02:00
|
|
|
widget_node_t *w;
|
|
|
|
int left = 0, right = 0;
|
|
|
|
char *data;
|
|
|
|
xcb_get_property_reply_t *prop_r;
|
|
|
|
xcb_get_property_cookie_t prop_c;
|
2008-06-22 22:09:48 +02:00
|
|
|
area_t rectangle = { 0, 0, 0, 0 };
|
2008-06-17 21:23:38 +02:00
|
|
|
xcb_atom_t rootpix_atom;
|
|
|
|
xutil_intern_atom_request_t rootpix_atom_req;
|
2008-06-03 16:32:23 +02:00
|
|
|
|
|
|
|
/* Send requests needed for transparency */
|
|
|
|
if(ctx->bg.alpha != 0xffff)
|
|
|
|
rootpix_atom_req = xutil_intern_atom(globalconf.connection, &globalconf.atoms, "_XROOTPMAP_ID");
|
|
|
|
|
|
|
|
rectangle.width = ctx->width;
|
|
|
|
rectangle.height = ctx->height;
|
|
|
|
|
|
|
|
if(ctx->bg.alpha != 0xffff)
|
|
|
|
{
|
2008-06-17 16:55:24 +02:00
|
|
|
s = xutil_screen_get(globalconf.connection, ctx->phys_screen);
|
2008-06-03 16:32:23 +02:00
|
|
|
rootpix_atom = xutil_intern_atom_reply(globalconf.connection, &globalconf.atoms, rootpix_atom_req);
|
2008-06-15 16:29:12 +02:00
|
|
|
prop_c = xcb_get_property_unchecked(globalconf.connection, false, s->root, rootpix_atom,
|
2008-06-17 21:23:38 +02:00
|
|
|
PIXMAP, 0, 1);
|
2008-06-03 16:32:23 +02:00
|
|
|
if((prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL)))
|
|
|
|
{
|
2008-06-15 16:14:39 +02:00
|
|
|
if((data = xcb_get_property_value(prop_r))
|
|
|
|
&& (rootpix = *(xcb_pixmap_t *) data))
|
2008-06-03 16:32:23 +02:00
|
|
|
switch(position)
|
|
|
|
{
|
|
|
|
case Left:
|
|
|
|
draw_rotate(ctx,
|
2008-06-04 16:13:41 +02:00
|
|
|
rootpix, ctx->pixmap,
|
2008-06-08 10:59:13 +02:00
|
|
|
s->width_in_pixels, s->height_in_pixels,
|
2008-06-03 16:32:23 +02:00
|
|
|
ctx->width, ctx->height,
|
|
|
|
M_PI_2,
|
|
|
|
y + ctx->width,
|
|
|
|
- x);
|
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
draw_rotate(ctx,
|
2008-06-04 16:13:41 +02:00
|
|
|
rootpix, ctx->pixmap,
|
2008-06-08 10:59:13 +02:00
|
|
|
s->width_in_pixels, s->height_in_pixels,
|
2008-06-03 16:32:23 +02:00
|
|
|
ctx->width, ctx->height,
|
|
|
|
- M_PI_2,
|
|
|
|
- y,
|
|
|
|
x + ctx->height);
|
|
|
|
break;
|
|
|
|
default:
|
2008-06-03 18:41:54 +02:00
|
|
|
xcb_copy_area(globalconf.connection, rootpix,
|
2008-06-04 16:13:41 +02:00
|
|
|
rotate_px, gc,
|
2008-06-03 18:41:54 +02:00
|
|
|
x, y,
|
|
|
|
0, 0,
|
|
|
|
ctx->width, ctx->height);
|
2008-06-03 16:32:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
p_delete(&prop_r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, ctx->bg);
|
|
|
|
|
|
|
|
for(w = wnode; w; w = w->next)
|
|
|
|
if(w->widget->isvisible && w->widget->align == AlignLeft)
|
|
|
|
left += w->widget->draw(ctx, screen, w, left, (left + right), object);
|
|
|
|
|
|
|
|
/* renders right widget from last to first */
|
|
|
|
for(w = *widget_node_list_last(&wnode); w; w = w->prev)
|
|
|
|
if(w->widget->isvisible && w->widget->align == AlignRight)
|
|
|
|
right += w->widget->draw(ctx, screen, w, right, (left + right), object);
|
|
|
|
|
|
|
|
for(w = wnode; w; w = w->next)
|
|
|
|
if(w->widget->isvisible && w->widget->align == AlignFlex)
|
|
|
|
left += w->widget->draw(ctx, screen, w, left, (left + right), object);
|
|
|
|
|
|
|
|
switch(position)
|
|
|
|
{
|
|
|
|
case Right:
|
2008-06-04 16:13:41 +02:00
|
|
|
draw_rotate(ctx, ctx->pixmap, rotate_px,
|
2008-06-03 16:32:23 +02:00
|
|
|
ctx->width, ctx->height,
|
|
|
|
ctx->height, ctx->width,
|
|
|
|
M_PI_2, ctx->height, 0);
|
|
|
|
break;
|
|
|
|
case Left:
|
2008-06-04 16:13:41 +02:00
|
|
|
draw_rotate(ctx, ctx->pixmap, rotate_px,
|
2008-06-03 16:32:23 +02:00
|
|
|
ctx->width, ctx->height,
|
|
|
|
ctx->height, ctx->width,
|
|
|
|
- M_PI_2, 0, ctx->width);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-29 09:09:25 +02:00
|
|
|
/** Common function for creating a widget.
|
|
|
|
* \param widget The allocated widget.
|
2008-03-06 11:41:26 +01:00
|
|
|
*/
|
2007-12-16 09:34:33 +01:00
|
|
|
void
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_common_new(widget_t *widget)
|
2007-12-16 09:34:33 +01:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
widget->align = AlignLeft;
|
2007-12-27 15:49:00 +01:00
|
|
|
widget->button_press = widget_common_button_press;
|
2007-12-16 09:34:33 +01:00
|
|
|
}
|
|
|
|
|
2008-03-06 11:41:26 +01:00
|
|
|
/** Invalidate widgets which should be refresh upon
|
2008-04-11 11:26:37 +02:00
|
|
|
* external modifications. widget_t who watch flags will
|
2008-03-06 11:41:26 +01:00
|
|
|
* be set to be refreshed.
|
2008-06-09 21:43:09 +02:00
|
|
|
* \param screen Virtual screen number.
|
2008-04-29 09:09:25 +02:00
|
|
|
* \param flags Cache flags to invalidate.
|
2008-03-06 11:41:26 +01:00
|
|
|
*/
|
2008-01-07 18:12:38 +01:00
|
|
|
void
|
2008-06-09 21:43:09 +02:00
|
|
|
widget_invalidate_cache(int screen, int flags)
|
2008-01-07 18:12:38 +01:00
|
|
|
{
|
2008-04-11 11:27:36 +02:00
|
|
|
statusbar_t *statusbar;
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_node_t *widget;
|
2008-01-07 18:12:38 +01:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
for(statusbar = globalconf.screens[screen].statusbar;
|
|
|
|
statusbar;
|
|
|
|
statusbar = statusbar->next)
|
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
|
|
|
if(widget->widget->cache_flags & flags)
|
|
|
|
{
|
|
|
|
statusbar->need_update = true;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-07 18:12:38 +01:00
|
|
|
}
|
|
|
|
|
2008-06-03 18:41:54 +02:00
|
|
|
/** Set a statusbar needs update because it has widget, or redraw a titlebar.
|
|
|
|
* \todo Probably needs more optimization.
|
2008-05-28 09:12:48 +02:00
|
|
|
* \param widget The widget to look for.
|
|
|
|
*/
|
2008-06-25 17:47:51 +02:00
|
|
|
void
|
2008-06-03 18:41:54 +02:00
|
|
|
widget_invalidate_bywidget(widget_t *widget)
|
2007-12-16 10:25:13 +01:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
int screen;
|
2008-04-11 11:27:36 +02:00
|
|
|
statusbar_t *statusbar;
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_node_t *witer;
|
2008-06-04 11:50:21 +02:00
|
|
|
client_t *c;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
|
|
|
for(statusbar = globalconf.screens[screen].statusbar;
|
|
|
|
statusbar;
|
|
|
|
statusbar = statusbar->next)
|
|
|
|
for(witer = statusbar->widgets; witer; witer = witer->next)
|
|
|
|
if(witer->widget == widget)
|
|
|
|
{
|
2008-05-31 16:04:46 +02:00
|
|
|
statusbar->need_update = true;
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2008-06-04 11:50:21 +02:00
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
if(c->titlebar)
|
|
|
|
for(witer = c->titlebar->widgets; witer; witer = witer->next)
|
|
|
|
if(witer->widget == widget)
|
|
|
|
titlebar_draw(c);
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Create a new widget.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-18 20:00:24 +02:00
|
|
|
* \lparam A table with at least a name and a type value. Optional attributes
|
2008-05-28 09:12:48 +02:00
|
|
|
* are: align.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lreturn A brand new widget.
|
2008-05-28 09:12:48 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_new(lua_State *L)
|
|
|
|
{
|
2008-06-30 14:01:55 +02:00
|
|
|
const char *buf, *type;
|
2008-05-25 17:37:00 +02:00
|
|
|
widget_t *w = NULL;
|
2008-05-25 14:07:01 +02:00
|
|
|
widget_constructor_t *wc;
|
2008-05-20 15:39:47 +02:00
|
|
|
alignment_t align;
|
2008-06-23 14:01:33 +02:00
|
|
|
size_t len;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
luaA_checktable(L, 2);
|
2008-06-30 13:50:49 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
buf = luaA_getopt_lstring(L, 2, "align", "left", &len);
|
2008-06-24 22:24:13 +02:00
|
|
|
align = draw_align_fromstr(buf, len);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
if(!(buf = luaA_getopt_string(L, 2, "name", NULL)))
|
2008-06-30 13:50:49 +02:00
|
|
|
luaL_error(L, "object widget must have a name");
|
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
type = luaA_getopt_string(L, 2, "type", NULL);
|
2007-12-17 10:57:17 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
if((wc = name_func_lookup(type, WidgetList)))
|
|
|
|
w = wc(align);
|
|
|
|
else
|
2008-05-25 14:08:46 +02:00
|
|
|
luaL_error(L, "unkown widget type: %s", type);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
w->type = wc;
|
|
|
|
|
2008-05-23 19:29:55 +02:00
|
|
|
/* Set visible by default. */
|
|
|
|
w->isvisible = true;
|
2007-12-17 10:57:17 +01:00
|
|
|
|
2008-06-30 13:50:49 +02:00
|
|
|
w->name = a_strdup(buf);
|
2007-12-16 10:25:13 +01:00
|
|
|
|
2008-06-18 18:31:35 +02:00
|
|
|
return luaA_widget_userdata_new(L, w);
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
2008-04-03 14:00:46 +02:00
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Add a mouse button bindings to a widget.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A widget.
|
2008-06-15 21:04:57 +02:00
|
|
|
* \lparam A mouse button bindings object.
|
2008-05-28 09:12:48 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
2008-06-13 15:35:47 +02:00
|
|
|
luaA_widget_mouse_add(lua_State *L)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
2008-06-13 15:35:47 +02:00
|
|
|
button_t **b = luaA_checkudata(L, 2, "mouse");
|
|
|
|
|
|
|
|
button_list_push(&(*widget)->buttons, *b);
|
|
|
|
button_ref(b);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove a mouse button bindings from a widget.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A widget.
|
2008-06-15 21:04:57 +02:00
|
|
|
* \lparam A mouse button bindings object.
|
2008-06-13 15:35:47 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_widget_mouse_remove(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
|
|
|
button_t **b = luaA_checkudata(L, 2, "mouse");
|
2007-12-22 15:46:57 +01:00
|
|
|
|
2008-06-13 15:35:47 +02:00
|
|
|
button_list_detach(&(*widget)->buttons, *b);
|
|
|
|
button_unref(b);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Convert a widget into a printable string.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A widget.
|
2008-05-28 09:12:48 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_tostring(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
widget_t **p = luaA_checkudata(L, 1, "widget");
|
2008-05-20 15:39:47 +02:00
|
|
|
lua_pushfstring(L, "[widget udata(%p) name(%s)]", *p, (*p)->name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Set the widget name.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A widget.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lparam A string with the new widget name.
|
2008-05-28 09:12:48 +02:00
|
|
|
*/
|
2008-05-23 15:58:12 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_name_set(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
2008-05-23 15:58:12 +02:00
|
|
|
const char *name = luaL_checkstring(L, 2);
|
|
|
|
p_delete(&(*widget)->name);
|
|
|
|
(*widget)->name = a_strdup(name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Get the widget name.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A widget.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lreturn A string with the name of the widget.
|
2008-05-28 09:12:48 +02:00
|
|
|
*/
|
2008-05-23 15:58:12 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_name_get(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
2008-05-23 15:58:12 +02:00
|
|
|
lua_pushstring(L, (*widget)->name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Set the visible attribute of a widget. If a widget is not visible, it is not
|
|
|
|
* drawn on the statusbar.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A widget.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lparam A boolean value.
|
2008-05-28 09:12:48 +02:00
|
|
|
*/
|
2008-05-23 19:29:55 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_visible_set(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
2008-05-23 19:29:55 +02:00
|
|
|
(*widget)->isvisible = luaA_checkboolean(L, 2);
|
2008-06-03 18:41:54 +02:00
|
|
|
widget_invalidate_bywidget(*widget);
|
2008-05-23 19:29:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Get the visible attribute of a widget.
|
2008-06-11 02:46:30 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-06-27 12:43:39 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
2008-06-11 02:46:30 +02:00
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A widget.
|
2008-05-28 09:12:48 +02:00
|
|
|
* \return A boolean value, true if the widget is visible, false otherwise.
|
|
|
|
*/
|
2008-05-23 19:29:55 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_visible_get(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
2008-05-23 19:29:55 +02:00
|
|
|
lua_pushboolean(L, (*widget)->isvisible);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-06-27 12:43:39 +02:00
|
|
|
|
|
|
|
/** Generic widget index.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
2008-06-25 16:37:51 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_index(lua_State *L)
|
|
|
|
{
|
2008-06-25 17:47:51 +02:00
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
2008-06-25 16:37:51 +02:00
|
|
|
|
2008-06-30 14:01:55 +02:00
|
|
|
lua_getmetatable(L, 1);
|
|
|
|
lua_pushvalue(L, 2);
|
|
|
|
lua_rawget(L, -2);
|
|
|
|
if (!lua_isnil(L, -1))
|
|
|
|
{
|
|
|
|
lua_remove(L, -2);
|
2008-06-25 16:37:51 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2008-06-28 01:01:11 +02:00
|
|
|
lua_pop(L, 2);
|
2008-06-30 14:01:55 +02:00
|
|
|
|
2008-06-28 01:01:11 +02:00
|
|
|
return (*widget)->index ? (*widget)->index(L) : 0;
|
2008-06-25 16:37:51 +02:00
|
|
|
}
|
|
|
|
|
2008-06-27 12:43:39 +02:00
|
|
|
/** Generic widget newindex.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_widget_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
|
|
|
|
|
|
|
if((*widget)->newindex)
|
|
|
|
return (*widget)->newindex(L);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
const struct luaL_reg awesome_widget_methods[] =
|
|
|
|
{
|
2008-06-30 14:01:55 +02:00
|
|
|
{ "__call", luaA_widget_new },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct luaL_reg awesome_widget_meta[] =
|
|
|
|
{
|
2008-06-13 15:35:47 +02:00
|
|
|
{ "mouse_add", luaA_widget_mouse_add },
|
|
|
|
{ "mouse_remove", luaA_widget_mouse_remove },
|
2008-05-23 15:58:12 +02:00
|
|
|
{ "name_set", luaA_widget_name_set },
|
|
|
|
{ "name_get", luaA_widget_name_get },
|
2008-05-23 19:29:55 +02:00
|
|
|
{ "visible_set", luaA_widget_visible_set },
|
|
|
|
{ "visible_get", luaA_widget_visible_get },
|
2008-06-25 16:37:51 +02:00
|
|
|
{ "__index", luaA_widget_index },
|
2008-06-27 12:43:39 +02:00
|
|
|
{ "__newindex", luaA_widget_newindex },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "__gc", luaA_widget_gc },
|
|
|
|
{ "__eq", luaA_widget_eq },
|
|
|
|
{ "__tostring", luaA_widget_tostring },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|