X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=scrotwm.c;h=10806c9bbf9a171a24d105751f09e106ade1a117;hb=48c0f7f55a3f10abac4a03969d069b4e2bdbee5b;hp=2ce3b49f84835096fb928d31afd5299b182f6669;hpb=c2adf746f6c01b3d919f9505c67bc7526f39e3db;p=spectrwm.git diff --git a/scrotwm.c b/scrotwm.c index 2ce3b49..10806c9 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -332,8 +332,10 @@ struct layout { { NULL, NULL, 0, NULL }, }; -/* position of max_stack mode in the layouts array */ -#define SWM_MAX_STACK 2 +/* position of max_stack mode in the layouts array, index into layouts! */ +#define SWM_V_STACK (0) +#define SWM_H_STACK (1) +#define SWM_MAX_STACK (2) #define SWM_H_SLICE (32) #define SWM_V_SLICE (32) @@ -341,6 +343,7 @@ struct layout { /* define work spaces */ struct workspace { int idx; /* workspace index */ + int always_raise; /* raise windows on focus */ struct layout *cur_layout; /* current layout handlers */ struct ws_win *focus; /* may be NULL */ struct ws_win *focus_prev; /* may be NULL */ @@ -1957,11 +1960,11 @@ focus_win(struct ws_win *win) if (win->java == 0) XSetInputFocus(display, win->id, RevertToParent, CurrentTime); - XMapRaised(display, win->id); grabbuttons(win, 1); XSetWindowBorder(display, win->id, win->ws->r->s->c[SWM_S_COLOR_FOCUS].color); - if (win->ws->cur_layout->flags & SWM_L_MAPONFOCUS) + if (win->ws->cur_layout->flags & SWM_L_MAPONFOCUS || + win->ws->always_raise) XMapRaised(display, win->id); XChangeProperty(display, win->s->root, @@ -3000,6 +3003,19 @@ send_to_ws(struct swm_region *r, union arg *args) } void +raise_toggle(struct swm_region *r, union arg *args) +{ + if (r && r->ws == NULL) + return; + + r->ws->always_raise = !r->ws->always_raise; + + /* bring floaters back to top */ + if (r->ws->always_raise == 0) + stack(); +} + +void iconify(struct swm_region *r, union arg *args) { union arg a; @@ -3484,6 +3500,7 @@ enum keyfuncid { kf_spawn_custom, kf_iconify, kf_uniconify, + kf_raise_toggle, kf_dumpwins, /* MUST BE LAST */ kf_invalid }; @@ -3560,6 +3577,7 @@ struct keyfunc { { "spawn_custom", dummykeyfunc, {0} }, { "iconify", iconify, {0} }, { "uniconify", uniconify, {0} }, + { "raise_toggle", raise_toggle, {0} }, { "dumpwins", dumpwins, {0} }, /* MUST BE LAST */ { "invalid key func", NULL, {0} }, }; @@ -4151,6 +4169,7 @@ setup_keys(void) setkeybinding(MODKEY|ShiftMask, XK_i, kf_spawn_custom, "initscr"); setkeybinding(MODKEY, XK_w, kf_iconify, NULL); setkeybinding(MODKEY|ShiftMask, XK_w, kf_uniconify, NULL); + setkeybinding(MODKEY|ShiftMask, XK_r, kf_raise_toggle,NULL); #ifdef SWM_DEBUG setkeybinding(MODKEY|ShiftMask, XK_d, kf_dumpwins, NULL); #endif @@ -4535,10 +4554,10 @@ setautorun(char *selector, char *value, int flags) bzero(s, sizeof s); if (sscanf(value, "ws[%d]:%1023c", &ws_id, s) != 2) - errx(1, "invalid autorun entry, should be 'ws:command'\n"); + errx(1, "invalid autorun entry, should be 'ws[]:command'\n"); ws_id--; if (ws_id < 0 || ws_id >= SWM_WS_MAX) - errx(1, "invalid workspace %d\n", ws_id + 1); + errx(1, "autorun: invalid workspace %d\n", ws_id + 1); /* * This is a little intricate @@ -4584,11 +4603,76 @@ setautorun(char *selector, char *value, int flags) return (0); } +int +setlayout(char *selector, char *value, int flags) +{ + int ws_id, st, i, x, mg, ma, si, raise; + char s[1024]; + struct workspace *ws; + + if (getenv("SWM_STARTED")) + return (0); + + bzero(s, sizeof s); + if (sscanf(value, "ws[%d]:%d:%d:%d:%d:%1023c", + &ws_id, &mg, &ma, &si, &raise, s) != 6) + errx(1, "invalid layout entry, should be 'ws[]:" + "::::" + "'\n"); + ws_id--; + if (ws_id < 0 || ws_id >= SWM_WS_MAX) + errx(1, "layout: invalid workspace %d\n", ws_id + 1); + + if (!strcasecmp(s, "vertical")) + st = SWM_V_STACK; + else if (!strcasecmp(s, "horizontal")) + st = SWM_H_STACK; + else if (!strcasecmp(s, "fullscreen")) + st = SWM_MAX_STACK; + else + errx(1, "invalid layout entry, should be 'ws[]:" + "::::" + "'\n"); + + for (i = 0; i < ScreenCount(display); i++) { + ws = (struct workspace *)&screens[i].ws; + ws[ws_id].cur_layout = &layouts[st]; + + ws[ws_id].always_raise = raise; + if (st == SWM_MAX_STACK) + continue; + + /* master grow */ + for (x = 0; x < abs(mg); x++) { + ws[ws_id].cur_layout->l_config(&ws[ws_id], + mg >= 0 ? SWM_ARG_ID_MASTERGROW : + SWM_ARG_ID_MASTERSHRINK); + stack(); + } + /* master add */ + for (x = 0; x < abs(ma); x++) { + ws[ws_id].cur_layout->l_config(&ws[ws_id], + ma >= 0 ? SWM_ARG_ID_MASTERADD : + SWM_ARG_ID_MASTERDEL); + stack(); + } + /* stack inc */ + for (x = 0; x < abs(si); x++) { + ws[ws_id].cur_layout->l_config(&ws[ws_id], + si >= 0 ? SWM_ARG_ID_STACKINC : + SWM_ARG_ID_STACKDEC); + stack(); + } + } + + return (0); +} + /* config options */ struct config_option { char *optname; - int (*func)(char*, char*, int); - int funcflags; + int (*func)(char*, char*, int); + int funcflags; }; struct config_option configopt[] = { { "bar_enabled", setconfvalue, SWM_S_BAR_ENABLED }, @@ -4624,6 +4708,7 @@ struct config_option configopt[] = { { "disable_border", setconfvalue, SWM_S_DISABLE_BORDER }, { "border_width", setconfvalue, SWM_S_BORDER_WIDTH }, { "autorun", setautorun, 0 }, + { "layout", setlayout, 0 }, };