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.
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
;
42 ev
.response_type
= XCB_CLIENT_MESSAGE
;
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
;
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.
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);
67 xembed_info_from_reply(xembed_info_t
*info
, xcb_get_property_reply_t
*prop_r
)
71 if(!prop_r
|| !prop_r
->value_len
)
74 if(!(data
= (uint32_t *) xcb_get_property_value(prop_r
)))
77 info
->version
= data
[0];
78 info
->flags
= data
[1] & XEMBED_INFO_FLAGS_ALL
;
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.
89 xembed_info_get_reply(xcb_connection_t
*connection
,
90 xcb_get_property_cookie_t cookie
,
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
);
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.
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
];
113 /** Update embedded window properties.
114 * \param connection The X connection.
115 * \param emwin The embedded window.
118 xembed_property_update(xcb_connection_t
*connection
, xembed_window_t
*emwin
,
119 xcb_get_property_reply_t
*reply
)
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
))
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
);
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