[hackers] [wmii] Fixed a bunch of focus stupidity.

From: Kris Maglione <jg_AT_suckless.org>
Date: Sat Feb 17 18:50:07 2007

changeset: 1894:7caa3e7323f7
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Feb 17 12:49:22 2007 -0500
summary: Fixed a bunch of focus stupidity.

diff -r 5a578dc52ed4 -r 7caa3e7323f7 client.c
--- a/client.c Sat Feb 17 02:20:11 2007 -0500
+++ b/client.c Sat Feb 17 12:49:22 2007 -0500
@@ -12,7 +12,7 @@ static char Ebadcmd[] = "bad command",
 static char Ebadcmd[] = "bad command",
             Ebadvalue[] = "bad value";
 
-#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
+#define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask | FocusChangeMask)
 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
 
 Client *
@@ -91,7 +91,8 @@ manage_client(Client *c) {
                 strncpy(c->tags, (char *)tags.value, sizeof(c->tags));
         XFree(tags.value);
 
- reparent_client(c, c->framewin, c->rect.x, c->rect.y);
+ gravitate_client(c, False);
+ reparent_client(c, c->framewin, def.border, labelh(&def.font));
 
         if(!strlen(c->tags))
                 apply_rules(c);
@@ -174,13 +175,18 @@ update_client_grab(Client *c) {
 update_client_grab(Client *c) {
         Frame *f;
         f = c->sel;
- if(!f->area->floating || f == f->area->stack) {
+ if((f->client != sel_client())
+ || (f->area->floating && f != f->area->stack)) {
+ if(verbose)
+ fprintf(stderr, "update_client_grab(%p) AnyButton => %s\n", c, str_nil(c->name));
+ grab_button(c->framewin, AnyButton, AnyModifier);
+ }else {
+ if(verbose)
+ fprintf(stderr, "update_client_grab(%p) def.mod => %s\n", c, str_nil(c->name));
                 XUngrabButton(blz.dpy, AnyButton, AnyModifier, c->framewin);
                 grab_button(c->framewin, Button1, def.mod);
                 grab_button(c->framewin, Button3, def.mod);
         }
- else
- grab_button(c->framewin, AnyButton, AnyModifier);
 }
 
 /* convenience function */
@@ -458,10 +464,6 @@ destroy_client(Client *c) {
 
         XGrabServer(blz.dpy);
         XSetErrorHandler(dummy_error_handler);
- if(c->frame) {
- c->rect.x = c->sel->rect.x;
- c->rect.y = c->sel->rect.y;
- }
         for(tc=&client; *tc; tc=&(*tc)->next)
                 if(*tc == c) {
                         *tc = c->next;
@@ -471,6 +473,7 @@ destroy_client(Client *c) {
         update_client_views(c, &dummy);
 
         unmap_client(c, WithdrawnState);
+ gravitate_client(c, True);
         reparent_client(c, blz.root, c->rect.x, c->rect.y);
         XFreeGC(blz.dpy, c->gc);
         XDestroyWindow(blz.dpy, c->framewin);
@@ -550,8 +553,12 @@ void
 void
 focus_client(Client *c) {
         if(verbose)
- fprintf(stderr, "focus_client(%p)\n", c);
+ fprintf(stderr, "focus_client(%p) => %s\n", c, (c ? c->name : nil));
         if(screen->focus != c) {
+ update_client_grab(c);
+ if(verbose)
+ fprintf(stderr, "\t%s => %s\n", (screen->focus ? screen->focus->name : "<nil>"),
+ (c ? c->name : "<nil>"));
                 if(c)
                         XSetInputFocus(blz.dpy, c->win, RevertToParent, CurrentTime);
                 else
diff -r 5a578dc52ed4 -r 7caa3e7323f7 event.c
--- a/event.c Sat Feb 17 02:20:11 2007 -0500
+++ b/event.c Sat Feb 17 12:49:22 2007 -0500
@@ -96,11 +96,11 @@ configurerequest(XEvent *e) {
 
         if(c) {
                 f = c->sel;
- if(verbose)
+ if(0 && verbose)
                         fprintf(stderr, "Configure: %s\n\ta: x=%d y=%d w=%d h=%d\n",
                                 c->name, c->rect.x, c->rect.y, c->rect.width, c->rect.height);
                 gravitate_client(c, True);
- if(verbose)
+ if(0 && verbose)
                         fprintf(stderr, "\tb: x=%d y=%d w=%d h=%d\n",
                                 c->rect.x, c->rect.y, c->rect.width, c->rect.height);
                 if(ev->value_mask & CWX)
@@ -113,11 +113,11 @@ configurerequest(XEvent *e) {
                         c->rect.height = ev->height;
                 if(ev->value_mask & CWBorderWidth)
                         c->border = ev->border_width;
- if(verbose)
+ if(0 && verbose)
                         fprintf(stderr, "\tb: x=%d y=%d w=%d h=%d\n",
                                 c->rect.x, c->rect.y, c->rect.width, c->rect.height);
                 gravitate_client(c, False);
- if(verbose)
+ if(0 && verbose)
                         fprintf(stderr, "\tb: x=%d y=%d w=%d h=%d\n",
                                 c->rect.x, c->rect.y, c->rect.width, c->rect.height);
 
@@ -131,7 +131,7 @@ configurerequest(XEvent *e) {
                 frect->x -= def.border;
                 frect->width += 2 * def.border;
                 frect->height += frame_delta_h();
- if(verbose)
+ if(0 && verbose)
                         fprintf(stderr, "\tb: x=%d y=%d w=%d h=%d\n",
                                 frect->x, frect->y, frect->width, frect->height);
 
@@ -278,12 +278,19 @@ focusin(XEvent *e) {
 
         c = client_of_win(ev->window);
         if(c) {
- if(verbose)
+ if(verbose) {
                         fprintf(stderr, "screen->focus: %p => %p\n", screen->focus, c);
+ fprintf(stderr, "\t%s => %s\n", (screen->focus ? screen->focus->name : nil),
+ c->name);
+ }
+ update_client_grab(c);
                 screen->focus = c;
         }else if(ev->window == screen->barwin) {
- if(verbose)
- fprintf(stderr, "screen->focus: %p => %p\n", screen->focus, nil);
+ if(verbose) {
+ fprintf(stderr, "screen->focus: %p => %p\n", screen->focus, c);
+ fprintf(stderr, "\t%s => %s\n", (screen->focus ? screen->focus->name : nil),
+ "<nil>");
+ }
                 screen->focus = nil;
         }
 #if 0
@@ -312,6 +319,12 @@ focusin(XEvent *e) {
 
 static void
 focusout(XEvent *e) {
+ Client *c;
+ XFocusChangeEvent *ev = &e->xfocus;
+
+ c = client_of_win(ev->window);
+ if(c)
+ update_client_grab(c);
 #if 0
         Client *c;
         XFocusChangeEvent *ev = &e->xfocus;
@@ -352,7 +365,7 @@ check_x_event(IXPConn *c) {
         XEvent ev;
         while(XPending(blz.dpy)) { /* main event loop */
                 XNextEvent(blz.dpy, &ev);
- if(verbose)
+ if(0 && verbose)
                         printevent(&ev);
                 if(handler[ev.type])
                         (handler[ev.type]) (&ev); /* call handler */
diff -r 5a578dc52ed4 -r 7caa3e7323f7 main.c
--- a/main.c Sat Feb 17 02:20:11 2007 -0500
+++ b/main.c Sat Feb 17 12:49:22 2007 -0500
@@ -332,7 +332,7 @@ main(int argc, char *argv[]) {
                 XChangeWindowAttributes(blz.dpy, blz.root, CWEventMask | CWCursor, &wa);
                 wa.override_redirect = 1;
                 wa.background_pixmap = ParentRelative;
- wa.event_mask = ExposureMask | ButtonReleaseMask
+ wa.event_mask = ExposureMask | ButtonReleaseMask | FocusChangeMask
                         | SubstructureRedirectMask | SubstructureNotifyMask;
                 s->brect = s->rect;
                 s->brect.height = labelh(&def.font);
@@ -359,8 +359,8 @@ main(int argc, char *argv[]) {
 
         screen = &screens[0];
 
- screen->focus = (void*)-1;
- focus_client(nil);
+ screen->focus = nil;
+ XSetInputFocus(blz.dpy, screen->barwin, RevertToParent, CurrentTime);
         scan_wins();
         starting = False;
         update_views();
Received on Sat Feb 17 2007 - 18:50:07 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:55:24 UTC