2003-03-18 03:11:55 +00:00
|
|
|
#include "../kernel/dispatch.h"
|
2003-03-18 05:21:50 +00:00
|
|
|
#include "../kernel/screen.h"
|
|
|
|
#include "../kernel/client.h"
|
2003-03-20 21:23:05 +00:00
|
|
|
#include "../kernel/frame.h"
|
2003-03-18 09:10:05 +00:00
|
|
|
#include "../kernel/focus.h"
|
2003-03-18 05:21:50 +00:00
|
|
|
#include "../kernel/stacking.h"
|
2003-03-18 09:21:07 +00:00
|
|
|
#include "../kernel/openbox.h"
|
2003-03-18 03:11:55 +00:00
|
|
|
|
2003-03-19 07:08:15 +00:00
|
|
|
static int skip_enter = 0;
|
2003-03-18 05:21:50 +00:00
|
|
|
|
2003-03-20 21:23:05 +00:00
|
|
|
static void focus_fallback(gboolean warp)
|
2003-03-18 09:21:07 +00:00
|
|
|
{
|
2003-03-19 07:08:15 +00:00
|
|
|
GList *it;
|
2003-03-18 09:21:07 +00:00
|
|
|
|
2003-03-20 21:23:05 +00:00
|
|
|
for (it = focus_order[screen_desktop]; it != NULL; it = it->next)
|
2003-03-18 09:21:07 +00:00
|
|
|
if (client_focus(it->data)) {
|
|
|
|
if (warp) { /* XXX make this configurable */
|
2003-03-19 07:08:15 +00:00
|
|
|
XEvent e;
|
2003-03-18 09:21:07 +00:00
|
|
|
Client *c = it->data;
|
2003-03-19 07:08:15 +00:00
|
|
|
|
|
|
|
/* skip the next enter event from the desktop switch so focus
|
|
|
|
doesn't skip briefly to what was under the pointer */
|
|
|
|
if (XCheckTypedEvent(ob_display, EnterNotify, &e)) {
|
|
|
|
XPutBackEvent(ob_display, &e);
|
2003-03-19 08:40:00 +00:00
|
|
|
/* XXX WERE NOT SKIPPING THEM ALL@&*)! */
|
|
|
|
g_message("Skip");
|
2003-03-19 07:08:15 +00:00
|
|
|
++skip_enter;
|
|
|
|
}
|
|
|
|
|
2003-03-19 08:40:00 +00:00
|
|
|
/* I have to do this warp twice! Otherwise windows dont get
|
|
|
|
Enter/Leave events when i warp on a desktop switch! */
|
2003-03-19 07:08:15 +00:00
|
|
|
XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
|
|
|
|
c->area.width / 2, c->area.height / 2);
|
2003-03-18 09:21:07 +00:00
|
|
|
XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
|
|
|
|
c->area.width / 2, c->area.height / 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-20 21:23:05 +00:00
|
|
|
static void focus_under_pointer()
|
|
|
|
{
|
|
|
|
Window w;
|
|
|
|
int i, x, y;
|
|
|
|
guint u;
|
|
|
|
GList *it;
|
|
|
|
|
|
|
|
if (XQueryPointer(ob_display, ob_root, &w, &w, &x, &y, &i, &i, &u))
|
|
|
|
{
|
|
|
|
for (it = stacking_list; it != NULL; it = it->next) {
|
|
|
|
Client *c = it->data;
|
|
|
|
if (c->desktop == screen_desktop &&
|
|
|
|
RECT_CONTAINS(c->frame->area, x, y))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (it != NULL) {
|
|
|
|
client_focus(it->data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
focus_fallback(FALSE);
|
|
|
|
}
|
|
|
|
|
2003-03-18 05:21:50 +00:00
|
|
|
static void events(ObEvent *e, void *foo)
|
|
|
|
{
|
|
|
|
switch (e->type) {
|
|
|
|
case Event_Client_Mapped:
|
|
|
|
/* focus new normal windows */
|
|
|
|
if (client_normal(e->data.c.client))
|
|
|
|
client_focus(e->data.c.client);
|
|
|
|
break;
|
|
|
|
|
2003-03-20 21:23:05 +00:00
|
|
|
case Event_Client_Unmapped:
|
|
|
|
if (ob_state == State_Exiting) break;
|
|
|
|
|
|
|
|
if (e->data.c.client->focused) {
|
|
|
|
/* if sloppy focus... */
|
|
|
|
focus_under_pointer();
|
|
|
|
|
|
|
|
/* otherwise... */
|
|
|
|
/*
|
|
|
|
/\* nothing is left with focus! *\/
|
|
|
|
if (focus_client == NULL)
|
|
|
|
/\* focus the next available target *\/
|
|
|
|
focus_fallback(screen_desktop, FALSE);
|
|
|
|
*/
|
|
|
|
}
|
2003-03-18 05:21:50 +00:00
|
|
|
break;
|
|
|
|
|
2003-03-20 21:23:05 +00:00
|
|
|
case Event_Ob_Desktop:
|
|
|
|
/* focus the next available target if moving from the current
|
|
|
|
desktop. */
|
|
|
|
if ((unsigned)e->data.o.num[1] == screen_desktop)
|
|
|
|
focus_fallback(TRUE);
|
2003-03-18 09:10:05 +00:00
|
|
|
break;
|
|
|
|
|
2003-03-19 06:00:16 +00:00
|
|
|
case Event_X_EnterNotify:
|
2003-03-19 07:08:15 +00:00
|
|
|
if (skip_enter)
|
|
|
|
--skip_enter;
|
|
|
|
else if (e->data.x.client && client_normal(e->data.x.client))
|
2003-03-19 06:00:16 +00:00
|
|
|
client_focus(e->data.x.client);
|
2003-03-19 06:00:52 +00:00
|
|
|
break;
|
2003-03-19 06:00:16 +00:00
|
|
|
|
2003-03-18 05:21:50 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_startup()
|
2003-03-18 03:11:55 +00:00
|
|
|
{
|
2003-03-19 07:08:15 +00:00
|
|
|
dispatch_register(Event_Client_Mapped |
|
|
|
|
Event_Ob_Desktop |
|
2003-03-20 21:23:05 +00:00
|
|
|
Event_Client_Unmapped |
|
2003-03-19 08:15:56 +00:00
|
|
|
Event_X_EnterNotify,
|
2003-03-18 09:10:05 +00:00
|
|
|
(EventHandler)events, NULL);
|
2003-03-18 03:11:55 +00:00
|
|
|
}
|
|
|
|
|
2003-03-18 05:21:50 +00:00
|
|
|
void plugin_shutdown()
|
2003-03-18 03:11:55 +00:00
|
|
|
{
|
2003-03-18 05:21:50 +00:00
|
|
|
dispatch_register(0, (EventHandler)events, NULL);
|
2003-03-18 03:11:55 +00:00
|
|
|
}
|