Wibox: Unref old widgets table
[awesome.git] / widgets / systray.c
blobab7450695491c770f8efd9cf891c324bc13dbda6
1 /*
2 * systray.c - systray widget
4 * Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <xcb/xcb.h>
23 #include <xcb/xcb_atom.h>
25 #include "widget.h"
26 #include "screen.h"
27 #include "wibox.h"
28 #include "luaa.h"
29 #include "globalconf.h"
30 #include "common/xembed.h"
31 #include "common/atoms.h"
33 #define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
34 #define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
36 typedef struct
38 /* systray height */
39 int height;
40 } systray_data_t;
42 static area_t
43 systray_extents(lua_State *L, widget_t *widget)
45 int screen = luaL_optnumber(L, -1, 1) - 1;
46 luaA_checkscreen(screen);
48 area_t geometry;
49 int phys_screen = screen_virttophys(screen), n = 0;
50 systray_data_t *d = widget->data;
52 for(int i = 0; i < globalconf.embedded.len; i++)
53 if(globalconf.embedded.tab[i].phys_screen == phys_screen)
54 n++;
56 /** \todo use class hints */
57 geometry.width = d->height * n;
58 geometry.height = d->height;
59 geometry.x = geometry.y = 0;
61 return geometry;
64 static void
65 systray_draw(widget_t *widget, draw_context_t *ctx,
66 area_t geometry, wibox_t *p)
68 uint32_t orient;
70 switch(p->position)
72 case Right:
73 case Left:
74 orient = _NET_SYSTEM_TRAY_ORIENTATION_VERT;
75 break;
76 default:
77 orient = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
78 break;
81 systray_data_t *d = widget->data;
83 if (p->orientation == East)
84 d->height = p->geometry.height;
85 else
86 d->height = p->geometry.width;
88 /* set wibox orientation */
89 /** \todo stop setting that property on each redraw */
90 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
91 globalconf.screens.tab[p->ctx.phys_screen].systray.window,
92 _NET_SYSTEM_TRAY_ORIENTATION, XCB_ATOM_CARDINAL, 32, 1, &orient);
95 /** Delete a systray widget.
96 * \param w The widget to destroy.
98 static void
99 systray_destructor(widget_t *w)
101 systray_data_t *d = w->data;
102 p_delete(&d);
105 /** Initialize a systray widget.
106 * \param w The widget to initialize.
107 * \return The same widget.
109 widget_t *
110 widget_systray(widget_t *w)
112 w->draw = systray_draw;
113 w->extents = systray_extents;
114 w->destructor = systray_destructor;
116 systray_data_t *d = w->data = p_new(systray_data_t, 1);
117 d->height = 0;
119 return w;
121 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80