Fix focus hooks calls

This patch fixes focus hooks calls - for every call to focus hook, there
should be call to unfocus hook.

Focus related info:
In this shape, awesome doesn't support multiple focused clients, that
means it follows the rule "there is only a single focus", which is not
true for MPX. To change this, I think it will need some magic with
FocusOut events handling and changes to some structures
(e.g. globalconf.screen_focus, screen_t.client_focus should be arrays) :p
Now we don't need to handle FocusOut events.

Signed-off-by: Mariusz Ceier <mceier@gmail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Mariusz Ceier 2009-04-28 10:54:10 +02:00 committed by Julien Danjou
parent cb0f88dfc7
commit ee77fce1ce
3 changed files with 18 additions and 43 deletions

View file

@ -498,6 +498,7 @@ main(int argc, char **argv)
| XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_PROPERTY_CHANGE
| XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_PRESS
| XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_RELEASE
| XCB_EVENT_MASK_FOCUS_CHANGE
}; };
xcb_change_window_attributes(globalconf.connection, xcb_change_window_attributes(globalconf.connection,

View file

@ -187,11 +187,12 @@ client_unfocus_update(client_t *c)
void void
client_unfocus(client_t *c) client_unfocus(client_t *c)
{ {
xcb_window_t root_win = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
globalconf.screens.tab[c->phys_screen].client_focus = NULL;
xcb_window_t root_win = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
/* Set focus on root window, so no events leak to the current window. */ /* Set focus on root window, so no events leak to the current window. */
window_setfocus(root_win, true); window_setfocus(root_win, true);
client_unfocus_update(c);
} }
/** Ban client and move it out of the viewport. /** Ban client and move it out of the viewport.
@ -239,6 +240,15 @@ client_focus_update(client_t *c)
return; return;
} }
if(globalconf.screen_focus
&& globalconf.screen_focus->client_focus)
{
if (globalconf.screen_focus->client_focus != c)
client_unfocus_update(globalconf.screen_focus->client_focus);
else
/* Already focused */
return;
}
/* stop hiding client */ /* stop hiding client */
c->ishidden = false; c->ishidden = false;
client_setminimized(c, false); client_setminimized(c, false);
@ -281,8 +291,8 @@ client_focus(client_t *c)
if(!client_maybevisible(c, c->screen)) if(!client_maybevisible(c, c->screen))
return; return;
globalconf.screen_focus = &globalconf.screens.tab[c->phys_screen]; if (!c->nofocus)
globalconf.screen_focus->client_focus = c; client_focus_update(c);
window_setfocus(c->win, !c->nofocus); window_setfocus(c->win, !c->nofocus);
} }

40
event.c
View file

@ -506,15 +506,8 @@ event_handle_focusin(void *data __attribute__ ((unused)),
/* Events that we are interested in: */ /* Events that we are interested in: */
switch(ev->detail) switch(ev->detail)
{ {
/* These are events that jump between windows of a toplevel client. /* These are events that jump between root windows.
*
* NotifyVirtual event is handled in case where NotifyAncestor or
* NotifyInferior event is not generated on window that is managed by
* awesome ( client_* returns NULL )
*
* Can someone explain exactly why they are needed ?
*/ */
case XCB_NOTIFY_DETAIL_VIRTUAL:
case XCB_NOTIFY_DETAIL_ANCESTOR: case XCB_NOTIFY_DETAIL_ANCESTOR:
case XCB_NOTIFY_DETAIL_INFERIOR: case XCB_NOTIFY_DETAIL_INFERIOR:
@ -528,37 +521,9 @@ event_handle_focusin(void *data __attribute__ ((unused)),
client_focus_update(c); client_focus_update(c);
/* all other events are ignored */ /* all other events are ignored */
default: default:
return 0; break;
} }
}
/** The focus out event handler.
* \param data currently unused.
* \param connection The connection to the X server.
* \param ev The event.
*/
static int
event_handle_focusout(void *data __attribute__ ((unused)),
xcb_connection_t *connection,
xcb_focus_out_event_t *ev)
{
client_t *c;
/* Events that we are interested in: */
switch(ev->detail)
{
/* These are events that jump between clients.
* Virtual events ensure we always get an event on our top-level window.
*/
case XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL:
case XCB_NOTIFY_DETAIL_NONLINEAR:
if((c = client_getbytitlebarwin(ev->event))
|| (c = client_getbywin(ev->event)))
client_unfocus_update(c);
/* all other events are ignored */
default:
return 0; return 0;
}
} }
/** The expose event handler. /** The expose event handler.
@ -851,7 +816,6 @@ void a_xcb_set_event_handlers(void)
xcb_event_set_enter_notify_handler(&globalconf.evenths, event_handle_enternotify, NULL); xcb_event_set_enter_notify_handler(&globalconf.evenths, event_handle_enternotify, NULL);
xcb_event_set_leave_notify_handler(&globalconf.evenths, event_handle_leavenotify, NULL); xcb_event_set_leave_notify_handler(&globalconf.evenths, event_handle_leavenotify, NULL);
xcb_event_set_focus_in_handler(&globalconf.evenths, event_handle_focusin, NULL); xcb_event_set_focus_in_handler(&globalconf.evenths, event_handle_focusin, NULL);
xcb_event_set_focus_out_handler(&globalconf.evenths, event_handle_focusout, NULL);
xcb_event_set_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, NULL); xcb_event_set_motion_notify_handler(&globalconf.evenths, event_handle_motionnotify, NULL);
xcb_event_set_expose_handler(&globalconf.evenths, event_handle_expose, NULL); xcb_event_set_expose_handler(&globalconf.evenths, event_handle_expose, NULL);
xcb_event_set_key_press_handler(&globalconf.evenths, event_handle_key, NULL); xcb_event_set_key_press_handler(&globalconf.evenths, event_handle_key, NULL);