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
|
|
|
* Copyright © 2007 Aldo Cortesi <aldo@nullcube.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-12-15 07:53:53 +01:00
|
|
|
#include "widget.h"
|
2007-12-17 10:57:17 +01:00
|
|
|
#include "statusbar.h"
|
2007-12-27 15:49:00 +01:00
|
|
|
#include "event.h"
|
2008-05-20 15:39:47 +02:00
|
|
|
#include "lua.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-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-04-29 09:09:25 +02:00
|
|
|
/** Find a widget on a screen by its name.
|
|
|
|
* \param name The widget name.
|
|
|
|
* \return A widget pointer.
|
2008-03-06 11:41:26 +01:00
|
|
|
*/
|
2008-04-30 18:44:23 +02:00
|
|
|
widget_t *
|
2008-05-20 20:13:44 +02:00
|
|
|
widget_getbyname(const char *name)
|
2007-12-16 10:25:13 +01:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_node_t *widget;
|
2008-05-20 20:13:44 +02:00
|
|
|
statusbar_t *sb;
|
|
|
|
int screen;
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-05-20 20:13:44 +02:00
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
|
|
|
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
|
|
|
for(widget = sb->widgets; widget; widget = widget->next)
|
|
|
|
if(!a_strcmp(name, widget->widget->name))
|
|
|
|
return widget->widget;
|
2007-12-30 21:00:34 +01:00
|
|
|
|
2007-12-16 10:25:13 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
* \param statusbar The statusbar.
|
2008-04-29 09:09:25 +02:00
|
|
|
* \param ev The button press event the widget received.
|
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,
|
|
|
|
statusbar_t *statusbar __attribute__ ((unused)),
|
|
|
|
xcb_button_press_event_t *ev)
|
2007-12-27 15:49:00 +01:00
|
|
|
{
|
2008-05-23 13:35:46 +02:00
|
|
|
button_t *b;
|
2007-12-27 15:49:00 +01: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)
|
|
|
|
luaA_dofunction(globalconf.L, b->fct, 0);
|
2007-12-27 15:49:00 +01:00
|
|
|
}
|
|
|
|
|
2008-03-06 11:41:26 +01:00
|
|
|
/** Common tell function for widget, which only warn user that widget
|
2008-04-29 09:09:25 +02:00
|
|
|
* cannot be told anything.
|
|
|
|
* \param widget The widget.
|
|
|
|
* \param new_value Unused argument.
|
|
|
|
* \return The status of the command, which is always an error in this case.
|
2008-03-06 11:41:26 +01:00
|
|
|
*/
|
2008-03-04 19:06:04 +01:00
|
|
|
static widget_tell_status_t
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_common_tell(widget_t *widget,
|
|
|
|
const char *property __attribute__ ((unused)),
|
|
|
|
const char *new_value __attribute__ ((unused)))
|
2007-12-17 10:57:17 +01:00
|
|
|
{
|
2008-05-23 22:53:59 +02:00
|
|
|
warn("%s widget does not accept commands.", widget->name);
|
2008-03-04 19:06:04 +01:00
|
|
|
return WIDGET_ERROR_CUSTOM;
|
2007-12-17 10:57:17 +01:00
|
|
|
}
|
|
|
|
|
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-22 20:55:17 +01:00
|
|
|
widget->tell = widget_common_tell;
|
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-04-29 09:09:25 +02:00
|
|
|
* \param screen Virtual screen number.
|
|
|
|
* \param flags Cache flags to invalidate.
|
2008-03-06 11:41:26 +01:00
|
|
|
*/
|
2008-01-07 18:12:38 +01:00
|
|
|
void
|
|
|
|
widget_invalidate_cache(int screen, int flags)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
for(statusbar = globalconf.screens[screen].statusbar;
|
|
|
|
statusbar;
|
|
|
|
statusbar = statusbar->next)
|
|
|
|
for(widget = statusbar->widgets; widget; widget = widget->next)
|
2008-05-20 15:39:47 +02:00
|
|
|
if(widget->widget->cache_flags & flags)
|
|
|
|
{
|
2008-05-31 16:04:46 +02:00
|
|
|
statusbar->need_update = true;
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-01-07 18:12:38 +01:00
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Set a statusbar needs update because it has widget.
|
|
|
|
* \param widget The widget to look for.
|
|
|
|
*/
|
2007-12-16 10:25:13 +01:00
|
|
|
void
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_invalidate_statusbar_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;
|
|
|
|
|
|
|
|
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-05-28 09:12:48 +02:00
|
|
|
/** Create a new widget userdata. The object is pushed on the stack.
|
|
|
|
* \param widget The widget.
|
|
|
|
* \return Return luaA_settype() return value.
|
|
|
|
*/
|
2008-05-24 19:58:25 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_userdata_new(widget_t *widget)
|
|
|
|
{
|
|
|
|
widget_t **w;
|
|
|
|
w = lua_newuserdata(globalconf.L, sizeof(widget_t *));
|
|
|
|
*w = widget;
|
|
|
|
widget_ref(w);
|
|
|
|
return luaA_settype(globalconf.L, "widget");
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Create a new widget.
|
|
|
|
* \param A table with at least a name and a type value. Optionnal attributes
|
|
|
|
* are: align.
|
|
|
|
* \return A brand new widget.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_new(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *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;
|
|
|
|
|
|
|
|
luaA_checktable(L, 1);
|
|
|
|
align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
|
|
|
|
|
|
|
type = luaA_getopt_string(L, 1, "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-05-23 19:29:55 +02:00
|
|
|
/* Set visible by default. */
|
|
|
|
w->isvisible = true;
|
2007-12-17 10:57:17 +01:00
|
|
|
|
2008-05-24 19:58:25 +02:00
|
|
|
w->name = luaA_name_init(L);
|
2007-12-16 10:25:13 +01:00
|
|
|
|
2008-05-24 19:58:25 +02:00
|
|
|
return luaA_widget_userdata_new(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.
|
|
|
|
* \param A table containing modifiers keys.
|
|
|
|
* \param A button number.
|
|
|
|
* \param A function to execute. Some widgets may passe arguments to this
|
|
|
|
* function.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_mouse(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t i, len;
|
|
|
|
/* arg 1 is object */
|
|
|
|
widget_t **widget = luaL_checkudata(L, 1, "widget");
|
|
|
|
int b;
|
2008-05-23 13:35:46 +02:00
|
|
|
button_t *button;
|
2008-04-03 14:00:46 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/* arg 2 is modkey table */
|
|
|
|
luaA_checktable(L, 2);
|
|
|
|
/* arg 3 is mouse button */
|
|
|
|
b = luaL_checknumber(L, 3);
|
|
|
|
/* arg 4 is cmd to run */
|
|
|
|
luaA_checkfunction(L, 4);
|
2008-02-17 08:16:40 +01:00
|
|
|
|
2008-05-23 13:35:46 +02:00
|
|
|
button = p_new(button_t, 1);
|
2008-05-20 15:39:47 +02:00
|
|
|
button->button = xutil_button_fromint(b);
|
|
|
|
button->fct = luaL_ref(L, LUA_REGISTRYINDEX);
|
2008-02-17 08:16:40 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
len = lua_objlen(L, 2);
|
|
|
|
for(i = 1; i <= len; i++)
|
2007-12-17 10:57:17 +01:00
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
lua_rawgeti(L, 2, i);
|
|
|
|
button->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1));
|
2007-12-17 10:57:17 +01:00
|
|
|
}
|
2007-12-22 15:46:57 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
button_list_push(&(*widget)->buttons, button);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Do what should be done with a widget_tell_status_t for a widget.
|
|
|
|
* \param widget The widget.
|
|
|
|
* \param status The status returned by the tell function of the widget.
|
|
|
|
* \para property The property updated.
|
|
|
|
*/
|
2008-05-20 20:25:49 +02:00
|
|
|
void
|
|
|
|
widget_tell_managestatus(widget_t *widget, widget_tell_status_t status, const char *property)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-05-20 20:25:49 +02:00
|
|
|
switch(status)
|
2008-04-02 15:31:19 +02:00
|
|
|
{
|
|
|
|
case WIDGET_ERROR:
|
2008-05-23 22:53:59 +02:00
|
|
|
warn("error changing property %s of widget %s",
|
2008-05-20 20:25:49 +02:00
|
|
|
property, widget->name);
|
2008-04-02 15:31:19 +02:00
|
|
|
break;
|
|
|
|
case WIDGET_ERROR_NOVALUE:
|
2008-05-23 22:53:59 +02:00
|
|
|
warn("error changing property %s of widget %s, no value given",
|
2008-05-20 20:25:49 +02:00
|
|
|
property, widget->name);
|
2008-04-02 15:31:19 +02:00
|
|
|
break;
|
|
|
|
case WIDGET_ERROR_FORMAT_FONT:
|
2008-05-23 22:53:59 +02:00
|
|
|
warn("error changing property %s of widget %s, must be a valid font",
|
2008-05-20 20:25:49 +02:00
|
|
|
property, widget->name);
|
2008-04-02 15:31:19 +02:00
|
|
|
break;
|
|
|
|
case WIDGET_ERROR_FORMAT_COLOR:
|
2008-05-23 22:53:59 +02:00
|
|
|
warn("error changing property %s of widget %s, must be a valid color",
|
2008-05-20 20:25:49 +02:00
|
|
|
property, widget->name);
|
2008-04-02 15:31:19 +02:00
|
|
|
break;
|
|
|
|
case WIDGET_ERROR_FORMAT_SECTION:
|
2008-05-23 22:53:59 +02:00
|
|
|
warn("error changing property %s of widget %s, section/title not found",
|
2008-05-20 20:25:49 +02:00
|
|
|
property, widget->name);
|
2008-04-02 15:31:19 +02:00
|
|
|
break;
|
|
|
|
case WIDGET_NOERROR:
|
2008-05-20 20:25:49 +02:00
|
|
|
widget_invalidate_statusbar_bywidget(widget);
|
2008-05-20 15:39:47 +02:00
|
|
|
break;
|
2008-04-02 15:31:19 +02:00
|
|
|
case WIDGET_ERROR_CUSTOM:
|
|
|
|
break;
|
|
|
|
}
|
2008-05-20 20:25:49 +02:00
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Set a widget property. Each widget type has its own set of property.
|
|
|
|
* \param The property name.
|
|
|
|
* \param The property value.
|
|
|
|
*/
|
2008-05-20 20:25:49 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_set(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaL_checkudata(L, 1, "widget");
|
|
|
|
const char *property, *value;
|
|
|
|
widget_tell_status_t status;
|
|
|
|
|
|
|
|
property = luaL_checkstring(L, 2);
|
|
|
|
value = luaL_checkstring(L, 3);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-05-20 20:25:49 +02:00
|
|
|
status = (*widget)->tell(*widget, property, value);
|
|
|
|
widget_tell_managestatus(*widget, status, property);
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
2007-12-16 10:25:13 +01:00
|
|
|
}
|
2007-12-16 09:34:33 +01:00
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Handle widget garbage collection.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_gc(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaL_checkudata(L, 1, "widget");
|
|
|
|
widget_unref(widget);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Convert a widget into a printable string.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_tostring(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **p = luaL_checkudata(L, 1, "widget");
|
|
|
|
lua_pushfstring(L, "[widget udata(%p) name(%s)]", *p, (*p)->name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Check for widget equality.
|
|
|
|
* \param Another widget.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_eq(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **t1 = luaL_checkudata(L, 1, "widget");
|
|
|
|
widget_t **t2 = luaL_checkudata(L, 2, "widget");
|
|
|
|
lua_pushboolean(L, (*t1 == *t2));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Get all widget from all statusbars.
|
|
|
|
* \return A table with all widgets from all statusbars.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_get(lua_State *L)
|
|
|
|
{
|
|
|
|
statusbar_t *sb;
|
|
|
|
widget_node_t *widget;
|
2008-05-23 13:17:02 +02:00
|
|
|
int i = 1, screen;
|
2008-05-20 15:39:47 +02:00
|
|
|
bool add = true;
|
|
|
|
widget_node_t *wlist = NULL, *witer;
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
|
|
|
for(sb = globalconf.screens[screen].statusbar; sb; sb = sb->next)
|
|
|
|
for(widget = sb->widgets; widget; widget = widget->next)
|
2008-05-23 13:17:02 +02:00
|
|
|
{
|
|
|
|
for(witer = wlist; witer; witer = witer->next)
|
|
|
|
if(witer->widget == widget->widget)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-05-23 13:17:02 +02:00
|
|
|
add = false;
|
|
|
|
break;
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
2008-05-23 13:17:02 +02:00
|
|
|
if(add)
|
|
|
|
{
|
|
|
|
witer = p_new(widget_node_t, 1);
|
|
|
|
widget_node_list_push(&wlist, witer);
|
2008-05-24 19:58:25 +02:00
|
|
|
luaA_widget_userdata_new(witer->widget);
|
2008-05-23 13:17:02 +02:00
|
|
|
/* ref again for the list */
|
|
|
|
widget_ref(&widget->widget);
|
|
|
|
lua_rawseti(L, -2, i++);
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
2008-05-23 13:17:02 +02:00
|
|
|
add = true;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
widget_node_list_wipe(&wlist);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Set the widget name.
|
|
|
|
* \param A string with the new widget name.
|
|
|
|
*/
|
2008-05-23 15:58:12 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_name_set(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaL_checkudata(L, 1, "widget");
|
|
|
|
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.
|
|
|
|
* \return A string with the name of the widget.
|
|
|
|
*/
|
2008-05-23 15:58:12 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_name_get(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaL_checkudata(L, 1, "widget");
|
|
|
|
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.
|
|
|
|
* \param A boolean value.
|
|
|
|
*/
|
2008-05-23 19:29:55 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_visible_set(lua_State *L)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaL_checkudata(L, 1, "widget");
|
|
|
|
(*widget)->isvisible = luaA_checkboolean(L, 2);
|
|
|
|
widget_invalidate_statusbar_bywidget(*widget);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-28 09:12:48 +02:00
|
|
|
/** Get the visible attribute of a widget.
|
|
|
|
* \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)
|
|
|
|
{
|
|
|
|
widget_t **widget = luaL_checkudata(L, 1, "widget");
|
|
|
|
lua_pushboolean(L, (*widget)->isvisible);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
const struct luaL_reg awesome_widget_methods[] =
|
|
|
|
{
|
|
|
|
{ "new", luaA_widget_new },
|
|
|
|
{ "get", luaA_widget_get },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct luaL_reg awesome_widget_meta[] =
|
|
|
|
{
|
|
|
|
{ "mouse", luaA_widget_mouse },
|
|
|
|
{ "set", luaA_widget_set },
|
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-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
|