From d6a4ebc742dc4db6f1c2d49e2c6bd82010a3571f Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 27 Mar 2025 14:39:27 -0700 Subject: [PATCH] hyprland/ipc: provide default sorting for workspaces --- src/wayland/hyprland/ipc/connection.cpp | 10 +++++++--- src/wayland/hyprland/ipc/connection.hpp | 2 ++ src/wayland/hyprland/ipc/qml.hpp | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/wayland/hyprland/ipc/connection.cpp b/src/wayland/hyprland/ipc/connection.cpp index 29a9cf44..5e56e09b 100644 --- a/src/wayland/hyprland/ipc/connection.cpp +++ b/src/wayland/hyprland/ipc/connection.cpp @@ -289,7 +289,7 @@ void HyprlandIpc::onEvent(HyprlandIpcEvent* event) { if (!existed) { this->refreshWorkspaces(false); - this->mWorkspaces.insertObject(workspace); + this->mWorkspaces.insertObjectSorted(workspace, &HyprlandIpc::compareWorkspaces); } } else if (event->name == "destroyworkspacev2") { auto args = event->parseView(2); @@ -413,7 +413,7 @@ HyprlandIpc::findWorkspaceByName(const QString& name, bool createIfMissing, qint auto* workspace = new HyprlandWorkspace(this); workspace->updateInitial(id, name); - this->mWorkspaces.insertObject(workspace); + this->mWorkspaces.insertObjectSorted(workspace, &HyprlandIpc::compareWorkspaces); return workspace; } else { return nullptr; @@ -464,7 +464,7 @@ void HyprlandIpc::refreshWorkspaces(bool canCreate) { workspace->updateFromObject(object); if (!existed) { - this->mWorkspaces.insertObject(workspace); + this->mWorkspaces.insertObjectSorted(workspace, &HyprlandIpc::compareWorkspaces); } ids.push_back(id); @@ -596,4 +596,8 @@ void HyprlandIpc::refreshMonitors(bool canCreate) { }); } +bool HyprlandIpc::compareWorkspaces(HyprlandWorkspace* a, HyprlandWorkspace* b) { + return a->bindableId().value() > b->bindableId().value(); +} + } // namespace qs::hyprland::ipc diff --git a/src/wayland/hyprland/ipc/connection.hpp b/src/wayland/hyprland/ipc/connection.hpp index b25643b1..5a5783f8 100644 --- a/src/wayland/hyprland/ipc/connection.hpp +++ b/src/wayland/hyprland/ipc/connection.hpp @@ -120,6 +120,8 @@ private: void onEvent(HyprlandIpcEvent* event); + static bool compareWorkspaces(HyprlandWorkspace* a, HyprlandWorkspace* b); + QLocalSocket eventSocket; QString mRequestSocketPath; QString mEventSocketPath; diff --git a/src/wayland/hyprland/ipc/qml.hpp b/src/wayland/hyprland/ipc/qml.hpp index bab90602..f776ef6a 100644 --- a/src/wayland/hyprland/ipc/qml.hpp +++ b/src/wayland/hyprland/ipc/qml.hpp @@ -27,7 +27,9 @@ class HyprlandIpcQml: public QObject { /// All hyprland monitors. QSDOC_TYPE_OVERRIDE(ObjectModel*); Q_PROPERTY(UntypedObjectModel* monitors READ monitors CONSTANT); - /// All hyprland workspaces. + /// All hyprland workspaces, sorted by id. + /// + /// > [!NOTE] Named workspaces have a negative id, and will appear before unnamed workspaces. QSDOC_TYPE_OVERRIDE(ObjectModel*); Q_PROPERTY(UntypedObjectModel* workspaces READ workspaces CONSTANT); // clang-format on