Skip to content

Commit

Permalink
Merge pull request #49 from levnikmyskin/feature/hyprland_0.41.1
Browse files Browse the repository at this point in the history
Support hyprland v0.41.1 (use hyprutils)
  • Loading branch information
levnikmyskin authored Jun 15, 2024
2 parents 02cadb1 + 003c77c commit b5121a4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 39 deletions.
9 changes: 9 additions & 0 deletions .github/actions/setup_base/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ runs:
cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
cmake --install build
- name: Get hyprutils
shell: bash
run: |
git clone https://github.com/hyprwm/hyprutils.git
cd hyprutils
cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf _NPROCESSORS_CONF`
cmake --install build
- name: Get Xorg pacman pkgs
shell: bash
if: inputs.INSTALL_XORG_PKGS == 'true'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
if: github.ref == 'refs/heads/main'|| github.base_ref == 'main'
with:
INSTALL_XORG_PKGS: true
branch: 'v0.41.0'
branch: 'v0.41.1'
hyprwayland: 'v0.3.10'

- name: Setup base on dev
Expand Down
6 changes: 4 additions & 2 deletions include/VirtualDesk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
#include "globals.hpp"
#include "utils.hpp"
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/helpers/memory/SharedPtr.hpp>
#include <hyprutils/memory/WeakPtr.hpp>

typedef std::unordered_map<int, int> WorkspaceMap;
using namespace Hyprutils::Memory;

typedef std::unordered_map<int, int> WorkspaceMap;
// map with CMonitor* -> hyprland workspace id
typedef std::unordered_map<const CMonitor*, int> Layout;
typedef std::string MonitorName;
Expand Down
4 changes: 3 additions & 1 deletion include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include <hyprland/src/debug/Log.hpp>
#include "globals.hpp"
#include <hyprland/src/config/ConfigManager.hpp>
#include <hyprland/src/helpers/memory/SharedPtr.hpp>
#include <hyprutils/memory/WeakPtr.hpp>
#include <string>
#include <hyprland/src/Compositor.hpp>

using namespace Hyprutils::Memory;

const std::string VIRTUALDESK_NAMES_CONF = "plugin:virtual-desktops:names";
const std::string CYCLEWORKSPACES_CONF = "plugin:virtual-desktops:cycleworkspaces";
const std::string REMEMBER_LAYOUT_CONF = "plugin:virtual-desktops:rememberlayout";
Expand Down
72 changes: 37 additions & 35 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <hyprland/src/desktop/Workspace.hpp>
#include <hyprland/src/debug/Log.hpp>
#include <hyprland/src/events/Events.hpp>
#include <hyprland/src/helpers/memory/SharedPtr.hpp>
#include <hyprutils/memory/SharedPtr.hpp>

#include "globals.hpp"
#include "VirtualDeskManager.hpp"
Expand All @@ -15,21 +15,23 @@
#include <any>
#include <vector>

using namespace Hyprutils::Memory;

static CSharedPointer<HOOK_CALLBACK_FN> onWorkspaceChangeHook = nullptr;
static CSharedPointer<HOOK_CALLBACK_FN> onWindowOpenHook = nullptr;
static CSharedPointer<HOOK_CALLBACK_FN> onConfigReloadedHook = nullptr;

inline CFunctionHook* g_pMonitorConnectHook = nullptr;
inline CFunctionHook* g_pMonitorDisconnectHook = nullptr;
typedef void (*origMonitorConnect)(void*, bool);
typedef void (*origMonitorDisconnect)(void*, bool);
typedef void (*origMonitorConnect)(void*, bool);
typedef void (*origMonitorDisconnect)(void*, bool);

std::unique_ptr<VirtualDeskManager> manager = std::make_unique<VirtualDeskManager>();
std::vector<StickyApps::SStickyRule> stickyRules;
bool notifiedInit = false;
bool monitorLayoutChanging = false;
std::unique_ptr<VirtualDeskManager> manager = std::make_unique<VirtualDeskManager>();
std::vector<StickyApps::SStickyRule> stickyRules;
bool notifiedInit = false;
bool monitorLayoutChanging = false;

void parseNamesConf(std::string& conf) {
void parseNamesConf(std::string& conf) {
size_t pos;
size_t delim;
std::string rule;
Expand Down Expand Up @@ -179,38 +181,36 @@ std::string printStateDispatch(eHyprCtlOutputFormat format, std::string arg) {
if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) {
out += "Virtual desks\n";
int index = 0;
for(auto const& [vdeskId, desk] : manager->vdesksMap) {
for (auto const& [vdeskId, desk] : manager->vdesksMap) {
unsigned int windows = 0;
std::string workspaces;
bool first = true;
for(auto const& [monitor, workspaceId] : desk->activeLayout(manager->conf)) {
std::string workspaces;
bool first = true;
for (auto const& [monitor, workspaceId] : desk->activeLayout(manager->conf)) {
windows += g_pCompositor->getWindowsOnWorkspace(workspaceId);
if(!first) workspaces += ", ";
else first = false;
if (!first)
workspaces += ", ";
else
first = false;
workspaces += std::format("{}", workspaceId);
}
out += std::format(
"- {}: {}\n Focused: {}\n Populated: {}\n Workspaces: {}\n Windows: {}\n",
desk->name,
desk->id,
manager->activeVdesk().get() == desk.get(),
windows > 0,
workspaces,
windows
);
if(index++ < manager->vdesksMap.size() - 1) out += "\n";
out += std::format("- {}: {}\n Focused: {}\n Populated: {}\n Workspaces: {}\n Windows: {}\n", desk->name, desk->id, manager->activeVdesk().get() == desk.get(),
windows > 0, workspaces, windows);
if (index++ < manager->vdesksMap.size() - 1)
out += "\n";
}
} else if(format == eHyprCtlOutputFormat::FORMAT_JSON) {
} else if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
std::string vdesks;
int index = 0;
for(auto const& [vdeskId, desk] : manager->vdesksMap) {
int index = 0;
for (auto const& [vdeskId, desk] : manager->vdesksMap) {
unsigned int windows = 0;
std::string workspaces;
bool first = true;
for(auto const& [monitor, workspaceId] : desk->activeLayout(manager->conf)) {
std::string workspaces;
bool first = true;
for (auto const& [monitor, workspaceId] : desk->activeLayout(manager->conf)) {
windows += g_pCompositor->getWindowsOnWorkspace(workspaceId);
if(!first) workspaces += ", ";
else first = false;
if (!first)
workspaces += ", ";
else
first = false;
workspaces += std::format("{}", workspaceId);
}
vdesks += std::format(R"#({{
Expand All @@ -220,8 +220,10 @@ std::string printStateDispatch(eHyprCtlOutputFormat format, std::string arg) {
"populated": {},
"workspaces": [{}],
"windows": {}
}})#", vdeskId, desk->name, manager->activeVdesk().get() == desk.get(), windows > 0, workspaces, windows);
if(index++ < manager->vdesksMap.size() - 1) vdesks += ",";
}})#",
vdeskId, desk->name, manager->activeVdesk().get() == desk.get(), windows > 0, workspaces, windows);
if (index++ < manager->vdesksMap.size() - 1)
vdesks += ",";
}
out += std::format(R"#([{}])#", vdesks);
}
Expand Down Expand Up @@ -418,5 +420,5 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {

// Initialize first vdesk
HyprlandAPI::reloadConfig();
return {"virtual-desktops", "Virtual desktop like workspaces", "LevMyskin", "2.2.3"};
return {"virtual-desktops", "Virtual desktop like workspaces", "LevMyskin", "2.2.4"};
}

0 comments on commit b5121a4

Please sign in to comment.