Skip to content
Back to top
View this page

# Input Capture

## Description

Portal for permitting input capture

The InputCapture portal allows capturing input events from connected physical or logical devices. Capturing input has two distinct states: “enabled” where an application has requested that input should be captured once certain conditions are met (but no input events are being delivered yet) and “active”, when input events are being delivered to the application. An application can only control the “enabled” state, the compositor decides when to switch into the “active” state - and which devices to capture.

Once the compositor activates input capturing, events from physical or logical devices are sent directly to the application instead of using those events to update the pointer position on-screen. The compositor is in control of the input capturing and may filter events and/or stop capturing at any time.

Input capturing is an asynchronous operation using “triggers”. An application sets up a number of triggers but it is the compositor who decides when the trigger conditions are met. Currently, the only defined trigger are pointer barriers: horizontal or vertical “lines” on the screen that should trigger when the cursor moves across those lines. See org.freedesktop.portal.InputCapture.SetPointerBarriers.

There is currently no way for an application to activate immediate input capture.

The InputCapture portal merely manages the logic when input should be captured. The transport of actual input events is delegated to a transport layer, specifically libei. See org.freedesktop.portal.InputCapture.ConnectToEIS.

This documentation describes version 2 of this interface.

## Properties

### org.freedesktop.portal.InputCapture:SupportedCapabilities

    SupportedCapabilities readable u

A bitmask of supported capabilities. This list is constant, it is not the list of capabilities currently available but rather which capabilies are implemented by the portal.

Applications must ignore unknown capabilities.

Currently defined types are:

- `1`: KEYBOARD

- `2`: POINTER

- `4`: TOUCHSCREEN

### org.freedesktop.portal.InputCapture:version

    version readable u

## Methods

### org.freedesktop.portal.InputCapture.CreateSession

    CreateSession (
      IN parent_window s,
      IN options a{sv},
      OUT handle o
    )

This method was deprecated in version 2 of this interface, see CreateSession2 instead.

Create an input capture session. A successfully created session can at any time be closed using org.freedesktop.portal.Session.Close, or may at any time be closed by the portal implementation, which will be signalled via org.freedesktop.portal.Session::Closed.

Supported keys in the `options` vardict include:

- `handle_token` (`s`)

  A string that will be used as the last element of the `handle`. Must be a valid object path element. See the Request documentation for more information about the `handle`.

- `session_handle_token` (`s`)

  A string that will be used as the last element of the session handle. Must be a valid object path element. See the Session documentation for more information about the session handle.

- `capabilities` (`u`)

  Bitmask of requested capabilities, see the SupportedCapabilities property. This value is required and must not be zero.

The following results get returned via the org.freedesktop.portal.Request::Response signal:

- `session_handle` (`o`)

  The session handle. An object path for the Session object representing the created session.

- `capabilities` (`u`)

  The capabilities available to this session. This is always a subset of the requested capabilities. See the SupportedCapabilities property for details. Note that while a capability may be available to a session, there is no guarantee a device with that capability is currently available or if one does become available that it will trigger input capture.

  It is best to view this set as a negative confirmation - a capability that was requested but is missing is an indication that this application may not capture events of that capability.

parent_window

  Identifier for the application window, see Window Identifiers

options

  Vardict with optional further information

handle

  Object path for the Request object representing this call

Warning

This method is deprecated.

### org.freedesktop.portal.InputCapture.CreateSession2

    CreateSession2 (
      IN options a{sv},
      OUT results a{sv}
    )

Create an input capture session. A successfully created session can at any time be closed using org.freedesktop.portal.Session.Close, or may at any time be closed by the portal implementation, which will be signalled via org.freedesktop.portal.Session::Closed.

The session must be started with org.freedesktop.portal.InputCapture.Start before using methods in this interface which take a session.

To capture clipboard content, you can call org.freedesktop.portal.Clipboard.RequestClipboard. When clipboard access has been granted (see clipboard_enabled in org.freedesktop.portal.InputCapture.Start), the clipboard may be accessed, but only when the session is active. See Clipboard for more information on the clipboard integration.

Supported keys in the `options` vardict include:

- `session_handle_token` (`s`)

  A string that will be used as the last element of the session handle. Must be a valid object path element. See the Session documentation for more information about the session handle.

Supported keys in the `results` vardict may include:

- `session_handle` (`o`)

  The session handle. An object path for the Session object representing the created session. Required.

This method was added in version 2 of this interface.

options

  Vardict with optional further information

results

### org.freedesktop.portal.InputCapture.Start

    Start (
      IN session_handle o,
      IN parent_window s,
      IN options a{sv},
      OUT handle o
    )

Start the input capture session. This will typically result in the portal presenting a dialog letting the user decide whether they want to allow the input of the session to be captured, and what capabilities to support.

