When switching windows also switch the desktop

If the window we switch to is not on the same desktop, first switch to
the desktop.
This commit is contained in:
Dimitar Yordanov 2016-04-28 22:45:01 +02:00
parent 7861b73690
commit 74d1b234d9
1 changed files with 40 additions and 2 deletions

View File

@ -37,6 +37,7 @@
#include <xcb/xcb.h>
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_icccm.h>
#include <xcb/xcb_atom.h>
#include <glib.h>
@ -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, &current_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 );