JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Add unobscure event so that we can rebuild the bar after dmenu exits.
[spectrwm.git] / scrotwm.c
index 65f6551..26d240d 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -122,13 +122,14 @@ XGCValues         bar_gcv;
 XFontStruct            *bar_fs;
 char                   bar_text[128];
 char                   *bar_fonts[] = {
-                               "-*-terminus-*-*-*-*-*-*-*-*-*-*-*-*",
-                               "-*-times-medium-r-*-*-*-*-*-*-*-*-*-*",
-                               NULL
+                           "-*-terminus-*-*-*-*-*-*-*-*-*-*-*-*",
+                           "-*-times-medium-r-*-*-*-*-*-*-*-*-*-*",
+                           NULL
 };
 
 /* terminal + args */
 char                           *spawn_term[] = { "xterm", NULL };
+char                           *spawn_menu[] = { "dmenu_run", NULL };
 
 struct ws_win {
        TAILQ_ENTRY(ws_win)     entry;
@@ -185,7 +186,6 @@ conf_load(char *filename)
                if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL)
                        if (feof(config))
                                break;
-
                cp = line;
                cp += (long)strspn(cp, SWM_CONF_WS);
                if (cp[0] == '\0') {
@@ -193,10 +193,8 @@ conf_load(char *filename)
                        free(line);
                        continue;
                }
-
                if ((var = strsep(&cp, SWM_CONF_WS)) == NULL || cp == NULL)
                        break;
-
                cp += (long)strspn(cp, SWM_CONF_WS);
                if ((val = strsep(&cp, SWM_CONF_WS)) == NULL)
                        break;
@@ -238,7 +236,6 @@ conf_load(char *filename)
                default:
                        goto bad;
                }
-
                free(line);
        }
 
@@ -323,10 +320,12 @@ bar_setup(void)
            bar_height - 2, 1, bar_border, bar_color);
        bar_gc = XCreateGC(display, bar_window, 0, &bar_gcv);
        XSetFont(display, bar_gc, bar_fs->fid);
+       XSelectInput(display, bar_window, VisibilityChangeMask);
        if (bar_enabled) {
                height -= bar_height; /* correct screen height */
                XMapWindow(display, bar_window);
        }
+       DNPRINTF(SWM_D_MISC, "bar_setup: bar_window %d\n", (int)bar_window);
 
        if (signal(SIGALRM, bar_signal) == SIG_ERR)
                err(1, "could not install bar_signal");
@@ -393,7 +392,7 @@ switchws(union arg *args)
 
        /* map new window first to prevent ugly blinking */
        TAILQ_FOREACH (win, &ws[wsid].winlist, entry)
-               XMapWindow(display, win->id);
+               XMapRaised(display, win->id);
        ws[wsid].visible = 1;
 
        TAILQ_FOREACH (win, &ws[current_ws].winlist, entry)
@@ -520,7 +519,7 @@ stack(void)
                        winfocus = win;
                else
                        unfocus_win(win);
-               XMapWindow(display, win->id);
+               XMapRaised(display, win->id);
                i++;
        }
 
@@ -585,7 +584,8 @@ struct key {
 } keys[] = {
        /* modifier             key     function                argument */
        { MODKEY,               XK_Return,      swap_to_main,   {0} },
-       { MODKEY | ShiftMask,   XK_Return,      spawn,          {.argv = spawn_term } },
+       { MODKEY | ShiftMask,   XK_Return,      spawn,          {.argv = spawn_term} },
+       { MODKEY,               XK_p,           spawn,          {.argv = spawn_menu} },
        { MODKEY | ShiftMask,   XK_q,           quit,           {0} },
        { MODKEY,               XK_m,           focus,          {.id = SWM_ARG_ID_FOCUSMAIN} },
        { MODKEY,               XK_1,           switchws,       {.id = 0} },
@@ -713,6 +713,11 @@ configurerequest(XEvent *e)
 
        DNPRINTF(SWM_D_EVENT, "configurerequest: window: %lu\n", ev->window);
 
+       TAILQ_FOREACH (win, &ws[current_ws].winlist, entry) {
+               if (ev->window == win->id)
+                       return;
+       }
+
        XSelectInput(display, ev->window, ButtonPressMask | EnterWindowMask |
            FocusChangeMask);
 
@@ -791,9 +796,10 @@ focusin(XEvent *e)
 
        DNPRINTF(SWM_D_EVENT, "focusin: window: %lu\n", ev->window);
 
+       XSync(display, False); /* not sure this helps redrawing graphic apps */
+
        if (ev->window == root)
                return;
-
        /*
         * kill grab for now so that we can cut and paste , this screws up
         * click to focus
@@ -837,6 +843,16 @@ unmapnotify(XEvent *e)
        DNPRINTF(SWM_D_EVENT, "unmapnotify: window: %lu\n", e->xunmap.window);
 }
 
+void
+visibilitynotify(XEvent *e)
+{
+       DNPRINTF(SWM_D_EVENT, "visibilitynotify: window: %lu\n", e->xvisibility.window);
+
+       if (e->xvisibility.window == bar_window &&
+           e->xvisibility.state == VisibilityUnobscured)
+               bar_print();
+}
+
 void                   (*handler[LASTEvent])(XEvent *) = {
                                [Expose] = expose,
                                [KeyPress] = keypress,
@@ -850,6 +866,7 @@ void                        (*handler[LASTEvent])(XEvent *) = {
                                [MapRequest] = maprequest,
                                [PropertyNotify] = propertynotify,
                                [UnmapNotify] = unmapnotify,
+                               [VisibilityNotify] = visibilitynotify,
 };
 
 int
@@ -909,7 +926,7 @@ main(int argc, char *argv[])
        width = DisplayWidth(display, screen) - 2;
        height = DisplayHeight(display, screen) - 2;
 
-       /* look for local and globale conf file */
+       /* look for local and global conf file */
        pwd = getpwuid(getuid());
        if (pwd == NULL)
                errx(1, "invalid user %d", getuid());