[gnome-settings-daemon/wip/benzea/sysfs-backlight-switch: 42/42] power: Bind building sysfs backlight helper to meson option



commit 6ecb27b9835b7482115da3c0f02055d2ffd573ca
Author: Benjamin Berg <bberg redhat com>
Date:   Mon Oct 1 10:52:53 2018 +0200

    power: Bind building sysfs backlight helper to meson option
    
    This is require so that BSDs can explicitly disable building the
    backlight helper. BSDs also have udev/GUdev support to some extend,
    which is why we need the explicit option.
    
    See issue #94

 meson.build                   |  9 +++++++++
 meson_options.txt             |  2 ++
 plugins/power/gsd-backlight.c | 28 ++++++++++++++--------------
 plugins/power/meson.build     |  5 +++--
 plugins/power/test.py         | 35 +++++++++++++++++++++++++++++++----
 5 files changed, 59 insertions(+), 20 deletions(-)
---
diff --git a/meson.build b/meson.build
index c94c4f85..ac1d5d75 100644
--- a/meson.build
+++ b/meson.build
@@ -126,6 +126,14 @@ if enable_gudev
 endif
 config_h.set10('HAVE_GUDEV', enable_gudev)
 
+# Linux sysfs backlight support (default enabled)
+enable_sysfs_backlight = get_option('sysfs_backlight')
+if enable_sysfs_backlight
+  assert(enable_gudev, 'GUDev support is required for sysfs backlight support.')
+endif
+config_h.set10('HAVE_SYSFS_BACKLIGHT', enable_sysfs_backlight)
+
+# Timer FD checking
 has_timerfd_create = cc.has_function('timerfd_create')
 config_h.set10('HAVE_TIMERFD', has_timerfd_create)
 
@@ -240,6 +248,7 @@ output += '        Cups support:             ' + enable_cups.to_string() + '\n'
 output += '        Wayland support:          ' + enable_wayland.to_string() + '\n'
 output += '        Wacom support:            ' + enable_wacom.to_string() + '\n'
 output += '        RFKill support:           ' + enable_rfkill.to_string() + '\n'
+output += '        Sysfs backlight support:  ' + enable_sysfs_backlight.to_string() + '\n'
 if enable_smartcard
   output += '        System nssdb:             ' + system_nssdb_dir + '\n'
 endif
