Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the workspace separation #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ It also provides the following config values

Keep in mind that if you're using, for example, the `wlr/workspaces` widgets in [waybar](https://github.com/Alexays/Waybar), this will require a change to your config. You should set `all-outputs` to `false`, and adjust the icon mapping.

If your workspace-per-monitor count is 10, the first monitor will have workspaces 1-10, the second 11-20 and so on. They will be accessed via numbers 1-10 while your mouse is on a given monitor.
# Workings
When you are on monitor `(ID=N)` and want to move to workspace `W`,
the actual workspace you go to is given by `(W - 1) * monitors + N + 1`.

# Special thanks
- [hyprsome](https://github.com/sopa0/hyprsome): An earlier project of similar nature
2 changes: 1 addition & 1 deletion hyprload.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[split-monitor-workspaces]
description = "Split monitor workspaces"
version = "1.0.0"
version = "1.1.0"
author = "Duckonaut"

[split-monitor-workspaces.build]
Expand Down
60 changes: 30 additions & 30 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,30 @@
const std::string k_workspaceCount = "plugin:split-monitor-workspaces:count";
const CColor s_pluginColor = {0x61 / 255.0f, 0xAF / 255.0f, 0xEF / 255.0f, 1.0f};

std::map<uint64_t, std::vector<std::string>> g_vMonitorWorkspaceMap;

static HOOK_CALLBACK_FN* e_monitorAddedHandle = nullptr;
static HOOK_CALLBACK_FN* e_monitorRemovedHandle = nullptr;

const std::string& getWorkspaceFromMonitor(CMonitor* monitor, const std::string& workspace)
const std::string getWorkspaceFromMonitor(CMonitor* monitor, const std::string& workspace)
{
int workspaceIndex = std::stoi(workspace);
if (workspaceIndex - 1 < 0) {
int workspaceIndex = 1;
try {
workspaceIndex = std::stoi(workspace);
} catch (...) {
return workspace;
}

if (workspaceIndex - 1 >= g_vMonitorWorkspaceMap[monitor->ID].size()) {
// Checks
int workspaceCount = g_pConfigManager->getConfigValuePtrSafe(k_workspaceCount)->intValue;
if (workspaceIndex < 1 || workspaceIndex > workspaceCount) {
return workspace;
}

return g_vMonitorWorkspaceMap[monitor->ID][workspaceIndex - 1];
// Compute workspace index
std::size_t monitors = g_pCompositor->m_vMonitors.size();

int actualIndex = (workspaceIndex - 1) * monitors + monitor->ID + 1;

return std::to_string(actualIndex);
}

void monitorWorkspace(std::string workspace)
Expand All @@ -57,29 +64,24 @@ void monitorMoveToWorkspaceSilent(std::string workspace)

void mapWorkspacesToMonitors()
{
g_vMonitorWorkspaceMap.clear();

int workspaceIndex = 1;

for (auto& monitor : g_pCompositor->m_vMonitors) {
int workspaceCount = g_pConfigManager->getConfigValuePtrSafe(k_workspaceCount)->intValue;
std::string logMessage =
"[split-monitor-workspaces] Mapping workspaces " + std::to_string(workspaceIndex) + "-" + std::to_string(workspaceIndex + workspaceCount - 1) + " to monitor " + monitor->szName;

HyprlandAPI::addNotification(PHANDLE, logMessage, s_pluginColor, 5000);
std::size_t monitors = g_pCompositor->m_vMonitors.size();
for (auto& workspace : g_pCompositor->m_vWorkspaces) {
int workIndex = 0;
try {
workIndex = std::stoi(workspace->m_szName);
} catch (...) {
continue;
}

for (int i = workspaceIndex; i < workspaceIndex + workspaceCount; i++) {
std::string workspaceName = std::to_string(i);
g_vMonitorWorkspaceMap[monitor->ID].push_back(workspaceName);
HyprlandAPI::invokeHyprctlCommand("keyword", "workspace " + workspaceName + "," + monitor->szName);
CWorkspace* workspace = g_pCompositor->getWorkspaceByName(workspaceName);
// Compute correct monitor (Reverse computation)
int monitor = ((workIndex % monitors) + monitors - 1) % monitors;

if (workspace != nullptr) {
g_pCompositor->moveWorkspaceToMonitor(workspace, monitor.get());
}
}
HyprlandAPI::invokeHyprctlCommand("dispatch", "workspace " + std::to_string(workspaceIndex));
workspaceIndex += workspaceCount;
std::string cmd = "moveworkspacetomonitor "
+ std::to_string(workIndex) + " "
+ std::to_string(monitor);

HyprlandAPI::addNotification(PHANDLE, cmd, s_pluginColor, 5000);
HyprlandAPI::invokeHyprctlCommand("dispatch", cmd);
}
}

Expand Down Expand Up @@ -119,6 +121,4 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle)
APICALL EXPORT void PLUGIN_EXIT()
{
HyprlandAPI::addNotification(PHANDLE, "[split-monitor-workspaces] Unloaded successfully!", s_pluginColor, 5000);

g_vMonitorWorkspaceMap.clear();
}