Class Surface

All Implemented Interfaces:
PointerInterface

public class Surface extends Object
A `GdkSurface` is a rectangular region on the screen.

It’s a low-level object, used to implement high-level objects
such as [class@Gtk.Window] or [class@Gtk.Dialog] in GTK.

The surfaces you see in practice are either [iface@Gdk.Toplevel] or
[iface@Gdk.Popup], and those interfaces provide much of the required
API to interact with these surfaces. Other, more specialized surface
types exist, but you will rarely interact with them directly.

https://docs.gtk.org/gdk4/class.Surface.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newPopupSurface

      public static Surface newPopupSurface(@Nonnull Surface parent, boolean autohide)
      Create a new popup surface.

      The surface will be attached to @parent and can be positioned
      relative to it using [method@Gdk.Popup.present].
      Parameters:
      parent - the parent surface to attach the surface to
      autohide - whether to hide the surface on outside clicks
      Returns:
      a new `GdkSurface`
    • newToplevelSurface

      public static Surface newToplevelSurface(@Nonnull Display display)
      Creates a new toplevel surface.
      Parameters:
      display - the display to create the surface on
      Returns:
      the new `GdkSurface`
    • beep

      public void beep()
      Emits a short beep associated to @surface.

      If the display of @surface does not support per-surface beeps,
      emits a short beep on the display just as [method@Gdk.Display.beep].
    • createCairoContext

      public CairoContext createCairoContext()
      Creates a new `GdkCairoContext` for rendering on @surface.
      Returns:
      the newly created `GdkCairoContext`
    • createGlContext

      public GLContext createGlContext() throws AllocationError
      Creates a new `GdkGLContext` for the `GdkSurface`.

      The context is disconnected from any particular surface or surface.
      If the creation of the `GdkGLContext` failed, @error will be set.
      Before using the returned `GdkGLContext`, you will need to
      call [method@Gdk.GLContext.make_current] or [method@Gdk.GLContext.realize].
      Returns:
      the newly created `GdkGLContext`
      Throws:
      AllocationError
    • createSimilarSurface

      public Surface createSimilarSurface(int content, int width, int height)
      Create a new Cairo surface that is as compatible as possible with the
      given @surface.

      For example the new surface will have the same fallback resolution
      and font options as @surface. Generally, the new surface will also
      use the same backend as @surface, unless that is not possible for
      some reason. The type of the returned surface may be examined with
      cairo_surface_get_type().

      Initially the surface contents are all 0 (transparent if contents
      have transparency, black otherwise.)

      This function always returns a valid pointer, but it will return a
      pointer to a “nil” surface if @other is already in an error state
      or any other error occurs.
      Parameters:
      content - the content for the new surface
      width - width of the new surface
      height - height of the new surface
      Returns:
      a pointer to the newly allocated surface. The caller owns the surface and should call cairo_surface_destroy() when done with it.
    • createVulkanContext

      public VulkanContext createVulkanContext() throws AllocationError
      Creates a new `GdkVulkanContext` for rendering on @surface.

      If the creation of the `GdkVulkanContext` failed, @error will be set.
      Returns:
      the newly created `GdkVulkanContext`, or %NULL on error
      Throws:
      AllocationError
    • destroy

      public void destroy()
      Destroys the window system resources associated with @surface and
      decrements @surface's reference count.

      The window system resources for all children of @surface are also
      destroyed, but the children’s reference counts are not decremented.

      Note that a surface will not be destroyed automatically when its
      reference count reaches zero. You must call this function yourself
      before that happens.
    • getCursor

      public Cursor getCursor()
      Retrieves a `GdkCursor` pointer for the cursor currently set on the
      `GdkSurface`.

      If the return value is %NULL then there is no custom cursor set on
      the surface, and it is using the cursor for its parent surface.

      Use [method@Gdk.Surface.set_cursor] to unset the cursor of the surface.
      Returns:
      a `GdkCursor`
    • getDeviceCursor

      public Cursor getDeviceCursor(@Nonnull Device device)
      Retrieves a `GdkCursor` pointer for the @device currently set on the
      specified `GdkSurface`.

      If the return value is %NULL then there is no custom cursor set on the
      specified surface, and it is using the cursor for its parent surface.

      Use [method@Gdk.Surface.set_cursor] to unset the cursor of the surface.
      Parameters:
      device - a pointer `GdkDevice`
      Returns:
      a `GdkCursor`
    • getDisplay

      public Display getDisplay()
      Gets the `GdkDisplay` associated with a `GdkSurface`.
      Returns:
      the `GdkDisplay` associated with @surface
    • getFrameClock

      public FrameClock getFrameClock()
      Gets the frame clock for the surface.

      The frame clock for a surface never changes unless the surface is
      reparented to a new toplevel surface.
      Returns:
      the frame clock
    • getHeight

      public int getHeight()
      Returns the height of the given @surface.

      Surface size is reported in ”application pixels”, not
      ”device pixels” (see [method@Gdk.Surface.get_scale_factor]).
      Returns:
      The height of @surface
    • getMapped

      public boolean getMapped()
      Checks whether the surface has been mapped.

      A surface is mapped with [method@Gdk.Toplevel.present]
      or [method@Gdk.Popup.present].
      Returns:
      %TRUE if the surface is mapped
    • getScaleFactor

      public int getScaleFactor()
      Returns the internal scale factor that maps from surface coordinates
      to the actual device pixels.

      On traditional systems this is 1, but on very high density outputs
      this can be a higher value (often 2). A higher value means that drawing
      is automatically scaled up to a higher resolution, so any code doing
      drawing will automatically look nicer. However, if you are supplying
      pixel-based data the scale value can be used to determine whether to
      use a pixel resource with higher resolution data.

      The scale of a surface may change during runtime.
      Returns:
      the scale factor
    • getWidth

      public int getWidth()
      Returns the width of the given @surface.

      Surface size is reported in ”application pixels”, not
      ”device pixels” (see [method@Gdk.Surface.get_scale_factor]).
      Returns:
      The width of @surface
    • hide

      public void hide()
      Hide the surface.

      For toplevel surfaces, withdraws them, so they will no longer be
      known to the window manager; for all surfaces, unmaps them, so
      they won’t be displayed. Normally done automatically as
      part of [method@Gtk.Widget.hide].
    • isDestroyed

      public boolean isDestroyed()
      Check to see if a surface is destroyed.
      Returns:
      %TRUE if the surface is destroyed
    • queueRender

      public void queueRender()
      Forces a [signal@Gdk.Surface::render] signal emission for @surface
      to be scheduled.

      This function is useful for implementations that track invalid
      regions on their own.
    • requestLayout

      public void requestLayout()
      Request a layout phase from the surface's frame clock.

      See [method@Gdk.FrameClock.request_phase].
    • setCursor

      public void setCursor(@Nullable Cursor cursor)
      Sets the default mouse pointer for a `GdkSurface`.

      Passing %NULL for the @cursor argument means that @surface will use
      the cursor of its parent surface. Most surfaces should use this default.
      Note that @cursor must be for the same display as @surface.

      Use [ctor@Gdk.Cursor.new_from_name] or [ctor@Gdk.Cursor.new_from_texture]
      to create the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR.
      Parameters:
      cursor - a `GdkCursor`
    • setDeviceCursor

      public void setDeviceCursor(@Nonnull Device device, @Nonnull Cursor cursor)
      Sets a specific `GdkCursor` for a given device when it gets inside @surface.

      Passing %NULL for the @cursor argument means that @surface will use the
      cursor of its parent surface. Most surfaces should use this default.

      Use [ctor@Gdk.Cursor.new_from_name] or [ctor@Gdk.Cursor.new_from_texture]
      to create the cursor. To make the cursor invisible, use %GDK_BLANK_CURSOR.
      Parameters:
      device - a pointer `GdkDevice`
      cursor - a `GdkCursor`
    • setInputRegion

      public void setInputRegion(@Nonnull Region region)
      Apply the region to the surface for the purpose of event
      handling.

      Mouse events which happen while the pointer position corresponds
      to an unset bit in the mask will be passed on the surface below
      @surface.

      An input region is typically used with RGBA surfaces. The alpha
      channel of the surface defines which pixels are invisible and
      allows for nicely antialiased borders, and the input region
      controls where the surface is “clickable”.

      Use [method@Gdk.Display.supports_input_shapes] to find out if
      a particular backend supports input regions.
      Parameters:
      region - region of surface to be reactive
    • setOpaqueRegion

      public void setOpaqueRegion(@Nullable Region region)
      Marks a region of the `GdkSurface` as opaque.

      For optimisation purposes, compositing window managers may
      like to not draw obscured regions of surfaces, or turn off blending
      during for these regions. With RGB windows with no transparency,
      this is just the shape of the window, but with ARGB32 windows, the
      compositor does not know what regions of the window are transparent
      or not.

      This function only works for toplevel surfaces.

      GTK will update this property automatically if the @surface background
      is opaque, as we know where the opaque regions are. If your surface
      background is not opaque, please update this property in your
      [vfunc@Gtk.Widget.css_changed] handler.
      Parameters:
      region - a region, or %NULL to make the entire surface opaque
    • onEnterMonitor

      public SignalHandler onEnterMonitor(Surface.OnEnterMonitor signal)
      Connect to signal "enter-monitor".
      See Surface.OnEnterMonitor.onEnterMonitor(ch.bailu.gtk.gdk.Monitor) for signal description.
      Field SIGNAL_ON_ENTER_MONITOR contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onEvent

      public SignalHandler onEvent(Surface.OnEvent signal)
      Connect to signal "event".
      See Surface.OnEvent.onEvent(ch.bailu.gtk.type.Pointer) for signal description.
      Field SIGNAL_ON_EVENT contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onLayout

      public SignalHandler onLayout(Surface.OnLayout signal)
      Connect to signal "layout".
      See Surface.OnLayout.onLayout(int, int) for signal description.
      Field SIGNAL_ON_LAYOUT contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onLeaveMonitor

      public SignalHandler onLeaveMonitor(Surface.OnLeaveMonitor signal)
      Connect to signal "leave-monitor".
      See Surface.OnLeaveMonitor.onLeaveMonitor(ch.bailu.gtk.gdk.Monitor) for signal description.
      Field SIGNAL_ON_LEAVE_MONITOR contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onRender

      public SignalHandler onRender(Surface.OnRender signal)
      Connect to signal "render".
      See Surface.OnRender.onRender(ch.bailu.gtk.cairo.Region) for signal description.
      Field SIGNAL_ON_RENDER contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()