Class Device

All Implemented Interfaces:
Proxy
Direct Known Subclasses:
Device.Device$Impl, DevicePad.DevicePad$Impl

@Generated("org.javagi.JavaGI") public abstract class Device extends GObject

Represents an input device, such as a keyboard, mouse or touchpad.

See the Seat documentation for more information about the various kinds of devices, and their relationships.

  • Constructor Details

    • Device

      public Device(MemorySegment address)
      Create a Device instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Device

      public Device()
      Create a new Device.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Device class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Device asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getActiveLayoutIndex

      public int getActiveLayoutIndex()

      Retrieves the index of the active layout of the keyboard.

      If there is no valid active layout for the GdkDevice, this function will return -1;

      This is only relevant for keyboard devices.

      Returns:
      The layout index of the active layout or -1.
      Since:
      4.18
    • getCapsLockState

      public boolean getCapsLockState()

      Retrieves whether the Caps Lock modifier of the keyboard is locked.

      This is only relevant for keyboard devices.

      Returns:
      true if Caps Lock is on for this Device
    • getDeviceTool

      public @Nullable DeviceTool getDeviceTool()
      Retrieves the current tool for device.
      Returns:
      the GdkDeviceTool
    • getDirection

      public Direction getDirection()

      Returns the direction of effective layout of the keyboard.

      This is only relevant for keyboard devices.

      The direction of a layout is the direction of the majority of its symbols. See Pango#unicharDirection.

      Returns:
      Direction.LTR or Direction.RTL if it can determine the direction. Direction.NEUTRAL otherwise
    • getDisplay

      public Display getDisplay()
      Returns the GdkDisplay to which this Device pertains.
      Returns:
      a GdkDisplay
    • getHasCursor

      public boolean getHasCursor()

      Determines whether the pointer follows device motion.

      This is not meaningful for keyboard devices, which don't have a pointer.

      Returns:
      true if the pointer follows device motion
    • getLayoutNames

      public @Nullable String @Nullable [] getLayoutNames()

      Retrieves the names of the layouts of the keyboard.

      This is only relevant for keyboard devices.

      Returns:
      null-terminated array of strings of layouts,
      Since:
      4.18
    • getModifierState

      public Set<ModifierType> getModifierState()

      Retrieves the current modifier state of the keyboard.

      This is only relevant for keyboard devices.

      Returns:
      the current modifier state
    • getName

      public String getName()
      The name of the device, suitable for showing in a user interface.
      Returns:
      a name
    • getNumLockState

      public boolean getNumLockState()

      Retrieves whether the Num Lock modifier of the keyboard is locked.

      This is only relevant for keyboard devices.

      Returns:
      true if Num Lock is on for this Device
    • getNumTouches

      public int getNumTouches()
      Retrieves the number of touch points associated to device.
      Returns:
      the number of touch points
    • getProductId

      public @Nullable String getProductId()

      Returns the product ID of this device.

      This ID is retrieved from the device, and does not change. See getVendorId() for more information.

      Returns:
      the product ID
    • getScrollLockState

      public boolean getScrollLockState()

      Retrieves whether the Scroll Lock modifier of the keyboard is locked.

      This is only relevant for keyboard devices.

      Returns:
      true if Scroll Lock is on for this Device
    • getSeat

      public Seat getSeat()
      Returns the GdkSeat the device belongs to.
      Returns:
      a GdkSeat
    • getSource

      public InputSource getSource()
      Determines the type of the device.
      Returns:
      a GdkInputSource
    • getSurfaceAtPosition

      public @Nullable Surface getSurfaceAtPosition(@Nullable Out<Double> winX, @Nullable Out<Double> winY)

      Obtains the surface underneath device, returning the location of the device in winX and winY.

      Returns null if the surface tree under this Device is not known to GDK (for example, belongs to another application).

      Parameters:
      winX - return location for the X coordinate of the device location relative to the surface origin
      winY - return location for the Y coordinate of the device location relative to the surface origin
      Returns:
      the GdkSurface under the device position
    • getTimestamp

      public int getTimestamp()

      Returns the timestamp of the last activity for this device.

      In practice, this means the timestamp of the last event that was received from the OS for this device. (GTK may occasionally produce events for a device that are not received from the OS, and will not update the timestamp).

      Returns:
      the timestamp of the last activity for this device
      Since:
      4.2
    • getVendorId

      public @Nullable String getVendorId()

      Returns the vendor ID of this device.

      This ID is retrieved from the device, and does not change.

      This function, together with getProductId(), can be used to eg. compose GSettings paths to store settings for this device.

       static GSettings *
       get_device_settings (GdkDevice *device)
       {
         const char *vendor, *product;
         GSettings *settings;
         GdkDevice *device;
         char *path;
      
         vendor = gdk_device_get_vendor_id (device);
         product = gdk_device_get_product_id (device);
      
         path = g_strdup_printf ("/org/example/app/devices/%s:%s/", vendor, product);
         settings = g_settings_new_with_path (DEVICE_SCHEMA, path);
         g_free (path);
      
         return settings;
       }
      
      Returns:
      the vendor ID
    • hasBidiLayouts

      public boolean hasBidiLayouts()

      Determines if layouts for both right-to-left and left-to-right languages are in use on the keyboard.

      This is only relevant for keyboard devices.

      Returns:
      true if there are layouts with both directions, false otherwise
    • onChanged

      Emitted either when the number of either axes or keys changes.

      On X11 this will normally happen when the physical device routing events through the logical device changes (for example, user switches from the USB mouse to a tablet); in that case the logical device will change to reflect the axes and keys on the new physical device.

      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitChanged

      public void emitChanged()
      Emits the "changed" signal. See onChanged(Device.ChangedCallback).
    • onToolChanged

      Emitted on pen/eraser devices whenever tools enter or leave proximity.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitToolChanged

      public void emitToolChanged(@Nullable DeviceTool tool)
      Emits the "tool-changed" signal. See onToolChanged(Device.ToolChangedCallback).