Make callbacks to rules.execute optional
[awesome.git] / common / xembed.c
blobbb70ab1f8281b3758b910dfe51f0c14750db89c9
1 /*
2 * common/xembed.c - XEMBED functions
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
5 * Copyright © 2004 Matthew Reppert
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "common/xembed.h"
24 #include "common/util.h"
25 #include "common/atoms.h"
27 /** Send an XEMBED message to a window.
28 * \param connection Connection to the X server.
29 * \param towin Destination window
30 * \param message The message.
31 * \param d1 Element 3 of message.
32 * \param d2 Element 4 of message.
33 * \param d3 Element 5 of message.
35 void
36 xembed_message_send(xcb_connection_t *connection, xcb_window_t towin,
37 long message, long d1, long d2, long d3)
39 xcb_client_message_event_t ev;
41 p_clear(&ev, 1);
42 ev.response_type = XCB_CLIENT_MESSAGE;
43 ev.window = towin;
44 ev.format = 32;
45 ev.data.data32[0] = XCB_CURRENT_TIME;
46 ev.data.data32[1] = message;
47 ev.data.data32[2] = d1;
48 ev.data.data32[3] = d2;
49 ev.data.data32[4] = d3;
50 ev.type = _XEMBED;
51 xcb_send_event(connection, false, towin, XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
54 /** Deliver a request to get XEMBED info for a window.
55 * \param connection The X connection.
56 * \param win The window.
57 * \return A cookie.
59 xcb_get_property_cookie_t
60 xembed_info_get_unchecked(xcb_connection_t *connection, xcb_window_t win)
62 return xcb_get_property_unchecked(connection, false, win, _XEMBED_INFO,
63 XCB_GET_PROPERTY_TYPE_ANY, 0L, 2);
66 static bool
67 xembed_info_from_reply(xembed_info_t *info, xcb_get_property_reply_t *prop_r)
69 uint32_t *data;
71 if(!prop_r || !prop_r->value_len)
72 return false;
74 if(!(data = (uint32_t *) xcb_get_property_value(prop_r)))
75 return false;
77 info->version = data[0];
78 info->flags = data[1] & XEMBED_INFO_FLAGS_ALL;
80 return true;
83 /** Get the XEMBED info for a window.
84 * \param connection The X connection.
85 * \param cookie The cookie of the request.
86 * \param info The xembed_info_t structure to fill.
88 bool
89 xembed_info_get_reply(xcb_connection_t *connection,
90 xcb_get_property_cookie_t cookie,
91 xembed_info_t *info)
93 xcb_get_property_reply_t *prop_r = xcb_get_property_reply(connection, cookie, NULL);
94 bool ret = xembed_info_from_reply(info, prop_r);
95 p_delete(&prop_r);
96 return ret;
99 /** Get a XEMBED window from a xembed_window_t list.
100 * \param list The xembed window list.
101 * \param win The window to look for.
102 * \return The xembed window if found, NULL otherwise.
104 xembed_window_t *
105 xembed_getbywin(xembed_window_array_t *list, xcb_window_t win)
107 for(int i = 0; i < list->len; i++)
108 if(list->tab[i].win == win)
109 return &list->tab[i];
110 return NULL;
113 /** Update embedded window properties.
114 * \param connection The X connection.
115 * \param emwin The embedded window.
117 void
118 xembed_property_update(xcb_connection_t *connection, xembed_window_t *emwin,
119 xcb_get_property_reply_t *reply)
121 int flags_changed;
122 xembed_info_t info = { 0, 0 };
124 xembed_info_from_reply(&info, reply);
126 /* test if it changed */
127 if(!(flags_changed = info.flags ^ emwin->info.flags))
128 return;
130 emwin->info.flags = info.flags;
131 if(flags_changed & XEMBED_MAPPED)
133 if(info.flags & XEMBED_MAPPED)
135 xcb_map_window(connection, emwin->win);
136 xembed_window_activate(connection, emwin->win);
138 else
140 xcb_unmap_window(connection, emwin->win);
141 xembed_window_deactivate(connection, emwin->win);
142 xembed_focus_out(connection, emwin->win);
147 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80