Click lock

Click lock allows holding a button logically down without requiring that button to be physically held. Where enabled, a button that is held down without moving for a while stays logically down after it is physically released. The user can then move the pointer, e.g. to drag a window or select text, and click again to release the button. Windows provides the same feature as ClickLock.

Click lock is available on devices with relative motion and a left button, e.g. mice, trackballs and trackpoints. It is not available on touchpads, or on devices that also report an absolute position, e.g. the virtual mouse of some virtual machines. It is disabled by default.

Behavior

The exact behavior of click lock is implementation-defined. As a general rule, the following can be expected in the timeout mode:

  • a button press starts a hold. If the button is released before the timeout or moves more than the motion threshold, it is a normal click

  • if the button is released after the timeout, no release event is generated and the button stays logically down, it is locked

  • pressing another button while a button is locked generates a release event for the locked button (and thus unlocks it). Then the other button’s events are passed on.

  • a button can only be locked if it is the only button held down during the timeout, i.e. if at any time two buttons are down simultaneously, neither button can lock.

  • once locked, motion does not release the button.

The button is logically released if:

  • the locked button is pressed and released. The logical release event is generated once the press event is received, the release event is discarded. Motion while that button is down, e.g. from a tremor, does not move whatever the button was dragging.

  • a different button is pressed. The logical release event for the locked button is generated once the other button’s press event is received.

A locked button is also logically released, immediately, when

  • click lock is disabled or the locked button is removed from the configured buttons

  • the device is removed or disabled (see Send Events Mode in Configuration options), or libinput is suspended

Click lock is per device. A button press on one device does not release a button locked on another device.

For example, a button that is held past the timeout, then moved and clicked again generates the following event sequence:

Action

Event

Button down
button press
Wait past the timeout
no event
Button up
no event, now locked
Device motion
pointer motion
Button down
button release
Button up
no event

A different button releases the lock and passes on its own events:

Action

Event

Left button down
left button press
Wait past the timeout
no event
Left button up
no event, now locked
Right button down

left button release
right button press
Right button up
right button release

A button that moves past the motion threshold before it is released is a normal drag:

Action

Event

Button down
button press
Motion past the threshold
pointer motion
Wait past the timeout
no event
Button up
button release

Configuration

libinput provides libinput_device_config_click_lock_set_mode() to select the click lock mode, and libinput_device_config_click_lock_set_timeout(), libinput_device_config_click_lock_set_buttons() and libinput_device_config_click_lock_set_threshold() for the options below.

Click lock has the following configuration options:

  • the mode, disabled by default. The only other mode is the timeout mode described above, other modes may be added in the future

  • the timeout, i.e. how long a button has to be held to lock, 1.2s by default. The maximum is implementation-defined. There is no minimum: with a timeout of 0 a button that is released without having moved past the motion threshold locks, however short the press. Every click then locks the button and the next click releases it, so user interfaces may want to restrict the timeout to e.g. 200ms and above

  • the buttons that can be locked, as a list of evdev button codes, e.g. BTN_LEFT, BTN_RIGHT, BTN_MIDDLE or BTN_SIDE. The default is BTN_LEFT only. The buttons are the button codes as reported in button events, i.e. with left-handed mode enabled BTN_LEFT is the physical right button. It is not an error to give a button that the device does not have. With an empty list no button is locked

  • the motion threshold in mm, 1mm by default. The maximum is implementation-defined. With a threshold of 0 any motion while the button is held ends the hold. For devices that do not provide their resolution, e.g. most mice, libinput assumes a resolution of 1000dpi. For a trackpoint the distance is calculated from the relative motion it reports, as for a mouse, it is not the distance the finger moves

Interaction with other features

The button used for on-button scrolling never locks, but pressing it releases a locked button. While it is held down, no other button starts a hold.

With middle button emulation enabled, an emulated middle button can lock if the middle button is one of the buttons click lock can lock.

On laptops with a trackpoint, e.g. Lenovo ThinkPads, the buttons above the touchpad (physical or top software buttons) are buttons of the trackpoint device and use the trackpoint’s click lock configuration. Only the trackpoint’s motion counts towards the motion threshold: a drag with one of these buttons and a finger on the touchpad locks the button if it is held past the timeout.