Subject: Menus in the Pager

From: Matthias Clasen <[email-masked]>
Date: Tue, 12 Jan 1999 21:17:05 +0100

A little extension of the pager. Alt-M2 over a window
in the pager pops up a menu. The menu actions will be 
applied to the window corresponding to the pager window. 
What menu to pop up is determined by the new config command 

FvwmPagerMenu menu

A useful example would be

FvwmPagerMenu Window-Ops

While implementing this, I found that it also needs a
little patch to fvwm/module.c to keep fvwm from dumping
core in ExecuteFunction. (There is code in HandleModuleInput
that pretends to handle Popup commands, but it forgets
to set ButtonWindow).

Shortcomings of this patch:

 *) Since the menu is popped up by fvwm, the actions must
    be fvwm commands. This is not quite appropriate for some
    actions, eg Move. One could probably have the pager do 
    it itself by using SendToModule. This would also need
    the pointer warped back over the (pager) window after
    popping down the menu.

 *) Instead of hard-coding Alt-M2, it might be worth a thought
    to make the bindings of the pager configurable like fvwm's.
    
 *) Maximizing offscreen windows behaves unfriendly. See my 
    next mail.

Matthias

--- fvwm/module.c.orig	Tue Jan 12 13:38:33 1999
+++ fvwm/module.c	Tue Jan 12 13:38:52 1999
@@ -263,6 +263,8 @@
   return;
 }
 
+extern FvwmWindow *ButtonWindow;
+
 /* Changed to return 66, Locking code AS dje */
 int HandleModuleInput(Window w, int channel)
 {
@@ -331,9 +333,10 @@
 	}
 
       /* If a module does XUngrabPointer(), it can now get proper Popups */
-      if(strncasecmp(text,"popup",5)==0) 
+      if(strncasecmp(text,"popup",5)==0) {
+          ButtonWindow = tmp_win;
 	  Event.xany.type = ButtonPress;
-      else
+      } else
 	  Event.xany.type = ButtonRelease;
       Event.xany.window = w;
 
--- modules/FvwmPager/FvwmPager.c.orig	Tue Jan 12 13:33:05 1999
+++ modules/FvwmPager/FvwmPager.c	Tue Jan 12 01:53:20 1999
@@ -71,6 +71,8 @@
 char *WindowHiBack = NULL;
 char *WindowHiFore = NULL;
 
+char *MenuName = NULL;
+
 int ShowBalloons = 0, ShowPagerBalloons = 0, ShowIconBalloons = 0;
 char *BalloonTypeString = NULL;
 char *BalloonBack = NULL;
@@ -1316,6 +1318,12 @@
 	{
 	  sscanf(arg1, "%d", &BalloonYOffset);
 	}
+      else if (StrEquals(resource, "Menu"))
+        {
+	  if (MenuName)
+	    free(MenuName);
+	  CopyString(&MenuName, arg1);
+        }
 
       free(resource);
       free(arg1);
--- modules/FvwmPager/x_pager.c1	Tue Jan 12 13:36:02 1999
+++ modules/FvwmPager/x_pager.c	Tue Jan 12 01:51:44 1999
@@ -36,6 +36,8 @@
 extern int MiniIcons;
 extern int ShowBalloons, ShowPagerBalloons, ShowIconBalloons;
 
+extern char *MenuName;
+
 extern int icon_w, icon_h, icon_x, icon_y;
 XFontStruct *font, *windowFont;
 
@@ -586,7 +588,13 @@
     case ButtonPress:
       if ( ShowBalloons )
         UnmapBalloonWindow();
-      if (((Event->xbutton.button == 2)||
+      if ((Event->xbutton.button == 2) &&
+	  (Event->xbutton.state & Mod1Mask) &&
+	  (Event->xbutton.subwindow != None)) 
+        {
+          WindowMenu(Event);
+        }
+      else if (((Event->xbutton.button == 2)||
 	   ((Event->xbutton.button == 3)&&
 	    (Event->xbutton.state & Mod1Mask)))&&
 	  (Event->xbutton.subwindow != None))
@@ -1346,6 +1354,43 @@
       Wait = 1;
     }
 #endif
+}
+
+void WindowMenu(XEvent *Event)
+{
+  char command[100];
+  PagerWindow *t;
+
+  if (MenuName == NULL) 
+    return;
+
+  sprintf(command, "Popup %s", MenuName);
+
+  t = Start;
+  while ((t != NULL)&&(t->PagerView != Event->xbutton.subwindow))
+    t= t->next;
+
+  if(t==NULL)
+    {
+      t = Start;
+      while ((t != NULL)&&(t->IconView != Event->xbutton.subwindow))
+	t= t->next;
+      if(t!=NULL)
+	{
+          XUngrabPointer(dpy, CurrentTime);
+          XSync(dpy, 0);
+          SendInfo(fd, command, t->icon_w);
+	  
+	  return;
+	}
+    }
+
+  if(t == NULL)
+    return;
+
+  XUngrabPointer(dpy, CurrentTime);
+  XSync(dpy, 0);
+  SendInfo(fd, command, t->w);
 }
 
 void MoveWindow(XEvent *Event)

-- 
Matthias Clasen, 
Tel. 0761/203-5606
Email: [email-masked]
Mathematisches Institut, Albert-Ludwigs-Universitaet Freiburg
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
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, 12 Jan 1999 23:26:15 +0100

>     to make the bindings of the pager configurable like fvwm's.

You should talk with Fred Maciel. We is or was writing a
module that allows exactly this ([email-masked]).

Bye

Dominik

--
Dominik Vogt, [email-masked]
Reply-To: [email-masked]