On Wed, Feb 08, 2006 at 05:11:48PM +0300, George Nephrite Potapov wrote:

I'm very sorry but there was a small error in my previous message with patch.
Here is the correct one. I'm very very sorry.

-- 
George 'Nephrite' Potapov
? buttonpress.patch
Index: modules/FvwmButtons/FvwmButtons.1.in
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmButtons/FvwmButtons.1.in,v
retrieving revision 1.2
diff -u -r1.2 FvwmButtons.1.in
--- modules/FvwmButtons/FvwmButtons.1.in        27 Feb 2005 07:47:25 -0000      
1.2
+++ modules/FvwmButtons/FvwmButtons.1.in        8 Feb 2006 14:19:31 -0000
@@ -1015,6 +1015,19 @@
 above. Command may be any fvwm command with variables $var that
 are expanded if supported.
 
+.IP "PressButton \fIbutton_id\fP [\fImouse_button\fP]"
+where
+.I button_id
+is the id of the button to press as specified using the
+.B Id
+button option and
+.I mouse_button
+is the number of mouse button used to click on the button e.g "1" for left
+mouse button etc. Quotes around the number is not needed. If
+.I mouse_button
+option is omitted "1" assumed. This command behaves exactly like if
+the button in question was pressed using the mouse.
+
 .IP Silent
 This prefix may be specified before other actions. It disables
 all possible error and warning messages.
Index: modules/FvwmButtons/FvwmButtons.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmButtons/FvwmButtons.c,v
retrieving revision 1.199
diff -u -r1.199 FvwmButtons.c
--- modules/FvwmButtons/FvwmButtons.c   27 Feb 2005 07:47:25 -0000      1.199
+++ modules/FvwmButtons/FvwmButtons.c   8 Feb 2006 14:19:32 -0000
@@ -880,6 +880,114 @@
        return b;
 }
 
