Subject: FVWM: Per-Window Styles

From: Craig Milo Rogers <[email-masked]>
Date: Sun, 16 Mar 2003 17:02:54 -0800

Today, out of the blue, I decided that I wanted to apply
styles to specific windows (and not to window names, classes, or
resources, any of which may the same for multiple windows) on my FVWM
desktop.  I noticed that a request to do this was already pending in
the FVWM bug site(id #568), but seeing that it's been over 2 years
since the enhancement request was queued in the bug tracking system, I
decided to look into it for fun.

	I made the following changes to "fvwm/style.c" in fvwm-2.5.6:

*** style.c.orig        2003-03-16 15:48:15.000000000 -0800
--- style.c     2003-03-16 15:51:17.000000000 -0800
***************
*** 4033,4038 ****
--- 4033,4042 ----
        /* clear callers return area */
        memset(styles, 0, sizeof(window_style));
  
+       /* Get the window ID: */
+       char winId[20];
+       sprintf(winId, "0x%x", (unsigned int)FW_W(fw));
+ 
        /* look thru all styles in order defined. */
        for (nptr = all_styles; nptr != NULL; nptr = SGET_NEXT_STYLE(*nptr))
        {
***************
*** 4051,4056 ****
--- 4055,4063 ----
                {
                        merge_styles(styles, nptr, False);
                }
+               else if (strcmp(SGET_NAME(*nptr), winId) == 0) {
+                       merge_styles(styles, nptr, False);
+               }
        }
        if (!DO_IGNORE_GNOME_HINTS(fw))
        {
***************
*** 4800,4808 ****
        for (t = Scr.FvwmRoot.next; t != NULL && t != &Scr.FvwmRoot;
             t = t->next)
        {
                if (matchWildcards(name, t->class.res_class) == TRUE ||
                    matchWildcards(name, t->class.res_name) == TRUE ||
!                   matchWildcards(name, t->name.name) == TRUE)
                {
                        SET_STYLE_DELETED(t, 1);
                        Scr.flags.do_need_window_update = 1;
--- 4807,4820 ----
        for (t = Scr.FvwmRoot.next; t != NULL && t != &Scr.FvwmRoot;
             t = t->next)
        {
+               /* Get the window ID: */
+               char winId[20];
+               sprintf(winId, "0x%x", (unsigned int)FW_W(t));
+ 
                if (matchWildcards(name, t->class.res_class) == TRUE ||
                    matchWildcards(name, t->class.res_name) == TRUE ||
!                   matchWildcards(name, t->name.name) == TRUE ||
!                   strcmp(name, winId) == 0)
                {
                        SET_STYLE_DELETED(t, 1);
                        Scr.flags.do_need_window_update = 1;

	This implements per-window styles, except for the the
possibility of the reuse of window IDs.  I apologize for the hokey
20-character fixed buffers; consider this a proof-of-concept
implementation, not rugged code.

	Here's a sample menu that applies per-window styles:

AddToMenu "WindowOps" "WindowOps" Title
+              "Focus Policy"        Popup FocusPolicyOps

AddToMenu "FocusPolicyOps" "Focus Policy" Title
+              "Click to Focus"      Current Style $[w.id] ClickToFocus
+              "Focus Follows Mouse" Current Style $[w.id] FocusFollowsMouse
+              "Never Focus"         Current Style $[w.id] NeverFocus
+              "Sloppy Focus"        Current Style $[w.id] SloppyFocus

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

---

From: Mikhael Goikhman <[email-masked]>
Date: Fri, 21 Mar 2003 18:08:54 +0000

> decided to look into it for fun.

I am not against applying this patch (because it is small), but the
problems with it are obvious:

  1) We already have ambiguity, because we mix window names, resources
     and classes. This patch adds additional ambiguity.

  2) There is no any indication that this is a window id, so expect bugs.
     Do a simple experiment, create a window, apply a style to its id,
     close a window, open a completely another window, the old style is
     applied to it, because it has the same window id. I would think
     the styles working on window ids should expire at the moment a
     window is closed.

The proper solution is, of course, to have named patterns, with a syntax
similar to:

  Style (Class "XTerm", Name "user@host") ...
  Current (Class XTerm) Style (Id $[w.id]) MiniIcon ...
  Key S A CM  Pick Style (Id $[w.id]) SloppyFocus

This is still in todo list.

P.S. Please always send patches in "diff -u" format only.

Regards,
Mikhael.