From bae542791336929366d711fb3bea0fcc6f0e82f3 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 10 Dec 2015 20:57:43 +0100 Subject: [PATCH] Add option to output to specific file. --- script/rofi-create-screenshot.sh | 8 ++++++++ source/rofi.c | 33 +++++++++++++++++++------------- source/xrmoptions.c | 14 +++++++------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/script/rofi-create-screenshot.sh b/script/rofi-create-screenshot.sh index 88740b57..32493c75 100755 --- a/script/rofi-create-screenshot.sh +++ b/script/rofi-create-screenshot.sh @@ -15,6 +15,9 @@ COLOR_BLUE="\e[0;34m" XRDB_FILE=$1 shift +OUTPUT_PNG=$1 +shift + XVFB=$(which Xvfb 2> /dev/null) XDOTOOL=$(which xdotool 2> /dev/null) XRDB=$(which xrdb 2> /dev/null) @@ -79,6 +82,11 @@ ROFI_OPTIONS="-selected-row 6 -u 2,3 -a 4,5 -location 0 -width 100 -lines 7 -col export DISPLAY=${VDISPLAY} +if [ -n "${OUTPUT_PNG}" ] +then + export ROFI_PNG_OUTPUT="${OUTPUT_PNG}" +fi + # Create fake X11 create_fake_x ${VDISPLAY} diff --git a/source/rofi.c b/source/rofi.c index 50becc8b..12326e9a 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -585,21 +585,28 @@ static void menu_capture_screenshot ( void ) return; } // Get current time. - GDateTime *now = g_date_time_new_now_local (); + GDateTime *now = g_date_time_new_now_local (); // Format filename. - char *timestmp = g_date_time_format ( now, "rofi-%Y-%m-%d-%H%M" ); - char *filename = g_strdup_printf ( "%s.png", timestmp ); + char *timestmp = g_date_time_format ( now, "rofi-%Y-%m-%d-%H%M" ); + char *filename = g_strdup_printf ( "%s.png", timestmp ); // Build full path - char *fpath = g_build_filename ( xdg_pict_dir, filename, NULL ); - while ( g_file_test ( fpath, G_FILE_TEST_EXISTS ) && index < 99 ) { - g_free ( fpath ); - g_free ( filename ); - // Try the next index. - index++; - // Format filename. - filename = g_strdup_printf ( "%s-%d.png", timestmp, index ); - // Build full path + char *fpath = NULL; + const char *outp = g_getenv ( "ROFI_PNG_OUTPUT" ); + if ( outp == NULL ) { fpath = g_build_filename ( xdg_pict_dir, filename, NULL ); + while ( g_file_test ( fpath, G_FILE_TEST_EXISTS ) && index < 99 ) { + g_free ( fpath ); + g_free ( filename ); + // Try the next index. + index++; + // Format filename. + filename = g_strdup_printf ( "%s-%d.png", timestmp, index ); + // Build full path + fpath = g_build_filename ( xdg_pict_dir, filename, NULL ); + } + } + else { + fpath = g_strdup ( outp ); } fprintf ( stderr, color_green "Storing screenshot %s\n"color_reset, fpath ); cairo_status_t status = cairo_surface_write_to_png ( surface, fpath ); @@ -2444,7 +2451,7 @@ int main ( int argc, char *argv[] ) exit ( EXIT_SUCCESS ); } if ( find_arg ( "-dump-xresources-theme" ) >= 0 ) { - print_xresources_theme(); + print_xresources_theme (); exit ( EXIT_SUCCESS ); } // Parse the keybindings. diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 2d3b5dd2..5cb3f588 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -513,18 +513,18 @@ void print_help_msg ( const char *option, const char *type, const char*text, con void print_xresources_theme ( void ) { - if( config.color_enabled != TRUE ) { - printf("! Dumping theme only works for the extended color scheme.\n"); + if ( config.color_enabled != TRUE ) { + printf ( "! Dumping theme only works for the extended color scheme.\n" ); return; } - printf("! ------------------------------------------------------------------------------\n"); - printf("! ROFI Color theme\n"); - printf("! ------------------------------------------------------------------------------\n"); + printf ( "! ------------------------------------------------------------------------------\n" ); + printf ( "! ROFI Color theme\n" ); + printf ( "! ------------------------------------------------------------------------------\n" ); const char * namePrefix = "rofi"; unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); for ( unsigned int i = 0; i < entries; ++i ) { - if ( strncmp(xrmOptions[i].name, "color-",6) == 0){ - xresource_dump_entry(namePrefix, &xrmOptions[i]); + if ( strncmp ( xrmOptions[i].name, "color-", 6 ) == 0 ) { + xresource_dump_entry ( namePrefix, &xrmOptions[i] ); } } }