2008-09-16 14:09:56 +02:00
|
|
|
/*
|
|
|
|
* property.c - property handlers
|
|
|
|
*
|
2009-08-10 11:36:11 +02:00
|
|
|
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
|
2008-09-16 14:09:56 +02:00
|
|
|
*
|
|
|
|
* 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_atom.h>
|
|
|
|
|
|
|
|
#include "property.h"
|
|
|
|
#include "ewmh.h"
|
2014-03-30 15:12:47 +02:00
|
|
|
#include "objects/client.h"
|
2010-10-06 13:35:14 +02:00
|
|
|
#include "objects/drawin.h"
|
2014-03-30 15:12:47 +02:00
|
|
|
#include "objects/screen.h"
|
2009-09-17 17:51:06 +02:00
|
|
|
#include "xwindow.h"
|
2009-08-17 16:38:56 +02:00
|
|
|
#include "luaa.h"
|
2008-09-16 14:09:56 +02:00
|
|
|
#include "common/atoms.h"
|
2009-04-17 16:52:25 +02:00
|
|
|
#include "common/xutil.h"
|
2008-09-16 14:09:56 +02:00
|
|
|
|
2009-08-24 10:05:50 +02:00
|
|
|
#define HANDLE_TEXT_PROPERTY(funcname, atom, setfunc) \
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_cookie_t \
|
|
|
|
property_get_##funcname(client_t *c) \
|
|
|
|
{ \
|
|
|
|
return xcb_get_property(globalconf.connection, \
|
|
|
|
false, \
|
|
|
|
c->window, \
|
|
|
|
atom, \
|
|
|
|
XCB_GET_PROPERTY_TYPE_ANY, \
|
|
|
|
0, \
|
|
|
|
UINT_MAX); \
|
|
|
|
} \
|
2009-08-24 10:05:50 +02:00
|
|
|
void \
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_##funcname(client_t *c, xcb_get_property_cookie_t cookie) \
|
2009-08-24 10:05:50 +02:00
|
|
|
{ \
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_reply_t * reply = \
|
|
|
|
xcb_get_property_reply(globalconf.connection, cookie, NULL); \
|
2009-08-24 10:05:50 +02:00
|
|
|
luaA_object_push(globalconf.L, c); \
|
|
|
|
setfunc(globalconf.L, -1, xutil_get_text_property_from_reply(reply)); \
|
|
|
|
lua_pop(globalconf.L, 1); \
|
2010-08-09 12:47:29 +02:00
|
|
|
p_delete(&reply); \
|
2009-08-24 10:05:50 +02:00
|
|
|
} \
|
|
|
|
static int \
|
2010-08-08 16:54:36 +02:00
|
|
|
property_handle_##funcname(uint8_t state, \
|
2010-08-09 13:06:32 +02:00
|
|
|
xcb_window_t window) \
|
2009-08-24 10:05:50 +02:00
|
|
|
{ \
|
|
|
|
client_t *c = client_getbywin(window); \
|
|
|
|
if(c) \
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_##funcname(c, property_get_##funcname(c));\
|
2009-08-24 10:05:50 +02:00
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-08 18:31:07 +02:00
|
|
|
HANDLE_TEXT_PROPERTY(wm_name, XCB_ATOM_WM_NAME, client_set_alt_name)
|
2009-08-25 16:39:10 +02:00
|
|
|
HANDLE_TEXT_PROPERTY(net_wm_name, _NET_WM_NAME, client_set_name)
|
2010-08-08 18:31:07 +02:00
|
|
|
HANDLE_TEXT_PROPERTY(wm_icon_name, XCB_ATOM_WM_ICON_NAME, client_set_alt_icon_name)
|
2009-08-25 16:39:10 +02:00
|
|
|
HANDLE_TEXT_PROPERTY(net_wm_icon_name, _NET_WM_ICON_NAME, client_set_icon_name)
|
2010-08-08 18:31:07 +02:00
|
|
|
HANDLE_TEXT_PROPERTY(wm_client_machine, XCB_ATOM_WM_CLIENT_MACHINE, client_set_machine)
|
2009-08-24 10:05:50 +02:00
|
|
|
HANDLE_TEXT_PROPERTY(wm_window_role, WM_WINDOW_ROLE, client_set_role)
|
|
|
|
|
|
|
|
#undef HANDLE_TEXT_PROPERTY
|
|
|
|
|
2009-08-24 11:22:28 +02:00
|
|
|
#define HANDLE_PROPERTY(name) \
|
|
|
|
static int \
|
2010-08-08 16:54:36 +02:00
|
|
|
property_handle_##name(uint8_t state, \
|
2010-08-09 13:06:32 +02:00
|
|
|
xcb_window_t window) \
|
2009-08-24 11:22:28 +02:00
|
|
|
{ \
|
|
|
|
client_t *c = client_getbywin(window); \
|
|
|
|
if(c) \
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_##name(c, property_get_##name(c));\
|
2009-08-24 11:22:28 +02:00
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE_PROPERTY(wm_protocols)
|
|
|
|
HANDLE_PROPERTY(wm_transient_for)
|
|
|
|
HANDLE_PROPERTY(wm_client_leader)
|
|
|
|
HANDLE_PROPERTY(wm_normal_hints)
|
|
|
|
HANDLE_PROPERTY(wm_hints)
|
|
|
|
HANDLE_PROPERTY(wm_class)
|
|
|
|
HANDLE_PROPERTY(net_wm_icon)
|
|
|
|
HANDLE_PROPERTY(net_wm_pid)
|
|
|
|
|
|
|
|
#undef HANDLE_PROPERTY
|
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_cookie_t
|
|
|
|
property_get_wm_transient_for(client_t *c)
|
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
return xcb_icccm_get_wm_transient_for_unchecked(globalconf.connection, c->window);
|
2010-08-09 12:47:29 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 14:09:56 +02:00
|
|
|
void
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_wm_transient_for(client_t *c, xcb_get_property_cookie_t cookie)
|
2008-09-16 14:09:56 +02:00
|
|
|
{
|
|
|
|
xcb_window_t trans;
|
2013-10-04 14:31:48 +02:00
|
|
|
int counter;
|
|
|
|
client_t *tc, *tmp;
|
2008-09-16 14:09:56 +02:00
|
|
|
|
2011-04-27 06:49:56 +02:00
|
|
|
if(!xcb_icccm_get_wm_transient_for_reply(globalconf.connection,
|
|
|
|
cookie,
|
|
|
|
&trans, NULL))
|
2008-09-16 14:09:56 +02:00
|
|
|
return;
|
|
|
|
|
2013-10-04 14:31:48 +02:00
|
|
|
tmp = tc = client_getbywin(trans);
|
|
|
|
|
2009-08-17 17:02:45 +02:00
|
|
|
luaA_object_push(globalconf.L, c);
|
|
|
|
client_set_type(globalconf.L, -1, WINDOW_TYPE_DIALOG);
|
|
|
|
client_set_above(globalconf.L, -1, false);
|
2013-10-04 14:31:48 +02:00
|
|
|
|
2013-11-23 14:42:56 +01:00
|
|
|
/* Verify that there are no loops in the transient_for relation after we are done */
|
2013-10-04 14:31:48 +02:00
|
|
|
for(counter = 0; tmp != NULL && counter <= globalconf.stack.len; counter++)
|
2013-11-23 14:42:56 +01:00
|
|
|
{
|
|
|
|
if (tmp == c)
|
|
|
|
/* We arrived back at the client we started from, so there is a loop */
|
|
|
|
counter = globalconf.stack.len+1;
|
2013-10-04 14:31:48 +02:00
|
|
|
tmp = tmp->transient_for;
|
2013-11-23 14:42:56 +01:00
|
|
|
}
|
2013-10-04 14:31:48 +02:00
|
|
|
if (counter <= globalconf.stack.len)
|
|
|
|
client_set_transient_for(globalconf.L, -1, tc);
|
|
|
|
|
2009-08-17 17:02:45 +02:00
|
|
|
lua_pop(globalconf.L, 1);
|
2008-09-16 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_cookie_t
|
|
|
|
property_get_wm_client_leader(client_t *c)
|
|
|
|
{
|
|
|
|
return xcb_get_property_unchecked(globalconf.connection, false, c->window,
|
2013-06-19 19:23:19 +02:00
|
|
|
WM_CLIENT_LEADER, XCB_ATOM_WINDOW, 0, 32);
|
2010-08-09 12:47:29 +02:00
|
|
|
}
|
|
|
|
|
2008-12-01 19:44:28 +01:00
|
|
|
/** Update leader hint of a client.
|
|
|
|
* \param c The client.
|
2010-08-09 12:47:29 +02:00
|
|
|
* \param cookie Cookie returned by property_get_wm_client_leader.
|
2008-12-01 19:44:28 +01:00
|
|
|
*/
|
|
|
|
void
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_wm_client_leader(client_t *c, xcb_get_property_cookie_t cookie)
|
2008-12-01 19:44:28 +01:00
|
|
|
{
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_reply_t *reply;
|
2008-12-01 19:44:28 +01:00
|
|
|
void *data;
|
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
reply = xcb_get_property_reply(globalconf.connection, cookie, NULL);
|
2008-12-01 19:44:28 +01:00
|
|
|
|
|
|
|
if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
|
2009-08-17 17:02:45 +02:00
|
|
|
c->leader_window = *(xcb_window_t *) data;
|
2008-12-01 19:44:28 +01:00
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
p_delete(&reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_get_property_cookie_t
|
|
|
|
property_get_wm_normal_hints(client_t *c)
|
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
return xcb_icccm_get_wm_normal_hints_unchecked(globalconf.connection, c->window);
|
2008-12-01 19:44:28 +01:00
|
|
|
}
|
|
|
|
|
2008-09-16 14:09:56 +02:00
|
|
|
/** Update the size hints of a client.
|
|
|
|
* \param c The client.
|
2010-08-09 12:47:29 +02:00
|
|
|
* \param cookie Cookie returned by property_get_wm_normal_hints.
|
2008-09-16 14:09:56 +02:00
|
|
|
*/
|
|
|
|
void
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_wm_normal_hints(client_t *c, xcb_get_property_cookie_t cookie)
|
2008-09-16 14:09:56 +02:00
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
xcb_icccm_get_wm_normal_hints_reply(globalconf.connection,
|
|
|
|
cookie,
|
|
|
|
&c->size_hints, NULL);
|
2010-08-09 12:47:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xcb_get_property_cookie_t
|
|
|
|
property_get_wm_hints(client_t *c)
|
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
return xcb_icccm_get_wm_hints_unchecked(globalconf.connection, c->window);
|
2008-09-16 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Update the WM hints of a client.
|
|
|
|
* \param c The client.
|
2010-08-09 12:47:29 +02:00
|
|
|
* \param cookie Cookie returned by property_get_wm_hints.
|
2008-09-16 14:09:56 +02:00
|
|
|
*/
|
|
|
|
void
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_wm_hints(client_t *c, xcb_get_property_cookie_t cookie)
|
2008-09-16 14:09:56 +02:00
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
xcb_icccm_wm_hints_t wmh;
|
2008-09-16 14:09:56 +02:00
|
|
|
|
2011-04-27 06:49:56 +02:00
|
|
|
if(!xcb_icccm_get_wm_hints_reply(globalconf.connection,
|
|
|
|
cookie,
|
|
|
|
&wmh, NULL))
|
2010-08-09 12:47:29 +02:00
|
|
|
return;
|
2008-09-16 14:09:56 +02:00
|
|
|
|
2009-08-17 17:02:45 +02:00
|
|
|
luaA_object_push(globalconf.L, c);
|
2011-04-27 06:49:56 +02:00
|
|
|
client_set_urgent(globalconf.L, -1, xcb_icccm_wm_hints_get_urgency(&wmh));
|
2008-09-16 14:09:56 +02:00
|
|
|
|
2011-04-27 06:49:56 +02:00
|
|
|
if(wmh.flags & XCB_ICCCM_WM_HINT_INPUT)
|
2008-10-11 09:52:03 +02:00
|
|
|
c->nofocus = !wmh.input;
|
2008-12-01 19:06:35 +01:00
|
|
|
|
2011-04-27 06:49:56 +02:00
|
|
|
if(wmh.flags & XCB_ICCCM_WM_HINT_WINDOW_GROUP)
|
2009-08-17 17:02:45 +02:00
|
|
|
client_set_group_window(globalconf.L, -1, wmh.window_group);
|
2010-02-09 14:02:38 +01:00
|
|
|
|
|
|
|
lua_pop(globalconf.L, 1);
|
2008-09-16 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_cookie_t
|
|
|
|
property_get_wm_class(client_t *c)
|
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
return xcb_icccm_get_wm_class_unchecked(globalconf.connection, c->window);
|
2010-08-09 12:47:29 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 14:20:06 +02:00
|
|
|
/** Update WM_CLASS of a client.
|
|
|
|
* \param c The client.
|
2010-08-09 12:47:29 +02:00
|
|
|
* \param cookie Cookie returned by property_get_wm_class.
|
2009-04-18 14:20:06 +02:00
|
|
|
*/
|
2009-04-04 13:41:17 +02:00
|
|
|
void
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_wm_class(client_t *c, xcb_get_property_cookie_t cookie)
|
2009-04-04 13:41:17 +02:00
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
xcb_icccm_get_wm_class_reply_t hint;
|
2009-04-04 13:41:17 +02:00
|
|
|
|
2011-04-27 06:49:56 +02:00
|
|
|
if(!xcb_icccm_get_wm_class_reply(globalconf.connection,
|
|
|
|
cookie,
|
|
|
|
&hint, NULL))
|
2010-08-09 12:47:29 +02:00
|
|
|
return;
|
2009-04-18 14:20:06 +02:00
|
|
|
|
2009-08-17 17:02:45 +02:00
|
|
|
luaA_object_push(globalconf.L, c);
|
2009-08-24 23:02:46 +02:00
|
|
|
client_set_class_instance(globalconf.L, -1, hint.class_name, hint.instance_name);
|
2009-08-17 17:02:45 +02:00
|
|
|
lua_pop(globalconf.L, 1);
|
2009-04-04 13:41:17 +02:00
|
|
|
|
2011-04-27 06:49:56 +02:00
|
|
|
xcb_icccm_get_wm_class_reply_wipe(&hint);
|
2009-04-04 13:41:17 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 14:09:56 +02:00
|
|
|
static int
|
2010-08-08 16:54:36 +02:00
|
|
|
property_handle_net_wm_strut_partial(uint8_t state,
|
2010-08-09 13:06:32 +02:00
|
|
|
xcb_window_t window)
|
2008-09-16 14:09:56 +02:00
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
2010-08-09 13:04:08 +02:00
|
|
|
ewmh_process_client_strut(c);
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_cookie_t
|
|
|
|
property_get_net_wm_icon(client_t *c)
|
|
|
|
{
|
|
|
|
return ewmh_window_icon_get_unchecked(c->window);
|
|
|
|
}
|
|
|
|
|
2009-08-17 17:02:45 +02:00
|
|
|
void
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_net_wm_icon(client_t *c, xcb_get_property_cookie_t cookie)
|
2009-08-17 17:02:45 +02:00
|
|
|
{
|
2012-05-28 09:29:47 +02:00
|
|
|
cairo_surface_t *surface = ewmh_window_icon_get_reply(cookie);
|
2009-08-17 17:02:45 +02:00
|
|
|
|
2012-05-28 09:29:47 +02:00
|
|
|
if(!surface)
|
|
|
|
return;
|
2009-08-17 17:02:45 +02:00
|
|
|
|
2012-05-28 09:29:47 +02:00
|
|
|
client_set_icon(c, surface);
|
|
|
|
cairo_surface_destroy(surface);
|
2009-08-17 17:02:45 +02:00
|
|
|
}
|
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_cookie_t
|
|
|
|
property_get_net_wm_pid(client_t *c)
|
|
|
|
{
|
|
|
|
return xcb_get_property_unchecked(globalconf.connection, false, c->window, _NET_WM_PID, XCB_ATOM_CARDINAL, 0L, 1L);
|
|
|
|
}
|
|
|
|
|
2009-08-10 11:40:06 +02:00
|
|
|
void
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_net_wm_pid(client_t *c, xcb_get_property_cookie_t cookie)
|
2009-08-10 11:40:06 +02:00
|
|
|
{
|
2010-08-09 12:47:29 +02:00
|
|
|
xcb_get_property_reply_t *reply;
|
2009-08-10 11:40:06 +02:00
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
reply = xcb_get_property_reply(globalconf.connection, cookie, NULL);
|
2009-08-10 11:40:06 +02:00
|
|
|
|
|
|
|
if(reply && reply->value_len)
|
|
|
|
{
|
|
|
|
uint32_t *rdata = xcb_get_property_value(reply);
|
|
|
|
if(rdata)
|
2009-08-17 17:02:45 +02:00
|
|
|
{
|
|
|
|
luaA_object_push(globalconf.L, c);
|
|
|
|
client_set_pid(globalconf.L, -1, *rdata);
|
|
|
|
lua_pop(globalconf.L, 1);
|
|
|
|
}
|
2009-08-10 11:40:06 +02:00
|
|
|
}
|
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
p_delete(&reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_get_property_cookie_t
|
|
|
|
property_get_wm_protocols(client_t *c)
|
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
return xcb_icccm_get_wm_protocols_unchecked(globalconf.connection,
|
|
|
|
c->window, WM_PROTOCOLS);
|
2009-08-10 11:40:06 +02:00
|
|
|
}
|
|
|
|
|
2009-06-24 17:59:19 +02:00
|
|
|
/** Update the list of supported protocols for a client.
|
|
|
|
* \param c The client.
|
2010-08-09 12:47:29 +02:00
|
|
|
* \param cookie Cookie from property_get_wm_protocols.
|
2009-06-24 17:59:19 +02:00
|
|
|
*/
|
|
|
|
void
|
2010-08-09 12:47:29 +02:00
|
|
|
property_update_wm_protocols(client_t *c, xcb_get_property_cookie_t cookie)
|
2009-06-24 17:59:19 +02:00
|
|
|
{
|
2011-04-27 06:49:56 +02:00
|
|
|
xcb_icccm_get_wm_protocols_reply_t protocols;
|
2010-03-22 14:17:27 +01:00
|
|
|
|
2010-08-09 12:47:29 +02:00
|
|
|
/* If this fails for any reason, we still got the old value */
|
2011-04-27 06:49:56 +02:00
|
|
|
if(!xcb_icccm_get_wm_protocols_reply(globalconf.connection,
|
|
|
|
cookie,
|
|
|
|
&protocols, NULL))
|
2010-08-09 12:47:29 +02:00
|
|
|
return;
|
2009-08-24 11:11:52 +02:00
|
|
|
|
2011-04-27 06:49:56 +02:00
|
|
|
xcb_icccm_get_wm_protocols_reply_wipe(&c->protocols);
|
2009-08-24 11:11:52 +02:00
|
|
|
memcpy(&c->protocols, &protocols, sizeof(protocols));
|
2009-06-24 17:59:19 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 14:09:56 +02:00
|
|
|
/** The property notify event handler.
|
2009-07-27 06:20:00 +02:00
|
|
|
* \param state currently unused
|
|
|
|
* \param window The window to obtain update the property with.
|
|
|
|
* \param name The protocol atom, currently unused.
|
|
|
|
* \param reply (Optional) An existing reply.
|
2008-09-16 14:09:56 +02:00
|
|
|
*/
|
|
|
|
static int
|
2010-08-08 16:54:36 +02:00
|
|
|
property_handle_xembed_info(uint8_t state,
|
2010-08-09 13:06:32 +02:00
|
|
|
xcb_window_t window)
|
2008-09-16 14:09:56 +02:00
|
|
|
{
|
2008-12-01 16:43:44 +01:00
|
|
|
xembed_window_t *emwin = xembed_getbywin(&globalconf.embedded, window);
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
if(emwin)
|
2010-08-09 13:04:08 +02:00
|
|
|
{
|
|
|
|
xcb_get_property_cookie_t cookie =
|
|
|
|
xcb_get_property(globalconf.connection, 0, window, _XEMBED_INFO,
|
|
|
|
XCB_GET_PROPERTY_TYPE_ANY, 0, 3);
|
|
|
|
xcb_get_property_reply_t *propr =
|
|
|
|
xcb_get_property_reply(globalconf.connection, cookie, 0);
|
|
|
|
xembed_property_update(globalconf.connection, emwin, propr);
|
|
|
|
p_delete(&propr);
|
|
|
|
}
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-25 16:27:17 +02:00
|
|
|
static int
|
2010-08-08 16:54:36 +02:00
|
|
|
property_handle_net_wm_opacity(uint8_t state,
|
2010-08-09 13:06:32 +02:00
|
|
|
xcb_window_t window)
|
2009-05-25 16:27:17 +02:00
|
|
|
{
|
2010-10-06 13:35:14 +02:00
|
|
|
drawin_t *drawin = drawin_getbywin(window);
|
2009-05-25 16:27:17 +02:00
|
|
|
|
2010-10-06 13:35:14 +02:00
|
|
|
if(drawin)
|
2009-08-17 16:56:03 +02:00
|
|
|
{
|
2010-10-06 13:35:14 +02:00
|
|
|
luaA_object_push(globalconf.L, drawin);
|
|
|
|
window_set_opacity(globalconf.L, -1, xwindow_get_opacity(drawin->window));
|
2009-08-17 16:56:03 +02:00
|
|
|
lua_pop(globalconf.L, -1);
|
|
|
|
}
|
2009-08-10 11:59:17 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
if(c)
|
2009-08-17 17:02:45 +02:00
|
|
|
{
|
|
|
|
luaA_object_push(globalconf.L, c);
|
2010-08-09 13:04:08 +02:00
|
|
|
window_set_opacity(globalconf.L, -1, xwindow_get_opacity(c->window));
|
2009-08-17 17:02:45 +02:00
|
|
|
lua_pop(globalconf.L, 1);
|
|
|
|
}
|
2009-08-10 11:59:17 +02:00
|
|
|
}
|
|
|
|
|
2009-05-25 16:27:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-07 21:52:24 +02:00
|
|
|
static int
|
|
|
|
property_handle_xrootpmap_id(uint8_t state,
|
|
|
|
xcb_window_t window)
|
|
|
|
{
|
|
|
|
signal_object_emit(globalconf.L, &global_signals, "wallpaper_changed", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-07 13:49:24 +01:00
|
|
|
/** The property notify event handler handling xproperties.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
property_handle_propertynotify_xproperty(xcb_property_notify_event_t *ev)
|
|
|
|
{
|
|
|
|
xproperty_t *prop;
|
|
|
|
xproperty_t lookup = { .atom = ev->atom };
|
|
|
|
buffer_t buf;
|
|
|
|
void *obj;
|
|
|
|
|
|
|
|
prop = xproperty_array_lookup(&globalconf.xproperties, &lookup);
|
|
|
|
if(!prop)
|
|
|
|
/* Property is not registered */
|
|
|
|
return;
|
|
|
|
|
2014-03-23 18:23:38 +01:00
|
|
|
if (ev->window != globalconf.screen->root)
|
|
|
|
{
|
|
|
|
obj = client_getbywin(ev->window);
|
|
|
|
if(!obj)
|
|
|
|
obj = drawin_getbywin(ev->window);
|
|
|
|
if(!obj)
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
obj = NULL;
|
2014-03-07 13:49:24 +01:00
|
|
|
|
|
|
|
/* Get us the name of the property */
|
|
|
|
buffer_inita(&buf, a_strlen(prop->name) + a_strlen("xproperty::") + 1);
|
|
|
|
buffer_addf(&buf, "xproperty::%s", prop->name);
|
|
|
|
|
|
|
|
/* And emit the right signal */
|
2014-03-23 18:23:38 +01:00
|
|
|
if (obj)
|
|
|
|
{
|
|
|
|
luaA_object_push(globalconf.L, obj);
|
|
|
|
luaA_object_emit_signal(globalconf.L, -1, buf.s, 0);
|
|
|
|
lua_pop(globalconf.L, 1);
|
|
|
|
} else
|
|
|
|
signal_object_emit(globalconf.L, &global_signals, buf.s, 0);
|
2014-03-07 13:49:24 +01:00
|
|
|
buffer_wipe(&buf);
|
|
|
|
}
|
2012-04-07 21:52:24 +02:00
|
|
|
|
2010-08-08 16:45:56 +02:00
|
|
|
/** The property notify event handler.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
2010-08-08 17:54:13 +02:00
|
|
|
void
|
|
|
|
property_handle_propertynotify(xcb_property_notify_event_t *ev)
|
2008-09-16 14:09:56 +02:00
|
|
|
{
|
2010-08-08 16:54:36 +02:00
|
|
|
int (*handler)(uint8_t state,
|
2010-08-09 13:06:32 +02:00
|
|
|
xcb_window_t window) = NULL;
|
2010-08-08 16:45:56 +02:00
|
|
|
|
2010-08-12 14:37:39 +02:00
|
|
|
globalconf.timestamp = ev->time;
|
|
|
|
|
2014-03-07 13:49:24 +01:00
|
|
|
property_handle_propertynotify_xproperty(ev);
|
|
|
|
|
2010-08-08 16:45:56 +02:00
|
|
|
/* Find the correct event handler */
|
2010-08-09 13:04:08 +02:00
|
|
|
#define HANDLE(atom_, cb) \
|
2010-08-08 16:45:56 +02:00
|
|
|
if (ev->atom == atom_) \
|
|
|
|
{ \
|
|
|
|
handler = cb; \
|
|
|
|
} else
|
2010-08-08 17:54:13 +02:00
|
|
|
#define END return
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
/* Xembed stuff */
|
2010-08-09 13:04:08 +02:00
|
|
|
HANDLE(_XEMBED_INFO, property_handle_xembed_info)
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
/* ICCCM stuff */
|
2010-08-09 13:04:08 +02:00
|
|
|
HANDLE(XCB_ATOM_WM_TRANSIENT_FOR, property_handle_wm_transient_for)
|
|
|
|
HANDLE(WM_CLIENT_LEADER, property_handle_wm_client_leader)
|
|
|
|
HANDLE(XCB_ATOM_WM_NORMAL_HINTS, property_handle_wm_normal_hints)
|
|
|
|
HANDLE(XCB_ATOM_WM_HINTS, property_handle_wm_hints)
|
|
|
|
HANDLE(XCB_ATOM_WM_NAME, property_handle_wm_name)
|
|
|
|
HANDLE(XCB_ATOM_WM_ICON_NAME, property_handle_wm_icon_name)
|
|
|
|
HANDLE(XCB_ATOM_WM_CLASS, property_handle_wm_class)
|
|
|
|
HANDLE(WM_PROTOCOLS, property_handle_wm_protocols)
|
|
|
|
HANDLE(XCB_ATOM_WM_CLIENT_MACHINE, property_handle_wm_client_machine)
|
|
|
|
HANDLE(WM_WINDOW_ROLE, property_handle_wm_window_role)
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
/* EWMH stuff */
|
2010-08-09 13:04:08 +02:00
|
|
|
HANDLE(_NET_WM_NAME, property_handle_net_wm_name)
|
|
|
|
HANDLE(_NET_WM_ICON_NAME, property_handle_net_wm_icon_name)
|
|
|
|
HANDLE(_NET_WM_STRUT_PARTIAL, property_handle_net_wm_strut_partial)
|
|
|
|
HANDLE(_NET_WM_ICON, property_handle_net_wm_icon)
|
|
|
|
HANDLE(_NET_WM_PID, property_handle_net_wm_pid)
|
|
|
|
HANDLE(_NET_WM_WINDOW_OPACITY, property_handle_net_wm_opacity)
|
2008-10-06 11:42:02 +02:00
|
|
|
|
2012-04-07 21:52:24 +02:00
|
|
|
/* background change */
|
|
|
|
HANDLE(_XROOTPMAP_ID, property_handle_xrootpmap_id)
|
|
|
|
|
2010-08-08 16:45:56 +02:00
|
|
|
/* If nothing was found, return */
|
|
|
|
END;
|
|
|
|
|
2010-08-09 13:04:08 +02:00
|
|
|
#undef HANDLE
|
2010-08-08 16:45:56 +02:00
|
|
|
#undef END
|
|
|
|
|
2010-08-09 13:06:32 +02:00
|
|
|
(*handler)(ev->state, ev->window);
|
2010-08-08 16:45:56 +02:00
|
|
|
}
|
|
|
|
|
2014-03-07 13:49:24 +01:00
|
|
|
/** Register a new xproperty.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam The name of the X11 property
|
|
|
|
* \lparam One of "string", "number" or "boolean"
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_register_xproperty(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
struct xproperty property;
|
|
|
|
struct xproperty *found;
|
|
|
|
const char *const args[] = { "string", "number", "boolean" };
|
|
|
|
xcb_intern_atom_reply_t *atom_r;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
name = luaL_checkstring(L, 1);
|
|
|
|
type = luaL_checkoption(L, 2, NULL, args);
|
|
|
|
if (type == 0)
|
|
|
|
property.type = PROP_STRING;
|
|
|
|
else if (type == 1)
|
|
|
|
property.type = PROP_NUMBER;
|
|
|
|
else
|
|
|
|
property.type = PROP_BOOLEAN;
|
|
|
|
|
|
|
|
atom_r = xcb_intern_atom_reply(globalconf.connection,
|
|
|
|
xcb_intern_atom_unchecked(globalconf.connection, false,
|
|
|
|
a_strlen(name), name),
|
|
|
|
NULL);
|
|
|
|
if(!atom_r)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
property.atom = atom_r->atom;
|
|
|
|
p_delete(&atom_r);
|
|
|
|
|
|
|
|
found = xproperty_array_lookup(&globalconf.xproperties, &property);
|
|
|
|
if(found)
|
|
|
|
{
|
|
|
|
/* Property already registered */
|
|
|
|
if(found->type != property.type)
|
|
|
|
return luaL_error(L, "xproperty '%s' already registered with different type", name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer_t buf;
|
|
|
|
buffer_inita(&buf, a_strlen(name) + a_strlen("xproperty::") + 1);
|
|
|
|
buffer_addf(&buf, "xproperty::%s", name);
|
|
|
|
|
|
|
|
property.name = a_strdup(name);
|
|
|
|
xproperty_array_insert(&globalconf.xproperties, property);
|
|
|
|
signal_add(&window_class.signals, buf.s);
|
2014-03-23 18:23:38 +01:00
|
|
|
signal_add(&global_signals, buf.s);
|
2014-03-07 13:49:24 +01:00
|
|
|
buffer_wipe(&buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-23 18:15:03 +01:00
|
|
|
/** Set an xproperty.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_set_xproperty(lua_State *L)
|
|
|
|
{
|
|
|
|
return window_set_xproperty(L, globalconf.screen->root, 1, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get an xproperty.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
luaA_get_xproperty(lua_State *L)
|
|
|
|
{
|
|
|
|
return window_get_xproperty(L, globalconf.screen->root, 1);
|
|
|
|
}
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|