Subject: Conditions in WindowList

From: Neil Bird <[email-masked]>
Date: Tue, 24 Aug 1999 11:14:17 +0100

I've just done a patch for windowlist.c that allows a Next-like '()'
condition specifier to appear in front of the current options (after
position).

  I'm in two minds as to whether it's worth removing some of the
'duplicate' WindowList options, though.

  The likely candidates are: CurrentDesk NoIcons OnlyIcons NoNormal
OnlyNormal NoSticky OnlySticky

  AFAICS, pro-removal:
  - tidier
  - less code duplication

  anti:
  - normal conditions are cumulative (i.e., a window has to match all the
conditions) while WindowList opts. generally aren't. I don't see how one
could, say, list all icons /and/ window on desk n. Not that I can see
anyone who'd want to, but ...
  - WindowList can do Desk <n>; () only has CurrentDesk [this ought to be
added, I guess].

  I'm tending towards leaving 'em in.

  On the same subject, should the given conditions be blindly applied if
given (i.e., a window is only included if it matches the conditions,
regardless of whether it matches the other WindowList options) or should
the conditions be used as an alternative (e.g., '(some condition) Desk 2'
lists all matching '(some condition)' /and/ on 'desk 2').

  I've coded as must-match-if-given, but if done as an alternative pick up
there'd be problems picking out your matches from all the other windows,
which by default will be shown.

-- 
=====================- http://www.racaldefence.com/ -===================
 Neil Bird                   |   This is who we are     The time is near
                             |
 mailto:[email-masked] |        There are 130 days remaining
--
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: Dominik Vogt <[email-masked]>
Date: Tue, 24 Aug 1999 13:17:33 +0200

>   I'm tending towards leaving 'em in.

Why don't you post the patch so that I can have a look
at it. If I had to do it I would give WindowList an optional
new syntax that takes a normal condition modifier like the 
Next, Prev, ... commands (see conditional.c). I wouldn't start
mixing both methods of specifying flags but mark the old
syntax as obsolete.

Bye

Dominik ^_^

-- 
Dominik Vogt, Hewlett-Packard GmbH, Dept. BVS
Herrenberger Str.130, 71034 Boeblingen, Germany
phone: 07031/14-4596, fax: 07031/14-3883, [email-masked]
--
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: Neil Bird <[email-masked]>
Date: Tue, 24 Aug 1999 12:23:35 +0100

Dominik Vogt wrote:
> at it.

  OK. It's not tested yet, mind.

> If I had to do it I would give WindowList an optional

  That brings us back to one of the questions I asked: Next/Prev
conditions are AND conditions (you get only windows that match all listed
conditions); those WindowList optons that are actually conditions seem to
be OR conditions (you get windows that match /any/ of the conditions).

  But yes, ideally, we'd extend the Next/Prev conditions to cover all
those supplied by WindowList, then leave the WindowList options as just
those things that really are options.

--- conditional.c.orig	Wed Aug 18 11:43:31 1999
+++ conditional.c	Tue Aug 24 08:56:59 1999
@@ -53,8 +53,9 @@
  * characters.  The start of the rest of the line is put in restptr.
  * Note that the returned string is allocated here and it must be
  * freed when it is not needed anymore.
+ * NOTE - exported via .h
  **********************************************************************/
