Copy purify.fvwm2rc to /tmp - add instructions in README.
[fvwm.git] / fvwm / focus_policy.c
bloba7ff9c84d61d952eef6b160a7c278d5818856e9d
1 /* -*-c-*- */
2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 /* Note: focus_policy.[ch] is meant to manage structures of type focus_policy_t
18 * only. No code dealing with *any* external data types belongs in here! Put
19 * it in focus.[ch] instead. */
21 /* ---------------------------- included header files ---------------------- */
23 #include "config.h"
24 #include <stdio.h>
26 #include "focus_policy.h"
28 /* ---------------------------- local definitions -------------------------- */
30 /* ---------------------------- local macros ------------------------------- */
32 /* ---------------------------- imports ------------------------------------ */
34 /* ---------------------------- included code files ------------------------ */
36 /* ---------------------------- local types -------------------------------- */
38 /* ---------------------------- forward declarations ----------------------- */
40 /* ---------------------------- local variables ---------------------------- */
42 /* ---------------------------- exported variables (globals) --------------- */
44 /* ---------------------------- local functions ---------------------------- */
46 /* ---------------------------- interface functions ------------------------ */
48 /* Initialise focus policy to the system defaults */
49 void fpol_init_default_fp(focus_policy_t *fp)
51 memset(fp, 0, sizeof(focus_policy_t));
52 FPS_FOCUS_ENTER(*fp, DEF_FP_FOCUS_ENTER);
53 FPS_UNFOCUS_LEAVE(*fp, DEF_FP_UNFOCUS_LEAVE);
54 FPS_FOCUS_CLICK_CLIENT(*fp, DEF_FP_FOCUS_CLICK_CLIENT);
55 FPS_FOCUS_CLICK_DECOR(*fp, DEF_FP_FOCUS_CLICK_DECOR);
56 FPS_FOCUS_BY_PROGRAM(*fp, DEF_FP_FOCUS_BY_PROGRAM);
57 FPS_FOCUS_BY_FUNCTION(*fp, DEF_FP_FOCUS_BY_FUNCTION);
58 FPS_WARP_POINTER_ON_FOCUS_FUNC(*fp, DEF_FP_WARP_POINTER_ON_FOCUS_FUNC);
59 FPS_LENIENT(*fp, DEF_FP_LENIENT);
60 FPS_RAISE_FOCUSED_CLIENT_CLICK(*fp, DEF_FP_RAISE_FOCUSED_CLIENT_CLICK);
61 FPS_RAISE_UNFOCUSED_CLIENT_CLICK(
62 *fp, DEF_FP_RAISE_UNFOCUSED_CLIENT_CLICK);
63 FPS_RAISE_FOCUSED_DECOR_CLICK(
64 *fp, DEF_FP_RAISE_FOCUSED_DECOR_CLICK);
65 FPS_RAISE_UNFOCUSED_DECOR_CLICK(
66 *fp, DEF_FP_RAISE_UNFOCUSED_DECOR_CLICK);
67 FPS_RAISE_FOCUSED_ICON_CLICK(
68 *fp, DEF_FP_RAISE_FOCUSED_ICON_CLICK);
69 FPS_RAISE_UNFOCUSED_ICON_CLICK(
70 *fp, DEF_FP_RAISE_UNFOCUSED_ICON_CLICK);
71 FPS_MOUSE_BUTTONS(*fp, DEF_FP_MOUSE_BUTTONS);
72 FPS_MODIFIERS(*fp, DEF_FP_MODIFIERS);
73 FPS_PASS_FOCUS_CLICK(*fp, DEF_FP_PASS_FOCUS_CLICK);
74 FPS_PASS_RAISE_CLICK(*fp, DEF_FP_PASS_RAISE_CLICK);
75 FPS_IGNORE_FOCUS_CLICK_MOTION(*fp, DEF_FP_IGNORE_FOCUS_CLICK_MOTION);
76 FPS_IGNORE_RAISE_CLICK_MOTION(*fp, DEF_FP_IGNORE_RAISE_CLICK_MOTION);
77 FPS_ALLOW_FUNC_FOCUS_CLICK(*fp, DEF_FP_ALLOW_FUNC_FOCUS_CLICK);
78 FPS_ALLOW_FUNC_RAISE_CLICK(*fp, DEF_FP_ALLOW_FUNC_RAISE_CLICK);
79 FPS_GRAB_FOCUS(*fp, DEF_FP_GRAB_FOCUS);
80 FPS_GRAB_FOCUS_TRANSIENT(*fp, DEF_FP_GRAB_FOCUS_TRANSIENT);
81 FPS_OVERRIDE_GRAB_FOCUS(*fp, DEF_FP_OVERRIDE_GRAB_FOCUS);
82 FPS_RELEASE_FOCUS(*fp, DEF_FP_RELEASE_FOCUS);
83 FPS_RELEASE_FOCUS_TRANSIENT(*fp, DEF_FP_RELEASE_FOCUS_TRANSIENT);
84 FPS_OVERRIDE_RELEASE_FOCUS(*fp, DEF_FP_OVERRIDE_RELEASE_FOCUS);
85 FPS_SORT_WINDOWLIST_BY(*fp, DEF_FP_SORT_WINDOWLIST_BY);
87 return;
90 int fpol_query_allow_set_focus(
91 focus_policy_t *fpol, fpol_set_focus_by_t set_by_mode)
93 switch (set_by_mode)
95 case FOCUS_SET_BY_ENTER:
96 return FP_DO_FOCUS_ENTER(*fpol);
97 case FOCUS_SET_BY_CLICK_CLIENT:
98 return FP_DO_FOCUS_CLICK_CLIENT(*fpol);
99 case FOCUS_SET_BY_CLICK_DECOR:
100 return FP_DO_FOCUS_CLICK_DECOR(*fpol);
101 case FOCUS_SET_BY_CLICK_ICON:
102 return FP_DO_FOCUS_CLICK_ICON(*fpol);
103 case FOCUS_SET_BY_PROGRAM:
104 return FP_DO_FOCUS_BY_PROGRAM(*fpol);
105 case FOCUS_SET_BY_FUNCTION:
106 return FP_DO_FOCUS_BY_FUNCTION(*fpol);
107 case FOCUS_SET_FORCE:
108 return 1;
111 return 0;
114 int fpol_query_allow_user_focus(
115 focus_policy_t *fpol)
117 int flag = 0;
119 flag |= FP_DO_FOCUS_ENTER(*fpol);
120 flag |= FP_DO_FOCUS_CLICK_CLIENT(*fpol);
121 flag |= FP_DO_FOCUS_CLICK_DECOR(*fpol);
122 flag |= FP_DO_FOCUS_BY_FUNCTION(*fpol);
124 return !!flag;
127 int fpol_is_policy_changed(
128 focus_policy_t *fpol)
130 if (FP_DO_FOCUS_ENTER(*fpol))
132 return 1;
134 if (FP_DO_UNFOCUS_LEAVE(*fpol))
136 return 1;
138 if (FP_DO_FOCUS_CLICK_CLIENT(*fpol))
140 return 1;
142 if (FP_DO_FOCUS_CLICK_DECOR(*fpol))
144 return 1;
146 if (FP_DO_FOCUS_BY_PROGRAM(*fpol))
148 return 1;
150 if (FP_DO_FOCUS_BY_FUNCTION(*fpol))
152 return 1;
154 if (FP_IS_LENIENT(*fpol))
156 return 1;
158 if (FP_DO_RAISE_FOCUSED_CLIENT_CLICK(*fpol))
160 return 1;
162 if (FP_DO_RAISE_UNFOCUSED_CLIENT_CLICK(*fpol))
164 return 1;
166 if (FP_DO_RAISE_FOCUSED_DECOR_CLICK(*fpol))
168 return 1;
170 if (FP_DO_RAISE_UNFOCUSED_DECOR_CLICK(*fpol))
172 return 1;
174 if (FP_USE_MOUSE_BUTTONS(*fpol))
176 return 1;
178 if (FP_USE_MODIFIERS(*fpol))
180 return 1;
183 return 0;