X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=scrotwm.c;h=4ef1088eb5a8ce530bbf48d65079c64f6fb94360;hb=769cba6f7f9837b2f47b89aec44757fab8b9aeae;hp=22d92b026f3acdd6736a6675643841677f1cfed0;hpb=ff3314e7ef2a8e298ba33777318f8469f688a118;p=spectrwm.git diff --git a/scrotwm.c b/scrotwm.c index 22d92b0..4ef1088 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -52,7 +52,7 @@ static const char *cvstag = "$scrotwm$"; -#define SWM_VERSION "0.9.13" +#define SWM_VERSION "0.9.15" #include #include @@ -94,6 +94,7 @@ static const char *cvstag = "$scrotwm$"; #endif #endif +#define SWM_DEBUG /* #define SWM_DEBUG */ #ifdef SWM_DEBUG #define DPRINTF(x...) do { if (swm_debug) fprintf(stderr, x); } while (0) @@ -337,7 +338,7 @@ struct layout { { horizontal_stack, horizontal_config, 0, "[-]" }, { max_stack, NULL, SWM_L_FOCUSPREV | SWM_L_MAPONFOCUS, "[ ]"}, - { NULL, NULL, 0}, + { NULL, NULL, 0, NULL }, }; #define SWM_H_SLICE (32) @@ -369,9 +370,9 @@ enum { SWM_S_COLOR_BAR, SWM_S_COLOR_BAR_BORDER, SWM_S_COLOR_BAR_FONT, SWM_S_COLOR_FOCUS, SWM_S_COLOR_UNFOCUS, SWM_S_COLOR_MAX }; /* physical screen mapping */ -#define SWM_WS_MAX (10) /* XXX Too small? */ +#define SWM_WS_MAX (10) struct swm_screen { - int idx; /* screen index */ + int idx; /* screen index */ struct swm_region_list rl; /* list of regions on this screen */ struct swm_region_list orl; /* list of old regions */ Window root; @@ -1350,14 +1351,8 @@ switchws(struct swm_region *r, union arg *args) struct ws_win *win, *winfocus = NULL, *parent = NULL; struct workspace *new_ws, *old_ws; - if (!(r && r->s)) { - fprintf(stderr, "r && r->s failed\n"); - abort(); - } - if (wsid < 0 || wsid > SWM_WS_MAX) { - fprintf(stderr, "illegal wsid\n"); - abort(); - } + if (!(r && r->s)) + return; this_r = r; old_ws = this_r->ws; @@ -1367,11 +1362,8 @@ 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); - if (new_ws == NULL || old_ws == NULL) { - fprintf(stderr, "new_ws = %p old_ws = %p\n", new_ws, old_ws); - abort(); - } - + if (new_ws == NULL || old_ws == NULL) + return; if (new_ws == old_ws) return; @@ -1672,10 +1664,6 @@ stack(void) { "(screen %d, region %d)\n", r->ws->idx, i, j++); /* start with screen geometry, adjust for bar */ - if (r == NULL) { - fprintf(stderr, "illegal r\n"); - abort(); - } g = r->g; g.w -= 2; g.h -= 2; @@ -1683,18 +1671,6 @@ stack(void) { g.y += bar_height; g.h -= bar_height; } - if (r->ws == NULL) { - fprintf(stderr, "illegal ws\n"); - abort(); - } - if (r->ws->cur_layout == NULL) { - fprintf(stderr, "illegal cur_layout\n"); - abort(); - } - if (r->ws->cur_layout->l_stack == NULL) { - fprintf(stderr, "illegal l_stack\n"); - abort(); - } r->ws->cur_layout->l_stack(r->ws, &g); } } @@ -1713,8 +1689,8 @@ stack_floater(struct ws_win *win, struct swm_region *r) bzero(&wc, sizeof wc); mask = CWX | CWY | CWBorderWidth | CWWidth | CWHeight; - if ((win->quirks & SWM_Q_FULLSCREEN) && (win->g.w == WIDTH(r)) && - (win->g.h == HEIGHT(r))) + if ((win->quirks & SWM_Q_FULLSCREEN) && (win->g.w >= WIDTH(r)) && + (win->g.h >= HEIGHT(r))) wc.border_width = 0; else wc.border_width = 1; @@ -1733,13 +1709,21 @@ stack_floater(struct ws_win *win, struct swm_region *r) } /* adjust for region */ - wc.x += r->g.x; - wc.y += r->g.y; + if (wc.x < r->g.x) + wc.x += r->g.x; + if (wc.y < r->g.y) + wc.y += r->g.y; + + win->g.x = wc.x; + win->g.y = wc.y; + win->g.w = wc.width; + win->g.h = wc.height; - DNPRINTF(SWM_D_STACK, "stack_floater: win %lu x %d y %d w %d h %d\n", + DNPRINTF(SWM_D_MISC, "stack_floater: win %lu x %d y %d w %d h %d\n", win->id, wc.x, wc.y, wc.width, wc.height); XConfigureWindow(display, win->id, mask, &wc); + configreq_win(win); } /* @@ -2206,7 +2190,7 @@ resize_window(struct ws_win *win, int center) win->id, wc.x, wc.y, wc.width, wc.height); XConfigureWindow(display, win->id, mask, &wc); - config_win(win); + configreq_win(win); } void @@ -2214,6 +2198,7 @@ resize(struct ws_win *win, union arg *args) { XEvent ev; Time time = 0; + struct swm_region *r = win->ws->r; DNPRINTF(SWM_D_MOUSE, "resize: win %lu floating %d trans %d\n", win->id, win->floating, win->transient); @@ -2235,6 +2220,14 @@ resize(struct ws_win *win, union arg *args) handler[ev.type](&ev); break; case MotionNotify: + /* do not allow resize outside of region */ + if (ev.xmotion.y_root < r->g.y || + ev.xmotion.y_root >= r->g.y + r->g.h - 1) + continue; + if (ev.xmotion.x_root < r->g.x || + ev.xmotion.x_root >= r->g.x + r->g.w - 1) + continue; + if (ev.xmotion.x <= 1) ev.xmotion.x = 1; if (ev.xmotion.y <= 1) @@ -2280,7 +2273,7 @@ move_window(struct ws_win *win) win->id, wc.x, wc.y, wc.width, wc.height); XConfigureWindow(display, win->id, mask, &wc); - config_win(win); + configreq_win(win); } void @@ -2289,6 +2282,7 @@ move(struct ws_win *win, union arg *args) XEvent ev; Time time = 0; int restack = 0; + struct swm_region *r = win->ws->r; DNPRINTF(SWM_D_MOUSE, "move: win %lu floating %d trans %d\n", win->id, win->floating, win->transient); @@ -2313,6 +2307,14 @@ move(struct ws_win *win, union arg *args) handler[ev.type](&ev); break; case MotionNotify: + /* don't allow to move window out of region */ + if (ev.xmotion.y_root < r->g.y || + ev.xmotion.y_root + win->g.h >= r->g.y + r->g.h - 1) + continue; + if (ev.xmotion.x_root < r->g.x || + ev.xmotion.x_root + win->g.w >= r->g.x + r->g.w - 1) + continue; + win->g.x = ev.xmotion.x_root; win->g.y = ev.xmotion.y_root; @@ -3513,8 +3515,10 @@ manage_window(Window id) !strcmp(win->ch.res_name, quirks[i].name)) { DNPRINTF(SWM_D_CLASS, "found: %s name: %s\n", win->ch.res_class, win->ch.res_name); - if (quirks[i].quirk & SWM_Q_FLOAT) + if (quirks[i].quirk & SWM_Q_FLOAT) { win->floating = 1; + border_me = 1; + } win->quirks = quirks[i].quirk; } } @@ -3703,7 +3707,8 @@ configurerequest(XEvent *e) XWindowChanges wc; if ((win = find_window(ev->window)) == NULL) - new = 1; + if ((win = find_unmanaged_window(ev->window)) == NULL) + new = 1; if (new) { DNPRINTF(SWM_D_EVENT, "configurerequest: new window: %lu\n", @@ -3729,27 +3734,8 @@ configurerequest(XEvent *e) win->g.w = ev->width; if (ev->value_mask & CWHeight) win->g.h = ev->height; - if (win->ws->r != NULL) { - /* this seems to be full screen */ - if (win->g.w >= WIDTH(win->ws->r)) { - win->g.x = 0; - win->g.w = WIDTH(win->ws->r); - ev->value_mask |= CWX | CWWidth; - } - if (win->g.h >= HEIGHT(win->ws->r)) { - /* kill border */ - win->g.y = 0; - win->g.h = HEIGHT(win->ws->r); - ev->value_mask |= CWY | CWHeight; - } - } - XMoveResizeWindow(display, win->id, - win->g.x, win->g.y, win->g.w, win->g.h); - if ((ev->value_mask & (CWX | CWY)) && - !(ev->value_mask & (CWWidth | CWHeight))) - config_win(win); - } else - config_win(win); + } + config_win(win); } } @@ -3778,21 +3764,22 @@ destroynotify(XEvent *e) struct workspace *ws; struct ws_win_list *wl; XDestroyWindowEvent *ev = &e->xdestroywindow; - int unmanaged = 0; DNPRINTF(SWM_D_EVENT, "destroynotify: window %lu\n", ev->window); if ((win = find_window(ev->window)) == NULL) { if ((win = find_unmanaged_window(ev->window)) == NULL) return; - unmanaged = 1; + free_window(win); + return; } /* find a window to focus */ ws = win->ws; wl = &ws->winlist; - for (w = TAILQ_FIRST(&ws->winlist); w != TAILQ_END(&ws->winlist); w = wn) { + for (w = TAILQ_FIRST(&ws->winlist); w != TAILQ_END(&ws->winlist); + w = wn) { wn = TAILQ_NEXT(w, entry); if (win == w) continue; /* can't happen but oh well */ @@ -3826,8 +3813,7 @@ destroynotify(XEvent *e) } } } - if (unmanaged == 0) - unmanage_window(win); + unmanage_window(win); free_window(win); ignore_enter = 1; @@ -4373,6 +4359,7 @@ main(int argc, char *argv[]) int xfd, i; fd_set rd; +swm_debug = 0; start_argv = argv; fprintf(stderr, "Welcome to scrotwm V%s cvs tag: %s\n", SWM_VERSION, cvstag);