From ede5a54355559ffe9d48888b92677f231068dda0 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 6 Oct 2008 11:42:02 +0200 Subject: [PATCH] event: handle background changes Signed-off-by: Julien Danjou --- awesome.c | 3 ++- common/xutil.c | 17 +++++++++++++++++ common/xutil.h | 2 ++ event.c | 4 +--- property.c | 30 ++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/awesome.c b/awesome.c index 937b8656..2ff811b0 100644 --- a/awesome.c +++ b/awesome.c @@ -484,7 +484,8 @@ main(int argc, char **argv) { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW - | XCB_EVENT_MASK_STRUCTURE_NOTIFY, + | XCB_EVENT_MASK_STRUCTURE_NOTIFY + | XCB_EVENT_MASK_PROPERTY_CHANGE, globalconf.cursor[CurNormal] }; diff --git a/common/xutil.c b/common/xutil.c index 8f262b4b..40891daa 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -427,4 +427,21 @@ xutil_cursor_new(xcb_connection_t *conn, unsigned int cursor_font) return cursor; } +/** Convert a root window a physical screen ID. + * \param connection The connection to the X server. + * \param root Root window. + * \return A physical screen number. + */ +int +xutil_root2screen(xcb_connection_t *connection, xcb_window_t root) +{ + xcb_screen_iterator_t iter; + int phys_screen = 0; + + for(iter = xcb_setup_roots_iterator(xcb_get_setup(connection)); + iter.rem && iter.data->root != root; xcb_screen_next(&iter), ++phys_screen); + + return phys_screen; +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/xutil.h b/common/xutil.h index cec59aa3..269daf33 100644 --- a/common/xutil.h +++ b/common/xutil.h @@ -143,5 +143,7 @@ xutil_screen_get(xcb_connection_t *c, int screen) return s; } +int xutil_root2screen(xcb_connection_t *, xcb_window_t); + #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/event.c b/event.c index b6187391..3b517976 100644 --- a/event.c +++ b/event.c @@ -511,7 +511,6 @@ event_handle_maprequest(void *data __attribute__ ((unused)), xcb_query_pointer_reply_t *qp_r = NULL; xcb_get_geometry_cookie_t geom_c; xcb_get_geometry_reply_t *geom_r; - xcb_screen_iterator_t iter; wa_c = xcb_get_window_attributes_unchecked(connection, ev->window); @@ -554,8 +553,7 @@ event_handle_maprequest(void *data __attribute__ ((unused)), } - for(iter = xcb_setup_roots_iterator(xcb_get_setup(connection)), phys_screen = 0; - iter.rem && iter.data->root != geom_r->root; xcb_screen_next(&iter), ++phys_screen); + phys_screen = xutil_root2screen(connection, geom_r->root); if(globalconf.xinerama_is_active && (qp_r = xcb_query_pointer_reply(connection, qp_c, NULL))) diff --git a/property.c b/property.c index 4b795a5e..d2ece640 100644 --- a/property.c +++ b/property.c @@ -321,6 +321,32 @@ property_handle_xembed_info(void *data __attribute__ ((unused)), return 0; } +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) + for(int screen = 0; screen < globalconf.nscreen; screen++) + { + wibox_array_t *w = &globalconf.screens[screen].wiboxes; + for(int i = 0; i < w->len; i++) + w->tab[i]->need_update = true; + } + else + { + int screen = xutil_root2screen(connection, window); + wibox_array_t *w = &globalconf.screens[screen].wiboxes; + for(int i = 0; i < w->len; i++) + w->tab[i]->need_update = true; + } + + return 0; +} + void a_xcb_set_property_handlers(void) { /* init */ @@ -347,6 +373,10 @@ void a_xcb_set_property_handlers(void) property_handle_net_wm_strut_partial, NULL); xcb_property_set_handler(&globalconf.prophs, _NET_WM_ICON, UINT_MAX, property_handle_net_wm_icon, NULL); + + /* background change */ + xcb_property_set_handler(&globalconf.prophs, _XROOTPMAP_ID, 1, + property_handle_xrootpmap_id, NULL); } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80