Skip to content

Commit

Permalink
all: chase hyprland
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Dec 22, 2024
1 parent 067bbc9 commit 8a29b42
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 5 deletions.
19 changes: 19 additions & 0 deletions hyprbars/BarPassElement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "BarPassElement.hpp"
#include <hyprland/src/render/OpenGL.hpp>
#include "barDeco.hpp"

CBarPassElement::CBarPassElement(const CBarPassElement::SBarData& data_) : data(data_) {
;
}

void CBarPassElement::draw(const CRegion& damage) {
data.deco->renderPass(g_pHyprOpenGL->m_RenderData.pMonitor.lock(), data.a);
}

bool CBarPassElement::needsLiveBlur() {
return false;
}

bool CBarPassElement::needsPrecomputeBlur() {
return false;
}
26 changes: 26 additions & 0 deletions hyprbars/BarPassElement.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include <hyprland/src/render/pass/PassElement.hpp>

class CHyprBar;

class CBarPassElement : public IPassElement {
public:
struct SBarData {
CHyprBar* deco = nullptr;
float a = 1.F;
};

CBarPassElement(const SBarData& data_);
virtual ~CBarPassElement() = default;

virtual void draw(const CRegion& damage);
virtual bool needsLiveBlur();
virtual bool needsPrecomputeBlur();

virtual const char* passName() {
return "CBarPassElement";
}

private:
SBarData data;
};
2 changes: 1 addition & 1 deletion hyprbars/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CXXFLAGS = -shared -fPIC --no-gnu-unique -g -std=c++2b -Wno-c++11-narrowing
INCLUDES = `pkg-config --cflags pixman-1 libdrm hyprland pangocairo libinput libudev wayland-server xkbcommon`
LIBS = `pkg-config --libs pangocairo`

SRC = main.cpp barDeco.cpp
SRC = main.cpp barDeco.cpp BarPassElement.cpp
TARGET = hyprbars.so

all: $(TARGET)
Expand Down
12 changes: 11 additions & 1 deletion hyprbars/barDeco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <hyprland/src/desktop/Window.hpp>
#include <hyprland/src/helpers/MiscFunctions.hpp>
#include <hyprland/src/managers/SeatManager.hpp>
#include <hyprland/src/render/Renderer.hpp>
#include <pango/pangocairo.h>

#include "globals.hpp"
#include "BarPassElement.hpp"

