From a579c86c1fbb9428f31199a04fc4ced8e554ab3f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 11 Feb 2017 17:12:07 +0100 Subject: [PATCH] Only switch to the desktop first if we are on AweSome WM --- include/x11-helper.h | 6 ++-- source/dialogs/window.c | 67 ++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/include/x11-helper.h b/include/x11-helper.h index 4c915da5..fadfcf5c 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -264,11 +264,11 @@ void x11_disable_decoration ( xcb_window_t window ); typedef enum { /** Default EWHM compatible window manager */ - WM_EWHM, + WM_EWHM = 0, /** I3 Window manager */ - WM_I3, + WM_I3 = 1, /** Awesome window manager */ - WM_AWESOME + WM_AWESOME = 2 } WindowManager; /** diff --git a/source/dialogs/window.c b/source/dialogs/window.c index f427aa2a..319558e5 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -578,44 +578,37 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i } else { rofi_view_hide (); - // 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; + if ( current_window_manager == WM_AWESOME ) + { + // 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; + // 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; + } + + 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 ); + } } - - // 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,