mirror of
https://github.com/hyprwm/hyprland-plugins.git
synced 2025-12-20 06:50:02 +01:00
hyprwinwrap: add position and coordinates options (#427)
This commit is contained in:
parent
d723e5b153
commit
d4bf99e722
2 changed files with 58 additions and 12 deletions
|
|
@ -10,6 +10,12 @@ plugin {
|
||||||
class = kitty-bg
|
class = kitty-bg
|
||||||
# you can also use title
|
# you can also use title
|
||||||
title = kitty-bg
|
title = kitty-bg
|
||||||
|
# you can add the position of the window in a percentage
|
||||||
|
pos_x = 25
|
||||||
|
pos_y = 30
|
||||||
|
# you can add the size of the window in a percentage
|
||||||
|
size_x = 40
|
||||||
|
size_y = 70
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
|
|
||||||
// Do NOT change this function.
|
// Do NOT change this function
|
||||||
APICALL EXPORT std::string PLUGIN_API_VERSION() {
|
APICALL EXPORT std::string PLUGIN_API_VERSION() {
|
||||||
return HYPRLAND_API_VERSION;
|
return HYPRLAND_API_VERSION;
|
||||||
}
|
}
|
||||||
|
|
@ -32,10 +32,14 @@ typedef void (*origCommit)(void* owner, void* data);
|
||||||
|
|
||||||
std::vector<PHLWINDOWREF> bgWindows;
|
std::vector<PHLWINDOWREF> bgWindows;
|
||||||
|
|
||||||
//
|
|
||||||
void onNewWindow(PHLWINDOW pWindow) {
|
void onNewWindow(PHLWINDOW pWindow) {
|
||||||
static auto* const PCLASS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:class")->getDataStaticPtr();
|
static auto* const PCLASS = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:class")->getDataStaticPtr();
|
||||||
static auto* const PTITLE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:title")->getDataStaticPtr();
|
static auto* const PTITLE = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:title")->getDataStaticPtr();
|
||||||
|
|
||||||
|
static auto* const PSIZEX = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:size_x")->getDataStaticPtr();
|
||||||
|
static auto* const PSIZEY = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:size_y")->getDataStaticPtr();
|
||||||
|
static auto* const PPOSX = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:pos_x")->getDataStaticPtr();
|
||||||
|
static auto* const PPOSY = (Hyprlang::STRING const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprwinwrap:pos_y")->getDataStaticPtr();
|
||||||
|
|
||||||
const std::string classRule(*PCLASS);
|
const std::string classRule(*PCLASS);
|
||||||
const std::string titleRule(*PTITLE);
|
const std::string titleRule(*PTITLE);
|
||||||
|
|
@ -47,26 +51,57 @@ void onNewWindow(PHLWINDOW pWindow) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto PMONITOR = pWindow->m_monitor.lock();
|
const auto PMONITOR = pWindow->m_monitor.lock();
|
||||||
|
|
||||||
if (!PMONITOR)
|
if (!PMONITOR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!pWindow->m_isFloating)
|
if (!pWindow->m_isFloating)
|
||||||
g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(pWindow);
|
g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(pWindow);
|
||||||
|
|
||||||
pWindow->m_realSize->setValueAndWarp(PMONITOR->m_size);
|
float sx = 100.f, sy = 100.f, px = 0.f, py = 0.f;
|
||||||
pWindow->m_realPosition->setValueAndWarp(PMONITOR->m_position);
|
|
||||||
pWindow->m_size = PMONITOR->m_size;
|
try { sx = std::stof(*PSIZEX); } catch (...) {}
|
||||||
pWindow->m_position = PMONITOR->m_position;
|
try { sy = std::stof(*PSIZEY); } catch (...) {}
|
||||||
|
try { px = std::stof(*PPOSX); } catch (...) {}
|
||||||
|
try { py = std::stof(*PPOSY); } catch (...) {}
|
||||||
|
|
||||||
|
sx = std::clamp(sx, 1.f, 100.f);
|
||||||
|
sy = std::clamp(sy, 1.f, 100.f);
|
||||||
|
px = std::clamp(px, 0.f, 100.f);
|
||||||
|
py = std::clamp(py, 0.f, 100.f);
|
||||||
|
|
||||||
|
if (px + sx > 100.f) {
|
||||||
|
Debug::log(WARN, "[hyprwinwrap] size_x (%d) + pos_x (%d) > 100, adjusting size_x to %d", sx, px, 100.f - px);
|
||||||
|
sx = 100.f - px;
|
||||||
|
}
|
||||||
|
if (py + sy > 100.f) {
|
||||||
|
Debug::log(WARN, "[hyprwinwrap] size_y (%d) + pos_y (%d) > 100, adjusting size_y to %d", sy, py, 100.f - py);
|
||||||
|
sy = 100.f - py;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector2D monitorSize = PMONITOR->m_size;
|
||||||
|
const Vector2D monitorPos = PMONITOR->m_position;
|
||||||
|
|
||||||
|
const Vector2D newSize = {
|
||||||
|
static_cast<int>(monitorSize.x * (sx / 100.f)),
|
||||||
|
static_cast<int>(monitorSize.y * (sy / 100.f))
|
||||||
|
};
|
||||||
|
|
||||||
|
const Vector2D newPos = {
|
||||||
|
static_cast<int>(monitorPos.x + (monitorSize.x * (px / 100.f))),
|
||||||
|
static_cast<int>(monitorPos.y + (monitorSize.y * (py / 100.f)))
|
||||||
|
};
|
||||||
|
|
||||||
|
pWindow->m_realSize->setValueAndWarp(newSize);
|
||||||
|
pWindow->m_realPosition->setValueAndWarp(newPos);
|
||||||
|
pWindow->m_size = newSize;
|
||||||
|
pWindow->m_position = newPos;
|
||||||
pWindow->m_pinned = true;
|
pWindow->m_pinned = true;
|
||||||
pWindow->sendWindowSize(true);
|
pWindow->sendWindowSize(true);
|
||||||
|
|
||||||
bgWindows.push_back(pWindow);
|
bgWindows.push_back(pWindow);
|
||||||
|
pWindow->m_hidden = true;
|
||||||
pWindow->m_hidden = true; // no renderino hyprland pls
|
|
||||||
|
|
||||||
g_pInputManager->refocus();
|
g_pInputManager->refocus();
|
||||||
|
|
||||||
Debug::log(LOG, "[hyprwinwrap] new window moved to bg {}", pWindow);
|
Debug::log(LOG, "[hyprwinwrap] new window moved to bg {}", pWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,6 +222,11 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
|
||||||
|
|
||||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprwinwrap:class", Hyprlang::STRING{"kitty-bg"});
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprwinwrap:class", Hyprlang::STRING{"kitty-bg"});
|
||||||
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprwinwrap:title", Hyprlang::STRING{""});
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprwinwrap:title", Hyprlang::STRING{""});
|
||||||
|
|
||||||
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprwinwrap:size_x", Hyprlang::STRING{"100"});
|
||||||
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprwinwrap:size_y", Hyprlang::STRING{"100"});
|
||||||
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprwinwrap:pos_x", Hyprlang::STRING{"0"});
|
||||||
|
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprwinwrap:pos_y", Hyprlang::STRING{"0"});
|
||||||
|
|
||||||
HyprlandAPI::addNotification(PHANDLE, "[hyprwinwrap] Initialized successfully!", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000);
|
HyprlandAPI::addNotification(PHANDLE, "[hyprwinwrap] Initialized successfully!", CHyprColor{0.2, 1.0, 0.2, 1.0}, 5000);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue