Skip to content

Gdk.Toplevel

interface

A freestanding toplevel surface.

The GdkToplevel interface provides useful APIs for interacting with the windowing system, such as controlling maximization and size of the surface, setting icons and transient parents for dialogs.

Methods

begin_move

def begin_move(self, device: Device, button: int, x: float, y: float, timestamp: int) -> None

Begins an interactive move operation.

You might use this function to implement draggable titlebars.

Parameters:

  • 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 Event.get_time)

begin_resize

def begin_resize(self, edge: SurfaceEdge | int, device: Device | None, button: int, x: float, y: float, timestamp: int) -> None

Begins an interactive resize operation.

You might use this function to implement a “window resize grip.”

Parameters:

  • 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 Event.get_time)

focus

def focus(self, timestamp: int) -> None

Sets keyboard focus to surface.

In most cases, Gtk.Window.present_with_time should be used on a GtkWindow, rather than calling this function.

Parameters:

  • timestamp — timestamp of the event triggering the surface focus

get_capabilities

def get_capabilities(self) -> ToplevelCapabilities

The capabilities that are available for this toplevel.

get_gravity

def get_gravity(self) -> Gravity

Returns the gravity that is used when changing the toplevel size programmatically.

get_state

def get_state(self) -> ToplevelState

Gets the bitwise or of the currently active surface state flags, from the GdkToplevelState enumeration.

inhibit_system_shortcuts

def inhibit_system_shortcuts(self, event: Event | None = ...) -> None

Requests that the toplevel inhibit the system shortcuts.

This is asking the desktop environment/windowing system to let all keyboard events reach the surface, as long as it is focused, instead of triggering system actions.

If granted, the rerouting remains active until the default shortcuts processing is restored with Toplevel.restore_system_shortcuts, or the request is revoked by the desktop environment, windowing system or the user.

A typical use case for this API is remote desktop or virtual machine viewers which need to inhibit the default system keyboard shortcuts so that the remote session or virtual host gets those instead of the local environment.

The windowing system or desktop environment may ask the user to grant or deny the request or even choose to ignore the request entirely.

The caller can be notified whenever the request is granted or revoked by listening to the Toplevel.shortcuts-inhibited property.

Parameters:

  • event — the GdkEvent that is triggering the inhibit request, or None if none is available

lower

def lower(self) -> bool

Asks to lower the toplevel below other windows.

The windowing system may choose to ignore the request.

minimize

def minimize(self) -> bool

Asks to minimize the toplevel.

The windowing system may choose to ignore the request.

present

def present(self, layout: ToplevelLayout) -> None

Present toplevel after having processed the GdkToplevelLayout rules.

If the toplevel was previously not showing, it will be showed, otherwise it will change layout according to layout.

GDK may emit the Toplevel.compute-size signal to let the user of this toplevel compute the preferred size of the toplevel surface.

Presenting is asynchronous and the specified layout parameters are not guaranteed to be respected.

Parameters:

  • layout — the GdkToplevelLayout object used to layout

restore_system_shortcuts

def restore_system_shortcuts(self) -> None

Restore default system keyboard shortcuts which were previously inhibited.

This undoes the effect of Toplevel.inhibit_system_shortcuts.

set_decorated

def set_decorated(self, decorated: bool) -> None

Sets the toplevel to be decorated.

Setting decorated to False hints the desktop environment that the surface has its own, client-side decorations and does not need to have window decorations added.

Parameters:

  • decoratedTrue to request decorations

set_deletable

def set_deletable(self, deletable: bool) -> None

Sets the toplevel to be deletable.

Setting deletable to True hints the desktop environment that it should offer the user a way to close the surface.

Parameters:

  • deletableTrue to request a delete button

set_gravity

def set_gravity(self, gravity: Gravity | int) -> None

Sets the gravity that is used when changing the toplevel size programmatically.

Parameters:

  • gravity — the new gravity

set_icon_list

def set_icon_list(self, surfaces: list[Texture]) -> None

Sets a list of icons for the surface.

