From c8afd993d9004fa5bbd43e3760cd888c73771dc3 Mon Sep 17 00:00:00 2001 From: Kristen McWilliam Date: Fri, 10 Sep 2021 13:08:24 -0400 Subject: [PATCH 1/2] Add hotkey option to move active window to center Adds a non-default hotkey alllowing the user to move the active window to screen center with only the keyboard. --- src/placement.cpp | 17 +++++++++++++++++ src/useractions.cpp | 2 ++ src/workspace.h | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/src/placement.cpp b/src/placement.cpp index e8009be317..eeec843233 100644 --- a/src/placement.cpp +++ b/src/placement.cpp @@ -719,6 +719,23 @@ void Workspace::slotWindowPackDown() } } +/** Returns the center point of the space available to the active window. */ +QPoint Workspace::clientMaximizeAreaCenter() +{ + return clientArea(MaximizeArea, active_client).center(); +} + +/** Moves the active window to the center of the screen. */ +void Workspace::slotWindowCenter() +{ + if (active_client && active_client->isMovable()) { + const QRect geometry = active_client->moveResizeGeometry(); + QPoint center = clientMaximizeAreaCenter(); + active_client->packTo(center.x() - (geometry.width() / 2), + center.y() - (geometry.height() / 2)); + } +} + void Workspace::slotWindowGrowHorizontal() { if (active_client) diff --git a/src/useractions.cpp b/src/useractions.cpp index 9044289974..4e611738b4 100644 --- a/src/useractions.cpp +++ b/src/useractions.cpp @@ -1007,6 +1007,8 @@ void Workspace::initShortcuts() Qt::CTRL + Qt::ALT + Qt::Key_A, slotActivateAttentionWindow); DEF(I18N_NOOP("Setup Window Shortcut"), 0, slotSetupWindowShortcut); + DEF2("Window Move Center", I18N_NOOP("Move Window to the Center"), 0, + slotWindowCenter); DEF2("Window Pack Right", I18N_NOOP("Pack Window to the Right"), 0, slotWindowPackRight); DEF2("Window Pack Left", I18N_NOOP("Pack Window to the Left"), diff --git a/src/workspace.h b/src/workspace.h index 0e41986536..de736a20dd 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -441,6 +441,10 @@ public Q_SLOTS: void slotWindowLower(); void slotWindowRaiseOrLower(); void slotActivateAttentionWindow(); + + QPoint clientMaximizeAreaCenter(); + void slotWindowCenter(); + void slotWindowPackLeft(); void slotWindowPackRight(); void slotWindowPackUp(); -- GitLab From 8b4a6060ed39f1bf5100c64bed341c2c230da141 Mon Sep 17 00:00:00 2001 From: Kristen McWilliam Date: Mon, 13 Sep 2021 09:27:14 -0400 Subject: [PATCH 2/2] Inline clientMaximizeAreaCenter() Better follow reuseability conventions --- src/placement.cpp | 8 +------- src/workspace.h | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/placement.cpp b/src/placement.cpp index eeec843233..0e40238bcd 100644 --- a/src/placement.cpp +++ b/src/placement.cpp @@ -719,18 +719,12 @@ void Workspace::slotWindowPackDown() } } -/** Returns the center point of the space available to the active window. */ -QPoint Workspace::clientMaximizeAreaCenter() -{ - return clientArea(MaximizeArea, active_client).center(); -} - /** Moves the active window to the center of the screen. */ void Workspace::slotWindowCenter() { if (active_client && active_client->isMovable()) { const QRect geometry = active_client->moveResizeGeometry(); - QPoint center = clientMaximizeAreaCenter(); + QPoint center = clientArea(MaximizeArea, active_client).center(); active_client->packTo(center.x() - (geometry.width() / 2), center.y() - (geometry.height() / 2)); } diff --git a/src/workspace.h b/src/workspace.h index de736a20dd..8e4bf6d6a2 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -442,7 +442,6 @@ public Q_SLOTS: void slotWindowRaiseOrLower(); void slotActivateAttentionWindow(); - QPoint clientMaximizeAreaCenter(); void slotWindowCenter(); void slotWindowPackLeft(); -- GitLab