mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-05 15:25:59 +01:00
37a211a2ae
* add slidefade and slidefadevert animations * fix swiping for slidefadevert * rename minPerc to movePerc for slidefade anim styles * change default slidefade percentage to 100% * remove useless comments * findlastof + 1 * debug logging for slidefade/slidefadevert percentage
202 lines
7.4 KiB
C++
202 lines
7.4 KiB
C++
#include "Workspace.hpp"
|
|
#include "../Compositor.hpp"
|
|
|
|
CWorkspace::CWorkspace(int monitorID, std::string name, bool special) {
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(monitorID);
|
|
|
|
if (!PMONITOR) {
|
|
Debug::log(ERR, "Attempted a creation of CWorkspace with an invalid monitor?");
|
|
return;
|
|
}
|
|
|
|
m_iMonitorID = monitorID;
|
|
m_szName = name;
|
|
m_bIsSpecialWorkspace = special;
|
|
|
|
if (!special) {
|
|
m_pWlrHandle = wlr_ext_workspace_handle_v1_create(PMONITOR->pWLRWorkspaceGroupHandle);
|
|
|
|
// set geometry here cuz we can
|
|
wl_array_init(&m_wlrCoordinateArr);
|
|
*reinterpret_cast<int*>(wl_array_add(&m_wlrCoordinateArr, sizeof(int))) = (int)PMONITOR->vecPosition.x;
|
|
*reinterpret_cast<int*>(wl_array_add(&m_wlrCoordinateArr, sizeof(int))) = (int)PMONITOR->vecPosition.y;
|
|
wlr_ext_workspace_handle_v1_set_coordinates(m_pWlrHandle, &m_wlrCoordinateArr);
|
|
wlr_ext_workspace_handle_v1_set_hidden(m_pWlrHandle, false);
|
|
wlr_ext_workspace_handle_v1_set_urgent(m_pWlrHandle, false);
|
|
}
|
|
|
|
m_vRenderOffset.m_pWorkspace = this;
|
|
m_vRenderOffset.create(AVARTYPE_VECTOR, special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"),
|
|
nullptr, AVARDAMAGE_ENTIRE);
|
|
m_fAlpha.m_pWorkspace = this;
|
|
m_fAlpha.create(AVARTYPE_FLOAT, special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"),
|
|
nullptr, AVARDAMAGE_ENTIRE);
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
|
|
m_vRenderOffset.registerVar();
|
|
m_fAlpha.registerVar();
|
|
|
|
g_pEventManager->postEvent({"createworkspace", m_szName});
|
|
EMIT_HOOK_EVENT("createWorkspace", this);
|
|
}
|
|
|
|
CWorkspace::~CWorkspace() {
|
|
m_vRenderOffset.unregister();
|
|
|
|
Debug::log(LOG, "Destroying workspace ID %d", m_iID);
|
|
|
|
if (m_pWlrHandle) {
|
|
wlr_ext_workspace_handle_v1_set_active(m_pWlrHandle, false);
|
|
wlr_ext_workspace_handle_v1_destroy(m_pWlrHandle);
|
|
m_pWlrHandle = nullptr;
|
|
}
|
|
|
|
g_pEventManager->postEvent({"destroyworkspace", m_szName});
|
|
EMIT_HOOK_EVENT("destroyWorkspace", this);
|
|
}
|
|
|
|
void CWorkspace::startAnim(bool in, bool left, bool instant) {
|
|
const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle;
|
|
|
|
if (ANIMSTYLE.find("slidefade") == 0) {
|
|
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));
|
|
} catch (std::exception& e) {
|
|
Debug::log(ERR, "Error in startAnim: invalid percentage");
|
|
}
|
|
}
|
|
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0, 0));
|
|
|
|
if (ANIMSTYLE.find("slidefadevert") == 0) {
|
|
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") {
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0, 0)); // fix a bug, if switching from slide -> fade.
|
|
|
|
if (in) {
|
|
m_fAlpha.setValueAndWarp(0.f);
|
|
m_fAlpha = 1.f;
|
|
} else {
|
|
m_fAlpha.setValueAndWarp(1.f);
|
|
m_fAlpha = 0.f;
|
|
}
|
|
} else if (ANIMSTYLE == "slidevert") {
|
|
// fallback is slide
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
|
|
|
|
m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide.
|
|
|
|
if (in) {
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(0, left ? PMONITOR->vecSize.y : -PMONITOR->vecSize.y));
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
} else {
|
|
m_vRenderOffset = Vector2D(0, left ? -PMONITOR->vecSize.y : PMONITOR->vecSize.y);
|
|
}
|
|
} else {
|
|
// fallback is slide
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID);
|
|
|
|
m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide.
|
|
|
|
if (in) {
|
|
m_vRenderOffset.setValueAndWarp(Vector2D(left ? PMONITOR->vecSize.x : -PMONITOR->vecSize.x, 0));
|
|
m_vRenderOffset = Vector2D(0, 0);
|
|
} else {
|
|
m_vRenderOffset = Vector2D(left ? -PMONITOR->vecSize.x : PMONITOR->vecSize.x, 0);
|
|
}
|
|
}
|
|
|
|
if (instant) {
|
|
m_vRenderOffset.warp();
|
|
m_fAlpha.warp();
|
|
}
|
|
}
|
|
|
|
void CWorkspace::setActive(bool on) {
|
|
if (m_pWlrHandle) {
|
|
wlr_ext_workspace_handle_v1_set_active(m_pWlrHandle, on);
|
|
}
|
|
}
|
|
|
|
void CWorkspace::moveToMonitor(const int& id) {
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromID(id);
|
|
|
|
if (!PMONITOR || m_bIsSpecialWorkspace)
|
|
return;
|
|
|
|
wlr_ext_workspace_handle_v1_set_active(m_pWlrHandle, false);
|
|
wlr_ext_workspace_handle_v1_destroy(m_pWlrHandle);
|
|
|
|
m_pWlrHandle = wlr_ext_workspace_handle_v1_create(PMONITOR->pWLRWorkspaceGroupHandle);
|
|
|
|
// set geometry here cuz we can
|
|
wl_array_init(&m_wlrCoordinateArr);
|
|
*reinterpret_cast<int*>(wl_array_add(&m_wlrCoordinateArr, sizeof(int))) = (int)PMONITOR->vecPosition.x;
|
|
*reinterpret_cast<int*>(wl_array_add(&m_wlrCoordinateArr, sizeof(int))) = (int)PMONITOR->vecPosition.y;
|
|
wlr_ext_workspace_handle_v1_set_coordinates(m_pWlrHandle, &m_wlrCoordinateArr);
|
|
wlr_ext_workspace_handle_v1_set_hidden(m_pWlrHandle, false);
|
|
wlr_ext_workspace_handle_v1_set_urgent(m_pWlrHandle, false);
|
|
|
|
wlr_ext_workspace_handle_v1_set_name(m_pWlrHandle, m_szName.c_str());
|
|
}
|
|
|
|
CWindow* CWorkspace::getLastFocusedWindow() {
|
|
if (!g_pCompositor->windowValidMapped(m_pLastFocusedWindow) || m_pLastFocusedWindow->m_iWorkspaceID != m_iID)
|
|
return nullptr;
|
|
|
|
return m_pLastFocusedWindow;
|
|
}
|
|
|
|
void CWorkspace::rememberPrevWorkspace(const CWorkspace* prev) {
|
|
if (!prev) {
|
|
m_sPrevWorkspace.iID = -1;
|
|
m_sPrevWorkspace.name = "";
|
|
return;
|
|
}
|
|
|
|
if (prev->m_sPrevWorkspace.iID == m_sPrevWorkspace.iID) {
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|