-static char *CreateFlagString(char *string, char **restptr)
+char *CreateFlagString(char *string, char **restptr)
 {
   char *retval;
   char *c;
@@ -107,8 +108,9 @@
 /**********************************************************************
  * The name field of the mask is allocated in CreateConditionMask.
  * It must be freed.
+ * NOTE - exported via .h
  **********************************************************************/
-static void FreeConditionMask(WindowConditionMask *mask)
+void FreeConditionMask(WindowConditionMask *mask)
 {
   if (mask->my_flags.needs_name)
     free(mask->name);
@@ -116,8 +118,10 @@
     free(mask->name - 1);
 }
 
-/* Assign the default values for the window mask */
-static void DefaultConditionMask(WindowConditionMask *mask)
+/* Assign the default values for the window mask
+ * NOTE - exported via .h
+ */
+void DefaultConditionMask(WindowConditionMask *mask)
 {
   memset(mask, 0, sizeof(WindowConditionMask));
   mask->layer = -2; /* -2  means no layer condition, -1 means current */
@@ -126,8 +130,9 @@
 /**********************************************************************
  * Note that this function allocates the name field of the mask struct.
  * FreeConditionMask must be called for the mask when the mask is discarded.
+ * NOTE - exported via .h
  **********************************************************************/
-static void CreateConditionMask(char *flags, WindowConditionMask *mask)
+void CreateConditionMask(char *flags, WindowConditionMask *mask)
 {
   char *condition;
   char *prev_condition = NULL;
@@ -267,8 +272,9 @@
 /**********************************************************************
  * Checks whether the given window matches the mask created with
  * CreateConditionMask.
+ * NOTE - exported via .h
  **********************************************************************/
-static Bool MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask)
+Bool MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask)
 {
   Bool fMatchesName;
   Bool fMatchesIconName;
--- conditional.h.orig	Tue Aug 17 20:56:53 1999
+++ conditional.h	Tue Aug 24 08:58:04 1999
@@ -25,4 +25,14 @@
 void PickFunc(F_CMD_ARGS);
 void AllFunc(F_CMD_ARGS);
 
+
+/* Condition matching routines
+ * Originally exported for WindowList - N.Bird 24/08/99
+ */
+extern char *CreateFlagString(char *string, char **restptr);
+extern void DefaultConditionMask(WindowConditionMask *mask);
+extern void CreateConditionMask(char *flags, WindowConditionMask *mask);
+extern void FreeConditionMask(WindowConditionMask *mask);
+extern Bool MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask);
+
 #endif /* CONDITIONAL_H */
--- windowlist.c.orig	Sun Jun 27 12:30:27 1999
+++ windowlist.c	Tue Aug 24 11:14:41 1999
@@ -40,6 +40,7 @@
 #include "misc.h"
 #include "screen.h"
 #include "stack.h"
+#include "conditional.h"
 
 extern FvwmWindow *Tmp_win;
 extern FvwmWindow *ButtonWindow;
@@ -103,12 +104,39 @@
   int high_layer = INT_MAX;
   int tc;
 
+  /* Condition vars. */
+  Bool use_condition = False;
+  WindowConditionMask mask;
+  char *cond_flags, *restofline;
+
+
   memset(&(mops.flags), 0, sizeof(mops.flags));
   if (action && *action)
   {
     /* parse postitioning args */
     action = GetMenuOptions(action, w, tmp_win, NULL, NULL, &mops);
     line = action;
+
+    /* Look for condition - CreateFlagString returns NULL if no '(' or '[' */
+    cond_flags = CreateFlagString(action, &restofline);
+    if (cond_flags)
+      {
+      /* Create window mask */
+      use_condition = True;
+      DefaultConditionMask(&mask);
+
+      /* override for Current [] */
+      mask.my_flags.use_circulate_hit = 1;
+      mask.my_flags.use_circulate_hit_icon = 1;
+
+      CreateConditionMask(cond_flags, &mask);
+      free(cond_flags);
+
+      /* Relocate action */
+      action = restofline;
+      }
+
+
     /* parse options */
     while (line && *line)
     {
@@ -130,11 +158,6 @@
 	  flags &= ~SHOW_ALLDESKS;
 	}
       }
-      else if (StrEquals(tok,"CurrentDesk"))
-      {
-        desk = Scr.CurrentDesk;
-        flags &= ~SHOW_ALLDESKS;
-      }
       else if (StrEquals(tok,"NotAlphabetic"))
         flags &= ~SHOW_ALPHABETIC;
       else if (StrEquals(tok,"Alphabetic"))
@@ -281,6 +304,8 @@
       if(((t->Desk == next_desk) || (flags & NO_DESK_SORT)) &&
          (!(DO_SKIP_WINDOW_LIST(t))))
       {
+	if (use_condition && !MatchesConditionMask(t, &mask))
+	  continue; /* doesn't match specified condition */
         if (!(flags & SHOW_ICONIC) && (IS_ICONIFIED(t)))
           continue; /* don't want icons - skip */
         if (!(flags & SHOW_STICKY) && (IS_STICKY(t)))
@@ -410,4 +435,6 @@
 		    EXPAND_COMMAND);
   if (default_action != NULL)
     free(default_action);
+  if (use_condition)
+    FreeConditionMask(&mask);
 }

---

From: Dominik Vogt <[email-masked]>
Date: Thu, 26 Aug 1999 00:44:27 +0200

> those things that really are options.

I have applied the patch. I think it's okay that the conditions work
differently than the options of WindowList. This gices you more
flexibility and is consistent with the other commands taking conditions
as arguments.

Bye

Dominik ^_^

--
Dominik Vogt, [email-masked]
Reply-To: [email-masked]
--
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]