Dispatcher to center floating window (#961)

Co-authored-by: Adam Nord <adam.nord@abbgymnasiet.se>
Co-authored-by: vaxerski <vaxry@vaxry.net>
This commit is contained in:
abbadanor 2022-11-07 13:16:30 +01:00 committed by GitHub
parent efbc3f8194
commit 1a55fb4170
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -16,6 +16,7 @@ CKeybindManager::CKeybindManager() {
m_mDispatchers["pseudo"] = toggleActivePseudo;
m_mDispatchers["movefocus"] = moveFocusTo;
m_mDispatchers["movewindow"] = moveActiveTo;
m_mDispatchers["centerwindow"] = centerWindow;
m_mDispatchers["togglegroup"] = toggleGroup;
m_mDispatchers["changegroupactive"] = changeGroupActive;
m_mDispatchers["togglesplit"] = toggleSplit;
@ -579,6 +580,18 @@ void CKeybindManager::toggleActiveFloating(std::string args) {
g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PWINDOW);
}
void CKeybindManager::centerWindow(std::string args) {
const auto PWINDOW = g_pCompositor->m_pLastWindow;
if (!PWINDOW || !PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen)
return;
const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID);
PWINDOW->m_vRealPosition = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f - PWINDOW->m_vRealSize.goalv() / 2.f;
PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goalv();
}
void CKeybindManager::toggleActivePseudo(std::string args) {
const auto ACTIVEWINDOW = g_pCompositor->m_pLastWindow;
@ -617,7 +630,7 @@ void CKeybindManager::changeworkspace(std::string args) {
return;
} else {
workspaceToChangeTo = PCURRENTWORKSPACE->m_iPrevWorkspaceID;
if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo); PWORKSPACETOCHANGETO)
workspaceName = PWORKSPACETOCHANGETO->m_szName;
else
@ -650,7 +663,7 @@ void CKeybindManager::changeworkspace(std::string args) {
const auto PPREVWORKSPACE = g_pCompositor->getWorkspaceByID(PCURRENTWORKSPACE->m_iPrevWorkspaceID);
workspaceToChangeTo = PCURRENTWORKSPACE->m_iPrevWorkspaceID;
if (PPREVWORKSPACE)
workspaceName = PPREVWORKSPACE->m_szName;
else

View file

@ -92,6 +92,7 @@ private:
static void moveActiveToWorkspace(std::string);
static void moveActiveToWorkspaceSilent(std::string);
static void moveFocusTo(std::string);
static void centerWindow(std::string);
static void moveActiveTo(std::string);
static void toggleGroup(std::string);
static void changeGroupActive(std::string);