diff --git a/meson_options.txt b/meson_options.txt
index 50bd1749..241f4e81 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -8,3 +8,5 @@ option('network_manager', type: 'boolean', value: true, description: 'build with
 option('rfkill', type: 'boolean', value: true, description: 'build with rfkill support (not optional on 
Linux platforms)')
 option('smartcard', type: 'boolean', value: true, description: 'build with smartcard support')
 option('wayland', type: 'boolean', value: true, description: 'build with Wayland support')
+
+option('sysfs_backlight', type: 'boolean', value: true, description: 'build with brightness control code via 
sysfs for Linux platforms')
diff --git a/plugins/power/gsd-backlight.c b/plugins/power/gsd-backlight.c
index 33e46af7..a9eb05df 100644
--- a/plugins/power/gsd-backlight.c
+++ b/plugins/power/gsd-backlight.c
@@ -25,9 +25,9 @@
 #include "gsd-power-constants.h"
 #include "gsd-power-manager.h"
 
-#ifdef HAVE_GUDEV
+#if HAVE_SYSFS_BACKLIGHT
 #include <gudev/gudev.h>
-#endif /* HAVE_GUDEV */
+#endif /* HAVE_SYSFS_BACKLIGHT */
 
 struct _GsdBacklight
 {
@@ -39,7 +39,7 @@ struct _GsdBacklight
         gint brightness_target;
         gint brightness_step;
 
-#ifdef HAVE_GUDEV
+#if HAVE_SYSFS_BACKLIGHT
         GUdevClient *udev;
         GUdevDevice *udev_device;
 
@@ -47,7 +47,7 @@ struct _GsdBacklight
         GQueue tasks;
 
         gint idle_update;
-#endif
+#endif /* HAVE_SYSFS_BACKLIGHT */
 
         GnomeRRScreen *rr_screen;
 };
@@ -70,7 +70,7 @@ G_DEFINE_TYPE_EXTENDED (GsdBacklight, gsd_backlight, G_TYPE_OBJECT, 0,
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
                                                gsd_backlight_initable_iface_init);)
 
-#ifdef HAVE_GUDEV
+#if HAVE_SYSFS_BACKLIGHT
 static GUdevDevice*
 gsd_backlight_udev_get_type (GList *devices, const gchar *type)
 {
@@ -395,7 +395,7 @@ gsd_backlight_process_taskqueue (GsdBacklight *backlight)
         /* And run it! */
         gsd_backlight_run_set_helper (backlight, to_run);
 }
-#endif /* HAVE_GUDEV */
+#endif /* HAVE_SYSFS_BACKLIGHT */
 
 static GnomeRROutput*
 gsd_backlight_rr_find_output (GsdBacklight *backlight, gboolean controllable)
@@ -464,7 +464,7 @@ gsd_backlight_set_brightness_val_async (GsdBacklight *backlight,
 
         task = g_task_new (backlight, cancellable, callback, user_data);
 
-#ifdef HAVE_GUDEV
+#if HAVE_SYSFS_BACKLIGHT
         if (backlight->udev_device != NULL) {
                 BacklightHelperData *task_data;
 
@@ -478,7 +478,7 @@ gsd_backlight_set_brightness_val_async (GsdBacklight *backlight,
 
                 return;
         }
-#endif /* HAVE_GUDEV */
+#endif /* HAVE_SYSFS_BACKLIGHT */
 
         /* Fallback to setting via GNOME RR/X11 */
         output = gsd_backlight_rr_find_output (backlight, TRUE);
@@ -716,11 +716,11 @@ gsd_backlight_initable_init (GInitable       *initable,
                 return FALSE;
         }
 
-#ifdef HAVE_GUDEV
+#if HAVE_SYSFS_BACKLIGHT
         /* Try finding a udev device. */
         if (gsd_backlight_udev_init (backlight))
                 goto found;
-#endif /* HAVE_GUDEV */
+#endif /* HAVE_SYSFS_BACKLIGHT */
 
         /* Try GNOME RR as a fallback. */
         output = gsd_backlight_rr_find_output (backlight, TRUE);
@@ -755,7 +755,7 @@ gsd_backlight_finalize (GObject *object)
 {
         GsdBacklight *backlight = GSD_BACKLIGHT (object);
 
-#ifdef HAVE_GUDEV
+#if HAVE_SYSFS_BACKLIGHT
         g_assert (backlight->active_task == NULL);
         g_assert (g_queue_is_empty (&backlight->tasks));
         g_clear_object (&backlight->udev);
@@ -764,7 +764,7 @@ gsd_backlight_finalize (GObject *object)
                 g_source_remove (backlight->idle_update);
                 backlight->idle_update = 0;
         }
-#endif /* HAVE_GUDEV */
+#endif /* HAVE_SYSFS_BACKLIGHT */
 
         g_clear_object (&backlight->rr_screen);
 }
@@ -807,10 +807,10 @@ gsd_backlight_init (GsdBacklight *backlight)
         backlight->brightness_val = -1;
         backlight->brightness_step = 1;
 
-#ifdef HAVE_GUDEV
+#if HAVE_SYSFS_BACKLIGHT
         backlight->active_task = NULL;
         g_queue_init (&backlight->tasks);
-#endif /* HAVE_GUDEV */
+#endif /* HAVE_SYSFS_BACKLIGHT */
 }
 
 GsdBacklight *
diff --git a/plugins/power/meson.build b/plugins/power/meson.build
index ea07ae9a..fc886440 100644
--- a/plugins/power/meson.build
+++ b/plugins/power/meson.build
@@ -25,7 +25,7 @@ native_deps = [
   dependency('gio-2.0', native:true)
 ]
 
-if enable_gudev
+if enable_sysfs_backlight
   deps += gudev_dep
 endif
 
@@ -67,7 +67,7 @@ gsd_power_enums_update = executable(
   native: true
 )
 
-if enable_gudev
+if enable_sysfs_backlight
   policy = 'org.gnome.settings-daemon.plugins.power.policy'
 
   policy_in = configure_file(
@@ -130,6 +130,7 @@ envs = [
   'BUILDDIR=' + meson.current_build_dir(),
   'TOP_BUILDDIR=' + meson.build_root(),
   'LD_PRELOAD=libumockdev-preload.so.0',
+  'HAVE_SYSFS_BACKLIGHT=' + (enable_sysfs_backlight ? '1' : '0')
 ]
 
 foreach i : [ 1, 2, 3, 4, 5, 6, 7, 8 ]
diff --git a/plugins/power/test.py b/plugins/power/test.py
index 57be628e..bbbea7b8 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -60,6 +60,11 @@ class PowerPluginBase(gsdtestcase.GSDTestCase):
         # device based on the name of the test.
         self.add_backlight()
 
+        if 'HAVE_SYSFS_BACKLIGHT' in os.environ and os.environ['HAVE_SYSFS_BACKLIGHT'] == 1:
+            self.skip_sysfs_backlight = False
+        else:
+            self.skip_sysfs_backlight = True
+
         # start mock upowerd
         (self.upowerd, self.obj_upower) = self.spawn_server_template(
             'upower', {'DaemonVersion': '0.99', 'OnBattery': True, 'LidIsClosed': False}, 
stdout=subprocess.PIPE)
@@ -538,7 +543,8 @@ class PowerPluginTest1(PowerPluginBase):
         time.sleep(0.5)
         self.reset_idle_timer()
         self.check_unblank(2)
-        self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS , 'incorrect 
unblanked brightness (%d != %d)' % (self.get_brightness(), gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS))
+        if not self.skip_sysfs_backlight:
+            self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS , 
'incorrect unblanked brightness (%d != %d)' % (self.get_brightness(), 
gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS))
 
         # Check for no blank before the normal blank timeout
         self.check_no_blank(gsdpowerconstants.SCREENSAVER_TIMEOUT_BLANK - 4)
@@ -790,8 +796,9 @@ class PowerPluginTest5(PowerPluginBase):
         self.check_dim(gsdpowerconstants.MINIMUM_IDLE_DIM_DELAY + 1)
         # Give time for the brightness to change
         time.sleep(2)
-        level = self.get_brightness();
-        self.assertTrue(level == dim_level, 'incorrect dim brightness (%d != %d)' % (level, dim_level))
+        if not self.skip_sysfs_backlight:
+            level = self.get_brightness();
+            self.assertTrue(level == dim_level, 'incorrect dim brightness (%d != %d)' % (level, dim_level))
 
         self.assertEqual(self.get_status(), gsdpowerenums.GSM_PRESENCE_STATUS_AVAILABLE)
 
@@ -811,7 +818,8 @@ class PowerPluginTest5(PowerPluginBase):
         time.sleep(1)
 
         # And check that we have the pre-dim brightness
-        self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS , 'incorrect 
unblanked brightness (%d != %d)' % (self.get_brightness(), gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS))
+        if not self.skip_sysfs_backlight:
+            self.assertTrue(self.get_brightness() == gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS , 
'incorrect unblanked brightness (%d != %d)' % (self.get_brightness(), 
gsdpowerconstants.GSD_MOCK_DEFAULT_BRIGHTNESS))
 
     def test_lid_close_inhibition(self):
         '''Check that we correctly inhibit suspend with an external monitor'''
@@ -1043,6 +1051,9 @@ class PowerPluginTest8(PowerPluginBase):
     def test_brightness_stepping(self):
         '''Check that stepping the backlight works as expected'''
 
+        if self.skip_sysfs_backlight:
+            self.skipTest("sysfs backlight support required for test")
+
         obj_gsd_power = self.session_bus_con.get_object(
             'org.gnome.SettingsDaemon.Power', '/org/gnome/SettingsDaemon/Power')
         obj_gsd_power_screen_iface = dbus.Interface(obj_gsd_power, 'org.gnome.SettingsDaemon.Power.Screen')
@@ -1098,6 +1109,10 @@ class PowerPluginTest8(PowerPluginBase):
 
     def test_brightness_compression(self):
         '''Check that compression also happens when setting the property'''
+
+        if self.skip_sysfs_backlight:
+            self.skipTest("sysfs backlight support required for test")
+
         # Now test that the compression works correctly.
         # NOTE: Relies on the implementation detail, that the property setter
         #       returns immediately rather than waiting for the brightness to
@@ -1120,6 +1135,9 @@ class PowerPluginTest8(PowerPluginBase):
         self.assertEqual(self.get_brightness(), 90)
 
     def test_brightness_uevent(self):
+        if self.skip_sysfs_backlight:
+            self.skipTest("sysfs backlight support required for test")
+
         obj_gsd_power = self.session_bus_con.get_object(
             'org.gnome.SettingsDaemon.Power', '/org/gnome/SettingsDaemon/Power')
         obj_gsd_power_prop_iface = dbus.Interface(obj_gsd_power, dbus.PROPERTIES_IFACE)
@@ -1140,18 +1158,27 @@ class PowerPluginTest8(PowerPluginBase):
         self.assertEqual(80, brightness)
 
     def test_brightness_step(self):
+        if self.skip_sysfs_backlight:
+            self.skipTest("sysfs backlight support required for test")
+
         # We cannot use check_plugin_log here because the startup check already
         # read the relevant message.
         log = open(self.plugin_log_write.name, 'rb').read()
         self.assertIn(b'Step size for backlight is 5.', log)
 
     def test_legacy_brightness_step(self):
+        if self.skip_sysfs_backlight:
+            self.skipTest("sysfs backlight support required for test")
+
         # We cannot use check_plugin_log here because the startup check already
         # read the relevant message.
         log = open(self.plugin_log_write.name, 'rb').read()
         self.assertIn(b'Step size for backlight is 1.', log)
 
     def test_legacy_brightness_rounding(self):
+        if self.skip_sysfs_backlight:
+            self.skipTest("sysfs backlight support required for test")
+
         obj_gsd_power = self.session_bus_con.get_object(
             'org.gnome.SettingsDaemon.Power', '/org/gnome/SettingsDaemon/Power')
         obj_gsd_power_prop_iface = dbus.Interface(obj_gsd_power, dbus.PROPERTIES_IFACE)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]