diff options
| author | memchr <118117622+memchr@users.noreply.github.com> | 2023-09-20 15:25:03 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-20 16:25:03 +0100 |
| commit | 3785defaf12b9d99137b2f4c74ab82c51cf733e1 (patch) | |
| tree | c064adb3ec5eedd612bbc850976bc73ddbe7d15a /src/Window.hpp | |
| parent | 6594b50e57935dd66930ccd35dba7a1b4131399d (diff) | |
logging: implement std::formatter for some types (#3380)
Diffstat (limited to 'src/Window.hpp')
| -rw-r--r-- | src/Window.hpp | 44 |
1 files changed, 43 insertions, 1 deletions
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 <typename CharT> +struct std::formatter<CWindow*, CharT> : std::formatter<CharT> { + 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 <typename FormatContext> + 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 |
