From 85172743eec65e83f98ccd079bb9f0876678080e Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Tue, 20 May 2014 09:43:45 +0200 Subject: [PATCH] Keys via xresources, dump config. --- config/config.c | 50 ++++++++++++++++++++++++++++++++++++++++++++- include/rofi.h | 1 + source/rofi.c | 15 ++++++++++---- source/xrmoptions.c | 4 ++++ 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/config/config.c b/config/config.c index f5872e1c..8519112b 100644 --- a/config/config.c +++ b/config/config.c @@ -99,7 +99,7 @@ void config_sanity_check( void ) exit(1); } - if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) ) + if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) ) { fprintf(stderr, "config.location is invalid. ( %d >= %d >= %d) does not hold.\n", WL_WEST, config.location, WL_CENTER); @@ -112,3 +112,51 @@ void config_sanity_check( void ) exit(1); } } + +/** + * Print out the current configuration. + */ +void config_print( void ) +{ + printf("Windows opacity: %3d%%\n", config.window_opacity); + printf("Border width: %3d\n", config.menu_bw); + printf("Padding: %3d\n", config.padding); + printf("Width: %4d%s\n", config.menu_width, + config.menu_width > 100? "px":"%"); + printf("offset (x,y): (%2d,%2d)px\n", config.x_offset, config.y_offset); + printf("Location: "); + switch(config.location) + { + case WL_CENTER: printf(" Center\n"); break; + case WL_NORTH_WEST: printf("North West\n"); break; + case WL_NORTH: printf(" North\n"); break; + case WL_NORTH_EAST: printf("North East\n"); break; + case WL_EAST: printf(" East\n"); break; + case WL_EAST_SOUTH: printf("East South\n"); break; + case WL_SOUTH: printf(" South\n"); break; + case WL_SOUTH_WEST: printf("South West\n"); break; + case WL_WEST: printf(" West\n"); break; + default: printf(" Invalid\n"); break; + } + printf("# Lines: %3d\n", config.menu_lines); + printf("# Columns: %3d\n", config.menu_columns); + printf("Fixed number of lines: %5s\n", config.fixed_num_lines?"true":"false"); + printf("Drawing mode: %10s\n", + config.hmode == VERTICAL?"Vertical":"Horizontal"); + + + printf("Font: %35s\n", config.menu_font); + /* Colors */ + printf("FG Color: %7s\n", config.menu_fg); + printf("BG Color: %7s\n", config.menu_bg); + printf("Highlight FG Color: %7s\n", config.menu_hlfg); + printf("Highlight BG Color: %7s\n", config.menu_hlbg); + printf("Border color: %7s\n", config.menu_bc); + + /* Terminal */ + printf("Terminal emulator: %22s\n", config.terminal_emulator); + /* Keybindings. */ + printf("Window switcher key: %7s\n", config.window_key); + printf("Run dialog key: %7s\n", config.run_key); + printf("SSH dialog key: %7s\n", config.ssh_key); +} diff --git a/include/rofi.h b/include/rofi.h index cbfc85ca..380e0965 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -109,4 +109,5 @@ int token_match ( char **tokens, const char *input, __attribute__( ( unused ) ) void *data ); void config_sanity_check ( void ); +void config_print ( void ); #endif diff --git a/source/rofi.c b/source/rofi.c index d1f0a0b7..74562155 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1903,6 +1903,11 @@ static void parse_cmd_options ( int argc, char ** argv ) { config.hmode = HORIZONTAL; } + + // Keybindings + find_arg_str ( argc, argv, "-key", &( config.window_key ) ); + find_arg_str ( argc, argv, "-rkey", &( config.run_key ) ); + find_arg_str ( argc, argv, "-skey", &( config.ssh_key ) ); } static void cleanup () @@ -2028,6 +2033,12 @@ int main ( int argc, char *argv[] ) // Parse command line for settings. parse_cmd_options ( argc, argv ); + if ( find_arg ( argc, argv, "-dump" ) >= 0 ) + { + config_print(); + return EXIT_SUCCESS; + } + // Sanity check config_sanity_check (); @@ -2052,16 +2063,12 @@ int main ( int argc, char *argv[] ) else { // Daemon mode, Listen to key presses.. - - find_arg_str ( argc, argv, "-key", &( config.window_key ) ); parse_key ( config.window_key, &windows_modmask, &windows_keysym ); grab_key ( windows_modmask, windows_keysym ); - find_arg_str ( argc, argv, "-rkey", &( config.run_key ) ); parse_key ( config.run_key, &rundialog_modmask, &rundialog_keysym ); grab_key ( rundialog_modmask, rundialog_keysym ); - find_arg_str ( argc, argv, "-skey", &( config.ssh_key ) ); parse_key ( config.ssh_key, &sshdialog_modmask, &sshdialog_keysym ); grab_key ( sshdialog_modmask, sshdialog_keysym ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index e4c0b601..886e8b49 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -75,6 +75,10 @@ static XrmOption xrmOptions[] = { { xrm_Number, "fixed_num_lines", { .num = &config.fixed_num_lines }, NULL }, { xrm_Number, "columns", { .num = &config.menu_columns }, NULL }, { xrm_Number, "hmode", { .num = &config.hmode }, NULL }, + /* Key bindings */ + { xrm_String, "key", { .str = &config.window_key }, NULL }, + { xrm_String, "rkey", { .str = &config.run_key }, NULL }, + { xrm_String, "skey", { .str = &config.ssh_key }, NULL }, };