X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=scrotwm.c;h=45e0787a6940fed9060ba050c2cac5befbd10702;hb=08c761d14b4c40dcf0be20dc5fc1ae71f81eff12;hp=40ecb3173f67174cfd00ffb672f8fc8293723db9;hpb=cdd5d1fed80c316205afd5107dd90a3ebf0c0aa2;p=spectrwm.git diff --git a/scrotwm.c b/scrotwm.c index 40ecb31..45e0787 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -56,6 +56,8 @@ #include #include #include +#include +#include #include #include @@ -128,9 +130,10 @@ TAILQ_HEAD(ws_win_list, ws_win); #define SWM_WS_MAX (10) struct workspace { int visible; /* workspace visible */ + int restack; /* restack on switch */ struct ws_win *focus; /* which win has focus */ int winno; /* total nr of windows */ - struct ws_win_list winlist; + struct ws_win_list winlist; /* list of windows in ws */ } ws[SWM_WS_MAX]; int current_ws = 0; @@ -143,12 +146,18 @@ union arg { char **argv; }; + +void stack(void); + void bar_print(void) { time_t tmt; struct tm tm; + if (bar_enabled == 0) + return; + /* clear old text */ XSetForeground(display, bar_gc, 0x000000); XDrawString(display, bar_window, bar_gc, 4, bar_fs->ascent, bar_text, @@ -162,7 +171,41 @@ bar_print(void) XDrawString(display, bar_window, bar_gc, 4, bar_fs->ascent, bar_text, strlen(bar_text)); XSync(display, False); + + alarm(60); +} + +void +bar_signal(int sig) +{ + /* XXX yeah yeah byte me */ + bar_print(); } + +void +bar_toggle(union arg *args) +{ + int i; + + DNPRINTF(SWM_D_MISC, "bar_toggle\n"); + + if (bar_enabled) { + bar_enabled = 0; + height += bar_height; /* correct screen height */ + XUnmapWindow(display, bar_window); + } else { + bar_enabled = 1; + height -= bar_height; /* correct screen height */ + XMapWindow(display, bar_window); + } + XSync(display, False); + for (i = 0; i < SWM_WS_MAX; i++) + ws[i].restack = 1; + + stack(); + bar_print(); /* must be after stack */ +} + void quit(union arg *args) { @@ -195,7 +238,7 @@ spawn(union arg *args) void focus_win(struct ws_win *win) { - DNPRINTF(SWM_D_FOCUS, "focus_win: id: %d\n", win->id); + DNPRINTF(SWM_D_FOCUS, "focus_win: id: %lu\n", win->id); XSetWindowBorder(display, win->id, col_focus); XSetInputFocus(display, win->id, RevertToPointerRoot, CurrentTime); ws[current_ws].focus = win; @@ -204,7 +247,7 @@ focus_win(struct ws_win *win) void unfocus_win(struct ws_win *win) { - DNPRINTF(SWM_D_FOCUS, "unfocus_win: id: %d\n", win->id); + DNPRINTF(SWM_D_FOCUS, "unfocus_win: id: %lu\n", win->id); XSetWindowBorder(display, win->id, col_unfocus); if (ws[current_ws].focus == win) ws[current_ws].focus = NULL; @@ -215,7 +258,6 @@ switchws(union arg *args) { int wsid = args->id; struct ws_win *win; - Window winfocus; DNPRINTF(SWM_D_WS, "switchws: %d\n", wsid + 1); @@ -234,9 +276,14 @@ switchws(union arg *args) current_ws = wsid; ignore_enter = 1; - if (ws[wsid].focus != NULL) - focus_win(ws[wsid].focus); - XSync(display, False); + if (ws[wsid].restack) { + stack(); + bar_print(); + } else { + if (ws[wsid].focus != NULL) + focus_win(ws[wsid].focus); + XSync(display, False); + } } void @@ -252,27 +299,22 @@ focus(union arg *args) switch (args->id) { case SWM_ARG_ID_FOCUSPREV: - if (ws[current_ws].focus == - TAILQ_FIRST(&ws[current_ws].winlist)) + ws[current_ws].focus = + TAILQ_PREV(ws[current_ws].focus, ws_win_list, entry); + if (ws[current_ws].focus == NULL) ws[current_ws].focus = TAILQ_LAST(&ws[current_ws].winlist, ws_win_list); - else - ws[current_ws].focus =TAILQ_PREV(ws[current_ws].focus, - ws_win_list, entry); break; case SWM_ARG_ID_FOCUSNEXT: - if (ws[current_ws].focus == TAILQ_LAST(&ws[current_ws].winlist, - ws_win_list)) + ws[current_ws].focus = TAILQ_NEXT(ws[current_ws].focus, entry); + if (ws[current_ws].focus == NULL) ws[current_ws].focus = TAILQ_FIRST(&ws[current_ws].winlist); - else - ws[current_ws].focus = - TAILQ_NEXT(ws[current_ws].focus, entry); break; case SWM_ARG_ID_FOCUSMAIN: - ws[current_ws].focus = TAILQ_FIRST(&ws[current_ws].winlist);; + ws[current_ws].focus = TAILQ_FIRST(&ws[current_ws].winlist); break; default: @@ -291,12 +333,14 @@ stack(void) { XWindowChanges wc; struct ws_win wf, *win, *winfocus = &wf; - int i, h, w, x, y, winno, hrh; + int i, h, w, x, y, hrh; DNPRINTF(SWM_D_EVENT, "stack: workspace: %d\n", current_ws); winfocus->id = root; + ws[current_ws].restack = 0; + if (ws[current_ws].winno == 0) return; @@ -311,7 +355,7 @@ stack(void) hrh = 0; x = 0; - y = bar_height; + y = bar_enabled ? bar_height : 0; h = height; i = 0; TAILQ_FOREACH (win, &ws[current_ws].winlist, entry) { @@ -362,7 +406,12 @@ swap_to_main(union arg *args) { struct ws_win *tmpwin = TAILQ_FIRST(&ws[current_ws].winlist); - DNPRINTF(SWM_D_MISC, "swap_to_main: win: %d\n", ws[current_ws].focus->id); + DNPRINTF(SWM_D_MISC, "swap_to_main: win: %lu\n", + ws[current_ws].focus ? ws[current_ws].focus->id : 0); + + if (ws[current_ws].focus == NULL || ws[current_ws].focus == tmpwin) + return; + TAILQ_REMOVE(&ws[current_ws].winlist, tmpwin, entry); TAILQ_INSERT_AFTER(&ws[current_ws].winlist, ws[current_ws].focus, tmpwin, entry); @@ -373,6 +422,33 @@ swap_to_main(union arg *args) stack(); } +void +send_to_ws(union arg *args) +{ + int wsid = args->id; + struct ws_win *win = ws[current_ws].focus; + + DNPRINTF(SWM_D_WS, "send_to_ws: win: %lu\n", win->id); + + XUnmapWindow(display, win->id); + + /* find a window to focus */ + ws[current_ws].focus = TAILQ_PREV(win, ws_win_list,entry); + if (ws[current_ws].focus == NULL) + ws[current_ws].focus = TAILQ_FIRST(&ws[current_ws].winlist); + + TAILQ_REMOVE(&ws[current_ws].winlist, win, entry); + ws[current_ws].winno--; + + TAILQ_INSERT_TAIL(&ws[wsid].winlist, win, entry); + if (ws[wsid].winno == 0) + ws[wsid].focus = win; + ws[wsid].winno++; + ws[wsid].restack = 1; + + stack(); +} + /* terminal + args */ char *term[] = { "xterm", NULL }; @@ -398,6 +474,17 @@ struct key { { MODKEY, XK_8, switchws, {.id = 7} }, { MODKEY, XK_9, switchws, {.id = 8} }, { MODKEY, XK_0, switchws, {.id = 9} }, + { 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} }, + { MODKEY | ShiftMask, XK_4, send_to_ws, {.id = 3} }, + { MODKEY | ShiftMask, XK_5, send_to_ws, {.id = 4} }, + { MODKEY | ShiftMask, XK_6, send_to_ws, {.id = 5} }, + { MODKEY | ShiftMask, XK_7, send_to_ws, {.id = 6} }, + { MODKEY | ShiftMask, XK_8, send_to_ws, {.id = 7} }, + { MODKEY | ShiftMask, XK_9, send_to_ws, {.id = 8} }, + { MODKEY | ShiftMask, XK_0, send_to_ws, {.id = 9} }, + { MODKEY, XK_b, bar_toggle, {0} }, { MODKEY, XK_Tab, focus, {.id = SWM_ARG_ID_FOCUSNEXT} }, { MODKEY | ShiftMask, XK_Tab, focus, {.id = SWM_ARG_ID_FOCUSPREV} }, }; @@ -443,9 +530,7 @@ grabkeys(void) void expose(XEvent *e) { - XExposeEvent *ev = &e->xexpose; - - DNPRINTF(SWM_D_EVENT, "expose: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "expose: window: %lu\n", e->xexpose.window); } void @@ -455,7 +540,7 @@ keypress(XEvent *e) KeySym keysym; XKeyEvent *ev = &e->xkey; - DNPRINTF(SWM_D_EVENT, "keypress: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "keypress: window: %lu\n", ev->window); keysym = XKeycodeToKeysym(display, (KeyCode)ev->keycode, 0); for(i = 0; i < LENGTH(keys); i++) @@ -469,15 +554,18 @@ void buttonpress(XEvent *e) { XButtonPressedEvent *ev = &e->xbutton; +#ifdef SWM_CLICKTOFOCUS struct ws_win *win; +#endif - DNPRINTF(SWM_D_EVENT, "buttonpress: window: %d\n", ev->window); + + DNPRINTF(SWM_D_EVENT, "buttonpress: window: %lu\n", ev->window); if (ev->window == root) return; if (ev->window == ws[current_ws].focus->id) return; -#if 0 +#ifdef SWM_CLICKTOFOCUS TAILQ_FOREACH(win, &ws[current_ws].winlist, entry) if (win->id == ev->window) { /* focus in the clicked window */ @@ -499,7 +587,7 @@ configurerequest(XEvent *e) XConfigureRequestEvent *ev = &e->xconfigurerequest; struct ws_win *win; - DNPRINTF(SWM_D_EVENT, "configurerequest: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "configurerequest: window: %lu\n", ev->window); XSelectInput(display, ev->window, ButtonPressMask | EnterWindowMask | FocusChangeMask); @@ -517,19 +605,17 @@ configurerequest(XEvent *e) void configurenotify(XEvent *e) { - XConfigureEvent *ev = &e->xconfigure; - - DNPRINTF(SWM_D_EVENT, "configurenotify: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "configurenotify: window: %lu\n", + e->xconfigure.window); } void destroynotify(XEvent *e) { - size_t sz; struct ws_win *win; XDestroyWindowEvent *ev = &e->xdestroywindow; - DNPRINTF(SWM_D_EVENT, "destroynotify: window %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "destroynotify: window %lu\n", ev->window); TAILQ_FOREACH (win, &ws[current_ws].winlist, entry) { if (ev->window == win->id) { @@ -556,7 +642,7 @@ enternotify(XEvent *e) XCrossingEvent *ev = &e->xcrossing; struct ws_win *win; - DNPRINTF(SWM_D_EVENT, "enternotify: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "enternotify: window: %lu\n", ev->window); if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) @@ -579,7 +665,7 @@ focusin(XEvent *e) { XFocusChangeEvent *ev = &e->xfocus; - DNPRINTF(SWM_D_EVENT, "focusin: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "focusin: window: %lu\n", ev->window); if (ev->window == root) return; @@ -589,7 +675,7 @@ focusin(XEvent *e) * click to focus */ /* - DNPRINTF(SWM_D_EVENT, "focusin: window: %d grabbing\n", ev->window); + DNPRINTF(SWM_D_EVENT, "focusin: window: %lu grabbing\n", ev->window); XGrabButton(display, Button1, AnyModifier, ev->window, False, ButtonPress, GrabModeAsync, GrabModeSync, None, None); */ @@ -600,7 +686,7 @@ mappingnotify(XEvent *e) { XMappingEvent *ev = &e->xmapping; - DNPRINTF(SWM_D_EVENT, "mappingnotify: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "mappingnotify: window: %lu\n", ev->window); XRefreshKeyboardMapping(ev); if(ev->request == MappingKeyboard) @@ -610,25 +696,21 @@ mappingnotify(XEvent *e) void maprequest(XEvent *e) { - XMapRequestEvent *ev = &e->xmaprequest; - - DNPRINTF(SWM_D_EVENT, "maprequest: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "maprequest: window: %lu\n", + e->xmaprequest.window); } void propertynotify(XEvent *e) { - XPropertyEvent *ev = &e->xproperty; - - DNPRINTF(SWM_D_EVENT, "propertynotify: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "propertynotify: window: %lu\n", + e->xproperty.window); } void unmapnotify(XEvent *e) { - XUnmapEvent *ev = &e->xunmap; - - DNPRINTF(SWM_D_EVENT, "unmapnotify: window: %d\n", ev->window); + DNPRINTF(SWM_D_EVENT, "unmapnotify: window: %lu\n", e->xunmap.window); } void (*handler[LASTEvent])(XEvent *) = { @@ -702,11 +784,13 @@ main(int argc, char *argv[]) /* make work space 1 active */ ws[0].visible = 1; + ws[0].restack = 0; ws[0].focus = NULL; ws[0].winno = 0; TAILQ_INIT(&ws[0].winlist); for (i = 1; i < SWM_WS_MAX; i++) { ws[i].visible = 0; + ws[i].restack = 0; ws[i].focus = NULL; ws[i].winno = 0; TAILQ_INIT(&ws[i].winlist); @@ -739,6 +823,9 @@ main(int argc, char *argv[]) height -= bar_height; /* correct screen height */ XMapWindow(display, bar_window); } + + if (signal(SIGALRM, bar_signal) == SIG_ERR) + err(1, "could not install bar_signal"); bar_print(); while (running) {