From cfb64b94f34ce94b65e6d62cb9aec970ffa5a49b Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sun, 18 Sep 2011 14:11:53 +0200 Subject: [PATCH] Fix grab keys after keybind conf --- wmfs2/src/client.c | 104 ++++++++++++++++++++------------------------ wmfs2/src/client.h | 1 + wmfs2/src/config.c | 4 +- wmfs2/src/config.h | 1 + wmfs2/src/infobar.c | 2 +- wmfs2/src/tag.c | 3 +- wmfs2/src/wmfs.c | 12 ++--- wmfs2/wmfsrc2 | 8 ++-- 8 files changed, 65 insertions(+), 70 deletions(-) diff --git a/wmfs2/src/client.c b/wmfs2/src/client.c index 7d0fc57..0561927 100644 --- a/wmfs2/src/client.c +++ b/wmfs2/src/client.c @@ -33,18 +33,19 @@ CLIENT_RESIZE_DIR(Bottom) void client_configure(struct client *c) { - XConfigureEvent ev; - - ev.type = ConfigureNotify; - ev.event = c->win; - ev.window = c->win; - ev.x = c->geo.x; - ev.y = c->geo.y; - ev.width = c->geo.w; - ev.height = c->geo.h; - ev.above = None; - ev.border_width = 0; - ev.override_redirect = 0; + XConfigureEvent ev = + { + .type = ConfigureNotify, + .event = c->win, + .window = c->win, + .x = c->geo.x, + .y = c->geo.y, + .width = c->geo.w, + .height = c->geo.h, + .above = None, + .border_width = 0, + .override_redirect = 0 + }; XSendEvent(W->dpy, c->win, False, StructureNotifyMask, (XEvent *)&ev); XSync(W->dpy, False); @@ -109,24 +110,6 @@ client_next_with_pos(struct client *bc, Position p) return c; } -/** Map a client - * \param c struct client pointer - */ -void -client_map(struct client *c) -{ - XMapWindow(W->dpy, c->win); -} - -/** Unmap a client - * \param c struct client pointer - */ -void -client_unmap(struct client *c) -{ - XUnmapWindow(W->dpy, c->win); -} - static void client_grabbuttons(struct client *c, bool focused) { @@ -176,9 +159,9 @@ client_focus(struct client *c) XSetWindowBorder(W->dpy, c->win, THEME_DEFAULT->client_s.bg); - client_grabbuttons(c, true); - XSetInputFocus(W->dpy, c->win, RevertToPointerRoot, CurrentTime); + + client_grabbuttons(c, true); } } @@ -209,9 +192,9 @@ client_get_name(struct client *c) void client_close(struct client *c) { - XEvent ev; - Atom *atom = NULL; + bool canbedel; int proto; + Atom *atom = NULL; /* Event will call client_remove */ if(XGetWMProtocols(W->dpy, c->win, &atom, &proto) && atom) @@ -219,29 +202,39 @@ client_close(struct client *c) while(proto--) if(atom[proto] == ATOM("WM_DELETE_WINDOW")) { - ev.type = ClientMessage; - ev.xclient.window = c->win; - ev.xclient.message_type = ATOM("WM_PROTOCOLS"); - ev.xclient.format = 32; - ev.xclient.data.l[0] = ATOM("WM_DELETE_WINDOW"); - ev.xclient.data.l[1] = CurrentTime; - ev.xclient.data.l[2] = 0; - ev.xclient.data.l[3] = 0; - ev.xclient.data.l[4] = 0; - - XSendEvent(W->dpy, c->win, False, NoEventMask, &ev); - + canbedel = true; XFree(atom); - - return; + break; } - XKillClient(W->dpy, c->win); + if(canbedel) + { + XEvent ev = + { + .type = ClientMessage, + .xclient.window = c->win, + .xclient.message_type = ATOM("WM_PROTOCOLS"), + .xclient.format = 32, + .xclient.data.l[0] = ATOM("WM_DELETE_WINDOW"), + .xclient.data.l[1] = CurrentTime + }; + + XSendEvent(W->dpy, c->win, False, NoEventMask, &ev); + } + else + XKillClient(W->dpy, c->win); } else XKillClient(W->dpy, c->win); } +void +uicb_client_close(Uicb cmd) +{ + if(W->client) + client_close(W->client); +} + struct client* client_new(Window w, XWindowAttributes *wa) { @@ -264,8 +257,7 @@ client_new(Window w, XWindowAttributes *wa) tag_client(W->screen->seltag, c); /* X window attributes */ - XSelectInput(W->dpy, w, EnterWindowMask | FocusChangeMask - | PropertyChangeMask | StructureNotifyMask); + XSelectInput(W->dpy, w, EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PropertyChangeMask); XSetWindowBorder(W->dpy, w, THEME_DEFAULT->client_n.bg); XSetWindowBorderWidth(W->dpy, w, THEME_DEFAULT->client_border_width); client_grabbuttons(c, false); @@ -274,8 +266,8 @@ client_new(Window w, XWindowAttributes *wa) SLIST_INSERT_HEAD(&W->h.client, c, next); /* Map */ - WIN_STATE(c->win, Map); - ewmh_set_wm_state(c->win, NormalState); + WIN_STATE(w, Map); + ewmh_set_wm_state(w, NormalState); client_configure(c); @@ -312,9 +304,9 @@ client_fac_resize(struct client *c, Position p, int fac) /* Check futur size/pos */ if(!client_fac_geo(c, p, fac) - || !client_fac_geo(gc, RPOS(p), -fac) - || !client_fac_check_row(c, p, fac) - || !client_fac_check_row(gc, RPOS(p), -fac)) + || !client_fac_geo(gc, RPOS(p), -fac) + || !client_fac_check_row(c, p, fac) + || !client_fac_check_row(gc, RPOS(p), -fac)) return; diff --git a/wmfs2/src/client.h b/wmfs2/src/client.h index 0e4ab5b..e75b688 100644 --- a/wmfs2/src/client.h +++ b/wmfs2/src/client.h @@ -15,6 +15,7 @@ struct client *client_next_with_pos(struct client *bc, Position p); void client_focus(struct client *c); void client_get_name(struct client *c); void client_close(struct client *c); +void uicb_client_close(Uicb cmd); struct client *client_new(Window w, XWindowAttributes *wa); void client_moveresize(struct client *c, struct geo g); void client_maximize(struct client *c); diff --git a/wmfs2/src/config.c b/wmfs2/src/config.c index 18334ea..1df8d89 100644 --- a/wmfs2/src/config.c +++ b/wmfs2/src/config.c @@ -16,7 +16,7 @@ static void config_theme(void) { - struct theme *t, *p; + struct theme *t, *p = NULL; size_t i, n; struct conf_sec *sec, **ks; @@ -191,6 +191,8 @@ config_keybind(void) SLIST_INSERT_HEAD(&W->h.keybind, k, next); } + wmfs_grab_keys(); + free(ks); } diff --git a/wmfs2/src/config.h b/wmfs2/src/config.h index 019daa0..1e2140e 100644 --- a/wmfs2/src/config.h +++ b/wmfs2/src/config.h @@ -31,6 +31,7 @@ static const struct { char *name; void (*func)(Uicb cmd); } uicb_list[] = { "tag_prev", uicb_tag_prev }, /* Client */ + { "client_close", uicb_client_close }, { "client_resize_right", uicb_client_resize_Right }, { "client_resize_left", uicb_client_resize_Left }, { "client_resize_top", uicb_client_resize_Top }, diff --git a/wmfs2/src/infobar.c b/wmfs2/src/infobar.c index b043263..1510b03 100644 --- a/wmfs2/src/infobar.c +++ b/wmfs2/src/infobar.c @@ -33,7 +33,7 @@ static void infobar_elem_tag_init(struct element *e) { struct tag *t; - struct barwin *b, *prev; + struct barwin *b, *prev = NULL; struct geo g = { 0, 0, 0, 0 }; int s, j; diff --git a/wmfs2/src/tag.c b/wmfs2/src/tag.c index 8cd33b6..53f940b 100644 --- a/wmfs2/src/tag.c +++ b/wmfs2/src/tag.c @@ -92,6 +92,7 @@ tag_client(struct tag *t, struct client *c) layout_split_arrange_closed(c); SLIST_REMOVE(&c->tag->clients, c, client, tnext); + /* TODO: Focus next client */ if(c->tag->sel == c) c->tag->sel = NULL; @@ -99,7 +100,6 @@ tag_client(struct tag *t, struct client *c) /* * Case of client removing: umap frame if empty - * TODO: arrange layout */ if(!t) { @@ -107,7 +107,6 @@ tag_client(struct tag *t, struct client *c) if(SLIST_EMPTY(&c->tag->clients)) WIN_STATE(c->tag->frame, Unmap); - return; } diff --git a/wmfs2/src/wmfs.c b/wmfs2/src/wmfs.c index 7b1596a..7168aaa 100644 --- a/wmfs2/src/wmfs.c +++ b/wmfs2/src/wmfs.c @@ -121,6 +121,11 @@ wmfs_xinit(void) W->xdepth = DefaultDepth(W->dpy, W->xscreen); W->gc = DefaultGC(W->dpy, W->xscreen); + /* + * Keys + */ + wmfs_numlockmask(); + /* * Root window/cursor */ @@ -132,11 +137,6 @@ wmfs_xinit(void) */ setlocale(LC_CTYPE, ""); - /* - * Keys - */ - wmfs_numlockmask(); - /* * Barwin linked list */ @@ -151,7 +151,7 @@ wmfs_grab_keys(void) KeyCode c; struct keybind *k; - /*wmfs_numlockmask();*/ + wmfs_numlockmask(); XUngrabKey(W->dpy, AnyKey, AnyModifier, W->root); diff --git a/wmfs2/wmfsrc2 b/wmfs2/wmfsrc2 index f2780c4..799d52b 100644 --- a/wmfs2/wmfsrc2 +++ b/wmfs2/wmfsrc2 @@ -115,13 +115,13 @@ # Resize selected tiled client with direction [key] mod = {"Super"} key = "h" func = "client_resize_left" cmd = "20" [/key] - [key] mod = {"Super"} key = "l" func = "client_resize_right" cmd = "20" [/key] + [key] mod = {"Super"} key = "l" func = "client_resize_left" cmd = "-20" [/key] [key] mod = {"Super"} key = "k" func = "client_resize_top" cmd = "20" [/key] - [key] mod = {"Super"} key = "j" func = "client_resize_bottom" cmd = "20" [/key] + [key] mod = {"Super"} key = "j" func = "client_resize_top" cmd = "-20" [/key] [key] mod = {"Super", "Control"} key = "h" func = "client_resize_right" cmd = "-20" [/key] - [key] mod = {"Super", "Control"} key = "l" func = "client_resize_left" cmd = "-20" [/key] + [key] mod = {"Super", "Control"} key = "l" func = "client_resize_right" cmd = "20" [/key] [key] mod = {"Super", "Control"} key = "k" func = "client_resize_bottom" cmd = "-20" [/key] - [key] mod = {"Super", "Control"} key = "j" func = "client_resize_top" cmd = "-20" [/key] + [key] mod = {"Super", "Control"} key = "j" func = "client_resize_bottom" cmd = "20" [/key] [/keys]