CHyprBar::CHyprBar(PHLWINDOW pWindow) : IHyprWindowDecoration(pWindow) {
m_pWindow = pWindow;
Expand Down Expand Up @@ -56,7 +58,8 @@ std::string CHyprBar::getDisplayName() {
}

void CHyprBar::onMouseDown(SCallbackInfo& info, IPointer::SButtonEvent e) {
if (!m_pWindow->m_pWorkspace->isVisible() || !g_pInputManager->m_dExclusiveLSes.empty() || (g_pSeatManager->seatGrab && !g_pSeatManager->seatGrab->accepts(m_pWindow->m_pWLSurface->resource())))
if (!m_pWindow->m_pWorkspace->isVisible() || !g_pInputManager->m_dExclusiveLSes.empty() ||
(g_pSeatManager->seatGrab && !g_pSeatManager->seatGrab->accepts(m_pWindow->m_pWLSurface->resource())))
return;

const auto WINDOWATCURSOR = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
Expand Down Expand Up @@ -399,6 +402,13 @@ void CHyprBar::draw(PHLMONITOR pMonitor, const float& a) {
if (!PWINDOW->m_sWindowData.decorate.valueOrDefault())
return;

auto data = CBarPassElement::SBarData{this, a};
g_pHyprRenderer->m_sRenderPass.add(makeShared<CBarPassElement>(data));
}

void CHyprBar::renderPass(PHLMONITOR pMonitor, const float& a) {
const auto PWINDOW = m_pWindow.lock();

static auto* const PCOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_color")->getDataStaticPtr();
static auto* const PHEIGHT = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_height")->getDataStaticPtr();
static auto* const PPRECEDENCE = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprbars:bar_precedence_over_border")->getDataStaticPtr();
Expand Down
3 changes: 3 additions & 0 deletions hyprbars/barDeco.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class CHyprBar : public IHyprWindowDecoration {

Vector2D cursorRelativeToBar();

void renderPass(PHLMONITOR, float const& a);
void renderBarTitle(const Vector2D& bufferSize, const float scale);
void renderText(SP<CTexture> out, const std::string& text, const CHyprColor& color, const Vector2D& bufferSize, const float scale, const int fontSize);
void renderBarButtons(const Vector2D& bufferSize, const float scale);
Expand All @@ -74,4 +75,6 @@ class CHyprBar : public IHyprWindowDecoration {

// for dynamic updates
int m_iLastHeight = 0;

friend class CBarPassElement;
};
2 changes: 1 addition & 1 deletion hyprexpo/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all:
$(CXX) -shared -fPIC --no-gnu-unique main.cpp overview.cpp -o hyprexpo.so -g `pkg-config --cflags pixman-1 libdrm hyprland pangocairo libinput libudev wayland-server xkbcommon` -std=c++2b -Wno-narrowing
$(CXX) -shared -fPIC --no-gnu-unique main.cpp overview.cpp OverviewPassElement.cpp -o hyprexpo.so -g `pkg-config --cflags pixman-1 libdrm hyprland pangocairo libinput libudev wayland-server xkbcommon` -std=c++2b -Wno-narrowing
clean:
rm ./hyprexpo.so
33 changes: 33 additions & 0 deletions hyprexpo/OverviewPassElement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "OverviewPassElement.hpp"
#include <hyprland/src/render/OpenGL.hpp>
#include "overview.hpp"

COverviewPassElement::COverviewPassElement() {
;
}

void COverviewPassElement::draw(const CRegion& damage) {
g_pOverview->fullRender();
}

bool COverviewPassElement::needsLiveBlur() {
return false;
}

bool COverviewPassElement::needsPrecomputeBlur() {
return false;
}

std::optional<CBox> COverviewPassElement::boundingBox() {
if (!g_pOverview->pMonitor)
return std::nullopt;

return CBox{{}, g_pOverview->pMonitor->vecSize};
}

CRegion COverviewPassElement::opaqueRegion() {
if (!g_pOverview->pMonitor)
return CRegion{};

return CBox{{}, g_pOverview->pMonitor->vecSize};
}
20 changes: 20 additions & 0 deletions hyprexpo/OverviewPassElement.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include <hyprland/src/render/pass/PassElement.hpp>

class COverview;

class COverviewPassElement : public IPassElement {
public:
COverviewPassElement();
virtual ~COverviewPassElement() = default;

virtual void draw(const CRegion& damage);
virtual bool needsLiveBlur();
virtual bool needsPrecomputeBlur();
virtual std::optional<CBox> boundingBox();
virtual CRegion opaqueRegion();

virtual const char* passName() {
return "COverviewPassElement";
}
};
6 changes: 5 additions & 1 deletion hyprexpo/overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/config/ConfigValue.hpp>
#undef private
#include "OverviewPassElement.hpp"

static void damageMonitor(void*) {
g_pOverview->damage();
Expand Down Expand Up @@ -378,7 +379,10 @@ void COverview::onWorkspaceChange() {
}

void COverview::render() {
g_pHyprRenderer->m_sRenderPass.add(makeShared<COverviewPassElement>());
}

void COverview::fullRender() {
const auto GAPSIZE = (closing ? (1.0 - size.getPercent()) : size.getPercent()) * GAP_WIDTH;

if (pMonitor->activeWorkspace != startedOn && !closing) {
Expand All @@ -399,7 +403,7 @@ void COverview::render() {
texbox.scale(pMonitor->scale).translate(pos.value());
texbox.round();
CRegion damage{0, 0, INT16_MAX, INT16_MAX};
g_pHyprOpenGL->renderTextureInternalWithDamage(images[x + y * SIDE_LENGTH].fb.getTexture(), &texbox, 1.0, &damage);
g_pHyprOpenGL->renderTextureInternalWithDamage(images[x + y * SIDE_LENGTH].fb.getTexture(), &texbox, 1.0, damage);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions hyprexpo/overview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class COverview {
void redrawID(int id, bool forcelowres = false);
void redrawAll(bool forcelowres = false);
void onWorkspaceChange();
void fullRender();

int SIDE_LENGTH = 3;
int GAP_WIDTH = 5;
Expand Down Expand Up @@ -75,6 +76,8 @@ class COverview {

bool swipe = false;
bool swipeWasCommenced = false;

friend class COverviewPassElement;
};

inline std::unique_ptr<COverview> g_pOverview;
2 changes: 1 addition & 1 deletion hyprtrails/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all:
$(CXX) -shared -fPIC --no-gnu-unique main.cpp trail.cpp -o hyprtrails.so -g `pkg-config --cflags pixman-1 libdrm hyprland pangocairo libinput libudev wayland-server xkbcommon` -std=c++2b -O2
$(CXX) -shared -fPIC --no-gnu-unique main.cpp trail.cpp TrailPassElement.cpp -o hyprtrails.so -g `pkg-config --cflags pixman-1 libdrm hyprland pangocairo libinput libudev wayland-server xkbcommon` -std=c++2b -O2
clean:
rm ./hyprtrails.so
19 changes: 19 additions & 0 deletions hyprtrails/TrailPassElement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "TrailPassElement.hpp"
#include <hyprland/src/render/OpenGL.hpp>
#include "trail.hpp"

CTrailPassElement::CTrailPassElement(const CTrailPassElement::STrailData& data_) : data(data_) {
;
}

void CTrailPassElement::draw(const CRegion& damage) {
data.deco->renderPass(g_pHyprOpenGL->m_RenderData.pMonitor.lock(), data.a);
}

bool CTrailPassElement::needsLiveBlur() {
return false;
}

bool CTrailPassElement::needsPrecomputeBlur() {
return false;
}
26 changes: 26 additions & 0 deletions hyprtrails/TrailPassElement.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include <hyprland/src/render/pass/PassElement.hpp>

class CTrail;

class CTrailPassElement : public IPassElement {
public:
struct STrailData {
CTrail* deco = nullptr;
float a = 1.F;
};

CTrailPassElement(const STrailData& data_);
virtual ~CTrailPassElement() = default;

virtual void draw(const CRegion& damage);
virtual bool needsLiveBlur();
virtual bool needsPrecomputeBlur();

virtual const char* passName() {
return "CTrailPassElement";
}

private:
STrailData data;
};
9 changes: 9 additions & 0 deletions hyprtrails/trail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/desktop/Window.hpp>
#include <hyprland/src/render/Renderer.hpp>

#include "globals.hpp"
#include "TrailPassElement.hpp"

void CTrail::onTick() {
static auto* const PHISTORYSTEP = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprtrails:history_step")->getDataStaticPtr();
Expand Down Expand Up @@ -87,6 +89,13 @@ void CTrail::draw(PHLMONITOR pMonitor, const float& a) {
if (!PWINDOW->m_sWindowData.decorate.valueOrDefault())
return;

auto data = CTrailPassElement::STrailData{this, a};
g_pHyprRenderer->m_sRenderPass.add(makeShared<CTrailPassElement>(data));
}

void CTrail::renderPass(PHLMONITOR pMonitor, const float& a) {
const auto PWINDOW = m_pWindow.lock();

static auto* const PBEZIERSTEP = (Hyprlang::FLOAT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprtrails:bezier_step")->getDataStaticPtr();
static auto* const PPOINTSPERSTEP = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprtrails:points_per_step")->getDataStaticPtr();
static auto* const PCOLOR = (Hyprlang::INT* const*)HyprlandAPI::getConfigValue(PHANDLE, "plugin:hyprtrails:color")->getDataStaticPtr();
Expand Down
3 changes: 3 additions & 0 deletions hyprtrails/trail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CTrail : public IHyprWindowDecoration {
private:
SP<HOOK_CALLBACK_FN> pTickCb;
void onTick();
void renderPass(PHLMONITOR pMonitor, const float& a);

std::deque<std::pair<box, std::chrono::system_clock::time_point>> m_dLastGeoms;

Expand All @@ -62,4 +63,6 @@ class CTrail : public IHyprWindowDecoration {

CBox m_bLastBox = {0};
bool m_bNeedsDamage = false;

friend class CTrailPassElement;
};

0 comments on commit 8a29b42

Please sign in to comment.