X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=scrotwm.c;h=a6aa81fc17e54f5f2e7d750d1d0c0c90e88e946f;hb=840c2ac2b668265acfd06f73ac2863c3ea111bbe;hp=9078c6b3d101f62bd60761c49015c2c839ffe021;hpb=5bc67cb7a856ad03f080e5e281984133ddbe932a;p=spectrwm.git diff --git a/scrotwm.c b/scrotwm.c index 9078c6b..a6aa81f 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -198,7 +198,7 @@ GC bar_gc; XGCValues bar_gcv; int bar_fidx = 0; XFontStruct *bar_fs; -char *bar_fonts[] = { NULL, NULL, NULL }; /* XXX Make fully dynamic */ +char *bar_fonts[] = { NULL, NULL, NULL, NULL };/* XXX Make fully dynamic */ char *spawn_term[] = { NULL, NULL }; /* XXX Make fully dynamic */ #define SWM_MENU_FN (2) @@ -1162,6 +1162,7 @@ unfocus_all(void) for (j = 0; j < SWM_WS_MAX; j++) TAILQ_FOREACH(win, &screens[i].ws[j].winlist, entry) unfocus_win(win); + XSync(display, False); } void @@ -1182,6 +1183,7 @@ focus_win(struct ws_win *win) grabbuttons(win, 1); XSetInputFocus(display, win->id, RevertToPointerRoot, CurrentTime); + XSync(display, False); } } @@ -1201,22 +1203,19 @@ switchws(struct swm_region *r, union arg *args) "%d -> %d\n", r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), old_ws->idx, wsid); - /* get focus window */ - if (new_ws->focus) - winfocus = new_ws->focus; - else if (new_ws->focus_prev) - winfocus = new_ws->focus_prev; + if (new_ws == old_ws) + return; + /* get focus window */ if (new_ws->focus) winfocus = new_ws->focus; else if (new_ws->focus_prev) winfocus = new_ws->focus_prev; - - if (new_ws == old_ws) - return; + else + winfocus = TAILQ_FIRST(&new_ws->winlist); other_r = new_ws->r; - if (!other_r) { + if (other_r == NULL) { /* if the other workspace is hidden, switch windows */ /* map new window first to prevent ugly blinking */ old_ws->r = NULL; @@ -1420,14 +1419,19 @@ void cycle_layout(struct swm_region *r, union arg *args) { struct workspace *ws = r->ws; + struct ws_win *winfocus; DNPRINTF(SWM_D_EVENT, "cycle_layout: workspace: %d\n", ws->idx); + winfocus = ws->focus; + ws->cur_layout++; if (ws->cur_layout->l_stack == NULL) ws->cur_layout = &layouts[0]; + ignore_enter = 1; stack(); + focus_win(winfocus); } void @@ -1858,7 +1862,7 @@ void send_to_ws(struct swm_region *r, union arg *args) { int wsid = args->id; - struct ws_win *win = r->ws->focus; + struct ws_win *win = r->ws->focus, *winfocus = NULL; struct workspace *ws, *nws; Atom ws_idx_atom = 0; unsigned char ws_idx_str[SWM_PROPLEN]; @@ -1871,14 +1875,20 @@ send_to_ws(struct swm_region *r, union arg *args) ws = win->ws; nws = &win->s->ws[wsid]; - XUnmapWindow(display, win->id); - /* find a window to focus */ - ws->focus = TAILQ_PREV(win, ws_win_list, entry); - if (ws->focus == NULL) - ws->focus = TAILQ_FIRST(&ws->winlist); - if (ws->focus == win) - ws->focus = NULL; + winfocus = TAILQ_PREV(win, ws_win_list, entry); + if (TAILQ_FIRST(&ws->winlist) == win) + winfocus = TAILQ_NEXT(win, entry); + else { + winfocus = TAILQ_PREV(ws->focus, ws_win_list, entry); + if (winfocus == NULL) + winfocus = TAILQ_LAST(&ws->winlist, ws_win_list); + } + /* out of windows in ws so focus on nws instead */ + if (winfocus == NULL) + winfocus = win; + + XUnmapWindow(display, win->id); TAILQ_REMOVE(&ws->winlist, win, entry); @@ -1901,6 +1911,7 @@ send_to_ws(struct swm_region *r, union arg *args) nws->restack = 1; stack(); + focus_win(winfocus); } void @@ -3189,7 +3200,7 @@ manage_window(Window id) { Window trans; struct workspace *ws; - struct ws_win *win; + struct ws_win *win, *ww; int format, i, ws_idx, n; unsigned long nitems, bytes; Atom ws_idx_atom = 0, type; @@ -3242,8 +3253,17 @@ manage_window(Window id) errstr, prop); } ws = &r->s->ws[ws_idx]; - } else + } else { ws = r->ws; + /* this should launch transients in the same ws as parent */ + /* XXX doesn't work for intel xrandr */ + if (id && trans) { + if ((ww = find_window(trans)) != NULL) { + ws = ww->ws; + r = ws->r; + } + } + } /* set up the window layout */ win->id = id; @@ -3316,9 +3336,6 @@ manage_window(Window id) if (win->floating && (ws->idx == r->ws->idx)) XMapRaised(display, win->id); - /* make new win focused */ - focus_win(win); - return (win); } @@ -3333,20 +3350,6 @@ unmanage_window(struct ws_win *win) DNPRINTF(SWM_D_MISC, "unmanage_window: %lu\n", win->id); ws = win->ws; - - /* find a window to focus */ - if (ws->focus == win) - ws->focus = TAILQ_PREV(win, ws_win_list, entry); - if (ws->focus == NULL) - ws->focus = TAILQ_FIRST(&ws->winlist); - if (ws->focus == NULL || ws->focus == win) { - ws->focus = NULL; - unfocus_win(win); - } else - focus_win(ws->focus); - if (ws->focus_prev == win) - ws->focus_prev = NULL; - TAILQ_REMOVE(&win->ws->winlist, win, entry); set_win_state(win, WithdrawnState); if (win->ch.res_class) @@ -3438,14 +3441,32 @@ configurenotify(XEvent *e) void destroynotify(XEvent *e) { - struct ws_win *win; + struct ws_win *win, *winfocus = NULL; + struct workspace *ws; + struct ws_win_list *wl; + XDestroyWindowEvent *ev = &e->xdestroywindow; DNPRINTF(SWM_D_EVENT, "destroynotify: window %lu\n", ev->window); if ((win = find_window(ev->window)) != NULL) { + /* find a window to focus */ + ws = win->ws; + wl = &ws->winlist; + if (ws->focus == win) { + if (TAILQ_FIRST(wl) == win) + winfocus = TAILQ_NEXT(win, entry); + else { + winfocus = TAILQ_PREV(ws->focus, ws_win_list, entry); + if (winfocus == NULL) + winfocus = TAILQ_LAST(wl, ws_win_list); + } + } + unmanage_window(win); stack(); + if (winfocus) + focus_win(winfocus); } } @@ -3462,6 +3483,12 @@ enternotify(XEvent *e) ignore_enter--; return; } + /* + * happens when a window is created or destroyed and the border + * crosses the mouse pointer + */ + if (QLength(display)) + return; if ((win = find_window(ev->window)) != NULL) focus_win(win); @@ -3494,6 +3521,9 @@ mappingnotify(XEvent *e) void maprequest(XEvent *e) { + struct ws_win *win; + struct swm_region *r; + XMapRequestEvent *ev = &e->xmaprequest; XWindowAttributes wa; @@ -3504,9 +3534,16 @@ maprequest(XEvent *e) return; if (wa.override_redirect) return; + manage_window(e->xmaprequest.window); stack(); + + /* make new win focused */ + win = find_window(ev->window); + r = root_to_region(win->wa.root); + if (win->ws == r->ws) /* XXX this probably breaks multi screen */ + focus_win(win); } void @@ -3883,6 +3920,9 @@ setup_globals(void) if ((bar_fonts[1] = strdup("-*-times-medium-r-*-*-*-*-*-*-*-*-*-*")) == NULL) err(1, "setup_globals: strdup"); + if ((bar_fonts[2] = strdup("-misc-fixed-medium-r-*-*-*-*-*-*-*-*-*-*")) + == NULL) + err(1, "setup_globals: strdup"); if ((spawn_term[0] = strdup("xterm")) == NULL) err(1, "setup_globals: strdup"); } @@ -3985,6 +4025,8 @@ main(int argc, char *argv[]) while (running) { while (XPending(display)) { XNextEvent(display, &e); + if (running == 0) + goto done; if (e.type < LASTEvent) { dumpevent(&e); if (handler[e.type]) @@ -4010,7 +4052,7 @@ main(int argc, char *argv[]) /* if we are being restarted go focus on first window */ if (winfocus) { rr = TAILQ_FIRST(&screens[0].rl); - /* move pointer to first screen */ + /* move pointer to first screen if multi screen */ if (ScreenCount(display) > 1 || outputs > 1) XWarpPointer(display, None, rr->s[0].root, 0, 0, 0, 0, rr->g.x, @@ -4025,13 +4067,15 @@ main(int argc, char *argv[]) FD_SET(xfd, &rd); if (select(xfd + 1, &rd, NULL, NULL, NULL) == -1) if (errno != EINTR) - errx(1, "select failed"); + DNPRINTF(SWM_D_MISC, "select failed"); + if (running == 0) + goto done; if (bar_alarm) { bar_alarm = 0; bar_update(); } } - +done: bar_extra_stop(); XCloseDisplay(display);