KX11Extras Class

A collection of functions to obtain information from and manipulate X11 windows. More...

Header: #include <KX11Extras>
CMake: find_package(KF6 REQUIRED COMPONENTS KWindowSystem)
target_link_libraries(mytarget PRIVATE KF6::KWindowSystem)
Since: 5.101
In QML: KX11Extras
Inherits: QObject

Public Types

enum IconSource { NETWM, WMHints, ClassHint, XApp }

Properties

Signals

void activeWindowChanged(WId id)
void compositingChanged(bool enabled)
void currentDesktopChanged(int desktop)
void desktopNamesChanged()
void numberOfDesktopsChanged(int num)
void stackingOrderChanged()
void strutChanged()
void windowAdded(WId id)
void windowChanged(WId id, NET::Properties properties, NET::Properties2 properties2)
void windowRemoved(WId id)
void workAreaChanged()

Static Public Members

void activateWindow(WId win, long time = 0)
WId activeWindow()
(since 6.0) void clearState(WId win, NET::States state)
bool compositingActive()
int currentDesktop()
QString desktopName(int desktop)
void forceActiveWindow(WId win, long time = 0)
bool hasWId(WId id)
QPixmap icon(WId win, int width = -1, int height = -1, bool scale = false)
QPixmap icon(WId win, int width, int height, bool scale, int flags)
QPixmap icon(WId win, int width, int height, bool scale, int flags, NETWinInfo *info)
bool mapViewport()
void minimizeWindow(WId win)
int numberOfDesktops()
QString readNameProperty(WId window, unsigned long atom)
KX11Extras *self()
void setCurrentDesktop(int desktop)
void setDesktopName(int desktop, const QString &name)
void setExtendedStrut(WId win, qreal left_width, qreal left_start, qreal left_end, qreal right_width, qreal right_start, qreal right_end, qreal top_width, qreal top_start, qreal top_end, qreal bottom_width, qreal bottom_start, qreal bottom_end)
void setOnActivities(WId win, const QStringList &activities)
void setOnAllDesktops(WId win, bool b)
void setOnDesktop(WId win, int desktop)
(since 6.0) void setState(WId win, NET::States state)
void setStrut(WId win, qreal left, qreal right, qreal top, qreal bottom)
(since 6.0) void setType(WId win, NET::WindowType windowType)
QList<WId> stackingOrder()
void unminimizeWindow(WId win)
QList<WId> windows()
QRect workArea(int desktop = -1)
QRect workArea(const QList<WId> &excludes, int desktop = -1)

Detailed Description

These are generally not applicable to other window systems.

Member Type Documentation

enum KX11Extras::IconSource

Masks specifying from which sources to read an icon.

They are tried from the best until an icon is found.

ConstantValueDescription
KX11Extras::NETWM1Property from the window manager specification.
KX11Extras::WMHints2From WMHints property.
KX11Extras::ClassHint4Load icon after getting name from the classhint.
KX11Extras::XApp8Load the standard X icon (last fallback).

Property Documentation

[read-only] compositingActive : const bool

This property holds whether desktop compositing is active.

Access functions:

Notifier signal:

void compositingChanged(bool enabled)

Member Function Documentation

[static] void KX11Extras::activateWindow(WId win, long time = 0)

Requests that window win is activated, with the optional X server timestamp time of the user activity that caused this request.

There are two ways how to activate a window, by calling activateWindow() and forceActiveWindow(). Generally, applications shouldn't make attempts to explicitly activate their windows, and instead let the user to activate them. In the special cases where this may be needed, applications should use activateWindow(). Window manager may consider whether this request wouldn't result in focus stealing, which would be obtrusive, and may refuse the request.

The usage of forceActiveWindow() is meant only for pagers and similar tools, which represent direct user actions related to window manipulation. Except for rare cases, this request will be always honored, and normal applications are forbidden to use it.

[static] WId KX11Extras::activeWindow()

Returns the currently active window id, or 0 if no window is active.

[signal] void KX11Extras::activeWindowChanged(WId id)

Hint that <Window> with the given id is active (= has focus) now.

[static, since 6.0] void KX11Extras::clearState(WId win, NET::States state)