This method may only be called once on a session previously created with CreateSession2. Sessions created by the deprecated CreateSession are immediately started.

Supported keys in the `options` vardict include:

- `handle_token` (`s`)

  A string that will be used as the last element of the `handle`. Must be a valid object path element. See the Request documentation for more information about the `handle`.

- `capabilities` (`u`)

  Bitmask of requested capabilities, see the SupportedCapabilities property. This value is required and must not be zero.

- `restore_token` (`s`)

  The token to restore a previous session.

  If the stored session cannot be restored, this value is ignored and the user will be prompted normally. This may happen when, for example, the session contains capabilities that are not available anymore, or when the stored permissions are withdrawn.

  The restore token is invalidated after using it once. To restore the same session again, use the new restore token sent in response to starting this session.

  This option was added in version 2 of this interface.

- `persist_mode` (`u`)

  How this session should persist. Default is 0. Accepted values are:

  - `0`: Do not persist (default)

  - `1`: Permissions persist as long as the application is running

  - `2`: Permissions persist until explicitly revoked

  If the permission for the session to persist is granted, a restore token will be returned via the org.freedesktop.portal.Request::Response signal of the start method used to start the session.

  This option was added in version 2 of this interface.

The following results get returned via the org.freedesktop.portal.Request::Response signal:

- `capabilities` (`u`)

  The capabilities available to this session. This is always a subset of the requested capabilities. See the SupportedCapabilities property for details. Note that while a capability may be available to a session, there is no guarantee a device with that capability is currently available or if one does become available that it will trigger input capture.

  It is best to view this set as a negative confirmation - a capability that was requested but is missing is an indication that this application may not capture events of that capability.

- `clipboard_enabled` (`b`)

  A boolean for whether the clipboard was enabled (‘true’) or not (‘false’). See the Clipboard documentation for more information.

- `restore_token` (`s`)

  The restore token. This token is a single use token that can later be used to restore a session. See org.freedesktop.portal.RemoteDesktop.SelectDevices for details.

  This response option was added in version 2 of this interface.

This method was added in version 2 of this interface.

session_handle

  Object path for the Session object

parent_window

  Identifier for the application window, see Window Identifiers

options

  Vardict with optional further information

handle

  Object path for the :ref:org.freedesktop.portal.Request object representing this call

### org.freedesktop.portal.InputCapture.GetZones

    GetZones (
      IN session_handle o,
      IN options a{sv},
      OUT handle o
    )

Retrieve the set of currently available input zones for this session. The zones may not be continuous and may be a logical representation of the physical screens (e.g. a 4k screen may be represented as low-resolution screen instead). A set of zones is identified by a unique zone_set ID.

The name “Zone” was chosen to provide distinction with the libei “Region”.

If the zones change (e.g. a monitor is unplugged), the org.freedesktop.portal.InputCapture::ZonesChanged signal is emitted and the application should re-request the current zones to update its internal state.

Note that zones are session-specific, there is no guarantee that two applications see the same screen zones. An empty zone list implies that no pointer barriers can be set.

Whenever the application calls GetZones, the current zone_set ID is returned that references the current set of zones. To establish a pointer barrier, the application must pass this ID to org.freedesktop.portal.InputCapture.SetPointerBarriers. A mismatch of zone_set IDs implies the application is not using the current zone set and pointer barriers will fail.

The zone_set ID increases by an unspecified amount with each change to the set of zones. Applications must be able to handle the zone_set ID wrapping around. Implementations of this portal must to increase the zone_set ID by a sensible amount to allow for wrapping detection.

The following results get returned via the org.freedesktop.portal.Request::Response signal:

- `zones` (`a(uuii)`)

  An array of regions, each specifying that zone’s width, height, x/y offset.

- `zone_set` (`u`)

  A unique ID to be used in the org.freedesktop.portal.InputCapture.SetPointerBarriers method to refer to this set of zones. This id increases by an unspecified amount whenever the zones change and pointer barriers can only be set up if the zone_set matches the most recent returned zone_set.

session_handle

  Object path for the Session object

options

  Vardict with optional further information

handle

  Object path for the Request object representing this call

### org.freedesktop.portal.InputCapture.SetPointerBarriers

    SetPointerBarriers (
      IN session_handle o,
      IN options a{sv},
      IN barriers aa{sv},
      IN zone_set u,
      OUT handle o
    )

Set up zero or more pointer barriers. Pointer barriers are horizontal or vertical “lines” that should trigger the start of input capture when the cursor moves across the pointer barrier. After a successful org.freedesktop.portal.InputCapture.Enable call and when the compositor has deemed the pointer barrier to be crossed, input events (from compositor-determined input devices) are sent to the application via the transport layer.

