Add reminder to investigate recursive commands for 2.6
[fvwm.git] / fvwm / windowshade.c
blob3c58a9120776e818c48db2007ac50ae273487eec
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 /* ---------------------------- included header files ---------------------- */
19 #include "config.h"
21 #include <stdio.h>
23 #include "libs/fvwmlib.h"
24 #include "libs/Parse.h"
25 #include "libs/Strings.h"
26 #include "fvwm.h"
27 #include "externs.h"
28 #include "execcontext.h"
29 #include "misc.h"
30 #include "commands.h"
31 #include "screen.h"
32 #include "module_list.h"
33 #include "module_interface.h"
34 #include "geometry.h"
35 #include "gnome.h"
36 #include "ewmh.h"
37 #include "borders.h"
38 #include "frame.h"
39 #include "focus.h"
41 /* ---------------------------- local definitions -------------------------- */
43 /* ---------------------------- local macros ------------------------------- */
45 /* ---------------------------- imports ------------------------------------ */
47 /* ---------------------------- included code files ------------------------ */
49 /* ---------------------------- local types -------------------------------- */
51 /* ---------------------------- forward declarations ----------------------- */
53 /* ---------------------------- local variables ---------------------------- */
55 /* ---------------------------- exported variables (globals) --------------- */
57 /* ---------------------------- local functions ---------------------------- */
59 /* ---------------------------- interface functions ------------------------ */
61 /* ---------------------------- builtin commands --------------------------- */
65 * WindowShade -- shades or unshades a window (veliaa@rpi.edu)
67 * Args: 1 -- shade, 2 -- unshade No Arg: toggle
70 void CMD_WindowShade(F_CMD_ARGS)
72 direction_t shade_dir;
73 int toggle;
74 frame_move_resize_mode resize_mode;
75 rectangle start_g;
76 rectangle end_g;
77 frame_move_resize_args mr_args;
78 char *token;
79 char *naction;
80 Bool do_force_shading;
81 Bool has_dir;
82 FvwmWindow * const fw = exc->w.fw;
84 if (IS_ICONIFIED(fw) || IS_EWMH_FULLSCREEN(fw))
86 return;
88 token = PeekToken(action, &naction);
89 if (StrEquals("shadeagain", token))
91 do_force_shading = True;
92 action = naction;
93 token = PeekToken(action, &naction);
95 else
97 do_force_shading = False;
99 /* parse arguments */
100 if (StrEquals("Last", token))
102 /* last given instead of a direction will make
103 * fvwm to reuse the last used shading direction.
104 * A new, nevershaded window will have
105 * USED_TITLE_DIR_FOR_SHADING set (in add_window.c:
106 * setup_window_structure)
108 action = naction;
109 if (!USED_TITLE_DIR_FOR_SHADING(fw))
111 shade_dir = SHADED_DIR(fw);
113 else
115 shade_dir = DIR_NONE;
118 else
120 /* parse normal direction if last was not given */
121 shade_dir = gravity_parse_dir_argument(action, NULL, -1);
124 if (shade_dir >= 0 && shade_dir <= DIR_MASK)
126 has_dir = True;
127 toggle = (!IS_SHADED(fw) || SHADED_DIR(fw) != shade_dir);
129 else
131 has_dir = False;
132 toggle = ParseToggleArgument(action, NULL, -1, 0);
133 if (toggle == -1 &&
134 GetIntegerArguments(action, NULL, &toggle, 1) > 0)
136 if (toggle == 1)
138 toggle = 1;
140 else if (toggle == 2)
142 toggle = 0;
144 else
146 toggle = -1;
149 if (toggle == -1)
151 toggle = !(IS_SHADED(fw));
153 if (!IS_SHADED(fw) && toggle == 1)
155 shade_dir = GET_TITLE_DIR(fw);
157 else if (IS_SHADED(fw) && toggle == 0)
159 shade_dir = SHADED_DIR(fw);
161 else
163 shade_dir = -1;
166 if (!IS_SHADED(fw) && toggle == 0)
168 /* nothing to do */
169 return;
171 if (IS_SHADED(fw) && toggle == 1)
173 if (has_dir == False)
175 /* nothing to do */
176 return;
178 else if (do_force_shading == False)
180 toggle = 0;
182 else if (shade_dir == SHADED_DIR(fw))
184 return;
188 if (toggle == 1)
190 SET_USED_TITLE_DIR_FOR_SHADING(fw, !has_dir);
192 /* draw the animation */
193 start_g = fw->g.frame;
194 get_unshaded_geometry(fw, &end_g);
195 if (toggle == 1)
197 get_shaded_geometry_with_dir(fw, &end_g, &end_g, shade_dir);
199 resize_mode = (DO_SHRINK_WINDOWSHADE(fw)) ?
200 FRAME_MR_SHRINK : FRAME_MR_SCROLL;
201 mr_args = frame_create_move_resize_args(
202 fw, resize_mode, &start_g, &end_g, fw->shade_anim_steps,
203 shade_dir);
204 frame_move_resize(fw, mr_args);
205 /* Set the new shade value before destroying the args but after the
206 * animation. */
207 SET_SHADED(fw, toggle);
208 if (toggle == 1)
210 SET_SHADED_DIR(fw, shade_dir);
212 frame_free_move_resize_args(fw, mr_args);
213 border_draw_decorations(
214 fw, PART_TITLEBAR, (fw == get_focus_window()) ? True : False,
215 0, CLEAR_BUTTONS, NULL, NULL);
216 /* update hints and inform modules */
217 BroadcastConfig(M_CONFIGURE_WINDOW, fw);
218 BroadcastPacket(
219 (toggle == 1) ? M_WINDOWSHADE : M_DEWINDOWSHADE, 3,
220 (long)FW_W(fw), (long)FW_W_FRAME(fw), (unsigned long)fw);
221 FlushAllMessageQueues();
222 XFlush(dpy);
223 EWMH_SetWMState(fw, False);
224 GNOME_SetHints(fw);
225 GNOME_SetWinArea(fw);
227 return;
230 /* set the number or size of shade animation steps, N => steps, Np => pixels */
231 void CMD_WindowShadeAnimate(F_CMD_ARGS)
233 char *buf;
235 if (!action)
237 action = "";
239 fvwm_msg(
240 ERR, "CMD_WindowShadeAnimate",
241 "The WindowShadeAnimate command is obsolete. "
242 "Please use 'Style * WindowShadeSteps %s' instead.", action);
243 buf = safemalloc(strlen(action) + 32);
244 sprintf(buf, "* WindowShadeSteps %s", action);
245 action = buf;
246 CMD_Style(F_PASS_ARGS);
247 free(buf);
249 return;