summaryrefslogtreecommitdiff
path: root/src/render/decorations/CHyprGroupBarDecoration.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-05-05 17:16:00 +0100
committerGitHub <noreply@github.com>2024-05-05 17:16:00 +0100
commit1ed1ce9506e65f76fe5236194516f23d662bba0b (patch)
tree124556baadfe27587d025913bfbdd579060ed317 /src/render/decorations/CHyprGroupBarDecoration.cpp
parent589f758d947cb4e8b888d2da00076a9fb0a6d521 (diff)
internal: new shared_ptr and weak_ptr implementation (#5883)
moves std::shared_ptrs to a new implementation Advantages: - you can dereference a weak_ptr directly. This will obviously segfault on a nullptr deref if it's expired. - this is useful to avoid the .lock() hell where we are 100% sure the pointer _should_ be valid. (and if it isn't, it should throw.) - weak_ptrs are still valid while the SP is being destroyed. - reasoning: while an object (e.g. CWindow) is being destroyed, its `weak_ptr self` should be accessible (the sp is still alive, and so is CWindow), but it's not because by stl it's already expired (to prevent resurrection) - this impl solves it differently. w_p is expired, but can still be dereferenced and used. Creating `s_p`s is not possible anymore, though. - this is useful in destructors and callbacks.
Diffstat (limited to 'src/render/decorations/CHyprGroupBarDecoration.cpp')
-rw-r--r--src/render/decorations/CHyprGroupBarDecoration.cpp50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp
index ee1e713a..e854d63a 100644
--- a/src/render/decorations/CHyprGroupBarDecoration.cpp
+++ b/src/render/decorations/CHyprGroupBarDecoration.cpp
@@ -39,7 +39,7 @@ SDecorationPositioningInfo CHyprGroupBarDecoration::getPositioningInfo() {
info.priority = *PPRIORITY;
info.reserved = true;
- if (*PENABLED && m_pWindow.lock()->m_sSpecialRenderData.decorate)
+ if (*PENABLED && m_pWindow->m_sSpecialRenderData.decorate)
info.desiredExtents = {{0, BAR_PADDING_OUTER_VERT * 2 + BAR_INDICATOR_HEIGHT + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0) + 2}, {0, 0}};
else
info.desiredExtents = {{0, 0}, {0, 0}};
@@ -58,8 +58,8 @@ eDecorationType CHyprGroupBarDecoration::getDecorationType() {
//
void CHyprGroupBarDecoration::updateWindow(PHLWINDOW pWindow) {
- if (m_pWindow.lock()->m_sGroupData.pNextWindow.expired()) {
- m_pWindow.lock()->removeWindowDeco(this);
+ if (m_pWindow->m_sGroupData.pNextWindow.expired()) {
+ m_pWindow->removeWindowDeco(this);
return;
}
@@ -76,14 +76,14 @@ void CHyprGroupBarDecoration::updateWindow(PHLWINDOW pWindow) {
damageEntire();
if (m_dwGroupMembers.size() == 0) {
- m_pWindow.lock()->removeWindowDeco(this);
+ m_pWindow->removeWindowDeco(this);
return;
}
}
void CHyprGroupBarDecoration::damageEntire() {
auto box = assignedBoxGlobal();
- box.translate(m_pWindow.lock()->m_vFloatingOffset);
+ box.translate(m_pWindow->m_vFloatingOffset);
g_pHyprRenderer->damageBox(&box);
}
@@ -97,7 +97,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) {
static auto PHEIGHT = CConfigValue<Hyprlang::INT>("group:groupbar:height");
static auto PGRADIENTS = CConfigValue<Hyprlang::INT>("group:groupbar:gradients");
- if (!*PENABLED || !m_pWindow.lock()->m_sSpecialRenderData.decorate)
+ if (!*PENABLED || !m_pWindow->m_sSpecialRenderData.decorate)
return;
const auto ASSIGNEDBOX = assignedBoxGlobal();
@@ -111,8 +111,8 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) {
int xoff = 0;
for (int i = 0; i < barsToDraw; ++i) {
- CBox rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow.lock()->m_vFloatingOffset.x,
- ASSIGNEDBOX.y + ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT - pMonitor->vecPosition.y + m_pWindow.lock()->m_vFloatingOffset.y, m_fBarWidth,
+ CBox rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x,
+ ASSIGNEDBOX.y + ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT - pMonitor->vecPosition.y + m_pWindow->m_vFloatingOffset.y, m_fBarWidth,
BAR_INDICATOR_HEIGHT};
if (rect.width <= 0 || rect.height <= 0)
@@ -129,7 +129,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) {
auto* const GROUPCOLACTIVELOCKED = (CGradientValueData*)(PGROUPCOLACTIVELOCKED.ptr())->getData();
auto* const GROUPCOLINACTIVELOCKED = (CGradientValueData*)(PGROUPCOLINACTIVELOCKED.ptr())->getData();
- const bool GROUPLOCKED = m_pWindow.lock()->getGroupHead()->m_sGroupData.locked;
+ const bool GROUPLOCKED = m_pWindow->getGroupHead()->m_sGroupData.locked;
const auto* const PCOLACTIVE = GROUPLOCKED ? GROUPCOLACTIVELOCKED : GROUPCOLACTIVE;
const auto* const PCOLINACTIVE = GROUPLOCKED ? GROUPCOLINACTIVELOCKED : GROUPCOLINACTIVE;
@@ -137,8 +137,8 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) {
color.a *= a;
g_pHyprOpenGL->renderRect(&rect, color);
- rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow.lock()->m_vFloatingOffset.x,
- ASSIGNEDBOX.y - pMonitor->vecPosition.y + m_pWindow.lock()->m_vFloatingOffset.y + BAR_PADDING_OUTER_VERT, m_fBarWidth,
+ rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x,
+ ASSIGNEDBOX.y - pMonitor->vecPosition.y + m_pWindow->m_vFloatingOffset.y + BAR_PADDING_OUTER_VERT, m_fBarWidth,
ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT * 2};
rect.scale(pMonitor->scale);
@@ -150,7 +150,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) {
}
if (*PRENDERTITLES) {
- CTitleTex* pTitleTex = textureFromTitle(m_dwGroupMembers[i].lock()->m_szTitle);
+ CTitleTex* pTitleTex = textureFromTitle(m_dwGroupMembers[i]->m_szTitle);
if (!pTitleTex)
pTitleTex = m_sTitleTexs.titleTexs
@@ -335,7 +335,7 @@ void refreshGroupBarGradients() {
}
bool CHyprGroupBarDecoration::onBeginWindowDragOnDeco(const Vector2D& pos) {
- if (m_pWindow.lock() == m_pWindow.lock()->m_sGroupData.pNextWindow.lock())
+ if (m_pWindow.lock() == m_pWindow->m_sGroupData.pNextWindow.lock())
return false;
const float BARRELATIVEX = pos.x - assignedBoxGlobal().x;
@@ -344,7 +344,7 @@ bool CHyprGroupBarDecoration::onBeginWindowDragOnDeco(const Vector2D& pos) {
if (BARRELATIVEX - (m_fBarWidth + BAR_HORIZONTAL_PADDING) * WINDOWINDEX > m_fBarWidth)
return false;
- PHLWINDOW pWindow = m_pWindow.lock()->getGroupWindowByIndex(WINDOWINDEX);
+ PHLWINDOW pWindow = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
// hack
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow);
@@ -370,7 +370,7 @@ bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, PHLWIND
const float BARRELATIVEX = pos.x - assignedBoxGlobal().x - m_fBarWidth / 2;
const int WINDOWINDEX = BARRELATIVEX < 0 ? -1 : (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING);
- PHLWINDOW pWindowInsertAfter = m_pWindow.lock()->getGroupWindowByIndex(WINDOWINDEX);
+ PHLWINDOW pWindowInsertAfter = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
PHLWINDOW pWindowInsertEnd = pWindowInsertAfter->m_sGroupData.pNextWindow.lock();
PHLWINDOW pDraggedHead = pDraggedWindow->m_sGroupData.pNextWindow.lock() ? pDraggedWindow->getGroupHead() : pDraggedWindow;
@@ -411,7 +411,7 @@ bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, PHLWIND
if (WINDOWINDEX == -1)
std::swap(pDraggedHead->m_sGroupData.head, pWindowInsertEnd->m_sGroupData.head);
- m_pWindow.lock()->setGroupCurrent(pDraggedWindow);
+ m_pWindow->setGroupCurrent(pDraggedWindow);
pDraggedWindow->applyGroupRules();
pDraggedWindow->updateWindowDecos();
g_pLayoutManager->getCurrentLayout()->recalculateWindow(pDraggedWindow);
@@ -423,7 +423,7 @@ bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, PHLWIND
}
bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_pointer_button_event* e) {
- if (m_pWindow.lock()->m_bIsFullscreen && m_pWindow.lock()->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL)
+ if (m_pWindow->m_bIsFullscreen && m_pWindow->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL)
return true;
const float BARRELATIVEX = pos.x - assignedBoxGlobal().x;
@@ -437,7 +437,7 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point
if (e->state == WL_POINTER_BUTTON_STATE_PRESSED)
pressedCursorPos = pos;
else if (e->state == WL_POINTER_BUTTON_STATE_RELEASED && pressedCursorPos == pos)
- g_pXWaylandManager->sendCloseWindow(m_pWindow.lock()->getGroupWindowByIndex(WINDOWINDEX));
+ g_pXWaylandManager->sendCloseWindow(m_pWindow->getGroupWindowByIndex(WINDOWINDEX));
return true;
}
@@ -452,9 +452,9 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point
return true;
}
- PHLWINDOW pWindow = m_pWindow.lock()->getGroupWindowByIndex(WINDOWINDEX);
+ PHLWINDOW pWindow = m_pWindow->getGroupWindowByIndex(WINDOWINDEX);
- if (pWindow != m_pWindow.lock())
+ if (pWindow != m_pWindow)
pWindow->setGroupCurrent(pWindow);
if (!g_pCompositor->isWindowActive(pWindow) && *PFOLLOWMOUSE != 3)
@@ -469,13 +469,13 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point
bool CHyprGroupBarDecoration::onScrollOnDeco(const Vector2D& pos, wlr_pointer_axis_event* e) {
static auto PGROUPBARSCROLLING = CConfigValue<Hyprlang::INT>("group:groupbar:scrolling");
- if (!*PGROUPBARSCROLLING || m_pWindow.lock()->m_sGroupData.pNextWindow.expired())
+ if (!*PGROUPBARSCROLLING || m_pWindow->m_sGroupData.pNextWindow.expired())
return false;
if (e->delta > 0)
- m_pWindow.lock()->setGroupCurrent(m_pWindow.lock()->m_sGroupData.pNextWindow.lock());
+ m_pWindow->setGroupCurrent(m_pWindow->m_sGroupData.pNextWindow.lock());
else
- m_pWindow.lock()->setGroupCurrent(m_pWindow.lock()->getGroupPrevious());
+ m_pWindow->setGroupCurrent(m_pWindow->getGroupPrevious());
return true;
}
@@ -506,9 +506,9 @@ CBox CHyprGroupBarDecoration::assignedBoxGlobal() {
CBox box = m_bAssignedBox;
box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, m_pWindow.lock()));
- const auto PWORKSPACE = m_pWindow.lock()->m_pWorkspace;
+ const auto PWORKSPACE = m_pWindow->m_pWorkspace;
- if (PWORKSPACE && !m_pWindow.lock()->m_bPinned)
+ if (PWORKSPACE && !m_pWindow->m_bPinned)
box.translate(PWORKSPACE->m_vRenderOffset.value());
return box;