1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00

Use fallback when truecolor visual fails.

- Fixes tests.
This commit is contained in:
Dave Davenport 2015-01-21 18:38:54 +01:00
parent 9cc63d4948
commit 19a0ec40f8
2 changed files with 39 additions and 9 deletions

View file

@ -363,6 +363,25 @@ GC gc = NULL;
Colormap map = None; Colormap map = None;
XVisualInfo vinfo; XVisualInfo vinfo;
static void create_visual_and_colormap ()
{
map = None;
// Try to create TrueColor map
if ( XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo ) ) {
// Visual found, lets try to create map.
map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
}
// Failed to create map.
// Use the defaults then.
if ( map == None ) {
// Two fields we use.
vinfo.visual = DefaultVisual ( display, DefaultScreen ( display ) );
vinfo.depth = DefaultDepth ( display, DefaultScreen ( display ) );
map = DefaultColormap ( display, DefaultScreen ( display ) );
}
}
/** /**
* Allocate a pixel value for an X named color * Allocate a pixel value for an X named color
*/ */
@ -2107,8 +2126,7 @@ SwitcherMode run_switcher_window ( char **input, G_GNUC_UNUSED void *data )
static int run_dmenu () static int run_dmenu ()
{ {
// Request truecolor visual. // Request truecolor visual.
XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo ); create_visual_and_colormap ();
map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
int ret_state; int ret_state;
textbox_setup ( &vinfo, map, textbox_setup ( &vinfo, map,
config.menu_bg, config.menu_bg_alt, config.menu_fg, config.menu_bg, config.menu_bg_alt, config.menu_fg,
@ -2146,8 +2164,7 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
XSync ( display, True ); XSync ( display, True );
} }
XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo ); create_visual_and_colormap ();
map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
// Because of the above fork, we want to do this here. // Because of the above fork, we want to do this here.
// Make sure this is isolated to its own thread. // Make sure this is isolated to its own thread.
@ -2677,8 +2694,7 @@ int main ( int argc, char *argv[] )
char *msg = NULL; char *msg = NULL;
if ( find_arg_str ( argc, argv, "-e", &( msg ) ) ) { if ( find_arg_str ( argc, argv, "-e", &( msg ) ) ) {
// Request truecolor visual. // Request truecolor visual.
XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo ); create_visual_and_colormap ();
map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
textbox_setup ( &vinfo, map, textbox_setup ( &vinfo, map,
config.menu_bg, config.menu_bg_alt, config.menu_fg, config.menu_bg, config.menu_bg_alt, config.menu_fg,
config.menu_hlbg, config.menu_hlbg,

View file

@ -37,6 +37,22 @@ static unsigned int color_get ( Display *display, const char *const name )
} }
} }
static void create_visual_and_colormap()
{
map = None;
// Try to create TrueColor map
if(XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo )) {
// Visual found, lets try to create map.
map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
}
// Failed to create map.
if (map == None ) {
// Two fields we use.
vinfo.visual = DefaultVisual(display, DefaultScreen(display));
vinfo.depth = DefaultDepth(display, DefaultScreen(display));
map = DefaultColormap( display, DefaultScreen (display));
}
}
int main ( int argc, char **argv ) int main ( int argc, char **argv )
{ {
@ -46,9 +62,7 @@ int main ( int argc, char **argv )
fprintf ( stderr, "cannot open display!\n" ); fprintf ( stderr, "cannot open display!\n" );
return EXIT_FAILURE; return EXIT_FAILURE;
} }
XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo ); create_visual_and_colormap();
map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
TASSERT( display != NULL ); TASSERT( display != NULL );
Screen *screen = DefaultScreenOfDisplay ( display ); Screen *screen = DefaultScreenOfDisplay ( display );
Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) ); Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) );