2009/2/7 Dominik Vogt <[email protected]>:
> On Fri, Feb 06, 2009 at 09:35:30AM +0000, Thomas Adam wrote:
>> 2009/2/6 Dominik Vogt <[email protected]>:
>> > On Thu, Feb 05, 2009 at 10:55:16PM +0000, Thomas Adam wrote:
>> >> 2009/1/26 Thomas Adam <[email protected]>:
>> > I was planning to look into the patch on saturday evening (GMT) or
>> > maybe earlier.
>>
>> Ah, OK.  Please don't think I'm forcing your hand on this, I just
>> never know how much time to give between pauses before I give a gentle
>> reminder that I haven't completely abandoned an idea.  :)
>
> Neither have I.  I have attached a much smaller version of the
> patch that removes all code that replaces other styles and fixes a
> couple of small problems:
>
>  * Don't look up the style in events.c again but pass the string
>    back from AddWindow().  As a side effect, the command is only
>    executed when the window is mapped initially, not when it's
>    mapped because of deiconification.  Therefore I renamed the
>    style to InitialMapCommand (which may or may not be a good
>    idea).

Ok, that looks fine to me.  Note "initialMapCommand" is also fine with
me, as it really does just that.  Anything else would be shed-painting
if you ask me, and I have to deal with that enough at work.  :)

>  * Call execute_function_override_window() with the proper
>    execution context.

Please see the attached patch which also adds the relevant
documentation to go with this new style.  I've not bothered to update
AUTHORS or anything like that, you've thankfully saved me the trouble.

I recommend you consider comitting this to CVS, and perhaps release a
new unstable version?  I think there's enough material in there now to
warrant that.

-- Thomas Adam
Index: ChangeLog
===================================================================
RCS file: /home/cvs/fvwm/fvwm/ChangeLog,v
retrieving revision 1.3061
diff -u -r1.3061 ChangeLog
--- ChangeLog	30 Dec 2008 13:32:40 -0000	1.3061
+++ ChangeLog	7 Feb 2009 20:23:22 -0000
@@ -1,3 +1,11 @@
+2009-02-07  Dominik Vogt  <dominik(dot)vogt(at)gmx(dot)de>
+
+	* fvwm/events.c (HandleMapRequestKeepRaised):
+	* fvwm/add_window.c (AddWindow):
+	* fvwm/style.h:
+	* fvwm/style.c (style_parse_one_style_option):
+	add new style InitialMapCommand
+
 2008-12-29  Alexandre Julliard  <[email protected]>
 
 	* fvwm/ewmh_events.c (ewmh_WMStateMaxHoriz):
Index: NEWS
===================================================================
RCS file: /home/cvs/fvwm/fvwm/NEWS,v
retrieving revision 1.767
diff -u -r1.767 NEWS
--- NEWS	30 Dec 2008 13:32:40 -0000	1.767
+++ NEWS	7 Feb 2009 20:23:23 -0000
@@ -18,6 +18,9 @@
         ... is now honoured.  Useful with IndexedWindowName as a style
         option.
 
+   - New style InitialMapCommand allows to execute any command
+     when a window is mapped first.
+
 * Bug fixes:
 
    - Fixed compilation without XRender support.
Index: doc/commands/Style.xml
===================================================================
RCS file: /home/cvs/fvwm/fvwm/doc/commands/Style.xml,v
retrieving revision 1.9
diff -u -r1.9 Style.xml
--- doc/commands/Style.xml	19 Oct 2008 12:04:13 -0000	1.9
+++ doc/commands/Style.xml	7 Feb 2009 20:23:25 -0000
@@ -204,6 +204,7 @@
 <emphasis remap='I'>EdgeMoveDelay</emphasis>,
 <emphasis remap='I'>EdgeResizeDelay</emphasis>.
 <emphasis remap='I'>EdgeMoveResistance</emphasis>,
+<emphasis remap='I'>InitialMapCommand</emphasis>
 </para>
 
 
