Skip to content

Commit

Permalink
all: chase storage refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
KZDKM committed May 4, 2024
1 parent cbdac93 commit 1b3e07c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/Globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ inline HANDLE pHandle = NULL;
typedef void (*tMouseKeybind)(std::string);
extern void* pMouseKeybind;

typedef void (*tRenderWindow)(void*, CWindow*, CMonitor*, timespec*, bool, eRenderPassMode, bool, bool);
typedef void (*tRenderWindow)(void*, PHLWINDOW, CMonitor*, timespec*, bool, eRenderPassMode, bool, bool);
extern void* pRenderWindow;
typedef void (*tRenderLayer)(void*, SLayerSurface*, CMonitor*, timespec*, bool);
typedef void (*tRenderLayer)(void*, PHLLS, CMonitor*, timespec*, bool);
extern void* pRenderLayer;

namespace Config {
Expand Down
6 changes: 3 additions & 3 deletions src/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
bool CHyprspaceWidget::buttonEvent(bool pressed, Vector2D coords) {
bool Return;

const auto targetWindow = g_pInputManager->currentlyDraggedWindow;
const auto targetWindow = g_pInputManager->currentlyDraggedWindow.lock();

// this is for click to exit, we set a timeout for button release
bool couldExit = false;
Expand Down Expand Up @@ -36,9 +36,9 @@ bool CHyprspaceWidget::buttonEvent(bool pressed, Vector2D coords) {
// if the cursor is hovering over workspace, clicking should switch workspace instead of starting window drag
if (Config::autoDrag && (targetWorkspace == nullptr || !pressed)) {
// when overview is active, always drag windows on mouse click
if (g_pInputManager->currentlyDraggedWindow) {
if (const auto curWindow = g_pInputManager->currentlyDraggedWindow.lock()) {
g_pLayoutManager->getCurrentLayout()->onEndDragWindow();
g_pInputManager->currentlyDraggedWindow = nullptr;
g_pInputManager->currentlyDraggedWindow.reset();
g_pInputManager->dragMode = MBIND_INVALID;
}
std::string keybind = (pressed ? "1" : "0") + std::string("movewindow");
Expand Down
6 changes: 3 additions & 3 deletions src/Overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void CHyprspaceWidget::show() {
// fixes youtube fullscreen not restoring properly
if (ws->m_efFullscreenMode == FULLSCREEN_FULL) w->m_bFakeFullscreenState = true;
// we use the getWindowFromHandle function to prevent dangling pointers
prevFullscreen.emplace_back(std::make_tuple((uint32_t)(((uint64_t)w) & 0xFFFFFFFF), ws->m_efFullscreenMode));
prevFullscreen.emplace_back(std::make_tuple((uint32_t)(((uint64_t)w.get()) & 0xFFFFFFFF), ws->m_efFullscreenMode));
g_pCompositor->setWindowFullscreen(w, false);
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ void CHyprspaceWidget::hide() {
// restore layer state
for (auto& ls : owner->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) {
if (!ls->readyToDelete && ls->mapped && ls->fadingOut) {
auto oAlpha = std::find_if(oLayerAlpha.begin(), oLayerAlpha.end(), [&] (const auto& tuple) {return std::get<0>(tuple) == ls.get();});
auto oAlpha = std::find_if(oLayerAlpha.begin(), oLayerAlpha.end(), [&] (const auto& tuple) {return std::get<0>(tuple) == ls;});
if (oAlpha != oLayerAlpha.end()) {
ls->fadingOut = false;
ls->alpha = std::get<1>(*oAlpha);
Expand All @@ -93,7 +93,7 @@ void CHyprspaceWidget::hide() {
}
for (auto& ls : owner->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) {
if (!ls->readyToDelete && ls->mapped && ls->fadingOut) {
auto oAlpha = std::find_if(oLayerAlpha.begin(), oLayerAlpha.end(), [&] (const auto& tuple) {return std::get<0>(tuple) == ls.get();});
auto oAlpha = std::find_if(oLayerAlpha.begin(), oLayerAlpha.end(), [&] (const auto& tuple) {return std::get<0>(tuple) == ls;});
if (oAlpha != oLayerAlpha.end()) {
ls->fadingOut = false;
ls->alpha = std::get<1>(*oAlpha);
Expand Down
2 changes: 1 addition & 1 deletion src/Overview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CHyprspaceWidget {
std::vector<std::tuple<uint32_t, eFullscreenMode>> prevFullscreen;

// for storing the layer alpha values prior to overview activation (which sets all panel to transparent when configured)
std::vector<std::tuple<SLayerSurface*, float>> oLayerAlpha;
std::vector<std::tuple<PHLLS, float>> oLayerAlpha;

// for click-to-exit
std::chrono::system_clock::time_point lastPressedTime = std::chrono::high_resolution_clock::now();
Expand Down
20 changes: 10 additions & 10 deletions src/Render.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Overview.hpp"
#include "Globals.hpp"

void renderWindowStub(CWindow* pWindow, CMonitor* pMonitor, PHLWORKSPACE pWorkspaceOverride, CBox rectOverride, timespec* time) {
void renderWindowStub(PHLWINDOW pWindow, CMonitor* pMonitor, PHLWORKSPACE pWorkspaceOverride, CBox rectOverride, timespec* time) {
if (!pWindow || !pMonitor || !pWorkspaceOverride || !time) return;

const auto oWorkspace = pWindow->m_pWorkspace;
Expand Down Expand Up @@ -50,7 +50,7 @@ void renderWindowStub(CWindow* pWindow, CMonitor* pMonitor, PHLWORKSPACE pWorksp
g_pHyprOpenGL->m_RenderData.renderModif.modifs.pop_back();
}

void renderLayerStub(SLayerSurface* pLayer, CMonitor* pMonitor, CBox rectOverride, timespec* time) {
void renderLayerStub(PHLLS pLayer, CMonitor* pMonitor, CBox rectOverride, timespec* time) {
if (!pLayer || !pMonitor || !time) return;

if (!pLayer->mapped || pLayer->readyToDelete || !pLayer->layerSurface) return;
Expand Down Expand Up @@ -213,13 +213,13 @@ void CHyprspaceWidget::draw() {
for (auto& ls : owner->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) {
CBox layerBox = {curWorkspaceBox.pos() + (ls->realPosition.value() - owner->vecPosition) * monitorSizeScaleFactor, ls->realSize.value() * monitorSizeScaleFactor};
g_pHyprOpenGL->m_RenderData.clipBox = curWorkspaceBox;
renderLayerStub(ls.get(), owner, layerBox, &time);
renderLayerStub(ls, owner, layerBox, &time);
g_pHyprOpenGL->m_RenderData.clipBox = CBox();
}
for (auto& ls : owner->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) {
CBox layerBox = {curWorkspaceBox.pos() + (ls->realPosition.value() - owner->vecPosition) * monitorSizeScaleFactor, ls->realSize.value() * monitorSizeScaleFactor};
g_pHyprOpenGL->m_RenderData.clipBox = curWorkspaceBox;
renderLayerStub(ls.get(), owner, layerBox, &time);
renderLayerStub(ls, owner, layerBox, &time);
g_pHyprOpenGL->m_RenderData.clipBox = CBox();
}
}
Expand All @@ -244,14 +244,14 @@ void CHyprspaceWidget::draw() {
CBox curWindowBox = {wX, wY, wW, wH};
g_pHyprOpenGL->m_RenderData.clipBox = curWorkspaceBox;
//g_pHyprOpenGL->renderRectWithBlur(&curWindowBox, CColor(0, 0, 0, 0));
renderWindowStub(w.get(), owner, owner->activeWorkspace, curWindowBox, &time);
renderWindowStub(w, owner, owner->activeWorkspace, curWindowBox, &time);
g_pHyprOpenGL->m_RenderData.clipBox = CBox();
}
}
// draw floating windows
for (auto& w : g_pCompositor->m_vWindows) {
if (!w) continue;
if (w->m_pWorkspace == ws && w->m_bIsFloating && ws->getLastFocusedWindow() != w.get()) {
if (w->m_pWorkspace == ws && w->m_bIsFloating && ws->getLastFocusedWindow() != w) {
double wX = curWorkspaceRectOffsetX + ((w->m_vRealPosition.value().x - owner->vecPosition.x) * monitorSizeScaleFactor * owner->scale);
double wY = curWorkspaceRectOffsetY + ((w->m_vRealPosition.value().y - owner->vecPosition.y) * monitorSizeScaleFactor * owner->scale);
double wW = w->m_vRealSize.value().x * monitorSizeScaleFactor * owner->scale;
Expand All @@ -260,14 +260,14 @@ void CHyprspaceWidget::draw() {
CBox curWindowBox = {wX, wY, wW, wH};
g_pHyprOpenGL->m_RenderData.clipBox = curWorkspaceBox;
//g_pHyprOpenGL->renderRectWithBlur(&curWindowBox, CColor(0, 0, 0, 0));
renderWindowStub(w.get(), owner, owner->activeWorkspace, curWindowBox, &time);
renderWindowStub(w, owner, owner->activeWorkspace, curWindowBox, &time);
g_pHyprOpenGL->m_RenderData.clipBox = CBox();
}
}
// draw last focused floating window on top
if (ws->getLastFocusedWindow())
if (ws->getLastFocusedWindow()->m_bIsFloating) {
CWindow* w = ws->getLastFocusedWindow();
const auto w = ws->getLastFocusedWindow();
double wX = curWorkspaceRectOffsetX + ((w->m_vRealPosition.value().x - owner->vecPosition.x) * monitorSizeScaleFactor * owner->scale);
double wY = curWorkspaceRectOffsetY + ((w->m_vRealPosition.value().y - owner->vecPosition.y) * monitorSizeScaleFactor * owner->scale);
double wW = w->m_vRealSize.value().x * monitorSizeScaleFactor * owner->scale;
Expand All @@ -287,15 +287,15 @@ void CHyprspaceWidget::draw() {
for (auto& ls : owner->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) {
CBox layerBox = {curWorkspaceBox.pos() + (ls->realPosition.value() - owner->vecPosition) * monitorSizeScaleFactor, ls->realSize.value() * monitorSizeScaleFactor};
g_pHyprOpenGL->m_RenderData.clipBox = curWorkspaceBox;
renderLayerStub(ls.get(), owner, layerBox, &time);
renderLayerStub(ls, owner, layerBox, &time);
g_pHyprOpenGL->m_RenderData.clipBox = CBox();
}

if (!Config::hideOverlayLayers)
for (auto& ls : owner->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) {
CBox layerBox = {curWorkspaceBox.pos() + (ls->realPosition.value() - owner->vecPosition) * monitorSizeScaleFactor, ls->realSize.value() * monitorSizeScaleFactor};
g_pHyprOpenGL->m_RenderData.clipBox = curWorkspaceBox;
renderLayerStub(ls.get(), owner, layerBox, &time);
renderLayerStub(ls, owner, layerBox, &time);
g_pHyprOpenGL->m_RenderData.clipBox = CBox();
}
}
Expand Down
34 changes: 20 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <hyprland/src/plugins/PluginSystem.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/devices/IKeyboard.hpp>
#include "Overview.hpp"
#include "Globals.hpp"

Expand Down Expand Up @@ -118,9 +119,11 @@ void onRender(void* thisptr, SCallbackInfo& info, std::any args) {
if (widget != nullptr)
if (widget->getOwner()) {
//widget->draw();
if (g_pInputManager->currentlyDraggedWindow && widget->isActive()) {
g_oAlpha = g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.goal();
g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.setValueAndWarp(0); // HACK: hide dragged window for the actual pass
if (const auto curWindow = g_pInputManager->currentlyDraggedWindow.lock()) {
if (widget->isActive()) {
g_oAlpha = curWindow->m_fActiveInactiveAlpha.goal();
curWindow->m_fActiveInactiveAlpha.setValueAndWarp(0); // HACK: hide dragged window for the actual pass
}
}
else g_oAlpha = -1;
}
Expand All @@ -135,12 +138,14 @@ void onRender(void* thisptr, SCallbackInfo& info, std::any args) {
if (widget != nullptr)
if (widget->getOwner()) {
widget->draw();
if (g_oAlpha != -1 && g_pInputManager->currentlyDraggedWindow) {
g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.setValueAndWarp(Config::dragAlpha);
timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
(*(tRenderWindow)pRenderWindow)(g_pHyprRenderer.get(), g_pInputManager->currentlyDraggedWindow, widget->getOwner(), &time, true, RENDER_PASS_MAIN, false, false);
g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.setValueAndWarp(g_oAlpha);
if (g_oAlpha != -1) {
if (const auto curWindow = g_pInputManager->currentlyDraggedWindow.lock()) {
curWindow->m_fActiveInactiveAlpha.setValueAndWarp(Config::dragAlpha);
timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
(*(tRenderWindow)pRenderWindow)(g_pHyprRenderer.get(), curWindow, widget->getOwner(), &time, true, RENDER_PASS_MAIN, false, false);
curWindow->m_fActiveInactiveAlpha.setValueAndWarp(g_oAlpha);
}
}
g_oAlpha = -1;
}
Expand Down Expand Up @@ -246,10 +251,10 @@ void onSwipeEnd(void* thisptr, SCallbackInfo& info, std::any args) {

// atm this is only for ESC to exit
void onKeyPress(void* thisptr, SCallbackInfo& info, std::any args) {
const auto e = std::any_cast<wlr_keyboard_key_event*>(std::any_cast<std::unordered_map<std::string, std::any>>(args)["event"]);
const auto e = std::any_cast<IKeyboard::SKeyEvent>(std::any_cast<std::unordered_map<std::string, std::any>>(args)["event"]);
//const auto k = std::any_cast<SKeyboard*>(std::any_cast<std::unordered_map<std::string, std::any>>(args)["keyboard"]);

if (e->keycode == KEY_ESC) {
if (e.keycode == KEY_ESC) {
const auto widget = getWidgetForMonitor(g_pCompositor->getMonitorFromCursor());
if (widget != nullptr)
if (widget->isActive()) {
Expand Down Expand Up @@ -285,18 +290,19 @@ void dispatchToggleOverview(std::string arg) {
if (widget->isActive()) {
for (auto& widget : g_overviewWidgets) {
if (widget != nullptr)
if (widget->isActive())
if (widget->isActive())
widget->hide();
}
}
else {
for (auto& widget : g_overviewWidgets) {
if (widget != nullptr)
if (!widget->isActive())
if (!widget->isActive())
widget->show();
}
}
} else
}
else
widget->isActive() ? widget->hide() : widget->show();
}
}
Expand Down

0 comments on commit 1b3e07c

Please sign in to comment.