Class Surface
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
DragSurface.DragSurface$Impl,Popup.Popup$Impl,Surface.Surface$Impl,Toplevel.Toplevel$Impl
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
Nested ClassesModifier and TypeClassDescriptionstatic classSurface.Builder<B extends Surface.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theEnterMonitorCallbackcallback.static interfaceFunctional interface declaration of theEventCallbackcallback.static interfaceFunctional interface declaration of theLayoutCallbackcallback.static interfaceFunctional interface declaration of theLeaveMonitorCallbackcallback.static interfaceFunctional interface declaration of theRenderCallbackcallback.static classThe Surface$Impl type represents a native instance of the abstract Surface class.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionSurface()Creates a new Surface.Surface(MemorySegment address) Create a Surface proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected SurfaceasParent()Returns this instance as if it were its parent type.voidbeep()Emits a short beep associated tosurface.Deprecated.Drawing content with Cairo should be done via Cairo rendernodes, not by using the Cairo renderer.Creates a newGdkGLContextfor theGdkSurface.org.freedesktop.cairo.SurfacecreateSimilarSurface(org.freedesktop.cairo.Content content, int width, int height) Deprecated.Create a suitable cairo image surface yourselfDeprecated.GTK does not expose any Vulkan internals.voiddestroy()Destroys the window system resources associated with this Surface and decrementssurface'sreference count.voidemitEnterMonitor(@Nullable Monitor monitor) Emits the "enter-monitor" signal.booleanEmits the "event" signal.voidemitLayout(int width, int height) Emits the "layout" signal.voidemitLeaveMonitor(@Nullable Monitor monitor) Emits the "leave-monitor" signal.booleanemitRender(@Nullable org.freedesktop.cairo.Region region) Emits the "render" signal.@Nullable CursorRetrieves aGdkCursorpointer for the cursor currently set on theGdkSurface.@Nullable CursorgetDeviceCursor(Device device) Retrieves aGdkCursorpointer for thedevicecurrently set on the specifiedGdkSurface.booleangetDevicePosition(Device device, @Nullable Out<Double> x, @Nullable Out<Double> y, @Nullable Out<Set<ModifierType>> mask) Obtains the current device position and modifier state.Gets theGdkDisplayassociated with aGdkSurface.Gets the frame clock for the surface.intReturns the height of the givensurface.booleanChecks whether the surface has been mapped.doublegetScale()Returns the internal scale that maps from surface coordinates to the actual device pixels.intReturns the internal scale factor that maps from surface coordinates to the actual device pixels.static @Nullable TypegetType()Get the GType of the Surface classintgetWidth()Returns the width of the givensurface.voidhide()Hide the surface.booleanCheck to see if a surface is destroyed.Emitted whensurfacestarts 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 ofsurfaceis changed, or when relayout should be performed.Emitted whensurfacestops being present on the monitor.onRender(Surface.RenderCallback handler) Emitted when part of the surface needs to be redrawn.static SurfaceCreate a new popup surface.voidForces aGdk.Surface::rendersignal emission for this Surface to be scheduled.voidRequest a layout phase from the surface's frame clock.voidSets the default mouse pointer for aGdkSurface.voidsetDeviceCursor(Device device, Cursor cursor) Sets a specificGdkCursorfor a given device when it gets insidesurface.voidsetInputRegion(@Nullable org.freedesktop.cairo.Region region) Apply the region to the surface for the purpose of event handling.voidsetOpaqueRegion(@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 SurfaceCreates a new toplevel surface.booleanTranslates coordinates between two surfaces.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, builder, 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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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
-
Surface
public Surface()Creates a new Surface.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, 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
parentand 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 tosurface.If the display of this Surface does not support per-surface beeps, emits a short beep on the display just as
Display.beep(). -
createCairoContext
Deprecated.Drawing content with Cairo should be done via Cairo rendernodes, not by using the Cairo renderer.Creates a newGdkCairoContextfor rendering onsurface.- Returns:
- the newly created
GdkCairoContext
-
createGlContext
Creates a newGdkGLContextfor theGdkSurface.The context is disconnected from any particular surface or surface. If the creation of the
GdkGLContextfailed,errorwill 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 givensurface.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 assurface,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
otheris 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 decrementssurface'sreference 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 aGdkCursorpointer for the cursor currently set on theGdkSurface.If the return value is
nullthen 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 aGdkCursorpointer for thedevicecurrently set on the specifiedGdkSurface.If the return value is
nullthen 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 Out<Double> x, @Nullable Out<Double> y, @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
surface.- Parameters:
device- pointerGdkDeviceto query tox- return location for the X coordinate ofdevicey- return location for the Y coordinate ofdevicemask- return location for the modifier mask- Returns:
trueif the device is over the surface
-
getDisplay
Gets theGdkDisplayassociated with aGdkSurface.- Returns:
- the
GdkDisplayassociated 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 givensurface.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:
trueif 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
- Since:
- 4.12
-
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 givensurface.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:
trueif the surface is destroyed
-
queueRender
public void queueRender()Forces aGdk.Surface::rendersignal 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
nullfor thecursorargument means that this Surface will use the cursor of its parent surface. Most surfaces should use this default. Note thatcursormust be for the same display assurface.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 specificGdkCursorfor a given device when it gets insidesurface.Passing
nullfor thecursorargument 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 pointerGdkDevicecursor- aGdkCursor
-
setInputRegion
public void setInputRegion(@Nullable 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
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, ornullto make the entire surface 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 theGdkSurfaceas 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, ornullto make the entire surface opaque
-
translateCoordinates
Translates coordinates between two surfaces.Note that this only works if
toand 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:
trueif the coordinates were successfully translated
-
onEnterMonitor
public SignalConnection<Surface.EnterMonitorCallback> onEnterMonitor(Surface.EnterMonitorCallback handler) Emitted whensurfacestarts 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 ofsurfaceis 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 whensurfacestops 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(@Nullable org.freedesktop.cairo.Region region) Emits the "render" signal. SeeonRender(org.gnome.gdk.Surface.RenderCallback).
-