-
Notifications
You must be signed in to change notification settings - Fork 32
feat: expose a method to move XWayland window position relative to wl_surface #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| find_package(Qt6 REQUIRED COMPONENTS WaylandClient Widgets) | ||
| find_package(TreelandProtocols REQUIRED) | ||
|
|
||
| qt_add_executable(test-set-xwindow-position | ||
| main.cpp | ||
| ) | ||
|
|
||
| qt_generate_wayland_protocol_client_sources(test-set-xwindow-position | ||
| FILES | ||
| ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-dde-shell-v1.xml | ||
| NO_INCLUDE_CORE_ONLY | ||
| ) | ||
|
|
||
| target_link_libraries(test-set-xwindow-position | ||
| PRIVATE | ||
| Qt6::Gui | ||
| Qt6::GuiPrivate | ||
| Qt6::Widgets | ||
| Qt6::WaylandClient | ||
| ) | ||
|
|
||
| install(TARGETS test-set-xwindow-position RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright (C) 2025 UnionTech Software Technology Co., Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | ||
|
|
||
| #include <QDebug> | ||
| #include <QFile> | ||
| #include <QGuiApplication> | ||
| #include <QtWidgets/QtWidgets> | ||
| #include <QtWaylandClient/QWaylandClientExtension> | ||
| #include <QTimer> | ||
|
|
||
| #include <qpa/qplatformnativeinterface.h> | ||
|
|
||
| #include <qwayland-treeland-dde-shell-v1.h> | ||
|
|
||
| #include <unistd.h> | ||
|
|
||
| class DDEShellManagerV1 | ||
| : public QWaylandClientExtensionTemplate<DDEShellManagerV1> | ||
| , public QtWayland::treeland_dde_shell_manager_v1 | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| DDEShellManagerV1() | ||
| : QWaylandClientExtensionTemplate<DDEShellManagerV1>( | ||
| treeland_dde_shell_manager_v1_interface.version) | ||
| { | ||
| } | ||
| }; | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| QApplication app(argc, argv); | ||
|
|
||
| qWarning() | ||
| << "In this example, an xeyes will be launched. Its window will be moved to (0, 0) " | ||
| "first using X API. Then, A test window of size 640x480 will be created. The xeyes " | ||
| "window will be moved to the top-right of the test window once per second using " | ||
| "set_xwindow_position_relative().\n\n" | ||
| "xeyes should be installed to run this example (sudo apt install x11-apps)."; | ||
|
|
||
| system("bash -c \"pkill xeyes; xeyes & disown\""); | ||
| sleep(1); | ||
| system("xdotool search --name \"xeyes\" windowmove 0 0"); | ||
| sleep(1); | ||
| system("xdotool search --name \"xeyes\" > /tmp/xeyes_wid.txt"); | ||
|
|
||
| QWidget *window = new QWidget(); | ||
| window->resize(640, 480); | ||
| window->setWindowTitle("Test set xwindow position"); | ||
| window->show(); | ||
|
|
||
| uint32_t wid = 0; | ||
| QFile file("/tmp/xeyes_wid.txt"); | ||
| if (file.open(QIODevice::ReadWrite)) { | ||
| wid = file.readLine().trimmed().toUInt(); | ||
| file.close(); | ||
| file.remove(); | ||
| } else { | ||
| qCritical() << "Failed to open /tmp/xeyes_wid.txt"; | ||
| return 1; | ||
| } | ||
|
|
||
| DDEShellManagerV1 manager; | ||
|
|
||
| struct wl_callback_listener callback_listener = { .done = []([[maybe_unused]] void *data, | ||
| wl_callback *callback, | ||
| uint32_t ok) { | ||
| wl_callback_destroy(callback); | ||
| if (ok != 0) | ||
| qCritical() << "Failed to set xwindow position relative!"; | ||
| else | ||
| qWarning() << "Successfully set xwindow position relative. Check screen for result."; | ||
| } }; | ||
|
|
||
| QTimer timer; | ||
| QObject::connect(&timer, &QTimer::timeout, [&] { | ||
| if (!manager.isActive()) { | ||
| qCritical() << "DDEShellManagerV1 is not active!"; | ||
| return; | ||
calsys456 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| struct wl_surface *surface = static_cast<wl_surface *>( | ||
| QGuiApplication::platformNativeInterface()->nativeResourceForWindow( | ||
| QStringLiteral("surface").toLocal8Bit(), | ||
| window->windowHandle())); | ||
|
|
||
| wl_fixed_t dx = wl_fixed_from_int(640); | ||
| wl_fixed_t dy = wl_fixed_from_int(0); | ||
|
|
||
| wl_callback *callback = manager.set_xwindow_position_relative(wid, surface, dx, dy); | ||
| wl_callback_add_listener(callback, &callback_listener, nullptr); | ||
| qWarning() << "Setting xwindow position relative, wait for result..."; | ||
| }); | ||
| timer.start(1000); | ||
|
|
||
| return app.exec(); | ||
| } | ||
|
|
||
| #include "main.moc" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.