core: add ability to select previous workspace per monitor (#6598)

Co-authored-by: Крылов Александр <aleksandr.krylov@hyperus.team>
This commit is contained in:
Alexander 2024-06-23 00:52:42 +03:00 committed by GitHub
parent 0b924f541c
commit 7f09646ab8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 154 additions and 146 deletions

View file

@ -1648,8 +1648,7 @@ PHLWORKSPACE CCompositor::getWorkspaceByString(const std::string& str) {
} }
try { try {
std::string name = ""; return getWorkspaceByID(getWorkspaceIDNameFromString(str).id);
return getWorkspaceByID(getWorkspaceIDFromString(str, name));
} catch (std::exception& e) { Debug::log(ERR, "Error in getWorkspaceByString, invalid id"); } } catch (std::exception& e) { Debug::log(ERR, "Error in getWorkspaceByString, invalid id"); }
return nullptr; return nullptr;

View file

@ -1815,14 +1815,13 @@ std::optional<std::string> CConfigManager::handleMonitor(const std::string& comm
newrule.vrr = std::stoi(ARGS[argno + 1]); newrule.vrr = std::stoi(ARGS[argno + 1]);
argno++; argno++;
} else if (ARGS[argno] == "workspace") { } else if (ARGS[argno] == "workspace") {
std::string name = ""; const auto& [id, name] = getWorkspaceIDNameFromString(ARGS[argno + 1]);
int wsId = getWorkspaceIDFromString(ARGS[argno + 1], name);
SWorkspaceRule wsRule; SWorkspaceRule wsRule;
wsRule.monitor = newrule.name; wsRule.monitor = newrule.name;
wsRule.workspaceString = ARGS[argno + 1]; wsRule.workspaceString = ARGS[argno + 1];
wsRule.workspaceId = id;
wsRule.workspaceName = name; wsRule.workspaceName = name;
wsRule.workspaceId = wsId;
m_dWorkspaceRules.emplace_back(wsRule); m_dWorkspaceRules.emplace_back(wsRule);
argno++; argno++;
@ -2370,11 +2369,11 @@ std::optional<std::string> CConfigManager::handleBlurLS(const std::string& comma
std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::string& command, const std::string& value) { std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::string& command, const std::string& value) {
// This can either be the monitor or the workspace identifier // This can either be the monitor or the workspace identifier
const auto FIRST_DELIM = value.find_first_of(','); const auto FIRST_DELIM = value.find_first_of(',');
std::string name = ""; auto first_ident = trim(value.substr(0, FIRST_DELIM));
auto first_ident = trim(value.substr(0, FIRST_DELIM));
int id = getWorkspaceIDFromString(first_ident, name); const auto& [id, name] = getWorkspaceIDNameFromString(first_ident);
auto rules = value.substr(FIRST_DELIM + 1); auto rules = value.substr(FIRST_DELIM + 1);
SWorkspaceRule wsRule; SWorkspaceRule wsRule;

View file

@ -57,6 +57,13 @@ void CWorkspace::init(PHLWORKSPACE self) {
EMIT_HOOK_EVENT("createWorkspace", this); EMIT_HOOK_EVENT("createWorkspace", this);
} }
SWorkspaceIDName CWorkspace::getPrevWorkspaceIDName(bool perMonitor) const {
if (perMonitor)
return m_sPrevWorkspacePerMonitor;
return m_sPrevWorkspace;
}
CWorkspace::~CWorkspace() { CWorkspace::~CWorkspace() {
m_vRenderOffset.unregister(); m_vRenderOffset.unregister();
@ -196,7 +203,7 @@ PHLWINDOW CWorkspace::getLastFocusedWindow() {
void CWorkspace::rememberPrevWorkspace(const PHLWORKSPACE& prev) { void CWorkspace::rememberPrevWorkspace(const PHLWORKSPACE& prev) {
if (!prev) { if (!prev) {
m_sPrevWorkspace.iID = -1; m_sPrevWorkspace.id = -1;
m_sPrevWorkspace.name = ""; m_sPrevWorkspace.name = "";
return; return;
} }
@ -206,8 +213,13 @@ void CWorkspace::rememberPrevWorkspace(const PHLWORKSPACE& prev) {
return; return;
} }
m_sPrevWorkspace.iID = prev->m_iID; m_sPrevWorkspace.id = prev->m_iID;
m_sPrevWorkspace.name = prev->m_szName; m_sPrevWorkspace.name = prev->m_szName;
if (prev->m_iMonitorID == m_iMonitorID) {
m_sPrevWorkspacePerMonitor.id = prev->m_iID;
m_sPrevWorkspacePerMonitor.name = prev->m_szName;
}
} }
std::string CWorkspace::getConfigName() { std::string CWorkspace::getConfigName() {
@ -228,9 +240,7 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
return true; return true;
if (isNumber(selector)) { if (isNumber(selector)) {
const auto& [wsid, wsname] = getWorkspaceIDNameFromString(selector);
std::string wsname = "";
int wsid = getWorkspaceIDFromString(selector, wsname);
if (wsid == WORKSPACE_INVALID) if (wsid == WORKSPACE_INVALID)
return false; return false;

View file

@ -4,6 +4,7 @@
#include <string> #include <string>
#include "../defines.hpp" #include "../defines.hpp"
#include "DesktopTypes.hpp" #include "DesktopTypes.hpp"
#include "helpers/MiscFunctions.hpp"
enum eFullscreenMode : int8_t { enum eFullscreenMode : int8_t {
FULLSCREEN_INVALID = -1, FULLSCREEN_INVALID = -1,
@ -25,17 +26,14 @@ class CWorkspace {
int m_iID = -1; int m_iID = -1;
std::string m_szName = ""; std::string m_szName = "";
uint64_t m_iMonitorID = -1; uint64_t m_iMonitorID = -1;
// Previous workspace ID is stored during a workspace change, allowing travel // Previous workspace ID and name is stored during a workspace change, allowing travel
// to the previous workspace. // to the previous workspace.
struct SPrevWorkspaceData { SWorkspaceIDName m_sPrevWorkspace, m_sPrevWorkspacePerMonitor;
int iID = -1;
std::string name = "";
} m_sPrevWorkspace;
bool m_bHasFullscreenWindow = false; bool m_bHasFullscreenWindow = false;
eFullscreenMode m_efFullscreenMode = FULLSCREEN_FULL; eFullscreenMode m_efFullscreenMode = FULLSCREEN_FULL;
wl_array m_wlrCoordinateArr; wl_array m_wlrCoordinateArr;
// for animations // for animations
CAnimatedVariable<Vector2D> m_vRenderOffset; CAnimatedVariable<Vector2D> m_vRenderOffset;
@ -63,21 +61,23 @@ class CWorkspace {
bool m_bPersistent = false; bool m_bPersistent = false;
// Inert: destroyed and invalid. If this is true, release the ptr you have. // Inert: destroyed and invalid. If this is true, release the ptr you have.
bool inert(); bool inert();
void startAnim(bool in, bool left, bool instant = false); void startAnim(bool in, bool left, bool instant = false);
void setActive(bool on); void setActive(bool on);
void moveToMonitor(const int&); void moveToMonitor(const int&);
PHLWINDOW getLastFocusedWindow(); PHLWINDOW getLastFocusedWindow();
void rememberPrevWorkspace(const PHLWORKSPACE& prevWorkspace); void rememberPrevWorkspace(const PHLWORKSPACE& prevWorkspace);
std::string getConfigName(); std::string getConfigName();
bool matchesStaticSelector(const std::string& selector); bool matchesStaticSelector(const std::string& selector);
void markInert(); void markInert();
SWorkspaceIDName getPrevWorkspaceIDName(bool perMonitor) const;
private: private:
void init(PHLWORKSPACE self); void init(PHLWORKSPACE self);

View file

@ -293,8 +293,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
if (WORKSPACEARGS[WORKSPACEARGS.size() - 1].starts_with("silent")) if (WORKSPACEARGS[WORKSPACEARGS.size() - 1].starts_with("silent"))
workspaceSilent = true; workspaceSilent = true;
std::string requestedWorkspaceName; const auto& [REQUESTEDWORKSPACEID, requestedWorkspaceName] = getWorkspaceIDNameFromString(WORKSPACEARGS.join(" ", 0, workspaceSilent ? WORKSPACEARGS.size() - 1 : 0));
const int REQUESTEDWORKSPACEID = getWorkspaceIDFromString(WORKSPACEARGS.join(" ", 0, workspaceSilent ? WORKSPACEARGS.size() - 1 : 0), requestedWorkspaceName);
if (REQUESTEDWORKSPACEID != WORKSPACE_INVALID) { if (REQUESTEDWORKSPACEID != WORKSPACE_INVALID) {
auto pWorkspace = g_pCompositor->getWorkspaceByID(REQUESTEDWORKSPACEID); auto pWorkspace = g_pCompositor->getWorkspaceByID(REQUESTEDWORKSPACEID);

View file

@ -214,37 +214,36 @@ bool isDirection(const char& arg) {
return arg == 'l' || arg == 'r' || arg == 'u' || arg == 'd' || arg == 't' || arg == 'b'; return arg == 'l' || arg == 'r' || arg == 'u' || arg == 'd' || arg == 't' || arg == 'b';
} }
int getWorkspaceIDFromString(const std::string& in, std::string& outName) { SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
int result = WORKSPACE_INVALID; SWorkspaceIDName result = {WORKSPACE_INVALID, ""};
if (in.starts_with("special")) { if (in.starts_with("special")) {
outName = "special:special"; result.name = "special:special";
if (in.length() > 8) { if (in.length() > 8) {
const auto NAME = in.substr(8); const auto NAME = in.substr(8);
const auto WS = g_pCompositor->getWorkspaceByName("special:" + NAME);
const auto WS = g_pCompositor->getWorkspaceByName("special:" + NAME); return {WS ? WS->m_iID : g_pCompositor->getNewSpecialID(), "special:" + NAME};
outName = "special:" + NAME;
return WS ? WS->m_iID : g_pCompositor->getNewSpecialID();
} }
return SPECIAL_WORKSPACE_START; result.id = SPECIAL_WORKSPACE_START;
return result;
} else if (in.starts_with("name:")) { } else if (in.starts_with("name:")) {
const auto WORKSPACENAME = in.substr(in.find_first_of(':') + 1); const auto WORKSPACENAME = in.substr(in.find_first_of(':') + 1);
const auto WORKSPACE = g_pCompositor->getWorkspaceByName(WORKSPACENAME); const auto WORKSPACE = g_pCompositor->getWorkspaceByName(WORKSPACENAME);
if (!WORKSPACE) { if (!WORKSPACE) {
result = g_pCompositor->getNextAvailableNamedWorkspace(); result.id = g_pCompositor->getNextAvailableNamedWorkspace();
} else { } else {
result = WORKSPACE->m_iID; result.id = WORKSPACE->m_iID;
} }
outName = WORKSPACENAME; result.name = WORKSPACENAME;
} else if (in.starts_with("empty")) { } else if (in.starts_with("empty")) {
const bool same_mon = in.substr(5).contains("m"); const bool same_mon = in.substr(5).contains("m");
const bool next = in.substr(5).contains("n"); const bool next = in.substr(5).contains("n");
if ((same_mon || next) && !g_pCompositor->m_pLastMonitor) { if ((same_mon || next) && !g_pCompositor->m_pLastMonitor) {
Debug::log(ERR, "Empty monitor workspace on monitor null!"); Debug::log(ERR, "Empty monitor workspace on monitor null!");
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
} }
std::set<int> invalidWSes; std::set<int> invalidWSes;
@ -259,41 +258,42 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
int id = next ? g_pCompositor->m_pLastMonitor->activeWorkspaceID() : 0; int id = next ? g_pCompositor->m_pLastMonitor->activeWorkspaceID() : 0;
while (++id < INT_MAX) { while (++id < INT_MAX) {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(id); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(id);
if (!invalidWSes.contains(id) && (!PWORKSPACE || g_pCompositor->getWindowsOnWorkspace(id) == 0)) if (!invalidWSes.contains(id) && (!PWORKSPACE || g_pCompositor->getWindowsOnWorkspace(id) == 0)) {
return id; result.id = id;
return result;
}
} }
} else if (in.starts_with("prev")) { } else if (in.starts_with("prev")) {
if (!g_pCompositor->m_pLastMonitor) if (!g_pCompositor->m_pLastMonitor)
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace;
if (!valid(PWORKSPACE)) if (!valid(PWORKSPACE))
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_sPrevWorkspace.iID); const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_sPrevWorkspace.id);
if (!PLASTWORKSPACE) if (!PLASTWORKSPACE)
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
outName = PLASTWORKSPACE->m_szName; return {PLASTWORKSPACE->m_iID, PLASTWORKSPACE->m_szName};
return PLASTWORKSPACE->m_iID;
} else { } else {
if (in[0] == 'r' && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) { if (in[0] == 'r' && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) {
bool absolute = in[1] == '~'; bool absolute = in[1] == '~';
if (!g_pCompositor->m_pLastMonitor) { if (!g_pCompositor->m_pLastMonitor) {
Debug::log(ERR, "Relative monitor workspace on monitor null!"); Debug::log(ERR, "Relative monitor workspace on monitor null!");
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
} }
const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in.substr(absolute ? 2 : 1), 0); const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in.substr(absolute ? 2 : 1), 0);
if (!PLUSMINUSRESULT.has_value()) if (!PLUSMINUSRESULT.has_value())
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
result = (int)PLUSMINUSRESULT.value(); result.id = (int)PLUSMINUSRESULT.value();
int remains = (int)result; int remains = (int)result.id;
std::set<int> invalidWSes; std::set<int> invalidWSes;
@ -330,13 +330,13 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
// traverse valid workspaces until we reach the remains // traverse valid workspaces until we reach the remains
if ((size_t)remains < namedWSes.size()) { if ((size_t)remains < namedWSes.size()) {
result = namedWSes[remains]; result.id = namedWSes[remains];
} else { } else {
remains -= namedWSes.size(); remains -= namedWSes.size();
result = 0; result.id = 0;
while (remains >= 0) { while (remains >= 0) {
result++; result.id++;
if (!invalidWSes.contains(result)) { if (!invalidWSes.contains(result.id)) {
remains--; remains--;
} }
} }
@ -430,14 +430,14 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
finalWSID = curID; finalWSID = curID;
} }
} }
result = finalWSID; result.id = finalWSID;
} }
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(result); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(result.id);
if (PWORKSPACE) if (PWORKSPACE)
outName = g_pCompositor->getWorkspaceByID(result)->m_szName; result.name = g_pCompositor->getWorkspaceByID(result.id)->m_szName;
else else
outName = std::to_string(result); result.name = std::to_string(result.id);
} else if ((in[0] == 'm' || in[0] == 'e') && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) { } else if ((in[0] == 'm' || in[0] == 'e') && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) {
bool onAllMonitors = in[0] == 'e'; bool onAllMonitors = in[0] == 'e';
@ -445,19 +445,19 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
if (!g_pCompositor->m_pLastMonitor) { if (!g_pCompositor->m_pLastMonitor) {
Debug::log(ERR, "Relative monitor workspace on monitor null!"); Debug::log(ERR, "Relative monitor workspace on monitor null!");
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
} }
// monitor relative // monitor relative
const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in.substr(absolute ? 2 : 1), 0); const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in.substr(absolute ? 2 : 1), 0);
if (!PLUSMINUSRESULT.has_value()) if (!PLUSMINUSRESULT.has_value())
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
result = (int)PLUSMINUSRESULT.value(); result.id = (int)PLUSMINUSRESULT.value();
// result now has +/- what we should move on mon // result now has +/- what we should move on mon
int remains = (int)result; int remains = (int)result.id;
std::vector<int> validWSes; std::vector<int> validWSes;
for (auto& ws : g_pCompositor->m_vWorkspaces) { for (auto& ws : g_pCompositor->m_vWorkspaces) {
@ -505,30 +505,30 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
} }
} }
result = validWSes[currentItem]; result.id = validWSes[currentItem];
outName = g_pCompositor->getWorkspaceByID(validWSes[currentItem])->m_szName; result.name = g_pCompositor->getWorkspaceByID(validWSes[currentItem])->m_szName;
} else { } else {
if (in[0] == '+' || in[0] == '-') { if (in[0] == '+' || in[0] == '-') {
if (g_pCompositor->m_pLastMonitor) { if (g_pCompositor->m_pLastMonitor) {
const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspaceID()); const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspaceID());
if (!PLUSMINUSRESULT.has_value()) if (!PLUSMINUSRESULT.has_value())
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
result = std::max((int)PLUSMINUSRESULT.value(), 1); result.id = std::max((int)PLUSMINUSRESULT.value(), 1);
} else { } else {
Debug::log(ERR, "Relative workspace on no mon!"); Debug::log(ERR, "Relative workspace on no mon!");
return WORKSPACE_INVALID; return {WORKSPACE_INVALID};
} }
} else if (isNumber(in)) } else if (isNumber(in))
result = std::max(std::stoi(in), 1); result.id = std::max(std::stoi(in), 1);
else { else {
// maybe name // maybe name
const auto PWORKSPACE = g_pCompositor->getWorkspaceByName(in); const auto PWORKSPACE = g_pCompositor->getWorkspaceByName(in);
if (PWORKSPACE) if (PWORKSPACE)
result = PWORKSPACE->m_iID; result.id = PWORKSPACE->m_iID;
} }
outName = std::to_string(result); result.name = std::to_string(result.id);
} }
} }

