JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Move some more declarations to where they belong.
[spectrwm.git] / scrotwm.c
index bc149b3..51f73cf 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -48,7 +48,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#define        SWM_VERSION     "0.5"
+#define        SWM_VERSION     "0.6"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -175,7 +175,7 @@ char                        *bar_fonts[] = {
 
 /* terminal + args */
 char                   *spawn_term[] = { "xterm", NULL };
-char                   *spawn_screenshot[] = { "screenshot.sh", NULL, NULL }; /* XXX get from conf */
+char                   *spawn_screenshot[] = { "screenshot.sh", NULL, NULL };
 char                   *spawn_menu[] = { "dmenu_run", "-fn", NULL,
                            "-nb", NULL, "-nf", NULL, "-sb", NULL, "-sf", NULL, NULL };
 
@@ -302,6 +302,8 @@ union arg {
 #define SWM_ARG_ID_STACKINIT   (11)
 #define SWM_ARG_ID_CYCLEWS_UP  (12)
 #define SWM_ARG_ID_CYCLEWS_DOWN        (13)
+#define SWM_ARG_ID_CYCLESC_UP  (14)
+#define SWM_ARG_ID_CYCLESC_DOWN        (15)
 #define SWM_ARG_ID_SS_ALL      (0)
 #define SWM_ARG_ID_SS_WINDOW   (1)
        char                    **argv;
@@ -457,10 +459,13 @@ conf_load(char *filename)
 
                case 's':
                        if (!strncmp(var, "spawn_term", strlen("spawn_term")))
-                               asprintf(&spawn_term[0], "%s", val); /* XXX args? */
+                               asprintf(&spawn_term[0], "%s", val);
                        if (!strncmp(var, "screenshot_enabled",
                            strlen("screenshot_enabled")))
                                ss_enabled = atoi(val);
+                       if (!strncmp(var, "screenshot_app",
+                           strlen("screenshot_app")))
+                               asprintf(&spawn_screenshot[0], "%s", val);
                        break;
                default:
                        goto bad;
@@ -720,6 +725,18 @@ quit(struct swm_region *r, union arg *args)
 }
 
 void
+unmap_all(void)
+{
+       struct ws_win           *win;
+       int                     i, j;
+
+       for (i = 0; i < ScreenCount(display); i++)
+               for (j = 0; j < SWM_WS_MAX; j++)
+                       TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry)
+                               XUnmapWindow(display, win->id);
+}
+
+void
 restart(struct swm_region *r, union arg *args)
 {
        DNPRINTF(SWM_D_MISC, "restart: %s\n", start_argv[0]);
@@ -731,6 +748,7 @@ restart(struct swm_region *r, union arg *args)
 
        bar_extra_stop();
        bar_extra = 1;
+       unmap_all();
        XCloseDisplay(display);
        execvp(start_argv[0], start_argv);
        fprintf(stderr, "execvp failed\n");
@@ -902,7 +920,6 @@ switchws(struct swm_region *r, union arg *args)
 
                TAILQ_FOREACH(win, &old_ws->winlist, entry)
                        XUnmapWindow(display, win->id);
-
                old_ws->r = NULL;
                old_ws->restack = 1;
        } else {
@@ -931,7 +948,6 @@ cyclews(struct swm_region *r, union arg *args)
            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:
@@ -960,6 +976,33 @@ cyclews(struct swm_region *r, union arg *args)
 }
 
 void
+cyclescr(struct swm_region *r, union arg *args)
+{
+       struct swm_region       *rr;
+       int                     i;
+
+       i = r->s->idx;
+       switch (args->id) {
+       case SWM_ARG_ID_CYCLESC_UP:
+               rr = TAILQ_NEXT(r, entry);
+               if (rr == NULL)
+                       rr = TAILQ_FIRST(&screens[i].rl);
+               break;
+       case SWM_ARG_ID_CYCLESC_DOWN:
+               rr = TAILQ_PREV(r, swm_region_list, entry);
+               if (rr == NULL)
+                       rr = TAILQ_LAST(&screens[i].rl, swm_region_list);
+               break;
+       default:
+               return;
+       };
+       unfocus_all();
+       XSetInputFocus(display, PointerRoot, RevertToPointerRoot, CurrentTime);
+       XWarpPointer(display, None, rr->s[i].root, 0, 0, 0, 0, rr->g.x,
+           rr->g.y + bar_enabled ? bar_height : 0);
+}
+
+void
 swapwin(struct swm_region *r, union arg *args)
 {
        struct ws_win           *target;
@@ -1044,7 +1087,7 @@ focus(struct swm_region *r, union arg *args)
                return;
        }
 
-       if (winfocus == winlostfocus)
+       if (winfocus == winlostfocus || winfocus == NULL)
                return;
 
        XMapRaised(display, winfocus->id);
@@ -1063,7 +1106,6 @@ cycle_layout(struct swm_region *r, union arg *args)
        if (ws->cur_layout->l_stack == NULL)
                ws->cur_layout = &layouts[0];
        ignore_enter = 1;
-
        stack();
 }
 
@@ -1524,6 +1566,8 @@ struct key {
        { 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_Right,       cyclescr,       {.id = SWM_ARG_ID_CYCLESC_UP} }, 
+       { MODKEY | ShiftMask,   XK_Left,        cyclescr,       {.id = SWM_ARG_ID_CYCLESC_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} },
@@ -1713,6 +1757,8 @@ manage_window(Window id)
        unsigned char           ws_idx_str[SWM_PROPLEN], *prop = NULL;
        struct swm_region       *r;
        long                    mask;
+       int                     ws_idx;
+       const char              *errstr;
 
        if ((win = find_window(id)) != NULL)
                        return (win);   /* already being managed */
@@ -1729,9 +1775,6 @@ manage_window(Window id)
        r = root_to_region(win->wa.root);
        /* If the window was managed before, put it in the same workspace */
        if (prop) {
-               int             ws_idx;
-               const char      *errstr;
-
                DNPRINTF(SWM_D_PROP, "got property _SWM_WS=%s\n", prop);
                ws_idx = strtonum(prop, 0, 9, &errstr);
                if (errstr)
@@ -1885,16 +1928,16 @@ destroynotify(XEvent *e)
                        ws->focus = TAILQ_PREV(win, ws_win_list, entry);
                if (ws->focus == NULL)
                        ws->focus = TAILQ_FIRST(&ws->winlist);
-               if (ws->focus == win)
+               if (ws->focus == NULL || ws->focus == win) {
                        ws->focus = NULL;
-               if (cur_focus == win)
+                       unfocus_all();
+               } else
                        focus_win(ws->focus);
-
                TAILQ_REMOVE(&ws->winlist, win, entry);
                set_win_state(win, WithdrawnState);
                free(win);
+               stack();
        }
-       stack();
 }
 
 void