Pointer barriers are situated on the top (for horizontal barriers) or left (for vertical barriers) edge of their respective pixels and their width or height is inclusive each pixel’s width or height. In other words, a barrier spanning x1=0, x2=1 is exactly two pixels wide. A pointer barrier must be situated at the outside boundary of the union of all zones. A pointer barrier must be fully contained within one zone.

For example, consider two zones of size 1920x1080 with offsets 0,0 and 1920,0, respectively. (i.e. a left-right dual-monitor setup). The following pointer barriers are permitted:

- top edge of left screen: x1=0, y1=0, x2=1919, y1=0

- bottom edge of left screen: x1=0, y1=1080, x2=1919, y1=1080

- top edge of right screen: x1=1920, y1=0, x2=3839, y1=0

- bottom edge of right screen: x1=1920, y1=1080, x2=3839, y1=1080

- left edge of left screen: x1=0, y1=0, x2=0, y1=1079

- right edge of right screen: x1=3840, y1=0, x2=3840, y1=1079

A pointer barrier is considered triggered when the pointer would logically move off that zone, even if the actual cursor movement is clipped to the zone.

A zero-sized array of pointer barriers removes all existing pointer barriers for this session. Setting pointer barriers immediately suspends the current session and the application must call org.freedesktop.portal.InputCapture.Enable after this method.

The `zone_set` must be equivalent to the last returned zone_set of the org.freedesktop.portal.InputCapture.GetZones method. A mismatch of ids implies the application is not using the current zone set and pointer barriers will fail.

Supported keys in the `options` vardict include:

- `handle_token` (`s`)

  A string that will be used as the last element of the `handle`. Must be a valid object path element. See the Request documentation for more information about the `handle`.

Supported keys in the `barriers` vardicts include:

- `barrier_id` (`u`)

  The non-zero id of this barrier. This id is used in the org.freedesktop.portal.InputCapture::Activated signal to inform which barrier triggered input capture.

- `position` (`(iiii)`)

  The x1/y1 x2/y2 position of the pointer barrier. A horizontal pointer barrier must have y1 == y2, a vertical pointer barrier must have x1 == x2. Diagonal pointer barriers are not supported.

The following results get returned via the org.freedesktop.portal.Request::Response signal:

- `failed_barriers` (`au`)

  An array of barrier_ids of pointer barriers that have been denied. The id matches the barrier_id of the entries in the `barriers` argument.

session_handle

  Object path for the Session object

options

  Vardict with optional further information

barriers

  An array of vardicts, each specifying one barrier

zone_set

  A unique zone_set ID referring to the zone set

handle

  Object path for the Request object representing this call

### org.freedesktop.portal.InputCapture.Enable

    Enable (
      IN session_handle o,
      IN options a{sv}
    )

Enable input capturing. This does not immediately trigger capture, it merely enables the capturing to be triggered at some future point (e.g. by the cursor moving across a barrier). If and when that happens, the org.freedesktop.portal.InputCapture::Activated signal is emitted.

session_handle

  Object path for the Session object

options

  Vardict with optional further information

### org.freedesktop.portal.InputCapture.Disable

    Disable (
      IN session_handle o,
      IN options a{sv}
    )

Disable input capturing. No org.freedesktop.portal.InputCapture::Disabled signal will be emitted.

If input capturing is currently ongoing, no org.freedesktop.portal.InputCapture::Deactivated signal will be emitted.

Due to the asynchronous nature of this protocol, org.freedesktop.portal.InputCapture::Deactivated and/or org.freedesktop.portal.InputCapture::Deactivated signals may nevertheless be received by the application after a call to org.freedesktop.portal.InputCapture.Enable.

Input events will not be captured until a subsequent org.freedesktop.portal.InputCapture.Enable call.

session_handle

  Object path for the Session object

options

  Vardict with optional further information

### org.freedesktop.portal.InputCapture.Release

    Release (
      IN session_handle o,
      IN options a{sv}
    )

Release any ongoing input capture. No org.freedesktop.portal.InputCapture::Deactivated signal will be emitted.

Due to the asynchronous nature of this protocol, a org.freedesktop.portal.InputCapture::Deactivated signal may nevertheless be received by the application after a call to org.freedesktop.portal.InputCapture.Release.

The activation_id provided in the `options` vardict specifies which currently ongoing input capture should be terminated. The asynchronous nature of this portal allows for an input capture to be Deactivated and a new input capture to be Activated before the client requests the Release for the previous input capture.

A compositor should ignore a org.freedesktop.portal.InputCapture.Release request for a no longer active activation_id.

Supported keys in the `options` vardict include:

- `activation_id` (`u`)

  The same activation_id number as in the org.freedesktop.portal.InputCapture::Activated signal.

- `cursor_position` (`(dd)`)

  The suggested cursor position within the Zones available in this session.

  This is a suggestion to the compositor to place the cursor in the correct position to allow for fluent movement between virtual screens. The compositor is not required to honor this suggestion.