View file

@ -13,13 +13,18 @@ struct SCallstackFrameInfo {
std::string desc; std::string desc;
}; };
struct SWorkspaceIDName {
int id = -1;
std::string name;
};
std::string absolutePath(const std::string&, const std::string&); std::string absolutePath(const std::string&, const std::string&);
void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString); void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
void removeWLSignal(wl_listener*); void removeWLSignal(wl_listener*);
std::string escapeJSONStrings(const std::string& str); std::string escapeJSONStrings(const std::string& str);
bool isDirection(const std::string&); bool isDirection(const std::string&);
bool isDirection(const char&); bool isDirection(const char&);
int getWorkspaceIDFromString(const std::string&, std::string&); SWorkspaceIDName getWorkspaceIDNameFromString(const std::string&);
std::optional<std::string> cleanCmdForWorkspace(const std::string&, std::string); std::optional<std::string> cleanCmdForWorkspace(const std::string&, std::string);
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2); float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
void logSystemInfo(); void logSystemInfo();
@ -42,4 +47,4 @@ template <typename... Args>
// because any suck format specifier will cause a compilation error // because any suck format specifier will cause a compilation error
// this is actually what std::format in stdlib does // this is actually what std::format in stdlib does
return std::vformat(fmt.get(), std::make_format_args(args...)); return std::vformat(fmt.get(), std::make_format_args(args...));
} }

