diff options
author | Vaxry <[email protected]> | 2024-04-29 01:28:26 +0100 |
---|---|---|
committer | Vaxry <[email protected]> | 2024-04-29 01:38:24 +0100 |
commit | 33e0bb14786dc22a0c82eaaf097b469d3fdeceea (patch) | |
tree | 0b4525880560950eeea48c6279ed41fa3dde0d67 /src | |
parent | a5a648091760ac002120fab18247e5292b6482de (diff) | |
download | Hyprland-33e0bb14786dc22a0c82eaaf097b469d3fdeceea.tar.gz Hyprland-33e0bb14786dc22a0c82eaaf097b469d3fdeceea.zip |
wlr-output-power: move to new impl
Diffstat (limited to 'src')
-rw-r--r-- | src/Compositor.cpp | 4 | ||||
-rw-r--r-- | src/Compositor.hpp | 1 | ||||
-rw-r--r-- | src/events/Events.hpp | 3 | ||||
-rw-r--r-- | src/events/Misc.cpp | 17 | ||||
-rw-r--r-- | src/helpers/Monitor.hpp | 2 | ||||
-rw-r--r-- | src/includes.hpp | 1 | ||||
-rw-r--r-- | src/managers/KeybindManager.cpp | 2 | ||||
-rw-r--r-- | src/managers/ProtocolManager.cpp | 3 | ||||
-rw-r--r-- | src/protocols/OutputPower.cpp | 80 | ||||
-rw-r--r-- | src/protocols/OutputPower.hpp | 50 | ||||
-rw-r--r-- | src/render/Renderer.cpp | 4 |
11 files changed, 141 insertions, 26 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index d178215c..d33c73d6 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -228,8 +228,6 @@ void CCompositor::initServer() { m_sWLROutputLayout = wlr_output_layout_create(m_sWLDisplay); - m_sWLROutputPowerMgr = wlr_output_power_manager_v1_create(m_sWLDisplay); - m_sWLRXDGShell = wlr_xdg_shell_create(m_sWLDisplay, 6); m_sWLRCursor = wlr_cursor_create(); @@ -319,7 +317,6 @@ void CCompositor::initAllSignals() { addWLSignal(&m_sWLRVirtPtrMgr->events.new_virtual_pointer, &Events::listen_newVirtPtr, m_sWLRVirtPtrMgr, "VirtPtrMgr"); addWLSignal(&m_sWLRVKeyboardMgr->events.new_virtual_keyboard, &Events::listen_newVirtualKeyboard, m_sWLRVKeyboardMgr, "VKeyboardMgr"); addWLSignal(&m_sWLRRenderer->events.destroy, &Events::listen_RendererDestroy, m_sWLRRenderer, "WLRRenderer"); - addWLSignal(&m_sWLROutputPowerMgr->events.set_mode, &Events::listen_powerMgrSetMode, m_sWLROutputPowerMgr, "PowerMgr"); addWLSignal(&m_sWLRIMEMgr->events.input_method, &Events::listen_newIME, m_sWLRIMEMgr, "IMEMgr"); addWLSignal(&m_sWLRActivation->events.request_activate, &Events::listen_activateXDG, m_sWLRActivation, "ActivationV1"); addWLSignal(&m_sWLRSessionLockMgr->events.new_lock, &Events::listen_newSessionLock, m_sWLRSessionLockMgr, "SessionLockMgr"); @@ -365,7 +362,6 @@ void CCompositor::removeAllSignals() { removeWLSignal(&Events::listen_newVirtPtr); removeWLSignal(&Events::listen_newVirtualKeyboard); removeWLSignal(&Events::listen_RendererDestroy); - removeWLSignal(&Events::listen_powerMgrSetMode); removeWLSignal(&Events::listen_newIME); removeWLSignal(&Events::listen_activateXDG); removeWLSignal(&Events::listen_newSessionLock); diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 47ffc7cf..931be9f3 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -66,7 +66,6 @@ class CCompositor { wlr_virtual_pointer_manager_v1* m_sWLRVirtPtrMgr; wlr_tablet_manager_v2* m_sWLRTabletManager; wlr_xdg_foreign_registry* m_sWLRForeignRegistry; - wlr_output_power_manager_v1* m_sWLROutputPowerMgr; wlr_input_method_manager_v2* m_sWLRIMEMgr; wlr_xdg_activation_v1* m_sWLRActivation; wlr_linux_dmabuf_v1* m_sWLRLinuxDMABuf; diff --git a/src/events/Events.hpp b/src/events/Events.hpp index 2f52f11d..b5109284 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -111,9 +111,6 @@ namespace Events { LISTENER(pinchUpdate); LISTENER(pinchEnd); - // Power - LISTENER(powerMgrSetMode); - // IME LISTENER(newIME); LISTENER(newVirtualKeyboard); diff --git a/src/events/Misc.cpp b/src/events/Misc.cpp index 996c5128..c6e42881 100644 --- a/src/events/Misc.cpp +++ b/src/events/Misc.cpp @@ -188,23 +188,6 @@ void Events::listener_sessionActive(wl_listener* listener, void* data) { g_pConfigManager->m_bWantsMonitorReload = 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; - const auto PMONITOR = g_pCompositor->getMonitorFromOutput(EVENT->output); - - if (!PMONITOR) { - Debug::log(ERR, "Invalid powerMgrSetMode output"); - return; - } - - wlr_output_state_set_enabled(PMONITOR->state.wlr(), EVENT->mode == 1); - - if (!PMONITOR->state.commit()) - Debug::log(ERR, "Couldn't set power mode"); -} - void Events::listener_newIME(wl_listener* listener, void* data) { Debug::log(LOG, "New IME added!"); diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 4d1e1c70..9fd9ee2f 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -133,6 +133,8 @@ class CMonitor { CSignal destroy; CSignal connect; CSignal disconnect; + CSignal dpmsChanged; + CSignal modeChanged; } events; std::array<std::vector<std::unique_ptr<SLayerSurface>>, 4> m_aLayerSurfaceLayers; diff --git a/src/includes.hpp b/src/includes.hpp index 7f679f97..1428351b 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -84,7 +84,6 @@ extern "C" { #include <wlr/types/wlr_xdg_foreign_registry.h> #include <wlr/types/wlr_xdg_foreign_v1.h> #include <wlr/types/wlr_xdg_foreign_v2.h> -#include <wlr/types/wlr_output_power_management_v1.h> #include <wlr/types/wlr_input_method_v2.h> #include <wlr/types/wlr_touch.h> #include <wlr/types/wlr_switch.h> diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 996424cc..556a7950 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2006,6 +2006,8 @@ void CKeybindManager::dpms(std::string arg) { if (enable) g_pHyprRenderer->damageMonitor(m.get()); + + m->events.dpmsChanged.emit(); } g_pCompositor->m_bDPMSStateON = enable; diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp index cffc6c83..9531e6d0 100644 --- a/src/managers/ProtocolManager.cpp +++ b/src/managers/ProtocolManager.cpp @@ -15,6 +15,7 @@ #include "../protocols/ShortcutsInhibit.hpp" #include "../protocols/TextInputV3.hpp" #include "../protocols/PointerConstraints.hpp" +#include "../protocols/OutputPower.hpp" #include "tearing-control-v1.hpp" #include "fractional-scale-v1.hpp" @@ -31,6 +32,7 @@ #include "keyboard-shortcuts-inhibit-unstable-v1.hpp" #include "text-input-unstable-v3.hpp" #include "pointer-constraints-unstable-v1.hpp" +#include "wlr-output-power-management-unstable-v1.hpp" CProtocolManager::CProtocolManager() { @@ -49,6 +51,7 @@ CProtocolManager::CProtocolManager() { PROTO::shortcutsInhibit = std::make_unique<CKeyboardShortcutsInhibitProtocol>(&zwp_keyboard_shortcuts_inhibit_manager_v1_interface, 1, "ShortcutsInhibit"); PROTO::textInputV3 = std::make_unique<CTextInputV3Protocol>(&zwp_text_input_manager_v3_interface, 1, "TextInputV3"); PROTO::constraints = std::make_unique<CPointerConstraintsProtocol>(&zwp_pointer_constraints_v1_interface, 1, "PointerConstraints"); + PROTO::outputPower = std::make_unique<COutputPowerProtocol>(&zwlr_output_power_manager_v1_interface, 1, "OutputPower"); // Old protocol implementations. // TODO: rewrite them to use hyprwayland-scanner. diff --git a/src/protocols/OutputPower.cpp b/src/protocols/OutputPower.cpp new file mode 100644 index 00000000..48e713f5 --- /dev/null +++ b/src/protocols/OutputPower.cpp @@ -0,0 +1,80 @@ +#include "OutputPower.hpp" +#include "../Compositor.hpp" + +#define LOGM PROTO::outputPower->protoLog + +COutputPower::COutputPower(SP<CZwlrOutputPowerV1> resource_, CMonitor* pMonitor_) : resource(resource_), pMonitor(pMonitor_) { + if (!resource->resource()) + return; + + resource->setDestroy([this](CZwlrOutputPowerV1* r) { PROTO::outputPower->destroyOutputPower(this); }); + resource->setOnDestroy([this](CZwlrOutputPowerV1* r) { PROTO::outputPower->destroyOutputPower(this); }); + + resource->setSetMode([this](CZwlrOutputPowerV1* r, zwlrOutputPowerV1Mode mode) { + if (!pMonitor) + return; + + pMonitor->dpmsStatus = mode == ZWLR_OUTPUT_POWER_V1_MODE_ON; + + wlr_output_state_set_enabled(pMonitor->state.wlr(), pMonitor->dpmsStatus); + + if (!pMonitor->state.commit()) + LOGM(ERR, "Couldn't set dpms to {} for {}", pMonitor->dpmsStatus, pMonitor->szName); + }); + + resource->sendMode(pMonitor->dpmsStatus ? ZWLR_OUTPUT_POWER_V1_MODE_ON : ZWLR_OUTPUT_POWER_V1_MODE_OFF); + + listeners.monitorDestroy = pMonitor->events.destroy.registerListener([this](std::any v) { + pMonitor = nullptr; + resource->sendFailed(); + }); + + listeners.monitorDpms = pMonitor->events.dpmsChanged.registerListener( + [this](std::any v) { resource->sendMode(pMonitor->dpmsStatus ? ZWLR_OUTPUT_POWER_V1_MODE_ON : ZWLR_OUTPUT_POWER_V1_MODE_OFF); }); + listeners.monitorState = pMonitor->events.modeChanged.registerListener( + [this](std::any v) { resource->sendMode(pMonitor->dpmsStatus ? ZWLR_OUTPUT_POWER_V1_MODE_ON : ZWLR_OUTPUT_POWER_V1_MODE_OFF); }); +} + +bool COutputPower::good() { + return resource->resource(); +} + +COutputPowerProtocol::COutputPowerProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) { + ; +} + +void COutputPowerProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) { + const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CZwlrOutputPowerManagerV1>(client, ver, id)).get(); + RESOURCE->setOnDestroy([this](CZwlrOutputPowerManagerV1* p) { this->onManagerResourceDestroy(p->resource()); }); + + RESOURCE->setDestroy([this](CZwlrOutputPowerManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); }); + RESOURCE->setGetOutputPower([this](CZwlrOutputPowerManagerV1* hiThereFriend, uint32_t id, wl_resource* output) { this->onGetOutputPower(hiThereFriend, id, output); }); +} + +void COutputPowerProtocol::onManagerResourceDestroy(wl_resource* res) { + std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; }); +} + +void COutputPowerProtocol::destroyOutputPower(COutputPower* power) { + std::erase_if(m_vOutputPowers, [&](const auto& other) { return other.get() == power; }); +} + +void COutputPowerProtocol::onGetOutputPower(CZwlrOutputPowerManagerV1* pMgr, uint32_t id, wl_resource* output) { + + const auto PMONITOR = g_pCompositor->getMonitorFromOutput(wlr_output_from_resource(output)); + + if (!PMONITOR) { + wl_resource_post_error(pMgr->resource(), 0, "Invalid output resource"); + return; + } + + const auto CLIENT = wl_resource_get_client(pMgr->resource()); + const auto RESOURCE = + m_vOutputPowers.emplace_back(std::make_unique<COutputPower>(std::make_shared<CZwlrOutputPowerV1>(CLIENT, wl_resource_get_version(pMgr->resource()), id), PMONITOR)).get(); + + if (!RESOURCE->good()) { + wl_resource_post_no_memory(pMgr->resource()); + m_vOutputPowers.pop_back(); + return; + } +} diff --git a/src/protocols/OutputPower.hpp b/src/protocols/OutputPower.hpp new file mode 100644 index 00000000..44788a8f --- /dev/null +++ b/src/protocols/OutputPower.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include <memory> +#include <vector> +#include <cstdint> +#include "WaylandProtocol.hpp" +#include "wlr-output-power-management-unstable-v1.hpp" +#include "../helpers/signal/Listener.hpp" + +class CMonitor; + +class COutputPower { + public: + COutputPower(SP<CZwlrOutputPowerV1> resource_, CMonitor* pMonitor); + + bool good(); + + private: + SP<CZwlrOutputPowerV1> resource; + + CMonitor* pMonitor = nullptr; + + struct { + CHyprSignalListener monitorDestroy; + CHyprSignalListener monitorState; + CHyprSignalListener monitorDpms; + } listeners; +}; + +class COutputPowerProtocol : public IWaylandProtocol { + public: + COutputPowerProtocol(const wl_interface* iface, const int& ver, const std::string& name); + + virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id); + + private: + void onManagerResourceDestroy(wl_resource* res); + void destroyOutputPower(COutputPower* pointer); + void onGetOutputPower(CZwlrOutputPowerManagerV1* pMgr, uint32_t id, wl_resource* output); + + // + std::vector<UP<CZwlrOutputPowerManagerV1>> m_vManagers; + std::vector<UP<COutputPower>> m_vOutputPowers; + + friend class COutputPower; +}; + +namespace PROTO { + inline UP<COutputPowerProtocol> outputPower; +};
\ No newline at end of file diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 4d1ee97d..e34e6a72 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1904,6 +1904,8 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR if (pMonitor->m_bEnabled) pMonitor->onDisconnect(); + pMonitor->events.modeChanged.emit(); + return true; } @@ -2301,6 +2303,8 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR EMIT_HOOK_EVENT("monitorLayoutChanged", nullptr); + pMonitor->events.modeChanged.emit(); + Events::listener_change(nullptr, nullptr); return true; |