]>
Dogcows Code - chaz/openbox/blob - plugins/focus.c
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"
8 #include "../kernel/config.h"
10 void plugin_setup_config()
14 config_def_set(config_def_new("focus.followMouse", Config_Bool
,
15 "Focus Follows Mouse",
16 "Focus windows when the mouse pointer "
19 config_set("focus.followMouse", Config_Bool
, val
);
20 config_def_set(config_def_new("focus.focusNew", Config_Bool
,
22 "Focus windows when they first appear."));
24 config_set("focus.focusNew", Config_Bool
, val
);
26 config_def_set(config_def_new("focus.warpOnDeskSwitch", Config_Bool,
27 "Warp Pointer On Desktop Switch",
28 "Warps the pointer to the focused window "
29 "when switching desktops."));
30 config_set("focus.warpOnDeskSwitch", Config_Bool, FALSE);
34 /*static int skip_enter = 0;*/
36 static gboolean
focus_under_pointer()
43 if (XQueryPointer(ob_display
, ob_root
, &w
, &w
, &x
, &y
, &i
, &i
, &u
))
45 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
47 if (c
->desktop
== screen_desktop
&&
48 RECT_CONTAINS(c
->frame
->area
, x
, y
))
52 return client_normal(it
->data
) && client_focus(it
->data
);
58 static void chew_enter_events()
63 skip the next enter event from the desktop switch so focus
64 doesn't skip briefly to what was under the pointer */
66 /* kill all enter events from prior to the desktop switch, we
67 aren't interested in them if we have found our own target
69 XXX this is rude to other plugins...can this be done
70 better? count the events in the queue? */
71 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
74 XPutBackEvent(ob_display, &e);
81 static void focus_fallback(gboolean switching_desks
)
85 for (it
= focus_order
[screen_desktop
]; it
!= NULL
; it
= it
->next
)
86 if (client_normal(it
->data
) && client_focus(it
->data
)) {
87 if (switching_desks
) {
92 if (FALSE
/*warp_on_desk_switch*/) {
93 /* I have to do this warp twice! Otherwise windows dont get
94 Enter/Leave events when i warp on a desktop switch! */
95 XWarpPointer(ob_display
, None
, c
->window
, 0, 0, 0, 0,
96 c
->area
.width
/ 2, c
->area
.height
/ 2);
97 XWarpPointer(ob_display
, None
, c
->window
, 0, 0, 0, 0,
98 c
->area
.width
/ 2, c
->area
.height
/ 2);
105 static void focus_desktop()
109 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
110 Client
*client
= it
->data
;
111 if (client
->type
== Type_Desktop
&& client
->frame
->visible
)
112 if (client_focus(client
))
118 static void event(ObEvent
*e
, void *foo
)
120 ConfigValue follow_mouse
, focus_new
;
122 if (!config_get("focus.followMouse", Config_Bool
, &follow_mouse
))
123 g_assert_not_reached();
126 case Event_Client_Mapped
:
127 if (!config_get("focus.focusNew", Config_Bool
, &focus_new
))
128 g_assert_not_reached();
129 if (focus_new
.bool && client_normal(e
->data
.c
.client
))
130 client_focus(e
->data
.c
.client
);
133 case Event_Client_Unmapped
:
134 if (ob_state
== State_Exiting
) break;
136 if (client_focused(e
->data
.c
.client
))
137 if (!follow_mouse
.bool || !focus_under_pointer())
138 focus_fallback(FALSE
);
141 case Event_Client_Desktop
:
142 /* focus the next available target if moving from the current
144 if ((unsigned)e
->data
.c
.num
[1] == screen_desktop
)
145 if (!follow_mouse
.bool || !focus_under_pointer())
146 focus_fallback(FALSE
);
148 case Event_Ob_Desktop
:
149 focus_fallback(TRUE
);
152 case Event_Ob_ShowDesktop
:
153 if (!e
->data
.o
.num
[0]) { /* hiding the desktop, showing the clients */
154 if (!follow_mouse
.bool || !focus_under_pointer())
155 focus_fallback(TRUE
);
156 } else /* hiding clients, showing the desktop */
160 case Event_X_EnterNotify
:
162 if (e->data.x.client != NULL)
163 g_message("skipped enter %lx", e->data.x.client->window);
165 g_message("skipped enter 'root'");
169 if (follow_mouse
.bool)
170 if (e
->data
.x
.client
!= NULL
&& client_normal(e
->data
.x
.client
))
171 client_focus(e
->data
.x
.client
);
175 g_assert_not_reached();
179 void plugin_startup()
181 dispatch_register(Event_Client_Mapped
|
183 Event_Client_Unmapped
|
184 Event_X_EnterNotify
|
185 Event_Ob_ShowDesktop
,
186 (EventHandler
)event
, NULL
);
189 void plugin_shutdown()
191 dispatch_register(0, (EventHandler
)event
, NULL
);
This page took 0.042828 seconds and 5 git commands to generate.