Remove "encoding=utf-8" from Vim modelines
[awesome.git] / common / xembed.c
blobd05ed4a1ea614f92e0bc1f341826608d6b92290b
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/xutil.h"
25 #include "common/util.h"
26 #include "common/atoms.h"
28 /** Send an XEMBED message to a window.
29 * \param connection Connection to the X server.
30 * \param towin Destination window
31 * \param message The message.
32 * \param d1 Element 3 of message.
33 * \param d2 Element 4 of message.
34 * \param d3 Element 5 of message.
36 void
37 xembed_message_send(xcb_connection_t *connection, xcb_window_t towin,
38 long message, long d1, long d2, long d3)
40 xcb_client_message_event_t ev;
42 p_clear(&ev, 1);
43 ev.response_type = XCB_CLIENT_MESSAGE;
44 ev.window = towin;
45 ev.format = 32;
46 ev.data.data32[0] = XCB_CURRENT_TIME;
47 ev.data.data32[1] = message;
48 ev.data.data32[2] = d1;
49 ev.data.data32[3] = d2;
50 ev.data.data32[4] = d3;
51 ev.type = _XEMBED;
52 xcb_send_event(connection, false, towin, XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
55 /** Deliver a request to get XEMBED info for a window.
56 * \param connection The X connection.
57 * \param win The window.
58 * \return A cookie.
60 xcb_get_property_cookie_t
61 xembed_info_get_unchecked(xcb_connection_t *connection, xcb_window_t win)
63 return xcb_get_property_unchecked(connection, false, win, _XEMBED_INFO,
64 XCB_GET_PROPERTY_TYPE_ANY, 0L, 2);
67 static bool
68 xembed_info_from_reply(xembed_info_t *info, xcb_get_property_reply_t *prop_r)
70 uint32_t *data;
72 if(!prop_r || !prop_r->value_len)
73 return false;
75 if(!(data = (uint32_t *) xcb_get_property_value(prop_r)))
76 return false;
78 info->version = data[0];
79 info->flags = data[1] & XEMBED_INFO_FLAGS_ALL;
81 return true;
84 /** Get the XEMBED info for a window.
85 * \param connection The X connection.
86 * \param cookie The cookie of the request.
87 * \param info The xembed_info_t structure to fill.
89 bool
90 xembed_info_get_reply(xcb_connection_t *connection,
91 xcb_get_property_cookie_t cookie,
92 xembed_info_t *info)
94 xcb_get_property_reply_t *prop_r = xcb_get_property_reply(connection, cookie, NULL);
95 bool ret = xembed_info_from_reply(info, prop_r);
96 p_delete(&prop_r);
97 return ret;
100 /** Get a XEMBED window from a xembed_window_t list.
101 * \param list The xembed window list.
102 * \param win The window to look for.
103 * \return The xembed window if found, NULL otherwise.
105 xembed_window_t *
106 xembed_getbywin(xembed_window_array_t *list, xcb_window_t win)
108 for(int i = 0; i < list->len; i++)
109 if(list->tab[i].win == win)
110 return &list->tab[i];
111 return NULL;
114 /** Update embedded window properties.
115 * \param connection The X connection.
116 * \param emwin The embedded window.
118 void
119 xembed_property_update(xcb_connection_t *connection, xembed_window_t *emwin,
120 xcb_get_property_reply_t *reply)
122 int flags_changed;
123 xembed_info_t info = { 0, 0 };
125 xembed_info_from_reply(&info, reply);
127 /* test if it changed */
128 if(!(flags_changed = info.flags ^ emwin->info.flags))
129 return;
131 emwin->info.flags = info.flags;
132 if(flags_changed & XEMBED_MAPPED)
134 if(info.flags & XEMBED_MAPPED)
136 xcb_map_window(connection, emwin->win);
137 xembed_window_activate(connection, emwin->win);
139 else
141 xcb_unmap_window(connection, emwin->win);
142 xembed_window_deactivate(connection, emwin->win);
143 xembed_focus_out(connection, emwin->win);
148 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80