Class Surface
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
DragSurface.DragSurfaceImpl
,Popup.PopupImpl
,Surface.SurfaceImpl
,Toplevel.ToplevelImpl
GdkSurface
is a rectangular region on the screen.
It’s a low-level object, used to implement high-level objects such as GtkWindow.
The surfaces you see in practice are either Toplevel
or
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Surface.Builder<B extends Surface.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theEnterMonitorCallback
callback.static interface
Functional interface declaration of theEventCallback
callback.static interface
Functional interface declaration of theLayoutCallback
callback.static interface
Functional interface declaration of theLeaveMonitorCallback
callback.static interface
Functional interface declaration of theRenderCallback
callback.static class
static class
The SurfaceImpl type represents a native instance of the abstract Surface class.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionSurface
(MemorySegment address) Create a Surface proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Surface
asParent()
Returns this instance as if it were its parent type.void
beep()
Emits a short beep associated to this Surface.static Surface.Builder
<? extends Surface.Builder> builder()
ASurface.Builder
object constructs aSurface
with the specified properties.Creates a newGdkCairoContext
for rendering on this Surface.Creates a newGdkGLContext
for theGdkSurface
.org.freedesktop.cairo.Surface
createSimilarSurface
(org.freedesktop.cairo.Content content, int width, int height) Deprecated.Create a suitable cairo image surface yourselfDeprecated.GTK does not expose any Vulkan internals.void
destroy()
Destroys the window system resources associated with this Surface and decrements this Surface's reference count.void
emitEnterMonitor
(Monitor monitor) Emits the "enter-monitor" signal.boolean
Emits the "event" signal.void
emitLayout
(int width, int height) Emits the "layout" signal.void
emitLeaveMonitor
(Monitor monitor) Emits the "leave-monitor" signal.boolean
emitRender
(org.freedesktop.cairo.Region region) Emits the "render" signal.Retrieves aGdkCursor
pointer for the cursor currently set on theGdkSurface
.getDeviceCursor
(Device device) Retrieves aGdkCursor
pointer for thedevice
currently set on the specifiedGdkSurface
.boolean
getDevicePosition
(Device device, @Nullable Out<Double> x, @Nullable Out<Double> y, @Nullable Out<Set<ModifierType>> mask) Obtains the current device position and modifier state.Gets theGdkDisplay
associated with aGdkSurface
.Gets the frame clock for the surface.int
Returns the height of the given this Surface.boolean
Checks whether the surface has been mapped.double
getScale()
Returns the internal scale that maps from surface coordinates to the actual device pixels.int
Returns the internal scale factor that maps from surface coordinates to the actual device pixels.static Type
getType()
Get the GType of the Surface classint
getWidth()
Returns the width of the given this Surface.void
hide()
Hide the surface.boolean
Check to see if a surface is destroyed.Emitted whensurface
starts being present on the monitor.onEvent
(Surface.EventCallback handler) Emitted when GDK receives an input event forsurface
.onLayout
(Surface.LayoutCallback handler) Emitted when the size ofsurface
is changed, or when relayout should be performed.Emitted whensurface
stops being present on the monitor.onRender
(Surface.RenderCallback handler) Emitted when part of the surface needs to be redrawn.static Surface
Create a new popup surface.void
Forces aGdk.Surface::render
signal emission for this Surface to be scheduled.void
Request a layout phase from the surface's frame clock.void
Sets the default mouse pointer for aGdkSurface
.void
setDeviceCursor
(Device device, Cursor cursor) Sets a specificGdkCursor
for a given device when it gets inside this Surface.void
setInputRegion
(org.freedesktop.cairo.Region region) Apply the region to the surface for the purpose of event handling.void
setOpaqueRegion
(@Nullable org.freedesktop.cairo.Region region) Deprecated.GDK can figure out the opaque parts of a window itself by inspecting the contents that are drawn.static Surface
Creates a new toplevel surface.boolean
Translates coordinates between two surfaces.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Surface
Create a Surface proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
popup
Create a new popup surface.The surface will be attached to
parent
and can be positioned relative to it usingPopup.present(int, int, org.gnome.gdk.PopupLayout)
.- Parameters:
parent
- the parent surface to attach the surface toautohide
- whether to hide the surface on outside clicks- Returns:
- a new
GdkSurface
-
toplevel
-
beep
public void beep()Emits a short beep associated to this Surface.If the display of this Surface does not support per-surface beeps, emits a short beep on the display just as
Display.beep()
. -
createCairoContext
Creates a newGdkCairoContext
for rendering on this Surface.- Returns:
- the newly created
GdkCairoContext
-
createGlContext
Creates a newGdkGLContext
for theGdkSurface
.The context is disconnected from any particular surface or surface. If the creation of the
GdkGLContext
failed,error
will be set. Before using the returnedGdkGLContext
, you will need to callGLContext.makeCurrent()
orGLContext.realize()
.- Returns:
- the newly created
GdkGLContext
- Throws:
GErrorException
- seeGError
-
createSimilarSurface
@Deprecated public org.freedesktop.cairo.Surface createSimilarSurface(org.freedesktop.cairo.Content content, int width, int height) Deprecated.Create a suitable cairo image surface yourselfCreate a new Cairo surface that is as compatible as possible with the given this Surface.For example the new surface will have the same fallback resolution and font options as this Surface. Generally, the new surface will also use the same backend as this 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 surfacewidth
- width of the new surfaceheight
- 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
Deprecated.GTK does not expose any Vulkan internals. This function is a leftover that was accidentally exposed.Sets an error and returnsnull
.- Returns:
null
- Throws:
GErrorException
- seeGError
-
destroy
public void destroy()Destroys the window system resources associated with this Surface and decrements this Surface's reference count.The window system resources for all children of this 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
Retrieves aGdkCursor
pointer for the cursor currently set on theGdkSurface
.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
setCursor(org.gnome.gdk.Cursor)
to unset the cursor of the surface.- Returns:
- a
GdkCursor
-
getDeviceCursor
Retrieves aGdkCursor
pointer for thedevice
currently set on the specifiedGdkSurface
.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
setCursor(org.gnome.gdk.Cursor)
to unset the cursor of the surface.- Parameters:
device
- a pointerGdkDevice
- Returns:
- a
GdkCursor
-
getDevicePosition
public boolean getDevicePosition(Device device, @Nullable @Nullable Out<Double> x, @Nullable @Nullable Out<Double> y, @Nullable @Nullable Out<Set<ModifierType>> mask) Obtains the current device position and modifier state.The position is given in coordinates relative to the upper left corner of this Surface.
- Parameters:
device
- pointerGdkDevice
to query tox
- return location for the X coordinate ofdevice
y
- return location for the Y coordinate ofdevice
mask
- return location for the modifier mask- Returns:
true
if the device is over the surface
-
getDisplay
Gets theGdkDisplay
associated with aGdkSurface
.- Returns:
- the
GdkDisplay
associated with this Surface
-
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 this Surface.Surface size is reported in ”application pixels”, not ”device pixels” (see
getScaleFactor()
).- Returns:
- The height of this Surface
-
getMapped
public boolean getMapped()Checks whether the surface has been mapped.A surface is mapped with
Toplevel.present(org.gnome.gdk.ToplevelLayout)
orPopup.present(int, int, org.gnome.gdk.PopupLayout)
.- Returns:
true
if the surface is mapped
-
getScale
public double getScale()Returns the internal scale that maps from surface coordinates to the actual device pixels.When the scale is bigger than 1, the windowing system prefers to get buffers with a resolution that is bigger than the surface size (e.g. to show the surface on a high-resolution display, or in a magnifier).
Compare with
getScaleFactor()
, which returns the next larger integer.The scale may change during the lifetime of the surface.
- Returns:
- the scale
-
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 factor may change during the lifetime of the surface.
- Returns:
- the scale factor
-
getWidth
public int getWidth()Returns the width of the given this Surface.Surface size is reported in ”application pixels”, not ”device pixels” (see
getScaleFactor()
).- Returns:
- The width of this 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 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 aGdk.Surface::render
signal emission for this 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
FrameClock.requestPhase(java.util.Set<org.gnome.gdk.FrameClockPhase>)
. -
setCursor
Sets the default mouse pointer for aGdkSurface
.Passing
null
for thecursor
argument means that this Surface will use the cursor of its parent surface. Most surfaces should use this default. Note thatcursor
must be for the same display as this Surface.Use
Cursor.fromName(java.lang.String, org.gnome.gdk.Cursor)
orCursor.fromTexture(org.gnome.gdk.Texture, int, int, org.gnome.gdk.Cursor)
to create the cursor. To make the cursor invisible, useGDK_BLANK_CURSOR
.- Parameters:
cursor
- aGdkCursor
-
setDeviceCursor
Sets a specificGdkCursor
for a given device when it gets inside this Surface.Passing
null
for thecursor
argument means that this Surface will use the cursor of its parent surface. Most surfaces should use this default.Use
Cursor.fromName(java.lang.String, org.gnome.gdk.Cursor)
orCursor.fromTexture(org.gnome.gdk.Texture, int, int, org.gnome.gdk.Cursor)
to create the cursor. To make the cursor invisible, useGDK_BLANK_CURSOR
.- Parameters:
device
- a pointerGdkDevice
cursor
- aGdkCursor
-
setInputRegion
public void setInputRegion(org.freedesktop.cairo.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 this 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
Display.supportsInputShapes()
to find out if a particular backend supports input regions.- Parameters:
region
- region of surface to be reactive
-
setOpaqueRegion
Deprecated.GDK can figure out the opaque parts of a window itself by inspecting the contents that are drawn.Marks a region of theGdkSurface
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 this 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 GtkWidgetClass.css_changed handler.
- Parameters:
region
- a region, ornull
to make the entire surface opaque
-
translateCoordinates
Translates coordinates between two surfaces.Note that this only works if
to
and this Surface are popups or transient-for to the same toplevel (directly or indirectly).- Parameters:
to
- the target surfacex
- coordinates to translatey
- coordinates to translate- Returns:
true
if the coordinates were successfully translated
-
onEnterMonitor
public SignalConnection<Surface.EnterMonitorCallback> onEnterMonitor(Surface.EnterMonitorCallback handler) Emitted whensurface
starts being present on the monitor.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitEnterMonitor
Emits the "enter-monitor" signal. SeeonEnterMonitor(org.gnome.gdk.Surface.EnterMonitorCallback)
. -
onEvent
Emitted when GDK receives an input event forsurface
.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitEvent
Emits the "event" signal. SeeonEvent(org.gnome.gdk.Surface.EventCallback)
. -
onLayout
Emitted when the size ofsurface
is changed, or when relayout should be performed.Surface size is reported in ”application pixels”, not ”device pixels” (see gdk_surface_get_scale_factor()).
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitLayout
public void emitLayout(int width, int height) Emits the "layout" signal. SeeonLayout(org.gnome.gdk.Surface.LayoutCallback)
. -
onLeaveMonitor
public SignalConnection<Surface.LeaveMonitorCallback> onLeaveMonitor(Surface.LeaveMonitorCallback handler) Emitted whensurface
stops being present on the monitor.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitLeaveMonitor
Emits the "leave-monitor" signal. SeeonLeaveMonitor(org.gnome.gdk.Surface.LeaveMonitorCallback)
. -
onRender
Emitted when part of the surface needs to be redrawn.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitRender
public boolean emitRender(org.freedesktop.cairo.Region region) Emits the "render" signal. SeeonRender(org.gnome.gdk.Surface.RenderCallback)
. -
builder
ASurface.Builder
object constructs aSurface
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withSurface.Builder.build()
.
-