From 5cbc2896c45056ba4806e8565a6fddc19a0dbeff Mon Sep 17 00:00:00 2001 From: Reginald Kennedy Date: Fri, 18 Jan 2013 09:31:01 +0800 Subject: [PATCH] Add new ws_next_move and ws_prev_move bindings. Switches to next/prev workspace with the current window. Improve grabkeys to only grab ws binds within workspace_limit. --- spectrwm.1 | 8 ++++++++ spectrwm.c | 39 +++++++++++++++++++++++++++++++-------- spectrwm_cz.conf | 2 ++ spectrwm_es.conf | 2 ++ spectrwm_fr.conf | 2 ++ spectrwm_fr_ch.conf | 2 ++ spectrwm_se.conf | 2 ++ spectrwm_us.conf | 2 ++ 8 files changed, 51 insertions(+), 8 deletions(-) diff --git a/spectrwm.1 b/spectrwm.1 index dc427c5..5736113 100644 --- a/spectrwm.1 +++ b/spectrwm.1 @@ -563,6 +563,10 @@ ws_next_all .It Cm M- Ns Aq Cm Down ws_prev_all .It Cm M-a +ws_next_move +.It Cm M-S- Ns Aq Cm Left +ws_prev_move +.It Cm M-S- Ns Aq Cm Up ws_prior .It Cm M-S- Ns Aq Cm Right rg_next @@ -701,6 +705,10 @@ Switch to previous workspace with a window in it. Switch to next workspace. .It Cm ws_prev_all Switch to previous workspace. +.It Cm ws_next_move +Switch to next workspace with the current window. +.It Cm ws_prev_move +Switch to previous workspace with the current window. .It Cm ws_prior Switch to last visited workspace. .It Cm rg_next diff --git a/spectrwm.c b/spectrwm.c index 5ad56a7..e19636a 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -577,6 +577,8 @@ union arg { #define SWM_ARG_ID_CYCLERG_DOWN (43) #define SWM_ARG_ID_CYCLEWS_UP_ALL (44) #define SWM_ARG_ID_CYCLEWS_DOWN_ALL (45) +#define SWM_ARG_ID_CYCLEWS_MOVE_UP (46) +#define SWM_ARG_ID_CYCLEWS_MOVE_DOWN (47) #define SWM_ARG_ID_STACKINC (50) #define SWM_ARG_ID_STACKDEC (51) #define SWM_ARG_ID_SS_ALL (60) @@ -831,8 +833,10 @@ enum keyfuncid { KF_WS_22, KF_WS_NEXT, KF_WS_NEXT_ALL, + KF_WS_NEXT_MOVE, KF_WS_PREV, KF_WS_PREV_ALL, + KF_WS_PREV_MOVE, KF_WS_PRIOR, KF_DUMPWINS, /* MUST BE LAST */ KF_INVALID @@ -3497,30 +3501,32 @@ cyclews(struct swm_region *r, union arg *args) union arg a; struct swm_screen *s = r->s; int cycle_all = 0; + int move = 0; DNPRINTF(SWM_D_WS, "cyclews: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n", args->id, r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), r->ws->idx); a.id = r->ws->idx; + do { switch (args->id) { + case SWM_ARG_ID_CYCLEWS_MOVE_UP: + move = 1; + /* FALLTHROUGH */ case SWM_ARG_ID_CYCLEWS_UP_ALL: cycle_all = 1; /* FALLTHROUGH */ case SWM_ARG_ID_CYCLEWS_UP: - if (a.id < workspace_limit - 1) - a.id++; - else - a.id = 0; + a.id = (a.id < workspace_limit - 1) ? a.id + 1 : 0; break; + case SWM_ARG_ID_CYCLEWS_MOVE_DOWN: + move = 1; + /* FALLTHROUGH */ case SWM_ARG_ID_CYCLEWS_DOWN_ALL: cycle_all = 1; /* FALLTHROUGH */ case SWM_ARG_ID_CYCLEWS_DOWN: - if (a.id > 0) - a.id--; - else - a.id = workspace_limit - 1; + a.id = (a.id > 0) ? a.id - 1 : workspace_limit - 1; break; default: return; @@ -3532,6 +3538,9 @@ cyclews(struct swm_region *r, union arg *args) if (!cycle_visible && s->ws[a.id].r != NULL) continue; + if (move) + send_to_ws(r, &a); + switchws(r, &a); } while (a.id != r->ws->idx); } @@ -5762,8 +5771,10 @@ struct keyfunc { { "ws_22", switchws, {.id = 21} }, { "ws_next", cyclews, {.id = SWM_ARG_ID_CYCLEWS_UP} }, { "ws_next_all", cyclews, {.id = SWM_ARG_ID_CYCLEWS_UP_ALL} }, + { "ws_next_move", cyclews, {.id = SWM_ARG_ID_CYCLEWS_MOVE_UP} }, { "ws_prev", cyclews, {.id = SWM_ARG_ID_CYCLEWS_DOWN} }, { "ws_prev_all", cyclews, {.id = SWM_ARG_ID_CYCLEWS_DOWN_ALL} }, + { "ws_prev_move", cyclews, {.id = SWM_ARG_ID_CYCLEWS_MOVE_DOWN} }, { "ws_prior", priorws, {0} }, { "dumpwins", dumpwins, {0} }, /* MUST BE LAST */ { "invalid key func", NULL, {0} }, @@ -6452,6 +6463,8 @@ setup_keys(void) setkeybinding(MODKEY, XK_Left, KF_WS_PREV, NULL); setkeybinding(MODKEY, XK_Up, KF_WS_NEXT_ALL, NULL); setkeybinding(MODKEY, XK_Down, KF_WS_PREV_ALL, NULL); + setkeybinding(MODKEY_SHIFT, XK_Up, KF_WS_NEXT_MOVE,NULL); + setkeybinding(MODKEY_SHIFT, XK_Down, KF_WS_PREV_MOVE,NULL); setkeybinding(MODKEY, XK_a, KF_WS_PRIOR, NULL); #ifdef SWM_DEBUG setkeybinding(MODKEY_SHIFT, XK_d, KF_DUMPWINS, NULL); @@ -6549,6 +6562,16 @@ grabkeys(void) xcb_ungrab_key(conn, XCB_GRAB_ANY, screens[k].root, XCB_MOD_MASK_ANY); RB_FOREACH(kp, key_tree, &keys) { + /* Skip unused ws binds. */ + if ((int)kp->funcid > KF_WS_1 + workspace_limit - 1 && + kp->funcid <= KF_WS_22) + continue; + + /* Skip unused mvws binds. */ + if ((int)kp->funcid > KF_MVWS_1 + workspace_limit - 1 && + kp->funcid <= KF_MVWS_22) + continue; + if ((code = xcb_key_symbols_get_keycode(syms, kp->keysym))) { for (j = 0; j < LENGTH(modifiers); j++) diff --git a/spectrwm_cz.conf b/spectrwm_cz.conf index 654f43d..0929bb8 100644 --- a/spectrwm_cz.conf +++ b/spectrwm_cz.conf @@ -45,6 +45,8 @@ bind[ws_next] = MOD+Right bind[ws_prev] = MOD+Left bind[ws_next_all] = MOD+Up bind[ws_prev_all] = MOD+Down +bind[ws_next_move] = MOD+Shift+Up +bind[ws_prev_move] = MOD+Shift+Down bind[ws_prior] = MOD+a bind[mvws_1] = MOD+Shift+plus bind[mvws_2] = MOD+Shift+ecaron diff --git a/spectrwm_es.conf b/spectrwm_es.conf index 351a2e5..09d60a7 100644 --- a/spectrwm_es.conf +++ b/spectrwm_es.conf @@ -45,6 +45,8 @@ bind[ws_next] = MOD+Right bind[ws_prev] = MOD+Left bind[ws_next_all] = MOD+Up bind[ws_prev_all] = MOD+Down +bind[ws_next_move] = MOD+Shift+Up +bind[ws_prev_move] = MOD+Shift+Down bind[ws_prior] = MOD+a bind[mvws_1] = MOD+Shift+1 bind[mvws_2] = MOD+Shift+2 diff --git a/spectrwm_fr.conf b/spectrwm_fr.conf index 9fc9778..5705458 100644 --- a/spectrwm_fr.conf +++ b/spectrwm_fr.conf @@ -45,6 +45,8 @@ bind[ws_next] = MOD+Right bind[ws_prev] = MOD+Left bind[ws_next_all] = MOD+Up bind[ws_prev_all] = MOD+Down +bind[ws_next_move] = MOD+Shift+Up +bind[ws_prev_move] = MOD+Shift+Down bind[ws_prior] = MOD+a bind[mvws_1] = MOD+Shift+ampersand bind[mvws_2] = MOD+Shift+eacute diff --git a/spectrwm_fr_ch.conf b/spectrwm_fr_ch.conf index 264f611..91bd898 100644 --- a/spectrwm_fr_ch.conf +++ b/spectrwm_fr_ch.conf @@ -45,6 +45,8 @@ bind[ws_next] = MOD+Right bind[ws_prev] = MOD+Left bind[ws_next_all] = MOD+Up bind[ws_prev_all] = MOD+Down +bind[ws_next_move] = MOD+Shift+Up +bind[ws_prev_move] = MOD+Shift+Down bind[ws_prior] = MOD+a bind[mvws_1] = MOD+Shift+1 bind[mvws_2] = MOD+Shift+2 diff --git a/spectrwm_se.conf b/spectrwm_se.conf index 7293925..1a14a6e 100644 --- a/spectrwm_se.conf +++ b/spectrwm_se.conf @@ -45,6 +45,8 @@ bind[ws_next] = MOD+Right bind[ws_prev] = MOD+Left bind[ws_next_all] = MOD+Up bind[ws_prev_all] = MOD+Down +bind[ws_next_move] = MOD+Shift+Up +bind[ws_prev_move] = MOD+Shift+Down bind[ws_prior] = MOD+a bind[mvws_1] = MOD+Shift+1 bind[mvws_2] = MOD+Shift+2 diff --git a/spectrwm_us.conf b/spectrwm_us.conf index 89b4ebd..331996d 100644 --- a/spectrwm_us.conf +++ b/spectrwm_us.conf @@ -45,6 +45,8 @@ bind[ws_next] = MOD+Right bind[ws_prev] = MOD+Left bind[ws_next_all] = MOD+Up bind[ws_prev_all] = MOD+Down +bind[ws_next_move] = MOD+Shift+Up +bind[ws_prev_move] = MOD+Shift+Down bind[ws_prior] = MOD+a bind[mvws_1] = MOD+Shift+1 bind[mvws_2] = MOD+Shift+2 -- 1.7.10.4