@@ -1360,8 +1361,18 @@
 opt="EdgeMoveResistance"/> can be used without any
 parameters.</para>
 
+<para>The option <fvwmopt cmd="Style" opt="InitialMapCommand"/> allows
+for any valid fvwm command or function to run when the window is 
+initially mapped by fvwm.  Example:</para>
+
+<programlisting>
+<fvwmref cmd="Style"/> MyWindow StartsOnPage 0 0, InitialMapCommand Iconify
+</programlisting>
 </section>
 
+<para>This would hence place the window called <emphasis>MyWindow</emphasis>
+on page 0 0 for the current desk, and immediately run the <fvwmref cmd="Iconify"/>
+command on that window.</para>
 
 
 <section id="window_manager_placement">
Index: fvwm/add_window.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/add_window.c,v
retrieving revision 1.398
diff -u -r1.398 add_window.c
--- fvwm/add_window.c	6 Aug 2008 17:55:28 -0000	1.398
+++ fvwm/add_window.c	7 Feb 2009 20:23:27 -0000
@@ -2125,8 +2125,8 @@
  *
  */
 FvwmWindow *AddWindow(
-	const exec_context_t *exc, FvwmWindow *ReuseWin,
-	initial_window_options_t * win_opts)
+	const char **ret_initial_map_command, const exec_context_t *exc,
+	FvwmWindow *ReuseWin, initial_window_options_t * win_opts)
 {
 	/* new fvwm window structure */
 	register FvwmWindow *fw;
@@ -2242,6 +2242,11 @@
 			fw->class.res_class);
 	}
 
+	/****** InitialMapCommand ******/
+	*ret_initial_map_command =
+		(style.flags.has_initial_map_command_string) ?
+		SGET_INITIAL_MAP_COMMAND_STRING(style) : NULL;
+
 	/****** state setup ******/
 	setup_icon_boxes(fw, &style);
 	SET_ICONIFIED(fw, 0);
Index: fvwm/add_window.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/add_window.h,v
retrieving revision 1.38
diff -u -r1.38 add_window.h
--- fvwm/add_window.h	17 Nov 2007 11:47:56 -0000	1.38
+++ fvwm/add_window.h	7 Feb 2009 20:23:27 -0000
@@ -58,8 +58,8 @@
 void FetchWmProtocols(
 	FvwmWindow *);
 FvwmWindow *AddWindow(
-	const exec_context_t *exc, FvwmWindow *ReuseWin,
-	initial_window_options_t * win_opts);
+	const char **ret_initial_map_command, const exec_context_t *exc,
+	FvwmWindow *ReuseWin, initial_window_options_t * win_opts);
 void GetWindowSizeHints(
 	FvwmWindow *);
 void free_window_names(
Index: fvwm/events.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/events.c,v
retrieving revision 1.561
diff -u -r1.561 events.c
--- fvwm/events.c	8 Aug 2008 11:44:01 -0000	1.561
+++ fvwm/events.c	7 Feb 2009 20:23:30 -0000
@@ -2878,7 +2878,9 @@
 	initial_window_options_t win_opts_bak;
 	Window ew;
 	FvwmWindow *fw;
+	const char *initial_map_command;
 
+	initial_map_command = NULL;
 	if (win_opts == NULL)
 	{
 		memset(&win_opts_bak, 0, sizeof(win_opts_bak));
@@ -2939,7 +2941,8 @@
 		}
 
 		/* Add decorations. */
-		fw = AddWindow(ea->exc, ReuseWin, win_opts);
+		fw = AddWindow(
+			&initial_map_command, ea->exc, ReuseWin, win_opts);
 		if (fw == AW_NO_WINDOW)
 		{
 			return;
@@ -3055,6 +3058,17 @@
 					(unsigned long)fw);
 #endif
 			}
