From 10255eee722634d5b85df757687d9fe7a4ca2b91 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 22 Sep 2022 20:47:09 -0400 Subject: [PATCH] Introduce new debug macros Introduce GDK_DISPLAY_DEBUG() and GDK_DEBUG() and the helper function gdk_debug_message(). This is meant to clean up the mess of our current debug statements which wildly mix g_message, g_print and g_printerr. --- gdk/gdk.c | 1 + gdk/gdkdebug.h | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/gdk/gdk.c b/gdk/gdk.c index 2c145a0898..babb4298ac 100644 --- a/gdk/gdk.c +++ b/gdk/gdk.c @@ -34,6 +34,7 @@ #include "gdkglcontextprivate.h" #include "gdkintl.h" #include "gdk-private.h" +#include #include #include diff --git a/gdk/gdkdebug.h b/gdk/gdkdebug.h index 8b185bf3d3..45519a1b4d 100644 --- a/gdk/gdkdebug.h +++ b/gdk/gdkdebug.h @@ -21,6 +21,7 @@ #include #include "gdktypes.h" +#include G_BEGIN_DECLS @@ -58,6 +59,8 @@ GdkDebugFlags gdk_display_get_debug_flags (GdkDisplay *display); void gdk_display_set_debug_flags (GdkDisplay *display, GdkDebugFlags flags); +#define gdk_debug_message(format, ...) g_fprintf (stderr, format "\n", ##__VA_ARGS__) + #ifdef G_ENABLE_DEBUG #define GDK_DISPLAY_DEBUG_CHECK(display,type) \ @@ -66,14 +69,20 @@ void gdk_display_set_debug_flags (GdkDisplay *display, if (GDK_DISPLAY_DEBUG_CHECK (display,type)) \ { action; }; } G_STMT_END +#define GDK_DISPLAY_DEBUG(display,type,...) \ + if (GDK_DISPLAY_DEBUG_CHECK (display,type)) \ + gdk_debug_message (__VA_ARGS__); \ + #else /* !G_ENABLE_DEBUG */ #define GDK_DISPLAY_DEBUG_CHECK(display,type) 0 #define GDK_DISPLAY_NOTE(display,type,action) +#define GDK_DISPLAY_DEBUG(display,type,...) #endif /* G_ENABLE_DEBUG */ #define GDK_DEBUG_CHECK(type) GDK_DISPLAY_DEBUG_CHECK (NULL,type) #define GDK_NOTE(type,action) GDK_DISPLAY_NOTE (NULL,type,action) +#define GDK_DEBUG(type,...) GDK_DISPLAY_DEBUG (NULL,type,__VA_ARGS__) #endif