+void ButtonPressProcess (b, act)
+    button_info *b;
+    char **act;
+{
+  FlocaleNameString tmp;
+    int i,i2;
+
+        memset(&tmp, 0, sizeof(tmp));
+       if (b && !*act && b->flags.b_Panel)
+       {
+         ActiveButton = b;
+         HandlePanelPress(b);
+         if (b->newflags.panel_mapped == 0)
+         {
+           if (is_transient)
+           {
+             /* terminate if transient and panel has been unmapped */
+             exit(0);
+           }
+           else if (is_transient_panel)
+           {
+             XWithdrawWindow(Dpy, MyWindow, screen);
+           }
+         }
+       } /* panel */
+       else
+       {
+         if (!*act)
+           *act=GetButtonAction(b,0);
+         if (b && b == CurrentButton && *act)
+         {
+           if (strncasecmp(*act,"Exec",4) == 0 &&
+               isspace(*act[4]))
+           {
+
+             /* Look for Exec "identifier", in which case the button
+                stays down until window "identifier" materializes */
+             i = 4;
+             while(isspace((unsigned char)*act[i]))
+               i++;
+             if(*act[i] == '"')
+             {
+               i2=i+1;
+               while(*act[i2]!=0 && *act[i2]!='"')
+                 i2++;
+
+               if(i2-i>1)
+               {
+                 b->flags.b_Hangon = 1;
+                 b->hangon = mymalloc(i2-i);
+                 strncpy(b->hangon,&*act[i+1],i2-i-1);
+                 b->hangon[i2-i-1] = 0;
+               }
+               i2++;
+             }
+             else
+               i2=i;
+
+             tmp.name = mymalloc(strlen(*act)+1);
+             strcpy(tmp.name, "Exec ");
+             while(*act[i2]!=0 && isspace((unsigned char)*act[i2]))
+               i2++;
+             strcat(tmp.name ,&*act[i2]);
+             if (is_transient)
+             {
+               /* delete the window before continuing */
+               XDestroyWindow(Dpy, MyWindow);
+               XSync(Dpy, 0);
+             }
+             SendText(fd,tmp.name,0);
+             if (is_transient)
+             {
+               /* and exit */
+               exit(0);
+             }
+             if (is_transient_panel)
+             {
+               XWithdrawWindow(Dpy, MyWindow, screen);
+             }
+             free(tmp.name);
+           } /* exec */
+           else if(strncasecmp(*act,"DumpButtons",11)==0)
+             DumpButtons(UberButton);
+           else if(strncasecmp(*act,"SaveButtons",11)==0)
+             SaveButtons(UberButton);
+           else
+           {
+             if (is_transient)
+             {
+               /* delete the window before continuing */
+               XDestroyWindow(Dpy, MyWindow);
+               XSync(Dpy, 0);
+             }
+             SendText(fd,*act,0);
+             if (is_transient)
+             {
+               /* and exit */
+               exit(0);
+             }
+             if (is_transient_panel)
+             {
+               XWithdrawWindow(Dpy, MyWindow, screen);
+             }
+           }
+         } /* *act */
+       } /* !panel */
+}
+
 /* -------------------------------- Main Loop -------------------------------*/
 
 /**
@@ -1171,104 +1279,8 @@
        }
        b = select_button(UberButton, x, y);
        act = GetButtonAction(b,Event.xbutton.button);
-       if (b && !act && b->flags.b_Panel)
-       {
-         ActiveButton = b;
-         HandlePanelPress(b);
-         if (b->newflags.panel_mapped == 0)
-         {
-           if (is_transient)
-           {
-             /* terminate if transient and panel has been unmapped */
-             exit(0);
-           }
-           else if (is_transient_panel)
-           {
-             XWithdrawWindow(Dpy, MyWindow, screen);
-           }
-         }
-       } /* panel */
-       else
-       {
-         if (!act)
-           act=GetButtonAction(b,0);
-         if (b && b == CurrentButton && act)
-         {
-           if (strncasecmp(act,"Exec",4) == 0 &&
-               isspace(act[4]))
-           {
-
-             /* Look for Exec "identifier", in which case the button
-                stays down until window "identifier" materializes */
-             i = 4;
-             while(isspace((unsigned char)act[i]))
-               i++;
-             if(act[i] == '"')
-             {
-               i2=i+1;
-               while(act[i2]!=0 && act[i2]!='"')
-                 i2++;
-
-               if(i2-i>1)
-               {
-                 b->flags.b_Hangon = 1;
-                 b->hangon = mymalloc(i2-i);
-                 strncpy(b->hangon,&act[i+1],i2-i-1);
-                 b->hangon[i2-i-1] = 0;
-               }
-               i2++;
-             }
-             else
-               i2=i;
-
-             tmp.name = mymalloc(strlen(act)+1);
-             strcpy(tmp.name, "Exec ");
-             while(act[i2]!=0 && isspace((unsigned char)act[i2]))
-               i2++;
-             strcat(tmp.name ,&act[i2]);
-             if (is_transient)
-             {
-               /* delete the window before continuing */
-               XDestroyWindow(Dpy, MyWindow);
-               XSync(Dpy, 0);
-             }
-             SendText(fd,tmp.name,0);
-             if (is_transient)
-             {
-               /* and exit */
-               exit(0);
-             }
-             if (is_transient_panel)
-             {
-               XWithdrawWindow(Dpy, MyWindow, screen);
-             }
-             free(tmp.name);
-           } /* exec */
-           else if(strncasecmp(act,"DumpButtons",11)==0)
-             DumpButtons(UberButton);
-           else if(strncasecmp(act,"SaveButtons",11)==0)
-             SaveButtons(UberButton);
-           else
-           {
-             if (is_transient)
-             {
-               /* delete the window before continuing */
-               XDestroyWindow(Dpy, MyWindow);
-               XSync(Dpy, 0);
-             }
-             SendText(fd,act,0);
-             if (is_transient)
-             {
-               /* and exit */
-               exit(0);
-             }
-             if (is_transient_panel)
-             {
-               XWithdrawWindow(Dpy, MyWindow, screen);
-             }
-           }
-         } /* act */
-       } /* !panel */
+    
+    ButtonPressProcess(b, &act);
 
        if (act != NULL)
        {
Index: modules/FvwmButtons/FvwmButtons.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmButtons/FvwmButtons.h,v
retrieving revision 1.50
diff -u -r1.50 FvwmButtons.h
--- modules/FvwmButtons/FvwmButtons.h   27 Feb 2005 07:47:25 -0000      1.50
+++ modules/FvwmButtons/FvwmButtons.h   8 Feb 2006 14:19:32 -0000
@@ -246,6 +246,9 @@
 void SetTransparentBackground(button_info *ub,int w,int h);
 void exec_swallow(char *action, button_info *b);
 
+char *GetButtonAction(button_info*,int);
+void ButtonPressProcess(button_info *b, char **act);
+
 /* ----------------------------- global variables -------------------------- */
 
 extern Display *Dpy;
Index: modules/FvwmButtons/dynamic.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/modules/FvwmButtons/dynamic.c,v
retrieving revision 1.14
diff -u -r1.14 dynamic.c
--- modules/FvwmButtons/dynamic.c       26 Nov 2005 21:55:12 -0000      1.14
+++ modules/FvwmButtons/dynamic.c       8 Feb 2006 14:19:32 -0000
@@ -195,7 +195,7 @@
 
 static char *actions[] =
 {
-       "Silent", "ChangeButton", "ExpandButtonVars", NULL
+       "Silent", "ChangeButton", "ExpandButtonVars", "PressButton", NULL
 };
 
 static char *button_options[] =
@@ -203,11 +203,19 @@
        "Title", "Icon", "ActiveTitle", "ActiveIcon", "PressTitle", 
"PressIcon", NULL
 };
 
+static int buttons[] = 
+{
+    0, Button1, Button2, Button3, Button4, Button5, NULL
+};
+
 void parse_message_line(char *line)
 {
        char *rest;
        int action = -1;
        button_info *b;
+    char *act;
+    char *buttonn;
+    int mousebutton;
 
        silent = False;
        do
@@ -365,6 +373,28 @@
                        free(line);
                }
                break;
+       case 3:
+               /* PressButton */
+        rest = GetQuotedString(
+            rest, &buttonn, "", NULL, NULL, NULL);
+        if (buttonn) {
+            mousebutton = atoi(buttonn);
+
+            free(buttonn);
+        }
+        if (!mousebutton) {
+            mousebutton = 1;
+        }
+        
+        CurrentButton = b;
+        act = GetButtonAction(b, buttons[mousebutton]);
+        ButtonPressProcess(b, &act);
+        if (act) {
+            free(act);
+        }
+        CurrentButton = NULL;
+
+               break;
        }
 
        return;

Reply via email to