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);
ewmh_set_supported_hints(screen);
/* 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);
@ -393,7 +393,18 @@ main(int argc, char *argv[])
{
XNextEvent(dpy, &ev);
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);
}

View File

@ -144,12 +144,22 @@ client_updatetitle(Client *c)
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
* \param c the client
*/
void
client_ban(Client *c)
{
if(globalconf.focus->client == c)
client_unfocus(c);
XUnmapWindow(globalconf.display, c->win);
window_setstate(c->win, IconicState);
}
@ -163,17 +173,6 @@ focus(Client *c, int 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 || (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);
}
if(c)
{
XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel);
window_grabbuttons(phys_screen, c->win, True, True);
}
/* unfocus current selected client */
if(globalconf.focus->client)
client_unfocus(globalconf.focus->client);
/* save sel in focus history */
focus_add_client(c);
if(globalconf.focus->client)
if(c)
{
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
XSetInputFocus(globalconf.display,
globalconf.focus->client->win, RevertToPointerRoot, CurrentTime);
XSetWindowBorder(globalconf.display, c->win,
globalconf.screens[screen].colors_selected[ColBorder].pixel);
XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
restack(screen);
}
else
@ -204,7 +201,9 @@ focus(Client *c, int screen)
RootWindow(globalconf.display, phys_screen),
RevertToPointerRoot, CurrentTime);
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
ewmh_update_net_active_window(phys_screen);
globalconf.drop_events |= EnterWindowMask;
}
/** Manage a new client
@ -300,7 +299,6 @@ client_manage(Window w, XWindowAttributes *wa, int screen)
}
XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
window_grabbuttons(phys_screen, c->win, False, True);
/* handle xshape */
if(globalconf.have_shape)

19
event.c
View File

@ -122,7 +122,7 @@ handle_event_buttonpress(XEvent *e)
&& ev->button == Button1)
{
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
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;
XCrossingEvent *ev = &e->xcrossing;
int screen;
Tag **curtags;
if(ev->mode != NotifyNormal)
return;
if((c = get_client_bywin(globalconf.clients, ev->window))
&& globalconf.screens[c->screen].sloppy_focus
&& c != globalconf.focus->client)
if((c = get_client_bywin(globalconf.clients, ev->window)))
{
window_grabbuttons(get_phys_screen(c->screen), c->win, False);
if(globalconf.screens[c->screen].sloppy_focus)
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
{
for(screen = 0; screen < ScreenCount(e->xany.display); screen++)
if(ev->window == RootWindow(e->xany.display, screen))
focus(NULL, screen);
if((c = globalconf.focus->client))
window_grabbuttons(c->screen, c->win, False, False);
}
window_root_grabbuttons(screen);
}
void

View File

@ -57,9 +57,6 @@ arrange(int screen)
{
Client *c;
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)
{
@ -77,33 +74,28 @@ arrange(int screen)
{
c->newcomer = False;
client_unban(c);
if(globalconf.screens[screen].new_get_focus)
focus(c, screen);
}
if(!globalconf.screens[screen].allow_lower_floats)
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 */
globalconf.screens[screen].need_arrange = False;
}
Bool
int
layout_refresh(void)
{
int screen;
Bool arranged = False;
int arranged = 0;
for(screen = 0; screen < globalconf.nscreen; screen++)
if(globalconf.screens[screen].need_arrange)
{
arrange(screen);
arranged = True;
arranged++;
}
return arranged;

View File

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

View File

@ -328,6 +328,8 @@ struct AwesomeConf
tag_client_node_t *tclink;
/** Command line passed to awesome */
char *argv;
/** EventMask to drop before each XEvent treatement */
long drop_events;
};
#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
*/
void
window_grabbuttons(int screen,
Window win,
Bool focused,
Bool raised)
window_grabbuttons(int screen, Window win, Bool raised)
{
Button *b;
XUngrabButton(globalconf.display, AnyButton, AnyModifier, win);
if(focused)
{
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)
{
XGrabButton(globalconf.display, b->button, b->mod, win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | LockMask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask, win, False,
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
}
XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, screen));
}
else
void
window_root_grabbuttons(int screen)
{
XGrabButton(globalconf.display, AnyButton, AnyModifier, win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
Button *b;
for(b = globalconf.buttons.root; b; b = b->next)
{
@ -143,7 +145,6 @@ window_grabbuttons(int screen,
GrabModeAsync, GrabModeSync, None, None);
}
}
}
void
window_setshape(int screen, Window win)

View File

@ -27,7 +27,8 @@
int window_setstate(Window, long);
long window_getstate(Window);
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);
int window_settrans(Window, double);
SimpleWindow * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int);