Merge lp:~kaihengfeng/unity-settings-daemon/add-brightness-limit-mechanism into lp:unity-settings-daemon

Proposed by Kai-Heng Feng
Status: Rejected
Rejected by: Lars Karlitski
Proposed branch: lp:~kaihengfeng/unity-settings-daemon/add-brightness-limit-mechanism
Merge into: lp:unity-settings-daemon
Diff against target: 256 lines (+85/-13)
3 files modified
plugins/power/gpm-common.c (+32/-5)
plugins/power/gpm-common.h (+15/-4)
plugins/power/gsd-power-manager.c (+38/-4)
To merge this branch: bzr merge lp:~kaihengfeng/unity-settings-daemon/add-brightness-limit-mechanism
Reviewer Review Type Date Requested Status
Lars Karlitski (community) Disapprove
Martin Pitt Disapprove
Ubuntu Desktop Pending
Review via email: mp+277416@code.launchpad.net

Description of the change

Add a mechanism that can make user to choose the minimum/maximum adjustable brightness level.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

TBH, I'm not a fan of introducing configurability for such things. It sounds too much like an "unbreak my desktop setting" and a hack for a bug, it introduces combinatorial explosion again which nobody will test properly, and it'll be hard to drop such settings again.

My opinion is not authoritative here of course, it's ultimately the desktop teams' decision.

review: Disapprove
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

I'm tentatively +1 on this. I agree with Martin that this is an "unbreak my system" knob but ultimately the world where I have this knob is better than the one we are in now, where desktops _are_ broken.

I would love to see an user-visible checkbox that controls if backlight turns off at 0% and a system-vendor tunable that actually controls the 0-100% span.

Revision history for this message
Martin Pitt (pitti) wrote :

> I would love to see an user-visible checkbox that controls if backlight turns off at 0% and a system-vendor tunable that actually controls the 0-100% span.

Erk, please no. This is the absolutely worst UI.

Revision history for this message
Martin Pitt (pitti) wrote :

Also, this high-level user space is *not* the point to second-guess/workaround kernel drivers. Userspace should use the brightness range that the kernel offers, and if there's somehting wrong with that it needs to be fixed in that driver.

Revision history for this message
Lars Karlitski (larsu) wrote :

I strongly agree with Martin's remarks. This should be fixed in the respective drivers. Not only because that's the conceptually correct place, but also because otherwise we'll have to hack around this in every place that brightness is controlled in user space.

> I would love to see an user-visible checkbox that controls if backlight turns off at 0% and a system-vendor tunable that actually controls the 0-100% span.

Why would anyone ever want to turn off the backlight for LCD screens? Turning down the brightness is not the same as turning off the screen.

review: Disapprove
Revision history for this message
Martin Pitt (pitti) wrote :

FTR, https://code.launchpad.net/~fourdollars/unity-settings-daemon/fix-lowest-brightness/+merge/277326 addresses the same problem in an (IMHO) much better way, as it keeps the heuristics in the code (and thus changeable) without providing extra knobs.

Revision history for this message
Kai-Heng Feng (kaihengfeng) wrote :

Although I still prefer configuration for such an issue, I am happy to see this issue being addressed.

Revision history for this message
Mateo Salta (mateo-salta) wrote :

please no, I only see thing on windows devices to trick the battery life stats - setting it lower on battery vs plugged in is one thing(user can still increase to actual max), but forcing a limit that you can't turn up past unless you go into settings is a bad idea.

Unmerged revisions

4118. By Kai-Heng Feng

power: Add a mechanism that can limit min/max brightness percentage via gsettings.

