X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=f78f74043efa9be72f3e0ca7760f557910f87c6d;hb=f1975d23f7f929e6318d1f0e242f778ac0e6b2e1;hp=61874aff305e151a6ea886d9cc83b0ad8d388760;hpb=7caf33e7559fb3a53ae4c18623cacb9db48515c1;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index 61874af..f78f740 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -244,6 +244,7 @@ u_int32_t swm_debug = 0 #define SH_INC_H(w) (w)->sh.height_inc #define SWM_MAX_FONT_STEPS (3) #define WINID(w) ((w) ? (w)->id : XCB_WINDOW_NONE) +#define WS_FOCUSED(ws) ((ws)->r && (ws)->r->s->r_focus == (ws)->r) #define YESNO(x) ((x) ? "yes" : "no") /* Constrain Window flags */ @@ -279,10 +280,7 @@ xcb_atom_t a_state; xcb_atom_t a_prot; xcb_atom_t a_delete; xcb_atom_t a_takefocus; -xcb_atom_t a_wmname; -xcb_atom_t a_netwmname; xcb_atom_t a_utf8_string; -xcb_atom_t a_string; xcb_atom_t a_swm_iconic; xcb_atom_t a_swm_ws; volatile sig_atomic_t running = 1; @@ -4860,7 +4858,7 @@ get_win_name(xcb_window_t win) xcb_get_property_reply_t *r; /* First try _NET_WM_NAME for UTF-8. */ - c = xcb_get_property(conn, 0, win, a_netwmname, + c = xcb_get_property(conn, 0, win, ewmh[_NET_WM_NAME].atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX); r = xcb_get_property_reply(conn, c, NULL); @@ -5309,16 +5307,12 @@ wkill(struct swm_region *r, union arg *args) int floating_toggle_win(struct ws_win *win) { - struct swm_region *r; - if (win == NULL) return (0); if (!win->ws->r) return (0); - r = win->ws->r; - /* reject floating toggles in max stack mode */ if (win->ws->cur_layout == &layouts[SWM_MAX_STACK]) return (0); @@ -5708,14 +5702,12 @@ move(struct ws_win *win, union arg *args) { xcb_timestamp_t timestamp = 0; int move_stp = 0, moving; - struct swm_region *r = NULL; xcb_query_pointer_reply_t *qpr = NULL; xcb_generic_event_t *evt; xcb_motion_notify_event_t *mne; if (win == NULL) return; - r = win->ws->r; if (win->ewmh_flags & EWMH_F_FULLSCREEN) return; @@ -8415,11 +8407,11 @@ destroynotify(xcb_destroy_notify_event_t *e) unmanage_window(win); stack(); - if (focus_mode != SWM_FOCUS_FOLLOW) { + if (focus_mode != SWM_FOCUS_FOLLOW && WS_FOCUSED(win->ws)) { 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) { + } else if (win == win->ws->focus) { xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, win->ws->r->id, XCB_CURRENT_TIME); } @@ -8568,7 +8560,7 @@ mapnotify(xcb_map_notify_event_t *e) win->mapped = 1; set_win_state(win, XCB_ICCCM_WM_STATE_NORMAL); - if (focus_mode != SWM_FOCUS_FOLLOW) { + if (focus_mode != SWM_FOCUS_FOLLOW && WS_FOCUSED(win->ws)) { if (win->ws->focus_pending == win) { focus_win(win); win->ws->focus_pending = NULL; @@ -8750,7 +8742,8 @@ propertynotify(xcb_property_notify_event_t *e) if (ws->r) { stack(); - if (focus_mode != SWM_FOCUS_FOLLOW) { + if (focus_mode != SWM_FOCUS_FOLLOW && + WS_FOCUSED(ws)) { if (ws->focus_pending) { focus_win(ws->focus_pending); ws->focus_pending = NULL; @@ -8777,7 +8770,7 @@ propertynotify(xcb_property_notify_event_t *e) } else if (e->atom == a_state) { /* State just changed, make sure it gets focused if mapped. */ if (e->state == XCB_PROPERTY_NEW_VALUE) { - if (focus_mode != SWM_FOCUS_FOLLOW) { + if (focus_mode != SWM_FOCUS_FOLLOW && WS_FOCUSED(ws)) { if (win->mapped && ws->focus_pending == win) { focus_win(ws->focus_pending); @@ -8833,15 +8826,16 @@ unmapnotify(xcb_unmap_notify_event_t *e) if (ws->r) stack(); - if (focus_mode == SWM_FOCUS_FOLLOW) { - if (ws->r) + if (WS_FOCUSED(ws)) { + if (focus_mode == SWM_FOCUS_FOLLOW) { 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 == NULL && ws->r) { - xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, - ws->r->id, XCB_CURRENT_TIME); + } else if (ws->focus_pending) { + focus_win(ws->focus_pending); + ws->focus_pending = NULL; + } else if (ws->focus == NULL) { + xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, + ws->r->id, XCB_CURRENT_TIME); + } } } @@ -8888,7 +8882,10 @@ clientmessage(xcb_client_message_event_t *e) if (e->type == ewmh[_NET_ACTIVE_WINDOW].atom) { DNPRINTF(SWM_D_EVENT, "clientmessage: _NET_ACTIVE_WINDOW\n"); - focus_win(win); + if (WS_FOCUSED(win->ws)) + focus_win(win); + else + win->ws->focus_pending = win; } if (e->type == ewmh[_NET_CLOSE_WINDOW].atom) { DNPRINTF(SWM_D_EVENT, "clientmessage: _NET_CLOSE_WINDOW\n"); @@ -9438,10 +9435,7 @@ setup_globals(void) a_prot = get_atom_from_string("WM_PROTOCOLS"); a_delete = get_atom_from_string("WM_DELETE_WINDOW"); a_takefocus = get_atom_from_string("WM_TAKE_FOCUS"); - a_wmname = get_atom_from_string("WM_NAME"); - a_netwmname = get_atom_from_string("_NET_WM_NAME"); a_utf8_string = get_atom_from_string("UTF8_STRING"); - a_string = get_atom_from_string("STRING"); a_swm_iconic = get_atom_from_string("_SWM_ICONIC"); a_swm_ws = get_atom_from_string("_SWM_WS"); } @@ -9470,7 +9464,8 @@ workaround(void) xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win, netwmcheck, XCB_ATOM_WINDOW, 32, 1, &win); xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win, - a_netwmname, a_utf8_string, 8, strlen("LG3D"), "LG3D"); + ewmh[_NET_WM_NAME].atom, a_utf8_string, 8, strlen("LG3D"), + "LG3D"); } }