aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2022-04-10 14:32:18 +0200
committervaxerski <[email protected]>2022-04-10 14:32:18 +0200
commit3753f83f69597325ad0dc88dbc70e0e9a483e2d4 (patch)
tree8597feeb36f9989c2cd2e1032f0492b3297a1a99
parent5046c02cceea9bccf1b39fbc84ad062f59ce6e22 (diff)
downloadHyprland-3753f83f69597325ad0dc88dbc70e0e9a483e2d4.tar.gz
Hyprland-3753f83f69597325ad0dc88dbc70e0e9a483e2d4.zip
Added default background as a PNG
-rw-r--r--Makefile4
-rw-r--r--assets/wall_2K.pngbin0 -> 67279 bytes
-rw-r--r--assets/wall_4K.pngbin0 -> 232836 bytes
-rw-r--r--assets/wall_8K.pngbin0 -> 236757 bytes
-rw-r--r--src/events/Monitors.cpp1
-rw-r--r--src/helpers/WLListener.cpp4
-rw-r--r--src/render/OpenGL.cpp56
-rw-r--r--src/render/OpenGL.hpp3
8 files changed, 66 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 6328cfa4..0451b1a3 100644
--- a/Makefile
+++ b/Makefile
@@ -73,5 +73,9 @@ install:
cp ./example/hyprland.desktop /usr/share/wayland-sessions/
cp ./build/Hyprland /usr/bin
cp ./hyprctl/hyprctl /usr/bin
+ mkdir -p /usr/share/hyprland
+ cp ./assets/wall_2K.png /usr/share/hyprland
+ cp ./assets/wall_4K.png /usr/share/hyprland
+ cp ./assets/wall_8K.png /usr/share/hyprland
config: xdg-shell-protocol.o wlr-layer-shell-unstable-v1-protocol.o wlr-screencopy-unstable-v1-protocol.o idle-protocol.o
diff --git a/assets/wall_2K.png b/assets/wall_2K.png
new file mode 100644
index 00000000..9f7cabc0
--- /dev/null
+++ b/assets/wall_2K.png
Binary files differ
diff --git a/assets/wall_4K.png b/assets/wall_4K.png
new file mode 100644
index 00000000..925b4476
--- /dev/null
+++ b/assets/wall_4K.png
Binary files differ
diff --git a/assets/wall_8K.png b/assets/wall_8K.png
new file mode 100644
index 00000000..132276c5
--- /dev/null
+++ b/assets/wall_8K.png
Binary files differ
diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp
index 0c34005f..669cf354 100644
--- a/src/events/Monitors.cpp
+++ b/src/events/Monitors.cpp
@@ -115,6 +115,7 @@ void Events::listener_monitorFrame(void* owner, void* data) {
g_pHyprOpenGL->begin(PMONITOR);
g_pHyprOpenGL->clear(CColor(11, 11, 11, 255));
+ g_pHyprOpenGL->clearWithTex(); // will apply the hypr "wallpaper"
g_pHyprRenderer->renderAllClientsForMonitor(PMONITOR->ID, &now);
diff --git a/src/helpers/WLListener.cpp b/src/helpers/WLListener.cpp
index 1c9b4335..adaab288 100644
--- a/src/helpers/WLListener.cpp
+++ b/src/helpers/WLListener.cpp
@@ -25,7 +25,6 @@ void CHyprWLListener::removeCallback() {
if (m_bIsConnected) {
Debug::log(LOG, "Callback %x -> %x, %s removed.", m_pCallback, m_pOwner, m_szAuthor.c_str());
wl_list_remove(&m_sListener.link);
- wl_list_init(&m_sListener.link);
}
m_bIsConnected = false;
@@ -36,6 +35,9 @@ bool CHyprWLListener::isConnected() {
}
void CHyprWLListener::initCallback(wl_signal* pSignal, std::function<void(void*, void*)> callback, void* pOwner, std::string author) {
+ if (m_bIsConnected)
+ removeCallback();
+
m_pOwner = pOwner;
m_pCallback = callback;
m_szAuthor = author;
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp
index 31934d98..acc5096f 100644
--- a/src/render/OpenGL.cpp
+++ b/src/render/OpenGL.cpp
@@ -127,8 +127,10 @@ void CHyprOpenGLImpl::begin(SMonitor* pMonitor) {
m_iWLROutputFb = m_iCurrentOutputFb;
// ensure a framebuffer for the monitor exists
- if (m_mMonitorFramebuffers.find(pMonitor) == m_mMonitorFramebuffers.end() || m_mMonitorFramebuffers[pMonitor].m_Size != pMonitor->vecSize)
+ if (m_mMonitorFramebuffers.find(pMonitor) == m_mMonitorFramebuffers.end() || m_mMonitorFramebuffers[pMonitor].m_Size != pMonitor->vecSize) {
m_mMonitorFramebuffers[pMonitor].alloc(pMonitor->vecSize.x, pMonitor->vecSize.y);
+ createBGTextureForMonitor(pMonitor);
+ }
// bind the Hypr Framebuffer
m_mMonitorFramebuffers[pMonitor].bind();
@@ -491,6 +493,7 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
}
void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) {
+ RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!");
const auto PWINDOW = *pWindow;
auto it = m_mWindowFramebuffers.begin();
@@ -511,4 +514,55 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) {
wlr_matrix_project_box(matrix, &windowBox, TRANSFORM, 0, PMONITOR->output->transform_matrix);
renderTexture(it->second.m_cTex, matrix, PWINDOW->m_fAlpha, 0);
+}
+
+void CHyprOpenGLImpl::createBGTextureForMonitor(SMonitor* pMonitor) {
+ RASSERT(m_RenderData.pMonitor, "Tried to createBGTex without begin()!");
+
+ // release the last tex if exists
+ const auto PTEX = &m_mMonitorBGTextures[pMonitor];
+ PTEX->destroyTexture();
+
+ PTEX->allocate();
+
+ // check if wallpapers exist
+ if (!std::filesystem::exists("/usr/share/hyprland/wall_8K.png"))
+ return; // the texture will be empty, oh well. We'll clear with a solid color anyways.
+
+ // get the adequate tex
+ std::string texPath = "/usr/share/hyprland/wall_";
+ if (pMonitor->vecSize.x > 7000)
+ texPath += "8K.png";
+ else if (pMonitor->vecSize.x > 3000)
+ texPath += "4K.png";
+ else
+ texPath += "2K.png";
+
+ // create a new one with cairo
+ const auto CAIROSURFACE = cairo_image_surface_create_from_png(texPath.c_str());
+
+ const auto CAIRO = cairo_create(CAIROSURFACE);
+
+ // copy the data to an OpenGL texture we have
+ const auto DATA = cairo_image_surface_get_data(CAIROSURFACE);
+ glBindTexture(GL_TEXTURE_2D, PTEX->m_iTexID);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pMonitor->vecSize.x, pMonitor->vecSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, DATA);
+
+ cairo_surface_destroy(CAIROSURFACE);
+ cairo_destroy(CAIRO);
+}
+
+void CHyprOpenGLImpl::clearWithTex() {
+ RASSERT(m_RenderData.pMonitor, "Tried to render BGtex without begin()!");
+
+ const auto TRANSFORM = wlr_output_transform_invert(WL_OUTPUT_TRANSFORM_NORMAL);
+ float matrix[9];
+ wlr_box box = {0, 0, m_RenderData.pMonitor->vecSize.x, m_RenderData.pMonitor->vecSize.y};
+ wlr_matrix_project_box(matrix, &box, TRANSFORM, 0, m_RenderData.pMonitor->output->transform_matrix);
+
+ renderTexture(m_mMonitorBGTextures[m_RenderData.pMonitor], matrix, 255, 0);
} \ No newline at end of file
diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp
index bc2c6d88..f18e48af 100644
--- a/src/render/OpenGL.hpp
+++ b/src/render/OpenGL.hpp
@@ -47,6 +47,7 @@ public:
void renderSnapshot(CWindow**);
void clear(const CColor&);
+ void clearWithTex();
void scissor(const wlr_box*);
SCurrentRenderData m_RenderData;
@@ -56,6 +57,7 @@ public:
std::unordered_map<CWindow*, CFramebuffer> m_mWindowFramebuffers;
std::unordered_map<SMonitor*, CFramebuffer> m_mMonitorFramebuffers;
+ std::unordered_map<SMonitor*, CTexture> m_mMonitorBGTextures;
private:
std::list<GLuint> m_lBuffers;
@@ -75,6 +77,7 @@ private:
GLuint createProgram(const std::string&, const std::string&);
GLuint compileShader(const GLuint&, std::string);
+ void createBGTextureForMonitor(SMonitor*);
};
inline std::unique_ptr<CHyprOpenGLImpl> g_pHyprOpenGL; \ No newline at end of file