Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add on-screen constraint to wrv2 'move' #3247

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ void Events::listener_mapWindow(void* owner, void* data) {
try {
auto value = r.szRule.substr(r.szRule.find(' ') + 1);

const bool ONSCREEN = value.find("onscreen") == 0;

if (ONSCREEN)
value = value.substr(value.find_first_of(' ') + 1);

const bool CURSOR = value.find("cursor") == 0;

if (CURSOR)
Expand All @@ -334,8 +339,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
int posY = 0;

if (POSXSTR.find("100%-") == 0) {
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
const auto POSXRAW = POSXSTR.substr(5);
const auto POSXRAW = POSXSTR.substr(5);
posX =
PMONITOR->vecSize.x - (!POSXRAW.contains('%') ? std::stoi(POSXRAW) : std::stof(POSXRAW.substr(0, POSXRAW.length() - 1)) * 0.01 * PMONITOR->vecSize.x);

Expand All @@ -354,8 +358,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
}

if (POSYSTR.find("100%-") == 0) {
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
const auto POSYRAW = POSYSTR.substr(5);
const auto POSYRAW = POSYSTR.substr(5);
posY =
PMONITOR->vecSize.y - (!POSYRAW.contains('%') ? std::stoi(POSYRAW) : std::stof(POSYRAW.substr(0, POSYRAW.length() - 1)) * 0.01 * PMONITOR->vecSize.y);

Expand All @@ -373,6 +376,16 @@ void Events::listener_mapWindow(void* owner, void* data) {
}
}

if (ONSCREEN) {
int borderSize = PWINDOW->getRealBorderSize();

posX = std::clamp(posX, (int)(PMONITOR->vecReservedTopLeft.x + borderSize),
(int)(PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize));

posY = std::clamp(posY, (int)(PMONITOR->vecReservedTopLeft.y + borderSize),
(int)(PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize));
}

Debug::log(LOG, "Rule move, applying to window {:x}", (uintptr_t)PWINDOW);

PWINDOW->m_vRealPosition = Vector2D(posX, posY) + PMONITOR->vecPosition;
Expand Down
Loading