Add an window manager detection function to startup.

current_window_manager now is an enum of known window managers.
This commit is contained in:
Dave Davenport 2017-02-11 16:53:37 +01:00
parent 98c625feab
commit c386521574
4 changed files with 45 additions and 10 deletions

View File

@ -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

View File

@ -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 ) ) {

View File

@ -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,

View File

@ -44,6 +44,7 @@
#include "xcb.h"
#include "settings.h"
#include "helper.h"
#include "x11-helper.h"
#include <rofi.h>
/** 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);
}
}