elementary / wingpanel-indicator-power

Wingpanel Power Indicator
GNU General Public License v3.0
26 stars 15 forks source link

Integrate with power profiles daemon #220

Closed jhaygood86 closed 2 months ago

jhaygood86 commented 3 years ago

Screenshot from 2021-09-10 23 19 52

Adds integration with power profiles daemon. Only runs if the system bus is active.

Allows changing the active profile via the power wingpanel

cassidyjames commented 3 years ago

@elementary/ux there's probably some design input needed here as well. This is the naive design I'd expect for the power profile daemon, but one other thought is that we could treat "Power Saver" more like you see on mobile, as its own standalone toggle. All hardware should have "Power Saver" and "Balanced" modes available, while only some hardware will have a "Performance" mode. And "Power Saver" in the daemon can be hooked off of by other apps as well so it would be a good feature to focus on on its own. Then that leaves the question of: what do we do for hardware that has a "Performance" mode as well?

cassidyjames commented 3 years ago

Another note is: we're not currently packaging the power profiles daemon, but I think it would be beneficial to do so so we can start using it in places like this and across our apps. @jhaygood86 how were you testing this/how would you recommend doing so?

SubhadeepJasu commented 3 years ago

I installed power profiles daemon on my system by hacking the make scripts. For the next release of elementary if we target a new Ubuntu version, I think this wont be a problem.

I closed my other pull request. @cassidyjames Would it help to change this to a simple button which cycles through the modes when clicked? And the other alternative is to change this to a granite mode button. Show the mode buttons when there's three modes. Show a normal toggle button that just says "Power Saver" when there are two modes (considering that one of them is always power saving). And don't show anything when there are no modes or ppd is unavailable.

Depending on this I'll change the switch board plug UI as well.

jhaygood86 commented 3 years ago

I installed power profiles daemon manually. We will need to package it ourselves since it's not in focal. We will need to apply a small patch for it to build on the focal base for it to build since focal's gudev doesn't have a single helper method that is in the current version, however it's trivial to re-implement in a patch.

I think it's worth it to package it for elementary OS 6.x without waiting on Ubuntu, and switch to Ubuntu's version in OS 7 (assuming they package it in 22.04+)

danirabbit commented 3 years ago

Seeing how new power profiles daemon is and that it requires a distro patch to build in OS 6, I'm inclined to wait the 7 months when it should theoretically be maintained upstream. Especially since there are questions about how to do this from a design perspective.

jhaygood86 commented 3 years ago

Seeing how new power profiles daemon is and that it requires a distro patch to build in OS 6, I'm inclined to wait the 7 months when it should theoretically be maintained upstream. Especially since there are questions about how to do this from a design perspective.

That would only benefit OS 7, right? Ubuntu versions newer than focal don't require a patch, only focal, due to gudev being one version behind. Focal specifically doesn't have this function:

g_udev_device_get_sysfs_attr_as_int_uncached

The distro patch is just to polyfill that in ppd-driver-platform-profile.c using the focal supported APIs:


const gchar *
g_udev_device_get_sysfs_attr_uncached (GUdevDevice  *device,
                                       const gchar  *name)
{
  g_autofree char *path = NULL;
  char *contents = NULL;

  g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
  g_return_val_if_fail (name != NULL, NULL);

  path = g_build_filename (g_udev_device_get_sysfs_path (device), name, NULL);
  if (!g_file_get_contents (path, &contents, NULL, NULL))
    return NULL;

  return contents;
}

gint
g_udev_device_get_sysfs_attr_as_int_uncached (GUdevDevice  *device,
                                              const gchar  *name)
{
  gint result;
  const gchar *s;

  g_return_val_if_fail (G_UDEV_IS_DEVICE (device), 0);
  g_return_val_if_fail (name != NULL, 0);

  result = 0;
  s = g_udev_device_get_sysfs_attr_uncached (device, name);
  if (s == NULL)
    goto out;

  result = strtol (s, NULL, 0);
out:
  return result;
}
danirabbit commented 2 months ago

Closing since this was fixed in #262