From 74d1b234d909846ce36fbf387944ca910ad940f0 Mon Sep 17 00:00:00 2001 From: Dimitar Yordanov Date: Thu, 28 Apr 2016 22:45:01 +0200 Subject: [PATCH] When switching windows also switch the desktop If the window we switch to is not on the same desktop, first switch to the desktop. --- source/dialogs/window.c | 42 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/source/dialogs/window.c b/source/dialogs/window.c index d1cedb3d..13a43dee 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -543,8 +544,45 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i if ( rmpd->config_i3_mode ) { // Hack for i3. i3_support_focus_window ( rmpd->ids->array[selected_line] ); - } - else{ + } else { + // Get the current desktop. + unsigned int current_desktop = 0; + xcb_get_property_cookie_t c = xcb_ewmh_get_current_desktop ( &xcb->ewmh, xcb->screen_nbr ); + if ( !xcb_ewmh_get_current_desktop_reply ( &xcb->ewmh, c, ¤t_desktop, NULL ) ) { + current_desktop = 0; + } + + // Get the desktop of the client to switch to + uint32_t wmdesktop = 0; + xcb_get_property_cookie_t cookie; + xcb_get_property_reply_t *r; + + cookie = xcb_get_property (xcb->connection, + 0, + rmpd->ids->array[selected_line], + xcb->ewmh._NET_WM_DESKTOP, + XCB_ATOM_CARDINAL, + 0, + 1); + r = xcb_get_property_reply ( xcb->connection, cookie, NULL ); + if ( r && r->type == XCB_ATOM_CARDINAL ) { + wmdesktop = *( (uint32_t *) xcb_get_property_value ( r ) ); + } + if ( r && r->type != XCB_ATOM_CARDINAL) { + // Assume the client is on all desktops. + wmdesktop = current_desktop; + } + free ( r ); + + // If we have to switch the desktop, do + if ( wmdesktop != current_desktop ) { + xcb_ewmh_request_change_current_desktop(&xcb->ewmh, + xcb->screen_nbr, + wmdesktop, + XCB_CURRENT_TIME); + } + + // Activate the window xcb_ewmh_request_change_active_window ( &xcb->ewmh, xcb->screen_nbr, rmpd->ids->array[selected_line], XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER, XCB_CURRENT_TIME, XCB_WINDOW_NONE );