property: macrotify all text property retrieval
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
e56ef78d92
commit
e5048f72d5
22
client.c
22
client.c
|
@ -150,30 +150,30 @@ client_set_pid(lua_State *L, int cidx, uint32_t pid)
|
|||
}
|
||||
|
||||
void
|
||||
client_set_icon_name(lua_State *L, int cidx, const char *icon_name)
|
||||
client_set_icon_name(lua_State *L, int cidx, char *icon_name)
|
||||
{
|
||||
client_t *c = luaA_client_checkudata(L, cidx);
|
||||
p_delete(&c->icon_name);
|
||||
c->icon_name = a_strdup(icon_name);
|
||||
c->icon_name = icon_name;
|
||||
luaA_object_emit_signal(L, cidx, "property::icon_name", 0);
|
||||
hook_property(c, "icon_name");
|
||||
}
|
||||
|
||||
void
|
||||
client_set_role(lua_State *L, int cidx, const char *role)
|
||||
client_set_role(lua_State *L, int cidx, char *role)
|
||||
{
|
||||
client_t *c = luaA_client_checkudata(L, cidx);
|
||||
p_delete(&c->role);
|
||||
c->role = a_strdup(role);
|
||||
c->role = role;
|
||||
luaA_object_emit_signal(L, cidx, "property::role", 0);
|
||||
}
|
||||
|
||||
void
|
||||
client_set_machine(lua_State *L, int cidx, const char *machine)
|
||||
client_set_machine(lua_State *L, int cidx, char *machine)
|
||||
{
|
||||
client_t *c = luaA_client_checkudata(L, cidx);
|
||||
p_delete(&c->machine);
|
||||
c->machine = a_strdup(machine);
|
||||
c->machine = machine;
|
||||
luaA_object_emit_signal(L, cidx, "property::machine", 0);
|
||||
}
|
||||
|
||||
|
@ -202,11 +202,11 @@ client_set_transient_for(lua_State *L, int cidx, client_t *transient_for)
|
|||
}
|
||||
|
||||
void
|
||||
client_set_name(lua_State *L, int cidx, const char *name)
|
||||
client_set_name(lua_State *L, int cidx, char *name)
|
||||
{
|
||||
client_t *c = luaA_client_checkudata(L, cidx);
|
||||
p_delete(&c->name);
|
||||
c->name = a_strdup(name);
|
||||
c->name = name;
|
||||
hook_property(c, "name");
|
||||
luaA_object_emit_signal(L, cidx, "property::name", 0);
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen,
|
|||
property_update_wm_transient_for(c, NULL);
|
||||
property_update_wm_client_leader(c, NULL);
|
||||
property_update_wm_client_machine(c, NULL);
|
||||
property_update_wm_window_role(c);
|
||||
property_update_wm_window_role(c, NULL);
|
||||
property_update_net_wm_pid(c, NULL);
|
||||
property_update_net_wm_icon(c, NULL);
|
||||
|
||||
|
@ -647,8 +647,8 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen,
|
|||
client_raise(c);
|
||||
|
||||
/* update window title */
|
||||
property_update_wm_name(c);
|
||||
property_update_wm_icon_name(c);
|
||||
property_update_wm_name(c, NULL);
|
||||
property_update_wm_icon_name(c, NULL);
|
||||
property_update_wm_class(c, NULL);
|
||||
property_update_wm_protocols(c);
|
||||
|
||||
|
|
8
client.h
8
client.h
|
@ -188,13 +188,13 @@ void client_set_minimized(lua_State *, int, bool);
|
|||
void client_set_border_width(lua_State *, int, int);
|
||||
void client_set_urgent(lua_State *, int, bool);
|
||||
void client_set_pid(lua_State *, int, uint32_t);
|
||||
void client_set_role(lua_State *, int, const char *);
|
||||
void client_set_machine(lua_State *, int, const char *);
|
||||
void client_set_icon_name(lua_State *, int, const char *);
|
||||
void client_set_role(lua_State *, int, char *);
|
||||
void client_set_machine(lua_State *, int, char *);
|
||||
void client_set_icon_name(lua_State *, int, char *);
|
||||
void client_set_class_instance(lua_State *, int, const char *, const char *);
|
||||
void client_set_type(lua_State *L, int, window_type_t);
|
||||
void client_set_transient_for(lua_State *L, int, client_t *);
|
||||
void client_set_name(lua_State *L, int, const char *);
|
||||
void client_set_name(lua_State *L, int, char *);
|
||||
void client_set_group_window(lua_State *, int, xcb_window_t);
|
||||
void client_set_icon(lua_State *, int, int);
|
||||
void client_set_skip_taskbar(lua_State *, int, bool);
|
||||
|
|
182
property.c
182
property.c
|
@ -31,6 +31,47 @@
|
|||
#include "common/atoms.h"
|
||||
#include "common/xutil.h"
|
||||
|
||||
|
||||
#define HANDLE_TEXT_PROPERTY(funcname, atom, setfunc) \
|
||||
void \
|
||||
property_update_##funcname(client_t *c, xcb_get_property_reply_t *reply) \
|
||||
{ \
|
||||
bool no_reply = !reply; \
|
||||
if(no_reply) \
|
||||
reply = xcb_get_property_reply(globalconf.connection, \
|
||||
xcb_get_any_property(globalconf.connection, \
|
||||
false, \
|
||||
c->window, \
|
||||
WM_NAME, \
|
||||
UINT_MAX), NULL); \
|
||||
luaA_object_push(globalconf.L, c); \
|
||||
setfunc(globalconf.L, -1, xutil_get_text_property_from_reply(reply)); \
|
||||
lua_pop(globalconf.L, 1); \
|
||||
if(no_reply) \
|
||||
p_delete(&reply); \
|
||||
} \
|
||||
static int \
|
||||
property_handle_##funcname(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_##funcname(c, reply); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
|
||||
HANDLE_TEXT_PROPERTY(wm_name, WM_NAME, client_set_name)
|
||||
HANDLE_TEXT_PROPERTY(wm_icon_name, WM_ICON_NAME, client_set_icon_name)
|
||||
HANDLE_TEXT_PROPERTY(wm_client_machine, WM_CLIENT_MACHINE, client_set_machine)
|
||||
HANDLE_TEXT_PROPERTY(wm_window_role, WM_WINDOW_ROLE, client_set_role)
|
||||
|
||||
#undef HANDLE_TEXT_PROPERTY
|
||||
|
||||
void
|
||||
property_update_wm_transient_for(client_t *c, xcb_get_property_reply_t *reply)
|
||||
{
|
||||
|
@ -73,77 +114,6 @@ property_handle_wm_transient_for(void *data,
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
property_update_wm_client_machine(client_t *c, xcb_get_property_reply_t *reply)
|
||||
{
|
||||
bool no_reply = !reply;
|
||||
|
||||
if(no_reply)
|
||||
reply = xcb_get_property_reply(globalconf.connection,
|
||||
xcb_get_any_property(globalconf.connection,
|
||||
false,
|
||||
c->window,
|
||||
WM_CLIENT_MACHINE,
|
||||
UINT_MAX), NULL);
|
||||
|
||||
const char *value = xutil_get_text_property_from_reply(reply);
|
||||
|
||||
luaA_object_push(globalconf.L, c);
|
||||
client_set_machine(globalconf.L, -1, value);
|
||||
lua_pop(globalconf.L, 1);
|
||||
|
||||
if(no_reply)
|
||||
p_delete(&reply);
|
||||
}
|
||||
|
||||
static int
|
||||
property_handle_wm_client_machine(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_machine(c, reply);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
property_update_wm_window_role(client_t *c)
|
||||
{
|
||||
ssize_t slen;
|
||||
char *value;
|
||||
|
||||
if(!xutil_text_prop_get(globalconf.connection, c->window,
|
||||
WM_WINDOW_ROLE, &value, &slen))
|
||||
return;
|
||||
|
||||
luaA_object_push(globalconf.L, c);
|
||||
client_set_role(globalconf.L, -1, value);
|
||||
p_delete(&value);
|
||||
lua_pop(globalconf.L, 1);
|
||||
}
|
||||
|
||||
static int
|
||||
property_handle_wm_window_role(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_window_role(c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Update leader hint of a client.
|
||||
* \param c The client.
|
||||
* \param reply (Optional) An existing reply.
|
||||
|
@ -276,25 +246,6 @@ property_handle_wm_hints(void *data,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** Update client name attribute with its new title.
|
||||
* \param c The client.
|
||||
*/
|
||||
void
|
||||
property_update_wm_name(client_t *c)
|
||||
{
|
||||
char *name;
|
||||
ssize_t len;
|
||||
|
||||
if(!xutil_text_prop_get(globalconf.connection, c->window, _NET_WM_NAME, &name, &len))
|
||||
if(!xutil_text_prop_get(globalconf.connection, c->window, WM_NAME, &name, &len))
|
||||
return;
|
||||
|
||||
luaA_object_push(globalconf.L, c);
|
||||
client_set_name(globalconf.L, -1, name);
|
||||
p_delete(&name);
|
||||
lua_pop(globalconf.L, 1);
|
||||
}
|
||||
|
||||
/** Update WM_CLASS of a client.
|
||||
* \param c The client.
|
||||
* \param reply The reply to get property request, or NULL if none.
|
||||
|
@ -326,57 +277,6 @@ property_update_wm_class(client_t *c, xcb_get_property_reply_t *reply)
|
|||
xcb_get_wm_class_reply_wipe(&hint);
|
||||
}
|
||||
|
||||
/** Update client icon name attribute with its new title.
|
||||
* \param c The client.
|
||||
*/
|
||||
void
|
||||
property_update_wm_icon_name(client_t *c)
|
||||
{
|
||||
char *name;
|
||||
ssize_t len;
|
||||
|
||||
if(!xutil_text_prop_get(globalconf.connection, c->window, _NET_WM_ICON_NAME, &name, &len))
|
||||
if(!xutil_text_prop_get(globalconf.connection, c->window, WM_ICON_NAME, &name, &len))
|
||||
return;
|
||||
|
||||
luaA_object_push(globalconf.L, c);
|
||||
client_set_icon_name(globalconf.L, -1, name);
|
||||
p_delete(&name);
|
||||
lua_pop(globalconf.L, 1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int
|
||||
property_handle_wm_class(void *data,
|
||||
xcb_connection_t *connection,
|
||||
|
|
|
@ -29,11 +29,11 @@ void property_update_wm_client_leader(client_t *c, xcb_get_property_reply_t *);
|
|||
void property_update_wm_normal_hints(client_t *, xcb_get_property_reply_t *);
|
||||
void property_update_wm_hints(client_t *, xcb_get_property_reply_t *);
|
||||
void property_update_wm_class(client_t *, xcb_get_property_reply_t *);
|
||||
void property_update_wm_name(client_t *);
|
||||
void property_update_wm_icon_name(client_t *);
|
||||
void property_update_wm_name(client_t *, xcb_get_property_reply_t *);
|
||||
void property_update_wm_icon_name(client_t *, xcb_get_property_reply_t *);
|
||||
void property_update_wm_protocols(client_t *);
|
||||
void property_update_wm_client_machine(client_t *, xcb_get_property_reply_t *);
|
||||
void property_update_wm_window_role(client_t *);
|
||||
void property_update_wm_window_role(client_t *, xcb_get_property_reply_t *);
|
||||
void property_update_net_wm_pid(client_t *, xcb_get_property_reply_t *);
|
||||
void property_update_net_wm_icon(client_t *, xcb_get_property_reply_t *);
|
||||
void a_xcb_set_property_handlers(void);
|
||||
|
|
Loading…
Reference in New Issue