2008-06-14 18:12:16 +02:00
|
|
|
/*
|
|
|
|
* systray.c - systray handling
|
|
|
|
*
|
|
|
|
* Copyright © 2008 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_icccm.h>
|
2008-06-30 13:06:23 +02:00
|
|
|
#include <xcb/xcb_atom.h>
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
#include "systray.h"
|
|
|
|
#include "window.h"
|
2008-06-14 23:20:35 +02:00
|
|
|
#include "widget.h"
|
2008-06-30 18:55:14 +02:00
|
|
|
#include "common/atoms.h"
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
#define SYSTEM_TRAY_REQUEST_DOCK 0 /* Begin icon docking */
|
|
|
|
|
2008-09-03 18:03:31 +02:00
|
|
|
/** Initialize systray information in X.
|
|
|
|
* \param phys_screen Physical screen.
|
|
|
|
*/
|
2008-06-15 10:25:26 +02:00
|
|
|
void
|
|
|
|
systray_init(int phys_screen)
|
|
|
|
{
|
|
|
|
xcb_client_message_event_t ev;
|
2008-06-17 16:55:24 +02:00
|
|
|
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
|
2008-09-16 14:42:17 +02:00
|
|
|
char *atom_name;
|
2008-06-30 18:55:14 +02:00
|
|
|
xcb_intern_atom_cookie_t atom_systray_q;
|
|
|
|
xcb_intern_atom_reply_t *atom_systray_r;
|
|
|
|
xcb_atom_t atom_systray;
|
2008-06-15 10:25:26 +02:00
|
|
|
|
|
|
|
/* Send requests */
|
2008-09-16 14:42:17 +02:00
|
|
|
if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen)))
|
|
|
|
{
|
|
|
|
warn("error getting systray atom");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
atom_systray_q = xcb_intern_atom_unchecked(globalconf.connection, false,
|
2008-09-20 16:16:05 +02:00
|
|
|
a_strlen(atom_name), atom_name);
|
2008-09-16 14:42:17 +02:00
|
|
|
|
|
|
|
p_delete(&atom_name);
|
2008-06-15 10:25:26 +02:00
|
|
|
|
2008-06-17 13:33:17 +02:00
|
|
|
globalconf.screens[phys_screen].systray.window = xcb_generate_id(globalconf.connection);
|
|
|
|
xcb_create_window(globalconf.connection, xscreen->root_depth,
|
|
|
|
globalconf.screens[phys_screen].systray.window,
|
|
|
|
xscreen->root,
|
|
|
|
-1, -1, 1, 1, 0,
|
|
|
|
XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL);
|
2008-06-15 10:25:26 +02:00
|
|
|
|
|
|
|
/* Fill event */
|
2008-06-24 19:54:54 +02:00
|
|
|
p_clear(&ev, 1);
|
2008-06-15 20:12:49 +02:00
|
|
|
ev.response_type = XCB_CLIENT_MESSAGE;
|
2008-06-24 17:38:44 +02:00
|
|
|
ev.window = xscreen->root;
|
2008-06-15 10:25:26 +02:00
|
|
|
ev.format = 32;
|
2008-06-30 18:55:14 +02:00
|
|
|
ev.type = MANAGER;
|
2008-06-15 10:25:26 +02:00
|
|
|
ev.data.data32[0] = XCB_CURRENT_TIME;
|
2008-06-17 13:33:17 +02:00
|
|
|
ev.data.data32[2] = globalconf.screens[phys_screen].systray.window;
|
2008-06-15 10:25:26 +02:00
|
|
|
ev.data.data32[3] = ev.data.data32[4] = 0;
|
|
|
|
|
2008-06-30 18:55:14 +02:00
|
|
|
if(!(atom_systray_r = xcb_intern_atom_reply(globalconf.connection, atom_systray_q, NULL)))
|
|
|
|
{
|
|
|
|
warn("error getting systray atom");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev.data.data32[1] = atom_systray = atom_systray_r->atom;
|
|
|
|
|
|
|
|
p_delete(&atom_systray_r);
|
2008-06-15 10:25:26 +02:00
|
|
|
|
|
|
|
xcb_set_selection_owner(globalconf.connection,
|
2008-06-17 13:33:17 +02:00
|
|
|
globalconf.screens[phys_screen].systray.window,
|
2008-06-15 10:25:26 +02:00
|
|
|
atom_systray,
|
|
|
|
XCB_CURRENT_TIME);
|
2008-06-15 11:22:34 +02:00
|
|
|
|
2008-06-24 19:54:54 +02:00
|
|
|
xcb_send_event(globalconf.connection, false, xscreen->root, 0xFFFFFF, (char *) &ev);
|
2008-06-15 10:25:26 +02:00
|
|
|
}
|
|
|
|
|
2008-09-03 18:03:31 +02:00
|
|
|
/** Remove systray information in X.
|
|
|
|
* \param phys_screen Physical screen.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
systray_cleanup(int phys_screen)
|
|
|
|
{
|
|
|
|
xcb_intern_atom_reply_t *atom_systray_r;
|
2008-09-16 14:42:17 +02:00
|
|
|
char *atom_name;
|
|
|
|
|
|
|
|
if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen))
|
|
|
|
|| !(atom_systray_r = xcb_intern_atom_reply(globalconf.connection,
|
|
|
|
xcb_intern_atom_unchecked(globalconf.connection,
|
|
|
|
false,
|
2008-09-20 16:16:05 +02:00
|
|
|
a_strlen(atom_name),
|
2008-09-16 14:42:17 +02:00
|
|
|
atom_name),
|
|
|
|
NULL)))
|
2008-09-03 18:03:31 +02:00
|
|
|
{
|
|
|
|
warn("error getting systray atom");
|
2008-09-16 14:42:17 +02:00
|
|
|
p_delete(&atom_name);
|
2008-09-03 18:03:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-16 14:42:17 +02:00
|
|
|
p_delete(&atom_name);
|
|
|
|
|
2008-09-03 18:03:31 +02:00
|
|
|
xcb_set_selection_owner(globalconf.connection,
|
|
|
|
XCB_NONE,
|
|
|
|
atom_systray_r->atom,
|
|
|
|
XCB_CURRENT_TIME);
|
|
|
|
|
|
|
|
p_delete(&atom_systray_r);
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
/** Handle a systray request.
|
|
|
|
* \param embed_win The window to embed.
|
|
|
|
*/
|
2008-06-30 13:06:23 +02:00
|
|
|
int
|
2008-06-14 18:12:16 +02:00
|
|
|
systray_request_handle(xcb_window_t embed_win, int phys_screen, xembed_info_t *info)
|
|
|
|
{
|
2008-12-01 16:43:44 +01:00
|
|
|
xembed_window_t em;
|
2008-08-12 15:29:01 +02:00
|
|
|
xcb_get_property_cookie_t em_cookie;
|
2008-06-14 23:20:35 +02:00
|
|
|
int i;
|
2008-06-14 18:12:16 +02:00
|
|
|
const uint32_t select_input_val[] =
|
|
|
|
{
|
|
|
|
XCB_EVENT_MASK_STRUCTURE_NOTIFY
|
|
|
|
| XCB_EVENT_MASK_PROPERTY_CHANGE
|
|
|
|
| XCB_EVENT_MASK_ENTER_WINDOW
|
|
|
|
};
|
|
|
|
|
2008-06-29 13:38:02 +02:00
|
|
|
/* check if not already trayed */
|
2008-12-01 16:43:44 +01:00
|
|
|
if(xembed_getbywin(&globalconf.embedded, embed_win))
|
2008-06-30 13:06:23 +02:00
|
|
|
return -1;
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-08-12 15:29:01 +02:00
|
|
|
p_clear(&em_cookie, 1);
|
|
|
|
|
|
|
|
if(!info)
|
|
|
|
em_cookie = xembed_info_get_unchecked(globalconf.connection, embed_win);
|
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
xcb_change_window_attributes(globalconf.connection, embed_win, XCB_CW_EVENT_MASK,
|
|
|
|
select_input_val);
|
2008-09-09 16:14:36 +02:00
|
|
|
window_state_set(embed_win, XCB_WM_STATE_WITHDRAWN);
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-09-01 17:54:53 +02:00
|
|
|
xcb_reparent_window(globalconf.connection, embed_win,
|
|
|
|
globalconf.screens[phys_screen].systray.window,
|
|
|
|
0, 0);
|
|
|
|
|
2008-12-01 16:43:44 +01:00
|
|
|
em.win = embed_win;
|
|
|
|
em.phys_screen = phys_screen;
|
2008-08-12 15:29:01 +02:00
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
if(info)
|
2008-12-01 16:43:44 +01:00
|
|
|
em.info = *info;
|
2008-06-14 18:12:16 +02:00
|
|
|
else
|
2008-12-01 16:43:44 +01:00
|
|
|
xembed_info_get_reply(globalconf.connection, em_cookie, &em.info);
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-12-01 16:43:44 +01:00
|
|
|
xembed_embedded_notify(globalconf.connection, em.win,
|
2008-06-17 13:33:17 +02:00
|
|
|
globalconf.screens[phys_screen].systray.window,
|
2008-12-01 16:43:44 +01:00
|
|
|
MIN(XEMBED_VERSION, em.info.version));
|
|
|
|
|
|
|
|
xembed_window_array_append(&globalconf.embedded, em);
|
2008-06-14 18:12:16 +02:00
|
|
|
|
2008-09-18 16:03:05 +02:00
|
|
|
for(i = 0; i < globalconf.nscreen; i++)
|
2008-11-12 14:55:30 +01:00
|
|
|
widget_invalidate_bytype(i, widget_systray);
|
2008-06-14 23:20:35 +02:00
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Handle systray message.
|
|
|
|
* \param ev The event.
|
|
|
|
* \return 0 on no error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
systray_process_client_message(xcb_client_message_event_t *ev)
|
|
|
|
{
|
2008-06-29 13:38:02 +02:00
|
|
|
int screen_nbr = 0, ret = 0;
|
2008-06-14 18:12:16 +02:00
|
|
|
xcb_get_geometry_cookie_t geom_c;
|
|
|
|
xcb_get_geometry_reply_t *geom_r;
|
|
|
|
xcb_screen_iterator_t iter;
|
|
|
|
|
|
|
|
switch(ev->data.data32[1])
|
|
|
|
{
|
|
|
|
case SYSTEM_TRAY_REQUEST_DOCK:
|
2008-06-21 12:56:51 +02:00
|
|
|
geom_c = xcb_get_geometry_unchecked(globalconf.connection, ev->window);
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
if(!(geom_r = xcb_get_geometry_reply(globalconf.connection, geom_c, NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for(iter = xcb_setup_roots_iterator(xcb_get_setup(globalconf.connection)), screen_nbr = 0;
|
|
|
|
iter.rem && iter.data->root != geom_r->root; xcb_screen_next (&iter), ++screen_nbr);
|
|
|
|
|
|
|
|
p_delete(&geom_r);
|
|
|
|
|
2008-06-29 13:38:02 +02:00
|
|
|
ret = systray_request_handle(ev->data.data32[2], screen_nbr, NULL);
|
2008-06-14 18:12:16 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-06-29 13:38:02 +02:00
|
|
|
|
|
|
|
return ret;
|
2008-06-14 18:12:16 +02:00
|
|
|
}
|
|
|
|
|
2008-06-30 13:06:23 +02:00
|
|
|
/** Check if a window is a KDE tray.
|
|
|
|
* \param w The window to check.
|
|
|
|
* \return True if it is, false otherwise.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
systray_iskdedockapp(xcb_window_t w)
|
|
|
|
{
|
|
|
|
xcb_get_property_cookie_t kde_check_q;
|
|
|
|
xcb_get_property_reply_t *kde_check;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
/* Check if that is a KDE tray because it does not repect fdo standards,
|
|
|
|
* thanks KDE. */
|
|
|
|
kde_check_q = xcb_get_property_unchecked(globalconf.connection, false, w,
|
2008-06-30 18:55:14 +02:00
|
|
|
_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR,
|
2008-06-30 13:06:23 +02:00
|
|
|
WINDOW, 0, 1);
|
|
|
|
|
|
|
|
kde_check = xcb_get_property_reply(globalconf.connection, kde_check_q, NULL);
|
|
|
|
|
|
|
|
/* it's a KDE systray ?*/
|
|
|
|
ret = (kde_check && kde_check->value_len);
|
|
|
|
|
|
|
|
p_delete(&kde_check);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
/** Handle xembed client message.
|
|
|
|
* \param ev The event.
|
|
|
|
* \return 0 on no error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xembed_process_client_message(xcb_client_message_event_t *ev)
|
|
|
|
{
|
|
|
|
switch(ev->data.data32[1])
|
|
|
|
{
|
|
|
|
case XEMBED_REQUEST_FOCUS:
|
|
|
|
xembed_focus_in(globalconf.connection, ev->window, XEMBED_FOCUS_CURRENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|