Surfaces

Surfaces — Onscreen display areas in the target window system

Functions

Properties

GdkCursor * cursor Read / Write
GdkDisplay * display Read / Write / Construct Only
GdkFrameClock * frame-clock Read / Write / Construct Only
gboolean mapped Read

Signals

void enter-monitor Run First
gboolean event Run Last
void leave-monitor Run First
void popup-layout-changed Run First
gboolean render Run Last
void size-changed Run First

Types and Values

Object Hierarchy

    GObject
    ╰── GdkSurface

Known Derived Interfaces

GdkSurface is required by GdkPopup and GdkToplevel.

Includes

#include <gdk/gdk.h>

Description

A GdkSurface is a (usually) rectangular region on the screen. It’s a low-level object, used to implement high-level objects such as GtkWindow on the GTK level.

Functions

gdk_surface_new_toplevel ()

GdkSurface *
gdk_surface_new_toplevel (GdkDisplay *display,
                          int width,
                          int height);

Creates a new toplevel surface.

[constructor]

Parameters

display

the display to create the surface on

 

width

width of new surface

 

height

height of new surface

 

Returns

the new GdkSurface.

[transfer full]


gdk_surface_new_popup ()

GdkSurface *
gdk_surface_new_popup (GdkSurface *parent,
                       gboolean autohide);

Create a new popup surface.

The surface will be attached to parent and can be positioned relative to it using gdk_surface_show_popup() or later using gdk_surface_layout_popup().

[constructor]

Parameters

parent

the parent surface to attach the surface to

 

autohide

whether to hide the surface on outside clicks

 

Returns

a new GdkSurface.

[transfer full]


gdk_surface_destroy ()

void
gdk_surface_destroy (GdkSurface *surface);

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.

Parameters

surface

a GdkSurface

 

gdk_surface_is_destroyed ()

gboolean
gdk_surface_is_destroyed (GdkSurface *surface);

Check to see if a surface is destroyed..

Parameters

surface

a GdkSurface

 

Returns

TRUE if the surface is destroyed


gdk_surface_get_display ()

GdkDisplay *
gdk_surface_get_display (GdkSurface *surface);

Gets the GdkDisplay associated with a GdkSurface.

Parameters

surface

a GdkSurface

 

Returns

the GdkDisplay associated with surface .

[transfer none]


gdk_surface_hide ()

