Subject: Titlebar text templates

From: Arne Georg Gleditsch <[email-masked]>
Date: Wed, 03 Mar 2004 10:02:20 +0100

Hi,

I like to enumerate my windows so that I can quickly jump to any one
of them using hotkeys.  I also like to keep every window's enumerated
id in the title bar for easy visual access.  To this end, I'd like to
submit the follwing patch.  It adds a command "WindowNameSuffix",
which given a window id and text string will set up this text string
as a fixed suffix that will always appear in the titlebar of the given
window.

I'm not sure if this ought to be generalized more; i.e let the given
string be a sprintf pattern where %s is expanded to the application-
set window title or something.  I'll be happy to make alterations that
make the patch more acceptable.

							Arne.

(The patch is against 2.5.8, but applies to 2.5.9 as well with only a
minimum of fuzz.)
diff -ru fvwm-2.5.8/fvwm/add_window.c fvwm-2.5.8-new/fvwm/add_window.c
--- fvwm-2.5.8/fvwm/add_window.c	Fri Oct 24 18:37:08 2003
+++ fvwm-2.5.8-new/fvwm/add_window.c	Wed Nov 12 10:33:35 2003
@@ -1521,6 +1521,17 @@
 		ext_name = name;
 	}
 
+	if (fw->name_suffix) {
+	    char *suf_name;
+	    len = strlen(ext_name) + strlen(fw->name_suffix) + 1;
+	    suf_name = (char *)safemalloc(len);
+	    strcpy(suf_name, ext_name);
+	    strcat(suf_name, fw->name_suffix);
+	    if (ext_name != name)
+		free(ext_name);
+	    ext_name = suf_name;
+	}
+
 	if (is_icon)
 	{
 		fw->visible_icon_name = ext_name;
diff -ru fvwm-2.5.8/fvwm/commands.h fvwm-2.5.8-new/fvwm/commands.h
--- fvwm-2.5.8/fvwm/commands.h	Wed Jul 16 11:10:40 2003
+++ fvwm-2.5.8-new/fvwm/commands.h	Wed Nov 12 10:34:41 2003
@@ -183,6 +183,7 @@
 	F_UPDATE_DECOR,
 	F_WARP,
 	F_WINDOWID,
+	F_WINDOWNAMESUFFIX,
 	F_WINDOW_SHADE,
 	F_WINDOW_STYLE,
 
@@ -373,6 +374,7 @@
 P(WindowFont);
 P(WindowId);
 P(WindowList);
+P(WindowNameSuffix);
 P(WindowShade);
 P(WindowShadeAnimate);
 P(WindowStyle);
diff -ru fvwm-2.5.8/fvwm/functable.c fvwm-2.5.8-new/fvwm/functable.c
--- fvwm-2.5.8/fvwm/functable.c	Wed Jul 16 11:10:40 2003
+++ fvwm-2.5.8-new/fvwm/functable.c	Wed Nov 12 10:33:35 2003
@@ -617,6 +617,10 @@
 	CMD_ENT("windowlist", CMD_WindowList, F_WINDOWLIST, 0, 0),
 	/* - Display the window list as a menu to select a window */
 
+	CMD_ENT("windownamesuffix", CMD_WindowNameSuffix, F_WINDOWNAMESUFFIX,
+		FUNC_NEEDS_WINDOW, CRS_SELECT),
+	/* - Set name suffix for window */
+
 	CMD_ENT("windowshade", CMD_WindowShade, F_WINDOW_SHADE,
 		FUNC_NEEDS_WINDOW, CRS_SELECT),
 	/* - Shade/unshade a window */
diff -ru fvwm-2.5.8/fvwm/fvwm.h fvwm-2.5.8-new/fvwm/fvwm.h
--- fvwm-2.5.8/fvwm/fvwm.h	Wed Sep 24 11:15:20 2003
+++ fvwm-2.5.8-new/fvwm/fvwm.h	Wed Nov 12 10:33:35 2003
@@ -618,6 +618,7 @@
 	char *visible_icon_name;
 	int name_count;
 	int icon_name_count;
+        char *name_suffix;
 	/* next fvwm window */
 	struct FvwmWindow *next;
 	/* prev fvwm window */
diff -ru fvwm-2.5.8/fvwm/update.c fvwm-2.5.8-new/fvwm/update.c
--- fvwm-2.5.8/fvwm/update.c	Thu Aug 14 10:48:20 2003
+++ fvwm-2.5.8-new/fvwm/update.c	Wed Nov 12 10:33:35 2003
@@ -752,3 +752,33 @@
 
 	return;
 }
