handle on decorations

modified:   src/layout/DwindleLayout.cpp
modified:   src/layout/MasterLayout.cpp
modified:   src/managers/KeybindManager.cpp
modified:   src/managers/input/InputManager.cpp
modified:   src/render/decorations/CHyprGroupBarDecoration.cpp
modified:   src/render/decorations/CHyprGroupBarDecoration.hpp
modified:   src/render/decorations/IHyprWindowDecoration.cpp
modified:   src/render/decorations/IHyprWindowDecoration.hpp

modified:   src/layout/DwindleLayout.cpp
modified:   src/layout/MasterLayout.cpp
modified:   src/managers/KeybindManager.cpp
modified:   src/managers/input/InputManager.cpp
modified:   src/render/decorations/CHyprGroupBarDecoration.cpp
modified:   src/render/decorations/CHyprGroupBarDecoration.hpp
modified:   src/render/decorations/IHyprWindowDecoration.cpp
modified:   src/render/decorations/IHyprWindowDecoration.hpp
Signed-off-by: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com>
This commit is contained in:
MightyPlaza 2023-09-14 23:41:20 +01:00
parent 59b436445e
commit ce3a5e5bb5
No known key found for this signature in database
GPG key ID: 284C27FD27A6DC0D
8 changed files with 142 additions and 54 deletions

View file

@ -149,7 +149,8 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
PWINDOW->m_sSpecialRenderData.shadow = false; PWINDOW->m_sSpecialRenderData.shadow = false;
PWINDOW->m_vRealPosition = PWINDOW->m_vPosition + PWINDOW->m_seReservedInternal.topLeft + PWINDOW->m_seReservedExternal.topLeft; PWINDOW->m_vRealPosition = PWINDOW->m_vPosition + PWINDOW->m_seReservedInternal.topLeft + PWINDOW->m_seReservedExternal.topLeft;
PWINDOW->m_vRealSize = PWINDOW->m_vSize - (PWINDOW->m_seReservedInternal.topLeft + PWINDOW->m_seReservedInternal.bottomRight) - (PWINDOW->m_seReservedExternal.topLeft + PWINDOW->m_seReservedExternal.bottomRight); PWINDOW->m_vRealSize = PWINDOW->m_vSize - (PWINDOW->m_seReservedInternal.topLeft + PWINDOW->m_seReservedInternal.bottomRight) -
(PWINDOW->m_seReservedExternal.topLeft + PWINDOW->m_seReservedExternal.bottomRight);
PWINDOW->updateWindowDecos(); PWINDOW->updateWindowDecos();
@ -322,16 +323,21 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire
m_lDwindleNodesData.remove(*PNODE); m_lDwindleNodesData.remove(*PNODE);
const wlr_box box = OPENINGON->pWindow->getDecorationByType(DECORATION_GROUPBAR)->getWindowDecorationRegion().getExtents(); bool handled = true;
if (wlr_box_contains_point(&box, MOUSECOORDS.x, MOUSECOORDS.y)) { // TODO: Deny when not using mouse
const int SIZE = OPENINGON->pWindow->getGroupSize(); for (auto& wd : OPENINGON->pWindow->m_dWindowDecorations) {
const int INDEX = (int)((MOUSECOORDS.x - box.x) * 2 * SIZE / box.width + 1) / 2 - 1; if (!wd->allowsInput())
CWindow* pWindowInsertAfter = OPENINGON->pWindow->getGroupWindowByIndex(INDEX); continue;
pWindowInsertAfter->insertWindowToGroup(pWindow);
if (INDEX == -1) if (wd->getWindowDecorationRegion().containsPoint(MOUSECOORDS)) {
std::swap(pWindow->m_sGroupData.pNextWindow->m_sGroupData.head, pWindow->m_sGroupData.head); wd->dragWindowToDecoration(pWindow, MOUSECOORDS);
} else { handled = false;
static const auto* USECURRPOS = &g_pConfigManager->getConfigValuePtr("misc:group_insert_after_current")->intValue; break;
}
}
if (handled) {
static const auto* USECURRPOS = &g_pConfigManager->getConfigValuePtr("group:insert_after_current")->intValue;
(*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); (*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow);
} }
@ -340,6 +346,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire
pWindow->updateWindowDecos(); pWindow->updateWindowDecos();
recalculateWindow(pWindow); recalculateWindow(pWindow);
g_pCompositor->focusWindow(pWindow);
return; return;
} }

