buffer: use a_strlen()
[awesome.git] / widgets / systray.c
blob324eef5ddc5e84cfecbdef2673dc51a9c302e4da
1 /*
2 * systray.c - systray widget
4 * Copyright © 2008 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 "common/xembed.h"
28 #include "common/atoms.h"
30 #define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
31 #define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
33 extern awesome_t globalconf;
35 static area_t
36 systray_geometry(widget_t *widget, int screen, int height, int width)
38 area_t geometry;
39 int phys_screen = screen_virttophys(screen), i = 0;
41 geometry.height = height;
43 for(xembed_window_t *em = globalconf.embedded; em; em = em->next)
44 if(em->phys_screen == phys_screen)
45 i++;
47 /** \todo use class hints */
48 geometry.width = MIN(i * height, width);
50 return geometry;
53 static void
54 systray_draw(widget_t *widget, draw_context_t *ctx,
55 area_t geometry, int screen, wibox_t *p)
57 uint32_t orient;
59 switch(p->position)
61 case Right:
62 case Left:
63 orient = _NET_SYSTEM_TRAY_ORIENTATION_VERT;
64 break;
65 default:
66 orient = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
67 break;
70 /* set wibox orientation */
71 /** \todo stop setting that property on each redraw */
72 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
73 globalconf.screens[p->sw.ctx.phys_screen].systray.window,
74 _NET_SYSTEM_TRAY_ORIENTATION, CARDINAL, 32, 1, &orient);
77 widget_t *
78 systray_new(alignment_t align)
80 widget_t *w;
82 w = p_new(widget_t, 1);
83 widget_common_new(w);
84 w->align = align;
85 w->draw = systray_draw;
86 w->geometry = systray_geometry;
87 w->cache_flags = WIDGET_CACHE_EMBEDDED;
89 return w;
91 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80