aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-03-23 19:13:11 +0100
committerMattias Andrée <m@maandree.se>2025-03-23 19:13:11 +0100
commit52a74b078e44e8f65dfdd2afdc0621fc7ea30d73 (patch)
treebc4f03e190ebfc9e77f807b6c0cfc6a7bc307166
parentAdd ability to select screen in crtc option (diff)
downloadredshift-ng-52a74b078e44e8f65dfdd2afdc0621fc7ea30d73.tar.gz
redshift-ng-52a74b078e44e8f65dfdd2afdc0621fc7ea30d73.tar.bz2
redshift-ng-52a74b078e44e8f65dfdd2afdc0621fc7ea30d73.tar.xz
Add ability to select multiple screens
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r--README38
-rw-r--r--TODO1
-rw-r--r--redshift.143
-rw-r--r--src/backend-direct.c63
4 files changed, 97 insertions, 48 deletions
diff --git a/README b/README
index 976764b..5ff673f 100644
--- a/README
+++ b/README
@@ -607,17 +607,20 @@ EXTENDED DESCRIPTION
available on Unix-like systems) and "corelocation" (available on
Mac OS X).
- Options for the location provider "randr" (preferred method for X) are:
+ Options for the adjustment method "randr" (preferred method for X) are:
display = name
X display to apply adjustments to. Default is determined
by the environment variable DISPLAY.
screen = ordinal
- X screen to apply adjustments to. All will be used if not
- specified.
+ Comma-separated (,) list of X screens to apply adjustments to.
+ All available X screens are used if the list is empty or if the
+ setting is omitted.
- crtc = number list or all
+ "all" may be specified as a synonym for an empty list.
+
+ crtc = number list or "all"
Comma-separated (,) list of CRTC numbers for monitors to
apply adjustments to. All available CRTCs are used if the
list is empty or if the setting is omitted.
@@ -632,7 +635,7 @@ EXTENDED DESCRIPTION
The index of the first CRTC is 0.
- edid = name list or list
+ edid = name list or "list"
Comma-separated (,) list of EDIDs of monitors to apply
adjustments to.
@@ -642,23 +645,30 @@ EXTENDED DESCRIPTION
This list must not be empty; to select all monitors,
instead specify crtc=all.
- Options for the location provider "vidmode" (fallback method for X) are:
+ Options for the adjustment method "vidmode" (fallback method for X) are:
display = name
X display to apply adjustments to. Default is determined
by the environment variable DISPLAY.
- screen = ordinal
- X screen to apply adjustments to. All will be used if not
- specified.
+ screen = ordinal list or "all"
+ Comma-separated (,) list of X screens to apply adjustments to.
+ All available X screens are used if the list is empty or if the
+ setting is omitted.
- Options for the location provider "drm" (method for Linux without
+ "all" may be specified as a synonym for an empty list.
+
+ Options for the adjustment method "drm" (method for Linux without
display server) are:
- card = ordinal
- Index of graphics card to apply adjustments to.
+ card = ordinal list or "all"
+ Comma-separated (,) list of indices of graphics card screens to
+ apply adjustments to. All available graphics cards are used if
+ the list is empty or if the setting is omitted.
+
+ "all" may be specified as a synonym for an empty list.
- crtc = number list or all
+ crtc = number list or "all"
Comma-separated (,) list of CRTC numbers for monitors to
apply adjustments to. All available CRTCs are used if the
list is empty or if the setting is omitted.
@@ -673,7 +683,7 @@ EXTENDED DESCRIPTION
The index of the first CRTC is 0.
- edid = name list or list
+ edid = name list or "list"
Comma-separated (,) list of EDIDs of monitors to apply
adjustments to.
diff --git a/TODO b/TODO
index 1b0748c..f813cc0 100644
--- a/TODO
+++ b/TODO
@@ -143,7 +143,6 @@ When disabled, redshift should be periodically set the gamma ramps
Add signals for setting location
Add signals for responding with sigqueue the state of redshift
-Add support for selecting multiple screens
Document option delimiter for -l and -m
The method option "display" requires support for ":", use ";" delimit after "display"
":" cannot be changed to ";" for all options are this would break backwards
diff --git a/redshift.1 b/redshift.1
index bd9b1bc..944da66 100644
--- a/redshift.1
+++ b/redshift.1
@@ -947,7 +947,7 @@ There are no options for the location providers
.B corelocation
(available on Mac OS X).
.PP
-Options for the location provider
+Options for the adjustment method
.B randr
(preferred method for X) are:
.TP
@@ -956,9 +956,15 @@ X display to apply adjustments to. Default is determined
by the environment variable
.IR DISPLAY .
.TP
-.BI screen\fR\ =\ ordinal
-X screen to apply adjustments to. All will be used if not
-specified.
+.BI screen\fR\ =\ "ordinal list or " all
+Comma-separated
+.RB ( , )
+list of X screens to apply adjustments to.
+All available X screens are used if the list is empty or
+if the setting is omitted.
+
+.B all
+may be specified as a synonym for an empty list.
.TP
.BI crtc\fR\ =\ "number list or " all
Comma-separated
@@ -995,7 +1001,7 @@ This list must not be empty; to select all monitors,
instead specify
.BR crtc=all .
.PP
-Options for the location provider
+Options for the adjustment method
.B vidmode
(fallback method for X) are:
.TP
@@ -1003,17 +1009,30 @@ Options for the location provider
X display to apply adjustments to. Default is determined
by the environment variable
.IR DISPLAY .
-.TP
-.BI screen\fR\ =\ ordinal
-X screen to apply adjustments to. All will be used if not
-specified.
+.BI screen\fR\ =\ "ordinal list or " all
+Comma-separated
+.RB ( , )
+list of X screens to apply adjustments to.
+All available X screens are used if the list is empty or
+if the setting is omitted.
+
+.B all
+may be specified as a synonym for an empty list.
.PP
-Options for the location provider
+Options for the adjustment method
.B drm
(method for Linux without display server) are:
.TP
-.BI card\fR\ =\ ordinal
-Index of graphics card to apply adjustments to.
+.BI card\fR\ =\ "ordinal list or " all
+Comma-separated
+.RB ( , )
+list of indices of graphics card screens to apply
+adjustments to. All available graphics cards
+are used if the list is empty or
+if the setting is omitted.
+
+.B all
+may be specified as a synonym for an empty list.
.TP
.BI crtc\fR\ =\ "number list or " all
Comma-separated
diff --git a/src/backend-direct.c b/src/backend-direct.c
index de58548..37c82c6 100644
--- a/src/backend-direct.c
+++ b/src/backend-direct.c
@@ -140,7 +140,7 @@ struct gamma_state {
/**
* Whether a parition has been selected
*/
- unsigned partition_selected : 1;
+ unsigned partitions_selected : 1;
/**
* Whether CRTCs have been selected
@@ -158,11 +158,6 @@ struct gamma_state {
int method;
/**
- * Selected parition (if `partition_selected`)
- */
- size_t selected_partition;
-
- /**
* Number of selected CRTCs
*/
size_t ncrtcs;
@@ -178,6 +173,11 @@ struct gamma_state {
size_t npartitions;
/**
+ * Selected paritions (if `partitions_selected`)
+ */
+ size_t *selected_partitions;
+
+ /**
* Selected CRTC numbers
*
* Deallocated by when no longer needed
@@ -274,7 +274,7 @@ direct_print_help(FILE *f, int method)
fprintf(f, " card=%s %s\n", _("N "), _("Graphics card to apply adjustments to"));
} else if (caps.multiple_partitions) {
/* TRANSLATORS: "N" represents "ordinal"; right-pad with spaces to preserve display width */
- fprintf(f, " screen=%s %s\n", _("N "), _("X screen to apply adjustments to"));
+ fprintf(f, " screen=%s %s\n", _("N "), _("List of comma-separated X screens to apply adjustments to"));
}
if (caps.multiple_crtcs) {
@@ -327,21 +327,38 @@ direct_set_site(struct gamma_state *state, const char *key, const char *value)
int
direct_set_partitions(struct gamma_state *state, const char *key, const char *value)
{
- const char *end;
+ const char *end, *p;
uintmax_t num;
+ size_t count;
/* Check previously unspecified */
- if (state->partition_selected)
+ if (state->partitions_selected)
weprintf(_("`%s' option specified multiple times, using last selection."), key);
- state->partition_selected = 1;
+ state->partitions_selected = 1;
- /* Parse number */
+ /* Check if all are selected */
+ state->npartitions = 0;
+ free(state->selected_partitions);
+ state->selected_partitions = NULL;
+ if (!*value || !strcasecmp(value, "all"))
+ return 0;
+
+ /* Get number count */
+ for (p = value, count = 1; *p; p++)
+ if (*p == ',')
+ count++;
+ state->selected_partitions = ecalloc(count, sizeof(*state->selected_partitions));
+
+ /* Parse numbers */
errno = 0;
- num = strtoumax(value, (void *)&end, 10);
- state->selected_partition = (size_t)num;
- if (num > (uintmax_t)SIZE_MAX || *end || !isdigit(*value) || errno) {
- weprintf(_("Invalid value of `%s' option: `%s'."), key, value);
- return -1;
+ for (p = value; *p; p = end) {
+ num = strtoumax(p, (void *)&end, 10);
+ state->selected_partitions[state->npartitions++] = (size_t)num;
+ if (num > (uintmax_t)SIZE_MAX || (*end && *end != ',') || !isdigit(*p) || errno) {
+ weprintf(_("Invalid value of `%s' option: `%s'."), key, value);
+ return -1;
+ }
+ end = &end[*end == ','];
}
return 0;
@@ -478,11 +495,14 @@ direct_start(struct gamma_state *state)
}
/* Allocate partition states */
- if (state->partition_selected) {
- state->partitions = ecalloc(1, sizeof(*state->partitions));
- state->partitions[0].state.partition = state->selected_partition;
- state->partitions[0].state.data = NULL;
- state->npartitions = 1;
+ if (state->npartitions) {
+ state->partitions = ecalloc(state->npartitions, sizeof(*state->partitions));
+ for (i = 0; i < state->npartitions; i++) {
+ state->partitions[i].state.partition = state->selected_partitions[i];
+ state->partitions[i].state.data = NULL;
+ }
+ free(state->selected_partitions);
+ state->selected_partitions = NULL;
} else if (!state->site.partitions_available) {
if (state->partitions_are_graphics_cards)
weprintf(_("No graphics card found."));
@@ -908,6 +928,7 @@ direct_free(struct gamma_state *state)
libgamma_partition_destroy(&state->partitions[i].state);
free(state->partitions);
}
+ free(state->selected_partitions);
free(state->selected_crtcs);
if (state->selected_edids) {
for (i = 0; i < state->nedids; i++)