View file

@ -109,16 +109,21 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc
m_lMasterNodesData.remove(*PNODE); m_lMasterNodesData.remove(*PNODE);
const wlr_box box = OPENINGON->pWindow->getDecorationByType(DECORATION_GROUPBAR)->getWindowDecorationRegion().getExtents(); bool handled = true;
if (wlr_box_contains_point(&box, MOUSECOORDS.x, MOUSECOORDS.y)) { // TODO: Deny when not using mouse
const int SIZE = OPENINGON->pWindow->getGroupSize(); for (auto& wd : OPENINGON->pWindow->m_dWindowDecorations) {
const int INDEX = (int)((MOUSECOORDS.x - box.x) * 2 * SIZE / box.width + 1) / 2 - 1; if (!wd->allowsInput())
CWindow* pWindowInsertAfter = OPENINGON->pWindow->getGroupWindowByIndex(INDEX); continue;
pWindowInsertAfter->insertWindowToGroup(pWindow);
if (INDEX == -1) if (wd->getWindowDecorationRegion().containsPoint(MOUSECOORDS)) {
std::swap(pWindow->m_sGroupData.pNextWindow->m_sGroupData.head, pWindow->m_sGroupData.head); wd->dragWindowToDecoration(pWindow, MOUSECOORDS);
} else { handled = false;
static const auto* USECURRPOS = &g_pConfigManager->getConfigValuePtr("misc:group_insert_after_current")->intValue; break;
}
}
if (handled) {
static const auto* USECURRPOS = &g_pConfigManager->getConfigValuePtr("group:insert_after_current")->intValue;
(*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); (*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow);
} }
@ -127,6 +132,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc
pWindow->updateWindowDecos(); pWindow->updateWindowDecos();
recalculateWindow(pWindow); recalculateWindow(pWindow);
g_pCompositor->focusWindow(pWindow);
return; return;
} }
@ -625,7 +631,8 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) {
PWINDOW->m_sSpecialRenderData.shadow = false; PWINDOW->m_sSpecialRenderData.shadow = false;
PWINDOW->m_vRealPosition = PWINDOW->m_vPosition + PWINDOW->m_seReservedInternal.topLeft + PWINDOW->m_seReservedExternal.topLeft; PWINDOW->m_vRealPosition = PWINDOW->m_vPosition + PWINDOW->m_seReservedInternal.topLeft + PWINDOW->m_seReservedExternal.topLeft;
PWINDOW->m_vRealSize = PWINDOW->m_vSize - (PWINDOW->m_seReservedInternal.topLeft + PWINDOW->m_seReservedInternal.bottomRight) - (PWINDOW->m_seReservedExternal.topLeft + PWINDOW->m_seReservedExternal.bottomRight); PWINDOW->m_vRealSize = PWINDOW->m_vSize - (PWINDOW->m_seReservedInternal.topLeft + PWINDOW->m_seReservedInternal.bottomRight) -
(PWINDOW->m_seReservedExternal.topLeft + PWINDOW->m_seReservedExternal.bottomRight);
PWINDOW->updateWindowDecos(); PWINDOW->updateWindowDecos();

View file

@ -1831,24 +1831,21 @@ void CKeybindManager::mouse(std::string args) {
const auto mouseCoords = g_pInputManager->getMouseCoordsInternal(); const auto mouseCoords = g_pInputManager->getMouseCoordsInternal();
CWindow* pWindow = g_pCompositor->vectorToWindowIdeal(mouseCoords); CWindow* pWindow = g_pCompositor->vectorToWindowIdeal(mouseCoords);
if (pWindow && !pWindow->m_bIsFullscreen && !pWindow->hasPopupAt(mouseCoords) && pWindow->m_sGroupData.pNextWindow) { if (pWindow && !pWindow->m_bIsFullscreen && !pWindow->hasPopupAt(mouseCoords)) {
const wlr_box box = pWindow->getDecorationByType(DECORATION_GROUPBAR)->getWindowDecorationRegion().getExtents(); for (auto& wd : pWindow->m_dWindowDecorations) {
if (wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) { if (!wd->allowsInput())
const int SIZE = pWindow->getGroupSize(); continue;
pWindow = pWindow->getGroupWindowByIndex((mouseCoords.x - box.x) * SIZE / box.width);
// hack if (wd->getWindowDecorationRegion().containsPoint(mouseCoords)) {
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow); wd->dragFromDecoration(mouseCoords);
if (!pWindow->m_bIsFloating) { break;
const bool GROUPSLOCKEDPREV = g_pKeybindManager->m_bGroupsLocked;
g_pKeybindManager->m_bGroupsLocked = true;
g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow);
g_pKeybindManager->m_bGroupsLocked = GROUPSLOCKEDPREV;
} }
} }
} }
if (g_pInputManager->currentlyDraggedWindow == nullptr)
g_pInputManager->currentlyDraggedWindow = pWindow; g_pInputManager->currentlyDraggedWindow = pWindow;
g_pInputManager->dragMode = MBIND_MOVE; g_pInputManager->dragMode = MBIND_MOVE;
g_pLayoutManager->getCurrentLayout()->onBeginDragWindow(); g_pLayoutManager->getCurrentLayout()->onBeginDragWindow();
} else { } else {

View file

@ -540,18 +540,18 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) {
const auto mouseCoords = g_pInputManager->getMouseCoordsInternal(); const auto mouseCoords = g_pInputManager->getMouseCoordsInternal();
const auto w = g_pCompositor->vectorToWindowIdeal(mouseCoords); const auto w = g_pCompositor->vectorToWindowIdeal(mouseCoords);
if (w && !w->m_bIsFullscreen && !w->hasPopupAt(mouseCoords) && w->m_sGroupData.pNextWindow) { if (w && !w->m_bIsFullscreen && !w->hasPopupAt(mouseCoords)) {
const wlr_box box = w->getDecorationByType(DECORATION_GROUPBAR)->getWindowDecorationRegion().getExtents(); for (auto& wd : w->m_dWindowDecorations) {
if (wlr_box_contains_point(&box, mouseCoords.x, mouseCoords.y)) { if (!wd->allowsInput())
if (e->state == WLR_BUTTON_PRESSED) { continue;
const int SIZE = w->getGroupSize();
CWindow* pWindow = w->getGroupWindowByIndex((mouseCoords.x - box.x) * SIZE / box.width); if (wd->getWindowDecorationRegion().containsPoint(mouseCoords)) {
if (w != pWindow) if (e->state == WLR_BUTTON_PRESSED)
w->setGroupCurrent(pWindow); wd->clickDecoration(mouseCoords);
}
return; return;
} }
} }
}
// clicking on border triggers resize // clicking on border triggers resize
// TODO detect click on LS properly // TODO detect click on LS properly

View file

@ -93,11 +93,11 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D&
const int ROUNDING = m_pWindow->getRealRounding(); const int ROUNDING = m_pWindow->getRealRounding();
const int BORDERSIZE = m_pWindow->getRealBorderSize(); const int BORDERSIZE = m_pWindow->getRealBorderSize();
const float BARW = (m_vLastWindowSize.x - 2 * ROUNDING - BAR_HORIZONTAL_PADDING * (barsToDraw + (m_bInternalBar ? 1 : -1))) / barsToDraw; m_fBarWidth = (m_vLastWindowSize.x - 2 * ROUNDING - BAR_HORIZONTAL_PADDING * (barsToDraw + 1)) / barsToDraw;
float currentOffset = m_bInternalBar ? BAR_HORIZONTAL_PADDING : 0; float currentOffset = BAR_HORIZONTAL_PADDING;
if (BARW <= 0) if (m_fBarWidth <= 0)
return; return;
// Bottom left of groupbar // Bottom left of groupbar
@ -106,8 +106,8 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D&
std::floor(m_vLastWindowPos.y) - pMonitor->vecPosition.y + offset.y + std::floor(m_vLastWindowPos.y) - pMonitor->vecPosition.y + offset.y +
(m_bOnTop ? (m_bInternalBar ? 0 : -BORDERSIZE) : std::floor(m_vLastWindowSize.y) + m_iBarInternalHeight + BAR_INTERNAL_PADDING + (m_bInternalBar ? 0 : BORDERSIZE))); (m_bOnTop ? (m_bInternalBar ? 0 : -BORDERSIZE) : std::floor(m_vLastWindowSize.y) + m_iBarInternalHeight + BAR_INTERNAL_PADDING + (m_bInternalBar ? 0 : BORDERSIZE)));
wlr_box barBox = {pos.x, pos.y - m_iBarHeight + (m_bOnTop ? -BAR_INTERNAL_PADDING : 0), BARW, m_iBarHeight}; wlr_box barBox = {pos.x, pos.y - m_iBarHeight + (m_bOnTop ? -BAR_INTERNAL_PADDING : 0), m_fBarWidth, m_iBarHeight};
wlr_box gradBox = {pos.x, pos.y - m_iBarHeight + (m_bOnTop ? -2 * BAR_INTERNAL_PADDING : -BAR_INTERNAL_PADDING) - m_iGradientHeight, BARW, m_iGradientHeight}; wlr_box gradBox = {pos.x, pos.y - m_iBarHeight + (m_bOnTop ? -2 * BAR_INTERNAL_PADDING : -BAR_INTERNAL_PADDING) - m_iGradientHeight, m_fBarWidth, m_iGradientHeight};
wlr_box textBox = m_iGradientHeight != 0 ? gradBox : barBox; wlr_box textBox = m_iGradientHeight != 0 ? gradBox : barBox;
textBox.y += BAR_TEXT_PAD; textBox.y += BAR_TEXT_PAD;
textBox.height -= 2 * BAR_TEXT_PAD; textBox.height -= 2 * BAR_TEXT_PAD;
@ -192,7 +192,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D&
&gradBox, 1.0); &gradBox, 1.0);
} }
currentOffset += (float)(BAR_HORIZONTAL_PADDING + BARW) * pMonitor->scale; currentOffset += (float)(BAR_HORIZONTAL_PADDING + m_fBarWidth) * pMonitor->scale;
} }
if (*PRENDERTITLES) if (*PRENDERTITLES)
@ -372,15 +372,72 @@ void CHyprGroupBarDecoration::forceReload(CWindow* pWindow) {
} }
CRegion CHyprGroupBarDecoration::getWindowDecorationRegion() { CRegion CHyprGroupBarDecoration::getWindowDecorationRegion() {
const int ROUNDING = m_pWindow->getRealRounding();
const int BORDERSIZE = m_pWindow->getRealBorderSize(); const int BORDERSIZE = m_pWindow->getRealBorderSize();
return CRegion(m_vLastWindowPos.x + ROUNDING, return CRegion(m_vLastWindowPos.x,
m_vLastWindowPos.y + m_vLastWindowPos.y +
(m_bOnTop ? -BAR_INTERNAL_PADDING - m_iBarInternalHeight - (m_bInternalBar ? 0 : BORDERSIZE) : (m_bOnTop ? -BAR_INTERNAL_PADDING - m_iBarInternalHeight - (m_bInternalBar ? 0 : BORDERSIZE) :
m_vLastWindowSize.y + BAR_INTERNAL_PADDING + (m_bInternalBar ? 0 : BORDERSIZE)), m_vLastWindowSize.y + BAR_INTERNAL_PADDING + (m_bInternalBar ? 0 : BORDERSIZE)),
m_vLastWindowSize.x - 2 * ROUNDING, m_iBarInternalHeight); m_vLastWindowSize.x, m_iBarInternalHeight);
} }
bool CHyprGroupBarDecoration::allowsInput() { bool CHyprGroupBarDecoration::allowsInput() {
return true; return true;
} }
void CHyprGroupBarDecoration::dragWindowToDecoration(CWindow* m_pDraggedWindow, const Vector2D& pos) {
const int ROUNDING = m_pWindow->getRealRounding();
const float BARRELATIVEX = pos.x - (m_vLastWindowPos.x + ROUNDING) - (m_fBarWidth / 2 + BAR_HORIZONTAL_PADDING);
const int WINDOWINDEX = BARRELATIVEX < 0 ? -1 : (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING);
CWindow* pWindowInsertAfter = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
pWindowInsertAfter->insertWindowToGroup(m_pDraggedWindow);
if (WINDOWINDEX == -1)
std::swap(m_pDraggedWindow->m_sGroupData.head, m_pDraggedWindow->m_sGroupData.pNextWindow->m_sGroupData.head);
}
void CHyprGroupBarDecoration::clickDecoration(const Vector2D& pos) {
const int ROUNDING = m_pWindow->getRealRounding();
const float BARRELATIVEX = pos.x - (m_vLastWindowPos.x + ROUNDING);
const int WINDOWINDEX = (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING);
if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX < BAR_HORIZONTAL_PADDING) {
if (!g_pCompositor->isWindowActive(m_pWindow))
g_pCompositor->focusWindow(m_pWindow);
return;
}
CWindow* pWindow = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
if (pWindow != m_pWindow)
pWindow->setGroupCurrent(pWindow);
if (!g_pCompositor->isWindowActive(pWindow))
g_pCompositor->focusWindow(pWindow);
}
void CHyprGroupBarDecoration::dragFromDecoration(const Vector2D& pos) {
const int ROUNDING = m_pWindow->getRealRounding();
const float BARRELATIVEX = pos.x - (m_vLastWindowPos.x + ROUNDING);
const int WINDOWINDEX = (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING);
if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX < BAR_HORIZONTAL_PADDING)
return;
CWindow* pWindow = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
// hack
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow);
if (!pWindow->m_bIsFloating) {
const bool GROUPSLOCKEDPREV = g_pKeybindManager->m_bGroupsLocked;
g_pKeybindManager->m_bGroupsLocked = true;
g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow);
g_pKeybindManager->m_bGroupsLocked = GROUPSLOCKEDPREV;
}
g_pInputManager->currentlyDraggedWindow = pWindow;
if (!g_pCompositor->isWindowActive(pWindow))
g_pCompositor->focusWindow(pWindow);
}

