From 124ca9d38ae6752f32b88a7c45111ea1bb423829 Mon Sep 17 00:00:00 2001 From: Zajcev Evgeny Date: Mon, 27 Jan 2020 01:26:26 +0300 Subject: [PATCH] [fix] battery.el (battery-upower-prop) - Commentary about UPower support - Interface typofix, use "org.freedesktop.UPower.Device" interface instead of "org.freedesktop.UPower" - Use "DisplayDevice" as `battery-upower-device'. Making `battery-upower' to work out-of-box for most users. - Detect upower availability. Set `battery-status-function' to `battery-upower' in case upower is available. All this makes `M-x battery RET' to work out-of-box using upower interface in case of its availability --- lisp/battery.el | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lisp/battery.el b/lisp/battery.el index 49b01d5b54..057629318e 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -23,10 +23,11 @@ ;;; Commentary: ;; There is at present support for GNU/Linux, macOS and Windows. This -;; library supports both the `/proc/apm' file format of Linux version -;; 1.3.58 or newer and the `/proc/acpi/' directory structure of Linux -;; 2.4.20 and 2.6. Darwin (macOS) is supported by using the `pmset' -;; program. Windows is supported by the GetSystemPowerStatus API call. +;; library supports UPower (https://upower.freedesktop.org) via D-Bus +;; API or the `/proc/apm' file format of Linux version 1.3.58 or newer +;; and the `/proc/acpi/' directory structure of Linux 2.4.20 and 2.6. +;; Darwin (macOS) is supported by using the `pmset' program. Windows +;; is supported by the GetSystemPowerStatus API call. ;;; Code: @@ -45,14 +46,18 @@ :type 'regexp :group 'battery) -(defcustom battery-upower-device "battery_BAT1" +(defcustom battery-upower-device "DisplayDevice" "Upower battery device name." :version "26.1" :type 'string :group 'battery) +(declare-function dbus-list-known-names "dbus.el" (bus)) + (defcustom battery-status-function - (cond ((and (eq system-type 'gnu/linux) + (cond ((member "org.freedesktop.UPower" (dbus-list-known-names :system)) + #'battery-upower) + ((and (eq system-type 'gnu/linux) (file-readable-p "/proc/apm")) #'battery-linux-proc-apm) ((and (eq system-type 'gnu/linux) @@ -547,7 +552,7 @@ The following %-sequences are provided: :system "org.freedesktop.UPower" (concat "/org/freedesktop/UPower/devices/" (or device battery-upower-device)) - "org.freedesktop.UPower" + "org.freedesktop.UPower.Device" pname)) (defun battery-upower () -- 2.17.1