session_handle

  Object path for the Session object

options

  Vardict with optional further information

### org.freedesktop.portal.InputCapture.ConnectToEIS

    ConnectToEIS (
      IN session_handle o,
      IN options a{sv},
      OUT fd h
    )

Set up the connection to an active EIS implementation. Once input capturing starts, input events are sent via the EI protocol between the compositor and the application. This call must be invoked before org.freedesktop.portal.InputCapture.Enable.

A session only needs to set this up once, the EIS implementation is not affected by calls to org.freedesktop.portal.InputCapture.Disable and org.freedesktop.portal.InputCapture.Enable - the same connection can be re-used until the session is closed.

session_handle

  Object path for the Session object

options

  Vardict with optional further information

fd

  A file descriptor to an active EIS implementation that can be passed to a passive libei context

## Signals

### org.freedesktop.portal.InputCapture::Disabled

    Disabled (
      session_handle o,
      options a{sv}
    )

The Disabled signal is emitted when the application will no longer receive captured input. If input capturing is currently ongoing, the org.freedesktop.portal.InputCapture::Deactivated signal is emitted before this signal.

Applications must call org.freedesktop.portal.InputCapture.Enable to request future input capturing for this session.

session_handle

  Object path for the Session object

options

  Vardict with optional further information

### org.freedesktop.portal.InputCapture::Activated

    Activated (
      session_handle o,
      options a{sv}
    )

The Activated signal is emitted when input capture starts and input events are about to be sent to the application.

This signal is only emitted after a prior call to org.freedesktop.portal.InputCapture.Enable.

Supported keys in the `options` vardict include:

- `activation_id` (`u`)

  A number that can be used to synchronize with the transport-layer. This number has no intrinsic meaning but is guaranteed to increase by an unspecified amount on each call.

  In particular: if the compositor sends a activation_id of N as part of this request it will also set the sequence in EIS’ start_emulating event the same value N on the EIS connection before the first event from a device is sent. This allows an application to have a synchronization point and attribute an event sequence to the portal interaction.

  Applications must be able to handle the activation_id number wrapping around. Implementations of this portal must increase the activation_id number by a sensible amount to allow for wrapping detection.

- `cursor_position` (`(dd)`)

  The current cursor position in the same coordinate space as the Zones. Note that this position is usually outside the Zones available to this session as all PointerBarriers are at the edge of their respective Zones.

  For example, a fast movement against a barrier on the right edge of a screen may logically put the cursor dozens of pixels into the (non-existing) screen on the other side of the barrier. It is the application’s responsibility to calculate and adjust the cursor position as necessary.

- `barrier_id` (`u`)

  The barrier id of the barrier that triggered. If the value is nonzero, it matches the barrier id as specified in org.freedesktop.portal.InputCapture.SetPointerBarriers.

  If the id is zero, the pointer barrier could not be determined. If the id is missing, the input capture was not triggered by a pointer barrier.

  Where more than one pointer barrier are triggered by the same movement it is up to the compositor to choose one barrier (or use a barrier id of zero).

session_handle

  Object path for the Session object

options

  Vardict with optional further information

### org.freedesktop.portal.InputCapture::Deactivated

    Deactivated (
      session_handle o,
      options a{sv}
    )

The Deactivated signal is emitted when input capture stopped and input events are no longer sent to the application. To prevent future input capture, an application must call org.freedesktop.portal.InputCapture.Disable.

Supported keys in the `options` vardict include:

- `activation_id` (`u`)

  > The same activation_id number as in the corresponding org.freedesktop.portal.InputCapture::Activated signal.

session_handle

  Object path for the Session object

options

  Vardict with optional further information

### org.freedesktop.portal.InputCapture::ZonesChanged

    ZonesChanged (
      session_handle o,
      options a{sv}
    )

The ZonesChanged signal is emitted when the set of zones available to this session change. An application should immediately call org.freedesktop.portal.InputCapture.GetZones to update its state of the zones followed by org.freedesktop.portal.InputCapture.SetPointerBarriers to re-establish the pointer barriers.

The ZonesChanged signal includes the zone_set ID of the set of zones invalidated, see #`org.freedesktop.portal.InputCapture.GetZones`_. Due to the asynchronous nature of this protocol, the zone_set ID may identify a set of zones that the application has never (or not yet) seen. Applications must be able to handle unknown zone_set IDs. In particular, because the zone_set ID is guaranteed to increment, an application holding a zone_set ID higher than the ID in this signal can usually simply discard the signal.

Supported keys in the `options` vardict include:

- `zone_set` (`u`)

  The zone_set ID of the invalidated zone set as described in org.freedesktop.portal.InputCapture.GetZones

session_handle

  Object path for the Session object

options

  Vardict with optional further information