Skip to content

Commit f3ff994

Browse files
committed
feat: add Synced (Blur) theme option with background blur and tint
1 parent 6221797 commit f3ff994

7 files changed

Lines changed: 97 additions & 7 deletions

File tree

src/greeter/appearance_sync.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace greeter::appearance {
1717
inline constexpr const char* kGreeterConfFileName = "greeter.conf";
1818
inline constexpr const char* kWallpaperBaseName = "wallpaper";
1919
inline constexpr const char* kSyncedSchemeDisplayName = "Synced";
20+
inline constexpr const char* kSyncedBlurSchemeDisplayName = "Synced (Blur)";
2021
inline constexpr const char* kSyncedDataDirEnv = "NOCTALIA_GREETER_STATE_DIR";
2122

2223
[[nodiscard]] std::filesystem::path syncedDataDirectory();

src/greeter/greeter_surface.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ void GreeterSurface::buildSchemeNames() {
13031303
m_syncedAppearance = loadGreeterSyncedAppearance();
13041304
if (m_syncedAppearance.has_value()) {
13051305
m_schemeNames.emplace_back(greeter::appearance::kSyncedSchemeDisplayName);
1306+
m_schemeNames.emplace_back(greeter::appearance::kSyncedBlurSchemeDisplayName);
13061307
m_selectedScheme = 0;
13071308
}
13081309

@@ -1315,8 +1316,12 @@ void GreeterSurface::buildSchemeNames() {
13151316
}
13161317

13171318
bool GreeterSurface::isSyncedScheme(const std::size_t schemeIndex) const {
1318-
return schemeIndex < m_schemeNames.size()
1319-
&& m_schemeNames[schemeIndex] == greeter::appearance::kSyncedSchemeDisplayName;
1319+
if (schemeIndex >= m_schemeNames.size()) {
1320+
return false;
1321+
}
1322+
const auto& name = m_schemeNames[schemeIndex];
1323+
return name == greeter::appearance::kSyncedSchemeDisplayName
1324+
|| name == greeter::appearance::kSyncedBlurSchemeDisplayName;
13201325
}
13211326

13221327
std::optional<std::size_t> GreeterSurface::findSchemeIndex(const std::string_view name) const {
@@ -1334,6 +1339,10 @@ void GreeterSurface::clearWallpaperDisplay() {
13341339
m_wallpaperFillMode = WallpaperFillMode::Crop;
13351340
m_wallpaperFillColor = rgba(0.0f, 0.0f, 0.0f, 0.0f);
13361341
m_wallpaperDirty = true;
1342+
if (m_wallpaper != nullptr) {
1343+
m_wallpaper->setBlurRadius(0.0f);
1344+
m_wallpaper->setTintColor(rgba(0.0f, 0.0f, 0.0f, 0.0f));
1345+
}
13371346
}
13381347

13391348
void GreeterSurface::applyScheme(const std::size_t schemeIndex) {
@@ -1360,6 +1369,19 @@ void GreeterSurface::applyScheme(const std::size_t schemeIndex) {
13601369
m_wallpaperFillColor = m_syncedAppearance->wallpaperFillColor;
13611370
m_hasSyncedWallpaper = !m_wallpaperPath.empty();
13621371
m_wallpaperDirty = true;
1372+
1373+
if (m_wallpaper != nullptr) {
1374+
const bool isBlur = m_schemeNames[schemeIndex] == greeter::appearance::kSyncedBlurSchemeDisplayName;
1375+
if (isBlur) {
1376+
Color tint = m_syncedAppearance->palette.surface;
1377+
tint.a = 0.4f;
1378+
m_wallpaper->setBlurRadius(30.0f);
1379+
m_wallpaper->setTintColor(tint);
1380+
} else {
1381+
m_wallpaper->setBlurRadius(0.0f);
1382+
m_wallpaper->setTintColor(rgba(0.0f, 0.0f, 0.0f, 0.0f));
1383+
}
1384+
}
13631385
return;
13641386
}
13651387

src/render/backend/gles_render_backend.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ void GlesRenderBackend::makeCurrent(RenderTarget& target) {
242242
void GlesRenderBackend::beginFrame(RenderTarget& target) {
243243
makeCurrent(target);
244244

245-
setViewport(target.bufferWidth(), target.bufferHeight());
245+
m_bufferWidth = target.bufferWidth();
246+
m_bufferHeight = target.bufferHeight();
247+
248+
setViewport(m_bufferWidth, m_bufferHeight);
246249
setBlendMode(RenderBlendMode::PremultipliedAlpha);
247250
disableScissor();
248251
clear(rgba(0.0f, 0.0f, 0.0f, 0.0f));
@@ -425,8 +428,48 @@ void GlesRenderBackend::drawWallpaper(
425428
WallpaperSourceKind sourceKind2, TextureId texture2, const Color& sourceColor2, float surfaceWidth,
426429
float surfaceHeight, float width, float height, float imageWidth1, float imageHeight1, float imageWidth2,
427430
float imageHeight2, float progress, float fillMode, const TransitionParams& params, const Color& fillColor,
428-
const Mat3& transform
431+
const Mat3& transform, float blurRadius, const Color& tintColor
429432
) {
433+
if (blurRadius > 0.0f) {
434+
const std::uint32_t targetWidth = m_bufferWidth > 0 ? m_bufferWidth : static_cast<std::uint32_t>(surfaceWidth);
435+
const std::uint32_t targetHeight = m_bufferHeight > 0 ? m_bufferHeight : static_cast<std::uint32_t>(surfaceHeight);
436+
const std::uint32_t fbWidth = std::max(1u, targetWidth / 4);
437+
const std::uint32_t fbHeight = std::max(1u, targetHeight / 4);
438+
439+
auto fb1 = createFramebuffer(fbWidth, fbHeight);
440+
auto fb2 = createFramebuffer(fbWidth, fbHeight);
441+
442+
if (fb1 != nullptr && fb2 != nullptr && fb1->valid() && fb2->valid()) {
443+
bindFramebuffer(*fb1);
444+
setViewport(fbWidth, fbHeight);
445+
clear(rgba(0.0f, 0.0f, 0.0f, 0.0f));
446+
447+
m_wallpaperProgram.ensureInitialized();
448+
m_wallpaperProgram.draw(
449+
transition, sourceKind1, texture1, sourceColor1, sourceKind2, texture2, sourceColor2, surfaceWidth,
450+
surfaceHeight, width, height, imageWidth1, imageHeight1, imageWidth2, imageHeight2, progress, fillMode,
451+
params, fillColor, transform
452+
);
453+
454+
bindFramebuffer(*fb2);
455+
setViewport(fbWidth, fbHeight);
456+
clear(rgba(0.0f, 0.0f, 0.0f, 0.0f));
457+
drawFramebufferBlur(fb1->colorTexture(), fbWidth, fbHeight, 1.0f, 0.0f, blurRadius);
458+
459+
bindDefaultFramebuffer();
460+
setViewport(targetWidth, targetHeight);
461+
drawFramebufferBlur(fb2->colorTexture(), fbWidth, fbHeight, 0.0f, 1.0f, blurRadius);
462+
463+
if (tintColor.a > 0.0f) {
464+
setBlendMode(RenderBlendMode::StraightAlpha);
465+
drawFullscreenTint(tintColor);
466+
setBlendMode(RenderBlendMode::PremultipliedAlpha);
467+
}
468+
return;
469+
}
470+
}
471+
472+
>>>>>>> b798c8b (feat: add Synced (Blur) theme option with background blur and tint)
430473
m_wallpaperProgram.ensureInitialized();
431474
m_wallpaperProgram.draw(
432475
transition, sourceKind1, texture1, sourceColor1, sourceKind2, texture2, sourceColor2, surfaceWidth, surfaceHeight,

src/render/backend/gles_render_backend.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class GlesRenderBackend final : public RenderBackend {
7474
WallpaperSourceKind sourceKind2, TextureId texture2, const Color& sourceColor2, float surfaceWidth,
7575
float surfaceHeight, float width, float height, float imageWidth1, float imageHeight1, float imageWidth2,
7676
float imageHeight2, float progress, float fillMode, const TransitionParams& params, const Color& fillColor,
77-
const Mat3& transform
77+
const Mat3& transform, float blurRadius = 0.0f, const Color& tintColor = rgba(0.0f, 0.0f, 0.0f, 0.0f)
7878
) override;
7979
void drawFullscreenTexture(TextureId texture, bool flipY) override;
8080
void drawFullscreenTint(Color color) override;
@@ -94,6 +94,8 @@ class GlesRenderBackend final : public RenderBackend {
9494
EGLConfig m_config = nullptr;
9595
EGLContext m_context = EGL_NO_CONTEXT;
9696
int m_maxTextureSize = 0;
97+
std::uint32_t m_bufferWidth = 0;
98+
std::uint32_t m_bufferHeight = 0;
9799
GlesTextureManager m_textureManager;
98100
RectProgram m_rectProgram;
99101
ImageProgram m_imageProgram;

src/render/backend/render_backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class RenderBackend {
148148
WallpaperSourceKind sourceKind2, TextureId texture2, const Color& sourceColor2, float surfaceWidth,
149149
float surfaceHeight, float width, float height, float imageWidth1, float imageHeight1, float imageWidth2,
150150
float imageHeight2, float progress, float fillMode, const TransitionParams& params, const Color& fillColor,
151-
const Mat3& transform
151+
const Mat3& transform, float blurRadius = 0.0f, const Color& tintColor = rgba(0.0f, 0.0f, 0.0f, 0.0f)
152152
) = 0;
153153
virtual void drawFullscreenTexture(TextureId texture, bool flipY) = 0;
154154
virtual void drawFullscreenTint(Color color) = 0;

src/render/render_context.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ void RenderContext::renderNode(
349349
wallpaper->transition(), wallpaper->sourceKind1(), wallpaper->texture1(), wallpaper->sourceColor1(),
350350
sourceKind2, texture2, sourceColor2, sw, sh, node->width(), node->height(), wallpaper->imageWidth1(),
351351
wallpaper->imageHeight1(), imageWidth2, imageHeight2, progress, static_cast<float>(wallpaper->fillMode()),
352-
wallpaper->transitionParams(), wallpaper->fillColor(), worldTransform
352+
wallpaper->transitionParams(), wallpaper->fillColor(), worldTransform, wallpaper->blurRadius(),
353+
wallpaper->tintColor()
353354
);
354355
}
355356
break;

src/render/scene/wallpaper_node.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ class WallpaperNode : public Node {
104104
markPaintDirty();
105105
}
106106

107+
[[nodiscard]] float blurRadius() const noexcept { return m_blurRadius; }
108+
[[nodiscard]] const Color& tintColor() const noexcept { return m_tintColor; }
109+
110+
void setBlurRadius(float radius) {
111+
if (m_blurRadius == radius) {
112+
return;
113+
}
114+
m_blurRadius = radius;
115+
markPaintDirty();
116+
}
117+
118+
void setTintColor(const Color& tintColor) {
119+
if (m_tintColor == tintColor) {
120+
return;
121+
}
122+
m_tintColor = tintColor;
123+
markPaintDirty();
124+
}
125+
107126
private:
108127
WallpaperSourceKind m_sourceKind1 = WallpaperSourceKind::Image;
109128
WallpaperSourceKind m_sourceKind2 = WallpaperSourceKind::Image;
@@ -120,4 +139,6 @@ class WallpaperNode : public Node {
120139
WallpaperFillMode m_fillMode = WallpaperFillMode::Crop;
121140
Color m_fillColor = rgba(0.0f, 0.0f, 0.0f, 1.0f);
122141
TransitionParams m_params;
142+
float m_blurRadius = 0.0f;
143+
Color m_tintColor = rgba(0.0f, 0.0f, 0.0f, 0.0f);
123144
};

0 commit comments

Comments
 (0)