How to obtain movement of title bar?

I had create an application with my own title bar and I would like to move the screen of my application in the same way as it occurs with the title bar of KDE.

My KDE version is 5.27.8 and it works with X11.

I need to know the same command/script to move/resize the window from title bar. The goal that I would like to achieve is implementing the move functionality that you can see in the attached image.

You could use QWidget::mouseMoveEvent to detect cursor movement and then QWidget::move to move the window. But that probably won’t work on Wayland since top-level windows aren’t allowed to position themselves there. Although GTK accomplishes this with client-side decorations so it must be possible somehow. Qt also supports them so you can find it somewhere in qtwayland codebase. Though that may require Wayland-specific code.

But I work with X11, not with Wayland. Are there any script that it work with X11 that perform this function?

The application has been designed in Godot 3.5, which has native functions for resizing or fullscreen, but not for moving. Since Godot allows to run the console and execute scripts, I would like to know what scripts KDE uses to perform the move function. This function required is the same that you can see in the image previous.

Any solution?

Please I need help to obtain my goal.

There is no “script” you can use to do this. What you are describing is functionality built into KWin (the window manager).

Applications that use client side decoration can start a move operation by calling xdg_toplevel::move. If Godot does not provide API to call this and there’s no way to call it directlu then you’ll need to request it being added to Godot

But my KDE version is 5.27.8 and it works with X11, not with Wayland.
There is way to obtain it without Wayland?

Not sure if I understand this correctly. So you want some kind of application that performs the same as dragging a window, whether qt or gtk? If that’s the case and you’re on x11, you could do the following. You’ll need xdotool for this. Then you can create a desktop application in ~/.local/share/applications which uses the key shortcut you have set for moving a window in system settings. For example:

[Desktop Entry]
Exec=xdotool key alt+shift+q
GenericName=move windows
Name=Move stuff

Clicking that icon will pop the move icon on the active window. However, there’s a catch. Whereas, if you drag windows that actually have titlebars to the top to maximize, this doesn’t. It only moves the window and unmaximizes a maximized one.

Hi dzon, Thanks for the information but this is not my goal exactly.

I would like to know how to obtain the script or whatever that KDE use. My app would be share and if I create a shortcut and other users haven’t the same shortcut, they will not could move the app.

I want to obtain this without to use any software layer how could be xdotool, directly the software layer/function/script or whatever KDE uses for obtain the move. I only ask for invoke this directly.

Okay, I get it now. I’m afraid Nicolasfella’s right. You’ll need the api for that.

But Nicolasfella’s said to use Wayland and my version of KDE works with X11.

The API to work with X11 windows is called XCB. I don’t know how to work with it personally, only that it’s pretty complex and low-level. But I’m pretty sure that it’s possible to implement what you want in a C or C++ code using XCB. You will need to research how to use it in your context (there is documentation on XCB website, e.g. windowcontextandmanipulation).

If XCB is the API to work with X11, there will be a function already that do the movement of the window. I want to use this function if this exist. In case of this function don´t exist, I would implement it.

Any developer to Konsole or another app that uses this function of move in X11 with XCB API and help me?

KWindowSystem is a KDE library that would let you do this with C++ code I think, no need to deal with raw libxcb. It’s one of the cool and underrated KDE Frameworks, it abstracts windowing system functionality for you.

I might be wrong and @nicolasfella would be able to correct me, but I guess KWindowSystem::NETRootInfo::moveResizeRequest would let you request the window manager/compositor to perform a move operation like that?

Not sure if KWindowSystem::NETRootInfo works on both X11 and Wayland.

On Wayland as nicolasfella said you’d use xdg_toplevel, as mentioned in the Wayland Book.

This seems interesting, but how could I do it?

If there is any code example or script that uses this in somewhere, please let me know.


I’m also interested in a way to trigger a move request from code on wayland. From what I can tell it’s rather easy to fake it with xcb (move requests + global mouse tracking) but next to impossible to go that route with wayland.

I note that the breeze decoration can instigate window drags from empty window areas, so it does seem to be possible. As for xdg_toplevel, I suppose you’d start with something like

auto waylandApp = qApp->nativeInterface<QNativeInterface::QWaylandApplication>();
if (!waylandApp) { return false; }
auto lastSerial = waylandApp->lastInputSerial();

Whereabouts you’d go after that I’m not sure, I admittedly don’t understand how to speak to wayland internals, nor have I felt the need to know until just now.

Since you’re using Godot, you could try setting the window position based on mouse movement. You’d need to store the initial mouse position and get the difference between the initial mouse position and current mouse position, then add that to the window position. Window — Godot Engine (stable) documentation in English

I’ve never actually used Godot before, but this seems like the first thing you could try using only Godot APIs.

I already tried to do that with the mouse position but this not work correctly because the window is moved with slides and the movement is not uniform.

For this reason, I am looking to do it the same way KDE does it and avoid this incorrect movement.

I though that obtain this will be more easy since KDE uses it in all apps but until now I still don’t know how to achieve it.

If you are using Qt use QWindow::startSystemMove.

1 Like