diff options
Diffstat (limited to 'src/crtc-server')
-rw-r--r-- | src/crtc-server/server.c | 41 | ||||
-rw-r--r-- | src/crtc-server/server.h | 7 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/crtc-server/server.c b/src/crtc-server/server.c index 6ce6560..6c524e5 100644 --- a/src/crtc-server/server.c +++ b/src/crtc-server/server.c @@ -19,6 +19,7 @@ #include "../state.h" #include "../communication.h" +#include <errno.h> #include <string.h> @@ -86,3 +87,43 @@ char* get_crtc_name(const libgamma_crtc_information_t* restrict info, } } + +/** + * Get partitions and CRTC:s + * + * @return Zero on success, -1 on error + */ +int initialise_crtcs(void) +{ + size_t i, j, n, n0; + int gerror; + + /* Get partitions */ + if (site.partitions_available) + if (!(partitions = calloc(site.partitions_available, sizeof(*partitions)))) + goto fail; + for (i = 0; i < site.partitions_available; i++) + { + if ((gerror = libgamma_partition_initialise(partitions + i, &site, i))) + goto fail_libgamma; + outputs_n += partitions[i].crtcs_available; + } + + /* Get CRTC:s */ + 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++) + if ((gerror = libgamma_crtc_initialise(crtcs + j, partitions + i, j - n0))) + goto fail_libgamma; + + return 0; + + fail_libgamma: + libgamma_perror(argv0, gerror); + errno = 0; + fail: + return -1; +} + diff --git a/src/crtc-server/server.h b/src/crtc-server/server.h index bc9ecf8..7dcfb18 100644 --- a/src/crtc-server/server.h +++ b/src/crtc-server/server.h @@ -55,6 +55,13 @@ GCC_ONLY(__attribute__((nonnull))) char* get_crtc_name(const libgamma_crtc_information_t* restrict info, const libgamma_crtc_state_t* restrict crtc); +/** + * Get partitions and CRTC:s + * + * @return Zero on success, -1 on error + */ +int initialise_crtcs(void); + #endif |