Class Display

All Implemented Interfaces:
Proxy

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

A representation of a workstation.

Their purpose are two-fold:

  • To manage and provide information about input devices (pointers, keyboards, etc)
  • To manage and provide information about output devices (monitors, projectors, etc)

Most of the input device handling has been factored out into separate Seat objects. Every display has a one or more seats, which can be accessed with getDefaultSeat() and listSeats().

Output devices are represented by Monitor objects, which can be accessed with getMonitorAtSurface(Surface) and similar APIs.

  • Constructor Details

    • Display

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

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

    • getType

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

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

      protected Display 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
    • getDefault

      public static @Nullable Display getDefault()

      Gets the default GdkDisplay.

      This is a convenience function for:

      gdk_display_manager_get_default_display (gdk_display_manager_get ())
      
      Returns:
      a GdkDisplay, or null if there is no default display
    • open

      public static @Nullable Display open(@Nullable String displayName)

      Opens a display.

      If opening the display fails, NULL is returned.

      Parameters:
      displayName - the name of the display to open
      Returns:
      a GdkDisplay
    • beep

      public void beep()
      Emits a short beep on this Display
    • close

      public void close()

      Closes the connection to the windowing system for the given display.

      This cleans up associated resources.

    • createGlContext

      public GLContext createGlContext() throws GErrorException

      Creates a new GdkGLContext for the GdkDisplay.

      The context is disconnected from any particular surface or surface and cannot be used to draw to any surface. It can only be used to draw to non-surface framebuffers like textures.

      If the creation of the GdkGLContext failed, error will be set. Before using the returned GdkGLContext, you will need to call GLContext.makeCurrent() or GLContext.realize().

      Returns:
      the newly created GdkGLContext
      Throws:
      GErrorException - see GError
      Since:
      4.6
    • deviceIsGrabbed

      public boolean deviceIsGrabbed(Device device)
      Returns true if there is an ongoing grab on device for display.
      Parameters:
      device - a GdkDevice
      Returns:
      true if there is a grab in effect for device.
    • flush

      public void flush()

      Flushes any requests queued for the windowing system.

      This happens automatically when the main loop blocks waiting for new events, but if your application is drawing without returning control to the main loop, you may need to call this function explicitly. A common case where this function needs to be called is when an application is executing drawing commands from a thread other than the thread where the main loop is running.

      This is most useful for X11. On windowing systems where requests are handled synchronously, this function will do nothing.

    • getAppLaunchContext

      public AppLaunchContext getAppLaunchContext()
      Returns a GdkAppLaunchContext suitable for launching applications on the given display.
      Returns:
      a new GdkAppLaunchContext for this Display
    • getClipboard

      public Clipboard getClipboard()
      Gets the clipboard used for copy/paste operations.
      Returns:
      the display's clipboard
    • getDefaultSeat

      public @Nullable Seat getDefaultSeat()

      Returns the default GdkSeat for this display.

      Note that a display may not have a seat. In this case, this function will return null.

      Returns:
      the default seat.
    • getDmabufFormats

      public DmabufFormats getDmabufFormats()

      Returns the dma-buf formats that are supported on this display.

      GTK may use OpenGL or Vulkan to support some formats. Calling this function will then initialize them if they aren't yet.

      The formats returned by this function can be used for negotiating buffer formats with producers such as v4l, pipewire or GStreamer.

      To learn more about dma-bufs, see DmabufTextureBuilder.

      This function is threadsafe. It can be called from any thread.

      Returns:
      a GdkDmabufFormats object
      Since:
      4.14
    • getMonitorAtSurface

      public @Nullable Monitor getMonitorAtSurface(Surface surface)
      Gets the monitor in which the largest area of surface resides.
      Parameters:
      surface - a GdkSurface
      Returns:
      the monitor with the largest overlap with surface
    • getMonitors

      public ListModel getMonitors()

      Gets the list of monitors associated with this display.

      Subsequent calls to this function will always return the same list for the same display.

      You can listen to the GListModel::items-changed signal on this list to monitor changes to the monitor of this display.

      Returns:
      a GListModel of GdkMonitor
    • getName

      public String getName()
      Gets the name of the display.
      Returns:
      a string representing the display name. This string is owned by GDK and should not be modified or freed.
    • getPrimaryClipboard

      public Clipboard getPrimaryClipboard()

      Gets the clipboard used for the primary selection.

      On backends where the primary clipboard is not supported natively, GDK emulates this clipboard locally.

      Returns:
      the primary clipboard
    • getSetting

      public boolean getSetting(String name, Value value)
      Retrieves a desktop-wide setting such as double-click time for the display.
      Parameters:
      name - the name of the setting
      value - location to store the value of the setting
      Returns:
      true if the setting existed and a value was stored in value, false otherwise
    • getStartupNotificationId

      @Deprecated public @Nullable String getStartupNotificationId()
      Deprecated.
      Gets the startup notification ID for a Wayland display, or null if no ID has been defined.
      Returns:
      the startup notification ID for this Display
    • isClosed

      public boolean isClosed()
      Finds out if the display has been closed.
      Returns:
      true if the display is closed.
    • isComposited

      public boolean isComposited()

      Returns whether surfaces can reasonably be expected to have their alpha channel drawn correctly on the screen.

      Check isRgba() for whether the display supports an alpha channel.

      On X11 this function returns whether a compositing manager is compositing on display.

      On modern displays, this value is always true.

      Returns:
      Whether surfaces with RGBA visuals can reasonably be expected to have their alpha channels drawn correctly on the screen.
    • isRgba

      public boolean isRgba()

      Returns whether surfaces on this this Display are created with an alpha channel.

      Even if a true is returned, it is possible that the surface’s alpha channel won’t be honored when displaying the surface on the screen: in particular, for X an appropriate windowing manager and compositing manager must be running to provide appropriate display. Use isComposited() to check if that is the case.

      On modern displays, this value is always true.

      Returns:
      true if surfaces are created with an alpha channel or false if the display does not support this functionality.
    • listSeats

      public List<Seat> listSeats()
      Returns the list of seats known to display.
      Returns:
      the list of seats known to the GdkDisplay
    • mapKeycode

      public boolean mapKeycode(int keycode, @Nullable Out<KeymapKey[]> keys, @Nullable Out<int[]> keyvals)

      Returns the keyvals bound to keycode.

      The Nth GdkKeymapKey in keys is bound to the Nth keyval in keyvals.

      When a keycode is pressed by the user, the keyval from this list of entries is selected by considering the effective keyboard group and level.

      Free the returned arrays with g_free().

      Parameters:
      keycode - a keycode
      keys - return location for array of GdkKeymapKey
      keyvals - return location for array of keyvals
      Returns:
      true if there were any entries
    • mapKeyval

      public boolean mapKeyval(int keyval, @Nullable Out<KeymapKey[]> keys)

      Obtains a list of keycode/group/level combinations that will generate keyval.

      Groups and levels are two kinds of keyboard mode; in general, the level determines whether the top or bottom symbol on a key is used, and the group determines whether the left or right symbol is used.

      On US keyboards, the shift key changes the keyboard level, and there are no groups. A group switch key might convert a keyboard between Hebrew to English modes, for example.

      GdkEventKey contains a group field that indicates the active keyboard group. The level is computed from the modifier mask.

      The returned array should be freed with g_free().

      Parameters:
      keyval - a keyval, such as GDK_KEY_a, GDK_KEY_Up, GDK_KEY_Return, etc.
      keys - return location for an array of GdkKeymapKey
      Returns:
      true if keys were found and returned
    • notifyStartupComplete

      @Deprecated public void notifyStartupComplete(String startupId)
      Deprecated.
      Using Toplevel.setStartupId(String) is sufficient

      Indicates to the GUI environment that the application has finished loading, using a given identifier.

      GTK will call this function automatically for GtkWindow with custom startup-notification identifier unless gtk_window_set_auto_startup_notification() is called to disable that feature.

      Parameters:
      startupId - a startup-notification identifier, for which notification process should be completed
    • prepareGl

      public boolean prepareGl() throws GErrorException

      Checks that OpenGL is available for this Display and ensures that it is properly initialized. When this fails, an error will be set describing the error and this function returns false.

      Note that even if this function succeeds, creating a GdkGLContext may still fail.

      This function is idempotent. Calling it multiple times will just return the same value or error.

      You never need to call this function, GDK will call it automatically as needed. But you can use it as a check when setting up code that might make use of OpenGL.

      Returns:
      true if the display supports OpenGL
      Throws:
      GErrorException - see GError
      Since:
      4.4
    • putEvent

      @Deprecated public void putEvent(Event event)
      Deprecated.
      This function is only useful in very special situations and should not be used by applications.
      Adds the given event to the event queue for display.
      Parameters:
      event - a GdkEvent
    • supportsInputShapes

      public boolean supportsInputShapes()

      Returns true if the display supports input shapes.

      This means that Surface.setInputRegion(Region) can be used to modify the input shape of surfaces on display.

      On modern displays, this value is always true.

      Returns:
      true if surfaces with modified input shape are supported
    • supportsShadowWidth

      public boolean supportsShadowWidth()

      Returns whether it's possible for a surface to draw outside of the window area.

      If true is returned the application decides if it wants to draw shadows. If false is returned, the compositor decides if it wants to draw shadows.

      Returns:
      true if surfaces can draw shadows or false if the display does not support this functionality.
      Since:
      4.14
    • sync

      public void sync()

      Flushes any requests queued for the windowing system and waits until all requests have been handled.

      This is often used for making sure that the display is synchronized with the current state of the program. Calling sync() before Display.errorTrapPop makes sure that any errors generated from earlier requests are handled before the error trap is removed.

      This is most useful for X11. On windowing systems where requests are handled synchronously, this function will do nothing.

    • translateKey

      public boolean translateKey(int keycode, Set<ModifierType> state, int group, @Nullable Out<Integer> keyval, @Nullable Out<Integer> effectiveGroup, @Nullable Out<Integer> level, @Nullable Out<Set<ModifierType>> consumed)

      Translates the contents of a GdkEventKey into a keyval, effective group, and level.

      Modifiers that affected the translation and are thus unavailable for application use are returned in consumedModifiers.

      The effectiveGroup is the group that was actually used for the translation; some keys such as Enter are not affected by the active keyboard group. The level is derived from state.

      consumedModifiers gives modifiers that should be masked out from state when comparing this key press to a keyboard shortcut. For instance, on a US keyboard, the plus symbol is shifted, so when comparing a key press to a <Control>plus accelerator <Shift> should be masked out.

      This function should rarely be needed, since GdkEventKey already contains the translated keyval. It is exported for the benefit of virtualized test environments.

      Parameters:
      keycode - a keycode
      state - a modifier state
      group - active keyboard group
      keyval - return location for keyval
      effectiveGroup - return location for effective group
      level - return location for level
      consumed - return location for modifiers that were used to determine the group or level
      Returns:
      true if there was a keyval bound to keycode/state/group.
    • translateKey

      public boolean translateKey(int keycode, ModifierType state, int group, @Nullable Out<Integer> keyval, @Nullable Out<Integer> effectiveGroup, @Nullable Out<Integer> level, @Nullable Out<ModifierType> consumed)

      Translates the contents of a GdkEventKey into a keyval, effective group, and level.

      Modifiers that affected the translation and are thus unavailable for application use are returned in consumedModifiers.

      The effectiveGroup is the group that was actually used for the translation; some keys such as Enter are not affected by the active keyboard group. The level is derived from state.

      consumedModifiers gives modifiers that should be masked out from state when comparing this key press to a keyboard shortcut. For instance, on a US keyboard, the plus symbol is shifted, so when comparing a key press to a <Control>plus accelerator <Shift> should be masked out.

      This function should rarely be needed, since GdkEventKey already contains the translated keyval. It is exported for the benefit of virtualized test environments.

      Parameters:
      keycode - a keycode
      state - a modifier state
      group - active keyboard group
      keyval - return location for keyval
      effectiveGroup - return location for effective group
      level - return location for level
      consumed - return location for modifiers that were used to determine the group or level
      Returns:
      true if there was a keyval bound to keycode/state/group.
    • onClosed

      Emitted when the connection to the windowing system for display is closed.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitClosed

      public void emitClosed(boolean isError)
      Emits the "closed" signal. See onClosed(Display.ClosedCallback).
    • onOpened

      Emitted when the connection to the windowing system for display is opened.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitOpened

      public void emitOpened()
      Emits the "opened" signal. See onOpened(Display.OpenedCallback).
    • onSeatAdded

      Emitted whenever a new seat is made known to the windowing system.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitSeatAdded

      public void emitSeatAdded(@Nullable Seat seat)
      Emits the "seat-added" signal. See onSeatAdded(Display.SeatAddedCallback).
    • onSeatRemoved

      Emitted whenever a seat is removed by the windowing system.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitSeatRemoved

      public void emitSeatRemoved(@Nullable Seat seat)
      Emits the "seat-removed" signal. See onSeatRemoved(Display.SeatRemovedCallback).
    • onSettingChanged

      Emitted whenever a setting changes its value.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitSettingChanged

      public void emitSettingChanged(String setting)
      Emits the "setting-changed" signal. See onSettingChanged(Display.SettingChangedCallback).
    • builder

      public static Display.Builder<? extends Display.Builder> builder()
      A Display.Builder object constructs a Display with the specified properties. Use the various set...() methods to set properties, and finish construction with Display.Builder.build().
      Returns:
      the builder object