diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gammad.c | 37 | ||||
-rw-r--r-- | src/output.c | 16 | ||||
-rw-r--r-- | src/output.h | 12 |
3 files changed, 53 insertions, 12 deletions
diff --git a/src/gammad.c b/src/gammad.c index 1a01c69..9d517bd 100644 --- a/src/gammad.c +++ b/src/gammad.c @@ -35,6 +35,16 @@ */ char* argv0; +/** + * Array of all outputs + */ +struct output* outputs = NULL; + +/** + * The nubmer of elements in `outputs` + */ +size_t outputs_n = 0; + /** @@ -179,8 +189,7 @@ int main(int argc, char** argv) libgamma_site_state_t site; libgamma_partition_state_t* partitions = NULL; libgamma_crtc_state_t* crtcs = NULL; - struct output* outputs = NULL; - size_t i, j, n, n0, crtcs_n = 0; + size_t i, j, n, n0; memset(&site, 0, sizeof(site)); @@ -220,12 +229,12 @@ int main(int argc, char** argv) { if ((gerror = libgamma_partition_initialise(partitions + i, &site, i))) goto fail_libgamma; - crtcs_n += partitions[i].crtcs_available; + outputs_n += partitions[i].crtcs_available; } /* Get CRTC:s */ - if (crtcs_n) - if (!(crtcs = calloc(crtcs_n, sizeof(*crtcs)))) + if (outputs_n) + if (!(crtcs = calloc(outputs_n, sizeof(*crtcs)))) goto fail; for (i = 0, j = n = 0; i < site.partitions_available; i++) for (n0 = n, n += partitions[i].crtcs_available; j < n; j++) @@ -233,10 +242,10 @@ int main(int argc, char** argv) goto fail_libgamma; /* Get CRTC information */ - if (crtcs_n) - if (!(outputs = calloc(crtcs_n, sizeof(*outputs)))) + if (outputs_n) + if (!(outputs = calloc(outputs_n, sizeof(*outputs)))) goto fail; - for (i = 0; i < crtcs_n; i++) + for (i = 0; i < outputs_n; i++) { libgamma_crtc_information_t info; int saved_errno; @@ -263,6 +272,10 @@ int main(int argc, char** argv) if (outputs[i].name == NULL) goto fail; } + free(crtcs), crtcs = NULL; + + /* Sort outputs */ + qsort(outputs, outputs_n, sizeof(*outputs), output_cmp_by_name); /* Load current gamma ramps */ #define LOAD_RAMPS(SUFFIX, MEMBER) \ @@ -279,7 +292,7 @@ int main(int argc, char** argv) } \ } \ while (0) - for (i = 0; i < crtcs_n; i++) + for (i = 0; i < outputs_n; i++) if (outputs[i].supported != LIBGAMMA_NO) switch (outputs[i].depth) { @@ -324,8 +337,8 @@ int main(int argc, char** argv) libgamma_perror(argv0, gerror); \ } \ while (0) - if (crtcs != NULL) - for (i = 0; i < crtcs_n; i++) + if (outputs != NULL) + for (i = 0; i < outputs_n; i++) { if (outputs[i].supported != LIBGAMMA_NO) switch (outputs[i].depth) @@ -351,8 +364,8 @@ int main(int argc, char** argv) default: break; /* impossible */ } + libgamma_crtc_destroy(outputs[i].crtc + i); output_destroy(outputs + i); - libgamma_crtc_destroy(crtcs + i); } free(crtcs); if (partitions != NULL) diff --git a/src/output.c b/src/output.c index 2e399bf..d6fae94 100644 --- a/src/output.c +++ b/src/output.c @@ -205,3 +205,19 @@ size_t output_unmarshal(struct output* this, const char* buf) return off; } + +/** + * Compare to outputs by the names of their respective CRTC:s + * + * @param a Return -1 if this one is lower + * @param b Return +1 if this one is higher + * @return See description of `a` and `b`, + * 0 if returned if they are the same + */ +int output_cmp_by_name(const void* a, const void* b) +{ + const char* an = ((const struct output*)a)->name; + const char* bn = ((const struct output*)b)->name; + return strcmp(an, bn); +} + diff --git a/src/output.h b/src/output.h index b27059f..6e0c4d5 100644 --- a/src/output.h +++ b/src/output.h @@ -139,3 +139,15 @@ size_t output_marshal(const struct output* this, char* buf); */ size_t output_unmarshal(struct output* this, const char* buf); +/** + * Compare to outputs by the names of their respective CRTC:s + * + * @param a Return -1 if this one is lower + * @param b Return +1 if this one is higher + * @return See description of `a` and `b`, + * 0 if returned if they are the same + */ +#if defined(__GNUC__) +__attribute__((pure)) +#endif +int output_cmp_by_name(const void* a, const void* b); |