rewrite focus handling

- arrange() does not focus() anymore
- restore dropping events infra
- add client_unfocus()
- grabbuttons() where we should and add root_grabbuttons() for root window
This commit is contained in:
Julien Danjou 2008-01-25 12:55:44 +01:00
parent b457c4b4c9
commit 485614f2df
8 changed files with 93 additions and 97 deletions

View File

@ -290,7 +290,7 @@ main(int argc, char *argv[])
loadawesomeprops(screen); loadawesomeprops(screen);
ewmh_set_supported_hints(screen); ewmh_set_supported_hints(screen);
/* call this to at least grab root window clicks */ /* call this to at least grab root window clicks */
window_grabbuttons(screen, None, False, True); window_root_grabbuttons(screen);
} }
handler = p_new(event_handler *, LASTEvent); handler = p_new(event_handler *, LASTEvent);
@ -393,7 +393,18 @@ main(int argc, char *argv[])
{ {
XNextEvent(dpy, &ev); XNextEvent(dpy, &ev);
if(handler[ev.type]) if(handler[ev.type])
handler[ev.type](&ev); handler[ev.type](&ev); /* call handler */
/* drop events requested to */
if(globalconf.drop_events)
{
/* need to resync */
XSync(dpy, False);
while(XCheckMaskEvent(dpy, globalconf.drop_events, &ev));
globalconf.drop_events = NoEventMask;
}
/* need to resync */
XSync(dpy, False); XSync(dpy, False);
} }

View File

@ -144,12 +144,22 @@ client_updatetitle(Client *c)
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
} }
static void
client_unfocus(Client *c)
{
XSetWindowBorder(globalconf.display, c->win,
globalconf.screens[c->screen].colors_normal[ColBorder].pixel);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
}
/** Ban client and unmap it /** Ban client and unmap it
* \param c the client * \param c the client
*/ */
void void
client_ban(Client *c) client_ban(Client *c)
{ {
if(globalconf.focus->client == c)
client_unfocus(c);
XUnmapWindow(globalconf.display, c->win); XUnmapWindow(globalconf.display, c->win);
window_setstate(c->win, IconicState); window_setstate(c->win, IconicState);
} }
@ -163,17 +173,6 @@ focus(Client *c, int screen)
{ {
int phys_screen = get_phys_screen(screen); int phys_screen = get_phys_screen(screen);
/* unfocus current selected client */
if(globalconf.focus->client)
{
widget_invalidate_cache(globalconf.focus->client->screen, WIDGET_CACHE_CLIENTS);
window_grabbuttons(get_phys_screen(globalconf.focus->client->screen),
globalconf.focus->client->win, False, True);
XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
globalconf.screens[screen].colors_normal[ColBorder].pixel);
}
/* if c is NULL or invisible, take next client in the focus history */ /* if c is NULL or invisible, take next client in the focus history */
if(!c || (c && !client_isvisible(c, screen))) if(!c || (c && !client_isvisible(c, screen)))
{ {
@ -183,20 +182,18 @@ focus(Client *c, int screen)
for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next); for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
} }
if(c) /* unfocus current selected client */
{ if(globalconf.focus->client)
XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel); client_unfocus(globalconf.focus->client);
window_grabbuttons(phys_screen, c->win, True, True);
}
/* save sel in focus history */ /* save sel in focus history */
focus_add_client(c); focus_add_client(c);
if(globalconf.focus->client) if(c)
{ {
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS); XSetWindowBorder(globalconf.display, c->win,
XSetInputFocus(globalconf.display, globalconf.screens[screen].colors_selected[ColBorder].pixel);
globalconf.focus->client->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
restack(screen); restack(screen);
} }
else else
@ -204,7 +201,9 @@ focus(Client *c, int screen)
RootWindow(globalconf.display, phys_screen), RootWindow(globalconf.display, phys_screen),
RevertToPointerRoot, CurrentTime); RevertToPointerRoot, CurrentTime);
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
ewmh_update_net_active_window(phys_screen); ewmh_update_net_active_window(phys_screen);
globalconf.drop_events |= EnterWindowMask;
} }
/** Manage a new client /** Manage a new client
@ -300,7 +299,6 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
} }
XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
window_grabbuttons(phys_screen, c->win, False, True);
/* handle xshape */ /* handle xshape */
if(globalconf.have_shape) if(globalconf.have_shape)

19
event.c
View File

@ -122,7 +122,7 @@ handle_event_buttonpress(XEvent *e)
&& ev->button == Button1) && ev->button == Button1)
{ {
XAllowEvents(globalconf.display, ReplayPointer, CurrentTime); XAllowEvents(globalconf.display, ReplayPointer, CurrentTime);
window_grabbuttons(get_phys_screen(c->screen), c->win, True, True); window_grabbuttons(get_phys_screen(c->screen), c->win, True);
} }
else else
handle_mouse_button_press(c->screen, ev->button, ev->state, globalconf.buttons.client, NULL); handle_mouse_button_press(c->screen, ev->button, ev->state, globalconf.buttons.client, NULL);
@ -233,29 +233,20 @@ handle_event_enternotify(XEvent * e)
Client *c; Client *c;
XCrossingEvent *ev = &e->xcrossing; XCrossingEvent *ev = &e->xcrossing;
int screen; int screen;
Tag **curtags;
if(ev->mode != NotifyNormal) if(ev->mode != NotifyNormal)
return; return;
if((c = get_client_bywin(globalconf.clients, ev->window)) if((c = get_client_bywin(globalconf.clients, ev->window)))
&& globalconf.screens[c->screen].sloppy_focus
&& c != globalconf.focus->client)
{ {
window_grabbuttons(get_phys_screen(c->screen), c->win, False);
if(globalconf.screens[c->screen].sloppy_focus)
focus(c, c->screen); focus(c, c->screen);
curtags = get_current_tags(c->screen);
if (c->isfloating || curtags[0]->layout->arrange == layout_floating)
window_grabbuttons(get_phys_screen(c->screen), c->win, True, False);
p_delete(&curtags);
} }
else else
{
for(screen = 0; screen < ScreenCount(e->xany.display); screen++) for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
if(ev->window == RootWindow(e->xany.display, screen)) if(ev->window == RootWindow(e->xany.display, screen))
focus(NULL, screen); window_root_grabbuttons(screen);
if((c = globalconf.focus->client))
window_grabbuttons(c->screen, c->win, False, False);
}
} }
void void

