Skip to content

Commit eecbfed

Browse files
minus7giucamt-8chbreznakmartinetd
committed
Implement Wayland support
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 <[email protected]> Co-Authored-By: Thomas Weißschuh <[email protected]> Co-Authored-By: Marek Otahal <[email protected]> Co-Authored-By: Dominique Martinet <[email protected]>
1 parent 04760af commit eecbfed

File tree

13 files changed

+828
-12
lines changed

13 files changed

+828
-12
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ m4/lt~obsolete.m4
115115
/src/redshift-gtk/defs.py
116116
/src/redshift-gtk/redshift-gtk
117117
/src/redshift-gtk/__pycache__/
118+
/src/gamma-control-client-protocol.h
119+
/src/gamma-control-protocol.c
120+
/src/orbital-authorizer-client-protocol.h
121+
/src/orbital-authorizer-protocol.c
118122

119123
# gettext
120124
/po/POTFILES

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ addons:
2323
# VidMode
2424
- libx11-dev
2525
- libxxf86vm-dev
26+
# Wayland
27+
- libwayland-dev
2628
# GeoClue2
2729
- libglib2.0-dev
2830
# GUI

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build_script:
1717
$env:MSYSTEM = "MINGW32"
1818
}
1919
20-
$env:CONFIGURE_FLAGS = "--disable-drm --disable-randr --disable-vidmode --enable-wingdi --disable-quartz --disable-geoclue2 --disable-corelocation --disable-gui --disable-ubuntu --disable-nls --host=$env:arch-w64-mingw32"
20+
$env:CONFIGURE_FLAGS = "--disable-drm --disable-wayland --disable-randr --disable-vidmode --enable-wingdi --disable-quartz --disable-geoclue2 --disable-corelocation --disable-gui --disable-ubuntu --disable-nls --host=$env:arch-w64-mingw32"
2121
2222
- ps: md (Join-Path $env:APPVEYOR_BUILD_FOLDER root)
2323
- C:\msys64\usr\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER && ./bootstrap"

configure.ac

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ PKG_CHECK_MODULES([XF86VM], [xxf86vm], [have_xf86vm=yes], [have_xf86vm=no])
6767
PKG_CHECK_MODULES([XCB], [xcb], [have_xcb=yes], [have_xcb=no])
6868
PKG_CHECK_MODULES([XCB_RANDR], [xcb-randr],
6969
[have_xcb_randr=yes], [have_xcb_randr=no])
70+
PKG_CHECK_MODULES([WAYLAND], [wayland-client wayland-scanner], [have_wayland=yes], [have_wayland=no])
71+
PKG_CHECK_VAR(WAYLAND_SCANNER, wayland-scanner, wayland_scanner)
7072

7173
PKG_CHECK_MODULES([GLIB], [glib-2.0 gobject-2.0], [have_glib=yes], [have_glib=no])
7274
PKG_CHECK_MODULES([GEOCLUE2], [glib-2.0 gio-2.0 >= 2.26], [have_geoclue2=yes], [have_geoclue2=no])
@@ -124,6 +126,30 @@ AS_IF([test "x$enable_drm" != xno], [
124126
])
125127
AM_CONDITIONAL([ENABLE_DRM], [test "x$enable_drm" = xyes])
126128

