On Mon, May 19, 2003 at 01:44:27PM +0200, Dominik Vogt wrote:
> Should the StyleById patch be applied before 2.6?  Please cast
> your votes here.
>

Seems that there is no conclusion here. It seems that there is two
votes for it (me and Mikhael) one vote against (Dominik) and one
unclear vote (Dan). So I ask for more votes and clarification
(Dan?). For that I send an other version of the patch (attached).
I've followed all the advice (I can follow) that I get in this
thread.  In particular, I've followed all the remarks (as I can) of
Dominik regarding the code. So, Dominik I even hope you revert your
vote (very little hope ...). Also: the cmds are named WindowStyle and
DestroyWindowStyle and act on the selected window and there is the
doc and some tests in purify.fvwm2rc.

Regards, Olivier

PS: What are the rules for the votes? 
Index: fvwm/add_window.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/add_window.c,v
retrieving revision 1.348
diff -u -r1.348 add_window.c
--- fvwm/add_window.c   27 May 2003 00:37:00 -0000      1.348
+++ fvwm/add_window.c   7 Jun 2003 17:13:26 -0000
@@ -3014,6 +3014,18 @@
                return;
        }
 
+       /* remove window style */
+       if (!IS_SCHEDULED_FOR_DESTROY(fw) && !DO_REUSE_DESTROYED(fw))
+       {
+               style_id_t s_id;
+
+               memset(&s_id, 0, sizeof(style_id_t));
+               SID_SET_WINDOW_ID(s_id, (XID)FW_W(fw));
+               SID_SET_HAS_WINDOW_ID(s_id, True);
+
+               style_destroy_style(s_id);
+       }
+
        /****** remove from window list ******/
        /* if the window is sheduled fro destroy the window has been already
         * removed from list */
Index: fvwm/commands.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/commands.h,v
retrieving revision 1.36
diff -u -r1.36 commands.h
--- fvwm/commands.h     3 Jan 2003 06:57:35 -0000       1.36
+++ fvwm/commands.h     7 Jun 2003 17:13:27 -0000
@@ -167,6 +167,7 @@
        F_DESTROY,
        F_DESTROY_DECOR,
        F_DESTROY_MOD,
+       F_DESTROY_WINDOW_STYLE,
        F_ECHO,
        F_FLIP_FOCUS,
        F_FOCUS,
@@ -194,6 +195,7 @@
        F_WARP,
        F_WINDOWID,
        F_WINDOW_SHADE,
+       F_WINDOW_STYLE,
 
        F_END_OF_LIST = 999,
 
@@ -260,6 +262,7 @@
 void CMD_DestroyMenuStyle(F_CMD_ARGS);
 void CMD_DestroyModuleConfig(F_CMD_ARGS);
 void CMD_DestroyStyle(F_CMD_ARGS);
+void CMD_DestroyWindowStyle(F_CMD_ARGS);
 void CMD_Direction(F_CMD_ARGS);
 void CMD_Echo(F_CMD_ARGS);
 void CMD_EdgeCommand(F_CMD_ARGS);
@@ -383,6 +386,7 @@
 void CMD_WindowList(F_CMD_ARGS);
 void CMD_WindowShade(F_CMD_ARGS);
 void CMD_WindowShadeAnimate(F_CMD_ARGS);
+void CMD_WindowStyle(F_CMD_ARGS);
 void CMD_Xinerama(F_CMD_ARGS);
 void CMD_XineramaPrimaryScreen(F_CMD_ARGS);
 void CMD_XineramaSls(F_CMD_ARGS);
Index: fvwm/functable.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/functable.c,v
retrieving revision 1.23
diff -u -r1.23 functable.c
--- fvwm/functable.c    11 Mar 2003 08:54:44 -0000      1.23
+++ fvwm/functable.c    7 Jun 2003 17:13:29 -0000
@@ -220,6 +220,10 @@
        CMD_ENT("destroystyle", CMD_DestroyStyle, F_DESTROY_STYLE, 0, 0),
        /* - Delete style defined using Style */
 
+       CMD_ENT("destroywindowstyle", CMD_DestroyWindowStyle,
+               F_DESTROY_WINDOW_STYLE, FUNC_NEEDS_WINDOW, CRS_SELECT),
+       /* - Delete style defined using WindowStyle */
+
        CMD_ENT("direction", CMD_Direction, F_DIRECTION, 0, 0),
        /* - Operate on the next window in the specified direction */
 
