Add Quartz (OSX) gamma adjustment method
This commit is contained in:
+32
-1
@@ -34,6 +34,8 @@ PKG_CHECK_MODULES([GLIB], [glib-2.0 gobject-2.0], [have_glib=yes], [have_glib=no
|
||||
PKG_CHECK_MODULES([GEOCLUE], [geoclue], [have_geoclue=yes], [have_geoclue=no])
|
||||
PKG_CHECK_MODULES([GEOCLUE2], [glib-2.0 gio-2.0 >= 2.26], [have_geoclue2=yes], [have_geoclue2=no])
|
||||
|
||||
AC_CHECK_HEADER([ApplicationServices/ApplicationServices.h], [have_appserv_h=yes], [have_appserv_h=no])
|
||||
|
||||
AC_CHECK_HEADER([windows.h], [have_windows_h=yes], [have_windows_h=no])
|
||||
|
||||
# Check for Python
|
||||
@@ -111,6 +113,34 @@ AS_IF([test "x$enable_vidmode" != xno], [
|
||||
])
|
||||
AM_CONDITIONAL([ENABLE_VIDMODE], [test "x$enable_vidmode" = xyes])
|
||||
|
||||
# Check Quartz (OSX) method
|
||||
AC_MSG_CHECKING([whether to enable Quartz method])
|
||||
AC_ARG_ENABLE([quartz], [AC_HELP_STRING([--enable-quartz],
|
||||
[enable Quartz (OSX) method])],
|
||||
[enable_quartz=$enableval],[enable_quartz=maybe])
|
||||
AS_IF([test "x$enable_quartz" != xno], [
|
||||
AS_IF([test $have_appserv_h = yes], [
|
||||
QUARTZ_CFLAGS=""
|
||||
QUARTZ_LIBS="-framework ApplicationServices"
|
||||
AC_DEFINE([ENABLE_QUARTZ], 1,
|
||||
[Define to 1 to enable Quartz method])
|
||||
AC_MSG_RESULT([yes])
|
||||
enable_quartz=yes
|
||||
], [
|
||||
AC_MSG_RESULT([missing dependencies])
|
||||
AS_IF([test "x$enable_quartz" = xyes], [
|
||||
AC_MSG_ERROR([missing Quartz headers])
|
||||
])
|
||||
enable_quartz=no
|
||||
])
|
||||
], [
|
||||
AC_MSG_RESULT([no])
|
||||
enable_quartz=no
|
||||
])
|
||||
AM_CONDITIONAL([ENABLE_QUARTZ], [test "x$enable_quartz" = xyes])
|
||||
AC_SUBST([QUARTZ_CFLAGS])
|
||||
AC_SUBST([QUARTZ_LIBS])
|
||||
|
||||
# Check Windows GDI method
|
||||
AC_MSG_CHECKING([whether to enable WinGDI method])
|
||||
AC_ARG_ENABLE([wingdi], [AC_HELP_STRING([--enable-wingdi],
|
||||
@@ -270,7 +300,8 @@ echo "
|
||||
DRM: ${enable_drm}
|
||||
RANDR: ${enable_randr}
|
||||
VidMode: ${enable_vidmode}
|
||||
WinGDI: ${enable_wingdi}
|
||||
Quartz (OSX): ${enable_quartz}
|
||||
WinGDI (Windows): ${enable_wingdi}
|
||||
|
||||
Location providers:
|
||||
Geoclue: ${enable_geoclue}
|
||||
|
||||
@@ -10,6 +10,7 @@ src/config-ini.c
|
||||
src/gamma-drm.c
|
||||
src/gamma-randr.c
|
||||
src/gamma-vidmode.c
|
||||
src/gamma-quartz.c
|
||||
src/gamma-w32gdi.c
|
||||
src/gamma-dummy.c
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ EXTRA_redshift_SOURCES = \
|
||||
gamma-drm.c gamma-drm.h \
|
||||
gamma-randr.c gamma-randr.h \
|
||||
gamma-vidmode.c gamma-vidmode.h \
|
||||
gamma-quartz.c gamma-quartz.h \
|
||||
gamma-w32gdi.c gamma-w32gdi.h \
|
||||
location-geoclue.c location-geoclue.h
|
||||
|
||||
@@ -51,6 +52,13 @@ redshift_LDADD += \
|
||||
$(XF86VM_LIBS) $(XF86VM_CFLAGS)
|
||||
endif
|
||||
|
||||
if ENABLE_QUARTZ
|
||||
redshift_SOURCES += gamma-quartz.c gamma-quartz.h
|
||||
AM_CFLAGS += $(QUARTZ_CFLAGS)
|
||||
redshift_LDADD += \
|
||||
$(QUARTZ_LIBS) $(QUARTZ_CFLAGS)
|
||||
endif
|
||||
|
||||
if ENABLE_WINGDI
|
||||
redshift_SOURCES += gamma-w32gdi.c gamma-w32gdi.h
|
||||
redshift_LDADD += -lgdi32
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
/* gamma-quartz.c -- Quartz (OSX) gamma adjustment
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(s) gettext(s)
|
||||
#else
|
||||
# define _(s) s
|
||||
#endif
|
||||
|
||||
#include "gamma-quartz.h"
|
||||
#include "colorramp.h"
|
||||
|
||||
|
||||
int
|
||||
quartz_init(quartz_state_t *state)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
quartz_start(quartz_state_t *state)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
quartz_restore(quartz_state_t *state)
|
||||
{
|
||||
CGDisplayRestoreColorSyncSettings();
|
||||
}
|
||||
|
||||
void
|
||||
quartz_free(quartz_state_t *state)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
quartz_print_help(FILE *f)
|
||||
{
|
||||
fputs(_("Adjust gamma ramps on OSX using Quartz.\n"), f);
|
||||
fputs("\n", f);
|
||||
}
|
||||
|
||||
int
|
||||
quartz_set_option(quartz_state_t *state, const char *key, const char *value)
|
||||
{
|
||||
fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
quartz_set_temperature_for_display(CGDirectDisplayID display, int temp,
|
||||
float brightness, const float gamma[3])
|
||||
{
|
||||
uint32_t ramp_size = CGDisplayGammaTableCapacity(display);
|
||||
if (ramp_size == 0) {
|
||||
fprintf(stderr, _("Gamma ramp size too small: %i\n"),
|
||||
ramp_size);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create new gamma ramps */
|
||||
float *gamma_ramps = malloc(3*ramp_size*sizeof(float));
|
||||
if (gamma_ramps == NULL) {
|
||||
perror("malloc");
|
||||
return;
|
||||
}
|
||||
|
||||
float *gamma_r = &gamma_ramps[0*ramp_size];
|
||||
float *gamma_g = &gamma_ramps[1*ramp_size];
|
||||
float *gamma_b = &gamma_ramps[2*ramp_size];
|
||||
|
||||
colorramp_fill_float(gamma_r, gamma_g, gamma_b, ramp_size,
|
||||
temp, brightness, gamma);
|
||||
|
||||
CGError error =
|
||||
CGSetDisplayTransferByTable(display, ramp_size,
|
||||
gamma_r, gamma_g, gamma_b);
|
||||
if (error != kCGErrorSuccess) {
|
||||
free(gamma_ramps);
|
||||
return;
|
||||
}
|
||||
|
||||
free(gamma_ramps);
|
||||
}
|
||||
|
||||
int
|
||||
quartz_set_temperature(quartz_state_t *state, int temp, float brightness,
|
||||
const float gamma[3])
|
||||
{
|
||||
int r;
|
||||
CGError error;
|
||||
uint32_t display_count;
|
||||
|
||||
error = CGGetOnlineDisplayList(0, NULL, &display_count);
|
||||
if (error != kCGErrorSuccess) return -1;
|
||||
|
||||
CGDirectDisplayID* displays =
|
||||
malloc(sizeof(CGDirectDisplayID)*display_count);
|
||||
if (displays == NULL) {
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
|
||||
error = CGGetOnlineDisplayList(display_count, displays,
|
||||
&display_count);
|
||||
if (error != kCGErrorSuccess) {
|
||||
free(displays);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < display_count; i++) {
|
||||
quartz_set_temperature_for_display(displays[i], temp,
|
||||
brightness, gamma);
|
||||
}
|
||||
|
||||
free(displays);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/* gamma-quartz.h -- Quartz (OSX) 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright (c) 2014 Jon Lund Steffensen <jonlst@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef REDSHIFT_GAMMA_QUARTZ_H
|
||||
#define REDSHIFT_GAMMA_QUARTZ_H
|
||||
|
||||
#include "redshift.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
int dummy;
|
||||
} quartz_state_t;
|
||||
|
||||
|
||||
int quartz_init(quartz_state_t *state);
|
||||
int quartz_start(quartz_state_t *state);
|
||||
void quartz_free(quartz_state_t *state);
|
||||
|
||||
void quartz_print_help(FILE *f);
|
||||
int quartz_set_option(quartz_state_t *state, const char *key,
|
||||
const char *value);
|
||||
|
||||
void quartz_restore(quartz_state_t *state);
|
||||
int quartz_set_temperature(quartz_state_t *state, int temp, float brightness,
|
||||
const float gamma[3]);
|
||||
|
||||
|
||||
#endif /* ! REDSHIFT_GAMMA_QUARTZ_H */
|
||||
@@ -65,6 +65,10 @@
|
||||
# include "gamma-vidmode.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_QUARTZ
|
||||
# include "gamma-quartz.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_WINGDI
|
||||
# include "gamma-w32gdi.h"
|
||||
#endif
|
||||
@@ -92,6 +96,9 @@ typedef union {
|
||||
#ifdef ENABLE_VIDMODE
|
||||
vidmode_state_t vidmode;
|
||||
#endif
|
||||
#ifdef ENABLE_QUARTZ
|
||||
quartz_state_t quartz;
|
||||
#endif
|
||||
#ifdef ENABLE_WINGDI
|
||||
w32gdi_state_t w32gdi;
|
||||
#endif
|
||||
@@ -136,6 +143,18 @@ static const gamma_method_t gamma_methods[] = {
|
||||
(gamma_method_set_temperature_func *)vidmode_set_temperature
|
||||
},
|
||||
#endif
|
||||
#ifdef ENABLE_QUARTZ
|
||||
{
|
||||
"quartz", 1,
|
||||
(gamma_method_init_func *)quartz_init,
|
||||
(gamma_method_start_func *)quartz_start,
|
||||
(gamma_method_free_func *)quartz_free,
|
||||
(gamma_method_print_help_func *)quartz_print_help,
|
||||
(gamma_method_set_option_func *)quartz_set_option,
|
||||
(gamma_method_restore_func *)quartz_restore,
|
||||
(gamma_method_set_temperature_func *)quartz_set_temperature
|
||||
},
|
||||
#endif
|
||||
#ifdef ENABLE_WINGDI
|
||||
{
|
||||
"wingdi", 1,
|
||||
|
||||
Reference in New Issue
Block a user