diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | src/filter.c | 46 | ||||
-rw-r--r-- | src/filter.h | 7 | ||||
-rw-r--r-- | src/gammad.c | 28 | ||||
-rw-r--r-- | src/output.c | 68 | ||||
-rw-r--r-- | src/output.h | 4 | ||||
-rw-r--r-- | src/ramps.c | 4 | ||||
-rw-r--r-- | src/ramps.h | 4 |
8 files changed, 102 insertions, 65 deletions
@@ -1,3 +1,7 @@ +PKGNAME = gammad +COMmAND = gammad + + SRC = filter gammad output ramps OPTIMISE = -Og -g @@ -16,7 +20,7 @@ FFLAGS = -fstrict-aliasing -fstrict-overflow -fipa-pure-const -ftree-vrp -fstack CCFLAGS = -std=c99 $(WARN) $(FFLAGS) $(OPTIMISE) LDFLAGS = $(OPTIMISE) -lgamma -CPPFLAGS = +CPPFLAGS = -D'PKGNAME="$(PKGNAME)"' -D'COMMAND="$(COMMAND)"' .PHONY: all diff --git a/src/filter.c b/src/filter.c index 508fd5f..5fa91ef 100644 --- a/src/filter.c +++ b/src/filter.c @@ -47,48 +47,49 @@ void filter_destroy(struct filter* this) * @param ramps_size The byte-size of `this->ramps` * @return The number of marshalled byte */ -size_t filter_marshal(const struct filter* this, char* buf, size_t ramps_size) +size_t filter_marshal(const struct filter* this, void* buf, size_t ramps_size) { size_t off = 0, n; char nonnulls = 0; + char* bs = buf; - if (buf != NULL) + if (bs != NULL) { if (this->crtc != NULL) nonnulls |= 1; if (this->class != NULL) nonnulls |= 2; if (this->ramps != NULL) nonnulls |= 4; - *(buf + off) = nonnulls; + *(bs + off) = nonnulls; } off += 1; - if (buf != NULL) - *(int64_t*)(buf + off) = this->priority; + if (bs != NULL) + *(int64_t*)(bs + off) = this->priority; off += sizeof(int64_t); - if (buf != NULL) - *(enum lifespan*)(buf + off) = this->lifespan; + if (bs != NULL) + *(enum lifespan*)(bs + off) = this->lifespan; off += sizeof(enum lifespan); if (this->crtc != NULL) { n = strlen(this->crtc) + 1; - if (buf != NULL) - memcpy(buf + off, this->crtc, n); + if (bs != NULL) + memcpy(bs + off, this->crtc, n); off += n; } if (this->class != NULL) { n = strlen(this->class) + 1; - if (buf != NULL) - memcpy(buf + off, this->class, n); + if (bs != NULL) + memcpy(bs + off, this->class, n); off += n; } if (this->ramps != NULL) { - if (buf != NULL) - memcpy(buf + off, this->ramps, ramps_size); + if (bs != NULL) + memcpy(bs + off, this->ramps, ramps_size); off += ramps_size; } @@ -104,43 +105,44 @@ size_t filter_marshal(const struct filter* this, char* buf, size_t ramps_size) * @param ramps_size The byte-size of `this->ramps` * @return The number of unmarshalled bytes, 0 on error */ -size_t filter_unmarshal(struct filter* this, const char* buf, size_t ramps_size) +size_t filter_unmarshal(struct filter* this, const void* buf, size_t ramps_size) { size_t off = 0, n; char nonnulls = 0; + const char* bs = buf; - nonnulls = *(buf + off); + nonnulls = *(bs + off); off += 1; this->crtc = NULL; this->class = NULL; this->ramps = NULL; - this->priority = *(const int64_t*)(buf + off); + this->priority = *(const int64_t*)(bs + off); off += sizeof(int64_t); - this->lifespan = *(const enum lifespan*)(buf + off); + this->lifespan = *(const enum lifespan*)(bs + off); off += sizeof(enum lifespan); if (nonnulls & 1) { - n = strlen(buf + off) + 1; - if (!(this->crtc = memdup(buf + off, n))) + n = strlen(bs + off) + 1; + if (!(this->crtc = memdup(bs + off, n))) goto fail; off += n; } if (nonnulls & 2) { - n = strlen(buf + off) + 1; - if (!(this->class = memdup(buf + off, n))) + n = strlen(bs + off) + 1; + if (!(this->class = memdup(bs + off, n))) goto fail; off += n; } if (nonnulls & 4) { - if (!(this->ramps = memdup(buf + off, ramps_size))) + if (!(this->ramps = memdup(bs + off, ramps_size))) goto fail; off += ramps_size; } diff --git a/src/filter.h b/src/filter.h index d53650c..f625125 100644 --- a/src/filter.h +++ b/src/filter.h @@ -51,7 +51,8 @@ struct filter { /** * The client that applied it. This need not be - * set unless `.lifespan == LIFESPAN_UNTIL_DEATH`. + * set unless `.lifespan == LIFESPAN_UNTIL_DEATH` + * and unless the process itself added this. * This is the file descriptor of the client's * connection. */ @@ -106,7 +107,7 @@ void filter_destroy(struct filter* this); * @param ramps_size The byte-size of `filter->ramps` * @return The number of marshalled byte */ -size_t filter_marshal(const struct filter* this, char* buf, size_t ramps_size); +size_t filter_marshal(const struct filter* this, void* buf, size_t ramps_size); /** * Unmarshal a filter @@ -117,5 +118,5 @@ size_t filter_marshal(const struct filter* this, char* buf, size_t ramps_size); * @param ramps_size The byte-size of `filter->ramps` * @return The number of unmarshalled bytes, 0 on error */ -size_t filter_unmarshal(struct filter* this, const char* buf, size_t ramps_size); +size_t filter_unmarshal(struct filter* this, const void* buf, size_t ramps_size); diff --git a/src/gammad.c b/src/gammad.c index 9d517bd..43c3586 100644 --- a/src/gammad.c +++ b/src/gammad.c @@ -325,6 +325,34 @@ int main(int argc, char** argv) break; } + /* Preserve current gamma ramps at priority=0 if -p */ + if (preserve) + for (i = 0; i < outputs_n; i++) + { + struct filter filter = { + .client = -1, + .crtc = NULL, + .priority = 0, + .class = NULL, + .lifespan = LIFESPAN_UNTIL_REMOVAL, + .ramps = NULL + }; + outputs[i].table_filters = calloc(4, sizeof(*(outputs[i].table_filters))); + outputs[i].table_sums = calloc(4, sizeof(*(outputs[i].table_sums))); + outputs[i].table_alloc = 4; + outputs[i].table_size = 1; + filter.class = memdup(PKGNAME "::" COMMAND "::preserved", sizeof(PKGNAME "::" COMMAND "::preserved")); + if (filter.class == NULL) + goto fail; + filter.ramps = memdup(outputs[i].saved_ramps.u8.red, outputs[i].ramps_size); + if (filter.ramps == NULL) + goto fail; + outputs[i].table_filters[0] = filter; + COPY_RAMP_SIZES(&(outputs[i].table_sums[0].u8), outputs + i); + if (!gamma_ramps_unmarshal(outputs[i].table_sums, outputs[i].saved_ramps.u8.red, outputs[i].ramps_size)) + goto fail; + } + /* Done */ rc = 0; done: diff --git a/src/output.c b/src/output.c index d6fae94..b0e0c14 100644 --- a/src/output.c +++ b/src/output.c @@ -88,49 +88,50 @@ void output_destroy(struct output* this) * needs to be * @return The number of marshalled byte */ -size_t output_marshal(const struct output* this, char* buf) +size_t output_marshal(const struct output* this, void* buf) { size_t off = 0, i, n; + char* bs = buf; - if (buf != NULL) - *(signed*)(buf + off) = this->depth; + if (bs != NULL) + *(signed*)(bs + off) = this->depth; off += sizeof(signed); - if (buf != NULL) - *(size_t*)(buf + off) = this->red_size; + if (bs != NULL) + *(size_t*)(bs + off) = this->red_size; off += sizeof(size_t); - if (buf != NULL) - *(size_t*)(buf + off) = this->green_size; + if (bs != NULL) + *(size_t*)(bs + off) = this->green_size; off += sizeof(size_t); - if (buf != NULL) - *(size_t*)(buf + off) = this->blue_size; + if (bs != NULL) + *(size_t*)(bs + off) = this->blue_size; off += sizeof(size_t); - if (buf != NULL) - *(size_t*)(buf + off) = this->ramps_size; + if (bs != NULL) + *(size_t*)(bs + off) = this->ramps_size; off += sizeof(size_t); - if (buf != NULL) - *(enum libgamma_decision*)(buf + off) = this->supported; + if (bs != NULL) + *(enum libgamma_decision*)(bs + off) = this->supported; off += sizeof(enum libgamma_decision); n = strlen(this->name) + 1; - if (buf != NULL) - memcpy(buf + off, this->name, n); + if (bs != NULL) + memcpy(bs + off, this->name, n); off += n; - off += gamma_ramps_marshal(&(this->saved_ramps), buf ? buf + off : NULL, this->ramps_size); + off += gamma_ramps_marshal(&(this->saved_ramps), bs ? bs + off : NULL, this->ramps_size); - if (buf != NULL) - *(size_t*)(buf + off) = this->table_size; + if (bs != NULL) + *(size_t*)(bs + off) = this->table_size; off += sizeof(size_t); for (i = 0; i < this->table_size; i++) { - off += filter_marshal(this->table_filters + i, buf ? buf + off : NULL, this->ramps_size); - off += gamma_ramps_marshal(this->table_sums + i, buf ? buf + off : NULL, this->ramps_size); + off += filter_marshal(this->table_filters + i, bs ? bs + off : NULL, this->ramps_size); + off += gamma_ramps_marshal(this->table_sums + i, bs ? bs + off : NULL, this->ramps_size); } return off; @@ -144,42 +145,43 @@ size_t output_marshal(const struct output* this, char* buf) * @param buf Buffer with the marshalled output * @return The number of unmarshalled bytes, 0 on error */ -size_t output_unmarshal(struct output* this, const char* buf) +size_t output_unmarshal(struct output* this, const void* buf) { size_t off = 0, i, n; + const char* bs = buf; this->crtc = NULL; this->name = NULL; - this->depth = *(const signed*)(buf + off); + this->depth = *(const signed*)(bs + off); off += sizeof(signed); - this->red_size = *(const size_t*)(buf + off); + this->red_size = *(const size_t*)(bs + off); off += sizeof(size_t); - this->green_size = *(const size_t*)(buf + off); + this->green_size = *(const size_t*)(bs + off); off += sizeof(size_t); - this->blue_size = *(const size_t*)(buf + off); + this->blue_size = *(const size_t*)(bs + off); off += sizeof(size_t); - this->ramps_size = *(const size_t*)(buf + off); + this->ramps_size = *(const size_t*)(bs + off); off += sizeof(size_t); - this->supported = *(const enum libgamma_decision*)(buf + off); + this->supported = *(const enum libgamma_decision*)(bs + off); off += sizeof(enum libgamma_decision); - n = strlen(buf + off) + 1; - this->name = memdup(buf + off, n); + n = strlen(bs + off) + 1; + this->name = memdup(bs + off, n); if (this->name == NULL) return 0; - off += n = gamma_ramps_unmarshal(&(this->saved_ramps), buf, this->ramps_size); + off += n = gamma_ramps_unmarshal(&(this->saved_ramps), bs, this->ramps_size); COPY_RAMP_SIZES(&(this->saved_ramps.u8), this); if (n == 0) return 0; - this->table_size = this->table_alloc = *(const size_t*)(buf + off); + this->table_size = this->table_alloc = *(const size_t*)(bs + off); off += sizeof(size_t); if (this->table_size > 0) { @@ -193,11 +195,11 @@ size_t output_unmarshal(struct output* this, const char* buf) for (i = 0; i < this->table_size; i++) { - off += n = filter_unmarshal(this->table_filters + i, buf + off, this->ramps_size); + off += n = filter_unmarshal(this->table_filters + i, bs + off, this->ramps_size); if (n == 0) return 0; COPY_RAMP_SIZES(&(this->table_sums[i].u8), this); - off += n = gamma_ramps_unmarshal(this->table_sums + i, buf + off, this->ramps_size); + off += n = gamma_ramps_unmarshal(this->table_sums + i, bs + off, this->ramps_size); if (n == 0) return 0; } diff --git a/src/output.h b/src/output.h index 6e0c4d5..248dad6 100644 --- a/src/output.h +++ b/src/output.h @@ -128,7 +128,7 @@ void output_destroy(struct output* this); * needs to be * @return The number of marshalled byte */ -size_t output_marshal(const struct output* this, char* buf); +size_t output_marshal(const struct output* this, void* buf); /** * Unmarshal an output @@ -137,7 +137,7 @@ size_t output_marshal(const struct output* this, char* buf); * @param buf Buffer with the marshalled output * @return The number of unmarshalled bytes, 0 on error */ -size_t output_unmarshal(struct output* this, const char* buf); +size_t output_unmarshal(struct output* this, const void* buf); /** * Compare to outputs by the names of their respective CRTC:s diff --git a/src/ramps.c b/src/ramps.c index 2c24b52..32c7994 100644 --- a/src/ramps.c +++ b/src/ramps.c @@ -40,7 +40,7 @@ extern char* argv0; * @param ramps_size The byte-size of ramps * @return The number of marshalled byte */ -size_t gamma_ramps_marshal(const union gamma_ramps* this, char* buf, size_t ramps_size) +size_t gamma_ramps_marshal(const union gamma_ramps* this, void* buf, size_t ramps_size) { if (buf != NULL) memcpy(buf, this->u8.red, ramps_size); @@ -57,7 +57,7 @@ size_t gamma_ramps_marshal(const union gamma_ramps* this, char* buf, size_t ramp * @param ramps_size The byte-size of ramps * @return The number of unmarshalled bytes, 0 on error */ -size_t gamma_ramps_unmarshal(union gamma_ramps* this, const char* buf, size_t ramps_size) +size_t gamma_ramps_unmarshal(union gamma_ramps* this, const void* buf, size_t ramps_size) { size_t depth = ramps_size / (this->u8.red_size + this->u8.green_size + this->u8.blue_size); int r = 0; diff --git a/src/ramps.h b/src/ramps.h index 7aa08fd..d01a22e 100644 --- a/src/ramps.h +++ b/src/ramps.h @@ -68,7 +68,7 @@ union gamma_ramps * @param ramps_size The byte-size of ramps * @return The number of marshalled byte */ -size_t gamma_ramps_marshal(const union gamma_ramps* this, char* buf, size_t ramps_size); +size_t gamma_ramps_marshal(const union gamma_ramps* this, void* buf, size_t ramps_size); /** * Unmarshal a ramp trio @@ -78,5 +78,5 @@ size_t gamma_ramps_marshal(const union gamma_ramps* this, char* buf, size_t ramp * @param ramps_size The byte-size of ramps * @return The number of unmarshalled bytes, 0 on error */ -size_t gamma_ramps_unmarshal(union gamma_ramps* this, const char* buf, size_t ramps_size); +size_t gamma_ramps_unmarshal(union gamma_ramps* this, const void* buf, size_t ramps_size); |