keybinds: Keep aspect ratio (#2907)

This commit is contained in:
MightyPlaza 2023-08-08 16:52:20 +00:00 committed by GitHub
parent b68292340c
commit 6295cbe9cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 39 deletions

View file

@ -532,6 +532,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
} catch (std::exception& e) { Debug::log(ERR, "BorderColor rule \"%s\" failed with: %s", r.szRule.c_str(), e.what()); } } catch (std::exception& e) { Debug::log(ERR, "BorderColor rule \"%s\" failed with: %s", r.szRule.c_str(), e.what()); }
} else if (r.szRule == "dimaround") { } else if (r.szRule == "dimaround") {
m_sAdditionalConfigData.dimAround = true; m_sAdditionalConfigData.dimAround = true;
} else if (r.szRule == "keepaspectratio") {
m_sAdditionalConfigData.keepAspectRatio = true;
} }
} }
@ -552,6 +554,7 @@ void CWindow::updateDynamicRules() {
m_sAdditionalConfigData.dimAround = false; m_sAdditionalConfigData.dimAround = false;
m_sAdditionalConfigData.forceRGBX = false; m_sAdditionalConfigData.forceRGBX = false;
m_sAdditionalConfigData.borderSize = -1; m_sAdditionalConfigData.borderSize = -1;
m_sAdditionalConfigData.keepAspectRatio = false;
const auto WINDOWRULES = g_pConfigManager->getMatchingRules(this); const auto WINDOWRULES = g_pConfigManager->getMatchingRules(this);
for (auto& r : WINDOWRULES) { for (auto& r : WINDOWRULES) {

View file

@ -10,8 +10,7 @@
#include "helpers/Vector2D.hpp" #include "helpers/Vector2D.hpp"
#include "helpers/WLSurface.hpp" #include "helpers/WLSurface.hpp"
enum eIdleInhibitMode enum eIdleInhibitMode {
{
IDLEINHIBIT_NONE = 0, IDLEINHIBIT_NONE = 0,
IDLEINHIBIT_ALWAYS, IDLEINHIBIT_ALWAYS,
IDLEINHIBIT_FULLSCREEN, IDLEINHIBIT_FULLSCREEN,
@ -122,6 +121,7 @@ struct SWindowAdditionalConfigData {
CWindowOverridableVar<bool> noMaxSize = false; CWindowOverridableVar<bool> noMaxSize = false;
CWindowOverridableVar<bool> dimAround = false; CWindowOverridableVar<bool> dimAround = false;
CWindowOverridableVar<bool> forceRGBX = false; CWindowOverridableVar<bool> forceRGBX = false;
CWindowOverridableVar<bool> keepAspectRatio = false;
CWindowOverridableVar<int> borderSize = -1; // -1 means unset, takes precedence over the renderdata one CWindowOverridableVar<int> borderSize = -1; // -1 means unset, takes precedence over the renderdata one
}; };

View file

@ -887,8 +887,9 @@ bool windowRuleValid(const std::string& RULE) {
RULE.find("maxsize") != 0 && RULE.find("pseudo") != 0 && RULE.find("monitor") != 0 && RULE.find("idleinhibit") != 0 && RULE != "nofocus" && RULE != "noblur" && RULE.find("maxsize") != 0 && RULE.find("pseudo") != 0 && RULE.find("monitor") != 0 && RULE.find("idleinhibit") != 0 && RULE != "nofocus" && RULE != "noblur" &&
RULE != "noshadow" && RULE != "nodim" && RULE != "noborder" && RULE != "center" && RULE != "opaque" && RULE != "forceinput" && RULE != "fullscreen" && RULE != "noshadow" && RULE != "nodim" && RULE != "noborder" && RULE != "center" && RULE != "opaque" && RULE != "forceinput" && RULE != "fullscreen" &&
RULE != "nofullscreenrequest" && RULE != "nomaximizerequest" && RULE != "fakefullscreen" && RULE != "nomaxsize" && RULE != "pin" && RULE != "noanim" && RULE != "nofullscreenrequest" && RULE != "nomaximizerequest" && RULE != "fakefullscreen" && RULE != "nomaxsize" && RULE != "pin" && RULE != "noanim" &&
RULE != "dimaround" && RULE != "windowdance" && RULE != "maximize" && RULE.find("animation") != 0 && RULE.find("rounding") != 0 && RULE.find("workspace") != 0 && RULE != "dimaround" && RULE != "windowdance" && RULE != "maximize" && RULE != "keepaspectratio" && RULE.find("animation") != 0 && RULE.find("rounding") != 0 &&
RULE.find("bordercolor") != 0 && RULE != "forcergbx" && RULE != "noinitialfocus" && RULE != "stayfocused" && RULE.find("bordersize") != 0); RULE.find("workspace") != 0 && RULE.find("bordercolor") != 0 && RULE != "forcergbx" && RULE != "noinitialfocus" && RULE != "stayfocused" &&
RULE.find("bordersize") != 0);
} }
bool layerRuleValid(const std::string& RULE) { bool layerRuleValid(const std::string& RULE) {

View file

@ -1002,6 +1002,8 @@ std::string dispatchSetProp(std::string request) {
PWINDOW->m_sAdditionalConfigData.forceRGBX.forceSetIgnoreLocked(configStringToInt(VAL), lock); PWINDOW->m_sAdditionalConfigData.forceRGBX.forceSetIgnoreLocked(configStringToInt(VAL), lock);
} else if (PROP == "bordersize") { } else if (PROP == "bordersize") {
PWINDOW->m_sSpecialRenderData.borderSize.forceSetIgnoreLocked(configStringToInt(VAL), lock); PWINDOW->m_sSpecialRenderData.borderSize.forceSetIgnoreLocked(configStringToInt(VAL), lock);
} else if (PROP == "keepaspectratio") {
PWINDOW->m_sAdditionalConfigData.keepAspectRatio.forceSetIgnoreLocked(configStringToInt(VAL), lock);
} else { } else {
return "prop not found"; return "prop not found";
} }

View file

@ -235,7 +235,7 @@ void IHyprLayout::onBeginDragWindow() {
} }
} }
if (g_pInputManager->dragMode != MBIND_RESIZE) if (g_pInputManager->dragMode != MBIND_RESIZE && g_pInputManager->dragMode != MBIND_RESIZE_FORCE_RATIO && g_pInputManager->dragMode != MBIND_RESIZE_BLOCK_RATIO)
g_pInputManager->setCursorImageUntilUnset("grab"); g_pInputManager->setCursorImageUntilUnset("grab");
g_pHyprRenderer->damageWindow(DRAGGINGWINDOW); g_pHyprRenderer->damageWindow(DRAGGINGWINDOW);
@ -314,29 +314,55 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
} }
g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goalv()); g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goalv());
} else if (g_pInputManager->dragMode == MBIND_RESIZE) { } else if (g_pInputManager->dragMode == MBIND_RESIZE || g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO || g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) {
if (DRAGGINGWINDOW->m_bIsFloating) { if (DRAGGINGWINDOW->m_bIsFloating) {
const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(DRAGGINGWINDOW); Vector2D MINSIZE = Vector2D(20, 20);
Vector2D MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(DRAGGINGWINDOW);
// calc the new size and pos
Vector2D newSize = m_vBeginDragSizeXY; Vector2D newSize = m_vBeginDragSizeXY;
Vector2D newPos = m_vBeginDragPositionXY; Vector2D newPos = m_vBeginDragPositionXY;
if (m_eGrabbedCorner == CORNER_BOTTOMRIGHT) { if (m_eGrabbedCorner == CORNER_BOTTOMRIGHT)
newSize = (newSize + DELTA).clamp(Vector2D(20, 20), MAXSIZE); newSize = newSize + DELTA;
} else if (m_eGrabbedCorner == CORNER_TOPLEFT) { else if (m_eGrabbedCorner == CORNER_TOPLEFT)
newSize = (newSize - DELTA).clamp(Vector2D(20, 20), MAXSIZE); newSize = newSize - DELTA;
newPos = newPos - newSize + m_vBeginDragSizeXY; else if (m_eGrabbedCorner == CORNER_TOPRIGHT)
} else if (m_eGrabbedCorner == CORNER_TOPRIGHT) { newSize = newSize + Vector2D(DELTA.x, -DELTA.y);
newSize = (newSize + Vector2D(DELTA.x, -DELTA.y)).clamp(Vector2D(20, 20), MAXSIZE); else if (m_eGrabbedCorner == CORNER_BOTTOMLEFT)
newPos = newPos + Vector2D(0, (m_vBeginDragSizeXY - newSize).y); newSize = newSize + Vector2D(-DELTA.x, DELTA.y);
} else if (m_eGrabbedCorner == CORNER_BOTTOMLEFT) {
newSize = (newSize + Vector2D(-DELTA.x, DELTA.y)).clamp(Vector2D(20, 20), MAXSIZE); if ((m_vBeginDragSizeXY.x >= 1 && m_vBeginDragSizeXY.y >= 1) &&
newPos = newPos + Vector2D((m_vBeginDragSizeXY - newSize).x, 0); (g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO ||
(!(g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) && DRAGGINGWINDOW->m_sAdditionalConfigData.keepAspectRatio))) {
const float RATIO = m_vBeginDragSizeXY.y / m_vBeginDragSizeXY.x;
if (MINSIZE.x * RATIO > MINSIZE.y)
MINSIZE = Vector2D(MINSIZE.x, MINSIZE.x * RATIO);
else
MINSIZE = Vector2D(MINSIZE.y / RATIO, MINSIZE.y);
if (MAXSIZE.x * RATIO < MAXSIZE.y)
MAXSIZE = Vector2D(MAXSIZE.x, MAXSIZE.x * RATIO);
else
MAXSIZE = Vector2D(MAXSIZE.y / RATIO, MAXSIZE.y);
if (newSize.x * RATIO > newSize.y)
newSize = Vector2D(newSize.x, newSize.x * RATIO);
else
newSize = Vector2D(newSize.y / RATIO, newSize.y);
} }
newSize = newSize.clamp(MINSIZE, MAXSIZE);
if (m_eGrabbedCorner == CORNER_TOPLEFT)
newPos = newPos - newSize + m_vBeginDragSizeXY;
else if (m_eGrabbedCorner == CORNER_TOPRIGHT)
newPos = newPos + Vector2D(0, (m_vBeginDragSizeXY - newSize).y);
else if (m_eGrabbedCorner == CORNER_BOTTOMLEFT)
newPos = newPos + Vector2D((m_vBeginDragSizeXY - newSize).x, 0);
if (*PANIMATE) { if (*PANIMATE) {
DRAGGINGWINDOW->m_vRealSize = newSize; DRAGGINGWINDOW->m_vRealSize = newSize;
DRAGGINGWINDOW->m_vRealPosition = newPos; DRAGGINGWINDOW->m_vRealPosition = newPos;

View file

@ -1942,10 +1942,10 @@ void CKeybindManager::pinActive(std::string args) {
} }
void CKeybindManager::mouse(std::string args) { void CKeybindManager::mouse(std::string args) {
const auto TRUEARG = args.substr(1); const auto ARGS = CVarList(args.substr(1), 2, ' ');
const auto PRESSED = args[0] == '1'; const auto PRESSED = args[0] == '1';
if (TRUEARG == "movewindow") { if (ARGS[0] == "movewindow") {
if (PRESSED) { if (PRESSED) {
g_pKeybindManager->m_bIsMouseBindActive = true; g_pKeybindManager->m_bIsMouseBindActive = true;
@ -1962,13 +1962,19 @@ void CKeybindManager::mouse(std::string args) {
g_pInputManager->dragMode = MBIND_INVALID; g_pInputManager->dragMode = MBIND_INVALID;
} }
} }
} else if (TRUEARG == "resizewindow") { } else if (ARGS[0] == "resizewindow") {
if (PRESSED) { if (PRESSED) {
g_pKeybindManager->m_bIsMouseBindActive = true; g_pKeybindManager->m_bIsMouseBindActive = true;
g_pInputManager->currentlyDraggedWindow = g_pCompositor->vectorToWindowIdeal(g_pInputManager->getMouseCoordsInternal()); g_pInputManager->currentlyDraggedWindow = g_pCompositor->vectorToWindowIdeal(g_pInputManager->getMouseCoordsInternal());
g_pInputManager->dragMode = MBIND_RESIZE;
try {
switch (std::stoi(ARGS[1])) {
case 1: g_pInputManager->dragMode = MBIND_RESIZE_FORCE_RATIO; break;
case 2: g_pInputManager->dragMode = MBIND_RESIZE_BLOCK_RATIO; break;
default: g_pInputManager->dragMode = MBIND_RESIZE;
}
} catch (std::exception& e) { g_pInputManager->dragMode = MBIND_RESIZE; }
g_pLayoutManager->getCurrentLayout()->onBeginDragWindow(); g_pLayoutManager->getCurrentLayout()->onBeginDragWindow();
} else { } else {
g_pKeybindManager->m_bIsMouseBindActive = false; g_pKeybindManager->m_bIsMouseBindActive = false;

View file

@ -7,21 +7,20 @@
#include "../../helpers/Timer.hpp" #include "../../helpers/Timer.hpp"
#include "InputMethodRelay.hpp" #include "InputMethodRelay.hpp"
enum eClickBehaviorMode enum eClickBehaviorMode {
{
CLICKMODE_DEFAULT = 0, CLICKMODE_DEFAULT = 0,
CLICKMODE_KILL CLICKMODE_KILL
}; };
enum eMouseBindMode enum eMouseBindMode {
{
MBIND_INVALID = -1, MBIND_INVALID = -1,
MBIND_MOVE = 0, MBIND_MOVE = 0,
MBIND_RESIZE MBIND_RESIZE = 1,
MBIND_RESIZE_BLOCK_RATIO = 2,
MBIND_RESIZE_FORCE_RATIO = 3
}; };
enum eBorderIconDirection enum eBorderIconDirection {
{
BORDERICON_NONE, BORDERICON_NONE,
BORDERICON_UP, BORDERICON_UP,
BORDERICON_DOWN, BORDERICON_DOWN,