diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2011-11-27 17:17:16 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2011-11-27 17:17:16 +0100 |
commit | 4bae608c5d8aec76d8a6c3d9b9f966f226772478 (patch) | |
tree | 699ea6cc78b0be642e68b5935fcefaa4c646b74f | |
parent | Fix hypen/minus usage in man page. (diff) | |
download | redshift-ng-4bae608c5d8aec76d8a6c3d9b9f966f226772478.tar.gz redshift-ng-4bae608c5d8aec76d8a6c3d9b9f966f226772478.tar.bz2 redshift-ng-4bae608c5d8aec76d8a6c3d9b9f966f226772478.tar.xz |
add -p option for print mode.
This mode only prints the current screen parameters and exits.
Useful for quick lookup of this value for use in scripts.
-rw-r--r-- | redshift.1 | 3 | ||||
-rw-r--r-- | src/redshift.c | 13 |
2 files changed, 14 insertions, 2 deletions
@@ -60,6 +60,9 @@ One shot mode (do not continously adjust color temperature) \fB\-O\fR TEMP One shot manual mode (set color temperature) .TP +\fB\-p\fR +Print mode (only print parameters and exit) +.TP \fB\-x\fR Reset mode (remove adjustment from screen) .TP diff --git a/src/redshift.c b/src/redshift.c index 9cd1e36..7247f54 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -226,6 +226,7 @@ static const location_provider_t location_providers[] = { typedef enum { PROGRAM_MODE_CONTINUAL, PROGRAM_MODE_ONE_SHOT, + PROGRAM_MODE_PRINT, PROGRAM_MODE_RESET, PROGRAM_MODE_MANUAL } program_mode_t; @@ -333,6 +334,7 @@ print_help(const char *program_name) " -o\t\tOne shot mode (do not continously adjust" " color temperature)\n" " -O TEMP\tOne shot manual mode (set color temperature)\n" + " -p\t\tPrint mode (only print parameters and exit)" " -x\t\tReset mode (remove adjustment from screen)\n" " -r\t\tDisable temperature transitions\n" " -t DAY:NIGHT\tColor temperature to set at daytime/night\n"), @@ -666,7 +668,7 @@ main(int argc, char *argv[]) /* Parse command line arguments. */ int opt; - while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:rt:vVx")) != -1) { + while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:prt:vVx")) != -1) { switch (opt) { case 'b': parse_brightness_string(optarg, &brightness_day, &brightness_night); @@ -771,6 +773,9 @@ main(int argc, char *argv[]) mode = PROGRAM_MODE_MANUAL; temp_set = atoi(optarg); break; + case 'p': + mode = PROGRAM_MODE_PRINT; + break; case 'r': transition = 0; break; @@ -1082,6 +1087,7 @@ main(int argc, char *argv[]) switch (mode) { case PROGRAM_MODE_ONE_SHOT: + case PROGRAM_MODE_PRINT: { /* Current angular elevation of the sun */ double now; @@ -1105,11 +1111,14 @@ main(int argc, char *argv[]) float brightness = calculate_interpolated_value(elevation, brightness_day, brightness_night); - if (verbose) { + if (verbose || mode == PROGRAM_MODE_PRINT) { print_period(elevation); printf(_("Color temperature: %uK\n"), temp); printf(_("Brightness: %.2f\n"), brightness); } + if(mode == PROGRAM_MODE_PRINT) { + exit(EXIT_SUCCESS); + } /* Adjust temperature */ r = method->set_temperature(&state, temp, brightness, gamma); |