Clears the state of window win from state.

Possible values are OR'ed combinations of:

This function was introduced in 6.0.

[static] bool KX11Extras::compositingActive()

Returns true if a compositing manager is running (i.e. ARGB windows are supported, effects will be provided, etc.).

Note: Getter function for property compositingActive.

[signal] void KX11Extras::compositingChanged(bool enabled)

Compositing was enabled or disabled.

Note that this signal may be emitted before any compositing plugins have been initialized in the window manager.

If you need to check if a specific compositing plugin such as the blur effect is enabled, you should track that separately rather than test for it in a slot connected to this signal.

Note: Notifier signal for property compositingActive.

[static] int KX11Extras::currentDesktop()

Returns the current virtual desktop.

See also setCurrentDesktop().

[signal] void KX11Extras::currentDesktopChanged(int desktop)

Switched to another virtual desktop.

[static] QString KX11Extras::desktopName(int desktop)

Returns the name of the specified desktop number.

See also setDesktopName().

[signal] void KX11Extras::desktopNamesChanged()

Desktops have been renamed.

[static] void KX11Extras::forceActiveWindow(WId win, long time = 0)

Sets window win to be the active window, with the optional X server timestamp time of the user activity that caused this request.

Note that this should be called only in special cases, applications shouldn't force themselves or other windows to be the active window. Generally, this call should used only by pagers and similar tools. See the explanation in description of activateWindow().

[static] bool KX11Extras::hasWId(WId id)

Returns whether id is still managed at present.

[static] QPixmap KX11Extras::icon(WId win, int width = -1, int height = -1, bool scale = false)

Returns an icon for window win.

If width and height are specified, the best icon for the requested size is returned.

If scale is true, the icon is smooth-scaled to have exactly the requested size.

[static] QPixmap KX11Extras::icon(WId win, int width, int height, bool scale, int flags)

This is an overloaded function.

Overloaded variant that allows specifying from which sources the icon should be read. You should usually prefer the simpler variant which tries all possibilities to get an icon.

win The id of the window. width The desired width, or -1. height The desired height, or -1. scale If true the icon will be scaled to the desired size. Otherwise the icon will not be modified. flags OR-ed flags from the IconSource enum.

[static] QPixmap KX11Extras::icon(WId win, int width, int height, bool scale, int flags, NETWinInfo *info)

This is an overloaded function.

Overloaded variant that allows passing in the NETWinInfo info to use for reading the information. This variant is only useful on the X11 platform, other platforms do not use NETWinInfo and delegate to the variant without NETWinInfo. Though if compiled with X11 support the X11 variant is used on other platforms if info is not nullptr. This can be used by applications using e.g. platform wayland but also connecting to an XServer.

The NETWinInfo must be constructed with properties:

win The id of the window.

width The desired width, or -1.

height The desired height, or -1.

scale If true the icon will be scaled to the desired size. Otherwise the icon will not be modified.

flags OR-ed flags from the IconSource enum.

[static] bool KX11Extras::mapViewport()

Returns true if viewports are mapped to virtual desktops.

[static] void KX11Extras::minimizeWindow(WId win)

Minimizes the window with id win.

On X11 this follows the protocol described in ICCCM section 4.1.4.

See also unminimizeWindow().

[static] int KX11Extras::numberOfDesktops()

Returns the number of virtual desktops.

[signal] void KX11Extras::numberOfDesktopsChanged(int num)

The number num of desktops changed.

[static] QString KX11Extras::readNameProperty(WId window, unsigned long atom)

Reads and returns the contents of the given text property (WM_NAME, WM_ICON_NAME,...).

[static] KX11Extras *KX11Extras::self()

[static] void KX11Extras::setCurrentDesktop(int desktop)

Convenience function to set the current desktop to desktop number.

See NETRootInfo.

See also currentDesktop().

[static] void KX11Extras::setDesktopName(int desktop, const QString &name)

Sets the name of the specified desktop number.

See also desktopName().

[static] void KX11Extras::setExtendedStrut(WId win, qreal left_width, qreal left_start, qreal left_end, qreal right_width, qreal right_start, qreal right_end, qreal top_width, qreal top_start, qreal top_end, qreal bottom_width, qreal bottom_start, qreal bottom_end)

