X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=scrotwm.c;h=0d4fc1ea2bc8aaa3094d3e935e29e8f4c77d1f26;hb=433cf0a7cbd857524a086aa2d2e5b9553e86298e;hp=d8b65197c59cd534b6ff03bf77770b97c859ae4b;hpb=ef5a4d70c75a403677a33caeade5b34a96cae687;p=spectrwm.git diff --git a/scrotwm.c b/scrotwm.c index d8b6519..0d4fc1e 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -154,6 +155,9 @@ 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, @@ -167,7 +171,37 @@ 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) +{ + 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); + + stack(); + bar_print(); /* must be after stack */ } + void quit(union arg *args) { @@ -260,27 +294,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: @@ -319,7 +348,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) { @@ -392,7 +421,7 @@ send_to_ws(union arg *args) int wsid = args->id; struct ws_win *win = ws[current_ws].focus; - DNPRINTF(SWM_D_MISC, "send_to_ws: win: %lu\n", win->id); + DNPRINTF(SWM_D_WS, "send_to_ws: win: %lu\n", win->id); XUnmapWindow(display, win->id); @@ -413,7 +442,6 @@ send_to_ws(union arg *args) stack(); } - /* terminal + args */ char *term[] = { "xterm", NULL }; @@ -449,8 +477,8 @@ struct key { { 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_Tab, focus, {.id = SWM_ARG_ID_FOCUSPREV} }, - { MODKEY | ShiftMask, XK_Tab, focus, {.id = SWM_ARG_ID_FOCUSNEXT} }, + { 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} }, }; @@ -788,6 +816,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) {