Received: from out.migadu.com (out.migadu.com [91.121.223.63]) by nld3-dev1.alpinelinux.org (Postfix) with ESMTPS id 02C8F7819E6 for <~alpine/aports@lists.alpinelinux.org>; Sun, 29 Mar 2020 04:40:57 +0000 (UTC) Received: (Migadu outbound); Sun, 29 Mar 2020 04:39:51 +0000 Authentication-Results: out.migadu.com; auth=pass (login) Received: from localhost (146-115-190-67.s3649.c3-0.wtr-cbr1.sbo-wtr.ma.cable.rcncustomer.com [146.115.190.67]) by out.migadu.com (Haraka/2.8.16) with ESMTPSA id EFBB134A-FE2E-471B-909D-5D1C72EA1BAE.1 envelope-from (authenticated bits=0) (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 verify=FAIL); Sun, 29 Mar 2020 04:39:48 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sun, 29 Mar 2020 00:11:50 -0400 Subject: [PATCH] community/redshift: Add wayland support patch From: "Cosmo Borsky" To: <~alpine/aports@lists.alpinelinux.org> Message-Id: DKIM-Signature: v=1;a=rsa-sha256;bh=uh5mcwGYXlL7GiD8dx5qairABTwgIPxUe6Gn/tgqdVA=;c=relaxed/simple;d=cosmoborsky.com;h=from:subject:date:to;s=default;b=yjBI4dRl8R59p8f2aUFfLgITvuUdbfbjsHpzbIjjJgly9ZGFnxq+cTQLwMk3BQfSstAyu8+2lrUxzVLalTLBVdvXf5dcUJkSBkDpgFnIQM+NrF1yCl8EYzm+FKRi+E+jRBoVR1pn0t9UcX3UmeYtUUt87SL25OuidzYa8WWB8oc= This patch comes from a fork of redshift by minus. The patch was edited to remove .gitignore, .travis.yml, and appveyor.yml changes. It didn't quite make sense to fork this package to add in one (large) patch= . If that is the desired action, do let me know. It has been almost 18 months since this patch for Wayland support was submitted to redshift with little interaction from the redshift developer, The patch seems to have been tested by various users, and is available in upstream repositories for Arch and other distros. NOTE: I have only tested this on Sway/Wayland. I would advise testing on X1= 1 and other supported platforms before merging. You can find more information about these changes at the following RedShift PRs: https://github.com/jonls/redshift/pull/663 --- .../0001-Implement-Wayland-support.patch | 1017 +++++++++++++++++ community/redshift/APKBUILD | 19 +- 2 files changed, 1032 insertions(+), 4 deletions(-) create mode 100644 community/redshift/0001-Implement-Wayland-support.patch diff --git a/community/redshift/0001-Implement-Wayland-support.patch b/comm= unity/redshift/0001-Implement-Wayland-support.patch new file mode 100644 index 0000000000..d3a2343f69 --- /dev/null +++ b/community/redshift/0001-Implement-Wayland-support.patch @@ -0,0 +1,1017 @@ +From 7da875d34854a6a34612d5ce4bd8718c32bec804 Mon Sep 17 00:00:00 2001 +From: minus +Date: Thu, 18 Apr 2019 00:43:21 +0200 +Subject: [PATCH] Implement Wayland support +MIME-Version: 1.0 +Content-Type: text/plain; charset=3DUTF-8 +Content-Transfer-Encoding: 8bit + +Implement the wlr_gamma_control_unstable_v1 protocol. +The Wayland backend is prioritized over randr since it will fail in +an X11 context anyway (but the randr backend would not fail in a Wayland +context with xwayland support). +The gamma setting is reset when the client disconnects, thus the +behavior for oneshot mode blocks, like for Quartz. + +Co-Authored-By: Giulio Camuffo +Co-Authored-By: Thomas Wei=C3=9Fschuh +Co-Authored-By: Marek Otahal +Co-Authored-By: Dominique Martinet +--- + configure.ac | 29 +++ + po/POTFILES.in | 1 + + src/Makefile.am | 32 ++++ + src/gamma-control.xml | 126 +++++++++++++ + src/gamma-wl.c | 372 +++++++++++++++++++++++++++++++++++++ + src/gamma-wl.h | 32 ++++ + src/orbital-authorizer.xml | 61 ++++++ + src/os-compatibility.c | 148 +++++++++++++++ + src/os-compatibility.h | 9 + + src/redshift.c | 32 ++-- + 13 files changed, 840 insertions(+), 14 deletions(-) + create mode 100644 src/gamma-control.xml + create mode 100644 src/gamma-wl.c + create mode 100644 src/gamma-wl.h + create mode 100644 src/orbital-authorizer.xml + create mode 100644 src/os-compatibility.c + create mode 100644 src/os-compatibility.h +diff --git a/configure.ac b/configure.ac +index b411626..8347dcc 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -68,6 +68,10 @@ PKG_CHECK_MODULES([XCB], [xcb], [have_xcb=3Dyes], [have= _xcb=3Dno]) + PKG_CHECK_MODULES([XCB_RANDR], [xcb-randr], + [have_xcb_randr=3Dyes], [have_xcb_randr=3Dno]) +=20 ++PKG_CHECK_MODULES([WAYLAND], [wayland-client wayland-scanner >=3D 1.15.0]= , ++ [have_wayland=3Dyes], [have_wayland=3Dno]) ++PKG_CHECK_VAR(WAYLAND_SCANNER, wayland-scanner, wayland_scanner) ++ + PKG_CHECK_MODULES([GLIB], [glib-2.0 gobject-2.0], [have_glib=3Dyes], [hav= e_glib=3Dno]) + PKG_CHECK_MODULES([GEOCLUE2], [glib-2.0 gio-2.0 >=3D 2.26], [have_geoclue= 2=3Dyes], [have_geoclue2=3Dno]) +=20 +@@ -124,6 +128,30 @@ AS_IF([test "x$enable_drm" !=3D xno], [ + ]) + AM_CONDITIONAL([ENABLE_DRM], [test "x$enable_drm" =3D xyes]) +=20 ++# Check Wayland method ++AC_MSG_CHECKING([whether to enable Wayland method]) ++AC_ARG_ENABLE([wayland], [AC_HELP_STRING([--enable-wayland], ++ [enable Wayland method])], ++ [enable_wayland=3D$enableval],[enable_wayland=3Dmaybe]) ++AS_IF([test "x$enable_wayland" !=3D xno], [ ++ AS_IF([test $have_wayland =3D yes], [ ++ AC_DEFINE([ENABLE_WAYLAND], 1, ++ [Define to 1 to enable Wayland method]) ++ AC_MSG_RESULT([yes]) ++ enable_wayland=3Dyes ++ ], [ ++ AC_MSG_RESULT([missing dependencies]) ++ AS_IF([test "x$enable_wayland" =3D xyes], [ ++ AC_MSG_ERROR([missing dependencies for Wayland method]) ++ ]) ++ enable_wayland=3Dno ++ ]) ++], [ ++ AC_MSG_RESULT([no]) ++ enable_wayland=3Dno ++]) ++AM_CONDITIONAL([ENABLE_WAYLAND], [test "x$enable_wayland" =3D xyes]) ++ + # Check RANDR method + AC_MSG_CHECKING([whether to enable RANDR method]) + AC_ARG_ENABLE([randr], [AC_HELP_STRING([--enable-randr], +@@ -376,6 +404,7 @@ echo " +=20 + Adjustment methods: + DRM: ${enable_drm} ++ Wayland: ${enable_wayland} + RANDR: ${enable_randr} + VidMode: ${enable_vidmode} + Quartz (macOS): ${enable_quartz} +diff --git a/po/POTFILES.in b/po/POTFILES.in +index 5ef8dac..1d25560 100644 +--- a/po/POTFILES.in ++++ b/po/POTFILES.in +@@ -9,6 +9,7 @@ src/options.c + src/config-ini.c +=20 + src/gamma-drm.c ++src/gamma-wl.c + src/gamma-randr.c + src/gamma-vidmode.c + src/gamma-quartz.c +diff --git a/src/Makefile.am b/src/Makefile.am +index 8aa96ea..ed40f2d 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -23,6 +23,7 @@ redshift_SOURCES =3D \ +=20 + EXTRA_redshift_SOURCES =3D \ + gamma-drm.c gamma-drm.h \ ++ gamma-wl.c gamma-wl.h \ + gamma-randr.c gamma-randr.h \ + gamma-vidmode.c gamma-vidmode.h \ + gamma-quartz.c gamma-quartz.h \ +@@ -43,6 +44,29 @@ redshift_LDADD +=3D \ + $(DRM_LIBS) $(DRM_CFLAGS) + endif +=20 ++if ENABLE_WAYLAND ++redshift_SOURCES +=3D gamma-wl.c gamma-wl.h os-compatibility.c os-compati= bility.h ++ ++AM_CFLAGS +=3D $(WAYLAND_CFLAGS) ++ ++redshift_LDADD +=3D \ ++ $(WAYLAND_LIBS) $(WAYLAND_CFLAGS) ++ ++nodist_redshift_SOURCES =3D \ ++ gamma-control-protocol.c \ ++ gamma-control-client-protocol.h \ ++ orbital-authorizer-protocol.c \ ++ orbital-authorizer-client-protocol.h ++ ++BUILT_SOURCES =3D \ ++ gamma-control-protocol.c \ ++ gamma-control-client-protocol.h \ ++ orbital-authorizer-protocol.c \ ++ orbital-authorizer-client-protocol.h ++ ++EXTRA_DIST +=3D gamma-control.xml orbital-authorizer.xml ++endif ++ + if ENABLE_RANDR + redshift_SOURCES +=3D gamma-randr.c gamma-randr.h + AM_CFLAGS +=3D $(XCB_CFLAGS) $(XCB_RANDR_CFLAGS) +@@ -103,3 +127,11 @@ endif +=20 + .rc.o: + $(AM_V_GEN)$(WINDRES) -I$(top_builddir) -i $< -o $@ ++ ++CLEANFILES =3D *-protocol.c *-client-protocol.h ++ ++%-protocol.c : $(srcdir)/%.xml ++ $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(WAYLAND_SCANNER) private-code < $< = > $@ ++ ++%-client-protocol.h : $(srcdir)/%.xml ++ $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(WAYLAND_SCANNER) client-header < $<= > $@ +diff --git a/src/gamma-control.xml b/src/gamma-control.xml +new file mode 100644 +index 0000000..ad71a15 +--- /dev/null ++++ b/src/gamma-control.xml +@@ -0,0 +1,126 @@ ++ ++ ++ ++ Copyright =C2=A9 2015 Giulio camuffo ++ Copyright =C2=A9 2018 Simon Ser ++ ++ Permission to use, copy, modify, distribute, and sell this ++ software and its documentation for any purpose is hereby granted ++ without fee, provided that the above copyright notice appear in ++ all copies and that both that copyright notice and this permission ++ notice appear in supporting documentation, and that the name of ++ the copyright holders not be used in advertising or publicity ++ pertaining to distribution of the software without specific, ++ written prior permission. The copyright holders make no ++ representations about the suitability of this software for any ++ purpose. It is provided "as is" without express or implied ++ warranty. ++ ++ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS ++ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND ++ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY ++ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ++ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ++ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ++ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ++ THIS SOFTWARE. ++ ++ ++ ++ This protocol allows a privileged client to set the gamma tables for ++ outputs. ++ ++ Warning! The protocol described in this file is experimental and ++ backward incompatible changes may be made. Backward compatible change= s ++ may be added together with the corresponding interface version bump. ++ Backward incompatible changes are done by bumping the version number = in ++ the protocol and interface names and resetting the interface version. ++ Once the protocol is to be declared stable, the 'z' prefix and the ++ version number in the protocol and interface names are removed and th= e ++ interface version number is reset. ++ ++ ++ ++ ++ This interface is a manager that allows creating per-output gamma ++ controls. ++ ++ ++ ++ ++ Create a gamma control that can be used to adjust gamma tables fo= r the ++ provided output. ++ ++ ++ ++ ++ ++ ++ ++ All objects created by the manager will still remain valid, until= their ++ appropriate destroy request has been called. ++ ++ ++ ++ ++ ++ ++ This interface allows a client to adjust gamma tables for a particu= lar ++ output. ++ ++ The client will receive the gamma size, and will then be able to se= t gamma ++ tables. At any time the compositor can send a failed event indicati= ng that ++ this object is no longer valid. ++ ++ There must always be at most one gamma control object per output, w= hich ++ has exclusive access to this particular output. When the gamma cont= rol ++ object is destroyed, the gamma table is restored to its original va= lue. ++ ++ ++ ++ ++ Advertise the size of each gamma ramp. ++ ++ This event is sent immediately when the gamma control object is c= reated. ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ Set the gamma table. The file descriptor can be memory-mapped to = provide ++ the raw gamma table, which contains successive gamma ramps for th= e red, ++ green and blue channels. Each gamma ramp is an array of 16-byte u= nsigned ++ integers which has the same length as the gamma size. ++ ++ The file descriptor data must have the same length as three times= the ++ gamma size. ++ ++ ++ ++ This event indicates that the gamma control is no longer valid. T= his ++ can happen for a number of reasons, including: ++ - The output doesn't support gamma tables ++ - Setting the gamma tables failed ++ - Another client already has exclusive gamma control for this out= put ++ - The compositor has transfered gamma control to another client ++ ++ Upon receiving this event, the client should destroy this object. ++ ++ ++ ++ ++ ++ Destroys the gamma control object. If the object is still valid, = this ++ restores the original gamma tables. ++ ++ ++ ++ +diff --git a/src/gamma-wl.c b/src/gamma-wl.c +new file mode 100644 +index 0000000..477c680 +--- /dev/null ++++ b/src/gamma-wl.c +@@ -0,0 +1,372 @@ ++/* gamma-wl.c -- Wayland gamma adjustment header ++ This file is part of Redshift. ++ ++ Redshift is free software: you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation, either version 3 of the License, or ++ (at your option) any later version. ++ ++ Redshift is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with Redshift. If not, see . ++ ++ Copyright (c) 2015 Giulio Camuffo ++*/ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef ENABLE_NLS ++# include ++# define _(s) gettext(s) ++#else ++# define _(s) s ++#endif ++ ++#include "gamma-wl.h" ++#include "os-compatibility.h" ++#include "colorramp.h" ++ ++#include "gamma-control-client-protocol.h" ++#include "orbital-authorizer-client-protocol.h" ++ ++typedef struct { ++ struct wl_display *display; ++ struct wl_registry *registry; ++ struct wl_callback *callback; ++ uint32_t gamma_control_manager_id; ++ struct zwlr_gamma_control_manager_v1 *gamma_control_manager; ++ int num_outputs; ++ struct output *outputs; ++ int authorized; ++} wayland_state_t; ++ ++struct output { ++ uint32_t global_id; ++ struct wl_output *output; ++ struct zwlr_gamma_control_v1 *gamma_control; ++ uint32_t gamma_size; ++}; ++ ++static int ++wayland_init(wayland_state_t **state) ++{ ++ /* Initialize state. */ ++ *state =3D malloc(sizeof(**state)); ++ if (*state =3D=3D NULL) return -1; ++ ++ memset(*state, 0, sizeof **state); ++ return 0; ++} ++ ++static void ++authorizer_feedback_granted(void *data, struct orbital_authorizer_feedbac= k *feedback) ++{ ++ wayland_state_t *state =3D data; ++ state->authorized =3D 1; ++} ++ ++static void ++authorizer_feedback_denied(void *data, struct orbital_authorizer_feedback= *feedback) ++{ ++ fprintf(stderr, _("Fatal: redshift was not authorized to bind the 'zwlr_= gamma_control_manager_v1' interface.\n")); ++ exit(EXIT_FAILURE); ++} ++ ++static const struct orbital_authorizer_feedback_listener authorizer_feedb= ack_listener =3D { ++ authorizer_feedback_granted, ++ authorizer_feedback_denied ++}; ++ ++static void ++registry_global(void *data, struct wl_registry *registry, uint32_t id, co= nst char *interface, uint32_t version) ++{ ++ wayland_state_t *state =3D data; ++ ++ if (strcmp(interface, "zwlr_gamma_control_manager_v1") =3D=3D 0) { ++ state->gamma_control_manager_id =3D id; ++ state->gamma_control_manager =3D wl_registry_bind(registry, id, &zwlr_g= amma_control_manager_v1_interface, 1); ++ } else if (strcmp(interface, "wl_output") =3D=3D 0) { ++ state->num_outputs++; ++ if (!(state->outputs =3D realloc(state->outputs, state->num_outputs * s= izeof(struct output)))) { ++ fprintf(stderr, _("Failed to allcate memory\n")); ++ return; ++ } ++ ++ struct output *output =3D &state->outputs[state->num_outputs - 1]; ++ output->global_id =3D id; ++ output->output =3D wl_registry_bind(registry, id, &wl_output_interface,= 1); ++ output->gamma_control =3D NULL; ++ } else if (strcmp(interface, "orbital_authorizer") =3D=3D 0) { ++ struct wl_event_queue *queue =3D wl_display_create_queue(state->display= ); ++ ++ struct orbital_authorizer *auth =3D wl_registry_bind(registry, id, &orb= ital_authorizer_interface, 1u); ++ wl_proxy_set_queue((struct wl_proxy *)auth, queue); ++ ++ struct orbital_authorizer_feedback *feedback =3D orbital_authorizer_aut= horize(auth, "zwlr_gamma_control_manager_v1"); ++ orbital_authorizer_feedback_add_listener(feedback, &authorizer_feedback= _listener, state); ++ ++ int ret =3D 0; ++ while (!state->authorized && ret >=3D 0) { ++ ret =3D wl_display_dispatch_queue(state->display, queue); ++ } ++ ++ orbital_authorizer_feedback_destroy(feedback); ++ orbital_authorizer_destroy(auth); ++ wl_event_queue_destroy(queue); ++ } ++} ++ ++static void ++registry_global_remove(void *data, struct wl_registry *registry, uint32_t= id) ++{ ++ wayland_state_t *state =3D data; ++ ++ if (state->gamma_control_manager_id =3D=3D id) { ++ fprintf(stderr, _("The zwlr_gamma_control_manager_v1 was removed\n")); ++ exit(EXIT_FAILURE); ++ } ++ ++ for (int i =3D 0; i < state->num_outputs; ++i) { ++ struct output *output =3D &state->outputs[i]; ++ if (output->global_id =3D=3D id) { ++ if (output->gamma_control) { ++ zwlr_gamma_control_v1_destroy(output->gamma_control); ++ output->gamma_control =3D NULL; ++ } ++ wl_output_destroy(output->output); ++ ++ /* If the removed output is not the last one in the array move the las= t one ++ * in the now empty slot. Then shrink the array */ ++ if (i < --state->num_outputs) { ++ memcpy(output, &state->outputs[state->num_outputs], sizeof(struct out= put)); ++ } ++ state->outputs =3D realloc(state->outputs, state->num_outputs * sizeof= (struct output)); ++ ++ return; ++ } ++ } ++} ++ ++static const struct wl_registry_listener registry_listener =3D { ++ registry_global, ++ registry_global_remove ++}; ++ ++static void ++gamma_control_gamma_size(void *data, struct zwlr_gamma_control_v1 *contro= l, uint32_t size) ++{ ++ struct output *output =3D data; ++ output->gamma_size =3D size; ++} ++ ++static void ++gamma_control_failed(void *data, struct zwlr_gamma_control_v1 *control) ++{ ++} ++ ++ ++static const struct zwlr_gamma_control_v1_listener gamma_control_listener= =3D { ++ gamma_control_gamma_size, ++ gamma_control_failed ++}; ++ ++static int ++wayland_start(wayland_state_t *state) ++{ ++ state->display =3D wl_display_connect(NULL); ++ if (!state->display) { ++ fputs(_("Could not connect to wayland display, exiting.\n"), stderr); ++ return -1; ++ } ++ state->registry =3D wl_display_get_registry(state->display); ++ ++ wl_registry_add_listener(state->registry, ®istry_listener, state); ++ ++ wl_display_roundtrip(state->display); ++ if (!state->gamma_control_manager) { ++ return -1; ++ } ++ if (state->num_outputs > 0 && !state->outputs) { ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static void ++wayland_restore(wayland_state_t *state) ++{ ++ for (int i =3D 0; i < state->num_outputs; ++i) { ++ struct output *output =3D &state->outputs[i]; ++ if (output->gamma_control) { ++ zwlr_gamma_control_v1_destroy(output->gamma_control); ++ output->gamma_control =3D NULL; ++ } ++ } ++ wl_display_flush(state->display); ++} ++ ++static void ++wayland_free(wayland_state_t *state) ++{ ++ int ret =3D 0; ++ /* Wait for the sync callback to destroy everything, otherwise ++ * we could destroy the gamma control before gamma has been set */ ++ while (state->callback && ret >=3D 0) { ++ ret =3D wl_display_dispatch(state->display); ++ } ++ if (state->callback) { ++ fprintf(stderr, _("Ignoring error on wayland connection while waiting t= o disconnect: %d\n"), ret); ++ wl_callback_destroy(state->callback); ++ } ++ ++ for (int i =3D 0; i < state->num_outputs; ++i) { ++ struct output *output =3D &state->outputs[i]; ++ if (output->gamma_control) { ++ zwlr_gamma_control_v1_destroy(output->gamma_control); ++ output->gamma_control =3D NULL; ++ } ++ wl_output_destroy(output->output); ++ } ++ ++ if (state->gamma_control_manager) { ++ zwlr_gamma_control_manager_v1_destroy(state->gamma_control_manager); ++ } ++ if (state->registry) { ++ wl_registry_destroy(state->registry); ++ } ++ if (state->display) { ++ wl_display_disconnect(state->display); ++ } ++ ++ free(state); ++} ++ ++static void ++wayland_print_help(FILE *f) ++{ ++ fputs(_("Adjust gamma ramps with a Wayland compositor.\n"), f); ++ fputs("\n", f); ++} ++ ++static int ++wayland_set_option(wayland_state_t *state, const char *key, const char *v= alue) ++{ ++ return 0; ++} ++ ++static void ++callback_done(void *data, struct wl_callback *cb, uint32_t t) ++{ ++ wayland_state_t *state =3D data; ++ state->callback =3D NULL; ++ wl_callback_destroy(cb); ++} ++ ++static const struct wl_callback_listener callback_listener =3D { ++ callback_done ++}; ++ ++static int ++wayland_set_temperature(wayland_state_t *state, const color_setting_t *se= tting) ++{ ++ int ret =3D 0, roundtrip =3D 0; ++ ++ /* We wait for the sync callback to throttle a bit and not send more ++ * requests than the compositor can manage, otherwise we'd get disconnec= ted. ++ * This also allows us to dispatch other incoming events such as ++ * wl_registry.global_remove. */ ++ while (state->callback && ret >=3D 0) { ++ ret =3D wl_display_dispatch(state->display); ++ } ++ if (ret < 0) { ++ fprintf(stderr, _("The Wayland connection experienced a fatal error: %d= \n"), ret); ++ return ret; ++ } ++ ++ for (int i =3D 0; i < state->num_outputs; ++i) { ++ struct output *output =3D &state->outputs[i]; ++ if (!output->gamma_control) { ++ output->gamma_control =3D zwlr_gamma_control_manager_v1_get_gamma_cont= rol(state->gamma_control_manager, output->output); ++ zwlr_gamma_control_v1_add_listener(output->gamma_control, &gamma_contr= ol_listener, output); ++ roundtrip =3D 1; ++ } ++ } ++ if (roundtrip) { ++ wl_display_roundtrip(state->display); ++ } ++ ++ for (int i =3D 0; i < state->num_outputs; ++i) { ++ struct output *output =3D &state->outputs[i]; ++ int size =3D output->gamma_size; ++ size_t ramp_bytes =3D size * sizeof(uint16_t); ++ size_t total_bytes =3D ramp_bytes * 3; ++ ++ int fd =3D os_create_anonymous_file(total_bytes); ++ if (fd < 0) { ++ perror("os_create_anonymous_file"); ++ return -1; ++ } ++ ++ void *ptr =3D mmap(NULL, total_bytes, ++ PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); ++ if (ptr =3D=3D MAP_FAILED) { ++ perror("mmap"); ++ close(fd); ++ return -1; ++ } ++ ++ uint16_t *r_gamma =3D ptr; ++ uint16_t *g_gamma =3D ptr + ramp_bytes; ++ uint16_t *b_gamma =3D ptr + 2 * ramp_bytes; ++ ++ /* Initialize gamma ramps to pure state */ ++ for (int i =3D 0; i < size; i++) { ++ uint16_t value =3D (double)i / size * (UINT16_MAX+1); ++ r_gamma[i] =3D value; ++ g_gamma[i] =3D value; ++ b_gamma[i] =3D value; ++ } ++ ++ colorramp_fill(r_gamma, g_gamma, b_gamma, size, setting); ++ if (munmap(ptr, total_bytes) =3D=3D -1) { ++ perror("munmap"); ++ close(fd); ++ return -1; ++ } ++ ++ zwlr_gamma_control_v1_set_gamma(output->gamma_control, fd); ++ close(fd); ++ } ++ ++ state->callback =3D wl_display_sync(state->display); ++ wl_callback_add_listener(state->callback, &callback_listener, state); ++ wl_display_flush(state->display); ++ ++ return 0; ++} ++ ++const gamma_method_t wl_gamma_method =3D { ++ "wayland", ++ 1, ++ (gamma_method_init_func *) wayland_init, ++ (gamma_method_start_func *) wayland_start, ++ (gamma_method_free_func *) wayland_free, ++ (gamma_method_print_help_func *) wayland_print_help, ++ (gamma_method_set_option_func *) wayland_set_option, ++ (gamma_method_restore_func *) wayland_restore, ++ (gamma_method_set_temperature_func *) wayland_set_temperature, ++}; +diff --git a/src/gamma-wl.h b/src/gamma-wl.h +new file mode 100644 +index 0000000..333e99b +--- /dev/null ++++ b/src/gamma-wl.h +@@ -0,0 +1,32 @@ ++/* gamma-wl.h -- Wayland gamma adjustment header ++ This file is part of Redshift. ++ ++ Redshift is free software: you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation, either version 3 of the License, or ++ (at your option) any later version. ++ ++ Redshift is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with Redshift. If not, see . ++ ++ Copyright (c) 2015 Giulio Camuffo ++*/ ++ ++#ifndef REDSHIFT_GAMMA_WAYLAND_H ++#define REDSHIFT_GAMMA_WAYLAND_H ++ ++#include ++ ++#include ++ ++#include "redshift.h" ++ ++extern const gamma_method_t wl_gamma_method; ++ ++ ++#endif /* ! REDSHIFT_GAMMA_DRM_H */ +diff --git a/src/orbital-authorizer.xml b/src/orbital-authorizer.xml +new file mode 100644 +index 0000000..bccaa08 +--- /dev/null ++++ b/src/orbital-authorizer.xml +@@ -0,0 +1,61 @@ ++ ++ ++ ++ ++ The orbital_authorizer global interface allows clients to ++ ask the compositor the authorization to bind certain restrict= ed ++ global interfaces. ++ Any client that aims to bind restricted interfaces should fir= st ++ request the authorization by using this interface. Failing to= do ++ so will result in the compositor sending a protocol error to = the ++ client when it binds the restricted interface. ++ ++ The list of restricted interfaces is compositor dependant, bu= t must ++ not include the core interfaces defined in wayland.xml. ++ ++ ++ ++ ++ ++ ++ ++ ++ The authorize request allows the client to ask the compos= itor the ++ authorization to bind a restricted global interface. The = newly ++ created orbital_authorizer_feedback will be invalid after= the ++ compositor send either the granted or denied event so the= client ++ must destroy it immediately after. ++ ++ ++ ++ ++ ++ ++ ++ ++ The orbital_authorizer_feedback interface is used by requesti= ng ++ an authorization with the orbital_authorizer.authorize reques= t. ++ The compositor will send either the granted or denied event b= ased ++ on the system and user configuration. How the authorization p= rocess ++ works is compositor specific, but a compositor is allowed to = ask ++ for user input, so the response for an authorization request = may ++ come after some time. ++ ++ ++ ++ ++ The authorization was granted. The client can now bind th= e restricted ++ interface. ++ ++ ++ ++ ++ ++ The authorization was denied. The client is not allowed t= o bind the ++ restricted interface and trying to do so will trigger a p= rotocol ++ error killing the client. ++ ++ ++ ++ ++ +diff --git a/src/os-compatibility.c b/src/os-compatibility.c +new file mode 100644 +index 0000000..32a9109 +--- /dev/null ++++ b/src/os-compatibility.c +@@ -0,0 +1,148 @@ ++/* ++ * Copyright =C2=A9 2012 Collabora, Ltd. ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining ++ * a copy of this software and associated documentation files (the ++ * "Software"), to deal in the Software without restriction, including ++ * without limitation the rights to use, copy, modify, merge, publish, ++ * distribute, sublicense, and/or sell copies of the Software, and to ++ * permit persons to whom the Software is furnished to do so, subject to ++ * the following conditions: ++ * ++ * The above copyright notice and this permission notice (including the ++ * next paragraph) shall be included in all copies or substantial ++ * portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ++ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ++ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ++ * SOFTWARE. ++ */ ++ ++#define _POSIX_C_SOURCE 200809L ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "os-compatibility.h" ++ ++int os_fd_set_cloexec(int fd) { ++ if (fd =3D=3D -1) { ++ return -1; ++ } ++ ++ long flags =3D fcntl(fd, F_GETFD); ++ if (flags =3D=3D -1) { ++ return -1; ++ } ++ ++ if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) =3D=3D -1) { ++ return -1; ++ } ++ ++ return 0; ++} ++ ++int set_cloexec_or_close(int fd) { ++ if (os_fd_set_cloexec(fd) !=3D 0) { ++ close(fd); ++ return -1; ++ } ++ return fd; ++} ++ ++int create_tmpfile_cloexec(char *tmpname) { ++ int fd; ++ mode_t prev_umask =3D umask(0066); ++#ifdef HAVE_MKOSTEMP ++ fd =3D mkostemp(tmpname, O_CLOEXEC); ++ if (fd >=3D 0) { ++ unlink(tmpname); ++ } ++#else ++ fd =3D mkstemp(tmpname); ++ if (fd >=3D 0) { ++ fd =3D set_cloexec_or_close(fd); ++ unlink(tmpname); ++ } ++#endif ++ umask(prev_umask); ++ ++ return fd; ++} ++ ++/* ++ * Create a new, unique, anonymous file of the given size, and ++ * return the file descriptor for it. The file descriptor is set ++ * CLOEXEC. The file is immediately suitable for mmap()'ing ++ * the given size at offset zero. ++ * ++ * The file should not have a permanent backing store like a disk, ++ * but may have if XDG_RUNTIME_DIR is not properly implemented in OS. ++ * ++ * The file name is deleted from the file system. ++ * ++ * The file is suitable for buffer sharing between processes by ++ * transmitting the file descriptor over Unix sockets using the ++ * SCM_RIGHTS methods. ++ * ++ * If the C library implements posix_fallocate(), it is used to ++ * guarantee that disk space is available for the file at the ++ * given size. If disk space is insufficient, errno is set to ENOSPC. ++ * If posix_fallocate() is not supported, program may receive ++ * SIGBUS on accessing mmap()'ed file contents instead. ++ */ ++int os_create_anonymous_file(off_t size) { ++ static const char template[] =3D "/redshift-shared-XXXXXX"; ++ ++ const char *path =3D getenv("XDG_RUNTIME_DIR"); ++ if (!path) { ++ errno =3D ENOENT; ++ return -1; ++ } ++ ++ char *name =3D malloc(strlen(path) + sizeof(template)); ++ if (!name) { ++ return -1; ++ } ++ ++ strcpy(name, path); ++ strcat(name, template); ++ ++ int fd =3D create_tmpfile_cloexec(name); ++ free(name); ++ if (fd < 0) { ++ return -1; ++ } ++ ++#ifdef WLR_HAS_POSIX_FALLOCATE ++ int ret; ++ do { ++ ret =3D posix_fallocate(fd, 0, size); ++ } while (ret =3D=3D EINTR); ++ if (ret !=3D 0) { ++ close(fd); ++ errno =3D ret; ++ return -1; ++ } ++#else ++ int ret; ++ do { ++ ret =3D ftruncate(fd, size); ++ } while (ret < 0 && errno =3D=3D EINTR); ++ if (ret < 0) { ++ close(fd); ++ return -1; ++ } ++#endif ++ ++ return fd; ++} +diff --git a/src/os-compatibility.h b/src/os-compatibility.h +new file mode 100644 +index 0000000..2038025 +--- /dev/null ++++ b/src/os-compatibility.h +@@ -0,0 +1,9 @@ ++#ifndef UTIL_OS_COMPATIBILITY_H ++#define UTIL_OS_COMPATIBILITY_H ++ ++int os_fd_set_cloexec(int fd); ++int set_cloexec_or_close(int fd); ++int create_tmpfile_cloexec(char *tmpname); ++int os_create_anonymous_file(off_t size); ++ ++#endif +diff --git a/src/redshift.c b/src/redshift.c +index e0221d5..488503e 100644 +--- a/src/redshift.c ++++ b/src/redshift.c +@@ -94,6 +94,10 @@ int poll(struct pollfd *fds, int nfds, int timeout) { a= bort(); return -1; } + # include "gamma-w32gdi.h" + #endif +=20 ++#ifdef ENABLE_WAYLAND ++# include "gamma-wl.h" ++#endif ++ +=20 + #include "location-manual.h" +=20 +@@ -902,6 +906,9 @@ main(int argc, char *argv[]) +=20 + /* List of gamma methods. */ + const gamma_method_t gamma_methods[] =3D { ++#ifdef ENABLE_WAYLAND ++ wl_gamma_method, ++#endif + #ifdef ENABLE_DRM + drm_gamma_method, + #endif +@@ -1237,11 +1244,12 @@ main(int argc, char *argv[]) + exit(EXIT_FAILURE); + } +=20 +- /* In Quartz (macOS) the gamma adjustments will +- automatically revert when the process exits. ++ /* In Quartz (macOS) and wayland, the gamma adjustments ++ will automatically revert when the process exits. + Therefore, we have to loop until CTRL-C is received. + */ +- if (strcmp(options.method->name, "quartz") =3D=3D 0) { ++ if (strcmp(options.method->name, "quartz") =3D=3D 0 || ++ strcmp(options.method->name, "wayland") =3D=3D 0) { + fputs(_("Press ctrl-c to stop...\n"), stderr); + pause(); + } +@@ -1266,10 +1274,11 @@ main(int argc, char *argv[]) + exit(EXIT_FAILURE); + } +=20 +- /* In Quartz (OSX) the gamma adjustments will automatically +- revert when the process exits. Therefore, we have to loop +- until CTRL-C is received. */ +- if (strcmp(options.method->name, "quartz") =3D=3D 0) { ++ /* In Quartz (OSX) and wayland, the gamma adjustments will ++ automatically revert when the process exits. ++ Therefore, we have to loop until CTRL-C is received. */ ++ if (strcmp(options.method->name, "quartz") =3D=3D 0 || ++ strcmp(options.method->name, "wayland") =3D=3D 0) { + fputs(_("Press ctrl-c to stop...\n"), stderr); + pause(); + } +@@ -1288,10 +1297,11 @@ main(int argc, char *argv[]) + exit(EXIT_FAILURE); + } +=20 +- /* In Quartz (OSX) the gamma adjustments will automatically +- revert when the process exits. Therefore, we have to loop +- until CTRL-C is received. */ +- if (strcmp(options.method->name, "quartz") =3D=3D 0) { ++ /* In Quartz (OSX) and wayland, the gamma adjustments will ++ automatically revert when the process exits. ++ Therefore, we have to loop until CTRL-C is received. */ ++ if (strcmp(options.method->name, "quartz") =3D=3D 0 || ++ strcmp(options.method->name, "wayland") =3D=3D 0) { + fputs(_("Press ctrl-c to stop...\n"), stderr); + pause(); + } +--=20 +2.24.1 + diff --git a/community/redshift/APKBUILD b/community/redshift/APKBUILD index 4504b5c4c9..f629800932 100644 --- a/community/redshift/APKBUILD +++ b/community/redshift/APKBUILD @@ -7,11 +7,21 @@ pkgdesc=3D"Adjusts the color temperature of your screen a= ccording to your surround url=3D"http://jonls.dk/redshift/" arch=3D"all" license=3D"GPL-3.0" -makedepends=3D"libxcb-dev libxxf86vm-dev libdrm-dev intltool" +makedepends=3D"libxcb-dev libxxf86vm-dev libdrm-dev intltool automake" subpackages=3D"$pkgname-doc" -source=3D"https://github.com/jonls/${pkgname}/releases/download/v${pkgver}= /${pkgname}-${pkgver}.tar.xz" +source=3D"https://github.com/jonls/${pkgname}/releases/download/v${pkgver}= /${pkgname}-${pkgver}.tar.xz + 0001-Implement-Wayland-support.patch" =20 builddir=3D"$srcdir"/$pkgname-$pkgver + +prepare() { + cd "$builddir" + patch -p1 -i "$srcdir"/0001-Implement-Wayland-support.patch + autoreconf -f -i + aclocal + intltoolize --force +} + build() { cd "$builddir" ./configure \ @@ -23,7 +33,7 @@ build() { --enable-randr \ --enable-vidmode \ --disable-silent-rules \ - --disable-nls \ + --disable-nls make } =20 @@ -37,4 +47,5 @@ package() { "$pkgdir"/usr/share/doc/$pkgname/ } =20 -sha512sums=3D"225e222e5f2c55be4571094ccaf02a92e162dfc35fd0fe504084e21e358b= 888a72f9992f9f9edaf1d496eb673af74a0d825ae5cf6ef7f0f1ab51d32419722c32 redsh= ift-1.12.tar.xz" +sha512sums=3D"225e222e5f2c55be4571094ccaf02a92e162dfc35fd0fe504084e21e358b= 888a72f9992f9f9edaf1d496eb673af74a0d825ae5cf6ef7f0f1ab51d32419722c32 redsh= ift-1.12.tar.xz +7b7b6fd56e581e008a1b062e493ce6dee1594198eab1e7f5e61a1a539d4943eb88e2d71aaa= ede60c8bf4aa2dbcc1b875997f62e3b54b74ce6680f3b659b607e1 0001-Implement-Wayl= and-support.patch" --=20 2.24.1