mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Read settings from Xresource.
Code borrowed from Sean Pringle (yet again).
This commit is contained in:
parent
76a8f79211
commit
0737b4f5b2
6 changed files with 77 additions and 9 deletions
|
@ -43,8 +43,6 @@ Settings config = {
|
||||||
.menu_fg = "#222222",
|
.menu_fg = "#222222",
|
||||||
// Background color
|
// Background color
|
||||||
.menu_bg = "#f2f1f0",
|
.menu_bg = "#f2f1f0",
|
||||||
// Background alternative color
|
|
||||||
.menu_bgalt = "#e9e8e7",
|
|
||||||
// Foreground color (selected)
|
// Foreground color (selected)
|
||||||
.menu_hlfg = "#ffffff",
|
.menu_hlfg = "#ffffff",
|
||||||
// Background color (selected)
|
// Background color (selected)
|
||||||
|
|
|
@ -87,7 +87,6 @@ typedef struct _Settings {
|
||||||
char * menu_font;
|
char * menu_font;
|
||||||
char * menu_fg;
|
char * menu_fg;
|
||||||
char * menu_bg;
|
char * menu_bg;
|
||||||
char * menu_bgalt;
|
|
||||||
char * menu_hlfg;
|
char * menu_hlfg;
|
||||||
char * menu_hlbg;
|
char * menu_hlbg;
|
||||||
char * menu_bc;
|
char * menu_bc;
|
||||||
|
|
|
@ -126,7 +126,7 @@ SwitcherMode dmenu_switcher_dialog ( char **input )
|
||||||
free( list[i] );
|
free( list[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if(list != NULL) free( list );
|
if ( list != NULL ) free( list );
|
||||||
|
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,6 +188,7 @@ static char ** get_mark ( )
|
||||||
char *result = malloc( sizeof( char )*( head.size+1 ) );
|
char *result = malloc( sizeof( char )*( head.size+1 ) );
|
||||||
ssize_t index = 0;
|
ssize_t index = 0;
|
||||||
t = 0;
|
t = 0;
|
||||||
|
|
||||||
// Grab results.
|
// Grab results.
|
||||||
while ( index < ( ssize_t )head.size ) {
|
while ( index < ( ssize_t )head.size ) {
|
||||||
t= recv( s, &result[index], ( head.size-t ), 0 );
|
t= recv( s, &result[index], ( head.size-t ), 0 );
|
||||||
|
@ -273,6 +274,7 @@ SwitcherMode mark_switcher_dialog ( char **input )
|
||||||
int shift=0;
|
int shift=0;
|
||||||
int selected_line = 0;
|
int selected_line = 0;
|
||||||
int mretv = menu( cmd_list, input, "mark:", NULL, &shift,token_match,NULL, &selected_line );
|
int mretv = menu( cmd_list, input, "mark:", NULL, &shift,token_match,NULL, &selected_line );
|
||||||
|
|
||||||
if ( mretv == MENU_NEXT ) {
|
if ( mretv == MENU_NEXT ) {
|
||||||
retv = NEXT_DIALOG;
|
retv = NEXT_DIALOG;
|
||||||
} else if ( mretv == MENU_OK && cmd_list[selected_line] != NULL ) {
|
} else if ( mretv == MENU_OK && cmd_list[selected_line] != NULL ) {
|
||||||
|
@ -280,11 +282,12 @@ SwitcherMode mark_switcher_dialog ( char **input )
|
||||||
} else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) {
|
} else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) {
|
||||||
exec_mark( *input );
|
exec_mark( *input );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( int i=0; cmd_list != NULL && cmd_list[i] != NULL; i++ ) {
|
for ( int i=0; cmd_list != NULL && cmd_list[i] != NULL; i++ ) {
|
||||||
free( cmd_list[i] );
|
free( cmd_list[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd_list) free( cmd_list );
|
if ( cmd_list ) free( cmd_list );
|
||||||
|
|
||||||
|
|
||||||
return retv;
|
return retv;
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/XKBlib.h>
|
#include <X11/XKBlib.h>
|
||||||
#include <X11/Xft/Xft.h>
|
#include <X11/Xft/Xft.h>
|
||||||
|
#include <X11/Xresource.h>
|
||||||
#include <X11/extensions/Xinerama.h>
|
#include <X11/extensions/Xinerama.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,10 +79,36 @@ xdgHandle xdg_handle;
|
||||||
const char *cache_dir = NULL;
|
const char *cache_dir = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
// Big thanks to Sean Pringle for this code.
|
||||||
|
// This maps xresource options to config structure.
|
||||||
|
#define xrm_String 0
|
||||||
|
#define xrm_Number 1
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int type;
|
||||||
|
char * name ;
|
||||||
|
union {
|
||||||
|
unsigned int * num;
|
||||||
|
char ** str;
|
||||||
|
};
|
||||||
|
} XrmOption;
|
||||||
|
XrmOption xrmOptions[] = {
|
||||||
|
{ xrm_Number, "opacity", { .num = &config.window_opacity } },
|
||||||
|
{ xrm_Number, "width", { .num = &config.menu_width } },
|
||||||
|
{ xrm_Number, "lines", { .num = &config.menu_lines } },
|
||||||
|
{ xrm_String, "font", { .str = &config.menu_font } },
|
||||||
|
{ xrm_String, "foreground", { .str = &config.menu_fg } },
|
||||||
|
{ xrm_String, "background", { .str = &config.menu_bg } },
|
||||||
|
{ xrm_String, "highlightfg", { .str = &config.menu_hlfg } },
|
||||||
|
{ xrm_String, "highlightbg", { .str = &config.menu_hlbg } },
|
||||||
|
{ xrm_String, "bordercolor", { .str = &config.menu_bc } },
|
||||||
|
{ xrm_Number, "padding", { .num = &config.padding } },
|
||||||
|
};
|
||||||
|
|
||||||
void* allocate( unsigned long bytes )
|
void* allocate( unsigned long bytes )
|
||||||
{
|
{
|
||||||
if(bytes == 0) return NULL;
|
if ( bytes == 0 ) return NULL;
|
||||||
|
|
||||||
void *ptr = malloc( bytes );
|
void *ptr = malloc( bytes );
|
||||||
|
|
||||||
if ( !ptr ) {
|
if ( !ptr ) {
|
||||||
|
@ -93,14 +120,16 @@ void* allocate( unsigned long bytes )
|
||||||
}
|
}
|
||||||
void* allocate_clear( unsigned long bytes )
|
void* allocate_clear( unsigned long bytes )
|
||||||
{
|
{
|
||||||
if(bytes == 0) return NULL;
|
if ( bytes == 0 ) return NULL;
|
||||||
|
|
||||||
void *ptr = allocate( bytes );
|
void *ptr = allocate( bytes );
|
||||||
memset( ptr, 0, bytes );
|
memset( ptr, 0, bytes );
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
void* reallocate( void *ptr, unsigned long bytes )
|
void* reallocate( void *ptr, unsigned long bytes )
|
||||||
{
|
{
|
||||||
if(bytes == 0) return NULL;
|
if ( bytes == 0 ) return NULL;
|
||||||
|
|
||||||
ptr = realloc( ptr, bytes );
|
ptr = realloc( ptr, bytes );
|
||||||
|
|
||||||
if ( !ptr ) {
|
if ( !ptr ) {
|
||||||
|
@ -1098,6 +1127,7 @@ MenuReturn menu( char **lines, char **input, char *prompt, Time *time, int *shif
|
||||||
release_keyboard();
|
release_keyboard();
|
||||||
|
|
||||||
if ( *input != NULL ) free( *input );
|
if ( *input != NULL ) free( *input );
|
||||||
|
|
||||||
*input = strdup( text->text );
|
*input = strdup( text->text );
|
||||||
|
|
||||||
|
|
||||||
|
@ -1426,10 +1456,47 @@ int main( int argc, char *argv[] )
|
||||||
// X atom values
|
// X atom values
|
||||||
for ( i = 0; i < NETATOMS; i++ ) netatoms[i] = XInternAtom( display, netatom_names[i], False );
|
for ( i = 0; i < NETATOMS; i++ ) netatoms[i] = XInternAtom( display, netatom_names[i], False );
|
||||||
|
|
||||||
|
// Map Xresource entries to simpleswitcher config options.
|
||||||
|
XrmInitialize();
|
||||||
|
char * xRMS = XResourceManagerString ( display );
|
||||||
|
|
||||||
|
if ( xRMS != NULL ) {
|
||||||
|
XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
|
||||||
|
|
||||||
|
char * xrmType;
|
||||||
|
XrmValue xrmValue;
|
||||||
|
// TODO: update when we have new name.
|
||||||
|
const char * namePrefix = "simpleswitcher";
|
||||||
|
const char * classPrefix = "Simpleswitcher";
|
||||||
|
|
||||||
|
for ( unsigned int i = 0; i < sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); ++i ) {
|
||||||
|
char *name = ( char* ) allocate( ( strlen ( namePrefix ) + 1 + strlen ( xrmOptions[i].name ) ) *
|
||||||
|
sizeof ( char ) + 1 );
|
||||||
|
char *class = ( char* ) allocate( ( strlen ( classPrefix ) + 1 + strlen ( xrmOptions[i].name ) ) *
|
||||||
|
sizeof ( char ) + 1 );
|
||||||
|
sprintf ( name, "%s.%s", namePrefix, xrmOptions[i].name );
|
||||||
|
sprintf ( class, "%s.%s", classPrefix, xrmOptions[i].name );
|
||||||
|
|
||||||
|
if ( XrmGetResource ( xDB, name, class, &xrmType, &xrmValue ) ) {
|
||||||
|
|
||||||
|
if ( xrmOptions[i].type == xrm_String ) {
|
||||||
|
*xrmOptions[i].str = ( char * ) malloc ( xrmValue.size * sizeof ( char ) );
|
||||||
|
strncpy ( *xrmOptions[i].str, xrmValue.addr, xrmValue.size );
|
||||||
|
} else if ( xrmOptions[i].type == xrm_Number ) {
|
||||||
|
*xrmOptions[i].num = strtol ( xrmValue.addr, NULL, 10 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free ( name );
|
||||||
|
free ( class );
|
||||||
|
}
|
||||||
|
|
||||||
|
XFree ( xRMS );
|
||||||
|
}
|
||||||
|
|
||||||
find_arg_str( argc, argv, "-font", &( config.menu_font ) );
|
find_arg_str( argc, argv, "-font", &( config.menu_font ) );
|
||||||
find_arg_str( argc, argv, "-fg", &( config.menu_fg ) );
|
find_arg_str( argc, argv, "-fg", &( config.menu_fg ) );
|
||||||
find_arg_str( argc, argv, "-bg", &( config.menu_bg ) );
|
find_arg_str( argc, argv, "-bg", &( config.menu_bg ) );
|
||||||
find_arg_str( argc, argv, "-bgalt", &( config.menu_bgalt ) );
|
|
||||||
find_arg_str( argc, argv, "-hlfg", &( config.menu_hlfg ) );
|
find_arg_str( argc, argv, "-hlfg", &( config.menu_hlfg ) );
|
||||||
find_arg_str( argc, argv, "-hlbg", &( config.menu_hlbg ) );
|
find_arg_str( argc, argv, "-hlbg", &( config.menu_hlbg ) );
|
||||||
find_arg_str( argc, argv, "-bc", &( config.menu_bc ) );
|
find_arg_str( argc, argv, "-bc", &( config.menu_bc ) );
|
||||||
|
|
|
@ -307,6 +307,7 @@ SwitcherMode ssh_switcher_dialog ( char **input )
|
||||||
int shift=0;
|
int shift=0;
|
||||||
int selected_line = 0;
|
int selected_line = 0;
|
||||||
int mretv = menu( cmd_list, input, "ssh", NULL, &shift,token_match, NULL , &selected_line );
|
int mretv = menu( cmd_list, input, "ssh", NULL, &shift,token_match, NULL , &selected_line );
|
||||||
|
|
||||||
if ( mretv == MENU_NEXT ) {
|
if ( mretv == MENU_NEXT ) {
|
||||||
retv = NEXT_DIALOG;
|
retv = NEXT_DIALOG;
|
||||||
} else if ( mretv == MENU_OK && cmd_list[selected_line] != NULL ) {
|
} else if ( mretv == MENU_OK && cmd_list[selected_line] != NULL ) {
|
||||||
|
|
Loading…
Reference in a new issue