void
gdk_surface_hide (GdkSurface *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().

Parameters

surface

a GdkSurface

 

gdk_surface_is_viewable ()

gboolean
gdk_surface_is_viewable (GdkSurface *surface);

Check if the surface and all ancestors of the surface are mapped. (This is not necessarily "viewable" in the X sense, since we only check as far as we have GDK surface parents, not to the root surface.)

Parameters

surface

a GdkSurface

 

Returns

TRUE if the surface is viewable


gdk_surface_get_mapped ()

gboolean
gdk_surface_get_mapped (GdkSurface *surface);

Checks whether the surface has been mapped (with gdk_surface_show() or gdk_surface_show_unraised()).

Parameters

surface

a GdkSurface

 

Returns

TRUE if the surface is mapped


gdk_surface_get_width ()

int
gdk_surface_get_width (GdkSurface *surface);

Returns the width of the given surface .

Surface size is reported in ”application pixels”, not ”device pixels” (see gdk_surface_get_scale_factor()).

Parameters

surface

a GdkSurface

 

Returns

The width of surface


gdk_surface_get_height ()

int
gdk_surface_get_height (GdkSurface *surface);

Returns the height of the given surface .

Surface size is reported in ”application pixels”, not ”device pixels” (see gdk_surface_get_scale_factor()).

Parameters

surface

a GdkSurface

 

Returns

The height of surface


gdk_surface_translate_coordinates ()

gboolean
gdk_surface_translate_coordinates (GdkSurface *from,
                                   GdkSurface *to,
                                   double *x,
                                   double *y);

Translates the given coordinates from being relative to the from surface to being relative to the to surface.

Note that this only works if to and from are popups or transient-for to the same toplevel (directly or indirectly).

Parameters

from

the origin surface

 

to

the target surface

 

x

coordinates to translate

 

y

coordinates to translate

 

Returns

TRUE if the coordinates were successfully translated


gdk_surface_begin_resize_drag ()

void
gdk_surface_begin_resize_drag (GdkSurface *surface,
                               GdkSurfaceEdge edge,
                               GdkDevice *device,
                               gint button,
                               gint x,
                               gint y,
                               guint32 timestamp);

Begins a surface resize operation (for a toplevel surface). You might use this function to implement a “window resize grip,”

Parameters

surface

a toplevel GdkSurface

 

edge

the edge or corner from which the drag is started

 

device

the device used for the operation

 

button

the button being used to drag, or 0 for a keyboard-initiated drag

 

x

surface X coordinate of mouse click that began the drag

 

y

surface Y coordinate of mouse click that began the drag

 

timestamp

timestamp of mouse click that began the drag (use gdk_event_get_time())

 

gdk_surface_begin_move_drag ()

void
gdk_surface_begin_move_drag (GdkSurface *surface,
                             GdkDevice *device,
                             gint button,
                             gint x,
                             gint y,
                             guint32 timestamp);

Begins a surface move operation (for a toplevel surface).

Parameters

surface

a toplevel GdkSurface

 

device

the device used for the operation

 

button

the button being used to drag, or 0 for a keyboard-initiated drag

 

x

surface X coordinate of mouse click that began the drag

 

y

surface Y coordinate of mouse click that began the drag

 

timestamp

timestamp of mouse click that began the drag

 

gdk_surface_beep ()

void
gdk_surface_beep (GdkSurface *surface);

Emits a short beep associated to surface in the appropriate display, if supported. Otherwise, emits a short beep on the display just as gdk_display_beep().

Parameters

surface

a toplevel GdkSurface

 

gdk_surface_get_scale_factor ()

gint
gdk_surface_get_scale_factor (GdkSurface *surface);

Returns the internal scale factor that maps from surface coordiantes 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, if this happens a configure event will be sent to the toplevel surface.

Parameters

surface

surface to get scale factor for

 

Returns

the scale factor


gdk_surface_set_opaque_region ()

void
gdk_surface_set_opaque_region (GdkSurface *surface,
                               cairo_region_t *region);

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 “css-changed” handler.

Parameters

surface

a top-level or non-native GdkSurface

 

region

a region, or NULL.

[allow-none]

gdk_surface_create_gl_context ()

GdkGLContext *
gdk_surface_create_gl_context (GdkSurface *surface,
                               GError **error);

Creates a new GdkGLContext matching the framebuffer format to the visual of 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 gdk_gl_context_make_current() or gdk_gl_context_realize().

Parameters

surface

a GdkSurface

 

error

return location for an error

 

Returns

the newly created GdkGLContext, or NULL on error.

[transfer full]


gdk_surface_create_vulkan_context ()

GdkVulkanContext *
gdk_surface_create_vulkan_context (GdkSurface *surface,
                                   GError **error);

Creates a new GdkVulkanContext for rendering on surface .

If the creation of the GdkVulkanContext failed, error will be set.

Parameters

surface

a GdkSurface

 

error

return location for an error

 

Returns

the newly created GdkVulkanContext, or NULL on error.

[transfer full]


gdk_surface_create_cairo_context ()

GdkCairoContext *
gdk_surface_create_cairo_context (GdkSurface *surface);

Creates a new GdkCairoContext for rendering on surface .

Parameters

surface

a GdkSurface

 

Returns

the newly created GdkCairoContext.

[transfer full]


gdk_surface_queue_expose ()

void
gdk_surface_queue_expose (GdkSurface *surface);

Forces an expose event for surface to be scheduled.

If the invalid area of surface is empty, an expose event will still be emitted. Its invalid region will be empty.

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

Parameters

surface

a GdkSurface

 

gdk_surface_freeze_updates ()

void
gdk_surface_freeze_updates (GdkSurface *surface);

Temporarily freezes a surface such that it won’t receive expose events. The surface will begin receiving expose events again when gdk_surface_thaw_updates() is called. If gdk_surface_freeze_updates() has been called more than once, gdk_surface_thaw_updates() must be called an equal number of times to begin processing exposes.

Parameters

surface

a GdkSurface

 

gdk_surface_thaw_updates ()

void
gdk_surface_thaw_updates (GdkSurface *surface);

Thaws a surface frozen with gdk_surface_freeze_updates(). Note that this will not necessarily schedule updates if the surface freeze count reaches zero.

Parameters

surface

a GdkSurface

 

gdk_surface_get_frame_clock ()

GdkFrameClock *
gdk_surface_get_frame_clock (GdkSurface *surface);

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.

Parameters

surface

surface to get frame clock for

 

Returns

the frame clock.

[transfer none]


gdk_surface_set_cursor ()

void
gdk_surface_set_cursor (GdkSurface *surface,
                        GdkCursor *cursor);

Sets the default mouse pointer for a GdkSurface.

Note that cursor must be for the same display as surface .

Use gdk_cursor_new_from_name() or gdk_cursor_new_from_texture() to create the cursor. To make the cursor invisible, use GDK_BLANK_CURSOR. Passing NULL for the cursor argument to gdk_surface_set_cursor() means that surface will use the cursor of its parent surface. Most surfaces should use this default.

Parameters

surface

a GdkSurface

 

cursor

a cursor.

[allow-none]

gdk_surface_get_cursor ()

GdkCursor *
gdk_surface_get_cursor (GdkSurface *surface);

Retrieves a GdkCursor pointer for the cursor currently set on the specified GdkSurface, or NULL. 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.

Parameters

surface

a GdkSurface

 

Returns

a GdkCursor, or NULL. The returned object is owned by the GdkSurface and should not be unreferenced directly. Use gdk_surface_set_cursor() to unset the cursor of the surface.

[nullable][transfer none]


gdk_surface_set_device_cursor ()

void
gdk_surface_set_device_cursor (GdkSurface *surface,
                               GdkDevice *device,
                               GdkCursor *cursor);

Sets a specific GdkCursor for a given device when it gets inside surface . Use gdk_cursor_new_fromm_name() or gdk_cursor_new_from_texture() to create the cursor. To make the cursor invisible, use GDK_BLANK_CURSOR. Passing NULL for the cursor argument to gdk_surface_set_cursor() means that surface will use the cursor of its parent surface. Most surfaces should use this default.

Parameters

surface

a GdkSurface

 

device

a master, pointer GdkDevice

 

cursor

a GdkCursor

 

gdk_surface_get_device_cursor ()

GdkCursor *
gdk_surface_get_device_cursor (GdkSurface *surface,
                               GdkDevice *device);

Retrieves a GdkCursor pointer for the device currently set on the specified GdkSurface, or NULL. 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.

Parameters

surface

a GdkSurface.

 

device

a master, pointer GdkDevice.

 

Returns

a GdkCursor, or NULL. The returned object is owned by the GdkSurface and should not be unreferenced directly. Use gdk_surface_set_cursor() to unset the cursor of the surface.

[nullable][transfer none]


gdk_surface_set_input_region ()

void
gdk_surface_set_input_region (GdkSurface *surface,
                              cairo_region_t *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 shape 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 shape controls where the surface is “clickable”.

On the X11 platform, this requires version 1.1 of the shape extension.

On the Win32 platform, this functionality is not present and the function does nothing.

Parameters

surface

a GdkSurface

 

region

region of surface to be reactive

 

gdk_surface_set_shadow_width ()

void
gdk_surface_set_shadow_width (GdkSurface *surface,
                              gint left,
                              gint right,
                              gint top,
                              gint bottom);

Newer GTK windows using client-side decorations use extra geometry around their frames for effects like shadows and invisible borders. Window managers that want to maximize windows or snap to edges need to know where the extents of the actual frame lie, so that users don’t feel like windows are snapping against random invisible edges.

Note that this property is automatically updated by GTK, so this function should only be used by applications which do not use GTK to create toplevel surfaces.

Parameters

surface

a GdkSurface

 

left

The left extent

 

right

The right extent

 

top

The top extent

 

bottom

The bottom extent

 

gdk_surface_get_device_position ()

void
gdk_surface_get_device_position (GdkSurface *surface,
                                 GdkDevice *device,
                                 double *x,
                                 double *y,
                                 GdkModifierType *mask);

Obtains the current device position in doubles and modifier state. The position is given in coordinates relative to the upper left corner of surface .

Parameters

surface

a GdkSurface.

 

device

pointer GdkDevice to query to.

 

x

return location for the X coordinate of device , or NULL.

[out][allow-none]

y

return location for the Y coordinate of device , or NULL.

[out][allow-none]

mask

return location for the modifier mask, or NULL.

[out][allow-none]

gdk_surface_get_support_multidevice ()

gboolean
gdk_surface_get_support_multidevice (GdkSurface *surface);

Returns TRUE if the surface is aware of the existence of multiple devices.

Parameters

surface

a GdkSurface.

 

Returns

TRUE if the surface handles multidevice features.


gdk_surface_set_support_multidevice ()

void
gdk_surface_set_support_multidevice (GdkSurface *surface,
                                     gboolean support_multidevice);

This function will enable multidevice features in surface .

Multidevice aware surfaces will need to handle properly multiple, per device enter/leave events, device grabs and grab ownerships.

Parameters

surface

a GdkSurface.

 

support_multidevice

TRUE to enable multidevice support in surface .

 

Types and Values

GdkSurface

typedef struct _GdkSurface GdkSurface;

The GdkSurface struct contains only private fields and should not be accessed directly.


enum GdkGravity

Defines the reference point of a surface and the meaning of coordinates passed to gtk_window_move(). See gtk_window_move() and the "implementation notes" section of the Extended Window Manager Hints specification for more details.

Members

GDK_GRAVITY_NORTH_WEST

the reference point is at the top left corner.

 

GDK_GRAVITY_NORTH

the reference point is in the middle of the top edge.

 

GDK_GRAVITY_NORTH_EAST

the reference point is at the top right corner.

 

GDK_GRAVITY_WEST

the reference point is at the middle of the left edge.

 

GDK_GRAVITY_CENTER

the reference point is at the center of the surface.

 

GDK_GRAVITY_EAST

the reference point is at the middle of the right edge.

 

GDK_GRAVITY_SOUTH_WEST

the reference point is at the lower left corner.

 

GDK_GRAVITY_SOUTH

the reference point is at the middle of the lower edge.

 

GDK_GRAVITY_SOUTH_EAST

the reference point is at the lower right corner.

 

GDK_GRAVITY_STATIC

the reference point is at the top left corner of the surface itself, ignoring window manager decorations.

 

enum GdkSurfaceEdge

Determines a surface edge or corner.

Members

GDK_SURFACE_EDGE_NORTH_WEST

the top left corner.

 

GDK_SURFACE_EDGE_NORTH

the top edge.

 

GDK_SURFACE_EDGE_NORTH_EAST

the top right corner.

 

GDK_SURFACE_EDGE_WEST

the left edge.

 

GDK_SURFACE_EDGE_EAST

the right edge.

 

GDK_SURFACE_EDGE_SOUTH_WEST

the lower left corner.

 

GDK_SURFACE_EDGE_SOUTH

the lower edge.

 

GDK_SURFACE_EDGE_SOUTH_EAST

the lower right corner.

 

enum GdkSurfaceTypeHint

These are hints for the window manager that indicate what type of function the window has. The window manager can use this when determining decoration and behaviour of the window. The hint must be set before mapping the window.

See the Extended Window Manager Hints specification for more details about window types.

Members

GDK_SURFACE_TYPE_HINT_NORMAL

Normal toplevel window.

 

GDK_SURFACE_TYPE_HINT_DIALOG

Dialog window.

 

GDK_SURFACE_TYPE_HINT_MENU

Window used to implement a menu; GTK uses this hint only for torn-off menus, see GtkTearoffMenuItem.

 

GDK_SURFACE_TYPE_HINT_TOOLBAR

Window used to implement toolbars.

 

GDK_SURFACE_TYPE_HINT_SPLASHSCREEN

Window used to display a splash screen during application startup.

 

GDK_SURFACE_TYPE_HINT_UTILITY

Utility windows which are not detached toolbars or dialogs.

 

GDK_SURFACE_TYPE_HINT_DOCK

Used for creating dock or panel windows.

 

GDK_SURFACE_TYPE_HINT_DESKTOP

Used for creating the desktop background window.

 

GDK_SURFACE_TYPE_HINT_DROPDOWN_MENU

A menu that belongs to a menubar.

 

GDK_SURFACE_TYPE_HINT_POPUP_MENU

A menu that does not belong to a menubar, e.g. a context menu.

 

GDK_SURFACE_TYPE_HINT_TOOLTIP

A tooltip.

 

GDK_SURFACE_TYPE_HINT_NOTIFICATION

A notification - typically a “bubble” that belongs to a status icon.

 

GDK_SURFACE_TYPE_HINT_COMBO

A popup from a combo box.

 

GDK_SURFACE_TYPE_HINT_DND

A window that is used to implement a DND cursor.

 

enum GdkSurfaceState

Specifies the state of a toplevel surface.

On platforms that support information about individual edges, the GDK_SURFACE_STATE_TILED state will be set whenever any of the individual tiled states is set. On platforms that lack that support, the tiled state will give an indication of tiledness without any of the per-edge states being set.

Members

GDK_SURFACE_STATE_WITHDRAWN

the surface is not shown

 

GDK_SURFACE_STATE_MINIMIZED

the surface is minimized

 

GDK_SURFACE_STATE_MAXIMIZED

the surface is maximized

 

GDK_SURFACE_STATE_STICKY

the surface is sticky

 

GDK_SURFACE_STATE_FULLSCREEN

the surface is maximized without decorations

 

GDK_SURFACE_STATE_ABOVE

the surface is kept above other surfaces

 

GDK_SURFACE_STATE_BELOW

the surface is kept below other surfaces

 

GDK_SURFACE_STATE_FOCUSED

the surface is presented as focused (with active decorations)

 

GDK_SURFACE_STATE_TILED

the surface is in a tiled state

 

GDK_SURFACE_STATE_TOP_TILED

whether the top edge is tiled

 

GDK_SURFACE_STATE_TOP_RESIZABLE

whether the top edge is resizable

 

GDK_SURFACE_STATE_RIGHT_TILED

whether the right edge is tiled

 

GDK_SURFACE_STATE_RIGHT_RESIZABLE

whether the right edge is resizable

 

GDK_SURFACE_STATE_BOTTOM_TILED

whether the bottom edge is tiled

 

GDK_SURFACE_STATE_BOTTOM_RESIZABLE

whether the bottom edge is resizable

 

GDK_SURFACE_STATE_LEFT_TILED

whether the left edge is tiled

 

GDK_SURFACE_STATE_LEFT_RESIZABLE

whether the left edge is resizable

 

enum GdkModifierType

A set of bit-flags to indicate the state of modifier keys and mouse buttons in various event types. Typical modifier keys are Shift, Control, Meta, Super, Hyper, Alt, Compose, Apple, CapsLock or ShiftLock.

Note that GDK may add internal values to events which include values outside of this enumeration. Your code should preserve and ignore them. You can use GDK_MODIFIER_MASK to remove all private values.

Members

GDK_SHIFT_MASK

the Shift key.

 

GDK_LOCK_MASK

a Lock key (depending on the modifier mapping of the X server this may either be CapsLock or ShiftLock).

 

GDK_CONTROL_MASK

the Control key.

 

GDK_ALT_MASK

the fourth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier, but normally it is the Alt key).

 

GDK_BUTTON1_MASK

the first mouse button.

 

GDK_BUTTON2_MASK

the second mouse button.

 

GDK_BUTTON3_MASK

the third mouse button.

 

GDK_BUTTON4_MASK

the fourth mouse button.

 

GDK_BUTTON5_MASK

the fifth mouse button.

 

GDK_SUPER_MASK

the Super modifier

 

GDK_HYPER_MASK

the Hyper modifier

 

GDK_META_MASK

the Meta modifier

 

GDK_MODIFIER_MASK

#define             GDK_MODIFIER_MASK

A mask covering all entries in GdkModifierType.

Property Details

The “cursor” property

  “cursor”                   GdkCursor *

The mouse pointer for a GdkSurface. See gdk_surface_set_cursor() and gdk_surface_get_cursor() for details.

Owner: GdkSurface

Flags: Read / Write


The “display” property

  “display”                  GdkDisplay *

The GdkDisplay connection of the surface. See gdk_surface_get_display() for details.

Owner: GdkSurface

Flags: Read / Write / Construct Only


The “frame-clock” property

  “frame-clock”              GdkFrameClock *

Frame Clock.

Owner: GdkSurface

Flags: Read / Write / Construct Only


The “mapped” property

  “mapped”                   gboolean

Mapped.

Owner: GdkSurface

Flags: Read

Default value: FALSE

Signal Details

The “enter-monitor” signal

void
user_function (GdkSurface *gdksurface,
               GdkMonitor *arg1,
               gpointer    user_data)

Flags: Run First


The “event” signal

gboolean
user_function (GdkSurface *surface,
               GdkEvent   *event,
               gpointer    user_data)

Emitted when GDK receives an input event for surface .

Parameters

surface

the GdkSurface

 

event

an input event

 

user_data

user data set when the signal handler was connected.

 

Returns

TRUE to indicate that the event has been handled

Flags: Run Last


The “leave-monitor” signal

void
user_function (GdkSurface *gdksurface,
               GdkMonitor *arg1,
               gpointer    user_data)

Flags: Run First


The “popup-layout-changed” signal

void
user_function (GdkSurface *surface,
               gpointer    user_data)

Emitted when the layout of a popup surface has changed, e.g. if the popup layout was reactive and after the parent moved causing the popover to end up partially off-screen.

Parameters

surface

the GdkSurface that was laid out

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First


The “render” signal

gboolean
user_function (GdkSurface  *surface,
               CairoRegion *region,
               gpointer     user_data)

Emitted when part of the surface needs to be redrawn.

Parameters

surface

the GdkSurface

 

region

the region that needs to be redrawn

 

user_data

user data set when the signal handler was connected.

 

Returns

TRUE to indicate that the signal has been handled

Flags: Run Last


The “size-changed” signal

void
user_function (GdkSurface *surface,
               gint        width,
               gint        height,
               gpointer    user_data)

Emitted when the size of surface is changed.

Surface size is reported in ”application pixels”, not ”device pixels” (see gdk_surface_get_scale_factor()).

Parameters

surface

the GdkSurface

 

width

the new width

 

height

the new height

 

user_data

user data set when the signal handler was connected.

 

Flags: Run First