I've written a menu style option to allow for scrolling of menus with a mouse wheel. I also fixed two obvious copy-past-programming errors.

Could someone with cvs wrilte-access apply this patch?

/Viktor Griph
? scroll.patch
Index: AUTHORS
===================================================================
RCS file: /home/cvs/fvwm/fvwm/AUTHORS,v
retrieving revision 1.103
diff -u -u -r1.103 AUTHORS
--- AUTHORS     29 Jun 2005 17:15:18 -0000      1.103
+++ AUTHORS     7 Aug 2005 08:48:56 -0000
@@ -4,6 +4,7 @@
 
 Viktor Griph:
 Patch for Perl modules on 64 bit machines.
+Scroll and ScrollOffPage menu style options.
 
 Bjoern Steinbrink:
 Patch for FvwmScript tasks running too often.
Index: ChangeLog
===================================================================
RCS file: /home/cvs/fvwm/fvwm/ChangeLog,v
retrieving revision 1.2607
diff -u -u -r1.2607 ChangeLog
--- ChangeLog   4 Aug 2005 20:21:00 -0000       1.2607
+++ ChangeLog   7 Aug 2005 08:48:58 -0000
@@ -1,3 +1,22 @@
+2005-08-07  Viktor Griph  <[EMAIL PROTECTED]>
+
+       * fvwm/menus.c (pop_menu_up): 
+       fixed check if parent menu is transparent, and not if the popup
+       is transparent
+
+       * fvwm/menustyle.c (menustyle_copy): 
+       fixed copy of PopdownDelay
+       
+       * fvwm/menustyle.h (enum, MenuFeel, ST_DO_SCROLL, MST_DO_SCROLL) 
+       (ST_SCROLL_OFF_PAGE, MST_SCROLL_OFF_PAGE): 
+       * fvwm/menustyle.c (menustyle_copy): 
+       (menustyle_get_styleopt_index): 
+       (menustyle_parse_style): 
+       * fvwm/menus.c (menuScroll): 
+       (__mloop_handle_event): 
+       * fvwm/fvwm.1.in: 
+       added Scroll and ScrollOffPage menu styles
+
 2005-08-04  Dominik Vogt  <[EMAIL PROTECTED]>
 
        * configure.in:
Index: NEWS
===================================================================
RCS file: /home/cvs/fvwm/fvwm/NEWS,v
retrieving revision 1.561
diff -u -u -r1.561 NEWS
--- NEWS        4 Aug 2005 16:25:40 -0000       1.561
+++ NEWS        7 Aug 2005 08:48:58 -0000
@@ -8,6 +8,7 @@
 * New features:
 
    - Fvwm now officially supports 64-bit architertures.
+   - Added Scroll and ScrollOffPage menu style options.
 
 * Bug Fixes:
 
@@ -15,6 +16,9 @@
    - Fixed a hang with layers set by applications (e.g. AbiWord).
    - GotoDesk with a relative page argument now wraps around at
      the end of the given range as documented. (Bug #1396).
+   - PopupDelayed menu style option was not copied on CopyMenuStyle
+   - Transparent Animated menus with non-transparent popup were not
+     animated correctly.
 
 -------------------------------------------------------------------
 
Index: fvwm/fvwm.1.in
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm.1.in,v
retrieving revision 1.167
diff -u -u -r1.167 fvwm.1.in
--- fvwm/fvwm.1.in      2 Jun 2005 20:54:53 -0000       1.167
+++ fvwm/fvwm.1.in      7 Aug 2005 08:48:59 -0000
@@ -2853,7 +2853,9 @@
 ItemFormat,
 VerticalItemSpacing,
 VerticalTitleSpacing,
-AutomaticHotkeys / AutomaticHotkeysOff.
+AutomaticHotkeys / AutomaticHotkeysOff,
+Scroll,
+ScrollOffPage.
 
 In the above list some options are listed as option pairs or
 triples with a '/' in between.  These options exclude each other.
@@ -3393,6 +3395,21 @@
 .B AddToMenu
 command.
 
+.IR Scroll
+controls the ability to scroll the menu using a mouse wheel. It takes
+one argument, that can be one of On, Off, Inverted or Pointer. On and
+Inverted enables menu scrolling around the pointer, Off disables it,
+and Pointer enables scrolling with Pointer wrapping. Inverted has
+inverted scrolling direction. That is the menu moves in the same
+direction as the mouse wheel, as opposed to the selected item.
+If no argument is supplied On is assumed.
+
+.IR ScrollOffPage 
+controls if a menu is allowed to be scrolled out of the visible area if
+.I Scroll 
+is set to On or Inverted. It takes one optional toggle argument. If no
+argument is supplied On is assumed.
+
 Examples:
 .EX
 MenuStyle * Mwm
Index: fvwm/menus.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/menus.c,v
retrieving revision 1.383
diff -u -u -r1.383 menus.c
--- fvwm/menus.c        1 Nov 2004 12:31:09 -0000       1.383
+++ fvwm/menus.c        7 Aug 2005 08:48:59 -0000
@@ -1496,6 +1496,113 @@
        return (*p != NULL);
 }
 
