From 5c7616709833bf3f7baf02653e7b767d05a9613b Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 13 Apr 2000 21:24:28 +0000 Subject: [PATCH] Initial mouse wheel code. --- WINGs/WINGsP.h | 4 ++- WINGs/configuration.c | 63 +++++++++++++++++++++++++++++++++++++++---- WINGs/wpopupbutton.c | 47 ++++++++++++++++++++++++++++++-- WINGs/wscroller.c | 31 +++++++++++++++------ WINGs/wslider.c | 23 +++++++++++++++- WindowMaker/Defaults/WMGLOBAL | 2 ++ 6 files changed, 153 insertions(+), 17 deletions(-) diff --git a/WINGs/WINGsP.h b/WINGs/WINGsP.h index b3b5ad47..b017885c 100644 --- a/WINGs/WINGsP.h +++ b/WINGs/WINGsP.h @@ -387,9 +387,11 @@ typedef struct W_EventHandler { typedef struct _WINGsConfiguration { char *systemFont; char *boldSystemFont; - int defaultFontSize; + int defaultFontSize; Bool useMultiByte; unsigned doubleClickDelay; + unsigned mouseWheelUp; + unsigned mouseWheelDown; } _WINGsConfiguration; extern _WINGsConfiguration WINGsConfiguration; diff --git a/WINGs/configuration.c b/WINGs/configuration.c index fd966551..7d9bb1f7 100644 --- a/WINGs/configuration.c +++ b/WINGs/configuration.c @@ -10,11 +10,32 @@ _WINGsConfiguration WINGsConfiguration; #define SYSTEM_FONT "-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-*-*-%d-*-*-*-*-*-*-*" - + #define BOLD_SYSTEM_FONT "-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-bold-r-*-*-%d-*-*-*-*-*-*-*" - +static unsigned +getButtonWithName(const char *name, unsigned defaultButton) +{ + if (strncmp(name, "Button", 6)==0 && strlen(name)==7) { + switch (name[6]) { + case '1': + return Button1; + case '2': + return Button2; + case '3': + return Button3; + case '4': + return Button4; + case '5': + return Button5; + default: + break; + } + } + + return defaultButton; +} void @@ -27,6 +48,9 @@ W_ReadConfigurations(void) defaults = WMGetStandardUserDefaults(); if (defaults) { + char *buttonName; + unsigned button; + WINGsConfiguration.systemFont = WMGetUDStringForKey(defaults, "SystemFont"); @@ -38,11 +62,34 @@ W_ReadConfigurations(void) WINGsConfiguration.doubleClickDelay = WMGetUDIntegerForKey(defaults, "DoubleClickTime"); - + + buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp"); + if (buttonName) { + button = getButtonWithName(buttonName, Button4); + free(buttonName); + } else { + button = Button4; + } + WINGsConfiguration.mouseWheelUp = button; + + buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown"); + if (buttonName) { + button = getButtonWithName(buttonName, Button5); + free(buttonName); + } else { + button = Button5; + } + WINGsConfiguration.mouseWheelDown = button; + + if (WINGsConfiguration.mouseWheelDown==WINGsConfiguration.mouseWheelUp) { + WINGsConfiguration.mouseWheelUp = Button4; + WINGsConfiguration.mouseWheelDown = Button5; + } + WINGsConfiguration.defaultFontSize = - WMGetUDIntegerForKey(defaults, "DefaultFontSize"); + WMGetUDIntegerForKey(defaults, "DefaultFontSize"); } - + if (!WINGsConfiguration.systemFont) { WINGsConfiguration.systemFont = SYSTEM_FONT; @@ -53,6 +100,12 @@ W_ReadConfigurations(void) if (WINGsConfiguration.doubleClickDelay == 0) { WINGsConfiguration.doubleClickDelay = 250; } + if (WINGsConfiguration.mouseWheelUp == 0) { + WINGsConfiguration.mouseWheelUp = Button4; + } + if (WINGsConfiguration.mouseWheelDown == 0) { + WINGsConfiguration.mouseWheelDown = Button5; + } if (WINGsConfiguration.defaultFontSize == 0) { WINGsConfiguration.defaultFontSize = 12; } diff --git a/WINGs/wpopupbutton.c b/WINGs/wpopupbutton.c index 2353594e..59e6a8f0 100644 --- a/WINGs/wpopupbutton.c +++ b/WINGs/wpopupbutton.c @@ -635,6 +635,37 @@ autoScroll(void *data) static void +wheelScrollUp(PopUpButton *bPtr) +{ + int testIndex = bPtr->selectedItemIndex - 1; + + while (testIndex>=0 && !WMGetPopUpButtonItemEnabled(bPtr, testIndex)) + testIndex--; + if (testIndex != -1) { + WMSetPopUpButtonSelectedItem(bPtr, testIndex); + if (bPtr->action) + (*bPtr->action)(bPtr, bPtr->clientData); + } +} + + +static void +wheelScrollDown(PopUpButton *bPtr) +{ + int itemCount = WMGetBagItemCount(bPtr->items); + int testIndex = bPtr->selectedItemIndex + 1; + + while (testIndexaction) + (*bPtr->action)(bPtr, bPtr->clientData); + } +} + + +static void handleActionEvents(XEvent *event, void *data) { PopUpButton *bPtr = (PopUpButton*)data; @@ -699,6 +730,14 @@ handleActionEvents(XEvent *event, void *data) if (!bPtr->flags.enabled) break; + if (!bPtr->flags.pullsDown && !bPtr->menuView->flags.mapped) { + if (event->xbutton.button==WINGsConfiguration.mouseWheelDown) { + wheelScrollDown(bPtr); + } else if (event->xbutton.button==WINGsConfiguration.mouseWheelUp) { + wheelScrollUp(bPtr); + } + break; + } popUpMenu(bPtr); if (!bPtr->flags.pullsDown) { bPtr->highlightedItem = bPtr->selectedItemIndex; @@ -714,6 +753,10 @@ handleActionEvents(XEvent *event, void *data) break; case ButtonRelease: + if (event->xbutton.button==WINGsConfiguration.mouseWheelUp || + event->xbutton.button==WINGsConfiguration.mouseWheelDown) { + break; + } XUngrabPointer(bPtr->view->screen->display, event->xbutton.time); if (!bPtr->flags.pullsDown) popDownMenu(bPtr); @@ -725,9 +768,9 @@ handleActionEvents(XEvent *event, void *data) if (bPtr->flags.insideMenu && bPtr->highlightedItem>=0) { WMMenuItem *item; - + item = WMGetPopUpButtonMenuItem(bPtr, bPtr->highlightedItem); - + if (WMGetMenuItemEnabled(item)) { int i; WMSetPopUpButtonSelectedItem(bPtr, bPtr->highlightedItem); diff --git a/WINGs/wscroller.c b/WINGs/wscroller.c index faa047a4..f9ed9602 100644 --- a/WINGs/wscroller.c +++ b/WINGs/wscroller.c @@ -815,14 +815,29 @@ handleActionEvents(XEvent *event, void *data) case ButtonPress: /* FIXME: change Mod1Mask with something else */ - handlePush(sPtr, event->xbutton.x, event->xbutton.y, - (event->xbutton.state & Mod1Mask) - ||event->xbutton.button==Button2); - /* continue scrolling if pushed on the buttons */ - if (sPtr->flags.hitPart == WSIncrementLine - || sPtr->flags.hitPart == WSDecrementLine) { - sPtr->timerID = WMAddTimerHandler(AUTOSCROLL_INITIAL_DELAY, - autoScroll, sPtr); + if (event->xbutton.button==WINGsConfiguration.mouseWheelUp) { + sPtr->flags.decrDown = 1; + sPtr->flags.hitPart = WSDecrementPage; + if (sPtr->action) { + (*sPtr->action)(sPtr, sPtr->clientData); + } + } + else if (event->xbutton.button==WINGsConfiguration.mouseWheelDown) { + sPtr->flags.incrDown = 1; + sPtr->flags.hitPart = WSIncrementPage; + if (sPtr->action) { + (*sPtr->action)(sPtr, sPtr->clientData); + } + } else { + handlePush(sPtr, event->xbutton.x, event->xbutton.y, + (event->xbutton.state & Mod1Mask) + ||event->xbutton.button==Button2); + /* continue scrolling if pushed on the buttons */ + if (sPtr->flags.hitPart == WSIncrementLine + || sPtr->flags.hitPart == WSDecrementLine) { + sPtr->timerID = WMAddTimerHandler(AUTOSCROLL_INITIAL_DELAY, + autoScroll, sPtr); + } } break; diff --git a/WINGs/wslider.c b/WINGs/wslider.c index 6494df80..d69a31a4 100644 --- a/WINGs/wslider.c +++ b/WINGs/wslider.c @@ -481,7 +481,28 @@ handleActionEvents(XEvent *event, void *data) switch (event->type) { case ButtonPress: - if (getSliderPart(sPtr, event->xbutton.x, event->xbutton.y)==KNOB_PART) + if (event->xbutton.button==WINGsConfiguration.mouseWheelUp + &&!sPtr->flags.dragging) { + // Wheel up + if (sPtr->value+1<=sPtr->maxValue) { + WMSetSliderValue(sPtr, sPtr->value+1); + if (sPtr->flags.continuous && sPtr->action) { + (*sPtr->action)(sPtr, sPtr->clientData); + } + } + } else if (event->xbutton.button==WINGsConfiguration.mouseWheelDown + &&!sPtr->flags.dragging) { + // Wheel down + if (sPtr->value-1>=sPtr->minValue) + { + WMSetSliderValue(sPtr, sPtr->value-1); + if (sPtr->flags.continuous && sPtr->action) { + (*sPtr->action)(sPtr, sPtr->clientData); + } + } + } + else if (getSliderPart(sPtr, event->xbutton.x, event->xbutton.y) + ==KNOB_PART) sPtr->flags.dragging = 1; else { #ifdef STRICT_NEXT_BEHAVIOUR diff --git a/WindowMaker/Defaults/WMGLOBAL b/WindowMaker/Defaults/WMGLOBAL index bd4f9311..182a08a1 100644 --- a/WindowMaker/Defaults/WMGLOBAL +++ b/WindowMaker/Defaults/WMGLOBAL @@ -3,4 +3,6 @@ BoldSystemFont = "-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*"; MultiByteText = NO; DoubleClickTime = 250; + MouseWheelUp = Button4; + MouseWheelDown = Button5; } -- 2.11.4.GIT