View file

@ -37,6 +37,12 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration {
virtual bool allowsInput(); virtual bool allowsInput();
virtual void dragWindowToDecoration(CWindow*, const Vector2D&);
virtual void clickDecoration(const Vector2D&);
virtual void dragFromDecoration(const Vector2D&);
private: private:
SWindowDecorationExtents m_seExtents; SWindowDecorationExtents m_seExtents;
@ -55,6 +61,8 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration {
int m_iBarHeight; int m_iBarHeight;
int m_iGradientHeight; int m_iGradientHeight;
float m_fBarWidth;
CTitleTex* textureFromTitle(const std::string&); CTitleTex* textureFromTitle(const std::string&);
void invalidateTextures(); void invalidateTextures();

View file

@ -32,6 +32,12 @@ bool IHyprWindowDecoration::allowsInput() {
return false; return false;
} }
void IHyprWindowDecoration::dragWindowToDecoration(CWindow*, const Vector2D&) {}
void IHyprWindowDecoration::clickDecoration(const Vector2D&) {}
void IHyprWindowDecoration::dragFromDecoration(const Vector2D&) {}
void addExtentsToBox(wlr_box* box, SWindowDecorationExtents* extents) { void addExtentsToBox(wlr_box* box, SWindowDecorationExtents* extents) {
box->x -= extents->topLeft.x; box->x -= extents->topLeft.x;
box->y -= extents->topLeft.y; box->y -= extents->topLeft.y;

View file

@ -43,6 +43,12 @@ class IHyprWindowDecoration {
virtual bool allowsInput(); virtual bool allowsInput();
virtual void dragWindowToDecoration(CWindow*, const Vector2D&);
virtual void clickDecoration(const Vector2D&);
virtual void dragFromDecoration(const Vector2D&);
private: private:
CWindow* m_pWindow = nullptr; CWindow* m_pWindow = nullptr;
}; };