From f96b611651f5bbaf2b0401d44f4250f699b15be2 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sat, 30 Jul 2022 22:41:24 +0200 Subject: [PATCH] support wlr-output-power-management --- Makefile | 12 +- ...lr-output-power-management-unstable-v1.xml | 128 ++++++++++++++++++ src/Compositor.cpp | 3 + src/Compositor.hpp | 1 + src/events/Events.hpp | 3 + src/events/Misc.cpp | 11 ++ src/includes.hpp | 1 + 7 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 protocols/wlr-output-power-management-unstable-v1.xml diff --git a/Makefile b/Makefile index 04bb72de..b1f120ce 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,16 @@ idle-protocol.c: idle-protocol.o: idle-protocol.h +wlr-output-power-management-unstable-v1-protocol.h: + $(WAYLAND_SCANNER) server-header \ + protocols/wlr-output-power-management-unstable-v1.xml $@ + +wlr-output-power-management-unstable-v1-protocol.c: + $(WAYLAND_SCANNER) private-code \ + protocols/wlr-output-power-management-unstable-v1.xml $@ + +wlr-output-power-management-unstable-v1-protocol.o: wlr-output-power-management-unstable-v1-protocol.h + legacyrenderer: mkdir -p build && cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DLEGACY_RENDERER:STRING=true -H./ -B./build -G Ninja cmake --build ./build --config Release --target all -j 10 @@ -133,7 +143,7 @@ uninstall: rm -f /usr/lib/libwlroots.so.11032 rm -rf ${PREFIX}/share/hyprland -protocols: xdg-shell-protocol.o wlr-layer-shell-unstable-v1-protocol.o wlr-screencopy-unstable-v1-protocol.o idle-protocol.o ext-workspace-unstable-v1-protocol.o pointer-constraints-unstable-v1-protocol.o tablet-unstable-v2-protocol.o +protocols: xdg-shell-protocol.o wlr-layer-shell-unstable-v1-protocol.o wlr-screencopy-unstable-v1-protocol.o idle-protocol.o ext-workspace-unstable-v1-protocol.o pointer-constraints-unstable-v1-protocol.o tablet-unstable-v2-protocol.o wlr-output-power-management-unstable-v1-protocol.o fixwlr: sed -i -E 's/(soversion = 11)([^032]|$$)/soversion = 11032/g' subprojects/wlroots/meson.build diff --git a/protocols/wlr-output-power-management-unstable-v1.xml b/protocols/wlr-output-power-management-unstable-v1.xml new file mode 100644 index 00000000..a9778399 --- /dev/null +++ b/protocols/wlr-output-power-management-unstable-v1.xml @@ -0,0 +1,128 @@ + + + + Copyright © 2019 Purism SPC + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + + + This protocol allows clients to control power management modes + of outputs that are currently part of the compositor space. The + intent is to allow special clients like desktop shells to power + down outputs when the system is idle. + + To modify outputs not currently part of the compositor space see + wlr-output-management. + + Warning! The protocol described in this file is experimental and + backward incompatible changes may be made. Backward compatible changes + may be added together with the corresponding interface version bump. + Backward incompatible changes are done by bumping the version number in + the protocol and interface names and resetting the interface version. + Once the protocol is to be declared stable, the 'z' prefix and the + version number in the protocol and interface names are removed and the + interface version number is reset. + + + + + This interface is a manager that allows creating per-output power + management mode controls. + + + + + Create a output power management mode control that can be used to + adjust the power management mode for a given output. + + + + + + + + All objects created by the manager will still remain valid, until their + appropriate destroy request has been called. + + + + + + + This object offers requests to set the power management mode of + an output. + + + + + + + + + + + + + + Set an output's power save mode to the given mode. The mode change + is effective immediately. If the output does not support the given + mode a failed event is sent. + + + + + + + Report the power management mode change of an output. + + The mode event is sent after an output changed its power + management mode. The reason can be a client using set_mode or the + compositor deciding to change an output's mode. + This event is also sent immediately when the object is created + so the client is informed about the current power management mode. + + + + + + + This event indicates that the output power management mode control + is no longer valid. This can happen for a number of reasons, + including: + - The output doesn't support power management + - Another client already has exclusive power management mode control + for this output + - The output disappeared + + Upon receiving this event, the client should destroy this object. + + + + + + Destroys the output power management mode control object. + + + + diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 74c3a1e8..714a0351 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -96,6 +96,8 @@ CCompositor::CCompositor() { m_sWLROutputLayout = wlr_output_layout_create(); + m_sWLROutputPowerMgr = wlr_output_power_manager_v1_create(m_sWLDisplay); + m_sWLRScene = wlr_scene_create(); wlr_scene_attach_output_layout(m_sWLRScene, m_sWLROutputLayout); @@ -195,6 +197,7 @@ void CCompositor::initAllSignals() { addWLSignal(&m_sWLRVirtPtrMgr->events.new_virtual_pointer, &Events::listen_newVirtPtr, m_sWLRVirtPtrMgr, "VirtPtrMgr"); addWLSignal(&m_sWLRRenderer->events.destroy, &Events::listen_RendererDestroy, m_sWLRRenderer, "WLRRenderer"); addWLSignal(&m_sWLRIdleInhibitMgr->events.new_inhibitor, &Events::listen_newIdleInhibitor, m_sWLRIdleInhibitMgr, "WLRIdleInhibitMgr"); + addWLSignal(&m_sWLROutputPowerMgr->events.set_mode, &Events::listen_powerMgrSetMode, m_sWLROutputPowerMgr, "PowerMgr"); if (m_sWLRSession) addWLSignal(&m_sWLRSession->events.active, &Events::listen_sessionActive, m_sWLRSession, "Session"); } diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 00b758e3..0357e08f 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -65,6 +65,7 @@ public: wlr_xdg_foreign_registry* m_sWLRForeignRegistry; wlr_idle_inhibit_manager_v1* m_sWLRIdleInhibitMgr; wlr_pointer_gestures_v1* m_sWLRPointerGestures; + wlr_output_power_manager_v1* m_sWLROutputPowerMgr; // ------------------------------------------------- // diff --git a/src/events/Events.hpp b/src/events/Events.hpp index ba8088a8..db15eceb 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -130,4 +130,7 @@ namespace Events { LISTENER(pinchBegin); LISTENER(pinchUpdate); LISTENER(pinchEnd); + + // Power + LISTENER(powerMgrSetMode); }; \ No newline at end of file diff --git a/src/events/Misc.cpp b/src/events/Misc.cpp index 503d2111..5caa8984 100644 --- a/src/events/Misc.cpp +++ b/src/events/Misc.cpp @@ -163,4 +163,15 @@ void Events::listener_sessionActive(wl_listener* listener, void* data) { Debug::log(LOG, "Session got activated!"); g_pCompositor->m_bSessionActive = true; +} + +void Events::listener_powerMgrSetMode(wl_listener* listener, void* data) { + Debug::log(LOG, "PowerMgr set mode!"); + + const auto EVENT = (wlr_output_power_v1_set_mode_event*)data; + + wlr_output_enable(EVENT->output, EVENT->mode == 1); + + if (!wlr_output_commit(EVENT->output)) + Debug::log(ERR, "Couldn't set power mode"); } \ No newline at end of file diff --git a/src/includes.hpp b/src/includes.hpp index e8367f50..8b350611 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -93,6 +93,7 @@ extern "C" { #include #include #include +#include } #undef class