Skip to content

Commit 461fa5a

Browse files
committed
Added a brightness setting to the GSD patches.
1 parent a72d072 commit 461fa5a

File tree

2 files changed

+122
-88
lines changed

2 files changed

+122
-88
lines changed

patches/gsd-3.22-color-Add-ability-to-change-the-color-temperature-of.patch

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
From f81dacbb7982a66cb58facd93eabe300b6ed202b Mon Sep 17 00:00:00 2001
1+
From 22ff87d414e97a8be0b464186cfe205a35e2b720 Mon Sep 17 00:00:00 2001
22
From: Benjamin Berg <[email protected]>
3-
Date: Sat, 19 Nov 2016 22:57:48 +0100
4-
Subject: [PATCH] color: Add ability to change the color temperature of the
5-
display
3+
Date: Wed, 18 Jan 2017 21:37:42 -0500
4+
Subject: [PATCH] color: Add ability to change the color temperature and
5+
brightness of the display
66

77
This is an experimental feature which allows the color temperature to be
88
changed while still keeping further gamma correction active.
@@ -12,20 +12,20 @@ This should be used with the experimental redshift extension from:
1212

1313
Signed-off-by: Benjamin Berg <[email protected]>
1414
---
15-
...settings-daemon.plugins.color.gschema.xml.in.in | 11 +
15+
...settings-daemon.plugins.color.gschema.xml.in.in | 17 ++
1616
plugins/color/Makefile.am | 4 +-
1717
plugins/color/colorramp.c | 308 +++++++++++++++++++++
1818
plugins/color/colorramp.h | 27 ++
19-
plugins/color/gsd-color-state.c | 69 ++++-
20-
5 files changed, 409 insertions(+), 10 deletions(-)
19+
plugins/color/gsd-color-state.c | 84 +++++-
20+
5 files changed, 429 insertions(+), 11 deletions(-)
2121
create mode 100644 plugins/color/colorramp.c
2222
create mode 100644 plugins/color/colorramp.h
2323