+
+void CMD_WindowNameSuffix(F_CMD_ARGS)
+{
+	char *name;
+	FvwmWindow *fw = exc->w.fw;
+	window_style style;
+        update_win flags;
+
+
+	/* parse style name */
+	name = PeekToken(action, &action);
+
+	/* in case there was no argument! */
+	if (name == NULL)
+		return;
+
+	if (fw->name_suffix)
+		free(fw->name_suffix);
+
+	fw->name_suffix = safestrdup(name);
+	/* setup_visible_name(fw, False); */
+
+	lookup_style(fw, &style);
+        memset(&flags, 0, sizeof(flags));
+        flags.do_update_visible_window_name = True;
+	flags.do_redecorate = True;
+        apply_window_updates(fw, &flags, &style, get_focus_window());
+
+	return;
+}

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 3 Mar 2004 10:23:40 +0000

> make the patch more acceptable.

I think WindowNameSuffix is not a good solution to the problem. We should
use existing window field visible_name for this and have a new command
like WindowNameFormat (just escape "$" if run under window context):

  WindowNameFormat "( $[w.name] )"

(or VisibleWindowNameFormat).

Regards,
Mikhael.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Arne Georg Gleditsch <[email-masked]>
Date: Wed, 03 Mar 2004 12:01:19 +0100

* Mikhael Goikhman
> (or VisibleWindowNameFormat).

I'm not sure I follow you.  The patch given hooks into the update path
for visible_name, and appends the fixed suffix where applicable.  If I
were to implement your proposal (which I like), I would do it much the
same way, calling expand_vars (?) at the same point in the update path
for visible_name instead of just appending a fixed string.  It's not
clear to me from your wording if you would like to se visible_name
itself be the format string, and expand it when used, or if an
implementation as the above, where visible_name is the expanded
string, would be acceptable.

							Arne.

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 3 Mar 2004 13:03:48 +0000

On 03 Mar 2004 12:01:19 +0100, Arne Georg Gleditsch wrote:
> for visible_name instead of just appending a fixed string.
> It's not clear to me from your wording if you would like to se
> visible_name itself be the format string, and expand it when used, or
> if an implementation as the above, where visible_name is the expanded

With my suggestion you don't need to modify FvwmWindow structure.

The suggested WindowNameFormat may be either a global command or a style
option, but not a window context command like yours. Then this format
string would be stored either globally or in style structure.

visible_name contains the final name after expansion just like now.

There are other problems with your patch, the command without parameter
should remove the string (the default is to use name for visible_name).
Your patch also leaks memory, i.e. it does not free the string when a
window is closed, AFAICS. (With my suggestion there is nothing to free.)

Regards,
Mikhael.

---

From: Arne Georg Gleditsch <[email-masked]>
Date: Wed, 03 Mar 2004 19:44:54 +0100

* Mikhael Goikhman
> visible_name contains the final name after expansion just like now.

Hm.  Perhaps I've been unclear.  I use this functionality to assign
every window a different title suffix, where the contents of this
suffix indicate which hotkey will bring focus to the window in
question.  The hotkeys are assigned from a arbitrary range; at the
moment I'm using the letters A..Z, and Win-A will bring focus to the
window marked with the suffix [A].  This hotkey/enumerated id/suffix
_is_ a window context property, and I can't see how to make the final
visible_name contain this without storing it in the window context
somehow.