+/* ------------------------------ menu scrolling --------------------------- */
+/*
+ * Procedure
+ *      menuScroll() - Menu scrolling processing
+ *
+ */
+static void menuScroll(
+       MenuRoot *mr, MenuParameters *pmp, MenuReturn *pmret, XEvent *event,
+       MenuItem **pmiCurrent)
+{
+        int direction, menu_x, menu_y, menu_height;
+       MenuItem *next = NULL;
+       MenuItem *miCurrent = pmiCurrent ? *pmiCurrent : NULL;
+
+       if (event->type == ButtonRelease)
+       {
+               switch (event->xbutton.button)
+               {
+               case 4: /* ScrollUp */
+                       direction = -1;
+                       break;
+               case 5: /* ScrollDown */
+                       direction = 1;
+                               break;
+               default:
+                       fvwm_msg(WARN, "menuScroll",
+                                "Called without scroll event.");
+                       return;
+               }
+       } 
+       else
+       {
+               fvwm_msg(WARN, "menuScroll",
+                                "Called without scroll event.");
+               return;
+       }
+
+       if (MST_DO_SCROLL(mr) == MDS_INVERTED)
+       {
+               direction *= -1;
+       }
+
+       if (!menu_get_geometry(
+                   mr, &JunkRoot, &menu_x, &menu_y, &JunkWidth, &menu_height,
+                   &JunkBW, &JunkDepth))
+       {               
+               fvwm_msg(ERR, "menuScroll",
+                        "can't get geometry of menu %s", MR_NAME(mr));
+               return;
+       }
+
+
+         
+       for (next = miCurrent; next && (! MI_IS_SELECTABLE(next) || next ==  
miCurrent );
+              next = (direction == 1) ?  MI_NEXT_ITEM(next) :  
MI_PREV_ITEM(next))
+         ; /* maybe use while... */
+       
+       if (next)
+       {              
+               *pmiCurrent = next;
+               if (MST_DO_SCROLL(mr) == MDS_POINTER)
+               {
+                       FWarpPointer(dpy, 0, 0, 0, 0, 0, 0, 0, 
menu_y-event->xbutton.y_root + MI_HEIGHT(next)/2 + MI_Y_OFFSET(next));
+                                       
+               }
+               else
+               {
+                       menu_y = event->xbutton.y_root - MI_HEIGHT(next)/2 - 
MI_Y_OFFSET(next);
+                       if (!MST_SCROLL_OFF_PAGE(mr) &&  menu_height < 
MR_SCREEN_HEIGHT(mr))
+                       {
+                               if (menu_y < 0)
+                               {
+                                       FWarpPointer(dpy, 0, 0, 0, 0, 0, 0, 0, 
-menu_y);
+                                       menu_y=0;
+                               }
+                               if (menu_y + menu_height > MR_SCREEN_HEIGHT(mr))
+                               {
+                                       FWarpPointer(dpy, 0, 0, 0, 0, 0, 0, 0,
+                                                    
MR_SCREEN_HEIGHT(mr)-menu_y - menu_height);
+                                       menu_y=MR_SCREEN_HEIGHT(mr)-menu_height;
+                               }
+                       }
+
+                       XMoveWindow(dpy, MR_WINDOW(mr), menu_x, menu_y);
+       
+                       if (ST_HAS_MENU_CSET(MR_STYLE(mr)) &&
+                               CSET_IS_TRANSPARENT(
+                                      ST_CSET_MENU(MR_STYLE(mr))))
+                       {
+                               MenuRepaintTransparentParameters mrtp;
+                               get_menu_repaint_transparent_parameters(&mrtp, 
mr,
+                                                                       
(*pmp->pexc)->w.fw);
+                               repaint_transparent_menu(
+                                                       &mrtp,
+                                                       
False,menu_x,menu_y,menu_x,menu_y);
+                                                
+                       }               
+               }
+               pmret->rc = MENU_NEWITEM;
+       }
+       else
+       {
+               pmret->rc = MENU_NOP;
+       }
+
+}
+
 /* ---------------------------- item list handling ------------------------- */
 
 static void unlink_item_from_menu(
@@ -4008,7 +4115,7 @@
                                MR_XANIMATION(parent_menu) += end_x - prev_x;
                                if (ST_HAS_MENU_CSET(MR_STYLE(parent_menu)) &&
                                    CSET_IS_TRANSPARENT(
-                                           ST_CSET_MENU(MR_STYLE(mr))))
+                                           
ST_CSET_MENU(MR_STYLE(parent_menu))))
                                {
                                        transparent_bg = True;
                                        get_menu_repaint_transparent_parameters(
@@ -4672,6 +4779,18 @@
                                pmret->rc = MENU_TEAR_OFF;
                                return MENU_MLOOP_RET_END;
                        }
+                       else if ( med->mrMi != NULL && MST_DO_SCROLL(med->mrMi) 
!= MDS_OFF && 
+                                 ((*pmp->pexc)->x.elast->xbutton.button == 4 ||
+                                  (*pmp->pexc)->x.elast->xbutton.button == 5))
+                       {                         
+                              menuScroll(med->mrMi, pmp, pmret, 
(*pmp->pexc)->x.elast,
+                                         &med->mi);
+                              if (pmret->rc == MENU_NOP)
+                              {
+                                       return MENU_MLOOP_RET_LOOP;
+                              }
+                              break;
+                       }
                }
                in->mif.was_item_unposted = 0;
                if (pmret->flags.is_menu_posted && med->mrMi != NULL)
