From 662c642cb2c1ec5aef98cae3a43d0d11d1289df9 Mon Sep 17 00:00:00 2001 From: Ryan McBride Date: Wed, 21 Jan 2009 01:26:56 +0000 Subject: [PATCH] Cycle workspaces in region with alt-leftarrow and alt-rightarrow. By default skips empty and already visible workspaces, set cycle_empty or cycle_visible to change this behaviour. --- scrotwm.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/scrotwm.c b/scrotwm.c index 3387f6f..621942e 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -132,6 +132,9 @@ int ignore_enter = 0; unsigned int numlockmask = 0; Display *display; +int cycle_empty = 0; +int cycle_visible = 0; + /* dialog windows */ double dialog_ratio = .6; /* status bar */ @@ -265,6 +268,8 @@ union arg { #define SWM_ARG_ID_MASTERDEL (9) #define SWM_ARG_ID_STACKRESET (10) #define SWM_ARG_ID_STACKINIT (11) +#define SWM_ARG_ID_CYCLEWS_UP (12) +#define SWM_ARG_ID_CYCLEWS_DOWN (13) char **argv; }; @@ -418,6 +423,10 @@ conf_load(char *filename) name_to_color(val); else goto badidx; + else if (!strncmp(var, "cycle_empty", strlen("cycle_empty"))) + cycle_visible = atoi(val); + else if (!strncmp(var, "cycle_visible", strlen("cycle_visible"))) + cycle_visible = atoi(val); else goto bad; break; @@ -785,6 +794,45 @@ switchws(struct swm_region *r, union arg *args) } void +cyclews(struct swm_region *r, union arg *args) +{ + union arg a; + struct swm_screen *s = r->s; + + DNPRINTF(SWM_D_WS, "cyclews id %d " + "in screen %d region %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_UP: + if (a.id < SWM_WS_MAX - 1) + a.id++; + else + a.id = 0; + break; + case SWM_ARG_ID_CYCLEWS_DOWN: + if (a.id > 0) + a.id--; + else + a.id = SWM_WS_MAX - 1; + break; + default: + return; + }; + + if (cycle_empty == 0 && TAILQ_EMPTY(&s->ws[a.id].winlist)) + continue; + if (cycle_visible == 0 && s->ws[a.id].r != NULL) + continue; + + switchws(r, &a); + } while (a.id != r->ws->idx); +} + +void swapwin(struct swm_region *r, union arg *args) { struct ws_win *target; @@ -1281,6 +1329,8 @@ struct key { { MODKEY, XK_8, switchws, {.id = 7} }, { MODKEY, XK_9, switchws, {.id = 8} }, { MODKEY, XK_0, switchws, {.id = 9} }, + { MODKEY, XK_Right, cyclews, {.id = SWM_ARG_ID_CYCLEWS_UP} }, + { MODKEY, XK_Left, cyclews, {.id = SWM_ARG_ID_CYCLEWS_DOWN} }, { MODKEY | ShiftMask, XK_1, send_to_ws, {.id = 0} }, { MODKEY | ShiftMask, XK_2, send_to_ws, {.id = 1} }, { MODKEY | ShiftMask, XK_3, send_to_ws, {.id = 2} }, -- 1.7.10.4