mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 19:26:00 +01:00
Added named workspaces
This commit is contained in:
parent
c02afa0c27
commit
b618fc1caa
4 changed files with 71 additions and 18 deletions
|
@ -707,5 +707,39 @@ CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) {
|
|||
return &w;
|
||||
}
|
||||
|
||||
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*);
|
||||
bool isWorkspaceVisible(const int&);
|
||||
CWorkspace* getWorkspaceByID(const int&);
|
||||
CWorkspace* getWorkspaceByName(const std::string&);
|
||||
CWorkspace* getWorkspaceByString(const std::string&);
|
||||
void sanityCheckWorkspaces();
|
||||
int getWindowsOnWorkspace(const int&);
|
||||
CWindow* getFirstWindowOnWorkspace(const int&);
|
||||
|
@ -108,6 +110,7 @@ public:
|
|||
CWindow* getWindowInDirection(CWindow*, char);
|
||||
void deactivateAllWLRWorkspaces();
|
||||
CWindow* getNextWindowOnWorkspace(CWindow*);
|
||||
int getNextAvailableNamedWorkspace();
|
||||
|
||||
private:
|
||||
void initAllSignals();
|
||||
|
|
|
@ -7,7 +7,10 @@ public:
|
|||
CWorkspace(int monitorID);
|
||||
~CWorkspace();
|
||||
|
||||
// Workspaces ID-based have IDs > 0
|
||||
// and workspaces name-based have IDs starting with -1337
|
||||
int m_iID = -1;
|
||||
std::string m_szName = "";
|
||||
uint64_t m_iMonitorID = -1;
|
||||
bool m_bHasFullscreenWindow = false;
|
||||
|
||||
|
|
|
@ -154,7 +154,22 @@ void CKeybindManager::toggleActivePseudo(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) {
|
||||
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();
|
||||
|
||||
// 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_iMonitorID = PMONITOR->ID;
|
||||
PWORKSPACE->m_szName = workspaceName;
|
||||
|
||||
PMONITOR->activeWorkspace = workspaceToChangeTo;
|
||||
|
||||
|
@ -258,32 +274,29 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
|
|||
if (!g_pCompositor->windowValidMapped(PWINDOW))
|
||||
return;
|
||||
|
||||
int workspaceID;
|
||||
try {
|
||||
workspaceID = stoi(args);
|
||||
} catch( ... ) {
|
||||
Debug::log(ERR, "Invalid movetoworkspace: %s", args.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
|
||||
|
||||
const auto OLDWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID);
|
||||
|
||||
// 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;
|
||||
|
||||
PWINDOW->m_iWorkspaceID = workspaceID;
|
||||
PWINDOW->m_iMonitorID = NEWWORKSPACE->m_iMonitorID;
|
||||
PWINDOW->m_iWorkspaceID = PWORKSPACE->m_iID;
|
||||
PWINDOW->m_iMonitorID = PWORKSPACE->m_iMonitorID;
|
||||
PWINDOW->m_bIsFullscreen = false;
|
||||
|
||||
if (NEWWORKSPACE->m_bHasFullscreenWindow) {
|
||||
g_pCompositor->getFullscreenWindowOnWorkspace(workspaceID)->m_bIsFullscreen = false;
|
||||
NEWWORKSPACE->m_bHasFullscreenWindow = false;
|
||||
if (PWORKSPACE->m_bHasFullscreenWindow) {
|
||||
g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID)->m_bIsFullscreen = false;
|
||||
PWORKSPACE->m_bHasFullscreenWindow = false;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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_vPosition = PWINDOW->m_vRealPosition;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue