From 3785defaf12b9d99137b2f4c74ab82c51cf733e1 Mon Sep 17 00:00:00 2001 From: memchr <118117622+memchr@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:25:03 +0000 Subject: logging: implement std::formatter for some types (#3380) --- src/Window.hpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/Window.hpp') diff --git a/src/Window.hpp b/src/Window.hpp index fecdfc55..7e4c73b8 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -1,7 +1,6 @@ #pragma once #include "defines.hpp" -#include "events/Events.hpp" #include "helpers/SubsurfaceTree.hpp" #include "helpers/AnimatedVariable.hpp" #include "render/decorations/IHyprWindowDecoration.hpp" @@ -9,6 +8,8 @@ #include "config/ConfigDataValues.hpp" #include "helpers/Vector2D.hpp" #include "helpers/WLSurface.hpp" +#include "macros.hpp" +#include "managers/XWaylandManager.hpp" enum eIdleInhibitMode { IDLEINHIBIT_NONE = 0, @@ -356,3 +357,44 @@ class CWindow { // For hidden windows and stuff bool m_bHidden = false; }; + +/** + format specification + - 'x', only address, equivalent of (uintpr_t)CWindow* + - 'm', with monitor id + - 'w', with workspace id + - 'c', with application class +*/ + +template +struct std::formatter : std::formatter { + bool formatAddressOnly = false; + bool formatWorkspace = false; + bool formatMonitor = false; + bool formatClass = false; + FORMAT_PARSE( // + FORMAT_FLAG('x', formatAddressOnly) // + FORMAT_FLAG('m', formatMonitor) // + FORMAT_FLAG('w', formatWorkspace) // + FORMAT_FLAG('c', formatClass), + CWindow*) + + template + auto format(CWindow* const& w, FormatContext& ctx) const { + auto&& out = ctx.out(); + if (formatAddressOnly) + return std::format_to(out, "{:x}", (uintptr_t)w); + if (!w) + return std::format_to(out, "[Window nullptr]"); + + std::format_to(out, "["); + std::format_to(out, "Window {:x}: title: \"{}\"", (uintptr_t)w, w->m_szTitle); + if (formatWorkspace) + std::format_to(out, ", workspace: {}", w->m_iWorkspaceID); + if (formatMonitor) + std::format_to(out, ", monitor: {}", w->m_iMonitorID); + if (formatClass) + std::format_to(out, ", class: {}", g_pXWaylandManager->getAppIDClass(w)); + return std::format_to(out, "]"); + } +}; \ No newline at end of file -- cgit v1.2.3