@@ -619,6 +623,10 @@
        CMD_ENT("windowshadeanimate", CMD_WindowShadeAnimate, F_SHADE_ANIMATE,
                0, 0),
        /* - (obsolete, use Style * WindowShadeSteps) */
+
+       CMD_ENT("windowstyle", CMD_WindowStyle, F_WINDOW_STYLE,
+               FUNC_NEEDS_WINDOW, CRS_SELECT),
+       /* - Set styles on the selected window */
 
        CMD_ENT("xinerama", CMD_Xinerama, F_XINERAMA, 0, 0),
        /* - Control Xinerama support */
Index: fvwm/fvwm.1.in
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm.1.in,v
retrieving revision 1.92
diff -u -r1.92 fvwm.1.in
--- fvwm/fvwm.1.in      3 Jun 2003 19:22:31 -0000       1.92
+++ fvwm/fvwm.1.in      7 Jun 2003 17:14:07 -0000
@@ -5769,10 +5769,16 @@
 all styles starting with "Application".
 
 .TP
+.B "DestroyWindowStyle"
+deletes the styles set by the
+.B WindowStyle
+command on the selected window. The changes take effect immediately.
+
+.TP
 .BI "UpdateStyles"
 All pending updates of all windows' styles and looks are applied
 immediately.  E.g. if
-.BR Style " or " TitleStyle
+.BR Style ", " WindowStyle " or " TitleStyle
 commands were issued inside a fvwm function.
 
 .TP
@@ -7540,6 +7546,14 @@
 Style * NoIcon
 Style FvwmPager Icon
 .EE
+
+.TP
+.BI "WindowStyle " "options"
+sets attributes (styles) on the selected window. The
+.I options  
+are exactly the same as for the
+.B Style
+command.
 
 .SS OTHER COMMANDS CONTROLLING WINDOW STYLES
 
Index: fvwm/fvwm.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm.h,v
retrieving revision 1.220
diff -u -r1.220 fvwm.h
--- fvwm/fvwm.h 2 Jan 2003 12:01:18 -0000       1.220
+++ fvwm/fvwm.h 7 Jun 2003 17:14:10 -0000
@@ -541,12 +541,24 @@
        unsigned has_placement_percentage_penalty : 1;
 } style_flags;
 
+typedef struct
+{
+       char *name;
+       XID window_id;
+       struct
+       {
+               unsigned has_name:1;
+               unsigned has_window_id:1;
+       } flags;
+} style_id_t;
+
+
 /* only style.c and add_window.c are allowed to access this struct!! */
 typedef struct window_style
 {
        struct window_style *next;
        struct window_style *prev;
-       char *name;
+       style_id_t id;
 #if 0
        WindowConditionMask *condition_mask;
 #endif
Index: fvwm/style.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/style.c,v
retrieving revision 1.210
diff -u -r1.210 style.c
--- fvwm/style.c        21 May 2003 22:58:58 -0000      1.210
+++ fvwm/style.c        7 Jun 2003 17:14:18 -0000
@@ -120,6 +120,49 @@
        return True;
 }
 
+Bool style_ids_are_equals(style_id_t a, style_id_t b)
+{
+       if (SID_GET_HAS_NAME(a) && SID_GET_HAS_NAME(b) &&
+           !strcmp(SID_GET_NAME(a), SID_GET_NAME(b)))
+       {
+               return True;
+       }
+       if (SID_GET_HAS_WINDOW_ID(a) && SID_GET_HAS_WINDOW_ID(b) &&
+           SID_GET_WINDOW_ID(a) == SID_GET_WINDOW_ID(b))
+       {
+               return True;
+       }
+       return False;
+}
+
+Bool style_id_equals_id(window_style s, style_id_t id)
+{
+       return style_ids_are_equals(SGET_ID(s), id);
+}
+
+Bool styles_have_same_id(window_style s, window_style t)
+{
+       return style_ids_are_equals(SGET_ID(s), SGET_ID(t));
+}
+
+Bool fw_match_style_id(FvwmWindow *fw, style_id_t s_id)
+{
+       if (SID_GET_HAS_NAME(s_id) &&
+           (matchWildcards(SID_GET_NAME(s_id), fw->class.res_class) == TRUE ||
+            matchWildcards(SID_GET_NAME(s_id), fw->class.res_name) == TRUE ||
+            matchWildcards(SID_GET_NAME(s_id), fw->name.name) == TRUE))
+       {
+               return True;
+       }
+       if (SID_GET_HAS_WINDOW_ID(s_id) &&
+           SID_GET_WINDOW_ID(s_id) == (XID)FW_W(fw))
+       {
+               return True;
+       }
+
+       return False;
+}
+
 static void remove_icon_boxes_from_style(window_style *pstyle)
 {
        if (SHAS_ICON_BOXES(&pstyle->flags))
@@ -724,7 +767,7 @@
        }
 }
 
