From e409322faf2074b0fa6e30cf77011aee5f28a99d Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 12 Jun 2023 19:16:46 +0200 Subject: [PATCH] Print window manager in -help output --- include/xcb.h | 7 +++++++ source/rofi.c | 9 +++++++++ source/xcb.c | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/include/xcb.h b/include/xcb.h index a9d33b8c..d56b2cf3 100644 --- a/include/xcb.h +++ b/include/xcb.h @@ -249,4 +249,11 @@ void cairo_image_surface_blur(cairo_surface_t *surface, double radius, void x11_event_handler_fowarding(xcb_xim_t *im, xcb_xic_t ic, xcb_key_press_event_t *event, void *user_data); #endif + +/** + * Get the currently detected window manager. + * + * @returns NULL when non found, otherwise a string (free with g_free) + */ +char *x11_helper_get_window_manager(void); #endif diff --git a/source/rofi.c b/source/rofi.c index 214a78f6..ff408027 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -358,6 +358,15 @@ static void help(G_GNUC_UNUSED int argc, char **argv) { printf("Global options:\n"); print_options(); printf("\n"); + printf("Detected Window manager:\n"); + char *wm = x11_helper_get_window_manager(); + if (wm) { + printf("\t• %s\n", wm); + g_free(wm); + } else { + printf("\t• No window manager detected.\n"); + } + printf("\n"); display_dump_monitor_layout(); printf("\n"); printf("Detected modes:\n"); diff --git a/source/xcb.c b/source/xcb.c index c4079a11..62dddfbf 100644 --- a/source/xcb.c +++ b/source/xcb.c @@ -1607,6 +1607,26 @@ static void x11_create_frequently_used_atoms(void) { } } +char *x11_helper_get_window_manager(void) { + char *retv = NULL; + xcb_window_t wm_win = 0; + xcb_get_property_cookie_t cc = xcb_ewmh_get_supporting_wm_check_unchecked( + &xcb->ewmh, xcb_stuff_get_root_window()); + + if (xcb_ewmh_get_supporting_wm_check_reply(&xcb->ewmh, cc, &wm_win, NULL)) { + xcb_ewmh_get_utf8_strings_reply_t wtitle; + xcb_get_property_cookie_t cookie = + xcb_ewmh_get_wm_name_unchecked(&(xcb->ewmh), wm_win); + if (xcb_ewmh_get_wm_name_reply(&(xcb->ewmh), cookie, &wtitle, (void *)0)) { + if (wtitle.strings_len > 0) { + retv = g_strdup(wtitle.strings); + } + xcb_ewmh_get_utf8_strings_reply_wipe(&wtitle); + } + } + return retv; +} + static void x11_helper_discover_window_manager(void) { xcb_window_t wm_win = 0; xcb_get_property_cookie_t cc = xcb_ewmh_get_supporting_wm_check_unchecked(