Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Battery applet setting 0 brightness is turning "off" the display. #701

Open
l-const opened this issue Oct 29, 2024 · 1 comment
Open

Comments

@l-const
Copy link
Contributor

l-const commented Oct 29, 2024

Cosmic-applets version:

Specific applet that this is regarding (if applicable):

Issue/Bug description:

Steps to reproduce:
set 0 to display brightness
Expected behavior:
Clamp the value to a "safe" min value
Other notes:

Other desktop environments seem to have fix this issue and do a bit of processing, as an example i found what the xfce desktop does here:

https://github.com/xfce-mirror/xfce4-power-manager/blob/3707578fbed608a1d275d7bf32eb6b299f657a01/common/xfpm-brightness.c#L123-L158

/*
 * Some laptops (and mostly newer ones with intel graphics) can turn off the
 * backlight completely. If the user is not careful and sets the brightness
 * very low using the slider, he might not be able to see the screen contents
 * anymore. Brightness keys do not work on every laptop, so it's better to use
 * a safe default minimum level that the user can change via the settings
 * editor if desired.
 */
void
xfpm_brightness_set_min_level (XfpmBrightness *brightness,
                               gint32 level)
{
  XfpmBrightnessPrivate *priv = get_instance_private (brightness);
  gint32 max_min;

  g_return_if_fail (XFPM_BRIGHTNESS (brightness));

  /* MIN_BRIGHTNESS_SLIDER_MIN_LEVEL = auto, we set the minimum as 10% of delta */
  if (level == MIN_BRIGHTNESS_SLIDER_MIN_LEVEL)
  {
    priv->min_level = priv->hw_min_level + MAX (priv->step, (priv->max_level - priv->hw_min_level) / 10);
    XFPM_DEBUG ("Setting default min brightness (%d) above hardware min (%d)", priv->min_level, priv->hw_min_level);
    return;
  }

  max_min = priv->max_level - priv->step;
  if (level < priv->hw_min_level || level > max_min)
  {
    XFPM_DEBUG ("Set min brightness (%d) clamped to admissible values [%d, %d]", level, priv->hw_min_level, max_min);
    priv->min_level = CLAMP (level, priv->hw_min_level, max_min);
    return;
  }

  XFPM_DEBUG ("Setting min brightness at %d", level);
  priv->min_level = level;
}
@l-const
Copy link
Contributor Author

l-const commented Oct 30, 2024

Found this gnome extension that does something similar here: https://github.com/F-i-f/soft-brightness?tab=readme-ov-file#minimum-brightness .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant