1 #include "../kernel/dispatch.h"
2 #include "../kernel/screen.h"
3 #include "../kernel/client.h"
4 #include "../kernel/frame.h"
5 #include "../kernel/focus.h"
6 #include "../kernel/stacking.h"
7 #include "../kernel/openbox.h"
10 static gboolean follow_mouse
= TRUE
;
11 static gboolean warp_on_desk_switch
= TRUE
;
12 static gboolean focus_new
= FALSE
;
14 static int skip_enter
= 0;
16 static gboolean
focus_under_pointer()
23 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
))
25 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
27 if (c
->desktop
== screen_desktop
&&
28 RECT_CONTAINS(c
->frame
->area
, x
, y
))
32 client_focus(it
->data
);
39 static void focus_fallback(gboolean switching_desks
)
43 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
44 if (client_normal(it
->data
) && client_focus(it
->data
)) {
45 if (switching_desks
&& warp_on_desk_switch
) {
50 skip the next enter event from the desktop switch so focus
51 doesn't skip briefly to what was under the pointer */
53 /* kill all enter events from prior to the desktop switch, we
54 aren't interested in them if we have found our own target
56 XXX this is rude to other plugins...can this be done
57 better? count the events in the queue? */
58 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
59 /* XPutBackEvent(ob_display, &e);
64 /* I have to do this warp twice! Otherwise windows dont get
65 Enter/Leave events when i warp on a desktop switch! */
66 XWarpPointer(ob_display
, None
, c
->window
, 0, 0, 0, 0,
67 c
->area
.width
/ 2, c
->area
.height
/ 2);
68 XWarpPointer(ob_display
, None
, c
->window
, 0, 0, 0, 0,
69 c
->area
.width
/ 2, c
->area
.height
/ 2);
75 static void events(ObEvent
*e
, void *foo
)
78 case Event_Client_Mapped
:
79 if (focus_new
&& client_normal(e
->data
.c
.client
))
80 client_focus(e
->data
.c
.client
);
83 case Event_Client_Unmapped
:
84 if (ob_state
== State_Exiting
) break;
86 if (e
->data
.c
.client
->focused
)
87 if (!follow_mouse
|| !focus_under_pointer())
88 focus_fallback(FALSE
);
91 case Event_Client_Desktop
:
92 /* focus the next available target if moving from the current
94 if ((unsigned)e
->data
.c
.num
[1] == screen_desktop
)
95 if (!follow_mouse
|| !focus_under_pointer())
96 focus_fallback(FALSE
);
98 case Event_Ob_Desktop
:
102 case Event_X_EnterNotify
:
104 if (e
->data
.x
.client
!= NULL
)
105 g_message("skipped enter %lx", e
->data
.x
.client
->window
);
107 g_message("skipped enter 'root'");
110 else if (e
->data
.x
.client
!= NULL
&& client_normal(e
->data
.x
.client
)) {
111 g_message("enter %lx", e
->data
.x
.client
->window
);
112 client_focus(e
->data
.x
.client
);
117 g_assert_not_reached();
121 void plugin_startup()
123 dispatch_register(Event_Client_Mapped
|
125 Event_Client_Unmapped
|
127 (EventHandler
)events
, NULL
);
130 void plugin_shutdown()
132 dispatch_register(0, (EventHandler
)events
, NULL
);