-static Bool remove_all_of_style_from_list(char *style_ref)
+static Bool remove_all_of_style_from_list(style_id_t style_id)
 {
        window_style *nptr = all_styles;
        window_style *next;
@@ -735,7 +778,7 @@
        {
                next = SGET_NEXT_STYLE(*nptr);
                /* Check if it's to be wiped */
-               if (!strcmp(SGET_NAME(*nptr), style_ref))
+               if (style_id_equals_id(*nptr, style_id))
                {
                        remove_style_from_list(nptr, True);
                        is_changed = True;
@@ -776,14 +819,14 @@
                cmp = SGET_PREV_STYLE(*cur);
                while (cmp)
                {
-                       if (strcmp(SGET_NAME(*cur), SGET_NAME(*cmp)) != 0)
+                       if (!styles_have_same_id(*cur, *cmp))
                        {
                                blockor((char *)&interflags,
                                        (char *)&interflags,
                                        (char *)&cmp->flag_mask,
                                        sizeof(style_flags));
                                blockor((char *)&interflags,
-                                       (char *)&interflags,
+                               (char *)&interflags,
                                        (char *)&cmp->flag_default,
                                        sizeof(style_flags));
                                cmp = SGET_PREV_STYLE(*cmp);
@@ -3665,7 +3708,8 @@
                        for (add_style = all_styles; add_style;
                             add_style = SGET_NEXT_STYLE(*add_style))
                        {
-                               if (StrEquals(token, SGET_NAME(*add_style)))
+                               if (SGET_ID_HAS_NAME(*add_style) &&
+                                   StrEquals(token, SGET_NAME(*add_style)))
                                {
                                        /* match style */
                                        hit = 1;
@@ -3887,7 +3931,7 @@
  * must be freed in ProcessDestroyStyle().
  */
 
-static void __style_command(F_CMD_ARGS, char *prefix)
+static void __style_command(F_CMD_ARGS, char *prefix, Bool is_window_style)
 {
        /* temp area to build name list */
        window_style *ps;
@@ -3904,14 +3948,25 @@
        /* default StartsOnPage behavior for initial capture */
        ps->flags.capture_honors_starts_on_page = 1;
 
-       /* parse style name */
-       action = GetNextToken(action, &SGET_NAME(*ps));
-       /* in case there was no argument! */
-       if (SGET_NAME(*ps) == NULL)
+       if (!is_window_style)
        {
-               free(ps);
-               return;
+               /* parse style name */
+               action = GetNextToken(action, &SGET_NAME(*ps));
+               /* in case there was no argument! */
+               if (SGET_NAME(*ps) == NULL)
+               {
+                       free(ps);
+                       return;
+               }
+               SSET_ID_HAS_NAME(*ps, True);
+       }
+       else
+       {
+               SSET_WINDOW_ID(*ps, (XID)FW_W(exc->w.fw));
+               SSET_ID_HAS_WINDOW_ID(*ps, True);
+               CopyString(&SGET_NAME(*ps), ""); /* safe */
        }
+
        if (action == NULL)
        {
                free(SGET_NAME(*ps));
@@ -3922,7 +3977,7 @@
        parse_and_set_window_style(action, prefix, ps);
 
        /* capture default icons */
-       if (StrEquals(SGET_NAME(*ps), "*"))
+       if (SGET_ID_HAS_NAME(*ps) && StrEquals(SGET_NAME(*ps), "*"))
        {
                if (ps->flags.has_icon == 1)
                {
@@ -3938,7 +3993,7 @@
                }
        }
        if (last_style_in_list &&
-           strcmp(SGET_NAME(*ps), SGET_NAME(*last_style_in_list)) == 0)
+           styles_have_same_id(*ps, *last_style_in_list))
        {
                /* merge with previous style */
                merge_styles(last_style_in_list, ps, True);
@@ -4037,18 +4092,7 @@
        /* look thru all styles in order defined. */
        for (nptr = all_styles; nptr != NULL; nptr = SGET_NEXT_STYLE(*nptr))
        {
-               /* If name/res_class/res_name match, merge */
-               if (matchWildcards(SGET_NAME(*nptr),fw->class.res_class) ==
-                   TRUE)
-               {
-                       merge_styles(styles, nptr, False);
-               }
-               else if (matchWildcards(SGET_NAME(*nptr),fw->class.res_name) ==
-                        TRUE)
-               {
-                       merge_styles(styles, nptr, False);
-               }
-               else if (matchWildcards(SGET_NAME(*nptr),fw->name.name) == TRUE)
+               if (fw_match_style_id(fw, SGET_ID(*nptr)))
                {
                        merge_styles(styles, nptr, False);
                }
@@ -4770,32 +4814,30 @@
 
 void CMD_Style(F_CMD_ARGS)
 {
-       __style_command(F_PASS_ARGS, NULL);
+       __style_command(F_PASS_ARGS, NULL, False);
 
        return;
 }
 
-void CMD_FocusStyle(F_CMD_ARGS)
+void CMD_WindowStyle(F_CMD_ARGS)
 {
-       __style_command(F_PASS_ARGS, "FP");
+       __style_command(F_PASS_ARGS, NULL, True);
 
        return;
 }
 
-void CMD_DestroyStyle(F_CMD_ARGS)
+void CMD_FocusStyle(F_CMD_ARGS)
 {
-       char *name;
-       FvwmWindow *t;
+       __style_command(F_PASS_ARGS, "FP", False);
 
-       /* parse style name */
-       name = PeekToken(action, &action);
+       return;
+}
 
-       /* in case there was no argument! */
-       if (name == NULL)
-               return;
+void style_destroy_style(style_id_t s_id)
+{
+       FvwmWindow *t;
 
-       /* Do it */
-       if (remove_all_of_style_from_list(name))
+       if (remove_all_of_style_from_list(s_id))
        {
                /* compact the current list of styles */
                Scr.flags.do_need_style_list_update = 1;
@@ -4808,9 +4850,7 @@
        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)
+               if (fw_match_style_id(t, s_id))
                {
                        SET_STYLE_DELETED(t, 1);
                        Scr.flags.do_need_window_update = 1;
@@ -4820,6 +4860,40 @@
        return;
 }
 
+void CMD_DestroyStyle(F_CMD_ARGS)
+{
+       char *name;
+       style_id_t s_id;
+
+       /* parse style name */
+       name = PeekToken(action, &action);
+
+       /* in case there was no argument! */
+       if (name == NULL)
+               return;
+
+       memset(&s_id, 0, sizeof(style_id_t));
+       SID_SET_NAME(s_id, name);
+       SID_SET_HAS_NAME(s_id, True);
+
+       /* Do it */
+       style_destroy_style(s_id);
+       return;
+}
+
+void CMD_DestroyWindowStyle(F_CMD_ARGS)
+{
+       style_id_t s_id;
+
+       memset(&s_id, 0, sizeof(style_id_t));
+       SID_SET_WINDOW_ID(s_id, (XID)FW_W(exc->w.fw));
+       SID_SET_HAS_WINDOW_ID(s_id, True);
+
+       /* Do it */
+       style_destroy_style(s_id);
+       return;
+}
+
 void print_styles(int verbose)
 {
        window_style *nptr;
@@ -4835,7 +4909,15 @@
                count++;
                if (verbose)
                {
-                       fprintf(stderr,"    * %s\n", SGET_NAME(*nptr));
+                       if (SGET_ID_HAS_NAME(*nptr))
+                       {
+                               fprintf(stderr,"    * %s\n", SGET_NAME(*nptr));
+                       }
+                       else
+                       {
+                               fprintf(stderr,"    * 0x%lx\n",
+                                       (unsigned long)SGET_WINDOW_ID(*nptr));
+                       }
                }
        }
        fprintf(stderr,"  Number of styles: %i\n", count);
Index: fvwm/style.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/style.h,v
retrieving revision 1.75
diff -u -r1.75 style.h
--- fvwm/style.h        21 May 2003 22:58:58 -0000      1.75
+++ fvwm/style.h        7 Jun 2003 17:14:20 -0000
@@ -351,6 +351,24 @@
 #define S_SET_EWMH_MAXIMIZE_MODE(c,x) \
        ((c).s.ewmh_maximize_mode = (x))
 
+/* access to style_id */
+#define SID_GET_NAME(id) \
+       ((id).name)
+#define SID_SET_NAME(id,x) \
+       ((id).name = (x))
+#define SID_GET_WINDOW_ID(id) \
+       ((id).window_id)
+#define SID_SET_WINDOW_ID(id,x) \
+       ((id).window_id = (x))
+#define SID_SET_HAS_NAME(id,x) \
+        ((id).flags.has_name = !!(x))
+#define SID_GET_HAS_NAME(id) \
+        ((id).flags.has_name)
+#define SID_SET_HAS_WINDOW_ID(id,x) \
+        ((id).flags.has_window_id = !!(x))
+#define SID_GET_HAS_WINDOW_ID(id) \
+        ((id).flags.has_window_id)
+
 /* access to other parts of a style (call with the style itself) */
 #define SGET_NEXT_STYLE(s) \
        ((s).next)
@@ -360,10 +378,24 @@
        ((s).prev)
 #define SSET_PREV_STYLE(s,x) \
        ((s).prev = (x))
+#define SGET_ID(s) \
+        ((s).id)
 #define SGET_NAME(s) \
-       ((s).name)
+       SID_GET_NAME(SGET_ID(s))
 #define SSET_NAME(s,x) \
-       ((s).name = (x))
+       SID_SET_NAME(SGET_ID(s),x)
+#define SGET_WINDOW_ID(s) \
+       SID_GET_WINDOW_ID(SGET_ID(s))
+#define SSET_WINDOW_ID(s,x) \
+       SID_SET_WINDOW_ID(SGET_ID(s),x)
+#define SSET_ID_HAS_NAME(s,x) \
+        SID_SET_HAS_NAME(SGET_ID(s), x)
+#define SGET_ID_HAS_NAME(s) \
+        SID_GET_HAS_NAME(SGET_ID(s))
+#define SSET_ID_HAS_WINDOW_ID(s,x) \
+        SID_SET_HAS_WINDOW_ID(SGET_ID(s),x)
+#define SGET_ID_HAS_WINDOW_ID(s) \
+        SID_GET_HAS_WINDOW_ID(SGET_ID(s))
 #define SGET_ICON_NAME(s) \
        ((s).icon_name)
 #define SSET_ICON_NAME(s,x) \
@@ -562,6 +594,7 @@
 void update_icon_title_cs_hi_style(FvwmWindow *fw, window_style *pstyle);
 void update_icon_background_cs_style(FvwmWindow *fw, window_style *pstyle);
 void free_icon_boxes(icon_boxes *ib);
+void style_destroy_style(style_id_t s_id);
 void print_styles(int verbose);
 
 #endif /* _STYLE_ */
Index: tests/purify/purify.fvwm2rc
===================================================================
RCS file: /home/cvs/fvwm/fvwm/tests/purify/purify.fvwm2rc,v
retrieving revision 1.41
diff -u -r1.41 purify.fvwm2rc
--- tests/purify/purify.fvwm2rc 26 May 2003 10:24:21 -0000      1.41
+++ tests/purify/purify.fvwm2rc 7 Jun 2003 17:14:33 -0000
@@ -1878,6 +1878,29 @@
 # The man page says not to do this, to-do-2.4 #130
  + I DestroyStyle *
 
+DestroyFunc WindowStyleAndUpdate
+AddToFunc CommandAndUpdate I Echo $*
++ I $*
++ I UpdateStyles
+
+AddTest "Test WindowStyle" WindowStyle-Func
+AddToFunc WindowStyle-Func
++ I CommandAndUpdate Next (window*) WindowStyle BorderWidth 5, HandleWidth 5
++ I CommandAndUpdate Next (window*) WindowStyle NoTitle
++ I CommandAndUpdate Next (window*) WindowStyle NoTitle
++ I CommandAndUpdate Next (window*) WindowStyle NoTitle, gffgghf
++ I CommandAndUpdate All (window*)  WindowStyle Sticky
++ I CommandAndUpdate All (window*)  WindowStyle Sticky
++ I CommandAndUpdate All (window*)  WindowStyle Slippery
++ I CommandAndUpdate All (window*)  WindowStyle Slippery
++ I CommandAndUpdate Next (window*) WindowStyle
++ I CommandAndUpdate Next (window*) WindowStyle
++ I CommandAndUpdate Next (window*) WindowStyle nvhjvhjvhvhv jbjhbjkbjb
++ I CommandAndUpdate Next (window*) DestroyWindowStyle
++ I CommandAndUpdate Next (window*) DestroyWindowStyle pouf
++ I CommandAndUpdate All (window*) DestroyWindowStyle
++ I CommandAndUpdate All (window*) DestroyWindowStyle
+
 DestroyFunc AddButtonStyleAndUpdate
 AddToFunc AddButtonStyleAndUpdate I Echo AddButtonStyle $*
 + I AddButtonStyle $*

Reply via email to