2424
diff --git a/data/org.gnome.settings-daemon.plugins.color.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.color.gschema.xml.in.in
25-
index e5bf62c..6b027ff 100644
25+
index e5bf62c6..e658686d 100644
2626
--- a/data/org.gnome.settings-daemon.plugins.color.gschema.xml.in.in
2727
+++ b/data/org.gnome.settings-daemon.plugins.color.gschema.xml.in.in
28-
@@ -20,5 +20,16 @@
28+
@@ -20,5 +20,22 @@
2929
<_summary>The duration a printer profile is valid</_summary>
3030
<_description>This is the number of days after which the printer color profile is considered invalid.</_description>
3131
</key>
@@ -39,11 +39,17 @@ index e5bf62c..6b027ff 100644
3939
+ <range min="1000" max="20000"/>
4040
+ <_summary>The color temperature of the displays</_summary>
4141
+ <_description>The color temperature of all displays that have a color profile is adjusted. A value of 6500 Kelvin is an identify transformation.</_description>
42+
+ </key>
43+
+ <key name="color-brightness" type="d">
44+
+ <default>1.0</default>
45+
+ <range min="0.1" max="1.0"/>
46+
+ <_summary>The color brightness of the displays</_summary>
47+
+ <_description>The color brightness of all displays that have a color profile is adjusted. Maximum standard brightness is 1.0.</_description>
4248
+ </key>
4349
</schema>
4450
</schemalist>
4551
diff --git a/plugins/color/Makefile.am b/plugins/color/Makefile.am
46-
index 0f7497a..e15913d 100644
52+
index 0f7497a9..e15913d2 100644
4753
--- a/plugins/color/Makefile.am
4854
+++ b/plugins/color/Makefile.am
4955
@@ -14,7 +14,9 @@ libcolor_la_SOURCES = \
@@ -59,7 +65,7 @@ index 0f7497a..e15913d 100644
5965
-I$(top_srcdir)/gnome-settings-daemon \
6066
diff --git a/plugins/color/colorramp.c b/plugins/color/colorramp.c
6167
new file mode 100644
62-
index 0000000..a4949d6
68+
index 00000000..1b4f297c
6369
--- /dev/null
6470
+++ b/plugins/color/colorramp.c
6571
@@ -0,0 +1,308 @@
@@ -346,7 +352,7 @@ index 0000000..a4949d6
346352
+}
347353
+
348354
+void
349-
+colorramp_get_factor(int to_temp, double *r, double *g, double *b)
355+
+colorramp_get_factor(int to_temp, double brightness, double *r, double *g, double *b)
350356
+{
351357
+ /* Approximate white point */
352358
+ float white_point[3];
@@ -367,13 +373,13 @@ index 0000000..a4949d6
367373
+ interpolate_color(alpha, &blackbody_color[temp_index],
368374
+ &blackbody_color[temp_index+3], white_point);
369375
+
370-
+ *r = white_point[0];
371-
+ *g = white_point[1];
372-
+ *b = white_point[2];
376+
+ *r = brightness * white_point[0];
377+
+ *g = brightness * white_point[1];
378+
+ *b = brightness * white_point[2];
373379
+}
374380
diff --git a/plugins/color/colorramp.h b/plugins/color/colorramp.h
375381
new file mode 100644
376-
index 0000000..436d736
382+
index 00000000..fcc32e8f
377383
--- /dev/null
378384
+++ b/plugins/color/colorramp.h
379385
@@ -0,0 +1,27 @@
@@ -401,11 +407,11 @@ index 0000000..436d736
401407
+
402408
+#include <stdint.h>
403409
+
404-
+void colorramp_get_factor(int to_temp, double *r, double *g, double *b);
410+
+void colorramp_get_factor(int to_temp, double brightness, double *r, double *g, double *b);
405411
+
406412
+#endif /* ! REDSHIFT_COLORRAMP_H */
407413
diff --git a/plugins/color/gsd-color-state.c b/plugins/color/gsd-color-state.c
408-
index 9f8308f..5ab4337 100644
414+
index 9f8308f8..a2f86d9f 100644
409415
--- a/plugins/color/gsd-color-state.c
410416
+++ b/plugins/color/gsd-color-state.c
411417
@@ -27,6 +27,7 @@
@@ -429,37 +435,38 @@ index 9f8308f..5ab4337 100644
429435
struct GsdColorStatePrivate
430436
{
431437
GCancellable *cancellable;
432-
@@ -53,6 +58,8 @@ struct GsdColorStatePrivate
438+
@@ -53,6 +58,9 @@ struct GsdColorStatePrivate
433439
GdkWindow *gdk_window;
434440
gboolean session_is_active;
435441
GHashTable *device_assign_hash;
436442
+ gint color_temperature;
443+
+ gdouble color_brightness;
437444
+ GSettings *settings;
438445
};
439446

440447
static void gsd_color_state_class_init (GsdColorStateClass *klass);
441-
@@ -360,7 +367,7 @@ out:
448+
@@ -360,7 +368,7 @@ out:
442449
}
443450

444451
static GPtrArray *
445452
-gcm_session_generate_vcgt (CdProfile *profile, guint size)
446-
+gcm_session_generate_vcgt (CdProfile *profile, gint color_temperature, guint size)
453+
+gcm_session_generate_vcgt (CdProfile *profile, gint color_temperature, gdouble color_brightness, guint size)
447454
{
448455
GnomeRROutputClutItem *tmp;
449456
GPtrArray *array = NULL;
450-
@@ -369,6 +376,7 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
457+
@@ -369,6 +377,7 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
451458
guint i;
452459
cmsHPROFILE lcms_profile;
453460
CdIcc *icc = NULL;
454461
+ double r, g, b;
455462

456463
/* invalid size */
457464
if (size == 0)
458-
@@ -387,14 +395,16 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
465+
@@ -387,14 +396,16 @@ gcm_session_generate_vcgt (CdProfile *profile, guint size)
459466
goto out;
460467
}
461468

