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. --- FL/Fl.H | 81 +++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 30 deletions(-) (limited to 'FL/Fl.H') diff --git a/FL/Fl.H b/FL/Fl.H index 57be52e5d..fceafc4c8 100644 --- a/FL/Fl.H +++ b/FL/Fl.H @@ -705,40 +705,51 @@ public: This returns garbage if the most recent event was not a FL_PUSH or FL_RELEASE event. \retval FL_LEFT_MOUSE \retval FL_MIDDLE_MOUSE - \retval FL_RIGHT_MOUSE. - \see Fl::event_buttons() + \retval FL_RIGHT_MOUSE + \retval FL_BACK_MOUSE + \retval FL_FORWARD_MOUSE. + \see Fl::event_buttons(), Fl::event_state() */ - static int event_button() {return e_keysym-FL_Button;} + static int event_button() { return e_keysym - FL_Button; } /** Returns the keyboard and mouse button states of the last event. This is a bitfield of what shift states were on and what mouse buttons were held down during the most recent event. - The legal event state bits are: - - - FL_SHIFT - - FL_CAPS_LOCK - - FL_CTRL - - FL_ALT - - FL_NUM_LOCK - - FL_META - - FL_SCROLL_LOCK - - FL_BUTTON1 - - FL_BUTTON2 - - FL_BUTTON3 - - \note FLTK platforms differ in what Fl::event_state() returns when it is called while a modifier key - is being pressed or released. - Under X11 and Wayland, Fl::event_state() indicates the state of the modifier keys just \b prior to the event. - Thus, during the FL_KEYDOWN event generated when pressing the shift key, for example, the FL_SHIFT bit of event_state() - is 0 and becomes 1 only at the next event (which can be another FL_KEYDOWN, FL_DRAG or FL_KEYUP). - Under other platforms, the reported state of modifier keys includes that of the key being pressed or released. - Notice that Fl::event_state() returns the same value under all platforms when it's called while a non-modifier key - (e.g., a letter, a function key) is being pressed or released. - X servers do not agree on shift states, and FL_NUM_LOCK, FL_META, and - FL_SCROLL_LOCK may not work. The values were selected to match the - XFree86 server on Linux. + \note FLTK platforms differ in what Fl::event_state() returns when it is called + while a modifier key or mouse button is being pressed or released. + + - Under X11 and Wayland, Fl::event_state() indicates the state of the modifier keys and + mouse buttons just \b prior to the event. Thus, during the \c FL_KEYDOWN event generated + when pressing the shift key, for example, the \c FL_SHIFT bit of event_state() is 0 and + becomes 1 only at the next event which can be any other event, including e.g. \c FL_MOVE. + - Under other platforms the reported state of modifier keys or mouse buttons includes that + of the key or button being pressed or released. + - Fl::event_state() returns the same value under all platforms when it's called while a + non-modifier key (e.g. a letter or function key) is being pressed or released. + - X servers do not agree on shift states, and \c FL_NUM_LOCK, \c FL_META, and \c FL_SCROLL_LOCK + may not work. + - The values were selected to match the XFree86 server on Linux. + + \note This inconsistency \b may be fixed (on X11 and Wayland) in a later release. + + The legal event state bits are: + + | Device | State Bit | Key or Button | Since | + |----------|----------------|-------------------------|-------| + | Keyboard | FL_SHIFT | Shift | | + | Keyboard | FL_CAPS_LOCK | Caps Lock | | + | Keyboard | FL_CTRL | Ctrl | | + | Keyboard | FL_ALT | Alt | | + | Keyboard | FL_NUM_LOCK | Num Lock | | + | Keyboard | FL_META | Meta, e.g. "Windows" | | + | Keyboard | FL_SCROLL_LOCK | Scroll Lock | | + | Mouse | FL_BUTTON1 | left button | | + | Mouse | FL_BUTTON2 | middle button | | + | Mouse | FL_BUTTON3 | right button | | + | Mouse | FL_BUTTON4 | side button 1 (back) | 1.4.0 | + | Mouse | FL_BUTTON5 | side button 2 (forward) | 1.4.0 | */ static int event_state() {return e_state;} @@ -1267,7 +1278,7 @@ public: time of the event. During an FL_RELEASE event, the state of the released button will be 0. To find out, which button caused an FL_RELEASE event, you can use Fl::event_button() instead. - \return a bit mask value like { [FL_BUTTON1] | [FL_BUTTON2] | [FL_BUTTON3] } + \return a bit mask value like { [FL_BUTTON1] | [FL_BUTTON2] | ... | [FL_BUTTON5] } */ static int event_buttons() {return e_state & FL_BUTTONS;} /** @@ -1276,15 +1287,25 @@ public: */ static int event_button1() {return e_state & FL_BUTTON1;} /** - Returns non-zero if button 2 is currently held down. + Returns non-zero if mouse button 2 is currently held down. For more details, see Fl::event_buttons(). */ static int event_button2() {return e_state & FL_BUTTON2;} /** - Returns non-zero if button 3 is currently held down. + Returns non-zero if mouse button 3 is currently held down. For more details, see Fl::event_buttons(). */ static int event_button3() {return e_state & FL_BUTTON3;} + /** + Returns non-zero if mouse button 4 is currently held down. + For more details, see Fl::event_buttons(). + */ + static int event_button4() {return e_state & FL_BUTTON4;} + /** + Returns non-zero if mouse button 5 is currently held down. + For more details, see Fl::event_buttons(). + */ + static int event_button5() {return e_state & FL_BUTTON5;} /** @} */ /** -- cgit v1.2.3