Change preserve option to command line switch
Changes each adjustment method to take a preserve parameter when setting the temperature instead of parsing the preserve option from the command line/configuration file. This helps resolve the issues around #513: - This allows the preserve option to be implemented as a command-line switch (-P). This switch _disables_ the preservation of existing gamma ramps. Having a command-line switch makes it easier to use directly with manual or one-shot mode. - The preserve options is on by default, so continual mode as well as other modes will default to applying the color adjustment on top of the current gamma ramps. - Preserve is always disabled in reset mode so resetting works as expected again.
This commit is contained in:
+2
-1
@@ -269,7 +269,8 @@ drm_set_option(drm_state_t *state, const char *key, const char *value)
|
||||
}
|
||||
|
||||
static int
|
||||
drm_set_temperature(drm_state_t *state, const color_setting_t *setting)
|
||||
drm_set_temperature(
|
||||
drm_state_t *state, const color_setting_t *setting, int preserve)
|
||||
{
|
||||
drm_crtc_state_t *crtcs = state->crtcs;
|
||||
int last_gamma_size = 0;
|
||||
|
||||
+2
-1
@@ -69,7 +69,8 @@ gamma_dummy_set_option(void *state, const char *key, const char *value)
|
||||
}
|
||||
|
||||
static int
|
||||
gamma_dummy_set_temperature(void *state, const color_setting_t *setting)
|
||||
gamma_dummy_set_temperature(
|
||||
void *state, const color_setting_t *setting, int preserve)
|
||||
{
|
||||
printf(_("Temperature: %i\n"), setting->temperature);
|
||||
return 0;
|
||||
|
||||
+13
-17
@@ -46,7 +46,6 @@ typedef struct {
|
||||
typedef struct {
|
||||
quartz_display_state_t *displays;
|
||||
uint32_t display_count;
|
||||
int preserve;
|
||||
} quartz_state_t;
|
||||
|
||||
|
||||
@@ -57,7 +56,6 @@ quartz_init(quartz_state_t **state)
|
||||
if (*state == NULL) return -1;
|
||||
|
||||
quartz_state_t *s = *state;
|
||||
s->preserve = 1;
|
||||
s->displays = NULL;
|
||||
|
||||
return 0;
|
||||
@@ -169,14 +167,7 @@ quartz_free(quartz_state_t *state)
|
||||
static void
|
||||
quartz_print_help(FILE *f)
|
||||
{
|
||||
fputs(_("Adjust gamma ramps on OSX using Quartz.\n"), f);
|
||||
fputs("\n", f);
|
||||
|
||||
/* TRANSLATORS: Quartz help output
|
||||
left column must not be translated */
|
||||
fputs(_(" preserve={0,1}\tWhether existing gamma should be"
|
||||
" preserved\n"),
|
||||
f);
|
||||
fputs(_("Adjust gamma ramps on macOS using Quartz.\n"), f);
|
||||
fputs("\n", f);
|
||||
}
|
||||
|
||||
@@ -184,7 +175,10 @@ static int
|
||||
quartz_set_option(quartz_state_t *state, const char *key, const char *value)
|
||||
{
|
||||
if (strcasecmp(key, "preserve") == 0) {
|
||||
state->preserve = atoi(value);
|
||||
fprintf(stderr, _("Parameter `%s` is now always on; "
|
||||
" Use the `%s` command-line option"
|
||||
" to disable.\n"),
|
||||
key, "-P");
|
||||
} else {
|
||||
fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
|
||||
return -1;
|
||||
@@ -194,8 +188,9 @@ quartz_set_option(quartz_state_t *state, const char *key, const char *value)
|
||||
}
|
||||
|
||||
static void
|
||||
quartz_set_temperature_for_display(quartz_state_t *state, int display_index,
|
||||
const color_setting_t *setting)
|
||||
quartz_set_temperature_for_display(
|
||||
quartz_state_t *state, int display_index,
|
||||
const color_setting_t *setting, int preserve)
|
||||
{
|
||||
CGDirectDisplayID display = state->displays[display_index].display;
|
||||
uint32_t ramp_size = state->displays[display_index].ramp_size;
|
||||
@@ -211,7 +206,7 @@ quartz_set_temperature_for_display(quartz_state_t *state, int display_index,
|
||||
float *gamma_g = &gamma_ramps[1*ramp_size];
|
||||
float *gamma_b = &gamma_ramps[2*ramp_size];
|
||||
|
||||
if (state->preserve) {
|
||||
if (preserve) {
|
||||
/* Initialize gamma ramps from saved state */
|
||||
memcpy(gamma_ramps, state->displays[display_index].saved_ramps,
|
||||
3*ramp_size*sizeof(float));
|
||||
@@ -240,11 +235,12 @@ quartz_set_temperature_for_display(quartz_state_t *state, int display_index,
|
||||
}
|
||||
|
||||
static int
|
||||
quartz_set_temperature(quartz_state_t *state,
|
||||
const color_setting_t *setting)
|
||||
quartz_set_temperature(
|
||||
quartz_state_t *state, const color_setting_t *setting, int preserve)
|
||||
{
|
||||
for (int i = 0; i < state->display_count; i++) {
|
||||
quartz_set_temperature_for_display(state, i, setting);
|
||||
quartz_set_temperature_for_display(
|
||||
state, i, setting, preserve);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
+15
-15
@@ -52,7 +52,6 @@ typedef struct {
|
||||
xcb_connection_t *conn;
|
||||
xcb_screen_t *screen;
|
||||
int preferred_screen;
|
||||
int preserve;
|
||||
int screen_num;
|
||||
int crtc_num_count;
|
||||
int* crtc_num;
|
||||
@@ -76,8 +75,6 @@ randr_init(randr_state_t **state)
|
||||
s->crtc_count = 0;
|
||||
s->crtcs = NULL;
|
||||
|
||||
s->preserve = 1;
|
||||
|
||||
xcb_generic_error_t *error;
|
||||
|
||||
/* Open X server connection */
|
||||
@@ -307,9 +304,8 @@ randr_print_help(FILE *f)
|
||||
/* TRANSLATORS: RANDR help output
|
||||
left column must not be translated */
|
||||
fputs(_(" screen=N\t\tX screen to apply adjustments to\n"
|
||||
" crtc=N\tList of comma separated CRTCs to apply adjustments to\n"
|
||||
" preserve={0,1}\tWhether existing gamma should be"
|
||||
" preserved\n"),
|
||||
" crtc=N\tList of comma separated CRTCs to apply"
|
||||
" adjustments to\n"),
|
||||
f);
|
||||
fputs("\n", f);
|
||||
}
|
||||
@@ -365,7 +361,10 @@ randr_set_option(randr_state_t *state, const char *key, const char *value)
|
||||
}
|
||||
}
|
||||
} else if (strcasecmp(key, "preserve") == 0) {
|
||||
state->preserve = atoi(value);
|
||||
fprintf(stderr, _("Parameter `%s` is now always on; "
|
||||
" Use the `%s` command-line option"
|
||||
" to disable.\n"),
|
||||
key, "-P");
|
||||
} else {
|
||||
fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
|
||||
return -1;
|
||||
@@ -375,8 +374,9 @@ randr_set_option(randr_state_t *state, const char *key, const char *value)
|
||||
}
|
||||
|
||||
static int
|
||||
randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num,
|
||||
const color_setting_t *setting)
|
||||
randr_set_temperature_for_crtc(
|
||||
randr_state_t *state, int crtc_num, const color_setting_t *setting,
|
||||
int preserve)
|
||||
{
|
||||
xcb_generic_error_t *error;
|
||||
|
||||
@@ -407,7 +407,7 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num,
|
||||
uint16_t *gamma_g = &gamma_ramps[1*ramp_size];
|
||||
uint16_t *gamma_b = &gamma_ramps[2*ramp_size];
|
||||
|
||||
if (state->preserve) {
|
||||
if (preserve) {
|
||||
/* Initialize gamma ramps from saved state */
|
||||
memcpy(gamma_ramps, state->crtcs[crtc_num].saved_ramps,
|
||||
3*ramp_size*sizeof(uint16_t));
|
||||
@@ -444,8 +444,8 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num,
|
||||
}
|
||||
|
||||
static int
|
||||
randr_set_temperature(randr_state_t *state,
|
||||
const color_setting_t *setting)
|
||||
randr_set_temperature(
|
||||
randr_state_t *state, const color_setting_t *setting, int preserve)
|
||||
{
|
||||
int r;
|
||||
|
||||
@@ -453,14 +453,14 @@ randr_set_temperature(randr_state_t *state,
|
||||
set temperature on all CRTCs. */
|
||||
if (state->crtc_num_count == 0) {
|
||||
for (int i = 0; i < state->crtc_count; i++) {
|
||||
r = randr_set_temperature_for_crtc(state, i,
|
||||
setting);
|
||||
r = randr_set_temperature_for_crtc(
|
||||
state, i, setting, preserve);
|
||||
if (r < 0) return -1;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < state->crtc_num_count; ++i) {
|
||||
r = randr_set_temperature_for_crtc(
|
||||
state, state->crtc_num[i], setting);
|
||||
state, state->crtc_num[i], setting, preserve);
|
||||
if (r < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-10
@@ -39,7 +39,6 @@
|
||||
|
||||
typedef struct {
|
||||
Display *display;
|
||||
int preserve;
|
||||
int screen_num;
|
||||
int ramp_size;
|
||||
uint16_t *saved_ramps;
|
||||
@@ -56,8 +55,6 @@ vidmode_init(vidmode_state_t **state)
|
||||
s->screen_num = -1;
|
||||
s->saved_ramps = NULL;
|
||||
|
||||
s->preserve = 1;
|
||||
|
||||
/* Open display */
|
||||
s->display = XOpenDisplay(NULL);
|
||||
if (s->display == NULL) {
|
||||
@@ -145,9 +142,7 @@ vidmode_print_help(FILE *f)
|
||||
|
||||
/* TRANSLATORS: VidMode help output
|
||||
left column must not be translated */
|
||||
fputs(_(" screen=N\t\tX screen to apply adjustments to\n"
|
||||
" preserve={0,1}\tWhether existing gamma should be"
|
||||
" preserved\n"),
|
||||
fputs(_(" screen=N\t\tX screen to apply adjustments to\n"),
|
||||
f);
|
||||
fputs("\n", f);
|
||||
}
|
||||
@@ -158,7 +153,10 @@ vidmode_set_option(vidmode_state_t *state, const char *key, const char *value)
|
||||
if (strcasecmp(key, "screen") == 0) {
|
||||
state->screen_num = atoi(value);
|
||||
} else if (strcasecmp(key, "preserve") == 0) {
|
||||
state->preserve = atoi(value);
|
||||
fprintf(stderr, _("Parameter `%s` is now always on; "
|
||||
" Use the `%s` command-line option"
|
||||
" to disable.\n"),
|
||||
key, "-P");
|
||||
} else {
|
||||
fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
|
||||
return -1;
|
||||
@@ -185,8 +183,8 @@ vidmode_restore(vidmode_state_t *state)
|
||||
}
|
||||
|
||||
static int
|
||||
vidmode_set_temperature(vidmode_state_t *state,
|
||||
const color_setting_t *setting)
|
||||
vidmode_set_temperature(
|
||||
vidmode_state_t *state, const color_setting_t *setting, int preserve)
|
||||
{
|
||||
int r;
|
||||
|
||||
@@ -201,7 +199,7 @@ vidmode_set_temperature(vidmode_state_t *state,
|
||||
uint16_t *gamma_g = &gamma_ramps[1*state->ramp_size];
|
||||
uint16_t *gamma_b = &gamma_ramps[2*state->ramp_size];
|
||||
|
||||
if (state->preserve) {
|
||||
if (preserve) {
|
||||
/* Initialize gamma ramps from saved state */
|
||||
memcpy(gamma_ramps, state->saved_ramps,
|
||||
3*state->ramp_size*sizeof(uint16_t));
|
||||
|
||||
+7
-13
@@ -42,7 +42,6 @@
|
||||
|
||||
typedef struct {
|
||||
WORD *saved_ramps;
|
||||
int preserve;
|
||||
} w32gdi_state_t;
|
||||
|
||||
|
||||
@@ -54,7 +53,6 @@ w32gdi_init(w32gdi_state_t **state)
|
||||
|
||||
w32gdi_state_t *s = *state;
|
||||
s->saved_ramps = NULL;
|
||||
s->preserve = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -116,20 +114,16 @@ w32gdi_print_help(FILE *f)
|
||||
{
|
||||
fputs(_("Adjust gamma ramps with the Windows GDI.\n"), f);
|
||||
fputs("\n", f);
|
||||
|
||||
/* TRANSLATORS: Windows GDI help output
|
||||
left column must not be translated */
|
||||
fputs(_(" preserve={0,1}\tWhether existing gamma should be"
|
||||
" preserved\n"),
|
||||
f);
|
||||
fputs("\n", f);
|
||||
}
|
||||
|
||||
static int
|
||||
w32gdi_set_option(w32gdi_state_t *state, const char *key, const char *value)
|
||||
{
|
||||
if (strcasecmp(key, "preserve") == 0) {
|
||||
state->preserve = atoi(value);
|
||||
fprintf(stderr, _("Parameter `%s` is now always on; "
|
||||
" Use the `%s` command-line option"
|
||||
" to disable.\n"),
|
||||
key, "-P");
|
||||
} else {
|
||||
fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
|
||||
return -1;
|
||||
@@ -163,8 +157,8 @@ w32gdi_restore(w32gdi_state_t *state)
|
||||
}
|
||||
|
||||
static int
|
||||
w32gdi_set_temperature(w32gdi_state_t *state,
|
||||
const color_setting_t *setting)
|
||||
w32gdi_set_temperature(
|
||||
w32gdi_state_t *state, const color_setting_t *setting, int preserve)
|
||||
{
|
||||
BOOL r;
|
||||
|
||||
@@ -187,7 +181,7 @@ w32gdi_set_temperature(w32gdi_state_t *state,
|
||||
WORD *gamma_g = &gamma_ramps[1*GAMMA_RAMP_SIZE];
|
||||
WORD *gamma_b = &gamma_ramps[2*GAMMA_RAMP_SIZE];
|
||||
|
||||
if (state->preserve) {
|
||||
if (preserve) {
|
||||
/* Initialize gamma ramps from saved state */
|
||||
memcpy(gamma_ramps, state->saved_ramps,
|
||||
3*GAMMA_RAMP_SIZE*sizeof(WORD));
|
||||
|
||||
+7
-1
@@ -189,6 +189,8 @@ print_help(const char *program_name)
|
||||
" color temperature)\n"
|
||||
" -O TEMP\tOne shot manual mode (set color temperature)\n"
|
||||
" -p\t\tPrint mode (only print parameters and exit)\n"
|
||||
" -P\t\tReset existing gamma ramps before applying new"
|
||||
" color effect\n"
|
||||
" -x\t\tReset mode (remove adjustment from screen)\n"
|
||||
" -r\t\tDisable fading between color temperatures\n"
|
||||
" -t DAY:NIGHT\tColor temperature to set at daytime/night\n"),
|
||||
@@ -318,6 +320,7 @@ options_init(options_t *options)
|
||||
options->provider_args = NULL;
|
||||
|
||||
options->use_fade = -1;
|
||||
options->preserve_gamma = 1;
|
||||
options->mode = PROGRAM_MODE_CONTINUAL;
|
||||
options->verbose = 0;
|
||||
}
|
||||
@@ -334,7 +337,7 @@ options_parse_args(
|
||||
|
||||
/* Parse command line arguments. */
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:prt:vVx")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:pPrt:vVx")) != -1) {
|
||||
switch (opt) {
|
||||
case 'b':
|
||||
parse_brightness_string(
|
||||
@@ -455,6 +458,9 @@ options_parse_args(
|
||||
case 'p':
|
||||
options->mode = PROGRAM_MODE_PRINT;
|
||||
break;
|
||||
case 'P':
|
||||
options->preserve_gamma = 0;
|
||||
break;
|
||||
case 'r':
|
||||
options->use_fade = 0;
|
||||
break;
|
||||
|
||||
@@ -34,6 +34,8 @@ typedef struct {
|
||||
int temp_set;
|
||||
/* Whether to fade between large skips in color temperature. */
|
||||
int use_fade;
|
||||
/* Whether to preserve gamma ramps if supported by gamma method. */
|
||||
int preserve_gamma;
|
||||
|
||||
/* Selected gamma method. */
|
||||
const gamma_method_t *method;
|
||||
|
||||
+9
-6
@@ -603,7 +603,7 @@ run_continual_mode(const location_provider_t *provider,
|
||||
const transition_scheme_t *scheme,
|
||||
const gamma_method_t *method,
|
||||
gamma_state_t *method_state,
|
||||
int use_fade, int verbose)
|
||||
int use_fade, int preserve_gamma, int verbose)
|
||||
{
|
||||
int r;
|
||||
|
||||
@@ -796,7 +796,8 @@ run_continual_mode(const location_provider_t *provider,
|
||||
}
|
||||
|
||||
/* Adjust temperature */
|
||||
r = method->set_temperature(method_state, &interp);
|
||||
r = method->set_temperature(
|
||||
method_state, &interp, preserve_gamma);
|
||||
if (r < 0) {
|
||||
fputs(_("Temperature adjustment failed.\n"),
|
||||
stderr);
|
||||
@@ -1227,7 +1228,7 @@ main(int argc, char *argv[])
|
||||
if (options.mode != PROGRAM_MODE_PRINT) {
|
||||
/* Adjust temperature */
|
||||
r = options.method->set_temperature(
|
||||
method_state, &interp);
|
||||
method_state, &interp, options.preserve_gamma);
|
||||
if (r < 0) {
|
||||
fputs(_("Temperature adjustment failed.\n"),
|
||||
stderr);
|
||||
@@ -1256,7 +1257,8 @@ main(int argc, char *argv[])
|
||||
/* Adjust temperature */
|
||||
color_setting_t manual = scheme->day;
|
||||
manual.temperature = options.temp_set;
|
||||
r = options.method->set_temperature(method_state, &manual);
|
||||
r = options.method->set_temperature(
|
||||
method_state, &manual, options.preserve_gamma);
|
||||
if (r < 0) {
|
||||
fputs(_("Temperature adjustment failed.\n"), stderr);
|
||||
options.method->free(method_state);
|
||||
@@ -1278,7 +1280,7 @@ main(int argc, char *argv[])
|
||||
color_setting_t reset;
|
||||
color_setting_reset(&reset);
|
||||
|
||||
r = options.method->set_temperature(method_state, &reset);
|
||||
r = options.method->set_temperature(method_state, &reset, 0);
|
||||
if (r < 0) {
|
||||
fputs(_("Temperature adjustment failed.\n"), stderr);
|
||||
options.method->free(method_state);
|
||||
@@ -1299,7 +1301,8 @@ main(int argc, char *argv[])
|
||||
r = run_continual_mode(
|
||||
options.provider, location_state, scheme,
|
||||
options.method, method_state,
|
||||
options.use_fade, options.verbose);
|
||||
options.use_fade, options.preserve_gamma,
|
||||
options.verbose);
|
||||
if (r < 0) exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
+2
-2
@@ -88,8 +88,8 @@ typedef void gamma_method_print_help_func(FILE *f);
|
||||
typedef int gamma_method_set_option_func(gamma_state_t *state, const char *key,
|
||||
const char *value);
|
||||
typedef void gamma_method_restore_func(gamma_state_t *state);
|
||||
typedef int gamma_method_set_temperature_func(gamma_state_t *state,
|
||||
const color_setting_t *setting);
|
||||
typedef int gamma_method_set_temperature_func(
|
||||
gamma_state_t *state, const color_setting_t *setting, int preserve);
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
|
||||
Reference in New Issue
Block a user