One of these will be used to represent the surface in iconic form. The icon may be shown in window lists or task bars. Which icon size is shown depends on the window manager. The window manager can scale the icon but setting several size icons can give better image quality.

Note that some platforms don't support surface icons.

Parameters:

  • surfaces — A list of textures to use as icon, of different sizes

set_modal

def set_modal(self, modal: bool) -> None

Sets the toplevel to be modal.

The application can use this hint to tell the window manager that a certain surface has modal behaviour. The window manager can use this information to handle modal surfaces in a special way.

You should only use this on surfaces for which you have previously called Toplevel.set_transient_for.

Parameters:

  • modalTrue if the surface is modal, False otherwise.

set_startup_id

def set_startup_id(self, startup_id: str) -> None

Sets the startup notification ID.

When using GTK, typically you should use Gtk.Window.set_startup_id instead of this low-level function.

Parameters:

  • startup_id — a string with startup-notification identifier

set_title

def set_title(self, title: str) -> None

Sets the title of a toplevel surface.

The title maybe be displayed in the titlebar, in lists of windows, etc.

Parameters:

  • title — title of surface

set_transient_for

def set_transient_for(self, parent: Surface) -> None

Sets a transient-for parent.

Indicates to the window manager that surface is a transient dialog associated with the application surface parent. This allows the window manager to do things like center surface on parent and keep surface above parent.

See Gtk.Window.set_transient_for if you’re using GtkWindow.

Parameters:

  • parent — another toplevel GdkSurface

show_window_menu

def show_window_menu(self, event: Event) -> bool

Asks the windowing system to show the window menu.

The window menu is the menu shown when right-clicking the titlebar on traditional windows managed by the window manager. This is useful for windows using client-side decorations, activating it with a right-click on the window decorations.

Parameters:

  • event — a GdkEvent to show the menu for

supports_edge_constraints

def supports_edge_constraints(self) -> bool

Returns whether the desktop environment supports tiled window states.

titlebar_gesture

def titlebar_gesture(self, gesture: TitlebarGesture | int) -> bool

Performs a title bar gesture.

Parameters:

  • gesture — a GdkTitlebarGesture

Properties

capabilities

capabilities: ToplevelCapabilities | int  # read-only

The capabilities that are available for this toplevel.

decorated

decorated: bool  # read/write

Whether the window manager should add decorations.

deletable

deletable: bool  # read/write

Whether the window manager should allow to close the surface.

fullscreen_mode

fullscreen_mode: FullscreenMode | int  # read/write

The fullscreen mode of the surface.

gravity

gravity: Gravity | int  # read/write

The gravity to use when resizing a surface programmatically.

Gravity describes which point of the surface we want to keep fixed (meaning that the surface will grow in the opposite direction). For example, a gravity of GDK_GRAVITY_NORTH_EAST means that we want to fix top right corner of the surface.

This property is just a hint that may affect the result when negotiating toplevel sizes with the windowing system. It does not affect interactive resizes started with Toplevel.begin_resize.

icon_list

icon_list: int  # read/write

A list of textures to use as icon.

modal

modal: bool  # read/write

Whether the surface is modal.

shortcuts_inhibited

shortcuts_inhibited: bool  # read-only

Whether the surface should inhibit keyboard shortcuts.

startup_id

startup_id: str  # read/write

The startup ID of the surface.

See AppLaunchContext for more information about startup feedback.

state

state: ToplevelState | int  # read-only

The state of the toplevel.

title

title: str  # read/write

The title of the surface.

transient_for

transient_for: Surface  # read/write

The transient parent of the surface.

Signals

compute-size

def on_compute_size(self, size: ToplevelSize) -> None: ...

Emitted when the size for the surface needs to be computed, when it is present.

This signal will normally be emitted during or after a call to Toplevel.present, depending on the configuration received by the windowing system. It may also be emitted at any other point in time, in response to the windowing system spontaneously changing the configuration of the toplevel surface.

It is the responsibility of the toplevel user to handle this signal and compute the desired size of the toplevel, given the information passed via the ToplevelSize object. Failing to do so will result in an arbitrary size being used as a result.