2008-09-16 14:09:56 +02:00
|
|
|
/*
|
|
|
|
* property.c - property handlers
|
|
|
|
*
|
|
|
|
* 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_atom.h>
|
|
|
|
|
2009-04-17 16:14:09 +02:00
|
|
|
#include "screen.h"
|
2008-09-16 14:09:56 +02:00
|
|
|
#include "property.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "ewmh.h"
|
2009-05-10 14:55:13 +02:00
|
|
|
#include "wibox.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"
|
2009-05-25 16:27:17 +02:00
|
|
|
#include "window.h"
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
property_update_wm_transient_for(client_t *c, xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
xcb_window_t trans;
|
|
|
|
|
|
|
|
if(reply)
|
|
|
|
{
|
|
|
|
if(!xcb_get_wm_transient_for_from_reply(&trans, reply))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!xcb_get_wm_transient_for_reply(globalconf.connection,
|
|
|
|
xcb_get_wm_transient_for_unchecked(globalconf.connection,
|
|
|
|
c->win),
|
|
|
|
&trans, NULL))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-16 18:07:42 +02:00
|
|
|
c->type = WINDOW_TYPE_DIALOG;
|
|
|
|
c->transient_for = client_getbywin(trans);
|
2009-03-26 22:13:43 +01:00
|
|
|
client_setabove(c, false);
|
2008-09-16 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
property_handle_wm_transient_for(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
2008-12-01 16:26:41 +01:00
|
|
|
if(c)
|
2008-09-16 14:09:56 +02:00
|
|
|
property_update_wm_transient_for(c, reply);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-01 19:44:28 +01:00
|
|
|
|
|
|
|
/** Update leader hint of a client.
|
|
|
|
* \param c The client.
|
|
|
|
* \param reply (Optional) An existing reply.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
property_update_wm_client_leader(client_t *c, xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
xcb_get_property_cookie_t client_leader_q;
|
|
|
|
void *data;
|
|
|
|
bool no_reply = !reply;
|
|
|
|
|
|
|
|
if(no_reply)
|
|
|
|
{
|
|
|
|
client_leader_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
|
|
|
|
WM_CLIENT_LEADER, WINDOW, 0, 32);
|
|
|
|
|
|
|
|
reply = xcb_get_property_reply(globalconf.connection, client_leader_q, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
|
|
|
|
c->leader_win = *(xcb_window_t *) data;
|
|
|
|
|
|
|
|
/* Only free when we created a reply ourselves. */
|
|
|
|
if(no_reply)
|
|
|
|
p_delete(&reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
property_handle_wm_client_leader(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
|
|
|
property_update_wm_client_leader(c, reply);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-16 14:09:56 +02:00
|
|
|
/** Update the size hints of a client.
|
|
|
|
* \param c The client.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
property_update_wm_normal_hints(client_t *c, xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
if(reply)
|
|
|
|
{
|
|
|
|
if(!xcb_get_wm_size_hints_from_reply(&c->size_hints, reply))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!xcb_get_wm_normal_hints_reply(globalconf.connection,
|
|
|
|
xcb_get_wm_normal_hints_unchecked(globalconf.connection,
|
|
|
|
c->win),
|
|
|
|
&c->size_hints, NULL))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
property_handle_wm_normal_hints(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
|
|
|
property_update_wm_normal_hints(c, reply);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Update the WM hints of a client.
|
|
|
|
* \param c The client.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
property_update_wm_hints(client_t *c, xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
xcb_wm_hints_t wmh;
|
|
|
|
|
|
|
|
if(reply)
|
|
|
|
{
|
|
|
|
if(!xcb_get_wm_hints_from_reply(&wmh, reply))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!xcb_get_wm_hints_reply(globalconf.connection,
|
|
|
|
xcb_get_wm_hints_unchecked(globalconf.connection, c->win),
|
|
|
|
&wmh, NULL))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isurgent = xcb_wm_hints_get_urgency(&wmh);
|
2009-02-11 18:41:58 +01:00
|
|
|
client_seturgent(c, isurgent);
|
2008-10-11 09:52:03 +02:00
|
|
|
if(wmh.flags & XCB_WM_HINT_STATE &&
|
2008-09-16 14:09:56 +02:00
|
|
|
wmh.initial_state == XCB_WM_STATE_WITHDRAWN)
|
|
|
|
client_setborder(c, 0);
|
|
|
|
|
2008-10-11 09:52:03 +02:00
|
|
|
if(wmh.flags & XCB_WM_HINT_INPUT)
|
|
|
|
c->nofocus = !wmh.input;
|
2008-12-01 19:06:35 +01:00
|
|
|
|
|
|
|
if(wmh.flags & XCB_WM_HINT_WINDOW_GROUP)
|
|
|
|
c->group_win = wmh.window_group;
|
2008-09-16 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
property_handle_wm_hints(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
|
|
|
property_update_wm_hints(c, reply);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Update client name attribute with its new title.
|
|
|
|
* \param c The client.
|
|
|
|
* \param Return true if it has been updated.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
property_update_wm_name(client_t *c)
|
|
|
|
{
|
2009-02-20 11:07:39 +01:00
|
|
|
char *name;
|
2008-09-16 14:09:56 +02:00
|
|
|
ssize_t len;
|
|
|
|
|
|
|
|
if(!xutil_text_prop_get(globalconf.connection, c->win, _NET_WM_NAME, &name, &len))
|
|
|
|
if(!xutil_text_prop_get(globalconf.connection, c->win, WM_NAME, &name, &len))
|
|
|
|
return;
|
|
|
|
|
|
|
|
p_delete(&c->name);
|
|
|
|
|
2009-02-20 11:07:39 +01:00
|
|
|
c->name = name;
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
/* call hook */
|
2009-05-07 14:11:15 +02:00
|
|
|
hook_property(client, c, "name");
|
2008-09-16 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 14:20:06 +02:00
|
|
|
/** Update WM_CLASS of a client.
|
|
|
|
* \param c The client.
|
|
|
|
* \param reply The reply to get property request, or NULL if none.
|
|
|
|
*/
|
2009-04-04 13:41:17 +02:00
|
|
|
void
|
2009-04-18 14:20:06 +02:00
|
|
|
property_update_wm_class(client_t *c, xcb_get_property_reply_t *reply)
|
2009-04-04 13:41:17 +02:00
|
|
|
{
|
|
|
|
xcb_get_wm_class_reply_t hint;
|
|
|
|
|
2009-04-18 14:20:06 +02:00
|
|
|
if(reply)
|
|
|
|
{
|
|
|
|
if(!xcb_get_wm_class_from_reply(&hint, reply))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!xcb_get_wm_class_reply(globalconf.connection,
|
|
|
|
xcb_get_wm_class_unchecked(globalconf.connection, c->win),
|
|
|
|
&hint, NULL))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-04 13:41:17 +02:00
|
|
|
p_delete(&c->instance);
|
|
|
|
p_delete(&c->class);
|
|
|
|
|
2009-04-18 14:20:06 +02:00
|
|
|
c->instance = a_strdup(hint.instance_name);
|
|
|
|
c->class = a_strdup(hint.class_name);
|
2009-04-21 08:46:36 +02:00
|
|
|
/* only delete reply if we get it ourselves */
|
|
|
|
if(!reply)
|
|
|
|
xcb_get_wm_class_reply_wipe(&hint);
|
2009-04-04 13:41:17 +02:00
|
|
|
}
|
|
|
|
|
2008-10-21 15:12:55 +02:00
|
|
|
/** Update client icon name attribute with its new title.
|
|
|
|
* \param c The client.
|
|
|
|
* \param Return true if it has been updated.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
property_update_wm_icon_name(client_t *c)
|
|
|
|
{
|
2009-02-20 11:07:39 +01:00
|
|
|
char *name;
|
2008-10-21 15:12:55 +02:00
|
|
|
ssize_t len;
|
|
|
|
|
|
|
|
if(!xutil_text_prop_get(globalconf.connection, c->win, _NET_WM_ICON_NAME, &name, &len))
|
|
|
|
if(!xutil_text_prop_get(globalconf.connection, c->win, WM_ICON_NAME, &name, &len))
|
|
|
|
return;
|
|
|
|
|
|
|
|
p_delete(&c->icon_name);
|
|
|
|
|
2009-02-20 11:07:39 +01:00
|
|
|
c->icon_name = name;
|
2008-10-21 15:12:55 +02:00
|
|
|
|
|
|
|
/* call hook */
|
2009-05-07 14:11:15 +02:00
|
|
|
hook_property(client, c, "icon_name");
|
2008-10-21 15:12:55 +02:00
|
|
|
}
|
|
|
|
|
2008-09-16 14:09:56 +02:00
|
|
|
static int
|
|
|
|
property_handle_wm_name(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
|
|
|
property_update_wm_name(c);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-21 15:12:55 +02:00
|
|
|
static int
|
|
|
|
property_handle_wm_icon_name(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
|
|
|
property_update_wm_icon_name(c);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-04 13:41:17 +02:00
|
|
|
static int
|
|
|
|
property_handle_wm_class(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
2009-04-18 14:20:06 +02:00
|
|
|
property_update_wm_class(c, reply);
|
2009-04-04 13:41:17 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-16 14:09:56 +02:00
|
|
|
static int
|
|
|
|
property_handle_net_wm_strut_partial(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
2009-02-07 19:40:07 +01:00
|
|
|
ewmh_process_client_strut(c, reply);
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
property_handle_net_wm_icon(void *data,
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
client_t *c = client_getbywin(window);
|
|
|
|
|
|
|
|
if(c)
|
|
|
|
{
|
2009-04-09 11:38:56 +02:00
|
|
|
image_unref(globalconf.L, c->icon);
|
|
|
|
if(ewmh_window_icon_from_reply(reply))
|
2009-06-16 17:14:48 +02:00
|
|
|
c->icon = image_ref(globalconf.L, -1);
|
2009-06-18 12:13:00 +02:00
|
|
|
else
|
|
|
|
c->icon = NULL;
|
2008-09-22 17:54:48 +02:00
|
|
|
/* execute hook */
|
2009-05-07 14:11:15 +02:00
|
|
|
hook_property(client, c, "icon");
|
2008-09-16 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** The property notify event handler.
|
|
|
|
* \param data currently unused.
|
|
|
|
* \param connection The connection to the X server.
|
|
|
|
* \param ev The event.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
property_handle_xembed_info(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
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)
|
|
|
|
xembed_property_update(connection, emwin, reply);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-06 11:42:02 +02:00
|
|
|
static int
|
|
|
|
property_handle_xrootpmap_id(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
if(globalconf.xinerama_is_active)
|
2009-05-10 14:55:13 +02:00
|
|
|
foreach(w, globalconf.wiboxes)
|
|
|
|
(*w)->need_update = true;
|
2008-10-06 11:42:02 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int screen = xutil_root2screen(connection, window);
|
2009-05-10 14:55:13 +02:00
|
|
|
foreach(w, globalconf.wiboxes)
|
|
|
|
if(screen == screen_array_indexof(&globalconf.screens, (*w)->screen))
|
|
|
|
(*w)->need_update = true;
|
2008-10-06 11:42:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-25 16:27:17 +02:00
|
|
|
static int
|
|
|
|
property_handle_opacity(void *data __attribute__ ((unused)),
|
|
|
|
xcb_connection_t *connection,
|
|
|
|
uint8_t state,
|
|
|
|
xcb_window_t window,
|
|
|
|
xcb_atom_t name,
|
|
|
|
xcb_get_property_reply_t *reply)
|
|
|
|
{
|
|
|
|
wibox_t *wibox = wibox_getbywin(window);
|
|
|
|
|
|
|
|
if (wibox)
|
|
|
|
wibox->sw.opacity = window_opacity_get_from_reply(reply);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-16 14:09:56 +02:00
|
|
|
void a_xcb_set_property_handlers(void)
|
|
|
|
{
|
|
|
|
/* init */
|
|
|
|
xcb_property_handlers_init(&globalconf.prophs, &globalconf.evenths);
|
|
|
|
|
|
|
|
/* Xembed stuff */
|
|
|
|
xcb_property_set_handler(&globalconf.prophs, _XEMBED_INFO, UINT_MAX,
|
|
|
|
property_handle_xembed_info, NULL);
|
|
|
|
|
|
|
|
/* ICCCM stuff */
|
|
|
|
xcb_property_set_handler(&globalconf.prophs, WM_TRANSIENT_FOR, UINT_MAX,
|
|
|
|
property_handle_wm_transient_for, NULL);
|
2008-12-01 19:44:28 +01:00
|
|
|
xcb_property_set_handler(&globalconf.prophs, WM_CLIENT_LEADER, UINT_MAX,
|
|
|
|
property_handle_wm_client_leader, NULL);
|
2008-09-16 14:09:56 +02:00
|
|
|
xcb_property_set_handler(&globalconf.prophs, WM_NORMAL_HINTS, UINT_MAX,
|
|
|
|
property_handle_wm_normal_hints, NULL);
|
|
|
|
xcb_property_set_handler(&globalconf.prophs, WM_HINTS, UINT_MAX,
|
|
|
|
property_handle_wm_hints, NULL);
|
|
|
|
xcb_property_set_handler(&globalconf.prophs, WM_NAME, UINT_MAX,
|
|
|
|
property_handle_wm_name, NULL);
|
2008-10-21 15:12:55 +02:00
|
|
|
xcb_property_set_handler(&globalconf.prophs, WM_ICON_NAME, UINT_MAX,
|
|
|
|
property_handle_wm_icon_name, NULL);
|
2009-04-04 13:41:17 +02:00
|
|
|
xcb_property_set_handler(&globalconf.prophs, WM_CLASS, UINT_MAX,
|
|
|
|
property_handle_wm_class, NULL);
|
2008-09-16 14:09:56 +02:00
|
|
|
|
|
|
|
/* EWMH stuff */
|
|
|
|
xcb_property_set_handler(&globalconf.prophs, _NET_WM_NAME, UINT_MAX,
|
|
|
|
property_handle_wm_name, NULL);
|
2008-10-21 15:12:55 +02:00
|
|
|
xcb_property_set_handler(&globalconf.prophs, _NET_WM_ICON_NAME, UINT_MAX,
|
|
|
|
property_handle_wm_icon_name, NULL);
|
2008-09-16 14:09:56 +02:00
|
|
|
xcb_property_set_handler(&globalconf.prophs, _NET_WM_STRUT_PARTIAL, UINT_MAX,
|
|
|
|
property_handle_net_wm_strut_partial, NULL);
|
|
|
|
xcb_property_set_handler(&globalconf.prophs, _NET_WM_ICON, UINT_MAX,
|
|
|
|
property_handle_net_wm_icon, NULL);
|
2008-10-06 11:42:02 +02:00
|
|
|
|
|
|
|
/* background change */
|
|
|
|
xcb_property_set_handler(&globalconf.prophs, _XROOTPMAP_ID, 1,
|
|
|
|
property_handle_xrootpmap_id, NULL);
|
2009-05-25 16:27:17 +02:00
|
|
|
|
|
|
|
/* Opacity */
|
|
|
|
xcb_property_set_handler(&globalconf.prophs, _NET_WM_WINDOW_OPACITY, 1,
|
|
|
|
property_handle_opacity, NULL);
|
2008-09-16 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|