summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FL/Enumerations.H20
-rw-r--r--FL/Fl.H8
-rw-r--r--src/Fl_x.cxx22
3 files changed, 36 insertions, 14 deletions
diff --git a/FL/Enumerations.H b/FL/Enumerations.H
index ff2f163e1..d944a13a2 100644
--- a/FL/Enumerations.H
+++ b/FL/Enumerations.H
@@ -562,8 +562,8 @@ enum Fl_Callback_Reason {
/**@{*/ // group: Event States
-// FIXME: it would be nice to have the modifiers in the upper 8 bit so that
-// a unicode key (24bit) can be sent as an unsigned with the modifiers.
+// FIXME: it would be nice to have the modifiers in the upper 8 bits so that
+// a unicode key (21 bits) can be sent as an unsigned with the modifiers.
#define FL_SHIFT 0x00010000 ///< One of the shift keys is down
#define FL_CAPS_LOCK 0x00020000 ///< The caps lock is on
@@ -575,14 +575,14 @@ 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
-#define FL_BUTTON2 0x02000000 ///< Mouse button 2 is pushed
-#define FL_BUTTON3 0x04000000 ///< Mouse button 3 is pushed
-#define FL_BUTTONS 0x7f000000 ///< Any mouse button is pushed
-#define FL_BUTTON(n) (0x00800000<<(n)) ///< Mouse button n (n > 0) is pushed
-
-#define FL_KEY_MASK 0x0000ffff ///< All keys are 16 bit for now
- // FIXME: Unicode needs 24 bits!
+#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
+
+#define FL_KEY_MASK 0x0000ffff ///< All keys are 16 bit for now
+ // FIXME: Unicode needs 21 bits!
/**@}*/ // group: Event States
diff --git a/FL/Fl.H b/FL/Fl.H
index 8d86370f3..796843d75 100644
--- a/FL/Fl.H
+++ b/FL/Fl.H
@@ -1263,22 +1263,22 @@ public:
caused an FL_RELEASE event, you can use Fl::event_button() instead.
\return a bit mask value like { [FL_BUTTON1] | [FL_BUTTON2] | [FL_BUTTON3] }
*/
- static int event_buttons() {return e_state&0x7f000000;}
+ static int event_buttons() {return e_state & FL_BUTTONS;}
/**
Returns non-zero if mouse button 1 is currently held down.
For more details, see Fl::event_buttons().
*/
- static int event_button1() {return e_state&FL_BUTTON1;}
+ static int event_button1() {return e_state & FL_BUTTON1;}
/**
Returns non-zero if button 2 is currently held down.
For more details, see Fl::event_buttons().
*/
- static int event_button2() {return e_state&FL_BUTTON2;}
+ static int event_button2() {return e_state & FL_BUTTON2;}
/**
Returns non-zero if button 3 is currently held down.
For more details, see Fl::event_buttons().
*/
- static int event_button3() {return e_state&FL_BUTTON3;}
+ static int event_button3() {return e_state & FL_BUTTON3;}
/** @} */
/**
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx
index 00ddaed2e..dcae946ab 100644
--- a/src/Fl_x.cxx
+++ b/src/Fl_x.cxx
@@ -972,6 +972,28 @@ char fl_key_vector[32]; // used by Fl::get_key()
static int px, py;
static ulong ptime;
+// Citation from XButtonEvent and XKeyEvent docs:
+// "The state member is set to indicate the logical state of the pointer buttons
+// and modifier keys just prior to the event, which is the bitwise inclusive OR
+// of one or more of the button or modifier key masks:
+// Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask,
+// ShiftMask, LockMask, ControlMask,
+// Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, and Mod5Mask."
+//
+// Actual values in Debian Bookworm as of July 2024 (pseudo code):
+// static int states[] = {
+// ShiftMask, LockMask, ControlMask, // 1<<0 .. 1<<2
+// Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask, // 1<<3 .. 1<<7
+// Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask // 1<<8 .. 1<<12
+// };
+//
+// Note: some more (undefined?) state bits *can* be set if the user uses a keyboard
+// other than the primary one (the top-most in keyboard settings). Therefore we must
+// take care not to use these undefined bits. These undefined bits will be set in
+// Fl::event_state() though: for backwards compatibility and transparency.
+// See definition of FL_BUTTONS in FL/Enumerations.H: only three "sticky" mouse
+// buttons as of July 2024.
+
static void set_event_xy(Fl_Window *win) {
# if FLTK_CONSOLIDATE_MOTION
send_motion = 0;