Subject: Patch to enable dynamic FvwmButton button titles

From: Tim Phipps <[email-masked]>
Date: Fri, 01 Feb 2002 16:17:17 +0000

Hi All,
	Here's a patch to make FvwmButtons understand this:

FvwmCommand "SendToModule FvwmButtons Title 5 You have Mail!"

Buttons are numbered from 0 and are in the order in your config file 
(containers don't count). It only works with buttons that have a title 
in the config file (could be " ") and I haven't tested it with anything 
other than a simple button (just a title, no icon or swallows).

I've stuffed the new code into FvwmButtons.c which is probably the wrong 
place.

Cheers,
Tim.

PS I think I can get rid of all my swallowed (non-fvwm) apps except 
xload with this.
Index: modules/FvwmButtons/FvwmButtons.c
===================================================================
RCS file: /u/phippst/share/cvsroot/fvwm/modules/FvwmButtons/FvwmButtons.c,v
retrieving revision 1.18
diff -u -r1.18 FvwmButtons.c
--- modules/FvwmButtons/FvwmButtons.c	2002/02/01 14:28:11	1.18
+++ modules/FvwmButtons/FvwmButtons.c	2002/02/01 16:01:53
@@ -110,6 +110,7 @@
 void process_message(unsigned long type,unsigned long *body);
 extern void send_clientmessage (Display *disp, Window w, Atom a,
 				Time timestamp);
+void parse_message_line(char *line);
 void CheckForHangon(unsigned long*);
 static Window GetRealGeometry(
   Display*,Window,int*,int*,unsigned int*,unsigned int*, unsigned int*,
@@ -936,7 +937,7 @@
 
   SetMessageMask(fd, M_NEW_DESK | M_END_WINDOWLIST | M_MAP | M_WINDOW_NAME
 		 | M_RES_CLASS | M_CONFIG_INFO | M_END_CONFIG_INFO | M_RES_NAME
-		 | M_SENDCONFIG | M_ADD_WINDOW | M_CONFIGURE_WINDOW);
+		 | M_SENDCONFIG | M_ADD_WINDOW | M_CONFIGURE_WINDOW | M_STRING);
   SetMessageMask(fd, MX_PROPERTY_CHANGE);
 
   /* request a window list, since this triggers a response which
@@ -2618,6 +2619,9 @@
       swallowed = body[1];
     }
     break;
+  case M_STRING:
+    parse_message_line((char *)&body[3]);
+    break;
   default:
     break;
   }
@@ -3076,5 +3080,54 @@
       }
       break;
     }
+  }
+}
+
+/* SendToModule options */
+static void parse_title(char *line)
+{
+  int n, count, i;
+  button_info *b, *ub = UberButton;
+
+  /* find out which button */
+  if (GetIntegerArguments(line, &line, &n, 1) != 1)
+    return;
+  if (n < 0)
+  {
+    fprintf(stderr, "%s: button number must not be negative\n", MyName);
+    return;
+  }
+  i = count = -1;
+  /* find the button */
+  while (NextButton(&ub, &b, &i, 0)) {
+    if (++count == n)
+      break;
+  }
+  if (count != n) {
+    fprintf(stderr, "%s: button number %d not found\n", MyName, n);
+    return;
+  }
+  if (b) {
+    if (!b->flags & b_Title) {
+      fprintf(stderr, "%s: cannot create a title, only change one\n", MyName);
+      return;
+    }
+    free(b->title);
+    CopyString(&b->title, line);
+    RedrawButton(b, 2);
+  }
+  return;  
+}
+
+static char *message_options[] = {"Title", NULL};
+
+void parse_message_line(char *line)
+{
+  char *rest;
+
+  switch(GetTokenIndex(line, message_options, -1, &rest)) {
+  case 0:
+    parse_title(rest);
+    break;
   }
 }

---

From: Dominik Vogt <[email-masked]>
Date: Sat, 2 Feb 2002 13:49:33 +0100

On Fri, Feb 01, 2002 at 04:17:17PM +0000, Tim Phipps wrote:
> (containers don't count).

That doesn't work as you think.  The buttons are counted from left
to right, top to bottom:

Regardless if I use

  *FvwmButtons(5x1+0+0, Action `Menu RootMenu`)
  *FvwmButtons(5x1+5+0, Action `Menu ModuleMenu`)

or

  *FvwmButtons(5x1+5+0, Action `Menu ModuleMenu`)
  *FvwmButtons(5x1+0+0, Action `Menu RootMenu`)

the RootMenu button always gets 0 and the ModuleMenu button gets
1.  I think the numbering is based on the position of the button.
My FvwmButtons looks like this:

  --------------------------------------------------
  |    |    |    | ||        ||         |          |
  ------------------|        |----------|          |
  |  |  |  |  |  |  |        |          |          |
  |  |  |  |  |  |  |        |          |          |
  ------------------|        |          |          |
  |  |  |  |  |  |  |        |----------|          |
  |  |  |  |  |  |  |        |          |          |
  --------------------------------------------------

It can be quite difficult to find ot the correct button numbers.

> It only works with buttons that have a title 

Do buttons inside containers count too?

> I've stuffed the new code into FvwmButtons.c which is probably the wrong 

I lika that patch :-)  Consider it applied.  The next logical
thing to do would be to change the pixmap of a button.

> PS I think I can get rid of all my swallowed (non-fvwm) apps except 

Please don't forget to include ChangeLog entries and the man page.

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]

---

From: [email-masked]
Date: Mon, 4 Feb 2002 09:02:20 -0500 (EST)

> thing to do would be to change the pixmap of a button.

Does this patch work if you have multiple instances of FvwmButtons
running?  For example, I sometimes have a number of FvwmButtons, one
that shows system names and swallows FvwmPager, another that swallows
FvwmIconMan and has "task bar" type buttons, etc.  Without assigning
names to buttons, how does FvwmButtons know which "button 5" is to be
changed?

Maybe to help, FvwmButtons could assign as "name" to a particular
button:

    *FvwmButtons(Icon status.xpm, Action 'beep', Title ' ', Name 'status')

    FvwmCommand "SendToModule FvwmButtons Title status 'I am up!'"

This way, you won't need to keep track of the internal button numbers.

Just a suggestion, anyway.

-- 
Larry Gensch                                          [email-masked]

            Working for COMPAQ for over a twentieth of a century

---

From: Tim Phipps <[email-masked]>
Date: Mon, 04 Feb 2002 14:15:01 +0000

>>thing to do would be to change the pixmap of a button.

I think a man page change is the next thing to do ;-)

> running?

Yes, just use the alias name instead of "FvwmButtons" to send the change 
to only one of them.

Cheers,
Tim.