From 5fdf1da80892d291d20d5a797189c7c06ae7c482 Mon Sep 17 00:00:00 2001 From: Kristen McWilliam Date: Mon, 20 Sep 2021 13:14:24 +0000 Subject: [PATCH] Add hotkey option to move active window to center --- src/placement.cpp | 11 +++++++++++ src/useractions.cpp | 2 ++ src/workspace.h | 3 +++ 3 files changed, 16 insertions(+) diff --git a/src/placement.cpp b/src/placement.cpp index e8009be317..0e40238bcd 100644 --- a/src/placement.cpp +++ b/src/placement.cpp @@ -719,6 +719,17 @@ void Workspace::slotWindowPackDown() } } +/** 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 = clientArea(MaximizeArea, active_client).center(); + 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..8e4bf6d6a2 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -441,6 +441,9 @@ public Q_SLOTS: void slotWindowLower(); void slotWindowRaiseOrLower(); void slotActivateAttentionWindow(); + + void slotWindowCenter(); + void slotWindowPackLeft(); void slotWindowPackRight(); void slotWindowPackUp();