(Of course, the window id <-> hotkey mapping exists in the internal
state of the module providing this functionality as well, but as far
as I'm aware you can't do module callouts in string expansions.  If
you can, then that would be a way to do this without adding stuff to
the window context.)

> There are other problems with your patch, [..]

No doubt there are, and I'll be happy to have a go at ironing them out
if/once the overall approach is deemed acceptable.

							Arne.

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 3 Mar 2004 19:27:39 +0000

> visible_name contain this without storing it in the window context

I think, this is pretty uncommon situation, to give unique name format
to every window. And you will still need additional work to manage and
assign unique latter identifiers. You use a separate module for this.
I can see why you need a window operation here rather then style.

Anyway, then you should go with a Style option and use WindowStyle for
your purpose. I don't think that direct modification of window structure
is justified here. For example, I may imagine myself using this window
name format feature for some windows, but automatically. i.e. I need a
Style option, not just a window operation.

And the attitude generally is to move every window operation to styles.

Regards,
Mikhael.

---

From: Dan Espen <[email-masked]>
Date: Wed, 03 Mar 2004 14:39:09 -0500

Mikhael Goikhman <[email-masked]> writes:
> to every window.

I think it is very common.
That's what the -name argument to xterm/rxvt is for.

To get the above behavior, I use a Perl/Gtk GUI to manage my list of
systems that I normally login to and assign the hotkeys.

-- 
Dan Espen                           E-mail: [email-masked]

---

From: Arne Georg Gleditsch <[email-masked]>
Date: Thu, 04 Mar 2004 22:40:38 +0100

* Mikhael Goikhman
> your purpose.

Ah, now I follow.  My mistake, I didn't realize styles could be set on
a per-window basis.  I'll see if I can't make something work for my
setup using WindowStyle.

							Arne.

---

From: Arne Georg Gleditsch <[email-masked]>
Date: Sat, 13 Mar 2004 23:15:10 +0100

* Arne Georg Gleditsch
> a per-window basis.  I'll see if I can't make something work for my

Could something like the appended be appropriate?

							Arne.
diff -ru fvwm-2.5.9.orig/fvwm/add_window.c fvwm-2.5.9/fvwm/add_window.c
--- fvwm-2.5.9.orig/fvwm/add_window.c	2004-02-19 10:36:01.000000000 +0100
+++ fvwm-2.5.9/fvwm/add_window.c	2004-03-13 23:08:10.000000000 +0100
@@ -84,6 +84,7 @@
 #include "frame.h"
 #include "colormaps.h"
 #include "decorations.h"
+#include "expand.h"
 
 /* ---------------------------- local definitions -------------------------- */
 
@@ -1461,6 +1462,8 @@
 	char *name;
 	int count;
 	int len;
+	window_style style;
+	char *template;
 
 	if (fw == NULL)
 	{
@@ -1521,6 +1524,32 @@
 		ext_name = name;
 	}
 
+	lookup_style(fw, &style);
+	template = SGET_VISIBLE_WNAME_FORMAT(style);
+
+	if (template != NULL)
+	{
+		char *arguments[11];
+		cond_rc_t dummy_rc;
+		const exec_context_t *exc;
+		exec_context_changes_t ecc;
+
+		memset(&arguments, 0, sizeof(arguments));
+		condrc_init(&dummy_rc);
+
+		ecc.type = EXCT_NULL;
+		ecc.w.fw = fw;
+		exc = exc_create_context(&ecc, ECC_TYPE | ECC_FW);
+
+		if (ext_name != name)
+			free(ext_name);
+
+		ext_name = expand_vars(template, arguments,
+				       False, False, &dummy_rc, exc);
+
+		exc_destroy_context(exc);
+	}
+	
 	if (is_icon)
 	{
 		fw->visible_icon_name = ext_name;
diff -ru fvwm-2.5.9.orig/fvwm/fvwm.h fvwm-2.5.9/fvwm/fvwm.h
--- fvwm-2.5.9.orig/fvwm/fvwm.h	2004-02-16 14:45:59.000000000 +0100
+++ fvwm-2.5.9/fvwm/fvwm.h	2004-03-13 22:58:06.000000000 +0100
@@ -530,6 +530,7 @@
 	unsigned recapture_honors_starts_on_page : 1;
 	unsigned has_placement_penalty : 1;
 	unsigned has_placement_percentage_penalty : 1;
+	unsigned has_visible_wname_format : 1;
 } style_flags;
 
 typedef struct
