xembed: make xembed_info_get() asynchronous
[awesome.git] / widgets / systray.c
blobb94aede891c7191cd7912f19e08f67cf25aa5b06
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 int
36 systray_draw(draw_context_t *ctx,
37 int screen __attribute__ ((unused)),
38 widget_node_t *w,
39 int offset, int used __attribute__ ((unused)),
40 void *p,
41 awesome_type_t type)
43 uint32_t orient;
44 /* p is always a statusbar, titlebars are forbidden */
45 statusbar_t *sb = (statusbar_t *) p;
47 /* we are on a statusbar */
48 assert(type == AWESOME_TYPE_STATUSBAR);
50 w->area.height = ctx->height;
52 if(ctx->width - used > 0)
54 int i = 0;
55 xembed_window_t *em;
56 for(em = globalconf.embedded; em; em = em->next)
57 if(em->phys_screen == sb->phys_screen)
58 i++;
59 /** \todo use clas hints */
60 w->area.width = MIN(i * ctx->height, ctx->width - used);
62 else
63 w->area.width = 0;
65 w->area.x = widget_calculate_offset(ctx->width,
66 w->area.width,
67 offset,
68 w->widget->align);
69 w->area.y = 0;
71 switch(sb->position)
73 case Right:
74 case Left:
75 orient = _NET_SYSTEM_TRAY_ORIENTATION_VERT;
76 break;
77 default:
78 orient = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
79 break;
82 /* set statusbar orientation */
83 /** \todo stop setting that property on each redraw */
84 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
85 globalconf.screens[sb->phys_screen].systray.window,
86 _NET_SYSTEM_TRAY_ORIENTATION, CARDINAL, 32, 1, &orient);
88 return w->area.width;
91 widget_t *
92 systray_new(alignment_t align)
94 widget_t *w;
96 w = p_new(widget_t, 1);
97 widget_common_new(w);
98 w->align = align;
99 w->draw = systray_draw;
100 w->cache_flags = WIDGET_CACHE_EMBEDDED;
102 return w;
104 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80