]>
Dogcows Code - chaz/openbox/blob - plugins/focus.c
7275b3fd6e90dbb7f6b52c3d0f177f247af2fb33
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"
9 static int skip_enter
= 0;
11 static void focus_fallback(gboolean warp
)
15 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
16 if (client_focus(it
->data
)) {
17 if (warp
) { /* XXX make this configurable */
21 /* skip the next enter event from the desktop switch so focus
22 doesn't skip briefly to what was under the pointer */
23 if (XCheckTypedEvent(ob_display
, EnterNotify
, &e
)) {
24 XPutBackEvent(ob_display
, &e
);
25 /* XXX WERE NOT SKIPPING THEM ALL@&*)! */
30 /* I have to do this warp twice! Otherwise windows dont get
31 Enter/Leave events when i warp on a desktop switch! */
32 XWarpPointer(ob_display
, None
, c
->window
, 0, 0, 0, 0,
33 c
->area
.width
/ 2, c
->area
.height
/ 2);
34 XWarpPointer(ob_display
, None
, c
->window
, 0, 0, 0, 0,
35 c
->area
.width
/ 2, c
->area
.height
/ 2);
41 static void focus_under_pointer()
48 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
))
50 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
52 if (c
->desktop
== screen_desktop
&&
53 RECT_CONTAINS(c
->frame
->area
, x
, y
))
57 client_focus(it
->data
);
61 focus_fallback(FALSE
);
64 static void events(ObEvent
*e
, void *foo
)
67 case Event_Client_Mapped
:
68 /* focus new normal windows */
69 if (client_normal(e
->data
.c
.client
))
70 client_focus(e
->data
.c
.client
);
73 case Event_Client_Unmapped
:
74 if (ob_state
== State_Exiting
) break;
76 if (e
->data
.c
.client
->focused
) {
77 /* if sloppy focus... */
78 focus_under_pointer();
82 /\* nothing is left with focus! *\/
83 if (focus_client == NULL)
84 /\* focus the next available target *\/
85 focus_fallback(screen_desktop, FALSE);
90 case Event_Ob_Desktop
:
91 /* focus the next available target if moving from the current
93 if ((unsigned)e
->data
.o
.num
[1] == screen_desktop
)
97 case Event_X_EnterNotify
:
100 else if (e
->data
.x
.client
&& client_normal(e
->data
.x
.client
))
101 client_focus(e
->data
.x
.client
);
105 g_assert_not_reached();
109 void plugin_startup()
111 dispatch_register(Event_Client_Mapped
|
113 Event_Client_Unmapped
|
115 (EventHandler
)events
, NULL
);
118 void plugin_shutdown()
120 dispatch_register(0, (EventHandler
)events
, NULL
);
This page took 0.042578 seconds and 4 git commands to generate.