From 73b25fe3c712793e283523707b0a1e650da72ed4 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 30 Nov 2011 19:53:59 +0100 Subject: [PATCH] Focus back selected client before reload, add tabbing keybind in rc --- src/client.c | 21 ++++++++++++++------- src/client.h | 18 +++++++++++++----- src/event.c | 7 +++++-- src/ewmh.c | 8 +++++--- src/ewmh.h | 1 + src/wmfs.c | 22 +++++++++++++++++----- src/wmfs.h | 1 + wmfsrc2 | 7 +++++++ 8 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/client.c b/src/client.c index a847460..97ee614 100644 --- a/src/client.c +++ b/src/client.c @@ -61,7 +61,7 @@ CLIENT_ACTION_DIR(focus, Top) CLIENT_ACTION_DIR(focus, Bottom) /* uicb_client_tab_dir() */ -#define client_tab(c) _client_tab(W->client, c) +#define client_tab(c) _client_tab(W->client, c, true) CLIENT_ACTION_DIR(tab, Right) CLIENT_ACTION_DIR(tab, Left) CLIENT_ACTION_DIR(tab, Top) @@ -416,6 +416,7 @@ client_tab_focus(struct client *c) c->tabmaster->geo = c->tabmaster->tgeo = g; } + /* Update tabmaster of tabbed client */ SLIST_FOREACH(cc, &c->tag->clients, tnext) if(cc != c && cc->tabmaster == c->tabmaster) { @@ -431,7 +432,7 @@ client_tab_focus(struct client *c) } void -_client_tab(struct client *c, struct client *cm) +_client_tab(struct client *c, struct client *cm, bool focus) { /* Do not tab already tabed client */ if(c->flags & (CLIENT_TABBED | CLIENT_TABMASTER)) @@ -443,8 +444,8 @@ _client_tab(struct client *c, struct client *cm) c->geo = cm->geo; cm->tabmaster = c; - client_focus(cm); - client_frame_update(cm, CCOL(cm)); + if(focus) + client_focus(cm); } static void @@ -488,8 +489,9 @@ client_untab(struct client *c) c->geo = c->tgeo = og; layout_split_integrate(c, cc); - client_moveresize(c, &c->geo); client_map(c); + client_moveresize(c, &c->geo); + client_update_props(c, CPROP_TAB); } client_frame_update(cc, CCOL(cc)); @@ -512,7 +514,10 @@ client_focus(struct client *c) if(W->client && W->client != c) { client_grabbuttons(W->client, false); - client_frame_update(W->client, &W->client->ncol); + + if(!(W->client->flags & CLIENT_TABMASTER + && c->tabmaster == W->client)) + client_frame_update(W->client, &W->client->ncol); } /* Focus c */ @@ -521,7 +526,7 @@ client_focus(struct client *c) c->tag->sel = c; client_grabbuttons(c, true); client_tab_focus(c); - client_frame_update(c, &c->scol); + client_frame_update(c, CCOL(c)); XSetInputFocus(W->dpy, c->win, RevertToPointerRoot, CurrentTime); } else @@ -529,6 +534,8 @@ client_focus(struct client *c) W->client = W->screen->seltag->sel = NULL; XSetInputFocus(W->dpy, W->root, RevertToPointerRoot, CurrentTime); } + + ewmh_update_wmfs_props(); } /** Get a client name diff --git a/src/client.h b/src/client.h index e33f348..9fa6d82 100644 --- a/src/client.h +++ b/src/client.h @@ -23,7 +23,7 @@ void client_swap(struct client *c, enum position p); #define CCOL(c) (c == c->tag->sel ? &c->scol : &c->ncol) void client_frame_update(struct client *c, struct colpair *cp); void client_tab_pull(struct client *c); -void _client_tab(struct client *c, struct client *cm); +void _client_tab(struct client *c, struct client *cm, bool focus); void client_tab_focus(struct client *c); void client_focus(struct client *c); void client_get_name(struct client *c); @@ -99,15 +99,23 @@ client_tab_next(struct client *c) static inline void client_map(struct client *c) { - WIN_STATE(c->frame, Map); - ewmh_set_wm_state(c->win, NormalState); + if(!(c->flags & CLIENT_MAPPED)) + { + WIN_STATE(c->frame, Map); + ewmh_set_wm_state(c->win, NormalState); + c->flags ^= CLIENT_MAPPED; + } } static inline void client_unmap(struct client *c) { - WIN_STATE(c->frame, Unmap); - ewmh_set_wm_state(c->win, IconicState); + if(c->flags & CLIENT_MAPPED) + { + WIN_STATE(c->frame, Unmap); + ewmh_set_wm_state(c->win, IconicState); + c->flags ^= CLIENT_MAPPED; + } } #endif /* CLIENT_H */ diff --git a/src/event.c b/src/event.c index be0af7b..cd2f035 100644 --- a/src/event.c +++ b/src/event.c @@ -52,7 +52,10 @@ event_enternotify(XEvent *e) if(c->flags & CLIENT_IGNORE_ENTER) c->flags ^= CLIENT_IGNORE_ENTER; else if(c != W->client) + { client_focus(c); + puts("ENTER"); + } } } @@ -112,10 +115,10 @@ event_destroynotify(XEvent *e) static void event_focusin(XEvent *e) { - if(W->client + /*if(W->client && e->xfocus.window != W->client->win && e->xfocus.window != W->client->frame) - client_focus(W->client); + client_focus(W->client);*/ } static void diff --git a/src/ewmh.c b/src/ewmh.c index c67f366..65238bb 100644 --- a/src/ewmh.c +++ b/src/ewmh.c @@ -52,6 +52,7 @@ ewmh_init(void) /* WMFS hints */ W->net_atom[wmfs_running] = ATOM("_WMFS_RUNNING"); + W->net_atom[wmfs_focus] = ATOM("_WMFS_FOCUS"); W->net_atom[wmfs_update_hints] = ATOM("_WMFS_UPDATE_HINTS"); W->net_atom[wmfs_set_screen] = ATOM("_WMFS_SET_SCREEN"); W->net_atom[wmfs_screen_count] = ATOM("_WMFS_SCREEN_COUNT"); @@ -59,11 +60,8 @@ ewmh_init(void) W->net_atom[wmfs_tag_list] = ATOM("_WMFS_TAG_LIST"); W->net_atom[wmfs_current_screen] = ATOM("_WMFS_CURRENT_SCREEN"); W->net_atom[wmfs_current_layout] = ATOM("_WMFS_CURRENT_LAYOUT"); - W->net_atom[wmfs_mwfact] = ATOM("_WMFS_MWFACT"); - W->net_atom[wmfs_nmaster] = ATOM("_WMFS_NMASTER"); W->net_atom[wmfs_function] = ATOM("_WMFS_FUNCTION"); W->net_atom[wmfs_cmd] = ATOM("_WMFS_CMD"); - W->net_atom[wmfs_font] = ATOM("_WMFS_FONT"); XChangeProperty(W->dpy, W->root, W->net_atom[net_supported], XA_ATOM, 32, PropModeReplace, (unsigned char*)W->net_atom, net_last); @@ -121,6 +119,10 @@ ewmh_update_wmfs_props(void) XChangeProperty(W->dpy, W->root, W->net_atom[wmfs_current_tag], XA_CARDINAL, 32, PropModeReplace, (unsigned char*)cts, n); + if(W->client) + XChangeProperty(W->dpy, W->root, W->net_atom[wmfs_focus], XA_WINDOW, 32, + PropModeReplace, (unsigned char*)&W->client->win, 1); + free(cts); } diff --git a/src/ewmh.h b/src/ewmh.h index 515e69c..b99409a 100644 --- a/src/ewmh.h +++ b/src/ewmh.h @@ -55,6 +55,7 @@ enum utf8_string, /* WMFS HINTS */ wmfs_running, + wmfs_focus, wmfs_update_hints, wmfs_current_tag, wmfs_current_screen, diff --git a/src/wmfs.c b/src/wmfs.c index 5dd88fa..0e87271 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -184,13 +184,13 @@ static void wmfs_scan(void) { struct geo g; - struct client *c, *cc; + struct client *c, *cc, *fc; int i, n, rf; int tag = -1, screen = -1, flags = -1; unsigned long ir, il; long *ret; XWindowAttributes wa; - Window usl, usl2, *w = NULL, tm; + Window usl, usl2, *w = NULL, tm, focus; Atom rt; SLIST_INIT(&W->h.client); @@ -212,6 +212,17 @@ wmfs_scan(void) XFree(ret); } + /* Previous focused client before reload */ + if(XGetWindowProperty(W->dpy, W->root, W->net_atom[wmfs_focus], 0, 32, + False, XA_WINDOW, &rt, &rf, &ir, &il, + (unsigned char**)&ret) + == Success && ret) + { + focus = *ret; + XFree(ret); + } + + if(XQueryTree(W->dpy, W->root, &usl, &usl2, &w, (unsigned int*)&n)) for(i = n - 1; i != -1; --i) { @@ -293,9 +304,10 @@ wmfs_scan(void) /* Re-adjust tabbed clients */ SLIST_FOREACH(c, &W->h.client, next) if((cc = client_gb_win(c->tmp)) && cc != c) - { - _client_tab(c, cc); - } + _client_tab(c, cc, false); + + if((fc = client_gb_win(focus))) + client_focus(fc); XFree(w); } diff --git a/src/wmfs.h b/src/wmfs.h index a74a218..f36ce6f 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -165,6 +165,7 @@ struct client #define CLIENT_TABMASTER 0x80 #define CLIENT_DYING 0x100 /* Saddest flag ever */ #define CLIENT_REMOVEALL 0x200 +#define CLIENT_MAPPED 0x400 Flags flags; Window win, frame, tmp; SLIST_ENTRY(client) next; /* Global list */ diff --git a/wmfsrc2 b/wmfsrc2 index 90b4b08..c0eef79 100644 --- a/wmfsrc2 +++ b/wmfsrc2 @@ -157,6 +157,13 @@ [key] mod = {"Super", "Control"} key = "k" func = "client_resize_bottom" cmd = "-20" [/key] [key] mod = {"Super", "Control"} key = "j" func = "client_resize_bottom" cmd = "20" [/key] + # Tabbing command + [key] mod = {"Alt", "Shift"} key = "h" func = "client_tab_left" [/key] + [key] mod = {"Alt", "Shift"} key = "l" func = "client_tab_right" [/key] + [key] mod = {"Alt", "Shift"} key = "k" func = "client_tab_top" [/key] + [key] mod = {"Alt", "Shift"} key = "j" func = "client_tab_bottom" [/key] + [key] mod = {"Alt", "Shift"} key = "u" func = "client_untab" [/key] + # Layout manipulation [key] mod = {"Super"} key = "m" func = "layout_vmirror" [/key] [key] mod = {"Super", "Shift"} key = "m" func = "layout_hmirror" [/key]