X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=scrotwm.c;h=5890eab28bbba5ef292d1fc59549e83bffa7b294;hb=4f26b7c5ca04f70c9091d7f714ac6ae8602b2273;hp=65f6551b374b5a8801f2c02993d9e2cdd5211894;hpb=b05bba3a0eb734161fb0fabfbaa921111cc96b70;p=spectrwm.git diff --git a/scrotwm.c b/scrotwm.c index 65f6551..5890eab 100644 --- 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; @@ -137,6 +138,9 @@ struct ws_win { int y; int width; int height; + int floating; + int transient; + XWindowAttributes wa; }; TAILQ_HEAD(ws_win_list, ws_win); @@ -147,7 +151,6 @@ 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; /* list of windows in ws */ } ws[SWM_WS_MAX]; int current_ws = 0; @@ -185,7 +188,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 +195,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 +238,6 @@ conf_load(char *filename) default: goto bad; } - free(line); } @@ -323,16 +322,33 @@ 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"); bar_print(); } +int +count_win(int wsid, int count_transient) +{ + struct ws_win *win; + int count = 0; + + TAILQ_FOREACH (win, &ws[wsid].winlist, entry) { + if (count_transient == 0 && win->transient) + continue; + count++; + } + DNPRINTF(SWM_D_MISC, "count_win: %d\n", count); + + return (count); +} void quit(union arg *args) { @@ -393,7 +409,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) @@ -419,7 +435,7 @@ focus(union arg *args) struct ws_win *winfocus, *winlostfocus; DNPRINTF(SWM_D_FOCUS, "focus: id %d\n", args->id); - if (ws[current_ws].focus == NULL || ws[current_ws].winno == 0) + if (ws[current_ws].focus == NULL || count_win(current_ws, 1) == 0) return; winlostfocus = ws[current_ws].focus; @@ -460,7 +476,9 @@ stack(void) { XWindowChanges wc; struct ws_win wf, *win, *winfocus = &wf; - int i, h, w, x, y, hrh; + int i, h, w, x, y, hrh, winno; + int floater = 0; + unsigned int mask; DNPRINTF(SWM_D_EVENT, "stack: workspace: %d\n", current_ws); @@ -468,16 +486,17 @@ stack(void) ws[current_ws].restack = 0; - if (ws[current_ws].winno == 0) + winno = count_win(current_ws, 0); + if (winno == 0) return; - if (ws[current_ws].winno > 1) + if (winno > 1) w = width / 2; else w = width; - if (ws[current_ws].winno > 2) - hrh = height / (ws[current_ws].winno - 1); + if (winno > 2) + hrh = height / (winno - 1); else hrh = 0; @@ -508,19 +527,36 @@ stack(void) } } + if (win->transient != 0 || win->floating != 0) + floater = 1; + else + floater = 0; + bzero(&wc, sizeof wc); - win->x = wc.x = x; - win->y = wc.y = y; - win->width = wc.width = w; - win->height = wc.height = h; wc.border_width = 1; - XConfigureWindow(display, win->id, CWX | CWY | CWWidth | - CWHeight | CWBorderWidth, &wc); + if (floater == 0) { + win->x = wc.x = x; + win->y = wc.y = y; + win->width = wc.width = w; + win->height = wc.height = h; + mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth; + } else { + /* make sure we don't clobber the screen */ + if (win->wa.width > width) + win->wa.width = width; + if (win->wa.height > height) + win->wa.width = height; + win->x = wc.x = (width - win->wa.width) / 2; + win->y = wc.y = (height - win->wa.height) / 2; + mask = CWX | CWY | CWBorderWidth; + } + XConfigureWindow(display, win->id, mask, &wc); + if (win == ws[current_ws].focus) winfocus = win; else unfocus_win(win); - XMapWindow(display, win->id); + XMapRaised(display, win->id); i++; } @@ -565,12 +601,10 @@ send_to_ws(union arg *args) 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) + if (count_win(wsid, 1) == 0) ws[wsid].focus = win; - ws[wsid].winno++; ws[wsid].restack = 1; stack(); @@ -585,7 +619,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} }, @@ -709,12 +744,18 @@ void configurerequest(XEvent *e) { XConfigureRequestEvent *ev = &e->xconfigurerequest; + Window trans; struct ws_win *win; 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); + FocusChangeMask | ExposureMask); if ((win = calloc(1, sizeof(struct ws_win))) == NULL) errx(1, "calloc: failed to allocate memory for new window"); @@ -722,7 +763,27 @@ configurerequest(XEvent *e) win->id = ev->window; TAILQ_INSERT_TAIL(&ws[current_ws].winlist, win, entry); ws[current_ws].focus = win; /* make new win focused */ - ws[current_ws].winno++; + + XGetTransientForHint(display, win->id, &trans); + if (trans) { + win->transient = trans; + DNPRINTF(SWM_D_MISC, "configurerequest: win %u transient %u\n", + (unsigned)win->id, win->transient); + } + XGetWindowAttributes(display, win->id, &win->wa); +#if 0 + XClassHint ch = { 0 }; + if(XGetClassHint(display, win->id, &ch)) { + fprintf(stderr, "class: %s name: %s\n", ch.res_class, ch.res_name); + if (!strcmp(ch.res_class, "Gvim") && !strcmp(ch.res_name, "gvim")) { + win->floating = 0; + } + if(ch.res_class) + XFree(ch.res_class); + if(ch.res_name) + XFree(ch.res_name); + } +#endif stack(); } @@ -752,7 +813,6 @@ destroynotify(XEvent *e) TAILQ_REMOVE(&ws[current_ws].winlist, win, entry); free(win); - ws[current_ws].winno--; break; } } @@ -791,9 +851,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 +898,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 +921,7 @@ void (*handler[LASTEvent])(XEvent *) = { [MapRequest] = maprequest, [PropertyNotify] = propertynotify, [UnmapNotify] = unmapnotify, + [VisibilityNotify] = visibilitynotify, }; int @@ -909,7 +981,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()); @@ -932,13 +1004,11 @@ main(int argc, char *argv[]) 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); } @@ -948,7 +1018,7 @@ main(int argc, char *argv[]) XSelectInput(display, root, SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask | KeyPressMask | EnterWindowMask | LeaveWindowMask | StructureNotifyMask | - FocusChangeMask | PropertyChangeMask); + FocusChangeMask | PropertyChangeMask | ExposureMask); grabkeys();