|
| 1 | +#include "ext_workspace.hpp" |
| 2 | + |
| 3 | +#include <qloggingcategory.h> |
| 4 | +#include <qobject.h> |
| 5 | +#include <qtmetamacros.h> |
| 6 | +#include <qtypes.h> |
| 7 | +#include <qwayland-ext-workspace-v1.h> |
| 8 | +#include <wayland-ext-workspace-v1-client-protocol.h> |
| 9 | + |
| 10 | +namespace qs::wayland::workspace { |
| 11 | + |
| 12 | +Q_LOGGING_CATEGORY(logWorkspace, "quickshell.wm.wayland.workspace"); |
| 13 | + |
| 14 | +WorkspaceManager::WorkspaceManager(): QWaylandClientExtensionTemplate(1) { this->initialize(); } |
| 15 | + |
| 16 | +WorkspaceManager* WorkspaceManager::instance() { |
| 17 | + static auto* instance = new WorkspaceManager(); |
| 18 | + return instance; |
| 19 | +} |
| 20 | + |
| 21 | +void WorkspaceManager::ext_workspace_manager_v1_workspace_group( |
| 22 | + ::ext_workspace_group_handle_v1* handle |
| 23 | +) { |
| 24 | + auto* group = new WorkspaceGroup(handle); |
| 25 | + qCDebug(logWorkspace) << "Created group" << group; |
| 26 | + this->mGroups.insert(handle, group); |
| 27 | + emit this->groupCreated(group); |
| 28 | +} |
| 29 | + |
| 30 | +void WorkspaceManager::ext_workspace_manager_v1_workspace(::ext_workspace_handle_v1* handle) { |
| 31 | + auto* workspace = new Workspace(handle); |
| 32 | + qCDebug(logWorkspace) << "Created workspace" << workspace; |
| 33 | + this->mWorkspaces.insert(handle, workspace); |
| 34 | + emit this->workspaceCreated(workspace); |
| 35 | +}; |
| 36 | + |
| 37 | +void WorkspaceManager::destroyWorkspace(Workspace* workspace) { |
| 38 | + this->mWorkspaces.remove(workspace->object()); |
| 39 | + this->destroyedWorkspaces.append(workspace); |
| 40 | + emit this->workspaceDestroyed(workspace); |
| 41 | +} |
| 42 | + |
| 43 | +void WorkspaceManager::destroyGroup(WorkspaceGroup* group) { |
| 44 | + this->mGroups.remove(group->object()); |
| 45 | + this->destroyedGroups.append(group); |
| 46 | + emit this->groupDestroyed(group); |
| 47 | +} |
| 48 | + |
| 49 | +void WorkspaceManager::ext_workspace_manager_v1_done() { |
| 50 | + qCDebug(logWorkspace) << "Workspace changes done"; |
| 51 | + emit this->serverCommit(); |
| 52 | + |
| 53 | + for (auto* workspace: this->destroyedWorkspaces) delete workspace; |
| 54 | + for (auto* group: this->destroyedGroups) delete group; |
| 55 | + this->destroyedWorkspaces.clear(); |
| 56 | + this->destroyedGroups.clear(); |
| 57 | +} |
| 58 | + |
| 59 | +void WorkspaceManager::ext_workspace_manager_v1_finished() { |
| 60 | + qCWarning(logWorkspace) << "ext_workspace_manager_v1.finished() was received"; |
| 61 | +} |
| 62 | + |
| 63 | +Workspace::~Workspace() { |
| 64 | + if (this->isInitialized()) this->destroy(); |
| 65 | +} |
| 66 | + |
| 67 | +void Workspace::ext_workspace_handle_v1_id(const QString& id) { |
| 68 | + qCDebug(logWorkspace) << "Updated id for workspace" << this << "to" << id; |
| 69 | + this->id = id; |
| 70 | +} |
| 71 | + |
| 72 | +void Workspace::ext_workspace_handle_v1_name(const QString& name) { |
| 73 | + qCDebug(logWorkspace) << "Updated name for workspace" << this << "to" << name; |
| 74 | + this->name = name; |
| 75 | +} |
| 76 | + |
| 77 | +void Workspace::ext_workspace_handle_v1_coordinates(wl_array* coordinates) { |
| 78 | + this->coordinates.clear(); |
| 79 | + |
| 80 | + auto* data = static_cast<qint32*>(coordinates->data); |
| 81 | + auto size = static_cast<qsizetype>(coordinates->size / sizeof(qint32)); |
| 82 | + |
| 83 | + for (auto i = 0; i != size; ++i) { |
| 84 | + this->coordinates.append(data[i]); // NOLINT |
| 85 | + } |
| 86 | + |
| 87 | + qCDebug(logWorkspace) << "Updated coordinates for workspace" << this << "to" << this->coordinates; |
| 88 | +} |
| 89 | + |
| 90 | +void Workspace::ext_workspace_handle_v1_state(quint32 state) { |
| 91 | + this->active = state & ext_workspace_handle_v1::state_active; |
| 92 | + this->urgent = state & ext_workspace_handle_v1::state_urgent; |
| 93 | + this->hidden = state & ext_workspace_handle_v1::state_hidden; |
| 94 | + |
| 95 | + qCDebug(logWorkspace).nospace() << "Updated state for workspace " << this |
| 96 | + << " to [active: " << this->active << ", urgent: " << this->urgent |
| 97 | + << ", hidden: " << this->hidden << ']'; |
| 98 | +} |
| 99 | + |
| 100 | +void Workspace::ext_workspace_handle_v1_capabilities(quint32 capabilities) { |
| 101 | + this->canActivate = capabilities & ext_workspace_handle_v1::workspace_capabilities_activate; |
| 102 | + this->canDeactivate = capabilities & ext_workspace_handle_v1::workspace_capabilities_deactivate; |
| 103 | + this->canRemove = capabilities & ext_workspace_handle_v1::workspace_capabilities_remove; |
| 104 | + this->canAssign = capabilities & ext_workspace_handle_v1::workspace_capabilities_assign; |
| 105 | + |
| 106 | + qCDebug(logWorkspace).nospace() << "Updated capabilities for workspace " << this |
| 107 | + << " to [activate: " << this->canActivate |
| 108 | + << ", deactivate: " << this->canDeactivate |
| 109 | + << ", remove: " << this->canRemove |
| 110 | + << ", assign: " << this->canAssign << ']'; |
| 111 | +} |
| 112 | + |
| 113 | +void Workspace::ext_workspace_handle_v1_removed() { |
| 114 | + qCDebug(logWorkspace) << "Destroyed workspace" << this; |
| 115 | + WorkspaceManager::instance()->destroyWorkspace(this); |
| 116 | + this->destroy(); |
| 117 | +} |
| 118 | + |
| 119 | +void Workspace::enterGroup(WorkspaceGroup* group) { this->group = group; } |
| 120 | + |
| 121 | +void Workspace::leaveGroup(WorkspaceGroup* group) { |
| 122 | + if (this->group == group) this->group = nullptr; |
| 123 | +} |
| 124 | + |
| 125 | +WorkspaceGroup::~WorkspaceGroup() { |
| 126 | + if (this->isInitialized()) this->destroy(); |
| 127 | +} |
| 128 | + |
| 129 | +void WorkspaceGroup::ext_workspace_group_handle_v1_capabilities(uint32_t capabilities) { |
| 130 | + this->canCreateWorkspace = |
| 131 | + capabilities & ext_workspace_group_handle_v1::group_capabilities_create_workspace; |
| 132 | + |
| 133 | + qCDebug(logWorkspace).nospace() << "Updated capabilities for group " << this |
| 134 | + << " to [create_workspace: " << this->canCreateWorkspace << ']'; |
| 135 | +} |
| 136 | + |
| 137 | +void WorkspaceGroup::ext_workspace_group_handle_v1_output_enter(::wl_output* output) { |
| 138 | + qCDebug(logWorkspace) << "Output" << output << "added to group" << this; |
| 139 | + this->screens.addOutput(output); |
| 140 | +} |
| 141 | + |
| 142 | +void WorkspaceGroup::ext_workspace_group_handle_v1_output_leave(::wl_output* output) { |
| 143 | + qCDebug(logWorkspace) << "Output" << output << "removed from group" << this; |
| 144 | + this->screens.removeOutput(output); |
| 145 | +} |
| 146 | + |
| 147 | +void WorkspaceGroup::ext_workspace_group_handle_v1_workspace_enter(::ext_workspace_handle_v1* handle |
| 148 | +) { |
| 149 | + auto* workspace = WorkspaceManager::instance()->mWorkspaces.value(handle); |
| 150 | + qCDebug(logWorkspace) << "Workspace" << workspace << "added to group" << this; |
| 151 | + |
| 152 | + if (workspace) workspace->enterGroup(this); |
| 153 | +} |
| 154 | + |
| 155 | +void WorkspaceGroup::ext_workspace_group_handle_v1_workspace_leave(::ext_workspace_handle_v1* handle |
| 156 | +) { |
| 157 | + auto* workspace = WorkspaceManager::instance()->mWorkspaces.value(handle); |
| 158 | + qCDebug(logWorkspace) << "Workspace" << workspace << "removed from group" << this; |
| 159 | + |
| 160 | + if (workspace) workspace->leaveGroup(this); |
| 161 | +} |
| 162 | + |
| 163 | +void WorkspaceGroup::ext_workspace_group_handle_v1_removed() { |
| 164 | + qCDebug(logWorkspace) << "Destroyed group" << this; |
| 165 | + WorkspaceManager::instance()->destroyGroup(this); |
| 166 | + this->destroy(); |
| 167 | +} |
| 168 | + |
| 169 | +} // namespace qs::wayland::workspace |
0 commit comments