diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-04-22 18:44:25 +0100 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-04-22 18:44:25 +0100 |
| commit | 012a2802e00a7b34e47c8c1098dc093031044ce9 (patch) | |
| tree | a72083d065f243a67dabbfaa704f026d501ee655 /src/protocols | |
| parent | 741c75d907916d760163f910e65186d410e27874 (diff) | |
Protocols: implement protoLog
Diffstat (limited to 'src/protocols')
| -rw-r--r-- | src/protocols/AlphaModifier.cpp | 8 | ||||
| -rw-r--r-- | src/protocols/CursorShape.cpp | 3 | ||||
| -rw-r--r-- | src/protocols/FractionalScale.cpp | 8 | ||||
| -rw-r--r-- | src/protocols/GammaControl.cpp | 20 | ||||
| -rw-r--r-- | src/protocols/WaylandProtocol.cpp | 6 | ||||
| -rw-r--r-- | src/protocols/WaylandProtocol.hpp | 6 | ||||
| -rw-r--r-- | src/protocols/XDGDecoration.cpp | 7 | ||||
| -rw-r--r-- | src/protocols/XDGOutput.cpp | 4 |
8 files changed, 44 insertions, 18 deletions
diff --git a/src/protocols/AlphaModifier.cpp b/src/protocols/AlphaModifier.cpp index 12bc3512..55349572 100644 --- a/src/protocols/AlphaModifier.cpp +++ b/src/protocols/AlphaModifier.cpp @@ -3,6 +3,8 @@ #include "../desktop/WLSurface.hpp" #include "../render/Renderer.hpp" +#define LOGM PROTO::alphaModifier->protoLog + CAlphaModifier::CAlphaModifier(SP<CWpAlphaModifierSurfaceV1> resource_, wlr_surface* surface_) : resource(resource_), pSurface(surface_) { if (!resource->resource()) return; @@ -21,6 +23,7 @@ CAlphaModifier::CAlphaModifier(SP<CWpAlphaModifierSurfaceV1> resource_, wlr_surf resource->setSetMultiplier([this](CWpAlphaModifierSurfaceV1* mod, uint32_t alpha) { if (!pSurface) { + LOGM(ERR, "Resource {:x} tried to setMultiplier but surface is gone", (uintptr_t)mod->resource()); wl_resource_post_error(mod->resource(), WP_ALPHA_MODIFIER_SURFACE_V1_ERROR_NO_SURFACE, "Surface is gone"); return; } @@ -47,7 +50,7 @@ void CAlphaModifier::setSurfaceAlpha(float a) { CWLSurface* surf = CWLSurface::surfaceFromWlr(pSurface); if (!surf) { - Debug::log(ERR, "Error in CAlphaModifier::setSurfaceAlpha: No CWLSurface for given surface??"); + LOGM(ERR, "CAlphaModifier::setSurfaceAlpha: No CWLSurface for given surface??"); return; } @@ -93,7 +96,7 @@ void CAlphaModifierProtocol::destroyModifier(CAlphaModifier* modifier) { } if (!deadptr) { - Debug::log(ERR, "CAlphaModifierProtocol::destroyModifier: dead resource but no deadptr???"); + LOGM(ERR, "CAlphaModifierProtocol::destroyModifier: dead resource but no deadptr???"); return; } @@ -103,6 +106,7 @@ void CAlphaModifierProtocol::destroyModifier(CAlphaModifier* modifier) { void CAlphaModifierProtocol::onGetSurface(CWpAlphaModifierV1* pMgr, uint32_t id, wlr_surface* surface) { if (m_mAlphaModifiers.contains(surface)) { + LOGM(ERR, "AlphaModifier already present for surface {:x}", (uintptr_t)surface); wl_resource_post_error(pMgr->resource(), WP_ALPHA_MODIFIER_V1_ERROR_ALREADY_CONSTRUCTED, "AlphaModifier already present"); return; } diff --git a/src/protocols/CursorShape.cpp b/src/protocols/CursorShape.cpp index e04cccb4..fb26d7a2 100644 --- a/src/protocols/CursorShape.cpp +++ b/src/protocols/CursorShape.cpp @@ -1,6 +1,8 @@ #include "CursorShape.hpp" #include <algorithm> +#define LOGM PROTO::cursorShape->protoLog + // clang-format off constexpr const char* SHAPE_NAMES[] = { "invalid", @@ -72,6 +74,7 @@ void CCursorShapeProtocol::onGetTabletToolV2(CWpCursorShapeManagerV1* pMgr, uint void CCursorShapeProtocol::createCursorShapeDevice(CWpCursorShapeManagerV1* pMgr, uint32_t id, wl_resource* resource) { if (m_mDevices.contains(resource)) { + LOGM(ERR, "CursorShape device already exists for {:x}", (uintptr_t)resource); wl_resource_post_error(resource, 0, "Device already exists"); return; } diff --git a/src/protocols/FractionalScale.cpp b/src/protocols/FractionalScale.cpp index 993d963b..86662d90 100644 --- a/src/protocols/FractionalScale.cpp +++ b/src/protocols/FractionalScale.cpp @@ -1,5 +1,7 @@ #include "FractionalScale.hpp" +#define LOGM PROTO::fractional->protoLog + static void onWlrSurfaceDestroy(void* owner, void* data) { const auto SURF = (wlr_surface*)owner; @@ -28,6 +30,12 @@ void CFractionalScaleProtocol::onManagerResourceDestroy(wl_resource* res) { } void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1* pMgr, uint32_t id, wlr_surface* surface) { + if (m_mAddons.contains(surface)) { + LOGM(ERR, "Surface {:x} already has a fractionalScale addon", (uintptr_t)surface); + wl_resource_post_error(pMgr->resource(), WP_FRACTIONAL_SCALE_MANAGER_V1_ERROR_FRACTIONAL_SCALE_EXISTS, "Fractional scale already exists"); + return; + } + const auto PADDON = m_mAddons .emplace(surface, std::make_unique<CFractionalScaleAddon>( diff --git a/src/protocols/GammaControl.cpp b/src/protocols/GammaControl.cpp index fa7fddd7..b0f9af7a 100644 --- a/src/protocols/GammaControl.cpp +++ b/src/protocols/GammaControl.cpp @@ -4,6 +4,8 @@ #include "../helpers/Monitor.hpp" #include "../Compositor.hpp" +#define LOGM PROTO::gamma->protoLog + CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* output) : resource(resource_) { if (!resource_->resource()) return; @@ -11,7 +13,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out wlr_output* wlrOutput = wlr_output_from_resource(output); if (!wlrOutput) { - Debug::log(ERR, "[gamma] No wlr_output"); + LOGM(ERR, "No wlr_output in CGammaControl"); resource->sendFailed(); return; } @@ -19,7 +21,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out pMonitor = g_pCompositor->getRealMonitorFromOutput(wlrOutput); if (!pMonitor) { - Debug::log(ERR, "[gamma] No CMonitor"); + LOGM(ERR, "No CMonitor"); resource->sendFailed(); return; } @@ -34,7 +36,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out gammaSize = wlr_output_get_gamma_size(wlrOutput); if (gammaSize <= 0) { - Debug::log(ERR, "[gamma] Output {} doesn't support gamma", pMonitor->szName); + LOGM(ERR, "Output {} doesn't support gamma", pMonitor->szName); resource->sendFailed(); return; } @@ -45,18 +47,18 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out resource->setOnDestroy([this](CZwlrGammaControlV1* gamma) { PROTO::gamma->destroyGammaControl(this); }); resource->setSetGamma([this](CZwlrGammaControlV1* gamma, int32_t fd) { - Debug::log(LOG, "[gamma] setGamma for {}", pMonitor->szName); + LOGM(LOG, "setGamma for {}", pMonitor->szName); int fdFlags = fcntl(fd, F_GETFL, 0); if (fdFlags < 0) { - Debug::log(ERR, "[gamma] Failed to get fd flags"); + LOGM(ERR, "Failed to get fd flags"); resource->sendFailed(); close(fd); return; } if (fcntl(fd, F_SETFL, fdFlags | O_NONBLOCK) < 0) { - Debug::log(ERR, "[gamma] Failed to set fd flags"); + LOGM(ERR, "Failed to set fd flags"); resource->sendFailed(); close(fd); return; @@ -64,7 +66,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out ssize_t readBytes = pread(fd, gammaTable.data(), gammaTable.size() * sizeof(uint16_t), 0); if (readBytes < 0 || (size_t)readBytes != gammaTable.size() * sizeof(uint16_t)) { - Debug::log(ERR, "[gamma] Failed to read bytes"); + LOGM(ERR, "Failed to read bytes"); close(fd); if ((size_t)readBytes != gammaTable.size() * sizeof(uint16_t)) { @@ -103,7 +105,7 @@ void CGammaControl::applyToMonitor() { if (!pMonitor) return; // ?? - Debug::log(LOG, "[gamma] setting to monitor {}", pMonitor->szName); + LOGM(LOG, "setting to monitor {}", pMonitor->szName); if (!gammaTableSet) { wlr_output_state_set_gamma_lut(pMonitor->state.wlr(), 0, nullptr, nullptr, nullptr); @@ -117,7 +119,7 @@ void CGammaControl::applyToMonitor() { wlr_output_state_set_gamma_lut(pMonitor->state.wlr(), gammaSize, red, green, blue); if (!pMonitor->state.test()) { - Debug::log(LOG, "[gamma] setting to monitor {} failed", pMonitor->szName); + LOGM(LOG, "setting to monitor {} failed", pMonitor->szName); wlr_output_state_set_gamma_lut(pMonitor->state.wlr(), 0, nullptr, nullptr, nullptr); } diff --git a/src/protocols/WaylandProtocol.cpp b/src/protocols/WaylandProtocol.cpp index 988836db..30120235 100644 --- a/src/protocols/WaylandProtocol.cpp +++ b/src/protocols/WaylandProtocol.cpp @@ -13,18 +13,18 @@ void IWaylandProtocol::onDisplayDestroy() { wl_global_destroy(m_pGlobal); } -IWaylandProtocol::IWaylandProtocol(const wl_interface* iface, const int& ver, const std::string& name) { +IWaylandProtocol::IWaylandProtocol(const wl_interface* iface, const int& ver, const std::string& name) : m_szName(name) { m_pGlobal = wl_global_create(g_pCompositor->m_sWLDisplay, iface, ver, this, &bindManagerInternal); if (!m_pGlobal) { - Debug::log(ERR, "[proto {}] could not create a global", name); + protoLog(ERR, "could not create a global"); return; } m_liDisplayDestroy.notify = displayDestroyInternal; wl_display_add_destroy_listener(g_pCompositor->m_sWLDisplay, &m_liDisplayDestroy); - Debug::log(LOG, "[proto {}] started", name); + protoLog(LOG, "Registered global"); } IWaylandProtocol::~IWaylandProtocol() { diff --git a/src/protocols/WaylandProtocol.hpp b/src/protocols/WaylandProtocol.hpp index d23a0e48..b0a33900 100644 --- a/src/protocols/WaylandProtocol.hpp +++ b/src/protocols/WaylandProtocol.hpp @@ -24,7 +24,13 @@ class IWaylandProtocol { virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) = 0; + template <typename... Args> + void protoLog(LogLevel level, std::format_string<Args...> fmt, Args&&... args) { + Debug::log(level, std::format("[{}] ", m_szName) + std::vformat(fmt.get(), std::make_format_args(args...))); + }; + private: + std::string m_szName; wl_global* m_pGlobal = nullptr; wl_listener m_liDisplayDestroy; };
\ No newline at end of file diff --git a/src/protocols/XDGDecoration.cpp b/src/protocols/XDGDecoration.cpp index 7a5303a3..b62f89bc 100644 --- a/src/protocols/XDGDecoration.cpp +++ b/src/protocols/XDGDecoration.cpp @@ -1,6 +1,8 @@ #include "XDGDecoration.hpp" #include <algorithm> +#define LOGM PROTO::xdgDecoration->protoLog + CXDGDecoration::CXDGDecoration(SP<CZxdgToplevelDecorationV1> resource_, wl_resource* toplevel) : resource(resource_), pToplevelResource(toplevel) { if (!resource->resource()) return; @@ -16,13 +18,12 @@ CXDGDecoration::CXDGDecoration(SP<CZxdgToplevelDecorationV1> resource_, wl_resou default: modeString = "INVALID"; break; } - Debug::log(LOG, "[xdgDecoration] setMode: {}. {} MODE_SERVER_SIDE as reply.", modeString, - (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE ? "Sending" : "Ignoring and sending")); + LOGM(LOG, "setMode: {}. {} MODE_SERVER_SIDE as reply.", modeString, (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE ? "Sending" : "Ignoring and sending")); resource->sendConfigure(ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); }); resource->setUnsetMode([this](CZxdgToplevelDecorationV1*) { - Debug::log(LOG, "[xdgDecoration] unsetMode. Sending MODE_SERVER_SIDE."); + LOGM(LOG, "unsetMode. Sending MODE_SERVER_SIDE."); resource->sendConfigure(ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); }); } diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp index 551d9d90..d472df92 100644 --- a/src/protocols/XDGOutput.cpp +++ b/src/protocols/XDGOutput.cpp @@ -10,6 +10,8 @@ // +#define LOGM PROTO::xdgOutput->protoLog + void CXDGOutputProtocol::onManagerResourceDestroy(wl_resource* res) { std::erase_if(m_vManagerResources, [&](const auto& other) { return other->resource() == res; }); } @@ -22,7 +24,7 @@ void CXDGOutputProtocol::bindManager(wl_client* client, void* data, uint32_t ver const auto RESOURCE = m_vManagerResources.emplace_back(std::make_unique<CZxdgOutputManagerV1>(client, ver, id)).get(); if (!RESOURCE->resource()) { - Debug::log(LOG, "Couldn't bind XDGOutputMgr"); + LOGM(LOG, "Couldn't bind XDGOutputMgr"); wl_client_post_no_memory(client); return; } |
