From 5af8444d1b3d16b9a62ac8198f6ae35bdf2ab73f Mon Sep 17 00:00:00 2001 From: korei999 Date: Wed, 29 Nov 2023 21:40:03 +0200 Subject: [PATCH] apply outputPowerManagement patch --- Makefile | 11 ++++++++--- dwl.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 168cfdb..c552269 100644 --- a/Makefile +++ b/Makefile @@ -5,18 +5,20 @@ include config.mk # flags for compiling DWLCPPFLAGS = -I. -DWLR_USE_UNSTABLE -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\" $(XWAYLAND) -DWLDEVCFLAGS = -g -pedantic -Wall -Wextra -Wdeclaration-after-statement -Wno-unused-parameter -Wno-sign-compare -Wshadow -Wunused-macros\ +DWLDEVCFLAGS = -pedantic -Wall -Wextra -Wdeclaration-after-statement -Wno-unused-parameter -Wno-sign-compare -Wshadow -Wunused-macros\ -Werror=strict-prototypes -Werror=implicit -Werror=return-type -Werror=incompatible-pointer-types # CFLAGS / LDFLAGS -PKGS = wlroots wayland-server xkbcommon libinput $(XLIBS) +CC = gcc -flto=auto +CFLAGS = -O2 -march=native +PKGS = wlroots wayland-server xkbcommon libinput pixman-1 $(XLIBS) DWLCFLAGS = `$(PKG_CONFIG) --cflags $(PKGS)` $(DWLCPPFLAGS) $(DWLDEVCFLAGS) $(CFLAGS) LDLIBS = `$(PKG_CONFIG) --libs $(PKGS)` $(LIBS) all: dwl dwl: dwl.o util.o $(CC) dwl.o util.o $(LDLIBS) $(LDFLAGS) $(DWLCFLAGS) -o $@ -dwl.o: dwl.c config.mk config.def.h client.h cursor-shape-v1-protocol.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h +dwl.o: dwl.c config.mk config.def.h client.h cursor-shape-v1-protocol.h xdg-shell-protocol.h wlr-layer-shell-unstable-v1-protocol.h wlr-output-power-management-unstable-v1-protocol.h util.o: util.c util.h # wayland-scanner is a tool which generates C headers and rigging for Wayland @@ -34,6 +36,9 @@ wlr-layer-shell-unstable-v1-protocol.h: cursor-shape-v1-protocol.h: $(WAYLAND_SCANNER) server-header \ $(WAYLAND_PROTOCOLS)/staging/cursor-shape/cursor-shape-v1.xml $@ +wlr-output-power-management-unstable-v1-protocol.h: + $(WAYLAND_SCANNER) server-header \ + protocols/wlr-output-power-management-unstable-v1.xml $@ clean: rm -f dwl *.o *-protocol.h diff --git a/dwl.c b/dwl.c index fa9a039..0c7f84d 100644 --- a/dwl.c +++ b/dwl.c @@ -31,8 +31,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -289,6 +291,8 @@ static void outputmgrtest(struct wl_listener *listener, void *data); static void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, uint32_t time); static void printstatus(void); +static void wlr_output_damage_whole(struct wlr_output *output); +static void powermgrsetmodenotify(struct wl_listener *listener, void *data); static void quit(const Arg *arg); static void rendermon(struct wl_listener *listener, void *data); static void requeststartdrag(struct wl_listener *listener, void *data); @@ -367,6 +371,9 @@ static struct wlr_scene_rect *locked_bg; static struct wlr_session_lock_v1 *cur_lock; static struct wl_listener lock_listener = {.notify = locksession}; +static struct wlr_output_power_manager_v1 *power_mgr; +static struct wl_listener power_mgr_set_mode = {.notify = powermgrsetmodenotify}; + static struct wlr_seat *seat; static struct wl_list keyboards; static unsigned int cursor_mode; @@ -1851,6 +1858,35 @@ printstatus(void) fflush(stdout); } +void +wlr_output_damage_whole(struct wlr_output *output) { + int width, height; + pixman_region32_t damage; + struct wlr_output_event_damage event; + + wlr_output_transformed_resolution(output, &width, &height); + + pixman_region32_init_rect(&damage, 0, 0, width, height); + + event = (struct wlr_output_event_damage){ + .output = output, + .damage = &damage, + }; + wl_signal_emit_mutable(&output->events.damage, &event); + + pixman_region32_fini(&damage); +} + +void +powermgrsetmodenotify(struct wl_listener *listener, void *data) +{ + struct wlr_output_power_v1_set_mode_event *event = data; + wlr_output_enable(event->output, event->mode); + if (event->mode) + wlr_output_damage_whole(event->output); + wlr_output_commit(event->output); +} + void quit(const Arg *arg) { @@ -2239,6 +2275,9 @@ setup(void) gamma_control_mgr = wlr_gamma_control_manager_v1_create(dpy); LISTEN_STATIC(&gamma_control_mgr->events.set_gamma, setgamma); + power_mgr = wlr_output_power_manager_v1_create(dpy); + wl_signal_add(&power_mgr->events.set_mode, &power_mgr_set_mode); + /* Creates an output layout, which a wlroots utility for working with an * arrangement of screens in a physical layout. */ output_layout = wlr_output_layout_create();