Index: fvwm/menustyle.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/menustyle.c,v
retrieving revision 1.29
diff -u -u -r1.29 menustyle.c
--- fvwm/menustyle.c    3 Nov 2003 17:41:20 -0000       1.29
+++ fvwm/menustyle.c    7 Aug 2005 08:48:59 -0000
@@ -348,6 +348,7 @@
                "PopdownDelay",
                "PopupActiveArea",
                "PopupIgnore", "PopupClose",
+               "Scroll", "ScrollOffPage",
                NULL
        };
 
@@ -1287,6 +1288,63 @@
                        ST_DO_POPUP_AS(tmpms) = MDP_CLOSE;
                        break;
 
+               case 56: /* Scroll */
+                       if (arg1)
+                       {
+                               if (StrEquals(arg1, "Off"))
+                               {
+                                       ST_DO_SCROLL(tmpms) = MDS_OFF;  
+                               }
+                               else if (StrEquals(arg1, "On") )
+                               {
+                                       ST_DO_SCROLL(tmpms) = MDS_ON;   
+                               }
+                               else if (StrEquals(arg1, "Inverted"))
+                               {
+                                       ST_DO_SCROLL(tmpms) = MDS_INVERTED;
+                               }
+                               else if (StrEquals(arg1, "Pointer"))
+                               {
+                                       ST_DO_SCROLL(tmpms) = MDS_POINTER;
+                               }
+                               else
+                               {
+                                       fvwm_msg(ERR, "NewMenuStyle", 
+                                                "unknown argument to Scroll 
'%s'",
+                                                arg1);
+                               }
+                       }
+                       else
+                       {
+                               ST_DO_SCROLL(tmpms) = MDS_ON;   
+                       }
+                       break;
+               case 57: /* ScrollOffPage */
+                       if (arg1)
+                       {                       
+                               switch (ParseToggleArgument(arg1, NULL, -2,0))
+                               {
+                               case -1: /* toggle */
+                                       ST_SCROLL_OFF_PAGE(tmpms) ^= 1;
+                                       break;
+                               case 0:
+                                       ST_SCROLL_OFF_PAGE(tmpms) = 0;
+                                       break;
+                               case 1:
+                                       ST_SCROLL_OFF_PAGE(tmpms) = 1;
+                                       break;
+                               default:
+                                       fvwm_msg(ERR, "NewMenuStyle", 
+                                                "unknown argument to Scroll 
'%s'",
+                                                arg1);
+                                       break;
+                               }
+                       }
+                       else
+                       {
+                               ST_SCROLL_OFF_PAGE(tmpms) = 1;
+                       }
+                       break;
 #if 0
                case 99: /* PositionHints */
                        /* to be implemented */
