mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-22 05:25:58 +01:00
Added splitratio
This commit is contained in:
parent
002247629e
commit
84a832181b
8 changed files with 58 additions and 6 deletions
|
@ -110,3 +110,6 @@ bind=SUPERSHIFT,8,movetoworkspace,8
|
|||
bind=SUPERSHIFT,9,movetoworkspace,9
|
||||
|
||||
bind=SUPER,SPACE,togglefloating,
|
||||
|
||||
bind=SUPER,equals,splitratio,+
|
||||
bind=SUPER,minus,splitratio,-
|
||||
|
|
|
@ -212,3 +212,7 @@ void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) {
|
|||
g_pWindowManager->setAllFloatingWindowsTop();
|
||||
}
|
||||
}
|
||||
|
||||
void KeybindManager::changeSplitRatio(std::string args) {
|
||||
g_pWindowManager->changeSplitRatioCurrent(args[0]);
|
||||
}
|
|
@ -27,4 +27,5 @@ namespace KeybindManager {
|
|||
void toggleActiveWindowFullscreen(std::string args);
|
||||
void toggleActiveWindowFloating(std::string args);
|
||||
void movetoworkspace(std::string args);
|
||||
void changeSplitRatio(std::string args);
|
||||
};
|
||||
|
|
|
@ -124,6 +124,7 @@ void handleBind(const std::string& command, const std::string& value) {
|
|||
if (HANDLER == "workspace") dispatcher = KeybindManager::changeworkspace;
|
||||
if (HANDLER == "lastworkspace") dispatcher = KeybindManager::changetolastworkspace;
|
||||
if (HANDLER == "togglefloating") dispatcher = KeybindManager::toggleActiveWindowFloating;
|
||||
if (HANDLER == "splitratio") dispatcher = KeybindManager::changeSplitRatio;
|
||||
|
||||
if (dispatcher && KEY != 0)
|
||||
KeybindManager::keybinds.push_back(Keybind(KeybindManager::modToMask(MOD), KEY, COMMAND, dispatcher));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "window.hpp"
|
||||
#include "windowManager.hpp"
|
||||
|
||||
CWindow::CWindow() { this->setDockHidden(false); this->setRealBorderColor(0); this->setEffectiveBorderColor(0); this->setFirstOpen(true); this->setConstructed(false); this->setTransient(false); this->setLastUpdatePosition(Vector2D(0,0)); this->setLastUpdateSize(Vector2D(0,0)); this->setDock(false); this->setUnderFullscreen(false); this->setIsSleeping(true); this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); }
|
||||
CWindow::CWindow() { this->setSplitRatio(1); this->setDockHidden(false); this->setRealBorderColor(0); this->setEffectiveBorderColor(0); this->setFirstOpen(true); this->setConstructed(false); this->setTransient(false); this->setLastUpdatePosition(Vector2D(0,0)); this->setLastUpdateSize(Vector2D(0,0)); this->setDock(false); this->setUnderFullscreen(false); this->setIsSleeping(true); this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); }
|
||||
CWindow::~CWindow() { }
|
||||
|
||||
void CWindow::generateNodeID() {
|
||||
|
@ -28,11 +28,14 @@ void CWindow::setDirtyRecursive(bool val) {
|
|||
void CWindow::recalcSizePosRecursive() {
|
||||
if (m_iChildNodeAID != 0) {
|
||||
const auto HORIZONTAL = m_vecSize.x > m_vecSize.y;
|
||||
|
||||
const auto REVERSESPLITRATIO = 2.f - m_fSplitRatio;
|
||||
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeAID)->setPosition(m_vecPosition);
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setPosition(m_vecPosition + (HORIZONTAL ? Vector2D(m_vecSize.x / 2.f, 0) : Vector2D(0, m_vecSize.y / 2.f)));
|
||||
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeAID)->setSize(Vector2D(m_vecSize.x / (HORIZONTAL ? 2 : 1), m_vecSize.y / (HORIZONTAL ? 1 : 2)));
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setSize(Vector2D(m_vecSize.x / (HORIZONTAL ? 2 : 1), m_vecSize.y / (HORIZONTAL ? 1 : 2)));
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setPosition(m_vecPosition + (HORIZONTAL ? Vector2D(m_vecSize.x / 2.f * m_fSplitRatio, 0) : Vector2D(0, m_vecSize.y / 2.f * m_fSplitRatio)));
|
||||
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeAID)->setSize(Vector2D(m_vecSize.x / (HORIZONTAL ? 2 / m_fSplitRatio : 1), m_vecSize.y / (HORIZONTAL ? 1 : 2 / m_fSplitRatio)));
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setSize(Vector2D(m_vecSize.x / (HORIZONTAL ? 2 / REVERSESPLITRATIO : 1), m_vecSize.y / (HORIZONTAL ? 1 : 2 / REVERSESPLITRATIO)));
|
||||
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeAID)->setDirty(true);
|
||||
g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setDirty(true);
|
||||
|
|
|
@ -59,6 +59,9 @@ public:
|
|||
EXPOSED_MEMBER(IsFloating, bool, b);
|
||||
EXPOSED_MEMBER(Drawable, int64_t, i); // int64_t because it's my internal ID system too.
|
||||
|
||||
// For splitting ratios
|
||||
EXPOSED_MEMBER(SplitRatio, float, f);
|
||||
|
||||
// Fullscreen
|
||||
EXPOSED_MEMBER(Fullscreen, bool, b);
|
||||
|
||||
|
|
|
@ -1113,7 +1113,7 @@ void CWindowManager::recalcEntireWorkspace(const int& workspace) {
|
|||
// get the master on the workspace
|
||||
CWindow* pMasterWindow = nullptr;
|
||||
for (auto& w : windows) {
|
||||
if (w.getWorkspaceID() == workspace && w.getParentNodeID() == 0) {
|
||||
if (w.getWorkspaceID() == workspace && w.getParentNodeID() == 0 && !w.getIsFloating() && !w.getDock()) {
|
||||
pMasterWindow = &w;
|
||||
break;
|
||||
}
|
||||
|
@ -2425,4 +2425,39 @@ SMonitor* CWindowManager::getMonitorFromCoord(const Vector2D coord) {
|
|||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CWindowManager::changeSplitRatioCurrent(const char& dir) {
|
||||
|
||||
const auto CURRENT = getWindowFromDrawable(LastWindow);
|
||||
|
||||
if (!CURRENT) {
|
||||
Debug::log(LOG, "Cannot change split ratio when lastwindow NULL.");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto PARENT = getWindowFromDrawable(CURRENT->getParentNodeID());
|
||||
|
||||
if (!PARENT) {
|
||||
Debug::log(LOG, "Cannot change split ratio when parent NULL.");
|
||||
return;
|
||||
}
|
||||
|
||||
switch(dir) {
|
||||
case '+':
|
||||
PARENT->setSplitRatio(PARENT->getSplitRatio() + 0.05f);
|
||||
break;
|
||||
case '-':
|
||||
PARENT->setSplitRatio(PARENT->getSplitRatio() - 0.05f);
|
||||
break;
|
||||
default:
|
||||
Debug::log(ERR, "changeSplitRatioCurrent called with an invalid dir!");
|
||||
return;
|
||||
}
|
||||
|
||||
PARENT->setSplitRatio(std::clamp(PARENT->getSplitRatio(), 0.1f, 1.9f));
|
||||
|
||||
Debug::log(LOG, "Changed SplitRatio of " + std::to_string(PARENT->getDrawable()) + " to " + std::to_string(PARENT->getSplitRatio()) + " (" + dir + ")" );
|
||||
|
||||
recalcEntireWorkspace(CURRENT->getWorkspaceID());
|
||||
}
|
|
@ -144,6 +144,8 @@ public:
|
|||
|
||||
bool shouldBeManaged(const int&);
|
||||
|
||||
void changeSplitRatioCurrent(const char& dir);
|
||||
|
||||
private:
|
||||
|
||||
// Internal WM functions that don't have to be exposed
|
||||
|
|
Loading…
Reference in a new issue