In attempt to fix #1381625, I think it should be the user to decide the minimun
brightness policy to be "screen dim" or "screen off". This newly added mechanism
does not change the current behavior, user can decide it by changing
"min-brightness-percentage".

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/power/gpm-common.c'
--- plugins/power/gpm-common.c 2014-06-26 00:02:19 +0000
+++ plugins/power/gpm-common.c 2015-11-13 07:45:35 +0000
@@ -1414,7 +1414,10 @@
1414}1414}
14151415
1416int1416int
1417backlight_get_percentage (GsdRRScreen *rr_screen, GError **error)1417backlight_get_percentage (GsdRRScreen *rr_screen,
1418 gfloat min_percentage,
1419 gfloat max_percentage,
1420 GError **error)
1418{1421{
1419 GsdRROutput *output;1422 GsdRROutput *output;
1420 gint now;1423 gint now;
@@ -1429,6 +1432,8 @@
1429 min = gsd_rr_output_get_backlight_min (output);1432 min = gsd_rr_output_get_backlight_min (output);
1430 max = gsd_rr_output_get_backlight_max (output);1433 max = gsd_rr_output_get_backlight_max (output);
1431 now = gsd_rr_output_get_backlight (output, error);1434 now = gsd_rr_output_get_backlight (output, error);
1435 min = MAX (min, max * min_percentage);
1436 max = max * max_percentage;
1432 if (now < 0)1437 if (now < 0)
1433 goto out;1438 goto out;
1434 value = ABS_TO_PERCENTAGE (min, max, now);1439 value = ABS_TO_PERCENTAGE (min, max, now);
@@ -1442,6 +1447,8 @@
1442 now = backlight_helper_get_value ("get-brightness", error);1447 now = backlight_helper_get_value ("get-brightness", error);
1443 if (now < 0)1448 if (now < 0)
1444 goto out;1449 goto out;
1450 min = MAX (min, max * min_percentage);
1451 max = max * max_percentage;
1445 value = ABS_TO_PERCENTAGE (min, max, now);1452 value = ABS_TO_PERCENTAGE (min, max, now);
1446out:1453out:
1447 return value;1454 return value;
@@ -1488,6 +1495,8 @@
1488gboolean1495gboolean
1489backlight_set_percentage (GsdRRScreen *rr_screen,1496backlight_set_percentage (GsdRRScreen *rr_screen,
1490 guint value,1497 guint value,
1498 gfloat min_percentage,
1499 gfloat max_percentage,
1491 GError **error)1500 GError **error)
1492{1501{
1493 GsdRROutput *output;1502 GsdRROutput *output;
@@ -1505,6 +1514,8 @@
1505 g_warning ("no xrandr backlight capability");1514 g_warning ("no xrandr backlight capability");
1506 return ret;1515 return ret;
1507 }1516 }
1517 min = MAX (min, max * min_percentage);
1518 max = max * max_percentage;
1508 discrete = PERCENTAGE_TO_ABS (min, max, value);1519 discrete = PERCENTAGE_TO_ABS (min, max, value);
1509 ret = gsd_rr_output_set_backlight (output,1520 ret = gsd_rr_output_set_backlight (output,
1510 discrete,1521 discrete,
@@ -1516,6 +1527,8 @@
1516 max = backlight_helper_get_value ("get-max-brightness", error);1527 max = backlight_helper_get_value ("get-max-brightness", error);
1517 if (max < 0)1528 if (max < 0)
1518 return ret;1529 return ret;
1530 min = MAX (min, max * min_percentage);
1531 max = max * max_percentage;
1519 discrete = PERCENTAGE_TO_ABS (min, max, value);1532 discrete = PERCENTAGE_TO_ABS (min, max, value);
1520 ret = backlight_helper_set_value ("set-brightness",1533 ret = backlight_helper_set_value ("set-brightness",
1521 discrete,1534 discrete,
@@ -1525,7 +1538,10 @@
1525}1538}
15261539
1527int1540int
1528backlight_step_up (GsdRRScreen *rr_screen, GError **error)1541backlight_step_up (GsdRRScreen *rr_screen,
1542 gfloat min_percentage,
1543 gfloat max_percentage,
1544 GError **error)
1529{1545{
1530 GsdRROutput *output;1546 GsdRROutput *output;
1531 gboolean ret = FALSE;1547 gboolean ret = FALSE;
@@ -1555,6 +1571,8 @@
1555 now = gsd_rr_output_get_backlight (output, error);1571 now = gsd_rr_output_get_backlight (output, error);
1556 if (now < 0)1572 if (now < 0)
1557 return percentage_value;1573 return percentage_value;
1574 min = MAX (min, max * min_percentage);
1575 max = max * max_percentage;
1558 step = BRIGHTNESS_STEP_AMOUNT (max - min + 1);1576 step = BRIGHTNESS_STEP_AMOUNT (max - min + 1);
1559 discrete = MIN (now + step, max);1577 discrete = MIN (now + step, max);
1560 ret = gsd_rr_output_set_backlight (output,1578 ret = gsd_rr_output_set_backlight (output,
@@ -1572,6 +1590,8 @@
1572 max = backlight_helper_get_value ("get-max-brightness", error);1590 max = backlight_helper_get_value ("get-max-brightness", error);
1573 if (max < 0)1591 if (max < 0)
1574 return percentage_value;1592 return percentage_value;
1593 min = MAX (min, max * min_percentage);
1594 max = max * max_percentage;
1575 step = BRIGHTNESS_STEP_AMOUNT (max - min + 1);1595 step = BRIGHTNESS_STEP_AMOUNT (max - min + 1);
1576 discrete = MIN (now + step, max);1596 discrete = MIN (now + step, max);
1577 ret = backlight_helper_set_value ("set-brightness",1597 ret = backlight_helper_set_value ("set-brightness",
@@ -1584,7 +1604,10 @@
1584}1604}
15851605
1586int1606int
1587backlight_step_down (GsdRRScreen *rr_screen, GError **error)1607backlight_step_down (GsdRRScreen *rr_screen,
1608 gfloat min_percentage,
1609 gfloat max_percentage,
1610 GError **error)
1588{1611{
1589 GsdRROutput *output;1612 GsdRROutput *output;
1590 gboolean ret = FALSE;1613 gboolean ret = FALSE;
@@ -1614,8 +1637,10 @@
1614 now = gsd_rr_output_get_backlight (output, error);1637 now = gsd_rr_output_get_backlight (output, error);
1615 if (now < 0)1638 if (now < 0)
1616 return percentage_value;1639 return percentage_value;
1640 min = MAX (min, max * min_percentage);
1641 max = max * max_percentage;
1617 step = BRIGHTNESS_STEP_AMOUNT (max - min + 1);1642 step = BRIGHTNESS_STEP_AMOUNT (max - min + 1);
1618 discrete = MAX (now - step, 0);1643 discrete = MAX (now - step, min);
1619 ret = gsd_rr_output_set_backlight (output,1644 ret = gsd_rr_output_set_backlight (output,
1620 discrete,1645 discrete,
1621 error);1646 error);
@@ -1631,8 +1656,10 @@
1631 max = backlight_helper_get_value ("get-max-brightness", error);1656 max = backlight_helper_get_value ("get-max-brightness", error);
1632 if (max < 0)1657 if (max < 0)
1633 return percentage_value;1658 return percentage_value;
1659 min = MAX (min, max * min_percentage);
1660 max = max * max_percentage;
1634 step = BRIGHTNESS_STEP_AMOUNT (max - min + 1);1661 step = BRIGHTNESS_STEP_AMOUNT (max - min + 1);
1635 discrete = MAX (now - step, 0);1662 discrete = MAX (now - step, min);
1636 ret = backlight_helper_set_value ("set-brightness",1663 ret = backlight_helper_set_value ("set-brightness",
1637 discrete,1664 discrete,
1638 error);1665 error);
16391666
=== modified file 'plugins/power/gpm-common.h'
--- plugins/power/gpm-common.h 2014-06-26 00:02:19 +0000
+++ plugins/power/gpm-common.h 2015-11-13 07:45:35 +0000
@@ -58,14 +58,25 @@
58int gsd_power_backlight_abs_to_percentage (int min, int max, int value);58int gsd_power_backlight_abs_to_percentage (int min, int max, int value);
59gboolean backlight_available (GsdRRScreen *rr_screen);59gboolean backlight_available (GsdRRScreen *rr_screen);
60int backlight_get_abs (GsdRRScreen *rr_screen, GError **error);60int backlight_get_abs (GsdRRScreen *rr_screen, GError **error);
61int backlight_get_percentage (GsdRRScreen *rr_screen, GError **error);61int backlight_get_percentage (GsdRRScreen *rr_screen,
62 gfloat min_percentage,
63 gfloat max_percentage,
64 GError **error);
62int backlight_get_min (GsdRRScreen *rr_screen);65int backlight_get_min (GsdRRScreen *rr_screen);
63int backlight_get_max (GsdRRScreen *rr_screen, GError **error);66int backlight_get_max (GsdRRScreen *rr_screen, GError **error);
64gboolean backlight_set_percentage (GsdRRScreen *rr_screen,67gboolean backlight_set_percentage (GsdRRScreen *rr_screen,
65 guint value,68 guint value,
66 GError **error);69 gfloat min_percentage,
67int backlight_step_up (GsdRRScreen *rr_screen, GError **error);70 gfloat max_percentage,
68int backlight_step_down (GsdRRScreen *rr_screen, GError **error);71 GError **error);
72int backlight_step_up (GsdRRScreen *rr_screen,
73 gfloat min_percentage,
74 gfloat max_percentage,
75 GError **error);
76int backlight_step_down (GsdRRScreen *rr_screen,
77 gfloat min_percentage,
78 gfloat max_percentage,
79 GError **error);
69int backlight_set_abs (GsdRRScreen *rr_screen,80int backlight_set_abs (GsdRRScreen *rr_screen,
70 guint value,81 guint value,
71 GError **error);82 GError **error);
7283
=== modified file 'plugins/power/gsd-power-manager.c'
--- plugins/power/gsd-power-manager.c 2015-10-22 09:04:20 +0000
+++ plugins/power/gsd-power-manager.c 2015-11-13 07:45:35 +0000
@@ -189,6 +189,8 @@
189 /* Brightness */189 /* Brightness */
190 gboolean backlight_available;190 gboolean backlight_available;
191 gint pre_dim_brightness; /* level, not percentage */191 gint pre_dim_brightness; /* level, not percentage */
192 gfloat min_brightness_percentage;
193 gfloat max_brightness_percentage;
192194
193 /* Keyboard */195 /* Keyboard */
194 GDBusProxy *upower_kdb_proxy;196 GDBusProxy *upower_kdb_proxy;
@@ -2626,6 +2628,15 @@
2626}2628}
26272629
2628static void2630static void
2631brightness_configure (GsdPowerManager *manager)
2632{
2633 gint min = CLAMP (g_settings_get_int (manager->priv->settings, "min-brightness-percentage"), 0, 100);
2634 gint max = CLAMP (g_settings_get_int (manager->priv->settings, "max-brightness-percentage"), min, 100);
2635 manager->priv->min_brightness_percentage = min * 0.01;
2636 manager->priv->max_brightness_percentage = max * 0.01;
2637}
2638
2639static void
2629main_battery_or_ups_low_changed (GsdPowerManager *manager,2640main_battery_or_ups_low_changed (GsdPowerManager *manager,
2630 gboolean is_low)2641 gboolean is_low)
2631{2642{
@@ -3013,6 +3024,11 @@
3013 setup_lid_closed_action (manager);3024 setup_lid_closed_action (manager);
3014 return;3025 return;
3015 }3026 }
3027 if (g_str_equal (key, "min-brightness-percentage") ||
3028 g_str_equal (key, "max-brightness-percentage")) {
3029 brightness_configure (manager);
3030 return;
3031 }
3016}3032}
30173033
3018static void3034static void
@@ -3416,6 +3432,7 @@
3416 /* coldplug the engine */3432 /* coldplug the engine */
3417 engine_coldplug (manager);3433 engine_coldplug (manager);
3418 idle_configure (manager);3434 idle_configure (manager);
3435 brightness_configure (manager);
34193436
3420 manager->priv->xscreensaver_watchdog_timer_id = gsd_power_enable_screensaver_watchdog ();3437 manager->priv->xscreensaver_watchdog_timer_id = gsd_power_enable_screensaver_watchdog ();
34213438
@@ -3590,12 +3607,21 @@
35903607
3591 if (g_strcmp0 (method_name, "GetPercentage") == 0) {3608 if (g_strcmp0 (method_name, "GetPercentage") == 0) {
3592 g_debug ("screen get percentage");3609 g_debug ("screen get percentage");
3593 value = backlight_get_percentage (manager->priv->rr_screen, &error);3610 value = backlight_get_percentage (
3611 manager->priv->rr_screen,
3612 manager->priv->min_brightness_percentage,
3613 manager->priv->max_brightness_percentage,
3614 &error);
35943615
3595 } else if (g_strcmp0 (method_name, "SetPercentage") == 0) {3616 } else if (g_strcmp0 (method_name, "SetPercentage") == 0) {
3596 g_debug ("screen set percentage");3617 g_debug ("screen set percentage");
3597 g_variant_get (parameters, "(u)", &value_tmp);3618 g_variant_get (parameters, "(u)", &value_tmp);
3598 ret = backlight_set_percentage (manager->priv->rr_screen, value_tmp, &error);3619 ret = backlight_set_percentage (
3620 manager->priv->rr_screen,
3621 value_tmp,
3622 manager->priv->min_brightness_percentage,
3623 manager->priv->max_brightness_percentage,
3624 &error);
3599 if (ret) {3625 if (ret) {
3600 value = value_tmp;3626 value = value_tmp;
3601 backlight_emit_changed (manager);3627 backlight_emit_changed (manager);
@@ -3603,12 +3629,20 @@
36033629
3604 } else if (g_strcmp0 (method_name, "StepUp") == 0) {3630 } else if (g_strcmp0 (method_name, "StepUp") == 0) {
3605 g_debug ("screen step up");3631 g_debug ("screen step up");
3606 value = backlight_step_up (manager->priv->rr_screen, &error);3632 value = backlight_step_up (
3633 manager->priv->rr_screen,
3634 manager->priv->min_brightness_percentage,
3635 manager->priv->max_brightness_percentage,
3636 &error);
3607 if (value != -1)3637 if (value != -1)
3608 backlight_emit_changed (manager);3638 backlight_emit_changed (manager);
3609 } else if (g_strcmp0 (method_name, "StepDown") == 0) {3639 } else if (g_strcmp0 (method_name, "StepDown") == 0) {
3610 g_debug ("screen step down");3640 g_debug ("screen step down");
3611 value = backlight_step_down (manager->priv->rr_screen, &error);3641 value = backlight_step_down (
3642 manager->priv->rr_screen,
3643 manager->priv->min_brightness_percentage,
3644 manager->priv->max_brightness_percentage,
3645 &error);
3612 if (value != -1)3646 if (value != -1)
3613 backlight_emit_changed (manager);3647 backlight_emit_changed (manager);
3614 } else {3648 } else {

Subscribers

People subscribed via source and target branches