+			/* TA:  20090125:  We *have* to handle
+			 * InitialMapCommand here and not in AddWindow() to
+			 * allow for correct timings when the window is truly
+			 * mapped. (c.f. things like Iconify.)
+			 */
+			if (initial_map_command != NULL)
+			{
+				execute_function_override_window(
+					NULL, ea->exc,
+					(char *)initial_map_command, 0, fw);
+			}
 			MyXUngrabServer(dpy);
 			break;
 
Index: fvwm/fvwm.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm.h,v
retrieving revision 1.259
diff -u -r1.259 fvwm.h
--- fvwm/fvwm.h	28 Nov 2008 23:29:27 -0000	1.259
+++ fvwm/fvwm.h	7 Feb 2009 20:23:30 -0000
@@ -594,6 +594,7 @@
 	unsigned has_placement_penalty : 1;
 	unsigned has_placement_percentage_penalty : 1;
 	unsigned has_placement_position_string : 1;
+	unsigned has_initial_map_command_string : 1;
 } style_flags;
 
 typedef struct style_id_t
@@ -679,6 +680,7 @@
 	pl_penalty_struct pl_penalty;
 	pl_percent_penalty_struct pl_percent_penalty;
 	char *pl_position_string;
+	char *initial_map_command_string;
 	style_flags flags;
 	style_flags flag_default;
 	style_flags flag_mask;
Index: fvwm/style.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/style.c,v
retrieving revision 1.260
diff -u -r1.260 style.c
--- fvwm/style.c	19 Oct 2008 12:04:13 -0000	1.260
+++ fvwm/style.c	7 Feb 2009 20:23:33 -0000
@@ -706,6 +706,13 @@
 			*merged_style,
 			strdup(SGET_PLACEMENT_POSITION_STRING(*add_style)));
 	}
+	if (add_style->flags.has_initial_map_command_string)
+	{
+		SAFEFREE(SGET_INITIAL_MAP_COMMAND_STRING(*merged_style));
+		SSET_INITIAL_MAP_COMMAND_STRING(
+			*merged_style,
+			strdup(SGET_INITIAL_MAP_COMMAND_STRING(*add_style)));
+	}
 	/* merge the style flags */
 
 	/*** ATTENTION:
@@ -761,6 +768,7 @@
 	SAFEFREE(SGET_MINI_ICON_NAME(*style));
 	remove_icon_boxes_from_style(style);
 	SAFEFREE(SGET_PLACEMENT_POSITION_STRING(*style));
+	SAFEFREE(SGET_INITIAL_MAP_COMMAND_STRING(*style));
 
 	return;
 }
@@ -2982,6 +2990,17 @@
 			S_SET_USE_INDEXED_ICON_NAME(SCM(*ps), 1);
 			S_SET_USE_INDEXED_ICON_NAME(SCC(*ps), 1);
 		}
+		else if (StrEquals(token, "InitialMapCommand"))
+		{
+			char *s;
+
+			s = (rest != NULL) ? strdup(rest) : NULL;
+			SSET_INITIAL_MAP_COMMAND_STRING(*ps, s);
+			ps->flags.has_initial_map_command_string = on;
+			ps->flag_mask.has_initial_map_command_string = on;
+			ps->change_mask.has_initial_map_command_string = 1;
+			rest = NULL; /* consume the entire string */
+		}
 		else
 		{
 			found = False;
Index: fvwm/style.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/style.h,v
retrieving revision 1.89
diff -u -r1.89 style.h
--- fvwm/style.h	17 Nov 2007 11:47:57 -0000	1.89
+++ fvwm/style.h	7 Feb 2009 20:23:34 -0000
@@ -657,6 +657,10 @@
 	((s).pl_position_string)
 #define SSET_PLACEMENT_POSITION_STRING(s,x)	\
 	((s).pl_position_string = (x))
+#define SGET_INITIAL_MAP_COMMAND_STRING(s) \
+	((s).initial_map_command_string)
+#define SSET_INITIAL_MAP_COMMAND_STRING(s,x)	\
+	((s).initial_map_command_string = (x))
 
 /* function prototypes */
 void lookup_style(FvwmWindow *fw, window_style *styles);

Reply via email to