Skip to content

Gtk.WindowControls

class — extends Widget, Accessible, Buildable, ConstraintTarget

Shows window frame controls.

Typical window frame controls are minimize, maximize and close buttons, and the window icon.

<picture> <source srcset="windowcontrols-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkWindowControls" src="windowcontrols.png"> </picture>

GtkWindowControls only displays start or end side of the controls (see WindowControls.side), so it's intended to be always used in pair with another GtkWindowControls for the opposite side, for example:

<object class="GtkBox">
  <child>
    <object class="GtkWindowControls">
      <property name="side">start</property>
    </object>
  </child>

  ...

  <child>
    <object class="GtkWindowControls">
      <property name="side">end</property>
    </object>
  </child>
</object>

CSS nodes

windowcontrols
├── [image.icon]
├── [button.minimize]
├── [button.maximize]
╰── [button.close]

A GtkWindowControls' CSS node is called windowcontrols. It contains subnodes corresponding to each title button. Which of the title buttons exist and where they are placed exactly depends on the desktop environment and WindowControls.decoration-layout value.

When WindowControls.empty is true, it gets the .empty style class.

Accessibility

GtkWindowControls uses the AccessibleRole.group role.

Constructors

new

@classmethod
def new(cls, side: PackType | int) -> Widget

Creates a new GtkWindowControls.

Parameters:

  • side — the side

Methods

get_decoration_layout

def get_decoration_layout(self) -> str | None

Gets the decoration layout of this window controls widget

get_empty

def get_empty(self) -> bool

Gets whether the widget has any window buttons.

get_side

def get_side(self) -> PackType

Gets the side to which this window controls widget belongs.

get_use_native_controls

def get_use_native_controls(self) -> bool

Returns whether platform native window controls are shown.

set_decoration_layout

def set_decoration_layout(self, layout: str | None = ...) -> None

Sets the decoration layout for the title buttons.

This overrides the Settings.gtk-decoration-layout setting.

The format of the string is button names, separated by commas. A colon separates the buttons that should appear on the left from those on the right. Recognized button names are minimize, maximize, close and icon (the window icon).

For example, “icon:minimize,maximize,close” specifies a icon on the left, and minimize, maximize and close buttons on the right.

If WindowControls.side value is PackType.start, self will display the part before the colon, otherwise after that.

Parameters:

  • layout — a decoration layout, or NULL to unset the layout

set_side

def set_side(self, side: PackType | int) -> None

Determines which part of decoration layout the window controls widget uses.

See WindowControls.decoration-layout.

Parameters:

  • side — a side

set_use_native_controls

def set_use_native_controls(self, setting: bool) -> None

Sets whether platform native window controls are used.

This option shows the "stoplight" buttons on macOS. For Linux, this option has no effect.

See also Using GTK on Apple macOS.

Parameters:

  • setting — true to show native window controls

Properties

decoration_layout

decoration_layout: str  # read/write

The decoration layout for window buttons.

If this property is not set, the Settings.gtk-decoration-layout setting is used.

empty

empty: bool  # read-only

Whether the widget has any window buttons.

side

side: PackType | int  # read/write

Whether the widget shows start or end side of the decoration layout.

See WindowControls.decoration_layout.

use_native_controls

use_native_controls: bool  # read/write

Whether to show platform native close/minimize/maximize buttons.

For macOS, the HeaderBar.decoration-layout property controls the use of native window controls.

On other platforms, this option has no effect.

See also Using GTK on Apple macOS.