mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-05 22:51:58 -07:00
Added named workspaces
This commit is contained in:
@@ -709,3 +709,37 @@ CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) {
|
|||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CCompositor::getNextAvailableNamedWorkspace() {
|
||||||
|
int highest = -1337 - 1;
|
||||||
|
for (auto& w : m_lWorkspaces) {
|
||||||
|
if (w.m_iID < 0 && w.m_iID > highest)
|
||||||
|
highest = w.m_iID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return highest + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CWorkspace* CCompositor::getWorkspaceByName(const std::string& name) {
|
||||||
|
for (auto& w : m_lWorkspaces) {
|
||||||
|
if (w.m_szName == name)
|
||||||
|
return &w;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
CWorkspace* CCompositor::getWorkspaceByString(const std::string& str) {
|
||||||
|
if (str.find("name:") == 0) {
|
||||||
|
return getWorkspaceByName(str.substr(str.find_first_of(':') + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int id = std::stoi(str);
|
||||||
|
return getWorkspaceByID(id);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
Debug::log(ERR, "Error in getWorkspaceByString, invalid id");
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
@@ -96,6 +96,8 @@ public:
|
|||||||
CWindow* getWindowFromSurface(wlr_surface*);
|
CWindow* getWindowFromSurface(wlr_surface*);
|
||||||
bool isWorkspaceVisible(const int&);
|
bool isWorkspaceVisible(const int&);
|
||||||
CWorkspace* getWorkspaceByID(const int&);
|
CWorkspace* getWorkspaceByID(const int&);
|
||||||
|
CWorkspace* getWorkspaceByName(const std::string&);
|
||||||
|
CWorkspace* getWorkspaceByString(const std::string&);
|
||||||
void sanityCheckWorkspaces();
|
void sanityCheckWorkspaces();
|
||||||
int getWindowsOnWorkspace(const int&);
|
int getWindowsOnWorkspace(const int&);
|
||||||
CWindow* getFirstWindowOnWorkspace(const int&);
|
CWindow* getFirstWindowOnWorkspace(const int&);
|
||||||
@@ -108,6 +110,7 @@ public:
|
|||||||
CWindow* getWindowInDirection(CWindow*, char);
|
CWindow* getWindowInDirection(CWindow*, char);
|
||||||
void deactivateAllWLRWorkspaces();
|
void deactivateAllWLRWorkspaces();
|
||||||
CWindow* getNextWindowOnWorkspace(CWindow*);
|
CWindow* getNextWindowOnWorkspace(CWindow*);
|
||||||
|
int getNextAvailableNamedWorkspace();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initAllSignals();
|
void initAllSignals();
|
||||||
|
@@ -7,7 +7,10 @@ public:
|
|||||||
CWorkspace(int monitorID);
|
CWorkspace(int monitorID);
|
||||||
~CWorkspace();
|
~CWorkspace();
|
||||||
|
|
||||||
|
// Workspaces ID-based have IDs > 0
|
||||||
|
// and workspaces name-based have IDs starting with -1337
|
||||||
int m_iID = -1;
|
int m_iID = -1;
|
||||||
|
std::string m_szName = "";
|
||||||
uint64_t m_iMonitorID = -1;
|
uint64_t m_iMonitorID = -1;
|
||||||
bool m_bHasFullscreenWindow = false;
|
bool m_bHasFullscreenWindow = false;
|
||||||
|
|
||||||
|
@@ -154,7 +154,22 @@ void CKeybindManager::toggleActivePseudo(std::string args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CKeybindManager::changeworkspace(std::string args) {
|
void CKeybindManager::changeworkspace(std::string args) {
|
||||||
int workspaceToChangeTo = std::clamp((int)getPlusMinusKeywordResult(args, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX);
|
int workspaceToChangeTo = 0;
|
||||||
|
std::string workspaceName = "";
|
||||||
|
|
||||||
|
if (args.find("name:") == 0) {
|
||||||
|
const auto WORKSPACENAME = args.substr(args.find_first_of(':') + 1);
|
||||||
|
const auto WORKSPACE = g_pCompositor->getWorkspaceByName(WORKSPACENAME);
|
||||||
|
if (!WORKSPACE) {
|
||||||
|
workspaceToChangeTo = g_pCompositor->getNextAvailableNamedWorkspace();
|
||||||
|
} else {
|
||||||
|
workspaceToChangeTo = WORKSPACE->m_iID;
|
||||||
|
}
|
||||||
|
workspaceName = WORKSPACENAME;
|
||||||
|
} else {
|
||||||
|
workspaceToChangeTo = std::clamp((int)getPlusMinusKeywordResult(args, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX);
|
||||||
|
workspaceName = std::to_string(workspaceToChangeTo);
|
||||||
|
}
|
||||||
|
|
||||||
if (workspaceToChangeTo == INT_MAX) {
|
if (workspaceToChangeTo == INT_MAX) {
|
||||||
Debug::log(ERR, "Error in changeworkspace, invalid value");
|
Debug::log(ERR, "Error in changeworkspace, invalid value");
|
||||||
@@ -211,10 +226,11 @@ void CKeybindManager::changeworkspace(std::string args) {
|
|||||||
const auto PWORKSPACE = &g_pCompositor->m_lWorkspaces.back();
|
const auto PWORKSPACE = &g_pCompositor->m_lWorkspaces.back();
|
||||||
|
|
||||||
// We are required to set the name here immediately
|
// We are required to set the name here immediately
|
||||||
wlr_ext_workspace_handle_v1_set_name(PWORKSPACE->m_pWlrHandle, std::to_string(workspaceToChangeTo).c_str());
|
wlr_ext_workspace_handle_v1_set_name(PWORKSPACE->m_pWlrHandle, workspaceName.c_str());
|
||||||
|
|
||||||
PWORKSPACE->m_iID = workspaceToChangeTo;
|
PWORKSPACE->m_iID = workspaceToChangeTo;
|
||||||
PWORKSPACE->m_iMonitorID = PMONITOR->ID;
|
PWORKSPACE->m_iMonitorID = PMONITOR->ID;
|
||||||
|
PWORKSPACE->m_szName = workspaceName;
|
||||||
|
|
||||||
PMONITOR->activeWorkspace = workspaceToChangeTo;
|
PMONITOR->activeWorkspace = workspaceToChangeTo;
|
||||||
|
|
||||||
@@ -258,32 +274,29 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
|
|||||||
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int workspaceID;
|
|
||||||
try {
|
|
||||||
workspaceID = stoi(args);
|
|
||||||
} catch( ... ) {
|
|
||||||
Debug::log(ERR, "Invalid movetoworkspace: %s", args.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
|
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
|
||||||
|
|
||||||
const auto OLDWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID);
|
const auto OLDWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID);
|
||||||
|
|
||||||
// hack
|
// hack
|
||||||
g_pKeybindManager->changeworkspace(std::to_string(workspaceID));
|
g_pKeybindManager->changeworkspace(args);
|
||||||
|
|
||||||
const auto NEWWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceID);
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByString(args);
|
||||||
|
|
||||||
|
if (PWORKSPACE == OLDWORKSPACE) {
|
||||||
|
Debug::log(LOG, "Not moving to workspace because it didn't change.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OLDWORKSPACE->m_bHasFullscreenWindow = false;
|
OLDWORKSPACE->m_bHasFullscreenWindow = false;
|
||||||
|
|
||||||
PWINDOW->m_iWorkspaceID = workspaceID;
|
PWINDOW->m_iWorkspaceID = PWORKSPACE->m_iID;
|
||||||
PWINDOW->m_iMonitorID = NEWWORKSPACE->m_iMonitorID;
|
PWINDOW->m_iMonitorID = PWORKSPACE->m_iMonitorID;
|
||||||
PWINDOW->m_bIsFullscreen = false;
|
PWINDOW->m_bIsFullscreen = false;
|
||||||
|
|
||||||
if (NEWWORKSPACE->m_bHasFullscreenWindow) {
|
if (PWORKSPACE->m_bHasFullscreenWindow) {
|
||||||
g_pCompositor->getFullscreenWindowOnWorkspace(workspaceID)->m_bIsFullscreen = false;
|
g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID)->m_bIsFullscreen = false;
|
||||||
NEWWORKSPACE->m_bHasFullscreenWindow = false;
|
PWORKSPACE->m_bHasFullscreenWindow = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack: So that the layout doesnt find our window at the cursor
|
// Hack: So that the layout doesnt find our window at the cursor
|
||||||
@@ -299,7 +312,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
|
|||||||
|
|
||||||
if (PWINDOW->m_bIsFloating) {
|
if (PWINDOW->m_bIsFloating) {
|
||||||
PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition;
|
PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition;
|
||||||
PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(NEWWORKSPACE->m_iMonitorID)->vecPosition;
|
PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition;
|
||||||
PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition;
|
PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition;
|
||||||
PWINDOW->m_vPosition = PWINDOW->m_vRealPosition;
|
PWINDOW->m_vPosition = PWINDOW->m_vRealPosition;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user