Hi people,
I finally found some time to hack around awesome again, so here i present a
backport of :extents() from the widget-layouts branch to the master branch and
a little addition to naughty which makes it behave much more friendly to screen
space by automagically resizing naughtyfications so they take exactly as much
space as they need.
The first patch export a function called :extents() for each widget which takes
a screen number as its argument. This is only used for systrays to correctly
calculate their geometries, for all other widgets it is ignored. If it's
omitted for a systray, 1 is assumed. It returns the geometry the widget wants
to be drawn at, which doesn't take later resizing into account (i.e. if you
have a square 64x64 imagebox with resize enabled on a wibox with 16 px
height, :extents().height will still be 64 although the widget is actually
drawn 16 pixels high).
The second patch adds support for resizing to naughty. See the commit message
for additional details on how it works.
--
GCS/IT/M d- s+:- a--- C++ UL+++ US UB++ P+++ L+++ E--- W+ N+ o--
K- w--- O M-- V PS+ PE- Y+ PGP+++ t+ 5 X+ R tv+ b++ DI+++ D+++ G+
e- h! r y+
Gregor Best
From b3d219ee638f76f9ecd97b0eeb0cace437c0cf64 Mon Sep 17 00:00:00 2001
From: Gregor Best farha...@googlemail.com
Date: Tue, 5 May 2009 19:55:29 +0200
Subject: [PATCH 1/2] widgets: export extents() function
This commit adds a function called extents() to widgets. In the case of
a systray, it takes the systray's screen as its argument to correctly
calculate the width. By default, 1 is assumed. For all other widgets,
the argument can be ommitted.
The function doesn't return the geometry as drawn, instead it returns
the geometry the widget _wants_ to be drawn at, for example an imagebox
always has (image width, image height) as the return values even if it's
drawn with a smaller width and height on a smaller wibox.
Signed-off-by: Gregor Best farha...@googlemail.com
---
widget.c | 24
widget.h |4 +++-
widgets/graph.c | 11 +++
widgets/imagebox.c| 21 +
widgets/progressbar.c | 29 +
widgets/systray.c | 28
widgets/textbox.c | 25 +
7 files changed, 141 insertions(+), 1 deletions(-)
diff --git a/widget.c b/widget.c
index f8c00e3..d6372bb 100644
--- a/widget.c
+++ b/widget.c
@@ -494,6 +494,29 @@ luaA_widget_newindex(lua_State *L)
return 0;
}
+static int
+luaA_widget_extents(lua_State *L)
+{
+widget_t *widget = luaL_checkudata(L, 1, widget);
+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;
+}
+
const struct luaL_reg awesome_widget_methods[] =
{
{ __call, luaA_widget_new },
@@ -502,6 +525,7 @@ const struct luaL_reg awesome_widget_methods[] =
const struct luaL_reg awesome_widget_meta[] =
{
{ buttons, luaA_widget_buttons },
+{ extents, luaA_widget_extents },
{ __index, luaA_widget_index },
{ __newindex, luaA_widget_newindex },
{ __gc, luaA_widget_gc },
diff --git a/widget.h b/widget.h
index 97c792e..02fbc9a 100644
--- a/widget.h
+++ b/widget.h
@@ -37,8 +37,10 @@ struct widget_t
widget_constructor_t *type;
/** Widget destructor */
widget_destructor_t *destructor;
-/** Geometry function */
+/** Geometry function for drawing */
area_t (*geometry)(widget_t *, screen_t *, int, int);
+/** Extents function */
+area_t (*extents)(lua_State *, widget_t *);
/** Draw function */
void (*draw)(widget_t *, draw_context_t *, area_t, wibox_t *);
/** Index function */
diff --git a/widgets/graph.c b/widgets/graph.c
index 675239b..44f8f0e 100644
--- a/widgets/graph.c
+++ b/widgets/graph.c
@@ -159,6 +159,16 @@ graph_geometry(widget_t *widget, screen_t *screen, int height, int width)
return geometry;
}
+static area_t
+graph_extents(lua_State *L, widget_t *widget)
+{
+area_t geometry;
+graph_data_t *d = widget-data;
+geometry.width = geometry.height = d-width;
+
+return geometry;
+}
+
/** Draw a graph widget.
* \param ctx The draw context.
* \param w The widget node we are called from.
@@ -592,6 +602,7 @@ widget_graph(widget_t *w)
w-newindex = luaA_graph_newindex;
w-destructor = graph_destructor;
w-geometry = graph_geometry;
+w-extents = graph_extents;
graph_data_t *d = w-data = p_new(graph_data_t, 1);
diff --git a/widgets/imagebox.c b/widgets/imagebox.c
index de8b5f0..ddcd131 100644
--- a/widgets/imagebox.c
+++ b/widgets/imagebox.c
@@ -72,6 +72,26 @@ imagebox_geometry(widget_t *widget, screen_t *screen, int height, int width)
return