diff --git a/include/x11-helper.h b/include/x11-helper.h index 7f37899d..4c915da5 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -260,5 +260,26 @@ int x11_modifier_active ( unsigned int mask, int key ); * (Set MOTIF_WM_HINTS, decoration field) */ void x11_disable_decoration ( xcb_window_t window ); + + +typedef enum { + /** Default EWHM compatible window manager */ + WM_EWHM, + /** I3 Window manager */ + WM_I3, + /** Awesome window manager */ + WM_AWESOME +} WindowManager; + +/** + * Indicates the current window manager. + * This is used for work-arounds. + */ +extern WindowManager current_window_manager; + +/** + * discover the window manager. + */ +void x11_helper_discover_window_manager ( void ); /*@}*/ #endif diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 5e9d3be3..f427aa2a 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -99,7 +99,6 @@ typedef struct unsigned int title_len; unsigned int role_len; GRegex *window_regex; - gboolean i3_mode; } ModeModePrivateData; winlist *cache_client = NULL; @@ -397,14 +396,6 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) xcb_window_t wins[100]; xcb_window_t curr_win_id; - // Check if we are in I3 mode. I3 has to be special and allow markup in it window name...... - char *i3_socket_path = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), netatoms[I3_SOCKET_PATH] ); - if ( i3_socket_path != NULL ) { - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Detected I3 Window manager running." ); - pd->i3_mode = TRUE; - g_free ( i3_socket_path ); - } - // Create cache x11_cache_create (); @@ -485,7 +476,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) } if ( c->wmdesktop != 0xFFFFFFFF ) { if ( has_names ) { - if ( pd->i3_mode ) { + if ( current_window_manager == WM_I3 ) { char *output = NULL; if ( pango_parse_markup ( _window_name_list_entry ( names.strings, names.strings_len, c->wmdesktop ), -1, 0, NULL, &output, NULL, NULL ) ) { diff --git a/source/rofi.c b/source/rofi.c index c753f488..4dfa58fe 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -858,6 +858,8 @@ int main ( int argc, char *argv[] ) fprintf ( stderr, "Failed to create EWMH atoms\n" ); free ( errors ); } + // Discover the current active window manager. + x11_helper_discover_window_manager(); TICK_N ( "Setup XCB" ); if ( xkb_x11_setup_xkb_extension ( xcb->connection, XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION, diff --git a/source/x11-helper.c b/source/x11-helper.c index 93ec2842..fff0e23d 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -44,6 +44,7 @@ #include "xcb.h" #include "settings.h" #include "helper.h" +#include "x11-helper.h" #include /** Checks if the if x and y is inside rectangle. */ @@ -54,6 +55,9 @@ /** Log domain for this module */ #define LOG_DOMAIN "X11Helper" + +WindowManager current_window_manager = WM_EWHM; + /** * Structure holding xcb objects needed to function. */ @@ -919,3 +923,20 @@ void x11_disable_decoration ( xcb_window_t window ) xcb_atom_t ha = netatoms[_MOTIF_WM_HINTS]; xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, window, ha, ha, 32, 5, &hints ); } + +void x11_helper_discover_window_manager ( void ) +{ + xcb_ewmh_get_utf8_strings_reply_t wtitle; + xcb_get_property_cookie_t cookie = xcb_ewmh_get_wm_name_unchecked(&(xcb->ewmh), xcb_stuff_get_root_window ( xcb ) ); + if ( xcb_ewmh_get_wm_name_reply(&(xcb->ewmh), cookie, &wtitle, (void *)0)) + { + if ( wtitle.strings_len > 0 ){ + if ( g_strcmp0(wtitle.strings, "i3") == 0 ){ + current_window_manager = WM_I3; + } else if ( g_strcmp0 ( wtitle.strings, "awesome" ) == 0 ){ + current_window_manager = WM_AWESOME; + } + } + xcb_ewmh_get_utf8_strings_reply_wipe(&wtitle); + } +}