@@ -1541,7 +1599,11 @@
        /* PopdownImmediately */
        ST_DO_POPDOWN_IMMEDIATELY(destms) = ST_DO_POPDOWN_IMMEDIATELY(origms);
        /* PopdownDelay */
-       ST_POPDOWN_DELAY(destms) = ST_POPDOWN_DELAY(destms);
+       ST_POPDOWN_DELAY(destms) = ST_POPDOWN_DELAY(origms);
+       /* Scroll */
+       ST_DO_SCROLL(destms) = ST_DO_SCROLL(origms);
+       /* ScrollOffPage */
+       ST_SCROLL_OFF_PAGE(destms) = ST_SCROLL_OFF_PAGE(origms);
 
        menustyle_update(destms);
 
Index: fvwm/menustyle.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/menustyle.h,v
retrieving revision 1.14
diff -u -u -r1.14 menustyle.h
--- fvwm/menustyle.h    3 Nov 2003 17:41:20 -0000       1.14
+++ fvwm/menustyle.h    7 Aug 2005 08:48:59 -0000
@@ -121,6 +121,10 @@
 #define ST_USE_AUTOMATIC_HOTKEYS(s)   ((s)->feel.flags.use_automatic_hotkeys)
 #define MST_USE_AUTOMATIC_HOTKEYS(m) \
        ((m)->s->ms->feel.flags.use_automatic_hotkeys)
+#define ST_DO_SCROLL(s)               ((s)->feel.flags.do_scroll)
+#define MST_DO_SCROLL(m)              ((m)->s->ms->feel.flags.do_scroll)
+#define ST_SCROLL_OFF_PAGE(s)         ((s)->feel.flags.scroll_off_page)
+#define MST_SCROLL_OFF_PAGE(m)        ((m)->s->ms->feel.flags.scroll_off_page)
 #define ST_FLAGS(s)                   ((s)->feel.flags)
 #define MST_FLAGS(m)                  ((m)->s->ms->feel.flags)
 #define ST_POPUP_OFFSET_PERCENT(s)    ((s)->feel.PopupOffsetPercent)
@@ -163,6 +167,14 @@
        MDP_CLOSE = 3
 } ms_do_popup_as_t;
 
+typedef enum
+{
+       MDS_OFF = 0,
+       MDS_ON = 1,
+       MDS_INVERTED = 2,       
+       MDS_POINTER = 3
+} ms_do_scroll_t;
+
 typedef struct MenuFeel
 {
        struct
@@ -175,6 +187,8 @@
                unsigned do_unmap_submenu_on_popdown : 1;
                unsigned use_left_submenus : 1;
                unsigned use_automatic_hotkeys : 1;
+               unsigned do_scroll : 2;
+               unsigned scroll_off_page : 1;
        } flags;
        int PopdownDelay10ms;
        int PopupOffsetPercent;

Reply via email to