View File

@ -57,9 +57,6 @@ arrange(int screen)
{ {
Client *c; Client *c;
Layout *curlay = get_current_layout(screen); Layout *curlay = get_current_layout(screen);
Window client_win, root_win;
int x, y, d;
unsigned int m;
for(c = globalconf.clients; c; c = c->next) for(c = globalconf.clients; c; c = c->next)
{ {
@ -77,33 +74,28 @@ arrange(int screen)
{ {
c->newcomer = False; c->newcomer = False;
client_unban(c); client_unban(c);
if(globalconf.screens[screen].new_get_focus)
focus(c, screen);
} }
if(!globalconf.screens[screen].allow_lower_floats) if(!globalconf.screens[screen].allow_lower_floats)
layout_raise_floatings(screen); layout_raise_floatings(screen);
c = focus_get_current_client(screen);
focus(c, screen);
if(c && XQueryPointer(globalconf.display, RootWindow(globalconf.display, get_phys_screen(screen)),
&root_win, &client_win, &x, &y, &d, &d, &m) &&
(root_win == None || client_win == None || client_win == root_win))
window_grabbuttons(c->screen, c->win, False, False);
/* reset status */ /* reset status */
globalconf.screens[screen].need_arrange = False; globalconf.screens[screen].need_arrange = False;
} }
Bool int
layout_refresh(void) layout_refresh(void)
{ {
int screen; int screen;
Bool arranged = False; int arranged = 0;
for(screen = 0; screen < globalconf.nscreen; screen++) for(screen = 0; screen < globalconf.nscreen; screen++)
if(globalconf.screens[screen].need_arrange) if(globalconf.screens[screen].need_arrange)
{ {
arrange(screen); arrange(screen);
arranged = True; arranged++;
} }
return arranged; return arranged;

View File

@ -40,7 +40,7 @@ struct Layout
DO_SLIST(Layout, layout, p_delete); DO_SLIST(Layout, layout, p_delete);
Bool layout_refresh(void); int layout_refresh(void);
Layout * get_current_layout(int); Layout * get_current_layout(int);
void restack(int); void restack(int);
void loadawesomeprops(int); void loadawesomeprops(int);

View File

@ -328,6 +328,8 @@ struct AwesomeConf
tag_client_node_t *tclink; tag_client_node_t *tclink;
/** Command line passed to awesome */ /** Command line passed to awesome */
char *argv; char *argv;
/** EventMask to drop before each XEvent treatement */
long drop_events;
}; };
#endif #endif

View File

@ -93,39 +93,41 @@ window_configure(Window win, Area geometry, int border)
* \param raised True if the client is above other clients * \param raised True if the client is above other clients
*/ */
void void
window_grabbuttons(int screen, window_grabbuttons(int screen, Window win, Bool raised)
Window win,
Bool focused,
Bool raised)
{ {
Button *b; Button *b;
XUngrabButton(globalconf.display, AnyButton, AnyModifier, win);
if(focused)
{
if(!raised) if(!raised)
XGrabButton(globalconf.display, Button1, NoSymbol, win, False, {
BUTTONMASK, GrabModeSync, GrabModeAsync, None, None); XGrabButton(globalconf.display, Button1, NoSymbol,
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
XGrabButton(globalconf.display, Button1, NoSymbol | LockMask,
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask,
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
}
for(b = globalconf.buttons.client; b; b = b->next) for(b = globalconf.buttons.client; b; b = b->next)
{ {
XGrabButton(globalconf.display, b->button, b->mod, win, False, BUTTONMASK, XGrabButton(globalconf.display, b->button, b->mod,
GrabModeAsync, GrabModeSync, None, None); win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | LockMask, win, False, XGrabButton(globalconf.display, b->button, b->mod | LockMask,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask, win, False, XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask, XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
} }
XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, screen)); XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, screen));
} }
else
void
window_root_grabbuttons(int screen)
{ {
XGrabButton(globalconf.display, AnyButton, AnyModifier, win, False, BUTTONMASK, Button *b;
GrabModeAsync, GrabModeSync, None, None);
for(b = globalconf.buttons.root; b; b = b->next) for(b = globalconf.buttons.root; b; b = b->next)
{ {
@ -143,7 +145,6 @@ window_grabbuttons(int screen,
GrabModeAsync, GrabModeSync, None, None); GrabModeAsync, GrabModeSync, None, None);
} }
} }
}
void void
window_setshape(int screen, Window win) window_setshape(int screen, Window win)

View File

@ -27,7 +27,8 @@
int window_setstate(Window, long); int window_setstate(Window, long);
long window_getstate(Window); long window_getstate(Window);
Status window_configure(Window, Area, int); Status window_configure(Window, Area, int);
void window_grabbuttons(int, Window, Bool, Bool); void window_grabbuttons(int, Window, Bool);
void window_root_grabbuttons(int);
void window_setshape(int, Window); void window_setshape(int, Window);
int window_settrans(Window, double); int window_settrans(Window, double);
SimpleWindow * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int); SimpleWindow * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int);