mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-15 09:05:58 +01:00
internal: check size limit in layouts (#8298)
modified: src/desktop/Window.cpp modified: src/desktop/Window.hpp modified: src/events/Windows.cpp modified: src/helpers/MiscFunctions.cpp modified: src/helpers/MiscFunctions.hpp modified: src/layout/DwindleLayout.cpp modified: src/layout/IHyprLayout.cpp modified: src/layout/MasterLayout.cpp modified: src/macros.hpp
This commit is contained in:
parent
5f721dce36
commit
12c1bb936d
9 changed files with 44 additions and 34 deletions
|
@ -1255,7 +1255,7 @@ int CWindow::surfacesCount() {
|
||||||
|
|
||||||
void CWindow::clampWindowSize(const std::optional<Vector2D> minSize, const std::optional<Vector2D> maxSize) {
|
void CWindow::clampWindowSize(const std::optional<Vector2D> minSize, const std::optional<Vector2D> maxSize) {
|
||||||
const Vector2D REALSIZE = m_vRealSize.goal();
|
const Vector2D REALSIZE = m_vRealSize.goal();
|
||||||
const Vector2D NEWSIZE = REALSIZE.clamp(minSize.value_or(Vector2D{0.f, 0.f}), maxSize.value_or(Vector2D{INFINITY, INFINITY}));
|
const Vector2D NEWSIZE = REALSIZE.clamp(minSize.value_or(Vector2D{MIN_WINDOW_SIZE, MIN_WINDOW_SIZE}), maxSize.value_or(Vector2D{INFINITY, INFINITY}));
|
||||||
const Vector2D DELTA = REALSIZE - NEWSIZE;
|
const Vector2D DELTA = REALSIZE - NEWSIZE;
|
||||||
|
|
||||||
m_vRealPosition = m_vRealPosition.goal() + DELTA / 2.0;
|
m_vRealPosition = m_vRealPosition.goal() + DELTA / 2.0;
|
||||||
|
|
|
@ -144,6 +144,13 @@ class CWindowOverridableVar {
|
||||||
unset(priority);
|
unset(priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator std::optional<T>() {
|
||||||
|
if (hasValue())
|
||||||
|
return value();
|
||||||
|
else
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<eOverridePriority, T> values;
|
std::map<eOverridePriority, T> values;
|
||||||
T defaultValue; // used for toggling, so required for bool
|
T defaultValue; // used for toggling, so required for bool
|
||||||
|
|
|
@ -334,13 +334,6 @@ void Events::listener_mapWindow(void* owner, void* data) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
auto stringToFloatClamp = [](const std::string& VALUE, const float CURR, const float REL) {
|
auto stringToFloatClamp = [](const std::string& VALUE, const float CURR, const float REL) {
|
||||||
auto stringToPercentage = [](const std::string& VALUE, const float REL) {
|
|
||||||
if (VALUE.ends_with('%'))
|
|
||||||
return (std::stof(VALUE.substr(0, VALUE.length() - 1)) * REL) / 100;
|
|
||||||
else
|
|
||||||
return std::stof(VALUE);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (VALUE.starts_with('<'))
|
if (VALUE.starts_with('<'))
|
||||||
return std::min(CURR, stringToPercentage(VALUE.substr(1, VALUE.length() - 1), REL));
|
return std::min(CURR, stringToPercentage(VALUE.substr(1, VALUE.length() - 1), REL));
|
||||||
else if (VALUE.starts_with('>'))
|
else if (VALUE.starts_with('>'))
|
||||||
|
@ -355,11 +348,11 @@ void Events::listener_mapWindow(void* owner, void* data) {
|
||||||
|
|
||||||
const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(PWINDOW);
|
const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(PWINDOW);
|
||||||
|
|
||||||
const float SIZEX =
|
const float SIZEX = SIZEXSTR == "max" ? std::clamp(MAXSIZE.x, MIN_WINDOW_SIZE, PMONITOR->vecSize.x) :
|
||||||
SIZEXSTR == "max" ? std::clamp(MAXSIZE.x, 20.0, PMONITOR->vecSize.x) : stringToFloatClamp(SIZEXSTR, PWINDOW->m_vRealSize.goal().x, PMONITOR->vecSize.x);
|
stringToFloatClamp(SIZEXSTR, PWINDOW->m_vRealSize.goal().x, PMONITOR->vecSize.x);
|
||||||
|
|
||||||
const float SIZEY =
|
const float SIZEY = SIZEYSTR == "max" ? std::clamp(MAXSIZE.y, MIN_WINDOW_SIZE, PMONITOR->vecSize.y) :
|
||||||
SIZEYSTR == "max" ? std::clamp(MAXSIZE.y, 20.0, PMONITOR->vecSize.y) : stringToFloatClamp(SIZEYSTR, PWINDOW->m_vRealSize.goal().y, PMONITOR->vecSize.y);
|
stringToFloatClamp(SIZEYSTR, PWINDOW->m_vRealSize.goal().y, PMONITOR->vecSize.y);
|
||||||
|
|
||||||
Debug::log(LOG, "Rule size, applying to {}", PWINDOW);
|
Debug::log(LOG, "Rule size, applying to {}", PWINDOW);
|
||||||
|
|
||||||
|
@ -478,12 +471,9 @@ void Events::listener_mapWindow(void* owner, void* data) {
|
||||||
|
|
||||||
const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(PWINDOW);
|
const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(PWINDOW);
|
||||||
|
|
||||||
const auto SIZEX = SIZEXSTR == "max" ?
|
const float SIZEX = SIZEXSTR == "max" ? std::clamp(MAXSIZE.x, MIN_WINDOW_SIZE, PMONITOR->vecSize.x) : stringToPercentage(SIZEXSTR, PMONITOR->vecSize.x);
|
||||||
std::clamp(MAXSIZE.x, 20.0, PMONITOR->vecSize.x) :
|
|
||||||
(!SIZEXSTR.contains('%') ? std::stoi(SIZEXSTR) : std::stof(SIZEXSTR.substr(0, SIZEXSTR.length() - 1)) * 0.01 * PMONITOR->vecSize.x);
|
const float SIZEY = SIZEYSTR == "max" ? std::clamp(MAXSIZE.y, MIN_WINDOW_SIZE, PMONITOR->vecSize.y) : stringToPercentage(SIZEYSTR, PMONITOR->vecSize.y);
|
||||||
const auto SIZEY = SIZEYSTR == "max" ?
|
|
||||||
std::clamp(MAXSIZE.y, 20.0, PMONITOR->vecSize.y) :
|
|
||||||
(!SIZEYSTR.contains('%') ? std::stoi(SIZEYSTR) : std::stof(SIZEYSTR.substr(0, SIZEYSTR.length() - 1)) * 0.01 * PMONITOR->vecSize.y);
|
|
||||||
|
|
||||||
Debug::log(LOG, "Rule size (tiled), applying to {}", PWINDOW);
|
Debug::log(LOG, "Rule size (tiled), applying to {}", PWINDOW);
|
||||||
|
|
||||||
|
|
|
@ -863,3 +863,10 @@ bool allocateSHMFilePair(size_t size, int* rw_fd_ptr, int* ro_fd_ptr) {
|
||||||
*ro_fd_ptr = ro_fd;
|
*ro_fd_ptr = ro_fd;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float stringToPercentage(const std::string& VALUE, const float REL) {
|
||||||
|
if (VALUE.ends_with('%'))
|
||||||
|
return (std::stof(VALUE.substr(0, VALUE.length() - 1)) * REL) / 100.f;
|
||||||
|
else
|
||||||
|
return std::stof(VALUE);
|
||||||
|
};
|
||||||
|
|
|
@ -40,6 +40,7 @@ void throwError(const std::string& err);
|
||||||
bool envEnabled(const std::string& env);
|
bool envEnabled(const std::string& env);
|
||||||
int allocateSHMFile(size_t len);
|
int allocateSHMFile(size_t len);
|
||||||
bool allocateSHMFilePair(size_t size, int* rw_fd_ptr, int* ro_fd_ptr);
|
bool allocateSHMFilePair(size_t size, int* rw_fd_ptr, int* ro_fd_ptr);
|
||||||
|
float stringToPercentage(const std::string& VALUE, const float REL);
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
[[deprecated("use std::format instead")]] std::string getFormat(std::format_string<Args...> fmt, Args&&... args) {
|
[[deprecated("use std::format instead")]] std::string getFormat(std::format_string<Args...> fmt, Args&&... args) {
|
||||||
|
|
|
@ -568,7 +568,9 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn
|
||||||
const auto PNODE = getNodeFromWindow(PWINDOW);
|
const auto PNODE = getNodeFromWindow(PWINDOW);
|
||||||
|
|
||||||
if (!PNODE) {
|
if (!PNODE) {
|
||||||
PWINDOW->m_vRealSize = Vector2D(std::max((PWINDOW->m_vRealSize.goal() + pixResize).x, 20.0), std::max((PWINDOW->m_vRealSize.goal() + pixResize).y, 20.0));
|
PWINDOW->m_vRealSize =
|
||||||
|
(PWINDOW->m_vRealSize.goal() + pixResize)
|
||||||
|
.clamp(PWINDOW->m_sWindowData.minSize.valueOr(Vector2D{MIN_WINDOW_SIZE, MIN_WINDOW_SIZE}), PWINDOW->m_sWindowData.maxSize.valueOr(Vector2D{INFINITY, INFINITY}));
|
||||||
PWINDOW->updateWindowDecos();
|
PWINDOW->updateWindowDecos();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -887,12 +887,11 @@ Vector2D IHyprLayout::predictSizeForNewWindowFloating(PHLWINDOW pWindow) { // ge
|
||||||
|
|
||||||
const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow);
|
const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow);
|
||||||
|
|
||||||
const auto SIZEX = SIZEXSTR == "max" ?
|
const float SIZEX = SIZEXSTR == "max" ? std::clamp(MAXSIZE.x, MIN_WINDOW_SIZE, g_pCompositor->m_pLastMonitor->vecSize.x) :
|
||||||
std::clamp(MAXSIZE.x, 20.0, g_pCompositor->m_pLastMonitor->vecSize.x) :
|
stringToPercentage(SIZEXSTR, g_pCompositor->m_pLastMonitor->vecSize.x);
|
||||||
(!SIZEXSTR.contains('%') ? std::stoi(SIZEXSTR) : std::stof(SIZEXSTR.substr(0, SIZEXSTR.length() - 1)) * 0.01 * g_pCompositor->m_pLastMonitor->vecSize.x);
|
|
||||||
const auto SIZEY = SIZEYSTR == "max" ?
|
const float SIZEY = SIZEYSTR == "max" ? std::clamp(MAXSIZE.y, MIN_WINDOW_SIZE, g_pCompositor->m_pLastMonitor->vecSize.y) :
|
||||||
std::clamp(MAXSIZE.y, 20.0, g_pCompositor->m_pLastMonitor->vecSize.y) :
|
stringToPercentage(SIZEYSTR, g_pCompositor->m_pLastMonitor->vecSize.y);
|
||||||
(!SIZEYSTR.contains('%') ? std::stoi(SIZEYSTR) : std::stof(SIZEYSTR.substr(0, SIZEYSTR.length() - 1)) * 0.01 * g_pCompositor->m_pLastMonitor->vecSize.y);
|
|
||||||
|
|
||||||
sizeOverride = {SIZEX, SIZEY};
|
sizeOverride = {SIZEX, SIZEY};
|
||||||
|
|
||||||
|
|
|
@ -706,7 +706,9 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne
|
||||||
const auto PNODE = getNodeFromWindow(PWINDOW);
|
const auto PNODE = getNodeFromWindow(PWINDOW);
|
||||||
|
|
||||||
if (!PNODE) {
|
if (!PNODE) {
|
||||||
PWINDOW->m_vRealSize = Vector2D(std::max((PWINDOW->m_vRealSize.goal() + pixResize).x, 20.0), std::max((PWINDOW->m_vRealSize.goal() + pixResize).y, 20.0));
|
PWINDOW->m_vRealSize =
|
||||||
|
(PWINDOW->m_vRealSize.goal() + pixResize)
|
||||||
|
.clamp(PWINDOW->m_sWindowData.minSize.valueOr(Vector2D{MIN_WINDOW_SIZE, MIN_WINDOW_SIZE}), PWINDOW->m_sWindowData.maxSize.valueOr(Vector2D{INFINITY, INFINITY}));
|
||||||
PWINDOW->updateWindowDecos();
|
PWINDOW->updateWindowDecos();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
|
|
||||||
#define MONITOR_INVALID -1L
|
#define MONITOR_INVALID -1L
|
||||||
|
|
||||||
|
#define MIN_WINDOW_SIZE 20.0
|
||||||
|
|
||||||
#define LISTENER(name) \
|
#define LISTENER(name) \
|
||||||
void listener_##name(wl_listener*, void*); \
|
void listener_##name(wl_listener*, void*); \
|
||||||
inline wl_listener listen_##name = {.notify = listener_##name}
|
inline wl_listener listen_##name = {.notify = listener_##name}
|
||||||
|
|
Loading…
Reference in a new issue