ewmh: use signals to update client hints

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-10-08 14:08:22 +02:00
parent 38edc58097
commit f4876b5275
3 changed files with 60 additions and 44 deletions

94
ewmh.c
View File

@ -40,6 +40,63 @@
#define _NET_WM_STATE_ADD 1
#define _NET_WM_STATE_TOGGLE 2
/** Update client EWMH hints.
* \param c The client.
*/
static int
ewmh_client_update_hints(lua_State *L)
{
client_t *c = luaA_checkudata(L, 1, &client_class);
xcb_atom_t state[10]; /* number of defined state atoms */
int i = 0;
if(c->modal)
state[i++] = _NET_WM_STATE_MODAL;
if(c->fullscreen)
state[i++] = _NET_WM_STATE_FULLSCREEN;
if(c->maximized_vertical)
state[i++] = _NET_WM_STATE_MAXIMIZED_VERT;
if(c->maximized_horizontal)
state[i++] = _NET_WM_STATE_MAXIMIZED_HORZ;
if(c->sticky)
state[i++] = _NET_WM_STATE_STICKY;
if(c->skip_taskbar)
state[i++] = _NET_WM_STATE_SKIP_TASKBAR;
if(c->above)
state[i++] = _NET_WM_STATE_ABOVE;
if(c->below)
state[i++] = _NET_WM_STATE_BELOW;
if(c->minimized)
state[i++] = _NET_WM_STATE_HIDDEN;
if(c->urgent)
state[i++] = _NET_WM_STATE_DEMANDS_ATTENTION;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
c->window, _NET_WM_STATE, ATOM, 32, i, state);
return 0;
}
static int
ewmh_signal_on_client_new(lua_State *L)
{
#define DO_ADD_SIGNAL_FOR_PROPERTY(prop) \
lua_pushcfunction(L, ewmh_client_update_hints); \
luaA_object_add_signal(L, 1, "property::" #prop , -1);
DO_ADD_SIGNAL_FOR_PROPERTY(modal)
DO_ADD_SIGNAL_FOR_PROPERTY(fullscreen)
DO_ADD_SIGNAL_FOR_PROPERTY(maximized_horizontal)
DO_ADD_SIGNAL_FOR_PROPERTY(maximized_vertical)
DO_ADD_SIGNAL_FOR_PROPERTY(sticky)
DO_ADD_SIGNAL_FOR_PROPERTY(skip_taskbar)
DO_ADD_SIGNAL_FOR_PROPERTY(above)
DO_ADD_SIGNAL_FOR_PROPERTY(below)
DO_ADD_SIGNAL_FOR_PROPERTY(minimized)
DO_ADD_SIGNAL_FOR_PROPERTY(urgent)
#undef DO_ADD_SIGNAL_FOR_PROPERTY
return 0;
}
/** Update the desktop geometry.
* \param phys_screen The physical screen id.
*/
@ -136,6 +193,9 @@ ewmh_init(int phys_screen)
father, _NET_WM_PID, CARDINAL, 32, 1, &i);
ewmh_update_desktop_geometry(phys_screen);
lua_pushcfunction(globalconf.L, ewmh_signal_on_client_new);
luaA_class_add_signal(globalconf.L, &client_class, "new", -1);
}
void
@ -383,40 +443,6 @@ ewmh_process_client_message(xcb_client_message_event_t *ev)
return 0;
}
/** Update client EWMH hints.
* \param c The client.
*/
void
ewmh_client_update_hints(client_t *c)
{
xcb_atom_t state[10]; /* number of defined state atoms */
int i = 0;
if(c->modal)
state[i++] = _NET_WM_STATE_MODAL;
if(c->fullscreen)
state[i++] = _NET_WM_STATE_FULLSCREEN;
if(c->maximized_vertical)
state[i++] = _NET_WM_STATE_MAXIMIZED_VERT;
if(c->maximized_horizontal)
state[i++] = _NET_WM_STATE_MAXIMIZED_HORZ;
if(c->sticky)
state[i++] = _NET_WM_STATE_STICKY;
if(c->skip_taskbar)
state[i++] = _NET_WM_STATE_SKIP_TASKBAR;
if(c->above)
state[i++] = _NET_WM_STATE_ABOVE;
if(c->below)
state[i++] = _NET_WM_STATE_BELOW;
if(c->minimized)
state[i++] = _NET_WM_STATE_HIDDEN;
if(c->urgent)
state[i++] = _NET_WM_STATE_DEMANDS_ATTENTION;
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
c->window, _NET_WM_STATE, ATOM, 32, i, state);
}
/** Update the client active desktop.
* This is "wrong" since it can be on several tags, but EWMH has a strict view
* of desktop system so just take the first tag.

1
ewmh.h
View File

@ -34,7 +34,6 @@ void ewmh_update_net_active_window(int);
int ewmh_process_client_message(xcb_client_message_event_t *);
void ewmh_update_net_client_list_stacking(int);
void ewmh_client_check_hints(client_t *);
void ewmh_client_update_hints(client_t *);
void ewmh_client_update_desktop(client_t *);
void ewmh_process_client_strut(client_t *, xcb_get_property_reply_t *);
void ewmh_update_strut(xcb_window_t, strut_t *);

View File

@ -68,7 +68,6 @@ client_set_urgent(lua_State *L, int cidx, bool urgent)
xcb_get_wm_hints_unchecked(globalconf.connection, c->window);
c->urgent = urgent;
ewmh_client_update_hints(c);
/* update ICCCM hints */
xcb_wm_hints_t wmh;
@ -717,7 +716,6 @@ client_set_minimized(lua_State *L, int cidx, bool s)
xwindow_set_state(c->window, XCB_WM_STATE_ICONIC);
else
xwindow_set_state(c->window, XCB_WM_STATE_NORMAL);
ewmh_client_update_hints(c);
if(strut_has_value(&c->strut))
screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
luaA_object_emit_signal(L, cidx, "property::minimized", 0);
@ -738,7 +736,6 @@ client_set_sticky(lua_State *L, int cidx, bool s)
{
c->sticky = s;
banning_need_update((c)->screen);
ewmh_client_update_hints(c);
luaA_object_emit_signal(L, cidx, "property::sticky", 0);
}
}
@ -771,7 +768,6 @@ client_set_fullscreen(lua_State *L, int cidx, bool s)
luaA_object_emit_signal(L, abs_cidx, "request::fullscreen", 1);
c->fullscreen = s;
stack_windows();
ewmh_client_update_hints(c);
luaA_object_emit_signal(L, abs_cidx, "property::fullscreen", 0);
}
}
@ -795,7 +791,6 @@ client_set_fullscreen(lua_State *L, int cidx, bool s)
luaA_object_emit_signal(L, abs_cidx, "request::maximized_" #type, 1); \
c->maximized_##type = s; \
stack_windows(); \
ewmh_client_update_hints(c); \
luaA_object_emit_signal(L, abs_cidx, "property::maximized_" #type, 0); \
} \
}
@ -824,7 +819,6 @@ client_set_above(lua_State *L, int cidx, bool s)
}
c->above = s;
stack_windows();
ewmh_client_update_hints(c);
luaA_object_emit_signal(L, cidx, "property::above", 0);
}
}
@ -850,7 +844,6 @@ client_set_below(lua_State *L, int cidx, bool s)
}
c->below = s;
stack_windows();
ewmh_client_update_hints(c);
luaA_object_emit_signal(L, cidx, "property::below", 0);
}
}
@ -869,7 +862,6 @@ client_set_modal(lua_State *L, int cidx, bool s)
{
c->modal = s;
stack_windows();
ewmh_client_update_hints(c);
luaA_object_emit_signal(L, cidx, "property::modal", 0);
}
}
@ -912,7 +904,6 @@ client_set_skip_taskbar(lua_State *L, int cidx, bool s)
if(c->skip_taskbar != s)
{
c->skip_taskbar = s;
ewmh_client_update_hints(c);
luaA_object_emit_signal(L, cidx, "property::skip_taskbar", 0);
}
}