@@ -594,6 +595,7 @@
 	int start_screen;
 	int max_window_width;
 	int max_window_height;
+	char *visible_window_name_format;
 	int shade_anim_steps;
 	icon_boxes *icon_boxes;
 	float norm_placement_penalty;
diff -ru fvwm-2.5.9.orig/fvwm/style.c fvwm-2.5.9/fvwm/style.c
--- fvwm-2.5.9.orig/fvwm/style.c	2004-02-16 14:45:59.000000000 +0100
+++ fvwm-2.5.9/fvwm/style.c	2004-03-13 23:01:31.000000000 +0100
@@ -613,6 +613,23 @@
 			*merged_style,
 			SGET_75_PLACEMENT_PERCENTAGE_PENALTY(*add_style));
 	}
+	if (add_style->flag_mask.has_visible_wname_format)
+	{
+		if (do_free_src_and_alloc_copy)
+		{
+			SAFEFREE(SGET_VISIBLE_WNAME_FORMAT(*merged_style));
+
+			SSET_VISIBLE_WNAME_FORMAT(
+				*merged_style, (SGET_VISIBLE_WNAME_FORMAT(*add_style)) ?
+				safestrdup(SGET_VISIBLE_WNAME_FORMAT(*add_style)) : NULL);
+		}
+		else
+		{
+			SSET_VISIBLE_WNAME_FORMAT(
+				*merged_style, SGET_VISIBLE_WNAME_FORMAT(*add_style));
+		}
+	}
+
 	/* merge the style flags */
 
 	/*** ATTENTION:
@@ -3853,6 +3870,15 @@
 			S_SET_IS_PSIZE_FIXED(SCM(*ps), 1);
 			S_SET_IS_PSIZE_FIXED(SCC(*ps), 1);
 		}
+		else if (StrEquals(token, "VisibleWindowNameFormat"))
+		{
+			SAFEFREE(SGET_VISIBLE_WNAME_FORMAT(*ps));
+			GetNextToken(rest, &token);
+			SSET_VISIBLE_WNAME_FORMAT(*ps, token);
+			ps->flags.has_visible_wname_format = (token != NULL);
+			ps->flag_mask.has_visible_wname_format = 1;
+			ps->change_mask.has_visible_wname_format = 1;
+		}
 		else
 		{
 			found = False;
@@ -4613,6 +4639,13 @@
 		flags->do_update_cr_motion_method = True;
 	}
 
+	/* Visible window name format */
+	if (ret_style->change_mask.has_visible_wname_format)
+	{
+		flags->do_update_visible_window_name = True;
+		flags->do_redecorate = True;
+	}
+
 	return;
 }
 
diff -ru fvwm-2.5.9.orig/fvwm/style.h fvwm-2.5.9/fvwm/style.h
--- fvwm-2.5.9.orig/fvwm/style.h	2004-02-16 14:45:59.000000000 +0100
+++ fvwm-2.5.9/fvwm/style.h	2004-03-03 22:03:59.000000000 +0100
@@ -523,6 +523,10 @@
 	((s).max_window_height)
 #define SSET_MAX_WINDOW_HEIGHT(s,x) \
 	((s).max_window_height = (x))
+#define SGET_VISIBLE_WNAME_FORMAT(s) \
+	((s).visible_window_name_format)
+#define SSET_VISIBLE_WNAME_FORMAT(s,x) \
+	((s).visible_window_name_format = (x))
 #define SGET_WINDOW_SHADE_STEPS(s) \
 	((s).shade_anim_steps)
 #define SSET_WINDOW_SHADE_STEPS(s,x) \