Revert "client: fix windows managed on startup"
[awesome.git] / systray.c
blob834e55b53c89f72b0230e7ad3173a90d97052cb8
1 /*
2 * systray.c - systray handling
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_icccm.h>
24 #include <xcb/xcb_atom.h>
26 #include "systray.h"
27 #include "window.h"
28 #include "widget.h"
29 #include "common/atoms.h"
31 #define SYSTEM_TRAY_REQUEST_DOCK 0 /* Begin icon docking */
33 extern awesome_t globalconf;
35 void
36 systray_init(int phys_screen)
38 xcb_client_message_event_t ev;
39 xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
40 char atom_name[22];
41 xcb_intern_atom_cookie_t atom_systray_q;
42 xcb_intern_atom_reply_t *atom_systray_r;
43 xcb_atom_t atom_systray;
44 ssize_t len;
46 /* Send requests */
47 len = snprintf(atom_name, sizeof(atom_name), "_NET_SYSTEM_TRAY_S%d", phys_screen);
48 atom_systray_q = xcb_intern_atom_unchecked(globalconf.connection, false, len, atom_name);
50 globalconf.screens[phys_screen].systray.window = xcb_generate_id(globalconf.connection);
51 xcb_create_window(globalconf.connection, xscreen->root_depth,
52 globalconf.screens[phys_screen].systray.window,
53 xscreen->root,
54 -1, -1, 1, 1, 0,
55 XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL);
57 /* Fill event */
58 p_clear(&ev, 1);
59 ev.response_type = XCB_CLIENT_MESSAGE;
60 ev.window = xscreen->root;
61 ev.format = 32;
62 ev.type = MANAGER;
63 ev.data.data32[0] = XCB_CURRENT_TIME;
64 ev.data.data32[2] = globalconf.screens[phys_screen].systray.window;
65 ev.data.data32[3] = ev.data.data32[4] = 0;
67 if(!(atom_systray_r = xcb_intern_atom_reply(globalconf.connection, atom_systray_q, NULL)))
69 warn("error getting systray atom");
70 return;
73 ev.data.data32[1] = atom_systray = atom_systray_r->atom;
75 p_delete(&atom_systray_r);
77 xcb_set_selection_owner(globalconf.connection,
78 globalconf.screens[phys_screen].systray.window,
79 atom_systray,
80 XCB_CURRENT_TIME);
82 xcb_send_event(globalconf.connection, false, xscreen->root, 0xFFFFFF, (char *) &ev);
85 /** Handle a systray request.
86 * \param embed_win The window to embed.
88 int
89 systray_request_handle(xcb_window_t embed_win, int phys_screen, xembed_info_t *info)
91 xembed_window_t *em;
92 int i;
93 const uint32_t select_input_val[] =
95 XCB_EVENT_MASK_STRUCTURE_NOTIFY
96 | XCB_EVENT_MASK_PROPERTY_CHANGE
97 | XCB_EVENT_MASK_ENTER_WINDOW
100 /* check if not already trayed */
101 if((em = xembed_getbywin(globalconf.embedded, embed_win)))
102 return -1;
104 xcb_change_window_attributes(globalconf.connection, embed_win, XCB_CW_EVENT_MASK,
105 select_input_val);
106 window_setstate(embed_win, XCB_WM_WITHDRAWN_STATE);
108 em = p_new(xembed_window_t, 1);
109 em->win = embed_win;
110 em->phys_screen = phys_screen;
112 if(info)
113 em->info = *info;
114 else
115 xembed_info_get(globalconf.connection, em->win, &em->info);
117 xembed_window_list_append(&globalconf.embedded, em);
119 xembed_embedded_notify(globalconf.connection, em->win,
120 globalconf.screens[phys_screen].systray.window,
121 MIN(XEMBED_VERSION, em->info.version));
123 for(i = 0; i < globalconf.screens_info->nscreen; i++)
124 widget_invalidate_cache(i, WIDGET_CACHE_EMBEDDED);
126 return 0;
129 /** Handle systray message.
130 * \param ev The event.
131 * \return 0 on no error.
134 systray_process_client_message(xcb_client_message_event_t *ev)
136 int screen_nbr = 0, ret = 0;
137 xcb_get_geometry_cookie_t geom_c;
138 xcb_get_geometry_reply_t *geom_r;
139 xcb_screen_iterator_t iter;
141 switch(ev->data.data32[1])
143 case SYSTEM_TRAY_REQUEST_DOCK:
144 geom_c = xcb_get_geometry_unchecked(globalconf.connection, ev->window);
146 if(!(geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL)))
147 return -1;
149 for(iter = xcb_setup_roots_iterator(xcb_get_setup(globalconf.connection)), screen_nbr = 0;
150 iter.rem && iter.data->root != geom_r->root; xcb_screen_next (&iter), ++screen_nbr);
152 p_delete(&geom_r);
154 ret = systray_request_handle(ev->data.data32[2], screen_nbr, NULL);
155 break;
158 return ret;
161 /** Check if a window is a KDE tray.
162 * \param w The window to check.
163 * \return True if it is, false otherwise.
165 bool
166 systray_iskdedockapp(xcb_window_t w)
168 xcb_get_property_cookie_t kde_check_q;
169 xcb_get_property_reply_t *kde_check;
170 bool ret;
172 /* Check if that is a KDE tray because it does not repect fdo standards,
173 * thanks KDE. */
174 kde_check_q = xcb_get_property_unchecked(globalconf.connection, false, w,
175 _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR,
176 WINDOW, 0, 1);
178 kde_check = xcb_get_property_reply(globalconf.connection, kde_check_q, NULL);
180 /* it's a KDE systray ?*/
181 ret = (kde_check && kde_check->value_len);
183 p_delete(&kde_check);
185 return ret;
188 /** Handle xembed client message.
189 * \param ev The event.
190 * \return 0 on no error.
193 xembed_process_client_message(xcb_client_message_event_t *ev)
195 switch(ev->data.data32[1])
197 case XEMBED_REQUEST_FOCUS:
198 xembed_focus_in(globalconf.connection, ev->window, XEMBED_FOCUS_CURRENT);
199 break;
201 return 0;
204 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80