This site has been retired. For up to date information, see handbook.gnome.org or gitlab.gnome.org.


[Home] [TitleIndex] [WordIndex

Background

GTK+ uses XInput2 for input events, which caters for a fully dynamic device hierarchy, and support for multiple pointer/keyboard pairs.

carlos@sacarino:~$ xinput list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Wacom ISDv4 E6 Pen stylus                 id=10   [slave  pointer  (2)]
⎜   ↳ Wacom ISDv4 E6 Finger touch               id=11   [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=13   [slave  pointer  (2)]
⎜   ↳ TPPS/2 IBM TrackPoint                     id=14   [slave  pointer  (2)]
⎜   ↳ Wacom ISDv4 E6 Pen eraser                 id=16   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Sleep Button                              id=8    [slave  keyboard (3)]
    ↳ Integrated Camera                         id=9    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=12   [slave  keyboard (3)]
    ↳ ThinkPad Extra Buttons                    id=15   [slave  keyboard (3)]
carlos@sacarino:~$ xinput create-master eek
carlos@sacarino:~$ xinput list
  ...
⎡ eek pointer                                   id=17   [master pointer  (18)]
⎜   ↳ eek XTEST pointer                         id=19   [slave  pointer  (17)]
⎣ eek keyboard                                  id=18   [master keyboard (17)]
    ↳ eek XTEST keyboard                        id=20   [slave  keyboard (18)]
carlos@sacarino:~$ xinput reattach 10 17
carlos@sacarino:~$ xinput list
  ...
⎡ eek pointer                                   id=17   [master pointer  (18)]
⎜   ↳ Wacom ISDv4 E6 Pen stylus                 id=10   [slave  pointer  (17)]
⎜   ↳ eek XTEST pointer                         id=19   [slave  pointer  (17)]
⎣ eek keyboard                                  id=18   [master keyboard (17)]
    ↳ eek XTEST keyboard                        id=20   [slave  keyboard (18)]

Listing and modifying the device hierarchy

The device hierarchy is formed by master and slave devices. Master devices are those represented in the screen (ie. mouse cursor and keyboard focus indicator), while slave devices represent the hardware connected to the computer. Slave devices can be either connected to a master (thus being able to drive them) or floating.

The client pointer

Under the presence of multiple pointers, XInput2 uses the "client pointer" principle to allow several legacy applications to interact simultaneously with different pointer/keyboard pairs, it would be usually set by the window manager for a focused window, so different applications could have different client pointers.

Under the hood, X11 uses the client pointer (or its paired keyboard) to satisfy core calls such as XGrabPointer/Keyboard, XQueryPointer and others that have been superseded by XInput2

Apps that don't want to deal with devices

There are applications that could have little gain in being multidevice aware, but there are still stituations where a device could be needed (eg. popping up a menu on the pointer coordinates).

For such applications, the client pointer may be a good approximation for these operations.

GdkDisplay *display;
GdkDeviceManager *device_manager;
GdkDevice *client_pointer, client_keyboard;

display = gdk_display_get_default ();
device_manager = gdk_display_get_device_manager (display);
client_pointer = gdk_device_manager_get_client_pointer (device_manager);

/* Or if we need a keyboard too */
client_keyboard = gdk_device_get_associated_device (client_pointer);

Getting the client pointer and keyboard

With multiple pointers, this gives a behavior most similar to that of legacy applications (i.e. gtk+2)

Dealing with multiple devices

There may be several usecases to deal with multiple devices, but the patterns to make them work are about the same

Event handling

Reacting differently to devices

Grabs

Handling broken grabs

Handling multipointer

Reading device axes

Getting to know a device axes

Getting an axis value

Dealing directly with slave (or floating) devices

enabling events for a slave device

Recommendations


2024-10-23 11:37