]> Dogcows Code - chaz/openbox/blob - plugins/focus.c
move the focus_order lists into the kernel
[chaz/openbox] / plugins / focus.c
1 #include "../kernel/dispatch.h"
2 #include "../kernel/screen.h"
3 #include "../kernel/client.h"
4 #include "../kernel/focus.h"
5 #include "../kernel/stacking.h"
6 #include "../kernel/openbox.h"
7
8 static int skip_enter = 0;
9
10 static void focus_fallback(guint desk, gboolean warp)
11 {
12 GList *it;
13
14 for (it = focus_order[desk]; it != NULL; it = it->next)
15 if (client_focus(it->data)) {
16 if (warp) { /* XXX make this configurable */
17 XEvent e;
18 Client *c = it->data;
19
20 /* skip the next enter event from the desktop switch so focus
21 doesn't skip briefly to what was under the pointer */
22 if (XCheckTypedEvent(ob_display, EnterNotify, &e)) {
23 XPutBackEvent(ob_display, &e);
24 ++skip_enter;
25 }
26
27 XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
28 c->area.width / 2, c->area.height / 2);
29 XWarpPointer(ob_display, None, c->window, 0, 0, 0, 0,
30 c->area.width / 2, c->area.height / 2);
31 }
32 break;
33 }
34 }
35
36 static void events(ObEvent *e, void *foo)
37 {
38 switch (e->type) {
39 case Event_Client_Mapped:
40 /* focus new normal windows */
41 if (client_normal(e->data.c.client))
42 client_focus(e->data.c.client);
43 break;
44
45 case Event_Ob_Desktop:
46 g_message("Desktop Switch");
47 /* focus the next available target */
48 focus_fallback(e->data.o.num[0], TRUE);
49 break;
50
51 case Event_Client_Unfocus:
52 /* dont do this shit with sloppy focus... */
53 /*
54 /\* nothing is left with focus! *\/
55 if (focus_client == NULL)
56 /\* focus the next available target *\/
57 focus_fallback(screen_desktop, FALSE);
58 */
59 break;
60
61 case Event_X_LeaveNotify:
62 g_message("Leave: %lx", e->data.x.client ? e->data.x.client->window : 0);
63 break;
64
65 case Event_X_EnterNotify:
66 g_message("Enter: %lx", e->data.x.client ? e->data.x.client->window : 0);
67 if (skip_enter)
68 --skip_enter;
69 else if (e->data.x.client && client_normal(e->data.x.client))
70 client_focus(e->data.x.client);
71 break;
72
73 default:
74 g_assert_not_reached();
75 }
76 }
77
78 void plugin_startup()
79 {
80 dispatch_register(Event_Client_Mapped |
81 Event_Ob_Desktop |
82 Event_Client_Unfocus |
83 Event_X_EnterNotify |
84 Event_X_LeaveNotify,
85 (EventHandler)events, NULL);
86 }
87
88 void plugin_shutdown()
89 {
90 dispatch_register(0, (EventHandler)events, NULL);
91 }
This page took 0.037759 seconds and 4 git commands to generate.