1 /* -*-c-*- */
2 
3 #ifndef FVWM_FOCUS_POLICY_H
4 #define FVWM_FOCUS_POLICY_H
5 
6 /* Note: focus_policy.[ch] is meant to manage structures of type focus_policy_t
7  * only.  No code dealing with *any* external data types belongs in here!  Put
8  * it in focus.[ch] instead. */
9 
10 /* ---------------------------- included header files ---------------------- */
11 #include "libs/defaults.h"
12 
13 /* ---------------------------- global definitions ------------------------- */
14 
15 #define FPOL_ANY_MODIFIER 0xff
16 
17 /* ---------------------------- access macros ------------------------------ */
18 
19 #define FP_DO_RAISE_FOCUSED_CLICK(fp) \
20 	((fp).do_raise_focused_click)
21 #define FP_DO_RAISE_UNFOCUSED_CLICK(fp) \
22 	((fp).do_raise_unfocused_click)
23 #define FP_DO_FOCUS_CLICK(fp) \
24 	((fp).do_focus_click)
25 #define FP_DO_RAISE_FOCUSED_CLIENT_CLICK(fp) \
26 	((fp).do_raise_focused_click.client)
27 #define FPS_RAISE_FOCUSED_CLIENT_CLICK(fp,x) \
28 	((fp).do_raise_focused_click.client = !!(x))
29 #define FP_DO_RAISE_UNFOCUSED_CLIENT_CLICK(fp) \
30 	((fp).do_raise_unfocused_click.client)
31 #define FPS_RAISE_UNFOCUSED_CLIENT_CLICK(fp,x) \
32 	((fp).do_raise_unfocused_click.client = !!(x))
33 #define FP_DO_RAISE_FOCUSED_DECOR_CLICK(fp) \
34 	((fp).do_raise_focused_click.decor)
35 #define FPS_RAISE_FOCUSED_DECOR_CLICK(fp,x) \
36 	((fp).do_raise_focused_click.decor = !!(x))
37 #define FP_DO_RAISE_UNFOCUSED_DECOR_CLICK(fp) \
38 	((fp).do_raise_unfocused_click.decor)
39 #define FPS_RAISE_UNFOCUSED_DECOR_CLICK(fp,x) \
40 	((fp).do_raise_unfocused_click.decor = !!(x))
41 #define FP_DO_RAISE_FOCUSED_ICON_CLICK(fp) \
42 	((fp).do_raise_focused_click.icon)
43 #define FPS_RAISE_FOCUSED_ICON_CLICK(fp,x) \
44 	((fp).do_raise_focused_click.icon = !!(x))
45 #define FP_DO_RAISE_UNFOCUSED_ICON_CLICK(fp) \
46 	((fp).do_raise_unfocused_click.icon)
47 #define FPS_RAISE_UNFOCUSED_ICON_CLICK(fp,x) \
48 	((fp).do_raise_unfocused_click.icon = !!(x))
49 #define FP_DO_FOCUS_ENTER(fp) \
50 	((fp).do_focus_enter)
51 #define FPS_FOCUS_ENTER(fp,x) \
52 	((fp).do_focus_enter = !!(x))
53 #define FP_DO_UNFOCUS_LEAVE(fp) \
54 	((fp).do_unfocus_leave)
55 #define FPS_UNFOCUS_LEAVE(fp,x) \
56 	((fp).do_unfocus_leave = !!(x))
57 #define FP_DO_FOCUS_CLICK_CLIENT(fp) \
58 	((fp).do_focus_click.client)
59 #define FPS_FOCUS_CLICK_CLIENT(fp,x) \
60 	((fp).do_focus_click.client = !!(x))
61 #define FP_DO_FOCUS_CLICK_DECOR(fp) \
62 	((fp).do_focus_click.decor)
63 #define FPS_FOCUS_CLICK_DECOR(fp,x) \
64 	((fp).do_focus_click.decor = !!(x))
65 #define FP_DO_FOCUS_CLICK_ICON(fp) \
66 	((fp).do_focus_click.icon)
67 #define FPS_FOCUS_CLICK_ICON(fp,x) \
68 	((fp).do_focus_click.icon = !!(x))
69 #define FP_DO_FOCUS_BY_PROGRAM(fp) \
70 	((fp).do_focus_by_program)
71 #define FPS_FOCUS_BY_PROGRAM(fp,x) \
72 	((fp).do_focus_by_program = !!(x))
73 #define FP_DO_FOCUS_BY_FUNCTION(fp) \
74 	((fp).do_focus_by_function)
75 #define FPS_FOCUS_BY_FUNCTION(fp,x) \
76 	((fp).do_focus_by_function = !!(x))
77 #define FP_DO_WARP_POINTER_ON_FOCUS_FUNC(fp) \
78 	((fp).do_warp_pointer_on_focus_func)
79 #define FPS_WARP_POINTER_ON_FOCUS_FUNC(fp,x) \
80 	((fp).do_warp_pointer_on_focus_func = !!(x))
81 #define FP_IS_LENIENT(fp) \
82 	((fp).is_lenient)
83 #define FPS_LENIENT(fp,x) \
84 	((fp).is_lenient = !!(x))
85 #define FP_USE_MOUSE_BUTTONS(fp) \
86 	((fp).use_mouse_buttons)
87 #define FPS_MOUSE_BUTTONS(fp,x) \
88 	((fp).use_mouse_buttons = (x))
89 #define FP_USE_MODIFIERS(fp) \
90 	((fp).use_modifiers)
91 #define FPS_MODIFIERS(fp,x) \
92 	((fp).use_modifiers = (x))
93 #define FP_DO_PASS_FOCUS_CLICK(fp) \
94 	((fp).do_pass_focus_click)
95 #define FPS_PASS_FOCUS_CLICK(fp,x) \
96 	((fp).do_pass_focus_click = !!(x))
97 #define FP_DO_PASS_RAISE_CLICK(fp) \
98 	((fp).do_pass_raise_click)
99 #define FPS_PASS_RAISE_CLICK(fp,x) \
100 	((fp).do_pass_raise_click = !!(x))
101 #define FP_DO_IGNORE_FOCUS_CLICK_MOTION(fp) \
102 	((fp).do_ignore_focus_click_motion)
103 #define FPS_IGNORE_FOCUS_CLICK_MOTION(fp,x) \
104 	((fp).do_ignore_focus_click_motion = !!(x))
105 #define FP_DO_IGNORE_RAISE_CLICK_MOTION(fp) \
106 	((fp).do_ignore_raise_click_motion)
107 #define FPS_IGNORE_RAISE_CLICK_MOTION(fp,x) \
108 	((fp).do_ignore_raise_click_motion = !!(x))
109 #define FP_DO_ALLOW_FUNC_FOCUS_CLICK(fp) \
110 	((fp).do_allow_func_focus_click)
111 #define FPS_ALLOW_FUNC_FOCUS_CLICK(fp,x) \
112 	((fp).do_allow_func_focus_click = !!(x))
113 #define FP_DO_ALLOW_FUNC_RAISE_CLICK(fp) \
114 	((fp).do_allow_func_raise_click)
115 #define FPS_ALLOW_FUNC_RAISE_CLICK(fp,x) \
116 	((fp).do_allow_func_raise_click = !!(x))
117 #define FP_DO_GRAB_FOCUS(fp) \
118 	((fp).do_open_grabs_focus)
119 #define FPS_GRAB_FOCUS(fp,x) \
120 	((fp).do_open_grabs_focus = !!(x))
121 #define FP_DO_GRAB_FOCUS_TRANSIENT(fp) \
122 	((fp).do_open_grabs_focus_transient)
123 #define FPS_GRAB_FOCUS_TRANSIENT(fp,x) \
124 	((fp).do_open_grabs_focus_transient = !!(x))
125 #define FP_DO_OVERRIDE_GRAB_FOCUS(fp) \
126 	((fp).do_override_grab_focus)
127 #define FPS_OVERRIDE_GRAB_FOCUS(fp,x) \
128 	((fp).do_override_grab_focus = !!(x))
129 #define FP_DO_RELEASE_FOCUS(fp) \
130 	((fp).do_close_releases_focus)
131 #define FPS_RELEASE_FOCUS(fp,x) \
132 	((fp).do_close_releases_focus = !!(x))
133 #define FP_DO_RELEASE_FOCUS_TRANSIENT(fp) \
134 	((fp).do_close_releases_focus_transient)
135 #define FPS_RELEASE_FOCUS_TRANSIENT(fp,x) \
136 	((fp).do_close_releases_focus_transient = !!(x))
137 #define FP_DO_OVERRIDE_RELEASE_FOCUS(fp) \
138 	((fp).do_override_release_focus)
139 #define FPS_OVERRIDE_RELEASE_FOCUS(fp,x) \
140 	((fp).do_override_release_focus = !!(x))
141 #define FP_DO_SORT_WINDOWLIST_BY(fp) \
142 	((fp).do_sort_windowlist_by)
143 #define FPS_SORT_WINDOWLIST_BY(fp,x) \
144 	((fp).do_sort_windowlist_by = !!(x))
145 
146 /* ---------------------------- type definitions --------------------------- */
147 
148 typedef enum
149 {
150 	FPOL_SORT_WL_BY_FOCUS = 0,
151 	FPOL_SORT_WL_BY_OPEN = 1
152 } fpol_sort_windowlist_t;
153 
154 typedef enum
155 {
156 	FOCUS_SET_BY_CLICK_CLIENT,
157 	FOCUS_SET_BY_CLICK_DECOR,
158 	FOCUS_SET_BY_CLICK_ICON,
159 	FOCUS_SET_BY_ENTER,
160 	FOCUS_SET_BY_PROGRAM,
161 	FOCUS_SET_BY_FUNCTION,
162 	/* used internally to restore the focus after certain actions */
163 	FOCUS_SET_FORCE
164 } fpol_set_focus_by_t;
165 
166 typedef struct
167 {
168 	unsigned client : 1;
169 	unsigned decor : 1;
170 	unsigned icon : 1;
171 } fpol_context_t;
172 
173 typedef struct
174 {
175 	/* raising the window */
176 	fpol_context_t do_raise_focused_click;
177 	fpol_context_t do_raise_unfocused_click;
178 	/* focus transition */
179 	fpol_context_t do_focus_click;
180 	unsigned do_focus_enter : 1;
181 	unsigned do_unfocus_leave : 1;
182 	unsigned do_focus_by_program : 1;
183 	unsigned do_focus_by_function : 1;
184 	unsigned do_warp_pointer_on_focus_func : 1;
185 	/* application focus model */
186 	unsigned is_lenient : 1;
187 	/* click configuration */
188 	unsigned use_mouse_buttons : NUMBER_OF_EXTENDED_MOUSE_BUTTONS;
189 	unsigned use_modifiers : 8;
190 	/* recycling of focus and raise clicks */
191 	unsigned do_pass_focus_click : 1;
192 	unsigned do_pass_raise_click : 1;
193 	unsigned do_ignore_focus_click_motion : 1;
194 	unsigned do_ignore_raise_click_motion : 1;
195 	unsigned do_allow_func_focus_click : 1;
196 	unsigned do_allow_func_raise_click : 1;
197 	/* keeping track of the focus */
198 	unsigned do_open_grabs_focus : 1;
199 	unsigned do_open_grabs_focus_transient : 1;
200 	unsigned do_override_grab_focus : 1;
201 	unsigned do_close_releases_focus : 1;
202 	unsigned do_close_releases_focus_transient : 1;
203 	unsigned do_override_release_focus : 1;
204 	unsigned do_sort_windowlist_by : 1;
205 } focus_policy_t;
206 
207 /* ---------------------------- forward declarations ----------------------- */
208 
209 /* ---------------------------- exported variables (globals) --------------- */
210 
211 /* ---------------------------- interface functions ------------------------ */
212 
213 void fpol_init_default_fp(
214 	focus_policy_t *fp);
215 int fpol_query_allow_set_focus(
216 	focus_policy_t *fpol, fpol_set_focus_by_t set_by_mode);
217 int fpol_query_allow_user_focus(
218 	focus_policy_t *fpol);
219 int fpol_is_policy_changed(
220 	focus_policy_t *fpol);
221 
222 #endif /* FVWM_FOCUS_POLICY_H */
223