Sets the strut of window win to left_width ranging from left_start to left_end on the left edge, and simiarly for the other edges. For not reserving a strut, pass 0 as the width. E.g. to reserve 10x10 square in the topleft corner, use e.g. setExtendedStrut( w, 10, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0 ).

win The id of the window.

left_width Width of the strut at the left edge.

left_start Starting y coordinate of the strut at the left edge.

left_end Ending y coordinate of the strut at the left edge.

right_width Width of the strut at the right edge.

right_start Starting y coordinate of the strut at the right edge.

right_end Ending y coordinate of the strut at the right edge.

top_width Width of the strut at the top edge.

top_start Starting x coordinate of the strut at the top edge.

top_end Ending x coordinate of the strut at the top edge.

bottom_width Width of the strut at the bottom edge.

bottom_start Starting x coordinate of the strut at the bottom edge.

bottom_end Ending x coordinate of the strut at the bottom edge.

[static] void KX11Extras::setOnActivities(WId win, const QStringList &activities)

Moves window id win to the list of activities UUIDs.

See also KWindowInfo::activities.

[static] void KX11Extras::setOnAllDesktops(WId win, bool b)

Sets window id win to be present on all virtual desktops if b is true. Otherwise the window lives only on one single desktop.

[static] void KX11Extras::setOnDesktop(WId win, int desktop)

Moves window id win to desktop.

[static, since 6.0] void KX11Extras::setState(WId win, NET::States state)

Sets the state of window win to state.

Possible values are OR'ed combinations of:

This function was introduced in 6.0.

[static] void KX11Extras::setStrut(WId win, qreal left, qreal right, qreal top, qreal bottom)

Convenience function for setExtendedStrut() that automatically makes struts as wide/high as the screen width/height. Sets the strut of window win to left, right, top, bottom.

See also setExtendedStrut.

[static, since 6.0] void KX11Extras::setType(WId win, NET::WindowType windowType)

Sets the type of window win to windowType.

This function was introduced in 6.0.

See also NET::WindowType.

[static] QList<WId> KX11Extras::stackingOrder()

Returns the list of all toplevel windows currently managed by the window manager in the current stacking order (from lower to higher).

May be useful for pagers.

[signal] void KX11Extras::stackingOrderChanged()

Emitted when the stacking order of the window changed.

The new order can be obtained with stackingOrder().

[signal] void KX11Extras::strutChanged()

Something changed with the struts, may or may not have changed the work area.

Usually just using the workAreaChanged() signal is sufficient.

[static] void KX11Extras::unminimizeWindow(WId win)

Unminimizes the window with id win.

On X11 this follows the protocol described in ICCCM section 4.1.4.

See also minimizeWindow().

[signal] void KX11Extras::windowAdded(WId id)

A window with the given id has been added.

[signal] void KX11Extras::windowChanged(WId id, NET::Properties properties, NET::Properties2 properties2)

The window with the given id changed.

Carries the NET::Properties properties and NET::Properties2 properties2 that were changed.

[signal] void KX11Extras::windowRemoved(WId id)

A window with the given id has been removed.

[static] QList<WId> KX11Extras::windows()

Returns the list of all toplevel windows currently managed by the window manager in the order of creation.

Please do not rely on indexes of this list: Whenever you enter Qt's event loop in your application, it may happen that entries are removed or added. Your module should perhaps work on a copy of this list and verify a window with hasWId() before any operations.

Iteration over this list can be done easily with:

QList<WId> windows = KWindowSystem::windows();
for (auto it = windows.cbegin(), end = windows.cend(); it != end; ++it) {
   ... do something here,  (*it) is the current WId.
}

[static] QRect KX11Extras::workArea(int desktop = -1)

Returns the workarea for the specified desktop, or the current work area if no desktop has been specified.

The current desktop corresponds to -1.

[static] QRect KX11Extras::workArea(const QList<WId> &excludes, int desktop = -1)

Returns the workarea for the specified desktop, or the current work area if no desktop has been specified.

A list of struts belonging to clients can be specified with excludes.

[signal] void KX11Extras::workAreaChanged()

The workarea has changed.