2022-04-11 19:51:37 +02:00
|
|
|
#include "Workspace.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
|
2022-06-28 12:39:56 +02:00
|
|
|
CWorkspace::CWorkspace(int monitorID, std::string name, bool special) {
|
2022-04-11 19:51:37 +02:00
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(monitorID);
|
|
|
|
|
|
|
|
if (!PMONITOR) {
|
|
|
|
Debug::log(ERR, "Attempted a creation of CWorkspace with an invalid monitor?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
m_iMonitorID = monitorID;
|
|
|
|
m_szName = name;
|
2022-05-31 14:01:00 +02:00
|
|
|
m_bIsSpecialWorkspace = special;
|
2022-09-25 20:07:48 +02:00
|
|
|
|
2022-05-12 11:27:31 +02:00
|
|
|
m_vRenderOffset.m_pWorkspace = this;
|
2024-03-02 01:35:17 +01:00
|
|
|
m_vRenderOffset.create(special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), nullptr,
|
|
|
|
AVARDAMAGE_ENTIRE);
|
2022-05-17 13:24:23 +02:00
|
|
|
m_fAlpha.m_pWorkspace = this;
|
2022-12-16 18:17:31 +01:00
|
|
|
m_fAlpha.create(AVARTYPE_FLOAT, special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"),
|
|
|
|
nullptr, 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-02-27 23:44:42 +01:00
|
|
|
const auto RULEFORTHIS = g_pConfigManager->getWorkspaceRuleFor(this);
|
|
|
|
if (RULEFORTHIS.defaultName.has_value())
|
|
|
|
m_szName = RULEFORTHIS.defaultName.value();
|
|
|
|
|
2023-07-06 15:23:11 +02:00
|
|
|
g_pEventManager->postEvent({"createworkspace", m_szName});
|
2023-02-19 21:54:53 +01:00
|
|
|
EMIT_HOOK_EVENT("createWorkspace", this);
|
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
|
|
|
|
2023-07-06 15:23:11 +02:00
|
|
|
g_pEventManager->postEvent({"destroyworkspace", m_szName});
|
2023-02-19 21:54:53 +01:00
|
|
|
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-02-18 16:00:34 +01:00
|
|
|
const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle;
|
|
|
|
static auto* const PWORKSPACEGAP = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_workspaces");
|
2022-05-16 23:13:32 +02:00
|
|
|
|
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);
|
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0, (left ? PMONITOR->vecSize.y : -PMONITOR->vecSize.y) * (movePerc / 100.f)));
|
|
|
|
m_fAlpha = 1.f;
|
|
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
|
|
} else {
|
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
|
|
m_fAlpha = 0.f;
|
|
|
|
m_vRenderOffset = Vector2D(0, (left ? -PMONITOR->vecSize.y : PMONITOR->vecSize.y) * (movePerc / 100.f));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (in) {
|
|
|
|
m_fAlpha.setValueAndWarp(0.f);
|
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D((left ? PMONITOR->vecSize.x : -PMONITOR->vecSize.x) * (movePerc / 100.f), 0));
|
|
|
|
m_fAlpha = 1.f;
|
|
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
|
|
} else {
|
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
|
|
m_fAlpha = 0.f;
|
|
|
|
m_vRenderOffset = Vector2D((left ? -PMONITOR->vecSize.x : PMONITOR->vecSize.x) * (movePerc / 100.f), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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-02-18 16:00:34 +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) {
|
2023-11-19 13:33:26 +01:00
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0, left ? YDISTANCE : -YDISTANCE));
|
2022-05-31 17:56:33 +02:00
|
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
|
|
} else {
|
2023-11-19 13:33:26 +01:00
|
|
|
m_vRenderOffset = Vector2D(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-02-18 16:00:34 +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) {
|
2023-11-19 13:33:26 +01:00
|
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(left ? XDISTANCE : -XDISTANCE, 0));
|
2022-05-16 23:13:32 +02:00
|
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
|
|
} else {
|
2023-11-19 13:33:26 +01:00
|
|
|
m_vRenderOffset = Vector2D(left ? -XDISTANCE : XDISTANCE, 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
|
|
|
}
|
|
|
|
|
|
|
|
void CWorkspace::moveToMonitor(const int& 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
|
|
|
}
|
|
|
|
|
|
|
|
CWindow* CWorkspace::getLastFocusedWindow() {
|
|
|
|
if (!g_pCompositor->windowValidMapped(m_pLastFocusedWindow) || m_pLastFocusedWindow->m_iWorkspaceID != m_iID)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return m_pLastFocusedWindow;
|
|
|
|
}
|
2023-04-10 21:07:49 +02:00
|
|
|
|
|
|
|
void CWorkspace::rememberPrevWorkspace(const CWorkspace* prev) {
|
|
|
|
if (!prev) {
|
|
|
|
m_sPrevWorkspace.iID = -1;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sPrevWorkspace.iID = prev->m_iID;
|
|
|
|
m_sPrevWorkspace.name = prev->m_szName;
|
|
|
|
}
|
2023-05-01 16:39:08 +02:00
|
|
|
|
|
|
|
std::string CWorkspace::getConfigName() {
|
|
|
|
if (m_bIsSpecialWorkspace) {
|
|
|
|
return "special:" + m_szName;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_iID > 0)
|
|
|
|
return std::to_string(m_iID);
|
|
|
|
|
|
|
|
return "name:" + m_szName;
|
|
|
|
}
|