2022-04-11 19:51:37 +02:00
|
|
|
#include "Workspace.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
2024-03-03 19:39:20 +01:00
|
|
|
#include "../config/ConfigValue.hpp"
|
2022-04-11 19:51:37 +02:00
|
|
|
|
2024-06-11 17:17:45 +02:00
|
|
|
#include <hyprutils/string/String.hpp>
|
|
|
|
using namespace Hyprutils::String;
|
|
|
|
|
2024-08-08 21:01:50 +02:00
|
|
|
PHLWORKSPACE CWorkspace::create(WORKSPACEID id, MONITORID monitorID, std::string name, bool special, bool isEmtpy) {
|
2024-05-12 01:03:32 +02:00
|
|
|
PHLWORKSPACE workspace = makeShared<CWorkspace>(id, monitorID, name, special, isEmtpy);
|
2024-04-02 21:32:39 +02:00
|
|
|
workspace->init(workspace);
|
|
|
|
return workspace;
|
|
|
|
}
|
|
|
|
|
2024-08-08 21:01:50 +02:00
|
|
|
CWorkspace::CWorkspace(WORKSPACEID id, MONITORID monitorID, std::string name, bool special, bool isEmtpy) {
|
2022-12-16 18:17:31 +01:00
|
|
|
m_iMonitorID = monitorID;
|
2024-03-08 18:39:53 +01:00
|
|
|
m_iID = id;
|
2022-12-16 18:17:31 +01:00
|
|
|
m_szName = name;
|
2022-05-31 14:01:00 +02:00
|
|
|
m_bIsSpecialWorkspace = special;
|
2024-05-12 01:03:32 +02:00
|
|
|
m_bWasCreatedEmtpy = isEmtpy;
|
2024-04-02 21:32:39 +02:00
|
|
|
}
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2024-04-02 21:32:39 +02:00
|
|
|
void CWorkspace::init(PHLWORKSPACE self) {
|
|
|
|
m_pSelf = self;
|
|
|
|
|
|
|
|
m_vRenderOffset.create(m_bIsSpecialWorkspace ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"),
|
|
|
|
self, AVARDAMAGE_ENTIRE);
|
|
|
|
m_fAlpha.create(AVARTYPE_FLOAT,
|
|
|
|
m_bIsSpecialWorkspace ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), self,
|
2024-03-29 01:23:16 +01:00
|
|
|
AVARDAMAGE_ENTIRE);
|
2023-01-05 19:25:45 +01:00
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
2022-06-28 12:39:56 +02:00
|
|
|
|
2022-11-04 16:56:31 +01:00
|
|
|
m_vRenderOffset.registerVar();
|
|
|
|
m_fAlpha.registerVar();
|
|
|
|
|
2024-04-05 17:54:30 +02:00
|
|
|
const auto RULEFORTHIS = g_pConfigManager->getWorkspaceRuleFor(self);
|
|
|
|
if (RULEFORTHIS.defaultName.has_value())
|
|
|
|
m_szName = RULEFORTHIS.defaultName.value();
|
2024-02-27 23:44:42 +01:00
|
|
|
|
2024-04-02 13:10:03 +02:00
|
|
|
m_pFocusedWindowHook = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any param) {
|
2024-04-27 13:43:12 +02:00
|
|
|
const auto PWINDOW = std::any_cast<PHLWINDOW>(param);
|
2024-04-02 13:10:03 +02:00
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
if (PWINDOW == m_pLastFocusedWindow.lock())
|
|
|
|
m_pLastFocusedWindow.reset();
|
2024-04-02 13:10:03 +02:00
|
|
|
});
|
|
|
|
|
2024-04-02 21:32:39 +02:00
|
|
|
m_bInert = false;
|
|
|
|
|
2024-04-05 20:32:05 +02:00
|
|
|
const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(self);
|
|
|
|
m_bPersistent = WORKSPACERULE.isPersistent;
|
|
|
|
|
2024-05-12 01:03:32 +02:00
|
|
|
if (self->m_bWasCreatedEmtpy)
|
|
|
|
if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd)
|
|
|
|
g_pKeybindManager->spawn(*cmd);
|
2024-04-06 16:53:32 +02:00
|
|
|
|
2023-07-06 15:23:11 +02:00
|
|
|
g_pEventManager->postEvent({"createworkspace", m_szName});
|
2024-03-08 18:39:53 +01:00
|
|
|
g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)});
|
2023-02-19 21:54:53 +01:00
|
|
|
EMIT_HOOK_EVENT("createWorkspace", this);
|
2022-04-11 19:51:37 +02:00
|
|
|
}
|
|
|
|
|
2024-06-22 23:52:42 +02:00
|
|
|
SWorkspaceIDName CWorkspace::getPrevWorkspaceIDName(bool perMonitor) const {
|
|
|
|
if (perMonitor)
|
|
|
|
return m_sPrevWorkspacePerMonitor;
|
|
|
|
|
|
|
|
return m_sPrevWorkspace;
|
|
|
|
}
|
|
|
|
|
2022-04-11 19:51:37 +02:00
|
|
|
CWorkspace::~CWorkspace() {
|
2022-05-12 11:27:31 +02:00
|
|
|
m_vRenderOffset.unregister();
|
|
|
|
|
2023-09-06 12:51:36 +02:00
|
|
|
Debug::log(LOG, "Destroying workspace ID {}", m_iID);
|
2022-05-30 20:05:38 +02:00
|
|
|
|
2024-04-08 19:28:11 +02:00
|
|
|
// check if g_pHookSystem and g_pEventManager exist, they might be destroyed as in when the compositor is closing.
|
|
|
|
if (g_pHookSystem)
|
|
|
|
g_pHookSystem->unhook(m_pFocusedWindowHook);
|
|
|
|
|
|
|
|
if (g_pEventManager) {
|
|
|
|
g_pEventManager->postEvent({"destroyworkspace", m_szName});
|
|
|
|
g_pEventManager->postEvent({"destroyworkspacev2", std::format("{},{}", m_iID, m_szName)});
|
|
|
|
EMIT_HOOK_EVENT("destroyWorkspace", this);
|
|
|
|
}
|
2022-05-16 23:13:32 +02:00
|
|
|
}
|
|
|
|
|
2022-05-30 20:05:38 +02:00
|
|
|
void CWorkspace::startAnim(bool in, bool left, bool instant) {
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle;
|
|
|
|
static auto PWORKSPACEGAP = CConfigValue<Hyprlang::INT>("general:gaps_workspaces");
|
2022-05-16 23:13:32 +02:00
|
|
|
|
2024-03-31 03:14:26 +02:00
|
|
|
// set floating windows offset callbacks
|
|
|
|
m_vRenderOffset.setUpdateCallback([&](void*) {
|
|
|
|
for (auto& w : g_pCompositor->m_vWindows) {
|
2024-04-27 13:43:12 +02:00
|
|
|
if (!validMapped(w) || w->workspaceID() != m_iID)
|
2024-03-31 03:14:26 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
w->onWorkspaceAnimUpdate();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-10-15 20:07:23 +02:00
|
|
|
if (ANIMSTYLE.starts_with("slidefade")) {
|
2023-08-17 22:30:20 +02:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
|
|
|
|
float movePerc = 100.f;
|
|
|
|
|
|
|
|
if (ANIMSTYLE.find("%") != std::string::npos) {
|
|
|
|
try {
|
|
|
|
auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' ') + 1);
|
|
|
|
movePerc = std::stoi(percstr.substr(0, percstr.length() - 1));
|
2023-08-25 18:05:08 +02:00
|
|
|
} catch (std::exception& e) { Debug::log(ERR, "Error in startAnim: invalid percentage"); }
|
2023-08-17 22:30:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
|
|
|
|
|
2023-10-15 20:07:23 +02:00
|
|
|
if (ANIMSTYLE.starts_with("slidefadevert")) {
|
2023-08-17 22:30:20 +02:00
|
|
|
if (in) {
|
|
|
|
m_fAlpha.setValueAndWarp(0.f);
|
2024-06-19 16:20:06 +02:00
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0.0, (left ? PMONITOR->vecSize.y : -PMONITOR->vecSize.y) * (movePerc / 100.f)));
|
2023-08-17 22:30:20 +02:00
|
|
|
m_fAlpha = 1.f;
|
|
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
|
|
} else {
|
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
|
|
m_fAlpha = 0.f;
|
2024-06-19 16:20:06 +02:00
|
|
|
m_vRenderOffset = Vector2D(0.0, (left ? -PMONITOR->vecSize.y : PMONITOR->vecSize.y) * (movePerc / 100.f));
|
2023-08-17 22:30:20 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (in) {
|
|
|
|
m_fAlpha.setValueAndWarp(0.f);
|
2024-06-19 16:20:06 +02:00
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D((left ? PMONITOR->vecSize.x : -PMONITOR->vecSize.x) * (movePerc / 100.f), 0.0));
|
2023-08-17 22:30:20 +02:00
|
|
|
m_fAlpha = 1.f;
|
|
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
|
|
} else {
|
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
|
|
m_fAlpha = 0.f;
|
2024-06-19 16:20:06 +02:00
|
|
|
m_vRenderOffset = Vector2D((left ? -PMONITOR->vecSize.x : PMONITOR->vecSize.x) * (movePerc / 100.f), 0.0);
|
2023-08-17 22:30:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ANIMSTYLE == "fade") {
|
2022-05-18 12:39:20 +02:00
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0, 0)); // fix a bug, if switching from slide -> fade.
|
|
|
|
|
2022-05-16 23:13:32 +02:00
|
|
|
if (in) {
|
|
|
|
m_fAlpha.setValueAndWarp(0.f);
|
2023-01-05 19:25:45 +01:00
|
|
|
m_fAlpha = 1.f;
|
2022-05-16 23:13:32 +02:00
|
|
|
} else {
|
2023-01-05 19:25:45 +01:00
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
2022-05-16 23:13:32 +02:00
|
|
|
m_fAlpha = 0.f;
|
|
|
|
}
|
2022-06-01 20:51:21 +02:00
|
|
|
} else if (ANIMSTYLE == "slidevert") {
|
2022-05-31 17:56:33 +02:00
|
|
|
// fallback is slide
|
2023-12-06 23:54:56 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto YDISTANCE = PMONITOR->vecSize.y + *PWORKSPACEGAP;
|
2022-05-31 17:56:33 +02:00
|
|
|
|
2023-01-05 19:25:45 +01:00
|
|
|
m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide.
|
2022-05-31 17:56:33 +02:00
|
|
|
|
|
|
|
if (in) {
|
2024-06-19 16:20:06 +02:00
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0.0, left ? YDISTANCE : -YDISTANCE));
|
2022-05-31 17:56:33 +02:00
|
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
|
|
} else {
|
2024-06-19 16:20:06 +02:00
|
|
|
m_vRenderOffset = Vector2D(0.0, left ? -YDISTANCE : YDISTANCE);
|
2022-05-31 17:56:33 +02:00
|
|
|
}
|
2022-05-16 23:13:32 +02:00
|
|
|
} else {
|
|
|
|
// fallback is slide
|
2023-12-06 23:54:56 +01:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
|
2024-03-03 19:39:20 +01:00
|
|
|
const auto XDISTANCE = PMONITOR->vecSize.x + *PWORKSPACEGAP;
|
2022-05-18 12:39:20 +02:00
|
|
|
|
2023-01-05 19:25:45 +01:00
|
|
|
m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide.
|
2022-05-18 12:39:20 +02:00
|
|
|
|
2022-05-16 23:13:32 +02:00
|
|
|
if (in) {
|
2024-06-19 16:20:06 +02:00
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(left ? XDISTANCE : -XDISTANCE, 0.0));
|
2022-05-16 23:13:32 +02:00
|
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
|
|
} else {
|
2024-06-19 16:20:06 +02:00
|
|
|
m_vRenderOffset = Vector2D(left ? -XDISTANCE : XDISTANCE, 0.0);
|
2022-05-16 23:13:32 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-30 20:05:38 +02:00
|
|
|
|
2023-08-25 18:05:08 +02:00
|
|
|
if (m_bIsSpecialWorkspace) {
|
|
|
|
// required for open/close animations
|
|
|
|
if (in) {
|
|
|
|
m_fAlpha.setValueAndWarp(0.f);
|
|
|
|
m_fAlpha = 1.f;
|
|
|
|
} else {
|
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
|
|
m_fAlpha = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-30 20:05:38 +02:00
|
|
|
if (instant) {
|
|
|
|
m_vRenderOffset.warp();
|
|
|
|
m_fAlpha.warp();
|
|
|
|
}
|
2022-05-25 10:25:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWorkspace::setActive(bool on) {
|
2023-09-01 17:10:03 +02:00
|
|
|
; // empty until https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/40
|
2022-05-30 20:51:45 +02:00
|
|
|
}
|
|
|
|
|
2024-08-08 21:01:50 +02:00
|
|
|
void CWorkspace::moveToMonitor(const MONITORID& id) {
|
2023-09-01 17:10:03 +02:00
|
|
|
; // empty until https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/40
|
2022-09-01 11:46:36 +02:00
|
|
|
}
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
PHLWINDOW CWorkspace::getLastFocusedWindow() {
|
2024-05-05 18:16:00 +02:00
|
|
|
if (!validMapped(m_pLastFocusedWindow) || m_pLastFocusedWindow->workspaceID() != m_iID)
|
2022-09-01 11:46:36 +02:00
|
|
|
return nullptr;
|
|
|
|
|
2024-04-27 13:43:12 +02:00
|
|
|
return m_pLastFocusedWindow.lock();
|
2022-09-01 11:46:36 +02:00
|
|
|
}
|
2023-04-10 21:07:49 +02:00
|
|
|
|
2024-04-02 21:32:39 +02:00
|
|
|
void CWorkspace::rememberPrevWorkspace(const PHLWORKSPACE& prev) {
|
2023-04-10 21:07:49 +02:00
|
|
|
if (!prev) {
|
2024-06-22 23:52:42 +02:00
|
|
|
m_sPrevWorkspace.id = -1;
|
2023-04-10 21:07:49 +02:00
|
|
|
m_sPrevWorkspace.name = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-11 16:14:43 +02:00
|
|
|
if (prev->m_iID == m_iID) {
|
2023-04-10 21:07:49 +02:00
|
|
|
Debug::log(LOG, "Tried to set prev workspace to the same as current one");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-22 23:52:42 +02:00
|
|
|
m_sPrevWorkspace.id = prev->m_iID;
|
2023-04-10 21:07:49 +02:00
|
|
|
m_sPrevWorkspace.name = prev->m_szName;
|
2024-06-22 23:52:42 +02:00
|
|
|
|
|
|
|
if (prev->m_iMonitorID == m_iMonitorID) {
|
|
|
|
m_sPrevWorkspacePerMonitor.id = prev->m_iID;
|
|
|
|
m_sPrevWorkspacePerMonitor.name = prev->m_szName;
|
|
|
|
}
|
2023-04-10 21:07:49 +02:00
|
|
|
}
|
2023-05-01 16:39:08 +02:00
|
|
|
|
|
|
|
std::string CWorkspace::getConfigName() {
|
|
|
|
if (m_bIsSpecialWorkspace) {
|
2024-04-24 17:07:22 +02:00
|
|
|
return m_szName;
|
2023-05-01 16:39:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_iID > 0)
|
|
|
|
return std::to_string(m_iID);
|
|
|
|
|
|
|
|
return "name:" + m_szName;
|
|
|
|
}
|
2024-03-19 21:56:20 +01:00
|
|
|
|
|
|
|
bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
|
2024-06-11 17:17:45 +02:00
|
|
|
auto selector = trim(selector_);
|
2024-03-19 21:56:20 +01:00
|
|
|
|
|
|
|
if (selector.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (isNumber(selector)) {
|
2024-06-22 23:52:42 +02:00
|
|
|
const auto& [wsid, wsname] = getWorkspaceIDNameFromString(selector);
|
2024-03-19 21:56:20 +01:00
|
|
|
|
|
|
|
if (wsid == WORKSPACE_INVALID)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return wsid == m_iID;
|
|
|
|
|
|
|
|
} else if (selector.starts_with("name:")) {
|
|
|
|
return m_szName == selector.substr(5);
|
2024-04-02 23:58:45 +02:00
|
|
|
} else if (selector.starts_with("special")) {
|
2024-03-20 19:05:57 +01:00
|
|
|
return m_szName == selector;
|
2024-03-19 21:56:20 +01:00
|
|
|
} else {
|
|
|
|
// parse selector
|
|
|
|
|
|
|
|
for (size_t i = 0; i < selector.length(); ++i) {
|
|
|
|
const char& cur = selector[i];
|
|
|
|
if (std::isspace(cur))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Allowed selectors:
|
|
|
|
// r - range: r[1-5]
|
|
|
|
// s - special: s[true]
|
|
|
|
// n - named: n[true] or n[s:string] or n[e:string]
|
|
|
|
// m - monitor: m[monitor_selector]
|
2024-04-09 13:08:38 +02:00
|
|
|
// w - windowCount: w[1-4] or w[1], optional flag t or f for tiled or floating and
|
|
|
|
// flag g to count groups instead of windows, e.g. w[t1-2], w[fg4]
|
2024-04-19 03:44:51 +02:00
|
|
|
// flag v will count only visible windows
|
2024-04-21 02:50:08 +02:00
|
|
|
// f - fullscreen state : f[-1], f[0], f[1], or f[2] for different fullscreen states
|
|
|
|
// -1: no fullscreen, 0: fullscreen, 1: maximized, 2: fullscreen without sending fs state to window
|
2024-03-19 21:56:20 +01:00
|
|
|
|
|
|
|
const auto NEXTSPACE = selector.find_first_of(' ', i);
|
|
|
|
std::string prop = selector.substr(i, NEXTSPACE == std::string::npos ? std::string::npos : NEXTSPACE - i);
|
2024-03-20 03:33:39 +01:00
|
|
|
i = std::min(NEXTSPACE, std::string::npos - 1);
|
2024-03-19 21:56:20 +01:00
|
|
|
|
|
|
|
if (cur == 'r') {
|
2024-08-08 21:01:50 +02:00
|
|
|
WORKSPACEID from = 0, to = 0;
|
2024-03-19 21:56:20 +01:00
|
|
|
if (!prop.starts_with("r[") || !prop.ends_with("]")) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = prop.substr(2, prop.length() - 3);
|
|
|
|
|
|
|
|
if (!prop.contains("-")) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto DASHPOS = prop.find("-");
|
|
|
|
const auto LHS = prop.substr(0, DASHPOS), RHS = prop.substr(DASHPOS + 1);
|
|
|
|
|
|
|
|
if (!isNumber(LHS) || !isNumber(RHS)) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
from = std::stoll(LHS);
|
|
|
|
to = std::stoll(RHS);
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (to < from || to < 1 || from < 1) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (std::clamp(m_iID, from, to) != m_iID)
|
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur == 's') {
|
|
|
|
if (!prop.starts_with("s[") || !prop.ends_with("]")) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = prop.substr(2, prop.length() - 3);
|
|
|
|
|
|
|
|
const auto SHOULDBESPECIAL = configStringToInt(prop);
|
|
|
|
|
|
|
|
if ((bool)SHOULDBESPECIAL != m_bIsSpecialWorkspace)
|
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur == 'm') {
|
|
|
|
if (!prop.starts_with("m[") || !prop.ends_with("]")) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = prop.substr(2, prop.length() - 3);
|
|
|
|
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromString(prop);
|
|
|
|
|
|
|
|
if (!(PMONITOR ? PMONITOR->ID == m_iMonitorID : false))
|
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur == 'n') {
|
|
|
|
if (!prop.starts_with("n[") || !prop.ends_with("]")) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = prop.substr(2, prop.length() - 3);
|
|
|
|
|
2024-04-13 02:55:17 +02:00
|
|
|
if (prop.starts_with("s:") && !m_szName.starts_with(prop.substr(2)))
|
|
|
|
return false;
|
|
|
|
if (prop.starts_with("e:") && !m_szName.ends_with(prop.substr(2)))
|
|
|
|
return false;
|
2024-03-19 21:56:20 +01:00
|
|
|
|
|
|
|
const auto WANTSNAMED = configStringToInt(prop);
|
|
|
|
|
|
|
|
if (WANTSNAMED != (m_iID <= -1337))
|
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur == 'w') {
|
2024-08-08 21:01:50 +02:00
|
|
|
WORKSPACEID from = 0, to = 0;
|
2024-03-19 21:56:20 +01:00
|
|
|
if (!prop.starts_with("w[") || !prop.ends_with("]")) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = prop.substr(2, prop.length() - 3);
|
|
|
|
|
2024-04-19 03:44:51 +02:00
|
|
|
int wantsOnlyTiled = -1;
|
|
|
|
bool wantsCountGroup = false;
|
|
|
|
bool wantsCountVisible = false;
|
2024-04-09 13:08:38 +02:00
|
|
|
|
|
|
|
int flagCount = 0;
|
|
|
|
for (auto& flag : prop) {
|
|
|
|
if (flag == 't' && wantsOnlyTiled == -1) {
|
|
|
|
wantsOnlyTiled = 1;
|
|
|
|
flagCount++;
|
|
|
|
} else if (flag == 'f' && wantsOnlyTiled == -1) {
|
|
|
|
wantsOnlyTiled = 0;
|
|
|
|
flagCount++;
|
|
|
|
} else if (flag == 'g' && !wantsCountGroup) {
|
|
|
|
wantsCountGroup = true;
|
|
|
|
flagCount++;
|
2024-04-19 03:44:51 +02:00
|
|
|
} else if (flag == 'v' && !wantsCountVisible) {
|
|
|
|
wantsCountVisible = true;
|
|
|
|
flagCount++;
|
2024-04-09 13:08:38 +02:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2024-03-19 21:56:20 +01:00
|
|
|
}
|
2024-04-09 13:08:38 +02:00
|
|
|
prop = prop.substr(flagCount);
|
2024-03-19 21:56:20 +01:00
|
|
|
|
|
|
|
if (!prop.contains("-")) {
|
|
|
|
// try single
|
|
|
|
|
|
|
|
if (!isNumber(prop)) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
from = std::stoll(prop);
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-09 13:08:38 +02:00
|
|
|
int count;
|
|
|
|
if (wantsCountGroup)
|
2024-04-19 03:44:51 +02:00
|
|
|
count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
|
|
|
|
wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
|
2024-04-09 13:08:38 +02:00
|
|
|
else
|
2024-04-19 03:44:51 +02:00
|
|
|
count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
|
|
|
|
wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
|
2024-04-09 13:08:38 +02:00
|
|
|
|
|
|
|
if (count != from)
|
|
|
|
return false;
|
|
|
|
continue;
|
2024-03-19 21:56:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto DASHPOS = prop.find("-");
|
|
|
|
const auto LHS = prop.substr(0, DASHPOS), RHS = prop.substr(DASHPOS + 1);
|
|
|
|
|
|
|
|
if (!isNumber(LHS) || !isNumber(RHS)) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
from = std::stoll(LHS);
|
|
|
|
to = std::stoll(RHS);
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (to < from || to < 1 || from < 1) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-08-08 21:01:50 +02:00
|
|
|
WORKSPACEID count;
|
2024-04-09 13:08:38 +02:00
|
|
|
if (wantsCountGroup)
|
2024-04-19 03:44:51 +02:00
|
|
|
count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
|
|
|
|
wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
|
2024-04-09 13:08:38 +02:00
|
|
|
else
|
2024-04-19 03:44:51 +02:00
|
|
|
count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
|
|
|
|
wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
|
2024-04-09 13:08:38 +02:00
|
|
|
|
|
|
|
if (std::clamp(count, from, to) != count)
|
2024-03-19 21:56:20 +01:00
|
|
|
return false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-04-21 02:50:08 +02:00
|
|
|
if (cur == 'f') {
|
|
|
|
if (!prop.starts_with("f[") || !prop.ends_with("]")) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = prop.substr(2, prop.length() - 3);
|
|
|
|
int FSSTATE = -1;
|
|
|
|
try {
|
|
|
|
FSSTATE = std::stoi(prop);
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (FSSTATE) {
|
|
|
|
case -1: // no fullscreen
|
|
|
|
if (m_bHasFullscreenWindow)
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case 0: // fullscreen full
|
2024-07-31 19:55:52 +02:00
|
|
|
if (!m_bHasFullscreenWindow || m_efFullscreenMode != FSMODE_FULLSCREEN)
|
2024-04-21 02:50:08 +02:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case 1: // maximized
|
2024-07-31 19:55:52 +02:00
|
|
|
if (!m_bHasFullscreenWindow || m_efFullscreenMode != FSMODE_MAXIMIZED)
|
2024-04-21 02:50:08 +02:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-03-19 21:56:20 +01:00
|
|
|
Debug::log(LOG, "Invalid selector {}", selector);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
2024-03-20 03:33:39 +01:00
|
|
|
}
|
2024-04-02 21:32:39 +02:00
|
|
|
|
|
|
|
void CWorkspace::markInert() {
|
2024-04-05 17:57:46 +02:00
|
|
|
m_bInert = true;
|
|
|
|
m_iID = WORKSPACE_INVALID;
|
2024-08-08 21:01:50 +02:00
|
|
|
m_iMonitorID = MONITOR_INVALID;
|
2024-04-05 17:57:46 +02:00
|
|
|
m_bVisible = false;
|
2024-04-02 21:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CWorkspace::inert() {
|
|
|
|
return m_bInert;
|
|
|
|
}
|