462-
+ colorramp_get_factor(color_temperature, &r, &g, &b);
469+
+ colorramp_get_factor(color_temperature, color_brightness, &r, &g, &b);
463470
+
464471
/* create array */
465472
array = g_ptr_array_new_with_free_func (g_free);
@@ -475,46 +482,49 @@ index 9f8308f..5ab4337 100644
475482
g_ptr_array_add (array, tmp);
476483
}
477484
out:
478-
@@ -475,6 +485,7 @@ out:
485+
@@ -475,6 +486,8 @@ out:
479486
static gboolean
480487
gcm_session_device_set_gamma (GnomeRROutput *output,
481488
CdProfile *profile,
482489
+ gint color_temperature,
490+
+ gdouble color_brightness,
483491
GError **error)
484492
{
485493
gboolean ret = FALSE;
486-
@@ -487,7 +498,7 @@ gcm_session_device_set_gamma (GnomeRROutput *output,
494+
@@ -487,7 +500,7 @@ gcm_session_device_set_gamma (GnomeRROutput *output,
487495
ret = TRUE;
488496
goto out;
489497
}
490498
- clut = gcm_session_generate_vcgt (profile, size);
491-
+ clut = gcm_session_generate_vcgt (profile, color_temperature, size);
499+
+ clut = gcm_session_generate_vcgt (profile, color_temperature, color_brightness, size);
492500
if (clut == NULL) {
493501
g_set_error_literal (error,
494502
GSD_COLOR_MANAGER_ERROR,
495-
@@ -507,7 +518,7 @@ out:
503+
@@ -507,8 +520,8 @@ out:
496504
}
497505

498506
static gboolean
499507
-gcm_session_device_reset_gamma (GnomeRROutput *output,
508+
- GError **error)
500509
+gcm_session_device_reset_gamma (GnomeRROutput *output, gint color_temperature,
501-
GError **error)
510+
+ gdouble color_brightness, GError **error)
502511
{
503512
gboolean ret;
504-
@@ -516,6 +527,7 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
513+
guint i;
514+
@@ -516,6 +529,7 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
505515
guint32 value;
506516
GPtrArray *clut;
507517
GnomeRROutputClutItem *data;
508518
+ double r, g, b;
509519

510520
/* create a linear ramp */
511521
g_debug ("falling back to dummy ramp");
512-
@@ -525,12 +537,15 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
522+
@@ -525,12 +539,15 @@ gcm_session_device_reset_gamma (GnomeRROutput *output,
513523
ret = TRUE;
514524
goto out;
515525
}
516526
+
517-
+ colorramp_get_factor(color_temperature, &r, &g, &b);
527+
+ colorramp_get_factor(color_temperature, color_brightness, &r, &g, &b);
518528
+
519529
for (i = 0; i < size; i++) {
520530
value = (i * 0xffff) / (size - 1);
@@ -528,52 +538,59 @@ index 9f8308f..5ab4337 100644
528538
g_ptr_array_add (clut, data);
529539
}
530540

531-
@@ -669,6 +684,7 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
541+
@@ -669,6 +686,7 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
532542
guint brightness_percentage;
533543
GcmSessionAsyncHelper *helper = (GcmSessionAsyncHelper *) user_data;
534544
GsdColorState *state = GSD_COLOR_STATE (helper->state);
535545
+ GsdColorStatePrivate *priv = state->priv;
536546

537547
/* get properties */
538548
ret = cd_profile_connect_finish (profile, res, &error);
539-
@@ -720,6 +736,7 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
549+
@@ -720,6 +738,8 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
540550
if (ret) {
541551
ret = gcm_session_device_set_gamma (output,
542552
profile,
543553
+ priv->color_temperature,
554+
+ priv->color_brightness,
544555
&error);
545556
if (!ret) {
546557
g_warning ("failed to set %s gamma tables: %s",
547-
@@ -730,6 +747,7 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
558+
@@ -730,6 +750,8 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
548559
}
549560
} else {
550561
ret = gcm_session_device_reset_gamma (output,
551562
+ priv->color_temperature,
563+
+ priv->color_brightness,
552564
&error);
553565
if (!ret) {
554566
g_warning ("failed to reset %s gamma tables: %s",
555-
@@ -874,6 +892,7 @@ gcm_session_device_assign_connect_cb (GObject *object,
567+
@@ -874,6 +896,8 @@ gcm_session_device_assign_connect_cb (GObject *object,
556568

557569
/* reset, as we want linear profiles for profiling */
558570
ret = gcm_session_device_reset_gamma (output,
559571
+ priv->color_temperature,
572+
+ priv->color_brightness,
560573
&error);
561574
if (!ret) {
562575
g_warning ("failed to reset %s gamma tables: %s",
563-
@@ -1359,6 +1378,25 @@ out:
576+
@@ -1359,6 +1383,29 @@ out:
564577
}
565578

566579
static void
567580
+engine_settings_key_changed_cb (GSettings *settings,
568581
+ const gchar *key,
569582
+ GsdColorState *state)
570583
+{
571-
+ if (g_str_equal (key, "color-temperature") || g_str_equal (key, "adjust-color-temperature")) {
584+
+ if (g_str_equal (key, "color-temperature") || g_str_equal (key, "color-brightness") ||
585+
+ g_str_equal (key, "adjust-color-temperature")) {
572586
+ if (g_settings_get_boolean (state->priv->settings, "adjust-color-temperature")) {
573587
+ state->priv->color_temperature = g_settings_get_int (state->priv->settings,
574588
+ "color-temperature");
589+
+ state->priv->color_brightness = g_settings_get_double (state->priv->settings,
590+
+ "color-brightness");
575591
+ } else {
576592
+ state->priv->color_temperature = -1;
593+
+ state->priv->color_brightness = 1.0;
577594
+ }
578595
+
579596
+ /* Emulate a screen change event. */
@@ -586,7 +603,7 @@ index 9f8308f..5ab4337 100644
586603
on_rr_screen_acquired (GObject *object,
587604
GAsyncResult *result,
588605
gpointer data)
589-
@@ -1404,6 +1442,18 @@ gsd_color_state_start (GsdColorState *state)
606+
@@ -1404,6 +1451,21 @@ gsd_color_state_start (GsdColorState *state)
590607
gnome_rr_screen_new_async (gdk_screen_get_default (),
591608
on_rr_screen_acquired,
592609
g_object_ref (state));
@@ -599,20 +616,24 @@ index 9f8308f..5ab4337 100644
599616
+ if (g_settings_get_boolean (state->priv->settings, "adjust-color-temperature")) {
600617
+ state->priv->color_temperature = g_settings_get_int (state->priv->settings,
601618
+ "color-temperature");
619+
+ state->priv->color_brightness = g_settings_get_double (state->priv->settings,
620+
+ "color-brightness");
602621
+ } else {
603622
+ state->priv->color_temperature = -1;
623+
+ state->priv->color_brightness = 1.0;
604624
+ }
605625
}
606626

607627
void
608-
@@ -1431,6 +1481,7 @@ gsd_color_state_init (GsdColorState *state)
628+
@@ -1431,6 +1493,8 @@ gsd_color_state_init (GsdColorState *state)
609629

610630
/* track the active session */
611631
priv->session = gnome_settings_bus_get_session_proxy ();
612632
+ priv->color_temperature = -1;
633+
+ priv->color_brightness = 1.0;
613634

614635
#ifdef GDK_WINDOWING_X11
615636
/* set the _ICC_PROFILE atoms on the root screen */
616637
--
617-
2.10.2
638+
2.11.0
618639

0 commit comments

Comments
 (0)