summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2024-09-26 17:59:52 +0200
committerAlbrecht Schlosser <fltk@aljus.de>2024-10-06 18:53:03 +0200
commit4f4a9be15b0c52837dd4d4a04ff021cc3e5d691e (patch)
treea7238b08a93b2af73c4df86a66b7abfa47689e76 /FL
parent3fbd4f944f0a6e16630974e56e1e896eb7bbf6f7 (diff)
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.
Diffstat (limited to 'FL')
-rw-r--r--FL/Enumerations.H24
-rw-r--r--FL/Fl.H81
2 files changed, 67 insertions, 38 deletions
diff --git a/FL/Enumerations.H b/FL/Enumerations.H
index 1beb450e5..97b4c7029 100644
--- a/FL/Enumerations.H
+++ b/FL/Enumerations.H
@@ -548,9 +548,11 @@ enum Fl_Callback_Reason {
/**@{*/
-#define FL_LEFT_MOUSE 1 ///< The left mouse button
-#define FL_MIDDLE_MOUSE 2 ///< The middle mouse button
-#define FL_RIGHT_MOUSE 3 ///< The right mouse button
+#define FL_LEFT_MOUSE 1 ///< The left mouse button
+#define FL_MIDDLE_MOUSE 2 ///< The middle mouse button
+#define FL_RIGHT_MOUSE 3 ///< The right mouse button
+#define FL_BACK_MOUSE 4 ///< The back mouse button (side button 1)
+#define FL_FORWARD_MOUSE 5 ///< The forward mouse button (side button 2)
/**@}*/ // group: Mouse Buttons
@@ -575,11 +577,17 @@ enum Fl_Callback_Reason {
// correct for XFree86
#define FL_SCROLL_LOCK 0x00800000 ///< The scroll lock is on
// correct for XFree86
-#define FL_BUTTON1 0x01000000 ///< Mouse button 1 is pushed (L)
-#define FL_BUTTON2 0x02000000 ///< Mouse button 2 is pushed (M)
-#define FL_BUTTON3 0x04000000 ///< Mouse button 3 is pushed (R)
-#define FL_BUTTONS 0x07000000 ///< Any mouse button (1-3) is pushed
-#define FL_BUTTON(n) (0x00800000<<(n)) ///< Mouse button n (n > 0) is pushed
+// Mouse buttons
+
+#define FL_BUTTON1 0x01000000 ///< Mouse button 1 is pushed (L)
+#define FL_BUTTON2 0x02000000 ///< Mouse button 2 is pushed (M)
+#define FL_BUTTON3 0x04000000 ///< Mouse button 3 is pushed (R)
+#define FL_BUTTON4 0x08000000 ///< Mouse button 4 is pushed (BACK)
+#define FL_BUTTON5 0x10000000 ///< Mouse button 5 is pushed (FORWARD)
+#define FL_BUTTONS 0x1f000000 ///< Bitmask: any mouse button (1-5) is pushed
+
+#define FL_BUTTON(n) (0x00800000<<(n)) ///< Mouse button n (n = 1..5) is pushed,
+ ///< *undefined* if n outside 1..5
#define FL_KEY_MASK 0x0000ffff ///< All keys are 16 bit for now
// FIXME: Unicode needs 21 bits!
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;}
/** @} */
/**