X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=93b42444d8c7607ead1ca7a118ff7e9d1696d2d3;hb=519aa00149f17f00cc7067c2b957e3639b8411f5;hp=420f2579f3ba1244bedcd95df7200fbbb213b6bb;hpb=10147c617a24ccc28626d8717f4e92c1f0ecf8ca;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index 420f257..93b4244 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -5,10 +5,10 @@ * Copyright (c) 2009 Pierre-Yves Ritschard * Copyright (c) 2010 Tuukka Kataja * Copyright (c) 2011 Jason L. Wright - * Copyright (c) 2011-2012 Reginald Kennedy + * Copyright (c) 2011-2013 Reginald Kennedy * Copyright (c) 2011-2012 Lawrence Teo * Copyright (c) 2011-2012 Tiago Cunha - * Copyright (c) 2012 David Hill + * Copyright (c) 2012-2013 David Hill * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -1989,12 +1989,12 @@ bar_window_name(char *s, size_t sz, struct swm_region *r) free(title); } -int urgent[SWM_WS_MAX]; void bar_urgent(char *s, size_t sz) { struct ws_win *win; int i, j, num_screens; + int urgent[SWM_WS_MAX]; char b[8]; xcb_get_property_cookie_t c; xcb_icccm_wm_hints_t hints; @@ -2979,6 +2979,8 @@ root_to_region(xcb_window_t root, int check) if (r == NULL && check & SWM_CK_FALLBACK) r = TAILQ_FIRST(&screens[i].rl); + DNPRINTF(SWM_D_MISC, "root_to_region: idx: %d\n", get_region_index(r)); + return (r); } @@ -3412,7 +3414,7 @@ focus_region(struct swm_region *r) if (old_r) unfocus_win(old_r->ws->focus); - xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, r->s->root, + xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, r->id, XCB_CURRENT_TIME); /* Clear bar since empty. */ @@ -3463,8 +3465,9 @@ switchws(struct swm_region *r, union arg *args) this_r->ws = new_ws; new_ws->r = this_r; - /* Set focus_pending before stacking. */ - if (focus_mode != SWM_FOCUS_FOLLOW) + /* Set focus_pending before stacking, if needed. */ + if (focus_mode != SWM_FOCUS_FOLLOW && (!new_ws->focus_pending || + validate_win(new_ws->focus_pending))) new_ws->focus_pending = get_region_focus(new_ws->r); stack(); @@ -3478,17 +3481,16 @@ switchws(struct swm_region *r, union arg *args) if (old_ws->r && focus_mode != SWM_FOCUS_FOLLOW) { if (new_ws->focus_pending) { focus_win(new_ws->focus_pending); - } else { - /* Empty region, focus on root. */ - xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, - new_ws->r->s[new_ws->r->s->idx].root, - XCB_CURRENT_TIME); + new_ws->focus_pending = NULL; } } - /* Clear bar if new ws is empty. */ - if (new_ws->focus_pending == NULL) + /* Clear bar and set focus on region input win if new ws is empty. */ + if (new_ws->focus_pending == NULL && new_ws->focus == NULL) { + xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, r->id, + XCB_CURRENT_TIME); bar_draw(); + } focus_flush(); @@ -4257,20 +4259,24 @@ stack_master(struct workspace *ws, struct swm_geometry *g, int rot, int flip) colno = (winno - mwin) / stacks; if (s <= (winno - mwin) % stacks) colno++; - split = split + colno; - hrh = (r_g.h / colno); + split += colno; + hrh = r_g.h / colno; extra = r_g.h - (colno * hrh); - if (flip) - win_g.x = r_g.x; - else + + if (!flip) win_g.x += win_g.w + 2 * border_width + tile_gap; + win_g.w = (r_g.w - msize - (stacks * (2 * border_width + tile_gap))) / stacks; if (s == 1) win_g.w += (r_g.w - msize - (stacks * (2 * border_width + tile_gap))) % stacks; + + if (flip) + win_g.x -= win_g.w + 2 * border_width + + tile_gap; s--; j = 0; } @@ -4634,11 +4640,10 @@ send_to_ws(struct swm_region *r, union arg *args) unfocus_win(parent); - if (focus_mode != SWM_FOCUS_FOLLOW) + if (focus_mode != SWM_FOCUS_FOLLOW) { pws->focus = pws->focus_pending; - - if (focus_mode != SWM_FOCUS_FOLLOW) pws->focus_pending = NULL; + } } /* Don't unmap parent if new ws is visible */ @@ -4683,8 +4688,14 @@ send_to_ws(struct swm_region *r, union arg *args) stack(); if (focus_mode != SWM_FOCUS_FOLLOW) { - focus_win(ws->focus_pending); - ws->focus_pending = NULL; + if (ws->focus_pending) { + focus_win(ws->focus_pending); + ws->focus_pending = NULL; + } else { + xcb_set_input_focus(conn, + XCB_INPUT_FOCUS_PARENT, r->id, + XCB_CURRENT_TIME); + } } focus_flush(); @@ -8199,6 +8210,9 @@ destroynotify(xcb_destroy_notify_event_t *e) if (win->ws->focus_pending) { focus_win(win->ws->focus_pending); win->ws->focus_pending = NULL; + } else if (win == win->ws->focus && win->ws->r) { + xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, + win->ws->r->id, XCB_CURRENT_TIME); } } @@ -8440,6 +8454,9 @@ motionnotify(xcb_motion_notify_event_t *e) last_event_time = e->time; + if (focus_mode == SWM_FOCUS_MANUAL) + return; + num_screens = get_screen_count(); for (i = 0; i < num_screens; i++) if (screens[i].root == e->root) @@ -8491,6 +8508,7 @@ void propertynotify(xcb_property_notify_event_t *e) { struct ws_win *win; + struct workspace *ws; #ifdef SWM_DEBUG char *name; @@ -8504,28 +8522,39 @@ propertynotify(xcb_property_notify_event_t *e) if (win == NULL) return; + ws = win->ws; + last_event_time = e->time; if (e->atom == a_swm_iconic) { if (e->state == XCB_PROPERTY_NEW_VALUE) { if (focus_mode != SWM_FOCUS_FOLLOW) - win->ws->focus_pending = get_focus_prev(win); + ws->focus_pending = get_focus_prev(win); unfocus_win(win); unmap_window(win); - if (win->ws->r) { + if (ws->r) { stack(); + if (focus_mode != SWM_FOCUS_FOLLOW) { - focus_win(win->ws->focus_pending); - win->ws->focus_pending = NULL; + if (ws->focus_pending) { + focus_win(ws->focus_pending); + ws->focus_pending = NULL; + } else { + xcb_set_input_focus(conn, + XCB_INPUT_FOCUS_PARENT, + ws->r->id, + XCB_CURRENT_TIME); + } } + focus_flush(); } } else if (e->state == XCB_PROPERTY_DELETE) { /* The window is no longer iconic, restack ws. */ if (focus_mode != SWM_FOCUS_FOLLOW) - win->ws->focus_pending = get_focus_magic(win); + ws->focus_pending = get_focus_magic(win); stack(); @@ -8537,9 +8566,9 @@ propertynotify(xcb_property_notify_event_t *e) if (e->state == XCB_PROPERTY_NEW_VALUE) { if (focus_mode != SWM_FOCUS_FOLLOW) { if (win->mapped && - win->ws->focus_pending == win) { - focus_win(win->ws->focus_pending); - win->ws->focus_pending = NULL; + ws->focus_pending == win) { + focus_win(ws->focus_pending); + ws->focus_pending = NULL; } } } @@ -8594,11 +8623,12 @@ unmapnotify(xcb_unmap_notify_event_t *e) if (focus_mode == SWM_FOCUS_FOLLOW) { if (ws->r) focus_win(get_pointer_win(ws->r->s->root)); - } else { - if (ws->focus_pending) { - focus_win(ws->focus_pending); - ws->focus_pending = NULL; - } + } else if (ws->focus_pending) { + focus_win(ws->focus_pending); + ws->focus_pending = NULL; + } else if (ws->focus == NULL && ws->r) { + xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, + ws->r->id, XCB_CURRENT_TIME); } }