View file

@ -415,20 +415,25 @@ int CMonitor::findAvailableDefaultWS() {
void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) { void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) {
// Workspace // Workspace
std::string newDefaultWorkspaceName = ""; std::string newDefaultWorkspaceName = "";
int64_t WORKSPACEID = g_pConfigManager->getDefaultWorkspaceFor(szName).empty() ? int64_t wsID = WORKSPACE_INVALID;
findAvailableDefaultWS() : if (g_pConfigManager->getDefaultWorkspaceFor(szName).empty())
getWorkspaceIDFromString(g_pConfigManager->getDefaultWorkspaceFor(szName), newDefaultWorkspaceName); wsID = findAvailableDefaultWS();
else {
const auto ws = getWorkspaceIDNameFromString(g_pConfigManager->getDefaultWorkspaceFor(szName));
wsID = ws.id;
newDefaultWorkspaceName = ws.name;
}
if (WORKSPACEID == WORKSPACE_INVALID || (WORKSPACEID >= SPECIAL_WORKSPACE_START && WORKSPACEID <= -2)) { if (wsID == WORKSPACE_INVALID || (wsID >= SPECIAL_WORKSPACE_START && wsID <= -2)) {
WORKSPACEID = g_pCompositor->m_vWorkspaces.size() + 1; wsID = g_pCompositor->m_vWorkspaces.size() + 1;
newDefaultWorkspaceName = std::to_string(WORKSPACEID); newDefaultWorkspaceName = std::to_string(wsID);
Debug::log(LOG, "Invalid workspace= directive name in monitor parsing, workspace name \"{}\" is invalid.", g_pConfigManager->getDefaultWorkspaceFor(szName)); Debug::log(LOG, "Invalid workspace= directive name in monitor parsing, workspace name \"{}\" is invalid.", g_pConfigManager->getDefaultWorkspaceFor(szName));
} }
auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(WORKSPACEID); auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(wsID);
Debug::log(LOG, "New monitor: WORKSPACEID {}, exists: {}", WORKSPACEID, (int)(PNEWWORKSPACE != nullptr)); Debug::log(LOG, "New monitor: WORKSPACEID {}, exists: {}", wsID, (int)(PNEWWORKSPACE != nullptr));
if (PNEWWORKSPACE) { if (PNEWWORKSPACE) {
// workspace exists, move it to the newly connected monitor // workspace exists, move it to the newly connected monitor
@ -438,9 +443,9 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) {
PNEWWORKSPACE->startAnim(true, true, true); PNEWWORKSPACE->startAnim(true, true, true);
} else { } else {
if (newDefaultWorkspaceName == "") if (newDefaultWorkspaceName == "")
newDefaultWorkspaceName = std::to_string(WORKSPACEID); newDefaultWorkspaceName = std::to_string(wsID);
PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(CWorkspace::create(WORKSPACEID, ID, newDefaultWorkspaceName)); PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(CWorkspace::create(wsID, ID, newDefaultWorkspaceName));
} }
activeWorkspace = PNEWWORKSPACE; activeWorkspace = PNEWWORKSPACE;

View file

@ -24,7 +24,8 @@
#define STRVAL_EMPTY "[[EMPTY]]" #define STRVAL_EMPTY "[[EMPTY]]"
#define WORKSPACE_INVALID -1L #define WORKSPACE_INVALID -1L
#define WORKSPACE_NOT_CHANGED -101
#define LISTENER(name) \ #define LISTENER(name) \
void listener_##name(wl_listener*, void*); \ void listener_##name(wl_listener*, void*); \

View file

@ -1034,10 +1034,26 @@ void CKeybindManager::toggleActivePseudo(std::string args) {
g_pLayoutManager->getCurrentLayout()->recalculateWindow(PWINDOW); g_pLayoutManager->getCurrentLayout()->recalculateWindow(PWINDOW);
} }
void CKeybindManager::changeworkspace(std::string args) { SWorkspaceIDName getWorkspaceToChangeFromArgs(std::string args, PHLWORKSPACE PCURRENTWORKSPACE) {
int workspaceToChangeTo = 0; if (!args.starts_with("previous")) {
std::string workspaceName = ""; return getWorkspaceIDNameFromString(args);
}
const SWorkspaceIDName PPREVWS = PCURRENTWORKSPACE->getPrevWorkspaceIDName(args.contains("_per_monitor"));
// Do nothing if there's no previous workspace, otherwise switch to it.
if (PPREVWS.id == -1) {
Debug::log(LOG, "No previous workspace to change to");
return {WORKSPACE_NOT_CHANGED, ""};
}
const auto ID = PCURRENTWORKSPACE->m_iID;
if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(PPREVWS.id); PWORKSPACETOCHANGETO)
return {ID, PWORKSPACETOCHANGETO->m_szName};
return {ID, PPREVWS.name.empty() ? std::to_string(PPREVWS.id) : PPREVWS.name};
}
void CKeybindManager::changeworkspace(std::string args) {
// Workspace_back_and_forth being enabled means that an attempt to switch to // Workspace_back_and_forth being enabled means that an attempt to switch to
// the current workspace will instead switch to the previous. // the current workspace will instead switch to the previous.
static auto PBACKANDFORTH = CConfigValue<Hyprlang::INT>("binds:workspace_back_and_forth"); static auto PBACKANDFORTH = CConfigValue<Hyprlang::INT>("binds:workspace_back_and_forth");
@ -1050,43 +1066,31 @@ void CKeybindManager::changeworkspace(std::string args) {
return; return;
const auto PCURRENTWORKSPACE = PMONITOR->activeWorkspace; const auto PCURRENTWORKSPACE = PMONITOR->activeWorkspace;
const bool EXPLICITPREVIOUS = args.starts_with("previous"); const bool EXPLICITPREVIOUS = args.contains("previous");
if (args.starts_with("previous")) {
// Do nothing if there's no previous workspace, otherwise switch to it.
if (PCURRENTWORKSPACE->m_sPrevWorkspace.iID == -1) {
Debug::log(LOG, "No previous workspace to change to");
return;
} else {
workspaceToChangeTo = PCURRENTWORKSPACE->m_iID;
if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(PCURRENTWORKSPACE->m_sPrevWorkspace.iID); PWORKSPACETOCHANGETO)
workspaceName = PWORKSPACETOCHANGETO->m_szName;
else
workspaceName =
PCURRENTWORKSPACE->m_sPrevWorkspace.name.empty() ? std::to_string(PCURRENTWORKSPACE->m_sPrevWorkspace.iID) : PCURRENTWORKSPACE->m_sPrevWorkspace.name;
}
} else {
workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName);
}
const auto& [workspaceToChangeTo, workspaceName] = getWorkspaceToChangeFromArgs(args, PCURRENTWORKSPACE);
if (workspaceToChangeTo == WORKSPACE_INVALID) { if (workspaceToChangeTo == WORKSPACE_INVALID) {
Debug::log(ERR, "Error in changeworkspace, invalid value"); Debug::log(ERR, "Error in changeworkspace, invalid value");
return; return;
} }
const bool BISWORKSPACECURRENT = workspaceToChangeTo == PCURRENTWORKSPACE->m_iID; if (workspaceToChangeTo == WORKSPACE_NOT_CHANGED) {
return;
}
if (BISWORKSPACECURRENT && (!(*PBACKANDFORTH || EXPLICITPREVIOUS) || PCURRENTWORKSPACE->m_sPrevWorkspace.iID == -1)) const auto PREVWS = PCURRENTWORKSPACE->getPrevWorkspaceIDName(args.contains("_per_monitor"));
const bool BISWORKSPACECURRENT = workspaceToChangeTo == PCURRENTWORKSPACE->m_iID;
if (BISWORKSPACECURRENT && (!(*PBACKANDFORTH || EXPLICITPREVIOUS) || PREVWS.id == -1))
return; return;
g_pInputManager->unconstrainMouse(); g_pInputManager->unconstrainMouse();
g_pInputManager->m_bEmptyFocusCursorSet = false; g_pInputManager->m_bEmptyFocusCursorSet = false;
auto pWorkspaceToChangeTo = g_pCompositor->getWorkspaceByID(BISWORKSPACECURRENT ? PCURRENTWORKSPACE->m_sPrevWorkspace.iID : workspaceToChangeTo); auto pWorkspaceToChangeTo = g_pCompositor->getWorkspaceByID(BISWORKSPACECURRENT ? PREVWS.id : workspaceToChangeTo);
if (!pWorkspaceToChangeTo) if (!pWorkspaceToChangeTo)
pWorkspaceToChangeTo = g_pCompositor->createNewWorkspace(BISWORKSPACECURRENT ? PCURRENTWORKSPACE->m_sPrevWorkspace.iID : workspaceToChangeTo, PMONITOR->ID, pWorkspaceToChangeTo =
BISWORKSPACECURRENT ? PCURRENTWORKSPACE->m_sPrevWorkspace.name : workspaceName); g_pCompositor->createNewWorkspace(BISWORKSPACECURRENT ? PREVWS.id : workspaceToChangeTo, PMONITOR->ID, BISWORKSPACECURRENT ? PREVWS.name : workspaceName);
if (!BISWORKSPACECURRENT && pWorkspaceToChangeTo->m_bIsSpecialWorkspace) { if (!BISWORKSPACECURRENT && pWorkspaceToChangeTo->m_bIsSpecialWorkspace) {
PMONITOR->setSpecialWorkspace(pWorkspaceToChangeTo); PMONITOR->setSpecialWorkspace(pWorkspaceToChangeTo);
@ -1169,10 +1173,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
if (!PWINDOW) if (!PWINDOW)
return; return;
// hack const auto& [WORKSPACEID, workspaceName] = getWorkspaceIDNameFromString(args);
std::string workspaceName;
const auto WORKSPACEID = getWorkspaceIDFromString(args, workspaceName);
if (WORKSPACEID == WORKSPACE_INVALID) { if (WORKSPACEID == WORKSPACE_INVALID) {
Debug::log(LOG, "Invalid workspace in moveActiveToWorkspace"); Debug::log(LOG, "Invalid workspace in moveActiveToWorkspace");
return; return;
@ -1233,10 +1234,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
if (!PWINDOW) if (!PWINDOW)
return; return;
std::string workspaceName = ""; const auto& [WORKSPACEID, workspaceName] = getWorkspaceIDNameFromString(args);
const int WORKSPACEID = getWorkspaceIDFromString(args, workspaceName);
if (WORKSPACEID == WORKSPACE_INVALID) { if (WORKSPACEID == WORKSPACE_INVALID) {
Debug::log(ERR, "Error in moveActiveToWorkspaceSilent, invalid value"); Debug::log(ERR, "Error in moveActiveToWorkspaceSilent, invalid value");
return; return;
@ -1702,8 +1700,7 @@ void CKeybindManager::moveWorkspaceToMonitor(std::string args) {
return; return;
} }
std::string workspaceName; const int WORKSPACEID = getWorkspaceIDNameFromString(workspace).id;
const int WORKSPACEID = getWorkspaceIDFromString(workspace, workspaceName);
if (WORKSPACEID == WORKSPACE_INVALID) { if (WORKSPACEID == WORKSPACE_INVALID) {
Debug::log(ERR, "moveWorkspaceToMonitor invalid workspace!"); Debug::log(ERR, "moveWorkspaceToMonitor invalid workspace!");
@ -1721,9 +1718,7 @@ void CKeybindManager::moveWorkspaceToMonitor(std::string args) {
} }
void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) {
std::string workspaceName; int workspaceID = getWorkspaceIDNameFromString(args).id;
int workspaceID = getWorkspaceIDFromString(args, workspaceName);
if (workspaceID == WORKSPACE_INVALID) { if (workspaceID == WORKSPACE_INVALID) {
Debug::log(ERR, "focusWorkspaceOnCurrentMonitor invalid workspace!"); Debug::log(ERR, "focusWorkspaceOnCurrentMonitor invalid workspace!");
return; return;
@ -1746,14 +1741,13 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) {
} }
static auto PBACKANDFORTH = CConfigValue<Hyprlang::INT>("binds:workspace_back_and_forth"); static auto PBACKANDFORTH = CConfigValue<Hyprlang::INT>("binds:workspace_back_and_forth");
const auto PREVWS = pWorkspace->getPrevWorkspaceIDName(false);
if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspaceID() == workspaceID && pWorkspace->m_sPrevWorkspace.iID != -1) { if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspaceID() == workspaceID && PREVWS.id != -1) {
const int PREVWORKSPACEID = pWorkspace->m_sPrevWorkspace.iID;
const auto PREVWORKSPACENAME = pWorkspace->m_sPrevWorkspace.name;
// Workspace to focus is previous workspace // Workspace to focus is previous workspace
pWorkspace = g_pCompositor->getWorkspaceByID(PREVWORKSPACEID); pWorkspace = g_pCompositor->getWorkspaceByID(PREVWS.id);
if (!pWorkspace) if (!pWorkspace)
pWorkspace = g_pCompositor->createNewWorkspace(PREVWORKSPACEID, PCURRMONITOR->ID, PREVWORKSPACENAME); pWorkspace = g_pCompositor->createNewWorkspace(PREVWS.id, PCURRMONITOR->ID, PREVWS.name);
workspaceID = pWorkspace->m_iID; workspaceID = pWorkspace->m_iID;
} }
@ -1776,9 +1770,7 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) {
} }
void CKeybindManager::toggleSpecialWorkspace(std::string args) { void CKeybindManager::toggleSpecialWorkspace(std::string args) {
std::string workspaceName = ""; const auto& [workspaceID, workspaceName] = getWorkspaceIDNameFromString("special:" + args);
int workspaceID = getWorkspaceIDFromString("special:" + args, workspaceName);
if (workspaceID == WORKSPACE_INVALID || !g_pCompositor->isWorkspaceSpecial(workspaceID)) { if (workspaceID == WORKSPACE_INVALID || !g_pCompositor->isWorkspaceSpecial(workspaceID)) {
Debug::log(ERR, "Invalid workspace passed to special"); Debug::log(ERR, "Invalid workspace passed to special");
return; return;

View file

@ -63,10 +63,9 @@ void CInputManager::endWorkspaceSwipe() {
m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
// commit // commit
std::string wsname = ""; auto workspaceIDLeft = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r-1" : "m-1")).id;
auto workspaceIDLeft = getWorkspaceIDFromString((*PSWIPEUSER ? "r-1" : "m-1"), wsname); auto workspaceIDRight = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r+1" : "m+1")).id;
auto workspaceIDRight = getWorkspaceIDFromString((*PSWIPEUSER ? "r+1" : "m+1"), wsname); const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX);
const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX);
// If we've been swiping off the right end with PSWIPENEW enabled, there is // If we've been swiping off the right end with PSWIPENEW enabled, there is
// no workspace there yet, and we need to choose an ID for a new one now. // no workspace there yet, and we need to choose an ID for a new one now.
@ -232,9 +231,8 @@ void CInputManager::updateWorkspaceSwipe(double delta) {
m_sActiveSwipe.avgSpeed = (m_sActiveSwipe.avgSpeed * m_sActiveSwipe.speedPoints + abs(d)) / (m_sActiveSwipe.speedPoints + 1); m_sActiveSwipe.avgSpeed = (m_sActiveSwipe.avgSpeed * m_sActiveSwipe.speedPoints + abs(d)) / (m_sActiveSwipe.speedPoints + 1);
m_sActiveSwipe.speedPoints++; m_sActiveSwipe.speedPoints++;
std::string wsname = ""; auto workspaceIDLeft = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r-1" : "m-1")).id;
auto workspaceIDLeft = getWorkspaceIDFromString((*PSWIPEUSER ? "r-1" : "m-1"), wsname); auto workspaceIDRight = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r+1" : "m+1")).id;
auto workspaceIDRight = getWorkspaceIDFromString((*PSWIPEUSER ? "r+1" : "m+1"), wsname);
if ((workspaceIDLeft == WORKSPACE_INVALID || workspaceIDRight == WORKSPACE_INVALID || workspaceIDLeft == m_sActiveSwipe.pWorkspaceBegin->m_iID) && !*PSWIPENEW) { if ((workspaceIDLeft == WORKSPACE_INVALID || workspaceIDRight == WORKSPACE_INVALID || workspaceIDLeft == m_sActiveSwipe.pWorkspaceBegin->m_iID) && !*PSWIPENEW) {
m_sActiveSwipe.pWorkspaceBegin = nullptr; // invalidate the swipe m_sActiveSwipe.pWorkspaceBegin = nullptr; // invalidate the swipe