[RFC PATCH inputproto] specs: Add new SwitchClass

Peter Hutterer peter.hutterer at who-t.net
Sun May 22 19:27:48 PDT 2011


Switches are different to buttons in that they usually provide permanent
state over temporary state. While a button's natural state is 0 (released),
a switch's natural state may be either on (1) or off (0).

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
I had this at some point for XI 2.0 but kicked it out due to time reasons.
Not sure I'll be able to implement the server support by the 1.11 merge
window so this may have to wait, but comments would be appreciated.

It's fairly straightforward and essentially a copy of the button handling.
One thing missing that I'm not convinced we need yet is a passive grab
type on SwithOn. Skipping that makes switch handling significantly easier.

Cheers,
  Peter

 XI2.h              |   10 +++++++-
 specs/XI2proto.txt |   62 +++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/XI2.h b/XI2.h
index a80d5a6..8b5a4ac 100644
--- a/XI2.h
+++ b/XI2.h
@@ -159,7 +159,11 @@
 #define XI_RawButtonPress                15
 #define XI_RawButtonRelease              16
 #define XI_RawMotion                     17
-#define XI_LASTEVENT                     XI_RawMotion
+#define XI_SwitchOn                      18
+#define XI_SwitchOff                     19
+#define XI_RawSwitchOn                   20
+#define XI_RawSwitchOff                  21
+#define XI_LASTEVENT                     XI_RawSwitchOff
 /* NOTE: XI2LASTEVENT in xserver/include/inputstr.h must be the same value
  * as XI_LASTEVENT if the server is supposed to handle masks etc. for this
  * type of event. */
@@ -185,5 +189,9 @@
 #define XI_RawButtonPressMask            (1 << XI_RawButtonPress)
 #define XI_RawButtonReleaseMask          (1 << XI_RawButtonRelease)
 #define XI_RawMotionMask                 (1 << XI_RawMotion)
+#define XI_SwitchOnMask                  (1 << XI_SwitchOn)
+#define XI_SwitchOffMask                 (1 << XI_SwitchOff)
+#define XI_RawSwitchOnMask               (1 << XI_RawSwitchOn)
+#define XI_RawSwitchOffMask              (1 << XI_RawSwitchOff)
 
 #endif /* _XI2_H_ */
diff --git a/specs/XI2proto.txt b/specs/XI2proto.txt
index ef9b5b5..d7e03f5 100644
--- a/specs/XI2proto.txt
+++ b/specs/XI2proto.txt
@@ -40,6 +40,8 @@ Changes introduced by version 2.1
 
 - RawEvents are sent regardless of the grab state.
 - XIGrabDevice takes  a confine_to parameter
+- Addition of SwitchClass and SwitchOn, SwitchOff, RawSwitchOn, and
+  RawSwitchOff events
 
 //                            ❧❧❧❧❧❧❧❧❧❧❧
 
@@ -236,6 +238,10 @@ ClientPointer to a different master pointer.
             The INT32 contains the integral part, the CARD32 the decimal fraction
             shifted by 32.
 
+    SWITCHMASK
+            A binary mask defined as (1 << switch number).
+            A SETofSWITCHMASK is a binary OR of zero or more SWITCHMASK.
+
     VALUATORMASK
             A binary mask defined as (1 << valuator number).
             A SETofVALUATORMASK is a binary OR of zero or more VALUATORMASK.
@@ -306,7 +312,7 @@ If major_version is less than 2, a BadValue error occurs.
                  name:                  LISTofCHAR8
                  classes:               LISTofCLASS }
 
-    CLASS { BUTTONCLASS, KEYCLASS, AXISCLASS }
+    CLASS { BUTTONCLASS, KEYCLASS, AXISCLASS, SWITCHCLASS }
 
     BUTTONCLASS { type:                 ButtonClass
                   length:               CARD16
@@ -331,6 +337,15 @@ If major_version is less than 2, a BadValue error occurs.
                   value:                FP3232
                   resolution:           CARD32 }
 
+    SWITCHCLASS*{ type:                 SwitchClass
+                  length:               CARD16
+                  sourceid:             CARD16
+                  switch_len:           CARD16
+                  state:                SETofSWITCHMASK
+                  labels:               LISTofATOM }
+
+    * since XI 2.1
+
 XIQueryDevice details information about the requested input devices.
 
     devices
@@ -373,7 +388,8 @@ Each deviceinfo is detailed as follows:
 For all classes, type specifies the device class. Clients are required
 to ignore unknown device classes. The length field specifies the length
 of the class in 4 byte units.
-The following classes may occur only once: ButtonClass, KeyClass
+The following classes may occur only once: ButtonClass, KeyClass,
+SwitchClass
 
     ButtonClass:
     type
@@ -430,6 +446,27 @@ The following classes may occur only once: ButtonClass, KeyClass
     value
         Last published axis value (if mode is absolute).
 
+    SwitchClass:
+    type
+        Always SwitchClass.
+    length
+        Length in 4 byte units.
+    sourceid
+        The device this class originates from.
+    num_switches
+        Number of switches provided by the device.
+    labels
+        List of Atoms specifying the label for each switch. An Atom of None
+        specifies an unlabeled switch.
+    state
+        The current switch mask for this device.
+        Each bit representing a switch is 1 if this switch is
+        logically on, or 0 otherwise. State is a multiple of 4-byte units
+        and always contains at least num_switch bits.
+
+SwitchClass was introduced in XI 2.1 and is only available to clients
+supporting version 2.1 or later.
+
 An axis in Relative mode may specify min and max as a hint to the
 client. If no min and max information is available, both must be 0.
 
@@ -1389,6 +1426,11 @@ Version 2.0:
         FocusIn
         FocusOut
         PropertyEvent
+Version 2.1:
+        SwitchOn
+        SwitchOff
+        RawSwitchOn
+        RawSwitchOff
 
 All events have a set of common fields specified as EVENTHEADER.
 
@@ -1517,8 +1559,12 @@ For a detailed description of classes, see the XQueryDevice request.
             buttons:                    SETofBUTTONMASK
             valuators:                  SETofVALUATORMASK
             axisvalues:                 LISTofFP3232
+            switches_len*:              CARD16
+            switches*:                  SETofSWITCHMASK
     └───
 
+    * since XI 2.1
+
     BUTTONBIT { (1 << Button1), (1 << Button2), ... , (1 << ButtonN) }
     VALUATORBIT { (1 << 1), ( 1 << 2), ... ( 1 << n) }
 
@@ -1537,11 +1583,13 @@ For a detailed description of classes, see the XQueryDevice request.
 
 An XIDeviceEvent is generated whenever the logical state of a device
 changes in response to a button press, a button release, a motion, a key
-press or a key release. The event type may be one of KeyPress,
-KeyRelease, ButtonPress, ButtonRelease, Motion.
+press, a key release, or a switch state change. The event type may be one of
+KeyPress, KeyRelease, ButtonPress, ButtonRelease, Motion, SwitchOn,
+SwitchOff. Event types SwitchOn and SwitchOn are only available to clients
+supporting XI 2.1 or later.
 
     detail
-        The button number or key code, or 0.
+        The button number or key code or switch number, or 0.
     root
     event
     child
@@ -1578,6 +1626,10 @@ KeyRelease, ButtonPress, ButtonRelease, Motion.
         KeyRepeat means that this event is for repeating purposes, and
         the physical state of the key has not changed.  This is only
         valid for KeyPress events.
+    switches_len
+        The length of switches in 4 byte units.
+    switches
+        Switch state before the event.
 
 Modifier state in mods is detailed as follows:
 
-- 
1.7.4.4



More information about the xorg-devel mailing list