129+
# Check Wayland method
130+
AC_MSG_CHECKING([whether to enable Wayland method])
131+
AC_ARG_ENABLE([wayland], [AC_HELP_STRING([--enable-wayland],
132+
[enable Wayland method])],
133+
[enable_wayland=$enableval],[enable_wayland=maybe])
134+
AS_IF([test "x$enable_wayland" != xno], [
135+
AS_IF([test $have_wayland = yes], [
136+
AC_DEFINE([ENABLE_WAYLAND], 1,
137+
[Define to 1 to enable Wayland method])
138+
AC_MSG_RESULT([yes])
139+
enable_wayland=yes
140+
], [
141+
AC_MSG_RESULT([missing dependencies])
142+
AS_IF([test "x$enable_wayland" = xyes], [
143+
AC_MSG_ERROR([missing dependencies for Wayland method])
144+
])
145+
enable_wayland=no
146+
])
147+
], [
148+
AC_MSG_RESULT([no])
149+
enable_wayland=no
150+
])
151+
AM_CONDITIONAL([ENABLE_WAYLAND], [test "x$enable_wayland" = xyes])
152+
127153
# Check RANDR method
128154
AC_MSG_CHECKING([whether to enable RANDR method])
129155
AC_ARG_ENABLE([randr], [AC_HELP_STRING([--enable-randr],
@@ -376,6 +402,7 @@ echo "
376402

377403
Adjustment methods:
378404
DRM: ${enable_drm}
405+
Wayland: ${enable_wayland}
379406
RANDR: ${enable_randr}
380407
VidMode: ${enable_vidmode}
381408
Quartz (macOS): ${enable_quartz}

po/POTFILES.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ src/options.c
99
src/config-ini.c
1010

1111
src/gamma-drm.c
12+
src/gamma-wl.c
1213
src/gamma-randr.c
1314
src/gamma-vidmode.c
1415
src/gamma-quartz.c

src/Makefile.am

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ redshift_SOURCES = \
2323

2424
EXTRA_redshift_SOURCES = \
2525
gamma-drm.c gamma-drm.h \
26+
gamma-wl.c gamma-wl.h \
2627
gamma-randr.c gamma-randr.h \
2728
gamma-vidmode.c gamma-vidmode.h \
2829
gamma-quartz.c gamma-quartz.h \
@@ -43,6 +44,27 @@ redshift_LDADD += \
4344
$(DRM_LIBS) $(DRM_CFLAGS)
4445
endif
4546

47+
if ENABLE_WAYLAND
48+
redshift_SOURCES += gamma-wl.c gamma-wl.h os-compatibility.c os-compatibility.h
49+
50+
AM_CFLAGS += $(WAYLAND_CFLAGS)
51+
52+
redshift_LDADD += \
53+
$(WAYLAND_LIBS) $(WAYLAND_CFLAGS)
54+
55+
nodist_redshift_SOURCES = \
56+
gamma-control-client-protocol.h \
57+
gamma-control-protocol.c \
58+
orbital-authorizer-protocol.c \
59+
orbital-authorizer-client-protocol.h
60+
61+
BUILT_SOURCES = \
62+
gamma-control-protocol.c \
63+
gamma-control-client-protocol.h \
64+
orbital-authorizer-protocol.c \
65+
orbital-authorizer-client-protocol.h
66+
endif
67+
4668
if ENABLE_RANDR
4769
redshift_SOURCES += gamma-randr.c gamma-randr.h
4870
AM_CFLAGS += $(XCB_CFLAGS) $(XCB_RANDR_CFLAGS)
@@ -103,3 +125,11 @@ endif
103125

104126
.rc.o:
105127
$(AM_V_GEN)$(WINDRES) -I$(top_builddir) -i $< -o $@
128+
129+
CLEANFILES = *-protocol.c *-client-protocol.h
130+
131+
%-protocol.c : $(srcdir)/%.xml
132+
$(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(WAYLAND_SCANNER) code < $< > $@
133+
134+
%-client-protocol.h : $(srcdir)/%.xml
135+
$(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(WAYLAND_SCANNER) client-header < $< > $@

src/gamma-control.xml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<protocol name="wlr_gamma_control_unstable_v1">
3+
<copyright>
4+
Copyright © 2015 Giulio camuffo
5+
Copyright © 2018 Simon Ser
6+
7+
Permission to use, copy, modify, distribute, and sell this
8+
software and its documentation for any purpose is hereby granted
9+
without fee, provided that the above copyright notice appear in
10+
all copies and that both that copyright notice and this permission
11+
notice appear in supporting documentation, and that the name of
12+
the copyright holders not be used in advertising or publicity
13+
pertaining to distribution of the software without specific,
14+
written prior permission. The copyright holders make no
15+
representations about the suitability of this software for any
16+
purpose. It is provided "as is" without express or implied
17+
warranty.
18+
19+
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
20+
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
21+
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
22+
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
24+
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
25+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
26+
THIS SOFTWARE.
27+
</copyright>
28+
29+
<description summary="manage gamma tables of outputs">
30+
This protocol allows a privileged client to set the gamma tables for
31+
outputs.
32+
33+
Warning! The protocol described in this file is experimental and
34+
backward incompatible changes may be made. Backward compatible changes
35+
may be added together with the corresponding interface version bump.
36+
Backward incompatible changes are done by bumping the version number in
37+
the protocol and interface names and resetting the interface version.
38+
Once the protocol is to be declared stable, the 'z' prefix and the
39+
version number in the protocol and interface names are removed and the
40+
interface version number is reset.
41+
</description>
42+
43+
<interface name="zwlr_gamma_control_manager_v1" version="1">
44+
<description summary="manager to create per-output gamma controls">
45+
This interface is a manager that allows creating per-output gamma
46+
controls.
47+
</description>
48+
49+
<request name="get_gamma_control">
50+
<description summary="get a gamma control for an output">
51+
Create a gamma control that can be used to adjust gamma tables for the
52+
provided output.
53+
</description>
54+
<arg name="id" type="new_id" interface="zwlr_gamma_control_v1"/>
55+
<arg name="output" type="object" interface="wl_output"/>
56+
</request>
57+
58+
<request name="destroy" type="destructor">
59+
<description summary="destroy the manager">
60+
All objects created by the manager will still remain valid, until their
61+
appropriate destroy request has been called.
62+
</description>
63+
</request>
64+
</interface>
65+
66+
<interface name="zwlr_gamma_control_v1" version="1">
67+
<description summary="adjust gamma tables for an output">
68+
This interface allows a client to adjust gamma tables for a particular
69+
output.
70+
71+
The client will receive the gamma size, and will then be able to set gamma
72+
tables. At any time the compositor can send a failed event indicating that
73+
this object is no longer valid.
74+
75+
There must always be at most one gamma control object per output, which
76+
has exclusive access to this particular output. When the gamma control
77+
object is destroyed, the gamma table is restored to its original value.
78+
</description>
79+
80+
<event name="gamma_size">
81+
<description summary="size of gamma ramps">
82+
Advertise the size of each gamma ramp.
83+
84+
This event is sent immediately when the gamma control object is created.
85+
</description>
86+
<arg name="size" type="uint"/>
87+
</event>
88+
89+
<enum name="error">
90+
<entry name="invalid_gamma" value="1" summary="invalid gamma tables"/>
91+
</enum>
92+
93+
<request name="set_gamma">
94+
<description summary="set the gamma table">
95+
Set the gamma table. The file descriptor can be memory-mapped to provide
96+
the raw gamma table, which contains successive gamma ramps for the red,
97+
green and blue channels. Each gamma ramp is an array of 16-byte unsigned
98+
integers which has the same length as the gamma size.
99+
100+
The file descriptor data must have the same length as three times the
101+
gamma size.
102+
</description>
103+
<arg name="fd" type="fd" summary="gamma table file descriptor"/>
104+
</request>
105+
106+
<event name="failed">
107+
<description summary="object no longer valid">
108+
This event indicates that the gamma control is no longer valid. This
109+
can happen for a number of reasons, including:
110+
- The output doesn't support gamma tables
111+
- Setting the gamma tables failed
112+
- Another client already has exclusive gamma control for this output
113+
- The compositor has transfered gamma control to another client
114+
115+
Upon receiving this event, the client should destroy this object.
116+
</description>
117+
</event>
118+
119+
<request name="destroy" type="destructor">
120+
<description summary="destroy this control">
121+
Destroys the gamma control object. If the object is still valid, this
122+
restores the original gamma tables.
123+
</description>
124+
</request>
125+
</interface>
126+
</protocol>

0 commit comments

Comments
 (0)