From 4f4a9be15b0c52837dd4d4a04ff021cc3e5d691e Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Thu, 26 Sep 2024 17:59:52 +0200 Subject: Support mouse buttons 4 + 5 (aka "side buttons") (#1076, #1068) This work is based on PR 1068 (patch by @CendioHalim) and extended to store button status (4,5) in Fl::event_state() like it's done for other mouse buttons (1-3). Changes: - new symbol: FL_BUTTON4 = side button 1 = "back" - new symbol: FL_BUTTON5 = side button 2 = "forward" - modified : FL_BUTTONS now includes bits for two side buttons Note: the status of these new buttons is not maintained by X11, therefore we need to maintain them in internal variables for this platform. --- src/Fl_cocoa.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/Fl_cocoa.mm') diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index ddb96c6b2..369ce8444 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -1046,7 +1046,7 @@ static void cocoaMagnifyHandler(NSEvent *theEvent) */ static void cocoaMouseHandler(NSEvent *theEvent) { - static int keysym[] = { 0, FL_Button+1, FL_Button+3, FL_Button+2 }; + static int keysym[] = { 0, FL_Button+1, FL_Button+3, FL_Button+2, FL_Button+4, FL_Button+5 }; static int px, py; fl_lock_function(); @@ -1060,7 +1060,7 @@ static void cocoaMouseHandler(NSEvent *theEvent) float s = Fl::screen_driver()->scale(0); pos.x /= s; pos.y /= s; pos.y = window->h() - pos.y; - NSInteger btn = [theEvent buttonNumber] + 1; + NSInteger btn = [theEvent buttonNumber] + 1; NSUInteger mods = [theEvent modifierFlags]; int sendEvent = 0; @@ -1070,13 +1070,17 @@ static void cocoaMouseHandler(NSEvent *theEvent) if (btn == 1) Fl::e_state |= FL_BUTTON1; else if (btn == 3) Fl::e_state |= FL_BUTTON2; else if (btn == 2) Fl::e_state |= FL_BUTTON3; + else if (btn == 4) Fl::e_state |= FL_BUTTON4; + else if (btn == 5) Fl::e_state |= FL_BUTTON5; } else if (etype == NSEventTypeLeftMouseUp || etype == NSEventTypeRightMouseUp || etype == NSEventTypeOtherMouseUp) { if (btn == 1) Fl::e_state &= ~FL_BUTTON1; else if (btn == 3) Fl::e_state &= ~FL_BUTTON2; else if (btn == 2) Fl::e_state &= ~FL_BUTTON3; - } + else if (btn == 4) Fl::e_state &= ~FL_BUTTON4; + else if (btn == 5) Fl::e_state &= ~FL_BUTTON5; + } switch ( etype ) { case NSEventTypeLeftMouseDown: -- cgit v1.2.3