2007-12-22 15:46:57 +01:00
|
|
|
/*
|
|
|
|
* widget.c - widget managing
|
|
|
|
*
|
2009-04-17 16:19:55 +02:00
|
|
|
* Copyright © 2007-2009 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
|
|
|
|
2009-04-17 16:14:09 +02:00
|
|
|
#include "screen.h"
|
2008-08-12 13:23:10 +02:00
|
|
|
#include "mouse.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
#include "widget.h"
|
2008-09-21 20:39:23 +02:00
|
|
|
#include "wibox.h"
|
2009-04-17 16:19:55 +02:00
|
|
|
#include "client.h"
|
2009-08-17 16:38:56 +02:00
|
|
|
#include "luaa.h"
|
2008-06-30 18:55:14 +02:00
|
|
|
#include "common/atoms.h"
|
2009-04-17 16:52:25 +02:00
|
|
|
#include "common/xutil.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2009-08-17 15:52:41 +02:00
|
|
|
LUA_OBJECT_FUNCS(widget_class, widget_t, widget);
|
2009-08-17 15:42:02 +02:00
|
|
|
|
2009-04-09 15:12:17 +02:00
|
|
|
/** Collect a widget structure.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return 0
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_widget_gc(lua_State *L)
|
|
|
|
{
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
2009-04-09 15:12:17 +02:00
|
|
|
if(widget->destructor)
|
|
|
|
widget->destructor(widget);
|
2009-08-14 16:46:35 +02:00
|
|
|
button_array_wipe(&widget->buttons);
|
2009-06-16 16:24:58 +02:00
|
|
|
return luaA_object_gc(L);
|
2009-04-09 15:12:17 +02:00
|
|
|
}
|
|
|
|
|
2008-12-03 23:03:44 +01:00
|
|
|
/** Get a widget node from a wibox by coords.
|
2009-05-10 16:17:39 +02:00
|
|
|
* \param orientation Wibox orientation.
|
2008-12-03 23:03:44 +01:00
|
|
|
* \param widgets The widget list.
|
|
|
|
* \param width The container width.
|
|
|
|
* \param height The container height.
|
|
|
|
* \param x X coordinate of the widget.
|
|
|
|
* \param y Y coordinate of the widget.
|
|
|
|
* \return A widget.
|
|
|
|
*/
|
|
|
|
widget_t *
|
2009-05-10 16:17:39 +02:00
|
|
|
widget_getbycoords(orientation_t orientation, widget_node_array_t *widgets,
|
2008-12-03 23:03:44 +01:00
|
|
|
int width, int height, int16_t *x, int16_t *y)
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
/* Need to transform coordinates like it was top/bottom */
|
2009-05-10 16:17:39 +02:00
|
|
|
switch(orientation)
|
2008-12-03 23:03:44 +01:00
|
|
|
{
|
2009-05-10 16:17:39 +02:00
|
|
|
case South:
|
2008-12-03 23:03:44 +01:00
|
|
|
tmp = *y;
|
|
|
|
*y = width - *x;
|
|
|
|
*x = tmp;
|
|
|
|
break;
|
2009-05-10 16:17:39 +02:00
|
|
|
case North:
|
2008-12-03 23:03:44 +01:00
|
|
|
tmp = *y;
|
|
|
|
*y = *x;
|
|
|
|
*x = height - tmp;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-04-09 15:12:17 +02:00
|
|
|
foreach(w, *widgets)
|
|
|
|
if(w->widget->isvisible
|
|
|
|
&& *x >= w->geometry.x && *x < w->geometry.x + w->geometry.width
|
2008-12-03 23:03:44 +01:00
|
|
|
&& *y >= w->geometry.y && *y < w->geometry.y + w->geometry.height)
|
|
|
|
return w->widget;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-08-30 07:26:19 +02:00
|
|
|
/** Convert a Lua table to a list of widget nodes.
|
2008-10-19 19:14:55 +02:00
|
|
|
* \param L The Lua VM state.
|
2010-05-25 15:43:18 +02:00
|
|
|
* \param idx Index of the table where to store the widgets references.
|
2008-10-19 19:14:55 +02:00
|
|
|
* \param widgets The linked list of widget node.
|
|
|
|
*/
|
2009-01-16 11:10:27 +01:00
|
|
|
static void
|
2010-05-25 15:43:18 +02:00
|
|
|
luaA_table2widgets(lua_State *L, int idx, widget_node_array_t *widgets)
|
2008-10-19 19:14:55 +02:00
|
|
|
{
|
|
|
|
if(lua_istable(L, -1))
|
|
|
|
{
|
2010-05-25 15:43:18 +02:00
|
|
|
int table_idx = luaA_absindex(L, idx);
|
2008-10-19 19:14:55 +02:00
|
|
|
lua_pushnil(L);
|
|
|
|
while(luaA_next(L, -2))
|
2010-05-25 15:43:18 +02:00
|
|
|
luaA_table2widgets(L, table_idx, widgets);
|
2009-04-09 15:12:17 +02:00
|
|
|
/* remove the table */
|
|
|
|
lua_pop(L, 1);
|
2008-10-19 19:14:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_toudata(L, -1, &widget_class);
|
2008-10-19 19:14:55 +02:00
|
|
|
if(widget)
|
|
|
|
{
|
2008-10-21 17:21:21 +02:00
|
|
|
widget_node_t w;
|
|
|
|
p_clear(&w, 1);
|
2010-05-25 15:43:18 +02:00
|
|
|
w.widget = luaA_object_ref_item(L, idx, -1);
|
2008-10-21 17:21:21 +02:00
|
|
|
widget_node_array_append(widgets, w);
|
2008-10-19 19:14:55 +02:00
|
|
|
}
|
2009-04-09 15:12:17 +02:00
|
|
|
else
|
|
|
|
lua_pop(L, 1); /* remove value */
|
2008-10-19 19:14:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
/** Retrieve a list of widget geometries using a Lua layout function.
|
2009-08-27 16:44:05 +02:00
|
|
|
* a table which contains the geometries is then pushed onto the stack
|
2009-02-10 17:30:57 +01:00
|
|
|
* \param wibox The wibox.
|
|
|
|
* \return True is everything is ok, false otherwise.
|
|
|
|
*/
|
2009-08-27 16:44:05 +02:00
|
|
|
static bool
|
2009-02-10 17:30:57 +01:00
|
|
|
widget_geometries(wibox_t *wibox)
|
|
|
|
{
|
|
|
|
/* get the layout field of the widget table */
|
2009-07-28 10:29:30 +02:00
|
|
|
if(wibox->widgets_table)
|
2009-02-10 17:30:57 +01:00
|
|
|
{
|
2009-07-28 10:29:30 +02:00
|
|
|
/* push wibox */
|
2009-06-29 11:02:13 +02:00
|
|
|
luaA_object_push(globalconf.L, wibox);
|
2009-07-28 10:29:30 +02:00
|
|
|
/* push widgets table */
|
|
|
|
luaA_object_push_item(globalconf.L, -1, wibox->widgets_table);
|
|
|
|
/* remove wibox */
|
|
|
|
lua_remove(globalconf.L, -2);
|
2009-08-27 17:05:19 +02:00
|
|
|
/* get layout field from the table */
|
2009-02-10 17:30:57 +01:00
|
|
|
lua_getfield(globalconf.L, -1, "layout");
|
2009-08-27 17:05:19 +02:00
|
|
|
/* remove the widget table */
|
|
|
|
lua_remove(globalconf.L, -2);
|
2009-02-10 17:30:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
lua_pushnil(globalconf.L);
|
|
|
|
|
|
|
|
/* if the layout field is a function */
|
|
|
|
if(lua_isfunction(globalconf.L, -1))
|
|
|
|
{
|
|
|
|
/* Push 1st argument: wibox geometry */
|
2009-07-28 16:04:58 +02:00
|
|
|
area_t geometry = wibox->geometry;
|
2009-02-10 17:30:57 +01:00
|
|
|
geometry.x = 0;
|
|
|
|
geometry.y = 0;
|
|
|
|
/* we need to exchange the width and height of the wibox window if it
|
|
|
|
* it is rotated, so the layout function doesn't need to care about that
|
|
|
|
*/
|
2009-07-28 16:04:58 +02:00
|
|
|
if(wibox->orientation != East)
|
2009-02-10 17:30:57 +01:00
|
|
|
{
|
|
|
|
int i = geometry.height;
|
|
|
|
geometry.height = geometry.width;
|
|
|
|
geometry.width = i;
|
|
|
|
}
|
|
|
|
luaA_pusharea(globalconf.L, geometry);
|
2009-08-27 17:05:19 +02:00
|
|
|
/* Push 2nd argument: widget table */
|
|
|
|
luaA_object_push(globalconf.L, wibox);
|
|
|
|
luaA_object_push_item(globalconf.L, -1, wibox->widgets_table);
|
|
|
|
lua_remove(globalconf.L, -2);
|
2009-02-10 17:30:57 +01:00
|
|
|
/* Push 3rd argument: wibox screen */
|
2009-11-09 21:27:00 +01:00
|
|
|
lua_pushnumber(globalconf.L, screen_array_indexof(&globalconf.screens, wibox->screen) + 1);
|
2009-02-10 17:30:57 +01:00
|
|
|
/* Re-push the layout function */
|
|
|
|
lua_pushvalue(globalconf.L, -4);
|
|
|
|
/* call the layout function with 3 arguments (wibox geometry, widget
|
|
|
|
* table, screen) and wait for one result */
|
|
|
|
if(!luaA_dofunction(globalconf.L, 3, 1))
|
|
|
|
return false;
|
|
|
|
|
2009-08-27 17:05:19 +02:00
|
|
|
/* Remove the left over layout function */
|
|
|
|
lua_remove(globalconf.L, -2);
|
2009-02-10 17:30:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-29 09:39:06 +02:00
|
|
|
/* Remove the "nil function" */
|
|
|
|
lua_pop(globalconf.L, 1);
|
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
/* If no layout function has been specified, we just push a table with
|
|
|
|
* geometries onto the stack. These geometries are nothing fancy, they
|
|
|
|
* have x = y = 0 and their height and width set to the widgets demands
|
|
|
|
* or the wibox size, depending on which is less.
|
|
|
|
*/
|
|
|
|
|
2010-05-25 15:43:18 +02:00
|
|
|
/* push wibox */
|
|
|
|
luaA_object_push(globalconf.L, wibox);
|
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
widget_node_array_t *widgets = &wibox->widgets;
|
2010-05-25 15:43:18 +02:00
|
|
|
wibox_widget_node_array_wipe(globalconf.L, -1);
|
2009-02-10 17:30:57 +01:00
|
|
|
widget_node_array_init(widgets);
|
|
|
|
|
2009-07-28 10:29:30 +02:00
|
|
|
/* push widgets table */
|
|
|
|
luaA_object_push_item(globalconf.L, -1, wibox->widgets_table);
|
2010-05-25 15:43:18 +02:00
|
|
|
/* Convert widgets table */
|
|
|
|
luaA_table2widgets(globalconf.L, -2, widgets);
|
2009-07-28 10:29:30 +02:00
|
|
|
/* remove wibox */
|
2010-05-25 15:43:18 +02:00
|
|
|
lua_remove(globalconf.L, -1);
|
2009-02-10 17:30:57 +01:00
|
|
|
|
|
|
|
lua_newtable(globalconf.L);
|
|
|
|
for(int i = 0; i < widgets->len; i++)
|
|
|
|
{
|
|
|
|
lua_pushnumber(globalconf.L, i + 1);
|
|
|
|
widget_t *widget = widgets->tab[i].widget;
|
2009-11-09 21:27:00 +01:00
|
|
|
lua_pushnumber(globalconf.L, screen_array_indexof(&globalconf.screens, wibox->screen) + 1);
|
2009-02-10 17:30:57 +01:00
|
|
|
area_t geometry = widget->extents(globalconf.L, widget);
|
|
|
|
lua_pop(globalconf.L, 1);
|
|
|
|
geometry.x = geometry.y = 0;
|
2009-07-28 16:04:58 +02:00
|
|
|
geometry.width = MIN(wibox->geometry.width, geometry.width);
|
|
|
|
geometry.height = MIN(wibox->geometry.height, geometry.height);
|
2009-02-10 17:30:57 +01:00
|
|
|
|
|
|
|
luaA_pusharea(globalconf.L, geometry);
|
|
|
|
|
|
|
|
lua_settable(globalconf.L, -3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-03 16:32:23 +02:00
|
|
|
/** Render a list of widgets.
|
2008-10-19 19:14:55 +02:00
|
|
|
* \param wibox The wibox.
|
2008-06-03 18:41:54 +02:00
|
|
|
* \todo Remove GC.
|
2008-06-03 16:32:23 +02:00
|
|
|
*/
|
|
|
|
void
|
2009-01-16 10:31:13 +01:00
|
|
|
widget_render(wibox_t *wibox)
|
2008-06-03 16:32:23 +02:00
|
|
|
{
|
2009-02-10 17:30:57 +01:00
|
|
|
lua_State *L = globalconf.L;
|
2009-07-28 16:04:58 +02:00
|
|
|
draw_context_t *ctx = &wibox->ctx;
|
2008-06-22 22:09:48 +02:00
|
|
|
area_t rectangle = { 0, 0, 0, 0 };
|
2009-04-17 18:40:43 +02:00
|
|
|
color_t col;
|
2008-06-03 16:32:23 +02:00
|
|
|
|
|
|
|
rectangle.width = ctx->width;
|
|
|
|
rectangle.height = ctx->height;
|
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
if (!widget_geometries(wibox))
|
|
|
|
return;
|
|
|
|
|
2008-06-03 16:32:23 +02:00
|
|
|
if(ctx->bg.alpha != 0xffff)
|
|
|
|
{
|
2009-10-09 16:13:01 +02:00
|
|
|
int x = wibox->geometry.x + wibox->border_width,
|
|
|
|
y = wibox->geometry.y + wibox->border_width;
|
2008-10-22 17:32:17 +02:00
|
|
|
xcb_get_property_reply_t *prop_r;
|
|
|
|
char *data;
|
|
|
|
xcb_pixmap_t rootpix;
|
|
|
|
xcb_get_property_cookie_t prop_c;
|
|
|
|
xcb_screen_t *s = xutil_screen_get(globalconf.connection, ctx->phys_screen);
|
2008-06-30 18:55:14 +02:00
|
|
|
prop_c = xcb_get_property_unchecked(globalconf.connection, false, s->root, _XROOTPMAP_ID,
|
2010-08-08 18:31:07 +02:00
|
|
|
XCB_ATOM_PIXMAP, 0, 1);
|
2008-06-03 16:32:23 +02:00
|
|
|
if((prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL)))
|
|
|
|
{
|
2008-08-05 11:26:06 +02:00
|
|
|
if(prop_r->value_len
|
|
|
|
&& (data = xcb_get_property_value(prop_r))
|
2008-06-15 16:14:39 +02:00
|
|
|
&& (rootpix = *(xcb_pixmap_t *) data))
|
2009-07-28 16:04:58 +02:00
|
|
|
switch(wibox->orientation)
|
2008-06-03 16:32:23 +02:00
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
case North:
|
2008-06-03 16:32:23 +02:00
|
|
|
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;
|
2008-09-24 12:13:21 +02:00
|
|
|
case South:
|
2008-06-03 16:32:23 +02:00
|
|
|
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;
|
2008-09-24 12:13:21 +02:00
|
|
|
case East:
|
2008-06-03 18:41:54 +02:00
|
|
|
xcb_copy_area(globalconf.connection, rootpix,
|
2009-07-28 16:04:58 +02:00
|
|
|
wibox->pixmap, wibox->gc,
|
2008-06-03 18:41:54 +02:00
|
|
|
x, y,
|
2008-08-21 15:08:56 +02:00
|
|
|
0, 0,
|
2008-06-03 18:41:54 +02:00
|
|
|
ctx->width, ctx->height);
|
2008-06-03 16:32:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
p_delete(&prop_r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-16 10:31:13 +01:00
|
|
|
widget_node_array_t *widgets = &wibox->widgets;
|
|
|
|
|
2009-07-28 10:29:30 +02:00
|
|
|
/* push wibox */
|
2009-06-29 11:02:13 +02:00
|
|
|
luaA_object_push(globalconf.L, wibox);
|
2010-05-25 15:43:18 +02:00
|
|
|
|
|
|
|
wibox_widget_node_array_wipe(globalconf.L, -1);
|
|
|
|
widget_node_array_init(widgets);
|
|
|
|
|
2009-07-28 10:29:30 +02:00
|
|
|
/* push widgets table */
|
|
|
|
luaA_object_push_item(globalconf.L, -1, wibox->widgets_table);
|
2010-05-25 15:43:18 +02:00
|
|
|
luaA_table2widgets(L, -2, widgets);
|
2009-07-28 10:29:30 +02:00
|
|
|
/* remove wibox */
|
2010-05-25 15:43:18 +02:00
|
|
|
lua_remove(globalconf.L, -1);
|
2009-01-16 11:10:27 +01:00
|
|
|
|
2010-09-17 16:08:06 +02:00
|
|
|
size_t num_widgets = lua_objlen(L, -1);
|
|
|
|
if(lua_objlen(L, -1) != (size_t) widgets->len)
|
|
|
|
{
|
|
|
|
warn("Widget layout returned wrong number of geometries. Got %d widgets and %lu geometries.",
|
|
|
|
widgets->len, (unsigned long) lua_objlen(L, -1));
|
|
|
|
/* Set num_widgets to min(widgets->len, lua_objlen(L, -1)); */
|
|
|
|
if(num_widgets > (size_t) widgets->len)
|
|
|
|
num_widgets = widgets->len;
|
|
|
|
}
|
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
/* get computed geometries */
|
2010-09-17 16:08:06 +02:00
|
|
|
for(size_t i = 0; i < num_widgets; i++)
|
2009-02-10 17:30:57 +01:00
|
|
|
{
|
|
|
|
lua_pushnumber(L, i + 1);
|
|
|
|
lua_gettable(L, -2);
|
2008-06-03 16:32:23 +02:00
|
|
|
|
2009-07-28 16:04:58 +02:00
|
|
|
widgets->tab[i].geometry.x = luaA_getopt_number(L, -1, "x", wibox->geometry.x);
|
|
|
|
widgets->tab[i].geometry.y = luaA_getopt_number(L, -1, "y", wibox->geometry.y);
|
2009-02-10 17:30:57 +01:00
|
|
|
widgets->tab[i].geometry.width = luaA_getopt_number(L, -1, "width", 1);
|
|
|
|
widgets->tab[i].geometry.height = luaA_getopt_number(L, -1, "height", 1);
|
2008-10-23 17:28:07 +02:00
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
lua_pop(L, 1);
|
2008-06-03 16:32:23 +02:00
|
|
|
|
2009-03-03 10:22:39 +01:00
|
|
|
/* draw background image, only if the background color is not opaque */
|
|
|
|
if(wibox->bg_image && ctx->bg.alpha != 0xffff)
|
|
|
|
draw_image(ctx, 0, 0, 1.0, wibox->bg_image);
|
|
|
|
|
|
|
|
/* draw background color */
|
2009-04-17 18:40:43 +02:00
|
|
|
xcolor_to_color(&ctx->bg, &col);
|
|
|
|
draw_rectangle(ctx, rectangle, 1.0, true, &col);
|
2008-10-22 17:32:17 +02:00
|
|
|
|
2009-03-03 10:22:39 +01:00
|
|
|
/* draw everything! */
|
2008-10-22 17:32:17 +02:00
|
|
|
for(int i = 0; i < widgets->len; i++)
|
|
|
|
if(widgets->tab[i].widget->isvisible)
|
|
|
|
widgets->tab[i].widget->draw(widgets->tab[i].widget,
|
2009-04-17 16:14:09 +02:00
|
|
|
ctx, widgets->tab[i].geometry, wibox);
|
2008-10-22 17:32:17 +02:00
|
|
|
|
2010-10-05 19:46:42 +02:00
|
|
|
cairo_surface_flush(ctx->surface);
|
|
|
|
|
2009-07-28 16:04:58 +02:00
|
|
|
switch(wibox->orientation)
|
2008-06-03 16:32:23 +02:00
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
case South:
|
2009-07-28 16:04:58 +02:00
|
|
|
draw_rotate(ctx, ctx->pixmap, wibox->pixmap,
|
2008-06-03 16:32:23 +02:00
|
|
|
ctx->width, ctx->height,
|
|
|
|
ctx->height, ctx->width,
|
|
|
|
M_PI_2, ctx->height, 0);
|
|
|
|
break;
|
2008-09-24 12:13:21 +02:00
|
|
|
case North:
|
2009-07-28 16:04:58 +02:00
|
|
|
draw_rotate(ctx, ctx->pixmap, wibox->pixmap,
|
2008-06-03 16:32:23 +02:00
|
|
|
ctx->width, ctx->height,
|
|
|
|
ctx->height, ctx->width,
|
|
|
|
- M_PI_2, 0, ctx->width);
|
|
|
|
break;
|
2008-09-24 12:13:21 +02:00
|
|
|
case East:
|
2008-06-03 16:32:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-12 13:45:08 +01:00
|
|
|
/** Invalidate widgets which should be refresh depending on their types.
|
|
|
|
* \param type Widget type to invalidate.
|
2008-03-06 11:41:26 +01:00
|
|
|
*/
|
2008-01-07 18:12:38 +01:00
|
|
|
void
|
2009-05-10 14:55:13 +02:00
|
|
|
widget_invalidate_bytype(widget_constructor_t *type)
|
2008-01-07 18:12:38 +01:00
|
|
|
{
|
2009-05-10 14:55:13 +02:00
|
|
|
foreach(wibox, globalconf.wiboxes)
|
2009-04-11 00:27:06 +02:00
|
|
|
foreach(wnode, (*wibox)->widgets)
|
|
|
|
if(wnode->widget->type == type)
|
2008-06-09 21:43:09 +02:00
|
|
|
{
|
2009-04-11 00:27:06 +02:00
|
|
|
(*wibox)->need_update = true;
|
2008-06-09 21:43:09 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-01-07 18:12:38 +01:00
|
|
|
}
|
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
/** Set a wibox needs update because it has widget, or redraw a titlebar.
|
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
|
|
|
{
|
2009-05-10 14:55:13 +02:00
|
|
|
foreach(wibox, globalconf.wiboxes)
|
|
|
|
if(!(*wibox)->need_update)
|
|
|
|
foreach(wnode, (*wibox)->widgets)
|
|
|
|
if(wnode->widget == widget)
|
|
|
|
{
|
|
|
|
(*wibox)->need_update = true;
|
|
|
|
break;
|
|
|
|
}
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2009-04-09 17:17:10 +02:00
|
|
|
foreach(_c, globalconf.clients)
|
|
|
|
{
|
|
|
|
client_t *c = *_c;
|
2008-08-06 14:24:54 +02:00
|
|
|
if(c->titlebar && !c->titlebar->need_update)
|
2008-10-21 17:21:21 +02:00
|
|
|
for(int j = 0; j < c->titlebar->widgets.len; j++)
|
|
|
|
if(c->titlebar->widgets.tab[j].widget == widget)
|
2008-10-19 19:14:55 +02:00
|
|
|
{
|
2008-07-31 14:10:54 +02:00
|
|
|
c->titlebar->need_update = true;
|
2008-10-19 19:14:55 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-04-09 17:17:10 +02:00
|
|
|
}
|
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
|
2009-03-20 21:15:38 +01:00
|
|
|
* \lparam A table with at least a type value.
|
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)
|
|
|
|
{
|
2009-08-17 15:42:02 +02:00
|
|
|
luaA_class_new(L, &widget_class);
|
2008-11-12 15:07:24 +01:00
|
|
|
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *w = luaA_checkudata(L, -1, &widget_class);
|
2008-05-23 19:29:55 +02:00
|
|
|
/* Set visible by default. */
|
|
|
|
w->isvisible = true;
|
2007-12-17 10:57:17 +01:00
|
|
|
|
2009-04-09 15:12:17 +02:00
|
|
|
return 1;
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
2008-04-03 14:00:46 +02:00
|
|
|
|
2009-08-14 16:46:35 +02:00
|
|
|
/** 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)
|
|
|
|
{
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
2009-08-14 16:46:35 +02:00
|
|
|
|
|
|
|
if(lua_gettop(L) == 2)
|
|
|
|
{
|
|
|
|
luaA_button_array_set(L, 1, 2, &widget->buttons);
|
2009-08-17 15:42:02 +02:00
|
|
|
luaA_object_emit_signal(L, 1, "property::buttons", 0);
|
2009-08-14 16:46:35 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return luaA_button_array_get(L, 1, &widget->buttons);
|
|
|
|
}
|
|
|
|
|
2008-07-28 16:03:38 +02:00
|
|
|
/** Generic widget.
|
2008-06-27 12:43:39 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
2008-07-02 10:34:14 +02:00
|
|
|
* \luastack
|
|
|
|
* \lfield visible The widget visibility.
|
2008-08-25 14:34:56 +02:00
|
|
|
* \lfield mouse_enter A function to execute when the mouse enter the widget.
|
|
|
|
* \lfield mouse_leave A function to execute when the mouse leave the widget.
|
2008-06-27 12:43:39 +02:00
|
|
|
*/
|
2008-06-25 16:37:51 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_index(lua_State *L)
|
|
|
|
{
|
2008-07-01 15:20:42 +02:00
|
|
|
size_t len;
|
2009-08-17 15:42:02 +02:00
|
|
|
const char *prop = luaL_checklstring(L, 2, &len);
|
|
|
|
awesome_token_t token = a_tokenize(prop, len);
|
2008-06-25 16:37:51 +02:00
|
|
|
|
2009-08-17 15:42:02 +02:00
|
|
|
/* Try standard method */
|
|
|
|
if(luaA_class_index(L))
|
2008-06-25 16:37:51 +02:00
|
|
|
return 1;
|
2008-06-30 14:01:55 +02:00
|
|
|
|
2009-08-17 15:42:02 +02:00
|
|
|
/* Then call special widget index */
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
2009-04-09 15:12:17 +02:00
|
|
|
return widget->index ? widget->index(L, token) : 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)
|
|
|
|
{
|
2008-07-01 15:20:42 +02:00
|
|
|
size_t len;
|
2009-08-17 15:42:02 +02:00
|
|
|
const char *prop = luaL_checklstring(L, 2, &len);
|
|
|
|
awesome_token_t token = a_tokenize(prop, len);
|
2008-06-27 12:43:39 +02:00
|
|
|
|
2009-08-17 15:42:02 +02:00
|
|
|
/* Try standard method */
|
|
|
|
luaA_class_newindex(L);
|
2008-08-21 15:08:56 +02:00
|
|
|
|
2009-08-17 15:42:02 +02:00
|
|
|
/* Then call special widget newindex */
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
2009-08-17 15:42:02 +02:00
|
|
|
return widget->newindex ? widget->newindex(L, token) : 0;
|
2008-06-27 12:43:39 +02:00
|
|
|
}
|
|
|
|
|
2009-05-05 19:55:29 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_extents(lua_State *L)
|
|
|
|
{
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
2009-05-05 19:55:29 +02:00
|
|
|
area_t g = {
|
|
|
|
.x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.width = 0,
|
|
|
|
.height = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
if(widget->extents)
|
|
|
|
g = widget->extents(L, widget);
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushnumber(L, g.width);
|
|
|
|
lua_setfield(L, -2, "width");
|
|
|
|
lua_pushnumber(L, g.height);
|
|
|
|
lua_setfield(L, -2, "height");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-08-17 15:42:02 +02:00
|
|
|
static int
|
|
|
|
luaA_widget_set_type(lua_State *L, widget_t *w)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2009-08-17 15:42:02 +02:00
|
|
|
size_t len;
|
|
|
|
const char *type = luaL_checklstring(L, -1, &len);
|
|
|
|
widget_constructor_t *wc = NULL;
|
|
|
|
|
|
|
|
switch(a_tokenize(type, len))
|
|
|
|
{
|
|
|
|
case A_TK_TEXTBOX:
|
|
|
|
wc = widget_textbox;
|
|
|
|
break;
|
|
|
|
case A_TK_PROGRESSBAR:
|
|
|
|
wc = widget_progressbar;
|
|
|
|
break;
|
|
|
|
case A_TK_GRAPH:
|
|
|
|
wc = widget_graph;
|
|
|
|
break;
|
|
|
|
case A_TK_SYSTRAY:
|
|
|
|
wc = widget_systray;
|
|
|
|
break;
|
|
|
|
case A_TK_IMAGEBOX:
|
|
|
|
wc = widget_imagebox;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!wc)
|
2009-08-30 07:26:19 +02:00
|
|
|
luaL_error(L, "unknown widget type: %s", type);
|
2009-08-17 15:42:02 +02:00
|
|
|
|
|
|
|
wc(w);
|
|
|
|
w->type = wc;
|
|
|
|
luaA_object_emit_signal(L, -3, "property::type", 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
luaA_widget_get_visible(lua_State *L, widget_t *w)
|
|
|
|
{
|
|
|
|
lua_pushboolean(L, w->isvisible);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
luaA_widget_set_visible(lua_State *L, widget_t *w)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2009-08-17 15:42:02 +02:00
|
|
|
w->isvisible = luaA_checkboolean(L, -1);
|
|
|
|
widget_invalidate_bywidget(w);
|
|
|
|
luaA_object_emit_signal(L, -3, "property::visible", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_class_setup(lua_State *L)
|
|
|
|
{
|
|
|
|
static const struct luaL_reg widget_methods[] =
|
|
|
|
{
|
|
|
|
LUA_CLASS_METHODS(widget)
|
|
|
|
{ "__call", luaA_widget_new },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct luaL_reg widget_meta[] =
|
|
|
|
{
|
|
|
|
LUA_OBJECT_META(widget)
|
|
|
|
{ "buttons", luaA_widget_buttons },
|
|
|
|
{ "extents", luaA_widget_extents },
|
|
|
|
{ "__index", luaA_widget_index },
|
|
|
|
{ "__newindex", luaA_widget_newindex },
|
|
|
|
{ "__gc", luaA_widget_gc },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
luaA_class_setup(L, &widget_class, "widget", (lua_class_allocator_t) widget_new,
|
2009-08-20 17:37:46 +02:00
|
|
|
NULL, NULL,
|
2009-08-17 15:42:02 +02:00
|
|
|
widget_methods, widget_meta);
|
|
|
|
luaA_class_add_property(&widget_class, A_TK_VISIBLE,
|
|
|
|
(lua_class_propfunc_t) luaA_widget_set_visible,
|
|
|
|
(lua_class_propfunc_t) luaA_widget_get_visible,
|
|
|
|
(lua_class_propfunc_t) luaA_widget_set_visible);
|
|
|
|
luaA_class_add_property(&widget_class, A_TK_TYPE,
|
|
|
|
(lua_class_propfunc_t) luaA_widget_set_type,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|