From b6fa77997201a7d86378ddf6f9432ccbe07e98f4 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 28 Sep 2010 13:07:31 +0200 Subject: [PATCH] Wibox type: Make this work correctly The last commit caused some lua errors and reading a wibox' type property didn't work. This should all be fixed now. Signed-off-by: Uli Schlachter --- ewmh.c | 11 ++++++ ewmh.h | 1 + objects/wibox.c | 4 +- objects/window.c | 98 +++++++++++++++++++++++++++++++----------------- objects/window.h | 2 +- 5 files changed, 77 insertions(+), 39 deletions(-) diff --git a/ewmh.c b/ewmh.c index ab9b78c21..f40194950 100644 --- a/ewmh.c +++ b/ewmh.c @@ -478,6 +478,17 @@ ewmh_update_strut(xcb_window_t window, strut_t *strut) } } +/** Update the window type. + * \param window The window to update. + * \param type The new type to set. + */ +void +ewmh_update_window_type(xcb_window_t window, uint32_t type) +{ + xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, + window, _NET_WM_WINDOW_TYPE, XCB_ATOM_ATOM, 32, 1, &type); +} + void ewmh_client_check_hints(client_t *c) { diff --git a/ewmh.h b/ewmh.h index fc6102a95..b56afd99d 100644 --- a/ewmh.h +++ b/ewmh.h @@ -35,6 +35,7 @@ void ewmh_client_check_hints(client_t *); void ewmh_client_update_desktop(client_t *); void ewmh_process_client_strut(client_t *); void ewmh_update_strut(xcb_window_t, strut_t *); +void ewmh_update_window_type(xcb_window_t window, uint32_t type); xcb_get_property_cookie_t ewmh_window_icon_get_unchecked(xcb_window_t); int ewmh_window_icon_get_reply(xcb_get_property_cookie_t); diff --git a/objects/wibox.c b/objects/wibox.c index ab7a3c486..fcc452363 100644 --- a/objects/wibox.c +++ b/objects/wibox.c @@ -183,9 +183,7 @@ wibox_init(wibox_t *w) wibox_draw_context_update(w); /* Set the right type property */ - uint32_t type = w->type; - w->type = 0; - window_set_type((window_t *) w, type); + ewmh_update_window_type(w->window, window_translate_type(w->type)); } /** Refresh the window content by copying its pixmap data to its window. diff --git a/objects/window.c b/objects/window.c index 17dc35956..050c0b499 100644 --- a/objects/window.c +++ b/objects/window.c @@ -238,25 +238,6 @@ luaA_window_get_type(lua_State *L, window_t *w) return 1; } -/** Set the window type. - * \param w The window object. - * \param type The window type to set - */ -void -window_set_type(window_t *w, uint32_t type) -{ - if(w->type != type) - { - w->type = type; - if(w->window != XCB_WINDOW_NONE) - xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, - w->window, _NET_WM_WINDOW_TYPE, XCB_ATOM_ATOM, 32, 1, &type); - luaA_object_push(globalconf.L, w); - luaA_object_emit_signal(globalconf.L, -1, "property::type", 0); - lua_pop(globalconf.L, 1); - } -} - /** Set the window type. * \param L The Lua VM state. * \param window The window object. @@ -265,47 +246,94 @@ window_set_type(window_t *w, uint32_t type) int luaA_window_set_type(lua_State *L, window_t *w) { - uint32_t type; + window_type_t type; const char *buf = luaL_checkstring(L, -1); if(a_strcmp(buf, "desktop") == 0) - type = _NET_WM_WINDOW_TYPE_DESKTOP; + type = WINDOW_TYPE_DESKTOP; else if(a_strcmp(buf, "dock") == 0) - type = _NET_WM_WINDOW_TYPE_DOCK; + type = WINDOW_TYPE_DOCK; else if(a_strcmp(buf, "splash") == 0) - type = _NET_WM_WINDOW_TYPE_SPLASH; + type = WINDOW_TYPE_SPLASH; else if(a_strcmp(buf, "dialog") == 0) - type = _NET_WM_WINDOW_TYPE_DIALOG; + type = WINDOW_TYPE_DIALOG; else if(a_strcmp(buf, "menu") == 0) - type = _NET_WM_WINDOW_TYPE_MENU; + type = WINDOW_TYPE_MENU; else if(a_strcmp(buf, "toolbar") == 0) - type = _NET_WM_WINDOW_TYPE_TOOLBAR; + type = WINDOW_TYPE_TOOLBAR; else if(a_strcmp(buf, "utility") == 0) - type = _NET_WM_WINDOW_TYPE_UTILITY; + type = WINDOW_TYPE_UTILITY; else if(a_strcmp(buf, "dropdown_menu") == 0) - type = _NET_WM_WINDOW_TYPE_DROPDOWN_MENU; + type = WINDOW_TYPE_DROPDOWN_MENU; else if(a_strcmp(buf, "popup_menu") == 0) - type = _NET_WM_WINDOW_TYPE_POPUP_MENU; + type = WINDOW_TYPE_POPUP_MENU; else if(a_strcmp(buf, "tooltip") == 0) - type = _NET_WM_WINDOW_TYPE_TOOLTIP; + type = WINDOW_TYPE_TOOLTIP; else if(a_strcmp(buf, "notification") == 0) - type = _NET_WM_WINDOW_TYPE_NOTIFICATION; + type = WINDOW_TYPE_NOTIFICATION; else if(a_strcmp(buf, "combo") == 0) - type = _NET_WM_WINDOW_TYPE_COMBO; + type = WINDOW_TYPE_COMBO; else if(a_strcmp(buf, "dnd") == 0) - type = _NET_WM_WINDOW_TYPE_DND; + type = WINDOW_TYPE_DND; else if(a_strcmp(buf, "normal") == 0) - type = _NET_WM_WINDOW_TYPE_NORMAL; + type = WINDOW_TYPE_NORMAL; else { warn("Unknown window type '%s'", buf); return 0; } - window_set_type(w, type); + if(w->type != type) + { + w->type = type; + if(w->window != XCB_WINDOW_NONE) + ewmh_update_window_type(w->window, window_translate_type(type)); + luaA_object_emit_signal(globalconf.L, -3, "property::type", 0); + } return 0; } +/** Translate a window_type_t into the corresponding EWMH atom. + * @param type The type to return. + * @return The EWMH atom for this type. + */ +uint32_t +window_translate_type(window_type_t type) +{ + switch(type) + { + case WINDOW_TYPE_NORMAL: + return _NET_WM_WINDOW_TYPE_NORMAL; + case WINDOW_TYPE_DESKTOP: + return _NET_WM_WINDOW_TYPE_DESKTOP; + case WINDOW_TYPE_DOCK: + return _NET_WM_WINDOW_TYPE_DOCK; + case WINDOW_TYPE_SPLASH: + return _NET_WM_WINDOW_TYPE_SPLASH; + case WINDOW_TYPE_DIALOG: + return _NET_WM_WINDOW_TYPE_DIALOG; + case WINDOW_TYPE_MENU: + return _NET_WM_WINDOW_TYPE_MENU; + case WINDOW_TYPE_TOOLBAR: + return _NET_WM_WINDOW_TYPE_TOOLBAR; + case WINDOW_TYPE_UTILITY: + return _NET_WM_WINDOW_TYPE_UTILITY; + case WINDOW_TYPE_DROPDOWN_MENU: + return _NET_WM_WINDOW_TYPE_DROPDOWN_MENU; + case WINDOW_TYPE_POPUP_MENU: + return _NET_WM_WINDOW_TYPE_POPUP_MENU; + case WINDOW_TYPE_TOOLTIP: + return _NET_WM_WINDOW_TYPE_TOOLTIP; + case WINDOW_TYPE_NOTIFICATION: + return _NET_WM_WINDOW_TYPE_NOTIFICATION; + case WINDOW_TYPE_COMBO: + return _NET_WM_WINDOW_TYPE_COMBO; + case WINDOW_TYPE_DND: + return _NET_WM_WINDOW_TYPE_DND; + } + return _NET_WM_WINDOW_TYPE_NORMAL; +} + static int luaA_window_set_border_width(lua_State *L, window_t *c) { diff --git a/objects/window.h b/objects/window.h index 801c02021..632f21372 100644 --- a/objects/window.h +++ b/objects/window.h @@ -84,7 +84,7 @@ void window_set_opacity(lua_State *, int, double); void window_set_border_width(lua_State *, int, int); int luaA_window_get_type(lua_State *, window_t *); int luaA_window_set_type(lua_State *, window_t *); -void window_set_type(window_t *, uint32_t); +uint32_t window_translate_type(window_type_t type); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80