client: store class and instance

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-04 13:41:17 +02:00
parent 208406ea90
commit 0d6d6c4fa7
5 changed files with 44 additions and 13 deletions

View File

@ -558,6 +558,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen,
/* update window title */ /* update window title */
property_update_wm_name(c); property_update_wm_name(c);
property_update_wm_icon_name(c); property_update_wm_icon_name(c);
property_update_wm_class(c);
/* update strut */ /* update strut */
ewmh_process_client_strut(c, NULL); ewmh_process_client_strut(c, NULL);
@ -1833,7 +1834,6 @@ luaA_client_index(lua_State *L)
const char *buf = luaL_checklstring(L, 2, &len); const char *buf = luaL_checklstring(L, 2, &len);
char *value; char *value;
void *data; void *data;
xcb_get_wm_class_reply_t hint;
xcb_get_property_cookie_t prop_c; xcb_get_property_cookie_t prop_c;
xcb_get_property_reply_t *prop_r = NULL; xcb_get_property_reply_t *prop_r = NULL;
double d; double d;
@ -1910,20 +1910,10 @@ luaA_client_index(lua_State *L)
} }
break; break;
case A_TK_CLASS: case A_TK_CLASS:
if(!xcb_get_wm_class_reply(globalconf.connection, lua_pushstring(L, (*c)->class);
xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
&hint, NULL))
return 0;
lua_pushstring(L, hint.class_name);
xcb_get_wm_class_reply_wipe(&hint);
break; break;
case A_TK_INSTANCE: case A_TK_INSTANCE:
if(!xcb_get_wm_class_reply(globalconf.connection, lua_pushstring(L, (*c)->instance);
xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
&hint, NULL))
return 0;
lua_pushstring(L, hint.instance_name);
xcb_get_wm_class_reply_wipe(&hint);
break; break;
case A_TK_ROLE: case A_TK_ROLE:
if(!xutil_text_prop_get(globalconf.connection, (*c)->win, if(!xutil_text_prop_get(globalconf.connection, (*c)->win,

View File

@ -36,6 +36,8 @@ static void
client_delete(client_t **c) client_delete(client_t **c)
{ {
button_array_wipe(&(*c)->buttons); button_array_wipe(&(*c)->buttons);
p_delete(&(*c)->class);
p_delete(&(*c)->instance);
p_delete(&(*c)->icon_name); p_delete(&(*c)->icon_name);
p_delete(&(*c)->name); p_delete(&(*c)->name);
p_delete(c); p_delete(c);

View File

@ -223,6 +223,24 @@ property_update_wm_name(client_t *c)
hooks_property(c, "name"); hooks_property(c, "name");
} }
void
property_update_wm_class(client_t *c)
{
xcb_get_wm_class_reply_t hint;
p_delete(&c->instance);
p_delete(&c->class);
if(xcb_get_wm_class_reply(globalconf.connection,
xcb_get_wm_class_unchecked(globalconf.connection, c->win),
&hint, NULL))
{
c->instance = a_strdup(hint.instance_name);
c->class = a_strdup(hint.class_name);
xcb_get_wm_class_reply_wipe(&hint);
}
}
/** Update client icon name attribute with its new title. /** Update client icon name attribute with its new title.
* \param c The client. * \param c The client.
* \param Return true if it has been updated. * \param Return true if it has been updated.
@ -277,6 +295,22 @@ property_handle_wm_icon_name(void *data,
return 0; return 0;
} }
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)
property_update_wm_class(c);
return 0;
}
static int static int
property_handle_net_wm_strut_partial(void *data, property_handle_net_wm_strut_partial(void *data,
xcb_connection_t *connection, xcb_connection_t *connection,
@ -386,6 +420,8 @@ void a_xcb_set_property_handlers(void)
property_handle_wm_name, NULL); property_handle_wm_name, NULL);
xcb_property_set_handler(&globalconf.prophs, WM_ICON_NAME, UINT_MAX, xcb_property_set_handler(&globalconf.prophs, WM_ICON_NAME, UINT_MAX,
property_handle_wm_icon_name, NULL); property_handle_wm_icon_name, NULL);
xcb_property_set_handler(&globalconf.prophs, WM_CLASS, UINT_MAX,
property_handle_wm_class, NULL);
/* EWMH stuff */ /* EWMH stuff */
xcb_property_set_handler(&globalconf.prophs, _NET_WM_NAME, UINT_MAX, xcb_property_set_handler(&globalconf.prophs, _NET_WM_NAME, UINT_MAX,

View File

@ -28,6 +28,7 @@ void property_update_wm_transient_for(client_t *, xcb_get_property_reply_t *);
void property_update_wm_client_leader(client_t *c, xcb_get_property_reply_t *reply); void property_update_wm_client_leader(client_t *c, xcb_get_property_reply_t *reply);
void property_update_wm_normal_hints(client_t *, 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_hints(client_t *, xcb_get_property_reply_t *);
void property_update_wm_class(client_t *);
void property_update_wm_name(client_t *); void property_update_wm_name(client_t *);
void property_update_wm_icon_name(client_t *); void property_update_wm_icon_name(client_t *);
void a_xcb_set_property_handlers(void); void a_xcb_set_property_handlers(void);

View File

@ -167,6 +167,8 @@ struct client_t
bool invalid; bool invalid;
/** Client name */ /** Client name */
char *name, *icon_name; char *name, *icon_name;
/** WM_CLASS stuff */
char *class, *instance;
/** Window geometry */ /** Window geometry */
area_t geometry; area_t geometry;
struct struct