2023-04-27 11:14:11 -07:00
|
|
|
#include <hyprland/src/plugins/PluginAPI.hpp>
|
|
|
|
#include <hyprland/src/Compositor.hpp>
|
2023-04-12 01:33:00 -07:00
|
|
|
|
2023-04-17 00:53:02 -07:00
|
|
|
#include "globals.hpp"
|
2023-04-30 00:47:01 -07:00
|
|
|
#include "SelectionHook.hpp"
|
2023-04-12 01:33:00 -07:00
|
|
|
|
|
|
|
APICALL EXPORT std::string PLUGIN_API_VERSION() {
|
|
|
|
return HYPRLAND_API_VERSION;
|
|
|
|
}
|
|
|
|
|
2023-04-13 14:12:48 -07:00
|
|
|
// return a window if a window action makes sense now
|
|
|
|
CWindow* window_for_action() {
|
|
|
|
if (g_pLayoutManager->getCurrentLayout() != g_Hy3Layout.get()) return nullptr;
|
2023-04-12 01:33:00 -07:00
|
|
|
|
2023-04-13 14:12:48 -07:00
|
|
|
auto* window = g_pCompositor->m_pLastWindow;
|
2023-04-12 01:33:00 -07:00
|
|
|
|
2023-04-13 14:12:48 -07:00
|
|
|
if (!window) return nullptr;
|
2023-04-12 01:33:00 -07:00
|
|
|
|
2023-04-13 14:12:48 -07:00
|
|
|
const auto workspace = g_pCompositor->getWorkspaceByID(window->m_iWorkspaceID);
|
|
|
|
if (workspace->m_bHasFullscreenWindow) return nullptr;
|
2023-04-12 01:33:00 -07:00
|
|
|
|
2023-04-13 14:12:48 -07:00
|
|
|
return window;
|
|
|
|
}
|
2023-04-12 01:33:00 -07:00
|
|
|
|
2023-04-26 00:57:24 -07:00
|
|
|
int workspace_for_action() {
|
|
|
|
if (g_pLayoutManager->getCurrentLayout() != g_Hy3Layout.get()) return -1;
|
|
|
|
|
|
|
|
int workspace_id = g_pCompositor->m_pLastMonitor->activeWorkspace;
|
|
|
|
|
|
|
|
if (workspace_id < 0) return -1;
|
|
|
|
auto* workspace = g_pCompositor->getWorkspaceByID(workspace_id);
|
|
|
|
if (workspace == nullptr) return -1;
|
|
|
|
if (workspace->m_bHasFullscreenWindow) return -1;
|
|
|
|
|
|
|
|
return workspace_id;
|
|
|
|
}
|
|
|
|
|
2023-04-13 14:12:48 -07:00
|
|
|
void dispatch_makegroup(std::string arg) {
|
2023-04-26 00:57:24 -07:00
|
|
|
int workspace = workspace_for_action();
|
|
|
|
if (workspace < 0) return;
|
2023-04-12 01:33:00 -07:00
|
|
|
|
2023-04-13 14:12:48 -07:00
|
|
|
if (arg == "h") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->makeGroupOn(workspace, Hy3GroupLayout::SplitH);
|
2023-04-13 14:12:48 -07:00
|
|
|
} else if (arg == "v") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->makeGroupOn(workspace, Hy3GroupLayout::SplitV);
|
2023-04-13 14:12:48 -07:00
|
|
|
}
|
|
|
|
}
|
2023-04-12 01:33:00 -07:00
|
|
|
|
2023-04-13 14:12:48 -07:00
|
|
|
void dispatch_movewindow(std::string arg) {
|
2023-04-26 00:57:24 -07:00
|
|
|
int workspace = workspace_for_action();
|
|
|
|
if (workspace < 0) return;
|
2023-04-13 14:12:48 -07:00
|
|
|
|
|
|
|
if (arg == "l") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->shiftWindow(workspace, ShiftDirection::Left);
|
2023-04-13 14:12:48 -07:00
|
|
|
} else if (arg == "u") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->shiftWindow(workspace, ShiftDirection::Up);
|
2023-04-13 14:12:48 -07:00
|
|
|
} else if (arg == "d") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->shiftWindow(workspace, ShiftDirection::Down);
|
2023-04-13 14:12:48 -07:00
|
|
|
} else if (arg == "r") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->shiftWindow(workspace, ShiftDirection::Right);
|
2023-04-13 14:12:48 -07:00
|
|
|
}
|
2023-04-12 01:33:00 -07:00
|
|
|
}
|
|
|
|
|
2023-04-16 16:27:18 -07:00
|
|
|
void dispatch_movefocus(std::string arg) {
|
2023-04-26 00:57:24 -07:00
|
|
|
int workspace = workspace_for_action();
|
|
|
|
if (workspace < 0) return;
|
2023-04-16 16:27:18 -07:00
|
|
|
|
|
|
|
if (arg == "l") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->shiftFocus(workspace, ShiftDirection::Left);
|
2023-04-16 16:27:18 -07:00
|
|
|
} else if (arg == "u") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->shiftFocus(workspace, ShiftDirection::Up);
|
2023-04-16 16:27:18 -07:00
|
|
|
} else if (arg == "d") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->shiftFocus(workspace, ShiftDirection::Down);
|
2023-04-16 16:27:18 -07:00
|
|
|
} else if (arg == "r") {
|
2023-04-26 00:57:24 -07:00
|
|
|
g_Hy3Layout->shiftFocus(workspace, ShiftDirection::Right);
|
2023-04-16 16:27:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-26 00:57:24 -07:00
|
|
|
void dispatch_raisefocus(std::string arg) {
|
|
|
|
int workspace = workspace_for_action();
|
|
|
|
if (workspace < 0) return;
|
|
|
|
|
|
|
|
g_Hy3Layout->raiseFocus(workspace);
|
|
|
|
}
|
|
|
|
|
2023-04-19 01:58:22 -07:00
|
|
|
void dispatch_debug(std::string arg) {
|
2023-04-26 00:57:24 -07:00
|
|
|
int workspace = workspace_for_action();
|
|
|
|
if (workspace < 0) return;
|
2023-04-19 01:58:22 -07:00
|
|
|
|
2023-04-26 00:57:24 -07:00
|
|
|
auto* root = g_Hy3Layout->getWorkspaceRootGroup(workspace);
|
|
|
|
if (workspace < 0) {
|
2023-04-19 01:58:22 -07:00
|
|
|
Debug::log(LOG, "DEBUG NODES: no nodes on workspace");
|
|
|
|
} else {
|
|
|
|
Debug::log(LOG, "DEBUG NODES\n%s", root->debugNode().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-12 01:33:00 -07:00
|
|
|
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
|
|
|
PHANDLE = handle;
|
|
|
|
|
2023-04-30 00:47:01 -07:00
|
|
|
selection_hook::init();
|
|
|
|
|
2023-04-17 00:53:02 -07:00
|
|
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hy3:no_gaps_when_only", SConfigValue{.intValue = 0});
|
|
|
|
|
2023-04-12 01:33:00 -07:00
|
|
|
g_Hy3Layout = std::make_unique<Hy3Layout>();
|
|
|
|
HyprlandAPI::addLayout(PHANDLE, "hy3", g_Hy3Layout.get());
|
|
|
|
|
2023-04-19 02:20:25 -07:00
|
|
|
HyprlandAPI::addDispatcher(PHANDLE, "hy3:makegroup", dispatch_makegroup);
|
|
|
|
HyprlandAPI::addDispatcher(PHANDLE, "hy3:movefocus", dispatch_movefocus);
|
|
|
|
HyprlandAPI::addDispatcher(PHANDLE, "hy3:movewindow", dispatch_movewindow);
|
2023-04-26 00:57:24 -07:00
|
|
|
HyprlandAPI::addDispatcher(PHANDLE, "hy3:raisefocus", dispatch_raisefocus);
|
2023-04-19 02:20:25 -07:00
|
|
|
HyprlandAPI::addDispatcher(PHANDLE, "hy3:debugnodes", dispatch_debug);
|
2023-04-12 01:33:00 -07:00
|
|
|
|
|
|
|
return {"hy3", "i3 like layout for hyprland", "outfoxxed", "0.1"};
|
|
|
|
}
|
|
|
|
|
|
|
|
APICALL EXPORT void PLUGIN_EXIT() {}
|