dwl-patches/patches/scenefx/scenefx.patch

376 lines
12 KiB
Diff

From 2d4fb60abd6284236ce4ba0b9c3b562165937963 Mon Sep 17 00:00:00 2001
From: wochap <gean.marroquin@gmail.com>
Date: Fri, 5 Jul 2024 11:45:43 -0500
Subject: [PATCH] implement scenefx
---
Makefile | 2 +-
client.h | 11 +++-
config.def.h | 28 ++++++++-
dwl.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 191 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile
index 0d651e7..0ae18a7 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ DWLDEVCFLAGS = -g -pedantic -Wall -Wextra -Wdeclaration-after-statement \
-Wfloat-conversion
# CFLAGS / LDFLAGS
-PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS)
+PKGS = scenefx wlroots wayland-server xkbcommon libinput $(XLIBS)
DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS)
LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` -lm $(LIBS)
diff --git a/client.h b/client.h
index 42f225f..f75b3ff 100644
--- a/client.h
+++ b/client.h
@@ -131,7 +131,7 @@ client_get_appid(Client *c)
return c->surface.xdg->toplevel->app_id;
}
-static inline void
+static inline int
client_get_clip(Client *c, struct wlr_box *clip)
{
struct wlr_box xdg_geom = {0};
@@ -144,12 +144,19 @@ client_get_clip(Client *c, struct wlr_box *clip)
#ifdef XWAYLAND
if (client_is_x11(c))
- return;
+ return 1;
#endif
wlr_xdg_surface_get_geometry(c->surface.xdg, &xdg_geom);
clip->x = xdg_geom.x;
clip->y = xdg_geom.y;
+
+ if (xdg_geom.width <= c->geom.width - (int)c->bw
+ && xdg_geom.height <= c->geom.height - (int)c->bw) {
+ return 0;
+ }
+
+ return 1;
}
static inline void
diff --git a/config.def.h b/config.def.h
index 22d2171..d28e698 100644
--- a/config.def.h
+++ b/config.def.h
@@ -12,7 +12,33 @@ static const float bordercolor[] = COLOR(0x444444ff);
static const float focuscolor[] = COLOR(0x005577ff);
static const float urgentcolor[] = COLOR(0xff0000ff);
/* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
-static const float fullscreen_bg[] = {0.1f, 0.1f, 0.1f, 1.0f}; /* You can also use glsl colors */
+static const float fullscreen_bg[] = {0.1f, 0.1f, 0.1f, 0.0f}; /* You can also use glsl colors */
+
+static const int opacity = 0; /* flag to enable opacity */
+static const float opacity_inactive = 0.5;
+static const float opacity_active = 1.0;
+
+static const int shadow = 1; /* flag to enable shadow */
+static const int shadow_only_floating = 0; /* only apply shadow to floating windows */
+static const struct wlr_render_color shadow_color = COLOR(0x0000FFff);
+static const struct wlr_render_color shadow_color_focus = COLOR(0xFF0000ff);
+static const int shadow_blur_sigma = 20;
+static const int shadow_blur_sigma_focus = 40;
+static const char *const shadow_ignore_list[] = { "xdg-desktop-portal-gtk", NULL }; /* list of app-id to ignore */
+
+static const int corner_radius = 0; /* 0 disables corner_radius */
+
+static const int blur = 1; /* flag to enable blur */
+static const int blur_optimized = 1;
+static const int blur_ignore_transparent = 1;
+static const struct blur_data blur_data = {
+ .radius = 5,
+ .num_passes = 3,
+ .noise = (float)0.02,
+ .brightness = (float)0.9,
+ .contrast = (float)0.9,
+ .saturation = (float)1.1,
+};
/* tagging - TAGCOUNT must be no greater than 31 */
#define TAGCOUNT (9)
diff --git a/dwl.c b/dwl.c
index dc0437e..d69054a 100644
--- a/dwl.c
+++ b/dwl.c
@@ -10,6 +10,10 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <time.h>
+#include <scenefx/render/fx_renderer/fx_renderer.h>
+#include <scenefx/types/fx/blur_data.h>
+#include <scenefx/types/fx/shadow_data.h>
+#include <scenefx/types/wlr_scene.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
@@ -42,7 +46,6 @@
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_primary_selection_v1.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
-#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_server_decoration.h>
@@ -140,6 +143,10 @@ typedef struct {
uint32_t tags;
int isfloating, isurgent, isfullscreen;
uint32_t resize; /* configure serial of a pending resize */
+
+ float opacity;
+ int corner_radius;
+ struct shadow_data shadow_data;
} Client;
typedef struct {
@@ -351,6 +358,9 @@ static Monitor *xytomon(double x, double y);
static void xytonode(double x, double y, struct wlr_surface **psurface,
Client **pc, LayerSurface **pl, double *nx, double *ny);
static void zoom(const Arg *arg);
+static int in_shadow_ignore_list(const char *str);
+static void iter_xdg_scene_buffers(struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data);
+static void iter_xdg_scene_buffers_shadow(struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data);
/* variables */
static const char broken[] = "broken";
@@ -1045,6 +1055,13 @@ createnotify(struct wl_listener *listener, void *data)
wlr_xdg_toplevel_set_wm_capabilities(xdg_surface->toplevel,
WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN);
+ c->opacity = opacity;
+ c->corner_radius = corner_radius;
+ c->shadow_data = shadow_data_get_default();
+ c->shadow_data.enabled = shadow_only_floating != 1 && !in_shadow_ignore_list(client_get_appid(c));
+ c->shadow_data.blur_sigma = shadow_blur_sigma;
+ c->shadow_data.color = shadow_color;
+
LISTEN(&xdg_surface->events.destroy, &c->destroy, destroynotify);
LISTEN(&xdg_surface->surface->events.commit, &c->commit, commitnotify);
LISTEN(&xdg_surface->surface->events.map, &c->map, mapnotify);
@@ -1346,8 +1363,21 @@ focusclient(Client *c, int lift)
/* Don't change border color if there is an exclusive focus or we are
* handling a drag operation */
- if (!exclusive_focus && !seat->drag)
+ if (!exclusive_focus && !seat->drag) {
client_set_border_color(c, focuscolor);
+ if (shadow) {
+ c->shadow_data.blur_sigma = shadow_blur_sigma_focus;
+ c->shadow_data.color = shadow_color_focus;
+ }
+ if (opacity) {
+ c->opacity = opacity_active;
+ }
+ if (opacity) {
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, iter_xdg_scene_buffers, c);
+ } else if (shadow) {
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, iter_xdg_scene_buffers_shadow, c);
+ }
+ }
}
/* Deactivate old client if focus is changing */
@@ -1365,6 +1395,18 @@ focusclient(Client *c, int lift)
* and probably other clients */
} else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
client_set_border_color(old_c, bordercolor);
+ if (shadow) {
+ old_c->shadow_data.blur_sigma = shadow_blur_sigma;
+ old_c->shadow_data.color = shadow_color;
+ }
+ if (opacity) {
+ old_c->opacity = opacity_inactive;
+ }
+ if (opacity) {
+ wlr_scene_node_for_each_buffer(&old_c->scene_surface->node, iter_xdg_scene_buffers, old_c);
+ } else if (shadow) {
+ wlr_scene_node_for_each_buffer(&old_c->scene_surface->node, iter_xdg_scene_buffers_shadow, old_c);
+ }
client_activate_surface(old, 0);
}
@@ -1653,6 +1695,8 @@ mapnotify(struct wl_listener *listener, void *data)
client_get_geometry(c, &c->geom);
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, iter_xdg_scene_buffers, c);
+
/* Handle unmanaged clients first so we can return prior create borders */
if (client_is_unmanaged(c)) {
/* Unmanaged clients always are floating */
@@ -1692,6 +1736,15 @@ mapnotify(struct wl_listener *listener, void *data)
}
printstatus();
+ if (shadow && shadow_only_floating) {
+ if (c->isfloating && !in_shadow_ignore_list(client_get_appid(c))) {
+ c->shadow_data.enabled = 1;
+ } else {
+ c->shadow_data.enabled = 0;
+ }
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, iter_xdg_scene_buffers_shadow, c);
+ }
+
unset_fullscreen:
m = c->mon ? c->mon : xytomon(c->geom.x, c->geom.y);
wl_list_for_each(w, &clients, link) {
@@ -2132,6 +2185,7 @@ resize(Client *c, struct wlr_box geo, int interact)
{
struct wlr_box *bbox;
struct wlr_box clip;
+ int should_clip;
if (!c->mon || !c->scene)
return;
@@ -2156,8 +2210,12 @@ resize(Client *c, struct wlr_box geo, int interact)
/* this is a no-op if size hasn't changed */
c->resize = client_set_size(c, c->geom.width - 2 * c->bw,
c->geom.height - 2 * c->bw);
- client_get_clip(c, &clip);
- wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
+ should_clip = client_get_clip(c, &clip);
+ if (should_clip) {
+ wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
+ } else {
+ wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, NULL);
+ }
}
void
@@ -2258,6 +2316,14 @@ setfloating(Client *c, int floating)
{
Client *p = client_get_parent(c);
c->isfloating = floating;
+ if (shadow && shadow_only_floating) {
+ if (c->isfloating && !in_shadow_ignore_list(client_get_appid(c))) {
+ c->shadow_data.enabled = 1;
+ } else {
+ c->shadow_data.enabled = 0;
+ }
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, iter_xdg_scene_buffers_shadow, c);
+ }
/* If in floating layout do not change the client's layer */
if (!c->mon || !client_surface(c)->mapped || !c->mon->lt[c->mon->sellt]->arrange)
return;
@@ -2407,11 +2473,15 @@ setup(void)
drag_icon = wlr_scene_tree_create(&scene->tree);
wlr_scene_node_place_below(&drag_icon->node, &layers[LyrBlock]->node);
+ // if (blur) {
+ // wlr_scene_set_blur_data(scene, blur_data);
+ // }
+
/* Autocreates a renderer, either Pixman, GLES2 or Vulkan for us. The user
* can also specify a renderer using the WLR_RENDERER env var.
* The renderer is responsible for defining the various pixel formats it
* supports for shared memory, this configures that for clients. */
- if (!(drw = wlr_renderer_autocreate(backend)))
+ if (!(drw = fx_renderer_create(backend)))
die("couldn't create renderer");
/* Create shm, drm and linux_dmabuf interfaces by ourselves.
@@ -2888,8 +2958,14 @@ urgent(struct wl_listener *listener, void *data)
c->isurgent = 1;
printstatus();
- if (client_surface(c)->mapped)
+ if (client_surface(c)->mapped) {
client_set_border_color(c, urgentcolor);
+ if (shadow) {
+ c->shadow_data.blur_sigma = shadow_blur_sigma_focus;
+ c->shadow_data.color = shadow_color_focus;
+ wlr_scene_node_for_each_buffer(&c->scene_surface->node, iter_xdg_scene_buffers_shadow, c);
+ }
+ }
}
void
@@ -3001,6 +3077,78 @@ zoom(const Arg *arg)
arrange(selmon);
}
+int
+in_shadow_ignore_list(const char *str) {
+ for (int i = 0; shadow_ignore_list[i] != NULL; i++) {
+ if (strcmp(shadow_ignore_list[i], str) == 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void
+iter_xdg_scene_buffers(struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data)
+{
+ Client *c = user_data;
+ struct wlr_scene_surface * scene_surface = wlr_scene_surface_try_from_buffer(buffer);
+ struct wlr_xdg_surface *xdg_surface;
+
+ if (!scene_surface) {
+ return;
+ }
+
+ xdg_surface = wlr_xdg_surface_try_from_wlr_surface(scene_surface->surface);
+
+ if (c &&
+ xdg_surface &&
+ xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
+ // TODO: Be able to set whole decoration_data instead of calling
+ // each individually?
+ if (opacity) {
+ wlr_scene_buffer_set_opacity(buffer, c->opacity);
+ }
+
+ if (!wlr_subsurface_try_from_wlr_surface(xdg_surface->surface)) {
+ if (corner_radius > 0) {
+ wlr_scene_buffer_set_corner_radius(buffer, c->corner_radius);
+ }
+
+ if (shadow) {
+ wlr_scene_buffer_set_shadow_data(buffer, c->shadow_data);
+ }
+
+ // if (blur) {
+ // wlr_scene_buffer_set_backdrop_blur(buffer, 1);
+ // wlr_scene_buffer_set_backdrop_blur_optimized(buffer, blur_optimized);
+ // wlr_scene_buffer_set_backdrop_blur_ignore_transparent(buffer, blur_ignore_transparent);
+ // }
+ }
+ }
+}
+
+void
+iter_xdg_scene_buffers_shadow(struct wlr_scene_buffer *buffer, int sx, int sy, void *user_data)
+{
+ Client *c = user_data;
+ struct wlr_scene_surface * scene_surface = wlr_scene_surface_try_from_buffer(buffer);
+ struct wlr_xdg_surface *xdg_surface;
+
+ if (!scene_surface) {
+ return;
+ }
+
+ xdg_surface = wlr_xdg_surface_try_from_wlr_surface(scene_surface->surface);
+
+ if (c &&
+ xdg_surface &&
+ xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
+ if (!wlr_subsurface_try_from_wlr_surface(xdg_surface->surface)) {
+ wlr_scene_buffer_set_shadow_data(buffer, c->shadow_data);
+ }
+ }
+}
+
#ifdef XWAYLAND
void
activatex11(struct wl_listener *listener, void *data)
--
2.45.1