Compare commits

..

No commits in common. "master" and "v1.90.7" have entirely different histories.

41 changed files with 278 additions and 3845 deletions

View file

@ -55,7 +55,6 @@ image: $FEDORA_IMAGE
pre_commit:
stage: pre-commit
script:
- dnf install -y libatomic
- dnf install -y pre-commit
- pre-commit run --all-files
@ -300,4 +299,4 @@ container_debian_build:
echo "deb-src http://deb.debian.org/debian/ trixie main contrib non-free" >> /etc/apt/sources.list &&
apt update &&
apt build-dep -y upower &&
curl https://gitlab.freedesktop.org/hadess/check-abi/-/raw/main/contrib/check-abi-fedora.sh | bash
curl https://gitlab.freedesktop.org/hadess/check-abi/-/raw/main/contrib/check-abi-fedora.sh | bash

View file

@ -1,4 +1,4 @@
default_stages: [pre-commit]
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0

41
NEWS
View file

@ -1,44 +1,3 @@
Version 1.91.0
--------------
Released: 2025-11-25
- New feature: Support multiple keyboard backlight LED control. (#291 !203)
- Make installation of tests optional (!202)
- Support conf.d style config file (!286)
- Deprecate CapacityLevel property (!290 #333)
Version 1.90.10
--------------
Released: 2025-08-26
- Fix wrong model name of the devices (!267, #309)
- Switch charge_types to "Custom" when charging threshold is enabled (!268, #275)
- Fix invalid command line arguments (!269)
- Fix leak when reporting daemon usage error (!270)
- OpenBSD: support battery status from qcpas (!272)
- Fix history progression (!274, #316)
- Add a battery filter to the upower command line (!275)
- Change the charging behaviors using charge_types (!276, !46, #275)
- Fix integration tests issues, including floating point value and race between umockdev and upower (!277, !278)
- Rework upower command (!280)
- Propagate charge-threshold-enabled to display device (!281)
Version 1.90.9
--------------
Released: 2025-04-10
- Fix unstable OnBattery status (#306 #307)
Version 1.90.8
--------------
Released: 2025-03-31
- Fix the incorrect percentage value of a removed battery. (#292) (!246)
- Fix device type for the gaming device. (#296 #295) (!247)
- Determine the battery discharging status when connecting a low-power charger. (#276) (!244)
- Fix memory leak when refreshing battery info. (#305) (!261)
- Fix memory leak when getting device id. (!261)
Version 1.90.7
--------------
Released: 2025-01-09

View file

@ -1,21 +1,6 @@
#!/usr/bin/env -S bash -e
#set up local repository
install_pip()
{
package=$1
args=$2
python3 -m pip install $package $args
}
setup_precommit()
{
echo "Configuring pre-commit hooks"
install_pip pre-commit
pre-commit install
}
setup_git()
{
echo "Configuring git environment"
@ -23,4 +8,3 @@ setup_git()
}
setup_git
setup_precommit

View file

@ -11,7 +11,6 @@ _enumerate_objects() {
}
_arguments \
"(--battery -b)"{--battery,-b}"[Dump all parameters for battery objects]" \
"(--enumerate -e)"{--enumerate,-e}"[Enumerate objects paths for devices]" \
"(--dump -d)"{--dump,-d}"[Dump all parameters for all objects]" \
"(--monitor -m)"{--monitor,-m}"[Monitor activity from the power daemon]" \

View file

@ -572,18 +572,11 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2
</property>
<property name="Luminosity" type="d" access="read">
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
<doc:doc>
<doc:description>
<doc:para>
Luminosity being recorded by the meter.
</doc:para>
<doc:para>
DEPRECATED
</doc:para>
<doc:para>
This property is deprecated since the code it depends on was removed in 0.99.12
</doc:para>
</doc:description>
</doc:doc>
</property>
@ -900,83 +893,6 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2
</doc:description>
</doc:doc>
</property>
<property name="ChargeThresholdSettingsSupported" type="u" access="read">
<doc:doc>
<doc:description>
<doc:para>The types of settings for charge thresholds that are supported. The value is a bitmask value and it is the sum of the supported types.</doc:para>
<doc:list>
<doc:item>
<doc:term>1</doc:term><doc:definition>The system supports charge start threshold. The battery discharges to a percentage, then starts charging.</doc:definition>
</doc:item>
<doc:item>
<doc:term>2</doc:term><doc:definition>The system supports charge end threshold. The battery charges to a percentage, then stops charging.</doc:definition>
</doc:item>
<doc:item>
<doc:term>4</doc:term><doc:definition>The system supports optimized charging behaviors controlled by the system firmware.</doc:definition>
</doc:item>
</doc:list>
<doc:para>Examples:</doc:para>
<doc:para>If the system supports charge start threshold and charge end threshold, the value is 3. If the system supports charge end threshold and the battery charging behavior is controlled by the system firmware, the value is 6.</doc:para>
</doc:description>
</doc:doc>
</property>
<property name="VoltageMinDesign" type="d" access="read">
<doc:doc>
<doc:description>
<doc:para>
The minimum design voltage of the battery, as reported by the kernel.
</doc:para>
</doc:description>
</doc:doc>
</property>
<property name="VoltageMaxDesign" type="d" access="read">
<doc:doc>
<doc:description>
<doc:para>
The maximum design voltage of the battery, as reported by the kernel.
</doc:para>
</doc:description>
</doc:doc>
</property>
<property name="CapacityLevel" type="s" access="read">
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
<doc:doc>
<doc:description>
<doc:para>
Coarse representation of battery capacity. The value is one of the following:
</doc:para>
<doc:list>
<doc:item>
<doc:term>Unknown</doc:term>
</doc:item>
<doc:item>
<doc:term>Critical</doc:term>
</doc:item>
<doc:item>
<doc:term>Low</doc:term>
</doc:item>
<doc:item>
<doc:term>Normal</doc:term>
</doc:item>
<doc:item>
<doc:term>High</doc:term>
</doc:item>
<doc:item>
<doc:term>Full</doc:term>
</doc:item>
</doc:list>
<doc:para>
DEPRECATED
</doc:para>
<doc:para>
This property is deprecated since it is duplicated from the 'BatteryLevel' property.
</doc:para>
</doc:description>
</doc:doc>
</property>
</interface>
</node>

View file

@ -11,12 +11,6 @@
org.freedesktop.UPower.KbdBacklight is a DBus interface implemented
by UPower.
It allows the keyboard backlight (if present) to be controlled.
The object path "/org/freedesktop/UPower/KbdBacklight" is going to be deprecated in the future.
The new object path is based on this, but the suffix of the path is the device name.
For example:
The interface is: org.freedesktop.UPower.KbdBacklight
The object path will be: /org/freedesktop/UPower/KbdBacklight/tpacpiookbd_backlight
</doc:para>
</doc:description>
</doc:doc>
@ -84,19 +78,6 @@
</doc:doc>
</method>
<!-- ************************************************************ -->
<property name="NativePath" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>
OS specific native path of the keyboard backlight LED device. On Linux this
is the sysfs path, for
example <doc:tt>/sys/devices/platform/thinkpad_acpi/leds/tpacpi\:\:kbd_backlight</doc:tt>.
</doc:para>
</doc:description>
</doc:doc>
</property>
<!-- ************************************************************ -->
<signal name="BrightnessChanged">
<arg name="value" direction="out" type="i">

View file

@ -51,21 +51,6 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
</doc:doc>
</method>
<method name="EnumerateKbdBacklights">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="KbdBacklight" direction="out" type="ao">
<doc:doc><doc:summary>An array of object paths for keyboard backlight LEDs.</doc:summary></doc:doc>
</arg>
<doc:doc>
<doc:description>
<doc:para>
Enumerate all keyboard backlight LED objects on the system.
</doc:para>
</doc:description>
</doc:doc>
</method>
<method name="GetDisplayDevice">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="device" direction="out" type="o">
@ -141,12 +126,6 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
<doc:item>
<doc:term>PowerOff</doc:term>
</doc:item>
<doc:item>
<doc:term>Suspend</doc:term>
</doc:item>
<doc:item>
<doc:term>Ignore</doc:term>
</doc:item>
</doc:list>
</doc:para>
</doc:description>

View file

@ -19,7 +19,6 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>upower</command>
<arg><option>--battery</option></arg>
<arg><option>--dump</option></arg>
<arg><option>--enumerate</option></arg>
<arg><option>--monitor-detail</option></arg>
@ -36,7 +35,7 @@
<emphasis><refentrytitle>upower</refentrytitle></emphasis> is a
simple command line client for the
<citerefentry><refentrytitle>UPower</refentrytitle><manvolnum>7</manvolnum></citerefentry>
daemon.
daemon. TODO: not fully documented.
</para>
</refsect1>
@ -44,31 +43,7 @@
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term><option>-b</option>, <option>--battery</option></term>
<listitem>
<para>
Dump all parameters for battery devices.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-d</option>, <option>--dump</option></term>
<listitem>
<para>
Dump all parameters for all devices.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-e</option>, <option>--enumerate</option></term>
<listitem>
<para>
Enumerate the object paths of all devices on the system.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-m</option>, <option>--monitor</option></term>
<term><option>--monitor</option></term>
<listitem>
<para>
Connect to the UPower daemon and print a line
@ -86,23 +61,7 @@
</listitem>
</varlistentry>
<varlistentry>
<term><option>-i</option>, <option>--show-info</option> <varname>OBJECT_PATH</varname></term>
<listitem>
<para>
Show information about the given device.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-v</option>, <option>--version</option></term>
<listitem>
<para>
Print version information for the client and daemon.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-h</option>, <option>--help</option></term>
<term><option>--help</option></term>
<listitem>
<para>
Show help options.

View file

@ -83,20 +83,11 @@ TimeAction=120
# Enable the risky CriticalPowerAction-Suspend
# This option is not recommended, but it is here for users who
# want to enable the risky CriticalPowerAction, such as "Suspend"
# want to enable the riscky CriticalPowerAction, such as "Suspend"
# to fulfill their needs.
# Default is false
AllowRiskyCriticalPowerAction=false
# If the user performs the battery recalibration, the battery behavior
# will be set to "force discharge" and the user expects the battery will
# be fully discharged. However, upower performs the
# CriticalPowerAction earlier than the battery was fully discharged.
# ExpectBatteryRecalibration allows upower to ignore the
# CriticalPowerAction when the user attempts to perform the battery recalibration.
# Default is false
ExpectBatteryRecalibration=false
# The action to take when "TimeAction" or "PercentageAction" above has been
# reached for the batteries (UPS or laptop batteries) supplying the computer
#

View file

@ -1,83 +0,0 @@
# UPower Configuration Override
The configuration in UPower.conf.d will override the primary configuration
in UPower.conf.
The primary method for overriding settings in the main UPower.conf file is by placing configuration snippets in the `/etc/UPower/UPower.conf.d/` directory.
## The format of filename
For a file to be correctly processed as an override, its filename must adhere to a strict format:
- It must start with a two-digit number between `00` and `99`.
- It must end with the `.conf` extension.
- The middle section can contain `alphanumeric characters`, `dashes`, and `underscores`.
This format is captured by the regular expression `^([0-9][0-9])-([a-zA-Z0-9-_])*\.conf$`.
- The valid examples
```text
01-upower-example.conf
02-upower-test-123.conf
03-upower-1a2b-3c4D__.conf
```
- The invalid examples
```text
0000-upower-abcd1234.conf
001-upower-@bcd.config
```
## The configuration override
UPower processes configuration files in sorted order, where settings in later files override identical settings (matching both Group and Key) from previous files, including the main UPower.conf. This hierarchy ensures that local, numerically-prefixed files in the drop-in directory (UPower.conf.d/) take precedence.
For example, consider `UPower.conf` that contains the defaults:
```text
PercentageLow=20.0
PercentageCritical=5.0
PercentageAction=2.0
```
and there is a file `UPower.conf.d/70-change-percentages.conf`
containing settings for all `Percentage*` keys:
```text
[UPower]
PercentageLow=15.0
PercentageCritical=10.0
PercentageAction=5.0
```
and another `UPower.conf.d/99-change-percentages-local.conf`
containing settings only for `PercentageAction`:
```text
[UPower]
PercentageAction=7.5
```
First the main `UPower.conf` will be processed, then
`UPower.conf.d/70-change-percentages.conf` overriding the defaults
of all percentages from the main config file with the given values,
and finally `UPower.conf.d/99-change-percentages-local.conf`
overriding once again only `PercentageAction`. The final, effective
values are:
```text
PercentageLow=15.0
PercentageCritical=10.0
PercentageAction=7.5
```
## The examples of overriding the default percentage policy values
```text
[UPower]
PercentageLow=25.0
PercentageCritical=10.0
PercentageAction=5.0
```

View file

@ -1,5 +0,0 @@
install_data(
'README.md',
install_tag: 'doc',
install_dir: get_option('sysconfdir') / 'UPower' / 'UPower.conf.d',
)

View file

@ -1,2 +1 @@
subdir('UPower.conf.d')
install_data('UPower.conf', install_dir: get_option('sysconfdir') / 'UPower')

View file

@ -94,9 +94,6 @@ enum {
PROP_CHARGE_END_THRESHOLD,
PROP_CHARGE_THRESHOLD_ENABLED,
PROP_CHARGE_THRESHOLD_SUPPORTED,
PROP_VOLTAGE_MIN_DESIGN,
PROP_VOLTAGE_MAX_DESIGN,
PROP_CAPACITY_LEVEL,
PROP_LAST
};
@ -273,7 +270,6 @@ up_device_to_text (UpDevice *device)
const gchar *vendor;
const gchar *model;
const gchar *serial;
const gchar *capacity_level;
UpDeviceKind kind;
gboolean is_display;
UpDeviceLevel battery_level;
@ -345,20 +341,6 @@ up_device_to_text (UpDevice *device)
g_string_append_printf (string, " energy-full: %g Wh\n", up_exported_device_get_energy_full (priv->proxy_device));
if (!is_display)
g_string_append_printf (string, " energy-full-design: %g Wh\n", up_exported_device_get_energy_full_design (priv->proxy_device));
if (up_exported_device_get_voltage_min_design (priv->proxy_device) > 0)
g_string_append_printf (string, " voltage-min-design: %g V\n", up_exported_device_get_voltage_min_design (priv->proxy_device));
if (up_exported_device_get_voltage_max_design (priv->proxy_device) > 0)
g_string_append_printf (string, " voltage-max-design: %g V\n", up_exported_device_get_voltage_max_design (priv->proxy_device));
/* Eliminate the display of the deprecation warning specific to the CapacityLevel property. */
/* DEPRECATED. This property is deprecated since it is duplicated from the 'BatteryLevel' property. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
capacity_level = up_exported_device_get_capacity_level (priv->proxy_device);
#pragma GCC diagnostic pop
if (capacity_level != NULL && capacity_level[0] != '\0')
g_string_append_printf (string, " capacity-level: %s\n", capacity_level);
}
if (kind == UP_DEVICE_KIND_BATTERY ||
kind == UP_DEVICE_KIND_MONITOR)
@ -376,12 +358,8 @@ up_device_to_text (UpDevice *device)
g_string_append_printf (string, " charge-cycles: %s\n", "N/A");
}
if (kind == UP_DEVICE_KIND_KEYBOARD) {
/* DEPRECATED. This property is deprecated since the code it depends on was removed in 0.99.12. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if (up_exported_device_get_luminosity (priv->proxy_device) > 0)
g_string_append_printf (string, " luminosity: %g lx\n", up_exported_device_get_luminosity (priv->proxy_device));
#pragma GCC diagnostic pop
}
if (kind == UP_DEVICE_KIND_BATTERY ||
kind == UP_DEVICE_KIND_UPS) {
@ -697,11 +675,7 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa
up_exported_device_set_voltage (device->priv->proxy_device, g_value_get_double (value));
break;
case PROP_LUMINOSITY:
/* DEPRECATED. This property is deprecated since the code it depends on was removed in 0.99.12. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
up_exported_device_set_luminosity (device->priv->proxy_device, g_value_get_double (value));
#pragma GCC diagnostic pop
break;
case PROP_TIME_TO_EMPTY:
up_exported_device_set_time_to_empty (device->priv->proxy_device, g_value_get_int64 (value));
@ -742,20 +716,6 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa
case PROP_CHARGE_THRESHOLD_SUPPORTED:
up_exported_device_set_charge_threshold_supported (device->priv->proxy_device, g_value_get_boolean (value));
break;
case PROP_VOLTAGE_MIN_DESIGN:
up_exported_device_set_voltage_min_design (device->priv->proxy_device, g_value_get_double (value));
break;
case PROP_VOLTAGE_MAX_DESIGN:
up_exported_device_set_voltage_max_design (device->priv->proxy_device, g_value_get_double (value));
break;
/* Eliminate the display of the deprecation warning specific to the CapacityLevel property. */
/* DEPRECATED. This property is deprecated since it is duplicated from the 'BatteryLevel' property. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
case PROP_CAPACITY_LEVEL:
up_exported_device_set_capacity_level (device->priv->proxy_device, g_value_get_string (value));
break;
#pragma GCC diagnostic pop
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -847,11 +807,7 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
g_value_set_double (value, up_exported_device_get_voltage (device->priv->proxy_device));
break;
case PROP_LUMINOSITY:
/* DEPRECATED. This property is deprecated since the code it depends on was removed in 0.99.12. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
g_value_set_double (value, up_exported_device_get_luminosity (device->priv->proxy_device));
#pragma GCC diagnostic pop
break;
case PROP_TIME_TO_EMPTY:
g_value_set_int64 (value, up_exported_device_get_time_to_empty (device->priv->proxy_device));
@ -889,20 +845,6 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
case PROP_CHARGE_THRESHOLD_SUPPORTED:
g_value_set_boolean (value, up_exported_device_get_charge_threshold_supported (device->priv->proxy_device));
break;
case PROP_VOLTAGE_MIN_DESIGN:
g_value_set_double (value, up_exported_device_get_voltage_min_design (device->priv->proxy_device));
break;
case PROP_VOLTAGE_MAX_DESIGN:
g_value_set_double (value, up_exported_device_get_voltage_max_design (device->priv->proxy_device));
break;
/* Eliminate the display of the deprecation warning specific to the CapacityLevel property. */
/* DEPRECATED. This property is deprecated since it is duplicated from the 'BatteryLevel' property. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
case PROP_CAPACITY_LEVEL:
g_value_set_string (value, up_exported_device_get_capacity_level (device->priv->proxy_device));
break;
#pragma GCC diagnostic pop
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1202,16 +1144,13 @@ up_device_class_init (UpDeviceClass *klass)
*
* The current luminosity of the device.
*
* NOTE: As of 1.91.1, this property is deprecated since the code it
* depends on was removed in 0.99.12.
*
* Since: 0.9.19
**/
g_object_class_install_property (object_class,
PROP_LUMINOSITY,
g_param_spec_double ("luminosity", NULL, NULL,
0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE | G_PARAM_DEPRECATED));
G_PARAM_READWRITE));
/**
* UpDevice:time-to-empty:
*
@ -1378,50 +1317,6 @@ up_device_class_init (UpDeviceClass *klass)
NULL, NULL,
FALSE,
G_PARAM_READWRITE));
/**
* UpDevice:voltage_min_design:
*
* The minimum supported voltage of the device as reported by the kernel.
*
* Since: 1.90.10
**/
g_object_class_install_property (object_class,
PROP_VOLTAGE_MIN_DESIGN,
g_param_spec_double ("voltage-min-design", NULL, NULL,
0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE));
/**
* UpDevice:voltage_max_design:
*
* The maximum supported voltage of the device as reported by the kernel.
*
* Since: 1.90.10
**/
g_object_class_install_property (object_class,
PROP_VOLTAGE_MAX_DESIGN,
g_param_spec_double ("voltage-max-design", NULL, NULL,
0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE));
/**
* UpDevice:capacity-level:
*
* Coarse representation of battery capacity. The value is one of the following:
* Unknown, Critical, Low, Normal, High, and Full.
*
* Since: 1.90.10
*
* DEPRECATED.
* This property is deprecated since it is duplicated from the 'BatteryLevel' property.
**/
g_object_class_install_property (object_class,
PROP_CAPACITY_LEVEL,
g_param_spec_string ("capacity-level",
NULL, NULL, NULL,
G_PARAM_READWRITE | G_PARAM_DEPRECATED));
}
static void

View file

@ -1,5 +1,5 @@
project('upower', 'c',
version: '1.91.0',
version: '1.90.7',
license: 'GPLv2+',
default_options: [
'buildtype=debugoptimized',
@ -10,7 +10,7 @@ project('upower', 'c',
soversion = 3
current = 1
revision = 1
revision = 0
libversion = '@0@.@1@.@2@'.format(soversion, current, revision)
gnome = import('gnome')
@ -30,7 +30,7 @@ cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
cdata.set_quoted('VERSION', meson.project_version())
cdata.set_quoted('PACKAGE_SYSCONF_DIR', get_option('sysconfdir'))
glib_min_version = '2.76'
glib_min_version = '2.66'
glib_version_def = 'GLIB_VERSION_@0@_@1@'.format(
glib_min_version.split('.')[0], glib_min_version.split('.')[1])

View file

@ -1,10 +1,10 @@
option('man',
type : 'boolean',
value : true,
value : 'true',
description : 'Build manpages')
option('gtk-doc',
type : 'boolean',
value : true,
value : 'true',
description : 'Build developer documentation')
option('introspection',
type : 'feature',
@ -44,7 +44,3 @@ option('zshcompletiondir',
type: 'string',
value: '',
description: 'Directory for zsh completion scripts ["no" disables]')
option('installed_tests',
type : 'boolean',
value : true,
description : 'Install integration tests')

View file

@ -2,7 +2,6 @@
#
fr
it
ka
sv
pl

View file

@ -21,8 +21,8 @@ file are instantly applied.
<icon_name>system-suspend</icon_name>
<action id="org.freedesktop.UPower.enable-charging-limit">
<description>Enable battery charging limit</description>
<message>Authentication is required to set battery charging start and end limit.</message>
<_description>Enable battery charging limit</_description>
<_message>Authentication is required to set battery charging start and end limit.</_message>
<defaults>
<allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active>

View file

@ -1,6 +1,6 @@
ACTION=="remove", GOTO="battery_end"
SUBSYSTEM=="power_supply", ATTR{charge_control_start_threshold}!="", \
SUBSYSTEM=="power_supply",ATTR{charge_control_start_threshold}!="" \
IMPORT{builtin}="hwdb 'battery:$kernel:$attr{model_name}:$attr{[dmi/id]modalias}'", \
GOTO="battery_end"

View file

@ -72,7 +72,6 @@ usb:v051Dp0000*
usb:v051Dp0002*
usb:v051Dp0003*
usb:v051Dp0004*
usb:v051Dp0005*
UPOWER_BATTERY_TYPE=ups
UPOWER_VENDOR=APC
@ -208,11 +207,6 @@ usb:v2E66p0302*
UPOWER_BATTERY_TYPE=ups
UPOWER_VENDOR=Salicru
# EcoFlow
usb:v3746pFFFF*
UPOWER_BATTERY_TYPE=ups
UPOWER_VENDOR=EcoFlow
# Powervar
usb:v4234p0002*
UPOWER_BATTERY_TYPE=ups

File diff suppressed because it is too large Load diff

View file

@ -18,8 +18,6 @@ upshared += { 'linux': static_library('upshared',
'up-device-wup.h',
'up-device-bluez.c',
'up-device-bluez.h',
'up-kbd-backlight-led.c',
'up-kbd-backlight-led.h',
'up-input.c',
'up-input.h',
'up-backend.c',

View file

@ -33,7 +33,6 @@
#include "up-backend.h"
#include "up-daemon.h"
#include "up-device.h"
#include "up-device-kbd-backlight.h"
#include "up-enumerator-udev.h"
@ -422,13 +421,9 @@ up_device_disconnected_cb (GObject *gobject,
NULL);
if (disconnected) {
g_debug("Device %s became disconnected, hiding device", path);
if (UP_IS_DEVICE (gobject)) {
if (up_device_is_registered (UP_DEVICE (gobject))) {
g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, gobject);
up_device_unregister (UP_DEVICE (gobject));
}
} else if (UP_IS_DEVICE_KBD_BACKLIGHT (gobject)) {
up_device_kbd_backlight_unregister (UP_DEVICE_KBD_BACKLIGHT (gobject));
if (up_device_is_registered (UP_DEVICE (gobject))) {
g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, gobject);
up_device_unregister (UP_DEVICE (gobject));
}
} else {
g_debug ("Device %s became connected, showing device", path);
@ -438,28 +433,20 @@ up_device_disconnected_cb (GObject *gobject,
}
static void
udev_device_added_cb (UpBackend *backend, GObject *device)
udev_device_added_cb (UpBackend *backend, UpDevice *device)
{
g_debug ("Got new device from udev enumerator: %p", device);
g_signal_connect (device, "notify::disconnected",
G_CALLBACK (up_device_disconnected_cb), backend);
if (UP_IS_DEVICE (device)) {
if (update_added_duplicate_device (backend, UP_DEVICE (device)))
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device);
} else if (UP_IS_DEVICE_KBD_BACKLIGHT (device)) {
if (update_added_duplicate_device (backend, device))
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device);
} else {
g_warning ("Unknown device type");
}
}
static void
udev_device_removed_cb (UpBackend *backend, GObject *device)
udev_device_removed_cb (UpBackend *backend, UpDevice *device)
{
g_debug ("Removing device from udev enumerator: %p", device);
if (UP_IS_DEVICE (device))
update_removed_duplicate_device (backend, UP_DEVICE (device));
update_removed_duplicate_device (backend, device);
g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, device);
}
@ -788,13 +775,13 @@ up_backend_class_init (UpBackendClass *klass)
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_added),
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
G_TYPE_NONE, 1, UP_TYPE_DEVICE);
signals [SIGNAL_DEVICE_REMOVED] =
g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_removed),
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
G_TYPE_NONE, 1, UP_TYPE_DEVICE);
}
static void

View file

@ -45,28 +45,6 @@ enum {
PROP_IGNORE_SYSTEM_PERCENTAGE
};
typedef enum {
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_0,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_UNKNOWN = 1 << 0,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_NA = 1 << 1,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_TRICKLE = 1 << 2,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST = 1 << 3,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD = 1 << 4,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE = 1 << 5,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_CUSTOM = 1 << 6,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_LONG_LIFE = 1 << 7,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_BYPASS = 1 << 8,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPE_LAST,
} UpDeviceSupplyBatteryChargeTypes;
typedef enum {
UP_DEVICE_SUPPLY_BATTERY_CHARGE_THRESHOLD_SETTINGS_0,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_THRESHOLD_SETTINGS_CHARGE_CONTROL_START_THRESHOLD = 1 << 0,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_THRESHOLD_SETTINGS_CHARGE_CONTROL_END_THRESHOLD = 1 << 1,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_THRESHOLD_SETTINGS_CHARGE_TYPES = 1 << 2,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_THRESHOLD_SETTINGS_LAST,
} UpDeviceSupplyBatteryChargeThresholdSettings;
struct _UpDeviceSupplyBattery
{
UpDeviceBattery parent;
@ -75,10 +53,6 @@ struct _UpDeviceSupplyBattery
gdouble *energy_old;
guint energy_old_first;
gdouble rate_old;
guint supported_charge_types;
UpDeviceSupplyBatteryChargeTypes charge_type;
UpDeviceSupplyBatteryChargeThresholdSettings charge_threshold_settings;
gboolean charge_threshold_by_charge_type;
gboolean shown_invalid_voltage_warning;
gboolean ignore_system_percentage;
};
@ -208,178 +182,9 @@ up_device_supply_battery_get_charge_control_limits (GUdevDevice *native, UpBatte
info->charge_control_start_threshold = charge_control_start_threshold;
info->charge_control_end_threshold = charge_control_end_threshold;
if (g_udev_device_has_sysfs_attr (native, "charge_control_start_threshold"))
info->charge_threshold_settings |= UP_DEVICE_SUPPLY_BATTERY_CHARGE_THRESHOLD_SETTINGS_CHARGE_CONTROL_START_THRESHOLD;
if (g_udev_device_has_sysfs_attr (native, "charge_control_end_threshold"))
info->charge_threshold_settings |= UP_DEVICE_SUPPLY_BATTERY_CHARGE_THRESHOLD_SETTINGS_CHARGE_CONTROL_END_THRESHOLD;
return TRUE;
}
static gchar*
remove_brackets (const gchar *type)
{
GString *washed_type = NULL;
washed_type = g_string_new(NULL);
for (int i = 0; type[i] != '\0'; i++) {
if (type[i] == '[')
continue;
if (type[i] == ']')
break;
g_string_append_c (washed_type, type[i]);
}
return g_string_free (washed_type, FALSE);
}
static UpDeviceSupplyBatteryChargeTypes
up_device_battery_charge_type_str_to_enum (const gchar *type)
{
if (type == NULL)
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPE_LAST;
if (!g_strcmp0 ("Unknown", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_UNKNOWN;
else if (!g_strcmp0 ("N/A", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_NA;
else if (!g_strcmp0 ("Trickle", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_TRICKLE;
else if (!g_strcmp0 ("Fast", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST;
else if (!g_strcmp0 ("Standard", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD;
else if (!g_strcmp0 ("Adaptive", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE;
else if (!g_strcmp0 ("Custom", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_CUSTOM;
else if (!g_strcmp0 ("Long_Life", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_LONG_LIFE;
else if (!g_strcmp0 ("Bypass", type))
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_BYPASS;
/* invalid type */
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPE_LAST;
}
static gchar *
up_device_battery_charge_type_enum_to_str (UpDeviceSupplyBatteryChargeTypes types)
{
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_UNKNOWN)
return g_strdup ("Unknown");
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_NA)
return g_strdup ("N/A");
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_TRICKLE)
return g_strdup ("Trickle");
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST)
return g_strdup ("Fast");
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD)
return g_strdup ("Standard");
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE)
return g_strdup ("Adaptive");
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_CUSTOM)
return g_strdup ("Custom");
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_LONG_LIFE)
return g_strdup ("Long_Life");
if (types == UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_BYPASS)
return g_strdup ("Bypass");
/* invalid type */
return g_strdup ("Unknown");
}
static UpDeviceSupplyBatteryChargeTypes
up_device_battery_charge_find_available_charge_types_for_charging (UpDevice *device) {
UpDeviceSupplyBattery *self = UP_DEVICE_SUPPLY_BATTERY (device);
UpDeviceSupplyBatteryChargeTypes charge_types = self->supported_charge_types;
if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST)
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST;
if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD)
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD;
if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE)
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE;
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPE_LAST;
}
static void
up_device_battery_get_supported_charge_types (UpDevice *device, UpBatteryInfo *info)
{
UpDeviceSupplyBattery *self = UP_DEVICE_SUPPLY_BATTERY (device);
GUdevDevice *native;
const gchar * charge_type_str = NULL;
gchar *tmp_type = NULL;
g_auto (GStrv) types = NULL;
native = G_UDEV_DEVICE (up_device_get_native (device));
charge_type_str = g_udev_device_get_sysfs_attr (native, "charge_types");
if (charge_type_str == NULL)
return;
info->charge_threshold_settings |= UP_DEVICE_SUPPLY_BATTERY_CHARGE_THRESHOLD_SETTINGS_CHARGE_TYPES;
types = g_strsplit (charge_type_str, " ", 0);
for (int i = 0; i < g_strv_length(types); i++) {
if (g_utf8_strchr (types[i], 1, '[') != NULL) {
tmp_type = remove_brackets (types[i]);
self->charge_type = up_device_battery_charge_type_str_to_enum (tmp_type);
} else {
tmp_type = g_strdup (types[i]);
}
self->supported_charge_types |= up_device_battery_charge_type_str_to_enum (tmp_type);
g_free (tmp_type);
}
}
/**
* up_device_supply_battery_is_charge_threshold_by_charge_type:
* @device: the device to check
*
* Return %TRUE if the charge threshold is controlled by charge_types,
* %FALSE otherwise.
*
* Co-work-with: Cursor
* Reviewed-by: Kate Hsuan <hpa@redhat.com>
*/
static gboolean
up_device_supply_battery_is_charge_threshold_by_charge_type (UpDevice *device) {
GUdevDevice *native = NULL;
UpDeviceSupplyBattery *self = UP_DEVICE_SUPPLY_BATTERY (device);
native = G_UDEV_DEVICE (up_device_get_native (device));
/* if the charge_control_start_threshold or charge_control_end_threshold is found,
* then the charge threshold is not controlled by charge_types. */
if (g_udev_device_has_sysfs_attr (native, "charge_control_start_threshold") ||
g_udev_device_has_sysfs_attr (native, "charge_control_end_threshold"))
return FALSE;
if (self->supported_charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_LONG_LIFE) {
if (self->supported_charge_types & (UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD |
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE |
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST)) {
g_debug ("charge_control_start_threshold and charge_control_end_threshold are not found but the supported charge_types Long_lift, Standard or Adaptive was found. Assuming charging threshold is supported");
return TRUE;
}
}
return FALSE;
}
static gboolean
up_device_supply_battery_refresh (UpDevice *device,
UpRefreshReason reason)
@ -389,11 +194,6 @@ up_device_supply_battery_refresh (UpDevice *device,
GUdevDevice *native;
UpBatteryInfo info = { 0 };
UpBatteryValues values = { 0 };
g_autofree gchar *vendor = NULL;
g_autofree gchar *model = NULL;
g_autofree gchar *serial = NULL;
g_autofree gchar *technology = NULL;
g_autofree gchar *capacity_level = NULL;
native = G_UDEV_DEVICE (up_device_get_native (device));
@ -411,13 +211,9 @@ up_device_supply_battery_refresh (UpDevice *device,
return TRUE;
}
vendor = up_make_safe_string (get_sysfs_attr_uncached (native, "manufacturer"));
model = up_make_safe_string (get_sysfs_attr_uncached (native, "model_name"));
serial = up_make_safe_string (get_sysfs_attr_uncached (native, "serial_number"));
info.vendor = vendor;
info.model = model;
info.serial = serial;
info.vendor = up_make_safe_string (get_sysfs_attr_uncached (native, "manufacturer"));
info.model = up_make_safe_string (get_sysfs_attr_uncached (native, "model_name"));
info.serial = up_make_safe_string (get_sysfs_attr_uncached (native, "serial_number"));
info.voltage_design = up_device_supply_battery_get_design_voltage (self, native);
info.charge_cycles = g_udev_device_get_sysfs_attr_as_int_uncached (native, "cycle_count");
@ -432,11 +228,7 @@ up_device_supply_battery_refresh (UpDevice *device,
info.energy.full = g_udev_device_get_sysfs_attr_as_double_uncached (native, "charge_full") / 1000000.0;
info.energy.design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "charge_full_design") / 1000000.0;
}
technology = get_sysfs_attr_uncached (native, "technology");
info.technology = up_convert_device_technology (technology);
info.voltage_max_design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_max_design") / 1000000.0;
info.voltage_min_design = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_min_design") / 1000000.0;
info.technology = up_convert_device_technology (get_sysfs_attr_uncached (native, "technology"));
if (up_device_supply_battery_get_charge_control_limits (native, &info)) {
info.charge_control_supported = TRUE;
@ -446,20 +238,6 @@ up_device_supply_battery_refresh (UpDevice *device,
info.charge_control_supported = FALSE;
}
/* refresh the changes of charge_types */
up_device_battery_get_supported_charge_types (device, &info);
/* Test charge_types attribute, if "Long_Life", "Standard", "Adaptive" or "Fast" are found,
* then set charge_control_supported to TRUE.
*
* Co-work-with: Cursor
* Reviewed-by: Kate Hsuan <hpa@redhat.com> */
if (up_device_supply_battery_is_charge_threshold_by_charge_type (device)) {
g_debug ("charge_types attribute is found, set charge_control_supported to TRUE");
info.charge_control_supported = TRUE;
self->charge_threshold_by_charge_type = TRUE;
}
/* NOTE: We used to warn about full > design, but really that is perfectly fine to happen. */
/* Update the battery information (will only fire events for actual changes) */
@ -474,8 +252,6 @@ up_device_supply_battery_refresh (UpDevice *device,
if (values.voltage < 0.01)
values.voltage = g_udev_device_get_sysfs_attr_as_double_uncached (native, "voltage_avg") / 1000000.0;
capacity_level = up_make_safe_string (get_sysfs_attr_uncached (native, "capacity_level"));
values.capacity_level = capacity_level;
switch (values.units) {
case UP_BATTERY_UNIT_CHARGE:
@ -516,16 +292,8 @@ up_device_supply_battery_refresh (UpDevice *device,
values.percentage = CLAMP(values.percentage, 0.0f, 100.0f);
}
/* For some battery solutions, for example axp20x-battery, the kernel reports
* status = charging but the battery actually discharges when connecting a
* charger. Upower reports the battery is "discharging" when current_now is
* found and is a negative value as long as the battery isn't fully charged.*/
values.state = up_device_supply_get_state (native);
if (values.state != UP_DEVICE_STATE_FULLY_CHARGED &&
g_udev_device_get_sysfs_attr_as_double_uncached (native, "current_now") < 0.0)
values.state = UP_DEVICE_STATE_DISCHARGING;
values.temperature = g_udev_device_get_sysfs_attr_as_double_uncached (native, "temp") / 10.0;
up_device_battery_report (battery, &values, reason);
@ -625,94 +393,27 @@ up_device_supply_device_path (GUdevDevice *device)
NULL);
}
static gboolean
up_device_supply_battery_is_charge_type_exist (UpDevice *device, const gchar *charge_type) {
UpDeviceSupplyBattery *self = UP_DEVICE_SUPPLY_BATTERY (device);
UpDeviceSupplyBatteryChargeTypes type;
type = up_device_battery_charge_type_str_to_enum (charge_type);
if (type & self->supported_charge_types)
return TRUE;
return FALSE;
}
static gboolean
up_device_supply_battery_set_battery_charge_types (UpDevice *device,
UpDeviceSupplyBatteryChargeTypes charge_type,
GError **error) {
GUdevDevice *native;
g_autofree gchar *charge_type_str = NULL;
g_autofree gchar *native_path = NULL;
g_autofree gchar *type_filename = NULL;
native = G_UDEV_DEVICE (up_device_get_native (device));
charge_type_str = up_device_battery_charge_type_enum_to_str (charge_type);
/* return, if the attribute "charge_types" is not found */
if (!g_udev_device_has_sysfs_attr (native, "charge_types"))
return TRUE;
native_path = up_device_supply_device_path (native);
type_filename = g_build_filename (native_path, "charge_types", NULL);
if (!up_device_supply_battery_is_charge_type_exist (device, charge_type_str)) {
g_debug ("charge_type %s is not supported, skip setting", charge_type_str);
return TRUE;
}
if (!g_file_set_contents_full (type_filename, charge_type_str, -1,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) {
g_set_error_literal (error, G_IO_ERROR,
G_IO_ERROR_FAILED, "Failed to set charge_types");
return TRUE;
}
return TRUE;
}
static gboolean
up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint start, guint end, GError **error) {
guint err_count = 0;
GUdevDevice *native;
UpDeviceSupplyBattery *self = UP_DEVICE_SUPPLY_BATTERY (device);
g_autofree gchar *native_path = NULL;
g_autofree gchar *start_filename = NULL;
g_autofree gchar *end_filename = NULL;
g_autoptr (GString) start_str = g_string_new (NULL);
g_autoptr (GString) end_str = g_string_new (NULL);
UpDeviceSupplyBatteryChargeTypes charge_type_enum;
native = G_UDEV_DEVICE (up_device_get_native (device));
native_path = up_device_supply_device_path (native);
start_filename = g_build_filename (native_path, "charge_control_start_threshold", NULL);
end_filename = g_build_filename (native_path, "charge_control_end_threshold", NULL);
/* if the charge threshold is controlled by charge_types,
* the charge_types will be set to Long_life when enabling the charge threshold.
* the charge_types will be set to Standard/Adaptive/Fast when disabling the charge threshold. */
if (self->charge_threshold_by_charge_type) {
if (start == 0 && end == 100) {
charge_type_enum = up_device_battery_charge_find_available_charge_types_for_charging (device);
up_device_supply_battery_set_battery_charge_types (device,
charge_type_enum,
NULL);
} else {
up_device_supply_battery_set_battery_charge_types (device,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_LONG_LIFE,
NULL);
}
return TRUE;
}
if (start != G_MAXUINT) {
g_string_printf (start_str, "%d", CLAMP (start, 0, 100));
if (!g_file_set_contents_full (start_filename, start_str->str, start_str->len,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, NULL))
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) {
err_count++;
}
} else {
g_debug ("Ignore charge_control_start_threshold setting");
}
@ -720,8 +421,9 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s
if (end != G_MAXUINT) {
g_string_printf (end_str, "%d", CLAMP (end, 0, 100));
if (!g_file_set_contents_full (end_filename, end_str->str, end_str->len,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, NULL))
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) {
err_count++;
}
} else {
g_debug ("Ignore charge_control_end_threshold setting");
}
@ -732,18 +434,6 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s
return FALSE;
}
if (start == 0 && end == 100) {
charge_type_enum = up_device_battery_charge_find_available_charge_types_for_charging (device);
up_device_supply_battery_set_battery_charge_types (device,
charge_type_enum,
NULL);
} else {
/* for the Dell laptops, the charge_types has to be set to "Custom" to enable the charging threshold */
up_device_supply_battery_set_battery_charge_types (device,
UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_CUSTOM,
NULL);
}
return TRUE;
}

View file

@ -331,12 +331,8 @@ static void
up_device_supply_sibling_discovered_guess_type (UpDevice *device,
GObject *sibling)
{
GUdevDevice *input, *native_device;
g_autoptr (GUdevDevice) parent_device = NULL;
g_autoptr (GUdevDevice) parent_sibling = NULL;
GUdevDevice *input;
UpDeviceKind cur_type, new_type;
gboolean is_same_parent = FALSE;
char *new_model_name;
char *model_name;
char *serial_number;
int i;
@ -358,16 +354,16 @@ up_device_supply_sibling_discovered_guess_type (UpDevice *device,
* a keyboard, a touchpad, and... etc, for example Sony DualShock4 joystick.
* A mouse and a touchpad may include a mouse and a keyboard.
* Therefore, the priority is:
* 1. Gaming_input
* 2. Audio
* 1. Audio
* 2. Gaming_input
* 3. Keyboard
* 4. Tablet
* 5. Touchpad
* 6. Mouse
*/
UpDeviceKind priority[] = {
UP_DEVICE_KIND_GAMING_INPUT,
UP_DEVICE_KIND_OTHER_AUDIO,
UP_DEVICE_KIND_GAMING_INPUT,
UP_DEVICE_KIND_KEYBOARD,
UP_DEVICE_KIND_TABLET,
UP_DEVICE_KIND_TOUCHPAD,
@ -469,35 +465,10 @@ up_device_supply_sibling_discovered_guess_type (UpDevice *device,
}
if (cur_type != new_type) {
native_device = G_UDEV_DEVICE (up_device_get_native (device));
parent_device = g_udev_device_get_parent (native_device);
parent_sibling = g_udev_device_get_parent (input);
g_debug ("Type changed from %s to %s",
up_device_kind_to_string (cur_type),
up_device_kind_to_string (new_type));
/* Check if the device and the sibling have the same parent. */
if (!g_strcmp0 (g_udev_device_get_sysfs_path (parent_device),
g_udev_device_get_sysfs_path (parent_sibling)))
is_same_parent = TRUE;
new_model_name = up_device_supply_get_string (input, "name");
/* The model name of a device component may be different. For example, DualSense
* joystick owns "Sony Interactive Entertainment DualSense Wireless Controller"
* for the joystick and "Sony Interactive Entertainment DualSense Wireless Controller
* Motion Sensors" for the accelerometer. If the type is change, the corresponding
* model name have to be changed too. */
if (new_model_name != NULL && is_same_parent) {
up_make_safe_string (new_model_name);
g_object_set (device,
"type", new_type,
"model", new_model_name,
NULL);
} else {
g_object_set (device, "type", new_type, NULL);
}
g_free (new_model_name);
up_device_kind_to_string(cur_type),
up_device_kind_to_string(new_type));
g_object_set (device, "type", new_type, NULL);
}
}

View file

@ -31,7 +31,6 @@
#include "up-device-supply-battery.h"
#include "up-device-hid.h"
#include "up-device-wup.h"
#include "up-kbd-backlight-led.h"
#ifdef HAVE_IDEVICE
#include "up-device-idevice.h"
#endif /* HAVE_IDEVICE */
@ -179,12 +178,6 @@ get_latest_udev_device (UpEnumeratorUdev *self,
{
const char *sysfs_path;
/* return NULL when receiving a non-GUdevDevice object */
if (!G_UDEV_IS_DEVICE (obj)) {
g_debug ("Receiving a non-udev object.");
return NULL;
}
sysfs_path = g_udev_device_get_sysfs_path (G_UDEV_DEVICE (obj));
return g_udev_client_query_by_sysfs_path (self->udev, sysfs_path);
}
@ -217,102 +210,13 @@ emit_changes_for_siblings (UpEnumeratorUdev *self,
}
}
static void
power_supply_add_helper (UpEnumeratorUdev *self,
const gchar *action,
GUdevDevice *device,
GUdevClient *client,
GObject *obj,
const gchar *device_key)
{
g_autoptr(UpDevice) up_dev = NULL;
g_autofree char *parent_id = NULL;
up_dev = device_new (self, device);
/* We work with `obj` further down, which is the UpDevice
* if we have it, or the GUdevDevice if not. */
if (up_dev)
obj = G_OBJECT (up_dev);
else
obj = G_OBJECT (device);
g_hash_table_insert (self->known, (char*) device_key, g_object_ref (obj));
/* Fire relevant sibling events and insert into lookup table */
parent_id = device_parent_id (device);
g_debug ("device %s has parent id: %s", device_key, parent_id);
if (parent_id) {
GPtrArray *devices = NULL;
char *parent_id_key = NULL;
int i;
g_hash_table_lookup_extended (self->siblings, parent_id,
(gpointer*)&parent_id_key, (gpointer*)&devices);
if (!devices)
devices = g_ptr_array_new_with_free_func (g_object_unref);
for (i = 0; i < devices->len; i++) {
GObject *sibling = g_ptr_array_index (devices, i);
if (up_dev) {
g_autoptr(GUdevDevice) d = get_latest_udev_device (self, sibling);
if (d)
up_device_sibling_discovered (up_dev, G_OBJECT (d));
}
if (UP_IS_DEVICE (sibling))
up_device_sibling_discovered (UP_DEVICE (sibling), obj);
}
g_ptr_array_add (devices, g_object_ref (obj));
if (!parent_id_key) {
parent_id_key = g_strdup (parent_id);
g_hash_table_insert (self->siblings, parent_id_key, devices);
}
/* Just a reference to the hash table key */
g_object_set_data (obj, "udev-parent-id", parent_id_key);
}
if (up_dev)
g_signal_emit_by_name (self, "device-added", up_dev);
}
static void
kbd_backlight_add_helper (UpEnumeratorUdev *self,
const gchar *action,
GUdevDevice *device,
GUdevClient *client,
GObject *obj,
const char *device_key)
{
UpDaemon *daemon;
g_autoptr(UpDeviceKbdBacklight) up_kbd = NULL;
g_autofree char *parent_id = NULL;
daemon = up_enumerator_get_daemon (UP_ENUMERATOR (self));
up_kbd = g_initable_new (UP_TYPE_KBD_BACKLIGHT_LED, NULL, NULL,
"daemon", daemon,
"native", device,
NULL);
if (up_kbd)
obj = G_OBJECT (up_kbd);
else
obj = G_OBJECT (device);
g_hash_table_insert (self->known, (char*) device_key, g_object_ref (obj));
if (up_kbd)
g_signal_emit_by_name (self, "device-added", G_OBJECT (up_kbd));
}
static void
uevent_signal_handler_cb (UpEnumeratorUdev *self,
const gchar *action,
GUdevDevice *device,
GUdevClient *client)
const gchar *action,
GUdevDevice *device,
GUdevClient *client)
{
const char *device_key = g_udev_device_get_sysfs_path (device);
gboolean is_kbd_backlight = FALSE;
g_debug ("Received uevent %s on device %s", action, device_key);
@ -320,19 +224,6 @@ uevent_signal_handler_cb (UpEnumeratorUdev *self,
if (g_strcmp0 (g_udev_device_get_subsystem (device), "power_supply") == 0)
device_key = g_udev_device_get_name (device);
/* Consider both 'kbd_backlight' and 'lp5523:kb' as keyboard backlight
* devices. See include/dt-bindings/leds/common.h. 'lp5523:kb' is still
* in use, despite being marked as obsolete/legacy.
*/
if (g_strcmp0 (g_udev_device_get_subsystem (device), "leds") == 0) {
if (g_strrstr (device_key, "kbd_backlight") == NULL &&
g_strrstr (device_key, "lp5523:kb") == NULL)
return;
is_kbd_backlight = TRUE;
}
g_debug ("uevent subsystem %s", g_udev_device_get_subsystem (device));
/* It appears that we may not always receive an "add" event. As such,
* treat "add"/"change" in the same way, by first checking if we have
* seen the device.
@ -353,10 +244,56 @@ uevent_signal_handler_cb (UpEnumeratorUdev *self,
}
if (!obj) {
if (is_kbd_backlight)
kbd_backlight_add_helper (self, action, device, client, obj, device_key);
g_autoptr(UpDevice) up_dev = NULL;
g_autofree char *parent_id = NULL;
up_dev = device_new (self, device);
/* We work with `obj` further down, which is the UpDevice
* if we have it, or the GUdevDevice if not. */
if (up_dev)
obj = G_OBJECT (up_dev);
else
power_supply_add_helper (self, action, device, client, obj, device_key);
obj = G_OBJECT (device);
g_hash_table_insert (self->known, (char*) device_key, g_object_ref (obj));
/* Fire relevant sibling events and insert into lookup table */
parent_id = device_parent_id (device);
g_debug ("device %s has parent id: %s", device_key, parent_id);
if (parent_id) {
GPtrArray *devices = NULL;
char *parent_id_key = NULL;
int i;
g_hash_table_lookup_extended (self->siblings, parent_id,
(gpointer*)&parent_id_key, (gpointer*)&devices);
if (!devices)
devices = g_ptr_array_new_with_free_func (g_object_unref);
for (i = 0; i < devices->len; i++) {
GObject *sibling = g_ptr_array_index (devices, i);
if (up_dev) {
g_autoptr(GUdevDevice) d = get_latest_udev_device (self, sibling);
if (d)
up_device_sibling_discovered (up_dev, G_OBJECT (d));
}
if (UP_IS_DEVICE (sibling))
up_device_sibling_discovered (UP_DEVICE (sibling), obj);
}
g_ptr_array_add (devices, g_object_ref (obj));
if (!parent_id_key) {
parent_id_key = g_strdup (parent_id);
g_hash_table_insert (self->siblings, parent_id_key, devices);
}
/* Just a reference to the hash table key */
g_object_set_data (obj, "udev-parent-id", parent_id_key);
}
if (up_dev)
g_signal_emit_by_name (self, "device-added", up_dev);
} else {
if (!UP_IS_DEVICE (obj)) {
@ -383,11 +320,6 @@ uevent_signal_handler_cb (UpEnumeratorUdev *self,
g_debug ("removing device for path %s", g_udev_device_get_sysfs_path (device));
if (is_kbd_backlight) {
g_signal_emit_by_name (self, "device-removed", obj);
return;
}
parent_id = g_object_get_data (obj, "udev-parent-id");
/* Remove from siblings table. */
@ -429,8 +361,8 @@ up_enumerator_udev_initable_init (UpEnumerator *enumerator)
guint i;
const gchar **subsystems;
/* List "input" first just to avoid some sibling hotplugging later */
const gchar *subsystems_no_wup[] = {"input", "power_supply", "usb", "usbmisc", "sound", "leds", NULL};
const gchar *subsystems_wup[] = {"input", "power_supply", "usb", "usbmisc", "sound", "tty", "leds", NULL};
const gchar *subsystems_no_wup[] = {"input", "power_supply", "usb", "usbmisc", "sound", NULL};
const gchar *subsystems_wup[] = {"input", "power_supply", "usb", "usbmisc", "sound", "tty", NULL};
config = up_config_new ();
if (up_config_get_boolean (config, "EnableWattsUpPro"))

View file

@ -1,323 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2025 Kate Hsuan <p.hsuan@gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include "up-kbd-backlight-led.h"
#include "up-native.h"
#include "up-types.h"
static void up_kbd_backlight_led_finalize (GObject *object);
struct UpKbdBacklightLedPrivate
{
gint max_brightness;
guint brightness;
gint fd_hw_changed;
GIOChannel *channel_hw_changed;
};
G_DEFINE_TYPE_WITH_PRIVATE (UpKbdBacklightLed, up_kbd_backlight_led, UP_TYPE_DEVICE_KBD_BACKLIGHT)
/**
* up_kbd_backlight_led_brightness_write:
*
* Write the brightness value to the LED device with a given path.
**/
static gboolean
up_kbd_backlight_led_brightness_write (UpDeviceKbdBacklight *kbd_backlight, const gchar *native_path, gint value)
{
UpKbdBacklightLed *kbd;
UpKbdBacklightLedPrivate *priv;
g_autoptr (GString) value_str = g_string_new (NULL);
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
kbd = UP_KBD_BACKLIGHT_LED (kbd_backlight);
priv = up_kbd_backlight_led_get_instance_private (kbd);
g_string_printf (value_str, "%d", CLAMP (value, 0, priv->max_brightness));
if (!g_file_set_contents_full (native_path, value_str->str, value_str->len,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, NULL)) {
g_debug ("Failed on setting keyboard backlight LED brightness: %s", native_path);
return FALSE;
}
return TRUE;
}
/**
* up_kbd_backlight_led_brightness_read:
*
* Read the brightness value from the LED device with a given path.
**/
static gint
up_kbd_backlight_led_brightness_read (UpDeviceKbdBacklight *kbd_backlight, const gchar *native_path)
{
g_autofree gchar *buf = NULL;
gint64 brightness = -1;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), brightness);
if (!g_file_get_contents (native_path, &buf, NULL, NULL))
return -1;
g_strstrip (buf);
g_debug ("brightness: %s", buf);
brightness = g_ascii_strtoll (buf, NULL, 10);
if (brightness < 0) {
g_warning ("failed to convert brightness.");
return -1;
}
return brightness;
}
/**
* up_kbd_backlight_led_set_brightness:
*
* Set the brightness.
**/
static gboolean
up_kbd_backlight_led_set_brightness (UpDeviceKbdBacklight *kbd_backlight, gint value)
{
GObject *native;
g_autofree gchar *filename = NULL;
const gchar *native_path;
gboolean ret = FALSE;
native = up_device_kbd_backlight_get_native (UP_DEVICE_KBD_BACKLIGHT (kbd_backlight));
g_return_val_if_fail (native != NULL, FALSE);
native_path = up_native_get_native_path (native);
g_return_val_if_fail (native_path != NULL, FALSE);
filename = g_build_filename (native_path, "brightness", NULL);
ret = up_kbd_backlight_led_brightness_write (kbd_backlight, filename, value);
return ret;
}
/**
* up_kbd_backlight_led_get_brightness:
*
* Get the brightness.
**/
static gint
up_kbd_backlight_led_get_brightness (UpDeviceKbdBacklight *kbd_backlight)
{
GObject *native;
const gchar *native_path;
g_autofree gchar *filename = NULL;
gint brightness = -1;
native = up_device_kbd_backlight_get_native (UP_DEVICE_KBD_BACKLIGHT (kbd_backlight));
g_return_val_if_fail (native != NULL, brightness);
native_path = up_native_get_native_path (native);
g_return_val_if_fail (native_path != NULL, brightness);
filename = g_build_filename (native_path, "brightness", NULL);
brightness = up_kbd_backlight_led_brightness_read (kbd_backlight, filename);
return brightness;
}
/**
* up_kbd_backlight_led_get_max_brightness:
*
* Gets the max brightness.
**/
static gint
up_kbd_backlight_led_get_max_brightness (UpDeviceKbdBacklight *kbd_backlight)
{
UpKbdBacklightLed *kbd = UP_KBD_BACKLIGHT_LED (kbd_backlight);
UpKbdBacklightLedPrivate *priv = up_kbd_backlight_led_get_instance_private (kbd);
return priv->max_brightness;
}
/**
* up_kbd_backlight_led_event_io:
*
* This function is called when the brightness of the LED device changes.
**/
static gboolean
up_kbd_backlight_led_event_io (GIOChannel *channel, GIOCondition condition, gpointer data)
{
UpDeviceKbdBacklight *kbd_backlight = UP_DEVICE_KBD_BACKLIGHT (data);
UpKbdBacklightLed *kbd = UP_KBD_BACKLIGHT_LED (kbd_backlight);
UpKbdBacklightLedPrivate *priv = up_kbd_backlight_led_get_instance_private (kbd);
gint brightness = 0;
gchar buf[16];
g_autofree gchar *ret_str = NULL;
glong len;
gchar *end = NULL;
if (priv->fd_hw_changed < 0)
return FALSE;
if (!(condition & G_IO_PRI))
return FALSE;
lseek (priv->fd_hw_changed, 0, SEEK_SET);
len = read (priv->fd_hw_changed, buf, G_N_ELEMENTS (buf) - 1);
if (len > 0) {
buf[len] = '\0';
g_strstrip (buf);
brightness = g_ascii_strtoll (buf, &end, 10);
if (brightness < 0 ||
brightness > priv->max_brightness ||
end == buf) {
brightness = -1;
g_warning ("kbd eventio: failed to convert brightness.");
}
}
g_debug ("kbd eventio: brightness: %d", brightness);
if (brightness < 0)
return FALSE;
if (brightness >= 0)
up_device_kbd_backlight_emit_change (kbd_backlight, brightness, "internal");
return TRUE;
}
/**
* up_kbd_backlight_led_coldplug:
*
* Update the LED settings to UpKbdBacklightLed device.
**/
static gboolean
up_kbd_backlight_led_coldplug (UpDeviceKbdBacklight *kbd_backlight)
{
UpKbdBacklightLed *kbd;
UpKbdBacklightLedPrivate *priv;
GObject *native;
g_autofree gchar *filename = NULL;
g_autofree gchar *path_hw_changed = NULL;
const gchar *native_path = NULL;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
kbd = UP_KBD_BACKLIGHT_LED (kbd_backlight);
priv = up_kbd_backlight_led_get_instance_private (kbd);
native = up_device_kbd_backlight_get_native (kbd_backlight);
if (native == NULL) {
priv->max_brightness = 0;
return FALSE;
}
native_path = up_native_get_native_path (native);
filename = g_build_filename (native_path, "max_brightness", NULL);
priv->max_brightness = up_kbd_backlight_led_brightness_read (kbd_backlight, filename);
/* Set up device watcher */
path_hw_changed = g_build_filename (native_path, "brightness_hw_changed", NULL);
priv->fd_hw_changed = open (path_hw_changed, O_RDONLY);
if (priv->fd_hw_changed >= 0) {
priv->channel_hw_changed = g_io_channel_unix_new (priv->fd_hw_changed);
g_io_add_watch (priv->channel_hw_changed,
G_IO_PRI, up_kbd_backlight_led_event_io, kbd_backlight);
}
return TRUE;
}
/**
* up_kbd_backlight_led_finalize:
**/
static void
up_kbd_backlight_led_finalize (GObject *object)
{
UpKbdBacklightLed *kbd_backlight;
UpKbdBacklightLedPrivate *priv;
g_return_if_fail (object != NULL);
g_return_if_fail (UP_IS_KBD_BACKLIGHT_LED (object));
kbd_backlight = UP_KBD_BACKLIGHT_LED (object);
priv = up_kbd_backlight_led_get_instance_private (kbd_backlight);
if (priv->channel_hw_changed) {
g_io_channel_shutdown (priv->channel_hw_changed, FALSE, NULL);
g_io_channel_unref (priv->channel_hw_changed);
}
if (priv->fd_hw_changed >= 0)
close (priv->fd_hw_changed);
G_OBJECT_CLASS (up_kbd_backlight_led_parent_class)->finalize (object);
}
/**
* up_kbd_backlight_led_class_init:
**/
static void
up_kbd_backlight_led_class_init (UpKbdBacklightLedClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
UpDeviceKbdBacklightClass *dev_kbd_klass = UP_DEVICE_KBD_BACKLIGHT_CLASS (klass);
object_class->finalize = up_kbd_backlight_led_finalize;
dev_kbd_klass->coldplug = up_kbd_backlight_led_coldplug;
dev_kbd_klass->get_max_brightness = up_kbd_backlight_led_get_max_brightness;
dev_kbd_klass->get_brightness = up_kbd_backlight_led_get_brightness;
dev_kbd_klass->set_brightness = up_kbd_backlight_led_set_brightness;
}
/**
* up_kbd_backlight_led_init:
**/
static void
up_kbd_backlight_led_init (UpKbdBacklightLed *kbd_backlight)
{
kbd_backlight->priv = up_kbd_backlight_led_get_instance_private (kbd_backlight);
}
/**
* up_kbd_backlight_led_new:
**/
UpKbdBacklightLed *
up_kbd_backlight_led_new (void)
{
return g_object_new (UP_TYPE_KBD_BACKLIGHT_LED, NULL);
}

View file

@ -1,55 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2025 Kate Hsuan <p.hsuan@gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __UP_KBD_BACKLIGHT_LED_H
#define __UP_KBD_BACKLIGHT_LED_H
#include <glib-object.h>
#include "up-device-kbd-backlight.h"
G_BEGIN_DECLS
#define UP_TYPE_KBD_BACKLIGHT_LED (up_kbd_backlight_led_get_type ())
#define UP_KBD_BACKLIGHT_LED(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_KBD_BACKLIGHT_LED, UpKbdBacklightLed))
#define UP_KBD_BACKLIGHT_LED_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_KBD_BACKLIGHT_LED, UpKbdBacklightLedClass))
#define UP_IS_KBD_BACKLIGHT_LED(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_KBD_BACKLIGHT_LED))
#define UP_IS_KBD_BACKLIGHT_LED_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_KBD_BACKLIGHT_LED))
#define UP_KBD_BACKLIGHT_LED_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_KBD_BACKLIGHT_LED, UpKbdBacklightLedClass))
typedef struct UpKbdBacklightLedPrivate UpKbdBacklightLedPrivate;
typedef struct
{
UpDeviceKbdBacklight parent;
UpKbdBacklightLedPrivate *priv;
} UpKbdBacklightLed;
typedef struct
{
UpDeviceKbdBacklightClass parent_class;
} UpKbdBacklightLedClass;
UpKbdBacklightLed *up_kbd_backlight_led_new (void);
GType up_kbd_backlight_led_get_type (void);
G_END_DECLS
#endif /* __UP_KBD_BACKLIGHT_LED_H */

View file

@ -40,8 +40,6 @@ upowerd_private = static_library('upowerd-private',
'up-enumerator.h',
'up-kbd-backlight.h',
'up-kbd-backlight.c',
'up-device-kbd-backlight.c',
'up-device-kbd-backlight.h',
'up-history.h',
'up-history.c',
'up-backend.h',
@ -144,27 +142,24 @@ if os_backend == 'linux' and gobject_introspection.found()
args: ut_args,
env: env,
depends: [ libupower_glib_typelib, upowerd ],
timeout: 150,
timeout: 80,
)
endforeach
installed_tests = get_option('installed_tests')
if installed_tests
install_data( [
'linux/integration-test.py',
'linux/output_checker.py',
],
install_dir: get_option('prefix') / get_option('libexecdir') / 'upower'
)
install_subdir('linux/tests/',
install_dir: get_option('prefix') / get_option('libexecdir') / 'upower'
)
install_data( [
'linux/integration-test.py',
'linux/output_checker.py',
],
install_dir: get_option('prefix') / get_option('libexecdir') / 'upower'
)
install_subdir('linux/tests/',
install_dir: get_option('prefix') / get_option('libexecdir') / 'upower'
)
configure_file(
input: 'upower-integration.test.in',
output: 'upower-integration.test',
install_dir: get_option('datadir') / 'installed-tests' / 'upower',
configuration: cdata
)
endif
configure_file(
input: 'upower-integration.test.in',
output: 'upower-integration.test',
install_dir: get_option('datadir') / 'installed-tests' / 'upower',
configuration: cdata
)
endif

View file

@ -383,8 +383,6 @@ up_backend_update_battery_state(UpDevice* device)
(void*) NULL);
if(up_native_get_sensordev("acpibat0", &sdev))
up_backend_update_acpibat_state(device, sdev);
else if(up_native_get_sensordev("qcpas0", &sdev))
up_backend_update_acpibat_state(device, sdev);
return TRUE;
}
return FALSE;

View file

@ -104,142 +104,6 @@ up_config_class_init (UpConfigClass *klass)
object_class->finalize = up_config_finalize;
}
/**
* up_config_list_compare_files:
**/
static gint
up_config_list_compare_files (gconstpointer a, gconstpointer b)
{
return g_strcmp0 ((const gchar*)a, (const gchar*)b);
}
/**
* up_config_list_confd_files:
*
* The format of the filename should be '^([0-9][0-9])-([a-zA-Z0-9-_])*\.conf$',
* that is, starting with "00-" to "99-", ending in ".conf", and with a mix of
* alphanumeric characters with dashes and underscores in between. For example:
* '01-upower-override.conf'.
*
* Files named differently, or containing invalid groups (currently only
* 'UPower' is valid), will not be considered.
*
* The candidate files within the given directory are sorted (with g_strcmp0(),
* so the ordering will be as with strcmp()). The configuration in the files
* being processed later will override previous config, in particular the main
* config, but also the one from previous files processed, if the Group and Key
* coincide.
*
* For example, consider 'UPower.conf' that contains the defaults:
* PercentageLow=20.0
* PercentageCritical=5.0
* PercentageAction=2.0
*
* and there is a file 'UPower.conf.d/70-change-percentages.conf'
* containing settings for all 'Percentage*' keys:
* [UPower]
* PercentageLow=15.0
* PercentageCritical=10.0
* PercentageAction=5.0
*
* and another 'UPower.conf.d/99-change-percentages-local.conf'
* containing settings only for 'PercentageAction':
* [UPower]
* PercentageAction=7.5
*
* First the main 'UPower.conf' will be processed, then
* 'UPower.conf.d/70-change-percentages.conf' overriding the defaults
* of all percentages from the main config file with the given values,
* and finally 'UPower.conf.d/99-change-percentages-local.conf'
* overriding once again only 'PercentageAction'. The final, effective
* values are:
* PercentageLow=15.0
* PercentageCritical=10.0
* PercentageAction=7.5
**/
static GPtrArray*
up_config_list_confd_files (const gchar* conf_d_path, GError** error)
{
g_autoptr (GPtrArray) ret_conf_d_files = NULL;
GDir *dir = NULL;
const gchar *filename = NULL;
const char *regex_pattern = "^([0-9][0-9])-([a-zA-Z0-9-_])*\\.conf$";
g_autoptr (GRegex) regex = NULL;
dir = g_dir_open (conf_d_path, 0, error);
if (dir == NULL)
return NULL;
regex = g_regex_new (regex_pattern, G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL);
g_assert (regex != NULL);
ret_conf_d_files = g_ptr_array_new_full (0, g_free);
while ((filename = g_dir_read_name (dir)) != NULL) {
g_autofree gchar *file_path = NULL;
g_autoptr (GFile) file = NULL;
g_autoptr (GFileInfo) file_info = NULL;
if (!g_regex_match (regex, filename, G_REGEX_MATCH_DEFAULT, NULL))
continue;
file_path = g_build_filename (conf_d_path, filename, NULL);
file = g_file_new_for_path (file_path);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL,
NULL);
if (file_info != NULL) {
g_debug ("Will consider additional config file '%s'", file_path);
g_ptr_array_add (ret_conf_d_files, g_strdup (file_path));
}
}
g_dir_close (dir);
g_ptr_array_sort_values (ret_conf_d_files, up_config_list_compare_files);
return g_ptr_array_ref (ret_conf_d_files);
}
/**
* up_config_override_from_confd:
**/
static void
up_config_override_from_confd (GKeyFile *key_file, const gchar* new_config_path)
{
g_autoptr (GKeyFile) new_keyfile = NULL;
gchar **keys = NULL;
gsize keys_size = 0;
new_keyfile = g_key_file_new();
if (!g_key_file_load_from_file (new_keyfile, new_config_path, G_KEY_FILE_NONE, NULL))
return;
if (!g_key_file_has_group (new_keyfile, "UPower"))
return;
keys = g_key_file_get_keys (new_keyfile, "UPower", &keys_size, NULL);
if (keys == NULL)
return;
for (gsize i = 0; i < keys_size; i++) {
g_autofree gchar *value = NULL;
g_autofree gchar *old_value = NULL;
value = g_key_file_get_value (new_keyfile, "UPower", keys[i], NULL);
if (value == NULL)
continue;
old_value = g_key_file_get_value (key_file, "UPower", keys[i], NULL);
if (old_value != NULL)
g_key_file_set_value (key_file, "UPower", keys[i], value);
}
g_strfreev (keys);
}
/**
* up_config_init:
**/
@ -247,26 +111,17 @@ static void
up_config_init (UpConfig *config)
{
gboolean allow_risky_critical_action = FALSE;
gboolean expect_battery_recalibration = FALSE;
g_autofree gchar *critical_action = NULL;
g_autoptr (GError) error = NULL;
GError *error = NULL;
g_autofree gchar *filename = NULL;
gboolean ret;
g_autofree gchar *conf_dir = NULL;
g_autofree gchar *conf_d_path = NULL;
g_autoptr (GPtrArray) conf_d_files = NULL;
config->priv = up_config_get_instance_private (config);
config->priv->keyfile = g_key_file_new ();
filename = g_strdup (g_getenv ("UPOWER_CONF_FILE_NAME"));
if (filename == NULL) {
if (filename == NULL)
filename = g_build_filename (PACKAGE_SYSCONF_DIR,"UPower", "UPower.conf", NULL);
conf_d_path = g_build_filename (PACKAGE_SYSCONF_DIR, "UPower", "UPower.conf.d", NULL);
} else {
conf_dir = g_path_get_dirname (filename);
conf_d_path = g_build_filename (conf_dir, "UPower.conf.d", NULL);
}
/* load */
ret = g_key_file_load_from_file (config->priv->keyfile,
@ -277,18 +132,7 @@ up_config_init (UpConfig *config)
if (!ret) {
g_warning ("failed to load config file '%s': %s",
filename, error->message);
g_clear_error (&error);
}
conf_d_files = up_config_list_confd_files (conf_d_path, &error);
if (conf_d_files != NULL) {
for (guint i = 0; i < conf_d_files->len; i++) {
const gchar* conf_d_file = (const gchar*)(g_ptr_array_index (conf_d_files, i));
up_config_override_from_confd (config->priv->keyfile,
conf_d_file);
}
} else {
g_debug ("failed to find files in 'UPower.conf.d': %s", error->message);
g_error_free (error);
}
/* Warn for any dangerous configurations */
@ -309,17 +153,6 @@ up_config_init (UpConfig *config)
" risky settings.", critical_action);
}
}
expect_battery_recalibration = up_config_get_boolean (config, "ExpectBatteryRecalibration");
if (expect_battery_recalibration) {
if (allow_risky_critical_action) {
g_warning ("The \"ExpectBatteryRecalibration\" setting is considered risky:"
" abrupt power loss due to battery exhaustion may lead to data"
" corruption. The system will unexpected down when the AC is disconnected."
" Use AllowRiskyCriticalPowerAction=false to disable support for"
" risky settings.");
}
}
}
/**

View file

@ -33,7 +33,6 @@
#include "up-polkit.h"
#include "up-device-list.h"
#include "up-device.h"
#include "up-device-kbd-backlight.h"
#include "up-backend.h"
#include "up-daemon.h"
@ -44,7 +43,6 @@ struct UpDaemonPrivate
UpPolkit *polkit;
UpBackend *backend;
UpDeviceList *power_devices;
UpDeviceList *kbd_backlight_devices;
guint action_timeout_id;
guint refresh_batteries_id;
guint warning_level_id;
@ -63,9 +61,6 @@ struct UpDaemonPrivate
gint64 time_to_empty;
gint64 time_to_full;
gboolean charge_threshold_enabled;
gboolean state_all_discharging;
/* WarningLevel configuration */
gboolean use_percentage_for_policy;
gdouble low_percentage;
@ -152,12 +147,8 @@ up_daemon_update_display_battery (UpDaemon *daemon)
gint64 time_to_empty_total = 0;
gint64 time_to_full_total = 0;
gboolean is_present_total = FALSE;
gboolean charge_threshold_enabled_total = FALSE;
guint num_batteries = 0;
gboolean state_all_discharging = TRUE;
gboolean state_any_discharging = FALSE;
/* Gather state from each device */
array = up_device_list_get_array (daemon->priv->power_devices);
for (i = 0; i < array->len; i++) {
@ -165,7 +156,6 @@ up_daemon_update_display_battery (UpDaemon *daemon)
UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;
UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN;
gboolean present = FALSE;
gdouble percentage = 0.0;
gdouble energy = 0.0;
gdouble energy_full = 0.0;
@ -173,11 +163,9 @@ up_daemon_update_display_battery (UpDaemon *daemon)
gint64 time_to_empty = 0;
gint64 time_to_full = 0;
gboolean power_supply = FALSE;
gboolean charge_threshold_enabled = FALSE;
device = g_ptr_array_index (array, i);
g_object_get (device,
"is-present", &present,
"type", &kind,
"state", &state,
"percentage", &percentage,
@ -187,12 +175,8 @@ up_daemon_update_display_battery (UpDaemon *daemon)
"time-to-empty", &time_to_empty,
"time-to-full", &time_to_full,
"power-supply", &power_supply,
"charge-threshold-enabled", &charge_threshold_enabled,
NULL);
if (!present)
continue;
/* When we have a UPS, it's either a desktop, and
* has no batteries, or a laptop, in which case we
* ignore the batteries */
@ -242,17 +226,6 @@ up_daemon_update_display_battery (UpDaemon *daemon)
else
state_total = UP_DEVICE_STATE_UNKNOWN;
/* Update charging state variables by considering any battery that is charging or fully charged to not
* be discharging. Additionally, also update state_any_discharge for any batteries explicitly
* discharging. */
if (state == UP_DEVICE_STATE_CHARGING || state == UP_DEVICE_STATE_FULLY_CHARGED) {
state_all_discharging = FALSE;
} else if (state == UP_DEVICE_STATE_DISCHARGING)
state_any_discharging = TRUE;
/* If at least one battery has charge thresholds enabled, propagate that. */
charge_threshold_enabled_total = charge_threshold_enabled_total || charge_threshold_enabled;
/* sum up composite */
kind_total = UP_DEVICE_KIND_BATTERY;
is_present_total = TRUE;
@ -315,9 +288,6 @@ out:
time_to_full_total = SECONDS_PER_HOUR * ((energy_full_total - energy_total) / energy_rate_total);
}
/* Compute state_all_discharging by ensuring at least one battery is discharging */
state_all_discharging = state_all_discharging && state_any_discharging;
/* Did anything change? */
if (daemon->priv->kind == kind_total &&
daemon->priv->state == state_total &&
@ -326,9 +296,7 @@ out:
daemon->priv->energy_rate == energy_rate_total &&
daemon->priv->time_to_empty == time_to_empty_total &&
daemon->priv->time_to_full == time_to_full_total &&
daemon->priv->percentage == percentage_total &&
daemon->priv->charge_threshold_enabled == charge_threshold_enabled_total &&
daemon->priv->state_all_discharging == state_all_discharging)
daemon->priv->percentage == percentage_total)
return FALSE;
daemon->priv->kind = kind_total;
@ -341,9 +309,6 @@ out:
daemon->priv->percentage = percentage_total;
daemon->priv->charge_threshold_enabled = charge_threshold_enabled_total;
daemon->priv->state_all_discharging = state_all_discharging;
g_object_set (daemon->priv->display_device,
"type", kind_total,
"state", state_total,
@ -354,7 +319,6 @@ out:
"time-to-full", time_to_full_total,
"percentage", percentage_total,
"is-present", is_present_total,
"charge-threshold-enabled", charge_threshold_enabled_total,
"power-supply", TRUE,
"update-time", (guint64) g_get_real_time () / G_USEC_PER_SEC,
NULL);
@ -365,7 +329,7 @@ out:
/**
* up_daemon_get_warning_level_local:
*
* As soon as _all_ batteries are low, external power is not available or not charging at least one battery, this is true
* As soon as _all_ batteries are low, this is true
**/
static UpDeviceLevel
up_daemon_get_warning_level_local (UpDaemon *daemon)
@ -378,10 +342,9 @@ up_daemon_get_warning_level_local (UpDaemon *daemon)
daemon->priv->state != UP_DEVICE_STATE_DISCHARGING)
return UP_DEVICE_LEVEL_NONE;
/* Ignore battery level if we have external power and not all batteries are discharging */
/* Check to see if the batteries have not noticed we are on AC */
if (daemon->priv->kind == UP_DEVICE_KIND_BATTERY &&
up_daemon_get_on_ac_local (daemon, NULL) &&
!daemon->priv->state_all_discharging)
up_daemon_get_on_ac_local (daemon, NULL))
return UP_DEVICE_LEVEL_NONE;
return up_daemon_compute_warning_level (daemon,
@ -499,38 +462,6 @@ up_daemon_enumerate_devices (UpExportedDaemon *skeleton,
return TRUE;
}
static gboolean
up_daemon_enumerate_kbd_backlights (UpExportedDaemon *skeleton,
GDBusMethodInvocation *invocation,
UpDaemon *daemon)
{
guint i;
GPtrArray *array;
GPtrArray *object_paths;
UpDeviceKbdBacklight *kbd_backlight;
/* build a pointer array of the object paths */
object_paths = g_ptr_array_new_with_free_func (g_free);
array = up_device_list_get_array (daemon->priv->kbd_backlight_devices);
for (i = 0; i < array->len; i++) {
const char *object_path;
kbd_backlight = (UpDeviceKbdBacklight *) g_ptr_array_index (array, i);
object_path = up_device_kbd_backlight_get_object_path (kbd_backlight);
if (object_path != NULL)
g_ptr_array_add (object_paths, g_strdup (object_path));
}
g_ptr_array_unref (array);
g_ptr_array_add (object_paths, NULL);
/* return it on the bus */
up_exported_daemon_complete_enumerate_kbd_backlights (skeleton, invocation,
(const gchar **) object_paths->pdata);
/* free */
g_ptr_array_unref (object_paths);
return TRUE;
}
/**
* up_daemon_get_display_device:
**/
@ -635,7 +566,6 @@ up_daemon_shutdown (UpDaemon *daemon)
/* forget about discovered devices */
up_device_list_clear (daemon->priv->power_devices);
up_device_list_clear (daemon->priv->kbd_backlight_devices);
/* release UpDaemon reference */
g_object_run_dispose (G_OBJECT (daemon->priv->display_device));
@ -769,8 +699,6 @@ up_daemon_compute_warning_level (UpDaemon *daemon,
gdouble percentage,
gint64 time_to_empty)
{
gboolean can_risky = FALSE;
gboolean expect_battery_recalibration = FALSE;
gboolean use_percentage = TRUE;
UpDeviceLevel default_level = UP_DEVICE_LEVEL_NONE;
@ -793,21 +721,6 @@ up_daemon_compute_warning_level (UpDaemon *daemon,
default_level = UP_DEVICE_LEVEL_DISCHARGING;
}
/* Check if the battery is performing the battery recalibration and
* AC is online, the battery level is UP_DEVICE_LEVEL_NONE. */
can_risky = up_config_get_boolean (daemon->priv->config,
"AllowRiskyCriticalPowerAction");
expect_battery_recalibration = up_config_get_boolean (daemon->priv->config,
"ExpectBatteryRecalibration");
if (can_risky && kind == UP_DEVICE_KIND_BATTERY) {
if (expect_battery_recalibration &&
up_daemon_get_on_ac_local (daemon, NULL)) {
g_debug ("ExpectBatteryRecalibration is enabled and the AC is connected, so the battery level is not critical");
return UP_DEVICE_LEVEL_NONE;
}
}
if (power_supply &&
!daemon->priv->use_percentage_for_policy &&
time_to_empty > 0.0)
@ -1086,50 +999,35 @@ up_daemon_get_env_override (UpDaemon *self)
* up_daemon_device_added_cb:
**/
static void
up_daemon_device_added_cb (UpBackend *backend, GObject *device, UpDaemon *daemon)
up_daemon_device_added_cb (UpBackend *backend, UpDevice *device, UpDaemon *daemon)
{
const gchar *object_path;
UpDaemonPrivate *priv = daemon->priv;
g_return_if_fail (UP_IS_DAEMON (daemon));
g_return_if_fail (UP_IS_DEVICE (device) || UP_IS_DEVICE_KBD_BACKLIGHT (device));
g_return_if_fail (UP_IS_DEVICE (device));
if (UP_IS_DEVICE (device)) {
/* power_supply */
/* add to device list */
up_device_list_insert (priv->power_devices, device);
/* add to device list */
up_device_list_insert (priv->power_devices, device);
/* connect, so we get changes */
g_signal_connect (device, "notify",
G_CALLBACK (up_daemon_device_changed_cb), daemon);
/* connect, so we get changes */
g_signal_connect (device, "notify",
G_CALLBACK (up_daemon_device_changed_cb), daemon);
/* emit */
object_path = up_device_get_object_path (UP_DEVICE (device));
if (object_path == NULL) {
g_debug ("Device %s was unregistered before it was on the bus",
up_exported_device_get_native_path (UP_EXPORTED_DEVICE (device)));
return;
}
/* Ensure we poll the new device if needed */
g_source_set_ready_time (daemon->priv->poll_source, 0);
g_debug ("emitting added: %s", object_path);
up_daemon_update_warning_level (daemon);
up_exported_daemon_emit_device_added (UP_EXPORTED_DAEMON (daemon), object_path);
} else {
/*leds*/
g_debug ("Add a led device to the device list");
/* emit */
object_path = up_device_kbd_backlight_get_object_path (UP_DEVICE_KBD_BACKLIGHT (device));
if (object_path == NULL) {
g_debug ("Device %s was unregistered before it was on the bus",
up_exported_kbd_backlight_get_native_path (UP_EXPORTED_KBD_BACKLIGHT (device)));
return;
}
up_device_list_insert (priv->kbd_backlight_devices, G_OBJECT (device));
up_exported_daemon_emit_device_added (UP_EXPORTED_DAEMON (daemon), object_path);
/* emit */
object_path = up_device_get_object_path (device);
if (object_path == NULL) {
g_debug ("Device %s was unregistered before it was on the bus",
up_exported_device_get_native_path (UP_EXPORTED_DEVICE (device)));
return;
}
/* Ensure we poll the new device if needed */
g_source_set_ready_time (daemon->priv->poll_source, 0);
g_debug ("emitting added: %s", object_path);
up_daemon_update_warning_level (daemon);
up_exported_daemon_emit_device_added (UP_EXPORTED_DAEMON (daemon), object_path);
}
/**
@ -1142,22 +1040,15 @@ up_daemon_device_removed_cb (UpBackend *backend, UpDevice *device, UpDaemon *dae
UpDaemonPrivate *priv = daemon->priv;
g_return_if_fail (UP_IS_DAEMON (daemon));
g_return_if_fail (UP_IS_DEVICE (device) || UP_IS_DEVICE_KBD_BACKLIGHT (device));
g_return_if_fail (UP_IS_DEVICE (device));
g_signal_handlers_disconnect_by_data (device, daemon);
/* remove from list (device remains valid during the function call) */
up_device_list_remove (priv->power_devices, device);
/* emit */
if (UP_IS_DEVICE (device)) {
/* remove from list (device remains valid during the function call) */
up_device_list_remove (priv->power_devices, device);
object_path = up_device_get_object_path (device);
} else if (UP_IS_DEVICE_KBD_BACKLIGHT (device)) {
/* remove from list (device remains valid during the function call) */
up_device_list_remove (priv->kbd_backlight_devices, device);
object_path = up_device_kbd_backlight_get_object_path (UP_DEVICE_KBD_BACKLIGHT (device));
} else {
return;
}
object_path = up_device_get_object_path (device);
/* don't crash the session */
if (object_path == NULL) {
@ -1168,10 +1059,6 @@ up_daemon_device_removed_cb (UpBackend *backend, UpDevice *device, UpDaemon *dae
g_debug ("emitting device-removed: %s", object_path);
up_exported_daemon_emit_device_removed (UP_EXPORTED_DAEMON (daemon), object_path);
/* Unregister keyboard backlight dbus path */
if (UP_IS_DEVICE_KBD_BACKLIGHT (device))
up_device_kbd_backlight_unregister (UP_DEVICE_KBD_BACKLIGHT (device));
/* In case a battery was removed */
up_daemon_refresh_battery_devices (daemon);
up_daemon_update_warning_level (daemon);
@ -1232,7 +1119,6 @@ up_daemon_init (UpDaemon *daemon)
daemon->priv->polkit = up_polkit_new ();
daemon->priv->config = up_config_new ();
daemon->priv->power_devices = up_device_list_new ();
daemon->priv->kbd_backlight_devices = up_device_list_new ();
daemon->priv->display_device = up_device_new (daemon, NULL);
daemon->priv->poll_source = g_source_new (&poll_source_funcs, sizeof (GSource));
@ -1259,8 +1145,6 @@ up_daemon_init (UpDaemon *daemon)
g_signal_connect (daemon, "handle-enumerate-devices",
G_CALLBACK (up_daemon_enumerate_devices), daemon);
g_signal_connect (daemon, "handle-enumerate-kbd_backlights",
G_CALLBACK (up_daemon_enumerate_kbd_backlights), daemon);
g_signal_connect (daemon, "handle-get-critical-action",
G_CALLBACK (up_daemon_get_critical_action), daemon);
g_signal_connect (daemon, "handle-get-display-device",
@ -1319,7 +1203,6 @@ up_daemon_finalize (GObject *object)
g_clear_pointer (&daemon->priv->poll_source, g_source_destroy);
g_object_unref (priv->power_devices);
g_object_unref (priv->kbd_backlight_devices);
g_object_unref (priv->display_device);
g_object_unref (priv->polkit);
g_object_unref (priv->config);

View file

@ -391,7 +391,6 @@ up_device_battery_report (UpDeviceBattery *self,
"energy-rate", values->energy.rate,
"time-to-empty", time_to_empty,
"time-to-full", time_to_full,
"capacity-level", values->capacity_level,
/* XXX: Move "update-time" updates elsewhere? */
"update-time", (guint64) g_get_real_time () / G_USEC_PER_SEC,
NULL);
@ -537,9 +536,6 @@ up_device_battery_update_info (UpDeviceBattery *self, UpBatteryInfo *info)
"charge-end-threshold", info->charge_control_end_threshold,
"charge-threshold-enabled", charge_threshold_enabled,
"charge-threshold-supported", info->charge_control_supported,
"charge-threshold-settings-supported", info->charge_threshold_settings,
"voltage-min-design", info->voltage_min_design,
"voltage-max-design", info->voltage_max_design,
NULL);
priv->present = TRUE;
@ -599,27 +595,18 @@ up_device_battery_update_info (UpDeviceBattery *self, UpBatteryInfo *info)
"vendor", NULL,
"model", NULL,
"serial", NULL,
"state", UP_DEVICE_STATE_UNKNOWN,
"technology", UP_DEVICE_TECHNOLOGY_UNKNOWN,
"capacity", (gdouble) 0.0,
"energy", (gdouble) 0.0,
"energy-full", (gdouble) 0.0,
"energy-full-design", (gdouble) 0.0,
"voltage", (gdouble) 0.0,
"charge-cycles", -1,
"has-history", FALSE,
"has-statistics", FALSE,
"percentage", (gdouble) 0.0,
"temperature", (gdouble) 0.0,
"update-time", (guint64) g_get_real_time () / G_USEC_PER_SEC,
"charge-start-threshold", 0,
"charge-end-threshold", 0,
"charge-end-threshold", 100,
"charge-threshold-enabled", FALSE,
"charge-threshold-supported", FALSE,
"charge-threshold-settings-supported", 0,
"voltage-min-design", (gdouble) 0.0,
"voltage-max-design", (gdouble) 0.0,
"capacity-level", NULL,
NULL);
}
}

View file

@ -64,7 +64,6 @@ typedef struct {
gdouble percentage;
gdouble voltage;
gdouble temperature;
gchar *capacity_level;
} UpBatteryValues;
typedef struct {
@ -90,15 +89,12 @@ typedef struct {
UpDeviceTechnology technology;
gdouble voltage_design;
gint charge_cycles;
gdouble voltage_max_design;
gdouble voltage_min_design;
/* battery charging threshold */
gboolean charge_control_enabled;
gboolean charge_control_supported;
guint charge_control_start_threshold;
guint charge_control_end_threshold;
guint charge_threshold_settings;
} UpBatteryInfo;

View file

@ -1,410 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2025 Kate Hsuan <p.hsuan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "config.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>
#include "up-native.h"
#include "up-device-kbd-backlight.h"
#include "up-stats-item.h"
typedef struct
{
UpDaemon *daemon;
GObject *native;
} UpDeviceKbdBacklightPrivate;
static void up_device_kbd_backlight_initable_iface_init (GInitableIface *iface);
G_DEFINE_TYPE_EXTENDED (UpDeviceKbdBacklight, up_device_kbd_backlight, UP_TYPE_EXPORTED_KBD_BACKLIGHT_SKELETON, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
up_device_kbd_backlight_initable_iface_init)
G_ADD_PRIVATE (UpDeviceKbdBacklight))
enum {
PROP_0,
PROP_DAEMON,
PROP_NATIVE,
N_PROPS
};
/* Upower keeps the legacy keyboard backlight DBus API (/org/freedesktop/UPower/KbdBacklight/)
* for backward compatibility.
* The new API path is based on the legacy one and the suffix is the name of the keyboard
* backlight device. For example, the path of the keyboard backlight device
* "tpacpiookbd_backlight" is
* "/org/freedesktop/UPower/KbdBacklight/tpacpiookbd_backlight".*/
#define UP_DEVICES_KBD_BACKLIGHT_DBUS_PATH "/org/freedesktop/UPower/KbdBacklight"
static GParamSpec *properties[N_PROPS];
/**
* up_kbd_backlight_emit_change:
**/
void
up_device_kbd_backlight_emit_change(UpDeviceKbdBacklight *kbd_backlight, int value, const char *source)
{
up_exported_kbd_backlight_emit_brightness_changed (UP_EXPORTED_KBD_BACKLIGHT (kbd_backlight), value);
up_exported_kbd_backlight_emit_brightness_changed_with_source (UP_EXPORTED_KBD_BACKLIGHT (kbd_backlight), value, source);
}
/**
* up_kbd_backlight_get_brightness:
*
* Gets the current brightness
**/
static gboolean
up_kbd_backlight_get_brightness (UpExportedKbdBacklight *skeleton,
GDBusMethodInvocation *invocation,
UpDeviceKbdBacklight *kbd_backlight)
{
UpDeviceKbdBacklightClass *klass;
gint brightness = 0;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (kbd_backlight);
brightness = klass->get_brightness (kbd_backlight);
if (brightness >= 0) {
up_exported_kbd_backlight_complete_get_brightness (skeleton, invocation,
brightness);
} else {
g_dbus_method_invocation_return_error (invocation,
UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
"error reading brightness");
}
return TRUE;
}
/**
* up_kbd_backlight_get_max_brightness:
*
* Gets the max brightness
**/
static gboolean
up_kbd_backlight_get_max_brightness (UpExportedKbdBacklight *skeleton,
GDBusMethodInvocation *invocation,
UpDeviceKbdBacklight *kbd_backlight)
{
UpDeviceKbdBacklightClass *klass;
gint brightness = -1;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (kbd_backlight);
if (klass->get_max_brightness != NULL)
brightness = klass->get_max_brightness (kbd_backlight);
if (brightness >= 0) {
up_exported_kbd_backlight_complete_get_max_brightness (skeleton, invocation,
brightness);
} else {
g_dbus_method_invocation_return_error (invocation,
UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
"error reading max brightness");
}
return TRUE;
}
/**
* up_kbd_backlight_set_brightness:
*
* Sets the kbd backlight LED brightness.
**/
static gboolean
up_kbd_backlight_set_brightness (UpExportedKbdBacklight *skeleton,
GDBusMethodInvocation *invocation,
gint value,
UpDeviceKbdBacklight *kbd_backlight)
{
UpDeviceKbdBacklightClass *klass;
gboolean ret = FALSE;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (kbd_backlight);
if (klass->set_brightness == NULL) {
g_dbus_method_invocation_return_error (invocation,
UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
"setting brightness is unsupported");
return TRUE;
}
ret = klass->set_brightness (kbd_backlight, value);
if (ret) {
up_exported_kbd_backlight_complete_set_brightness (skeleton, invocation);
up_device_kbd_backlight_emit_change (kbd_backlight, value, "external");
} else {
g_dbus_method_invocation_return_error (invocation,
UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
"error writing brightness %d", value);
}
return TRUE;
}
GObject *
up_device_kbd_backlight_get_native (UpDeviceKbdBacklight *device)
{
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (device), NULL);
return priv->native;
}
static gchar *
up_device_kbd_backlight_compute_object_path (UpDeviceKbdBacklight *device)
{
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
g_autofree gchar *basename = NULL;
g_autofree gchar *id = NULL;
gchar *object_path;
const gchar *native_path;
guint i;
if (priv->native == NULL) {
return g_build_filename (UP_DEVICES_KBD_BACKLIGHT_DBUS_PATH, "KbdBacklight", NULL);
}
native_path = up_exported_kbd_backlight_get_native_path (UP_EXPORTED_KBD_BACKLIGHT (device));
basename = g_path_get_basename (native_path);
id = g_strjoin ("_", basename, NULL);
/* make DBUS valid path */
for (i=0; id[i] != '\0'; i++) {
if (id[i] == '-')
id[i] = '_';
if (id[i] == '.')
id[i] = 'x';
if (id[i] == ':')
id[i] = 'o';
if (id[i] == '@')
id[i] = '_';
}
object_path = g_build_filename (UP_DEVICES_KBD_BACKLIGHT_DBUS_PATH, id, NULL);
return object_path;
}
static void
up_device_kbd_backlight_export_skeleton (UpDeviceKbdBacklight *device,
const gchar *object_path)
{
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
GError *error = NULL;
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (device),
g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (priv->daemon)),
object_path,
&error);
if (error != NULL) {
g_critical ("error registering device on system bus: %s", error->message);
g_error_free (error);
}
}
gboolean
up_device_kbd_backlight_register (UpDeviceKbdBacklight *device)
{
g_autofree char *computed_object_path = NULL;
if (g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (device)) != NULL)
return FALSE;
computed_object_path = up_device_kbd_backlight_compute_object_path (device);
g_debug ("Exported Keyboard backlight with path %s", computed_object_path);
up_device_kbd_backlight_export_skeleton (device, computed_object_path);
return TRUE;
}
void
up_device_kbd_backlight_unregister (UpDeviceKbdBacklight *device)
{
g_autofree char *object_path = NULL;
object_path = g_strdup (g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (device)));
if (object_path != NULL) {
g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (device));
g_debug ("Unexported UpDeviceKbdBacklight with path %s", object_path);
}
}
const gchar *
up_device_kbd_backlight_get_object_path (UpDeviceKbdBacklight *device)
{
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (device), NULL);
return g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (device));
}
static void
up_device_kbd_backlight_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
UpDeviceKbdBacklight *device = UP_DEVICE_KBD_BACKLIGHT (object);
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
switch (prop_id)
{
case PROP_DAEMON:
priv->daemon = g_value_dup_object (value);
break;
case PROP_NATIVE:
priv->native = g_value_dup_object (value);
if (priv->native == NULL)
g_warning ("KBD native is NULL");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
up_device_kbd_backlight_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static gboolean
up_device_kbd_backlight_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
UpDeviceKbdBacklight *device = UP_DEVICE_KBD_BACKLIGHT (initable);
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
const gchar *native_path = NULL;
UpDeviceKbdBacklightClass *klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (device);
int ret;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (device), FALSE);
if (priv->native) {
native_path = up_native_get_native_path (priv->native);
up_exported_kbd_backlight_set_native_path (UP_EXPORTED_KBD_BACKLIGHT (device), native_path);
}
/* coldplug source */
if (klass->coldplug != NULL) {
ret = klass->coldplug (device);
if (!ret) {
g_debug ("failed to coldplug %s", native_path);
g_propagate_error (error, g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to coldplug %s", native_path));
return FALSE;
}
}
up_device_kbd_backlight_register (device);
return TRUE;
}
static void
up_device_kbd_backlight_initable_iface_init (GInitableIface *iface)
{
iface->init = up_device_kbd_backlight_initable_init;
}
/**
* up_kbd_backlight_init:
**/
static void
up_device_kbd_backlight_init (UpDeviceKbdBacklight *kbd_backlight)
{
g_signal_connect (kbd_backlight, "handle-get-brightness",
G_CALLBACK (up_kbd_backlight_get_brightness), kbd_backlight);
g_signal_connect (kbd_backlight, "handle-get-max-brightness",
G_CALLBACK (up_kbd_backlight_get_max_brightness), kbd_backlight);
g_signal_connect (kbd_backlight, "handle-set-brightness",
G_CALLBACK (up_kbd_backlight_set_brightness), kbd_backlight);
}
/**
* up_kbd_backlight_finalize:
**/
static void
up_device_kbd_backlight_finalize (GObject *object)
{
g_return_if_fail (object != NULL);
g_return_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (object));
G_OBJECT_CLASS (up_device_kbd_backlight_parent_class)->finalize (object);
}
static void
up_device_kbd_backlight_class_init (UpDeviceKbdBacklightClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = up_device_kbd_backlight_finalize;
object_class->set_property = up_device_kbd_backlight_set_property;
object_class->get_property = up_device_kbd_backlight_get_property;
properties[PROP_DAEMON] =
g_param_spec_object ("daemon",
"UpDaemon",
"UpDaemon reference",
UP_TYPE_DAEMON,
G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_NATIVE] =
g_param_spec_object ("native",
"Native",
"Native Object",
G_TYPE_OBJECT,
G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
/**
* up_kbd_backlight_new:
**/
UpDeviceKbdBacklight *
up_device_kbd_backlight_new (UpDaemon *daemon, GObject *native)
{
return UP_DEVICE_KBD_BACKLIGHT (g_object_new (UP_TYPE_DEVICE_KBD_BACKLIGHT,
"daemon", daemon,
"native", native,
NULL));
}

View file

@ -1,60 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2025 Kate Hsuan <p.hsuan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __UP_DEVICE_KBD_BACKLIGHT_H__
#define __UP_DEVICE_KBD_BACKLIGHT_H__
#include <dbus/up-kbd-backlight-generated.h>
#include "up-daemon.h"
G_BEGIN_DECLS
#define UP_TYPE_DEVICE_KBD_BACKLIGHT (up_device_kbd_backlight_get_type ())
G_DECLARE_DERIVABLE_TYPE (UpDeviceKbdBacklight, up_device_kbd_backlight, UP, DEVICE_KBD_BACKLIGHT, UpExportedKbdBacklightSkeleton)
struct _UpDeviceKbdBacklightClass
{
UpExportedKbdBacklightSkeletonClass parent_class;
gboolean (*coldplug) (UpDeviceKbdBacklight *device);
gint (*get_max_brightness) (UpDeviceKbdBacklight *device);
gint (*get_brightness) (UpDeviceKbdBacklight *device);
gboolean (*set_brightness) (UpDeviceKbdBacklight *device, gint brightness);
};
GType up_device_kbd_backlight_get_type (void);
void up_device_kbd_backlight_emit_change (UpDeviceKbdBacklight *kbd_backlight,
int value,
const char *source);
const gchar *up_device_kbd_backlight_get_object_path (UpDeviceKbdBacklight *device);
GObject *up_device_kbd_backlight_get_native (UpDeviceKbdBacklight *device);
UpDeviceKbdBacklight *up_device_kbd_backlight_new (UpDaemon *daemon,
GObject *native);
gboolean up_device_kbd_backlight_register (UpDeviceKbdBacklight *device);
void up_device_kbd_backlight_unregister (UpDeviceKbdBacklight *device);
G_END_DECLS
#endif /* __UP_DEVICE_KBD_BACKLIGHT_H__ */

View file

@ -28,7 +28,6 @@
#include "up-native.h"
#include "up-device-list.h"
#include "up-device.h"
#include "up-device-kbd-backlight.h"
static void up_device_list_finalize (GObject *object);
@ -81,10 +80,7 @@ up_device_list_insert (UpDeviceList *list, gpointer device)
g_return_val_if_fail (UP_IS_DEVICE_LIST (list), FALSE);
g_return_val_if_fail (device != NULL, FALSE);
if (UP_IS_DEVICE_KBD_BACKLIGHT (device))
native = up_device_kbd_backlight_get_native (UP_DEVICE_KBD_BACKLIGHT (device));
else
native = up_device_get_native (UP_DEVICE (device));
native = up_device_get_native (UP_DEVICE (device));
g_return_val_if_fail (native != NULL, FALSE);
native_path = up_native_get_native_path (native);

View file

@ -220,7 +220,6 @@ up_device_notify (GObject *object, GParamSpec *pspec)
{
UpDevice *device = UP_DEVICE (object);
UpDevicePrivate *priv = up_device_get_instance_private (device);
g_autofree gchar *id = NULL;
/* Not finished setting up the object? */
if (priv->daemon == NULL)
@ -228,20 +227,18 @@ up_device_notify (GObject *object, GParamSpec *pspec)
G_OBJECT_CLASS (up_device_parent_class)->notify (object, pspec);
id = up_device_get_id (device);
if (g_strcmp0 (pspec->name, "type") == 0 ||
g_strcmp0 (pspec->name, "is-present") == 0) {
update_icon_name (device);
/* Clearing the history object for lazily loading when device id was changed. */
if (priv->history != NULL &&
!up_history_is_device_id_equal (priv->history, id))
!up_history_is_device_id_equal (priv->history, up_device_get_id(device)))
g_clear_object (&priv->history);
} else if (g_strcmp0 (pspec->name, "vendor") == 0 ||
g_strcmp0 (pspec->name, "model") == 0 ||
g_strcmp0 (pspec->name, "serial") == 0) {
if (priv->history != NULL &&
!up_history_is_device_id_equal (priv->history, id))
!up_history_is_device_id_equal (priv->history, up_device_get_id(device)))
g_clear_object (&priv->history);
} else if (g_strcmp0 (pspec->name, "power-supply") == 0 ||
g_strcmp0 (pspec->name, "time-to-empty") == 0) {
@ -292,13 +289,6 @@ up_device_get_online (UpDevice *device, gboolean *online)
return klass->get_online (device, online);
}
/**
* up_device_get_id:
*
* Return the id of a Device.
* Note: The caller of the method takes ownership of the returned data, and is
* responsible for freeing it.
**/
static gchar *
up_device_get_id (UpDevice *device)
{

View file

@ -155,11 +155,11 @@ up_history_array_limit_resolution (GPtrArray *array, guint max_num)
guint64 preset;
item = (UpHistoryItem *) g_ptr_array_index (array, i);
preset = first - ((first - last) * (guint64) step) / max_num;
preset = last + ((first - last) * (guint64) step) / max_num;
/* if state changed or we went over the preset do a new point */
if (count > 0 &&
(up_history_item_get_time (item) < preset ||
(up_history_item_get_time (item) > preset ||
up_history_item_get_state (item) != state)) {
item_new = up_history_item_new ();
up_history_item_set_time (item_new, time_s / count);

View file

@ -210,7 +210,6 @@ main (gint argc, gchar **argv)
if (!g_option_context_parse (context, &argc, &argv, &error)) {
g_warning ("Failed to parse command-line options: %s", error->message);
g_error_free (error);
g_option_context_free (context);
return 1;
}
g_option_context_free (context);

View file

@ -181,116 +181,30 @@ up_tool_do_monitor (UpClient *client)
return FALSE;
}
static void
up_tool_output_daemon (UpClient *client)
{
g_print ("Daemon:\n");
up_client_print (client);
}
static gint
up_tool_output_display_device (UpClient *client)
{
g_autoptr (UpDevice) device = NULL;
g_autofree gchar *text = NULL;
device = up_client_get_display_device (client);
if (!device) {
g_print ("Failed to get display device\n");
return 1;
}
g_print ("Device: %s\n", up_device_get_object_path (device));
text = up_device_to_text (device);
g_print ("%s\n", text);
return 0;
}
static gint
up_tool_output_device_dump (UpClient *client, GList *device_filter)
{
g_autoptr (GPtrArray) devices = NULL;
UpDevice *device;
guint i;
guint kind = 0;
gint ret = 0;
gchar *text = NULL;
devices = up_client_get_devices2 (client);
if (!devices) {
g_print ("Failed to get device list\n");
return 1;
}
for (i=0; i < devices->len; i++) {
device = (UpDevice*) g_ptr_array_index (devices, i);
g_object_get (device, "kind", &kind, NULL);
if (g_list_find (device_filter, GINT_TO_POINTER (kind)) || device_filter == NULL) {
g_print ("Device: %s\n", up_device_get_object_path (device));
text = up_device_to_text (device);
g_print ("%s\n", text);
g_free (text);
}
}
if (device_filter == NULL) {
ret = up_tool_output_display_device (client);
up_tool_output_daemon (client);
}
return ret;
}
static gint
up_tool_output_enumerate (UpClient *client)
{
g_autoptr (GPtrArray) devices = NULL;
g_autoptr (UpDevice) display_device = NULL;
UpDevice *device;
guint i;
devices = up_client_get_devices2 (client);
for (i = 0; i < devices->len; i++) {
device = (UpDevice*) g_ptr_array_index (devices, i);
g_print ("%s\n", up_device_get_object_path (device));
}
display_device = up_client_get_display_device (client);
if (display_device == NULL) {
g_print ("Failed to get display device\n");
return 1;
}
g_print ("%s\n", up_device_get_object_path (display_device));
return 0;
}
/**
* main:
**/
int
main (int argc, char **argv)
{
gint retval = EXIT_FAILURE;
guint i;
GOptionContext *context;
gboolean opt_battery = FALSE;
gboolean opt_dump = FALSE;
gboolean opt_enumerate = FALSE;
gboolean opt_monitor = FALSE;
gchar *opt_show_info = FALSE;
gboolean opt_version = FALSE;
GList *device_filter = NULL;
gboolean ret;
gint retval;
GError *error = NULL;
gchar *text = NULL;
g_autoptr (UpClient) client = NULL;
UpClient *client;
UpDevice *device;
const GOptionEntry entries[] = {
{ "battery", 'b', 0, G_OPTION_ARG_NONE, &opt_battery, _("Dump all parameters for battery objects"), NULL },
{ "dump", 'd', 0, G_OPTION_ARG_NONE, &opt_dump, _("Dump all parameters for all objects"), NULL },
{ "enumerate", 'e', 0, G_OPTION_ARG_NONE, &opt_enumerate, _("Enumerate objects paths for devices"), NULL },
{ "dump", 'd', 0, G_OPTION_ARG_NONE, &opt_dump, _("Dump all parameters for all objects"), NULL },
{ "monitor", 'm', 0, G_OPTION_ARG_NONE, &opt_monitor, _("Monitor activity from the power daemon"), NULL },
{ "monitor-detail", 0, 0, G_OPTION_ARG_NONE, &opt_monitor_detail, _("Monitor with detail"), NULL },
{ "show-info", 'i', 0, G_OPTION_ARG_STRING, &opt_show_info, _("Show information about object path"), NULL },
@ -305,13 +219,8 @@ main (int argc, char **argv)
context = g_option_context_new ("UPower tool");
g_option_context_add_main_entries (context, entries, NULL);
ret = g_option_context_parse (context, &argc, &argv, &error);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
if (!ret) {
g_print ("Failed to parse command-line options: %s\n", error->message);
g_error_free (error);
return EXIT_FAILURE;
}
loop = g_main_loop_new (NULL, FALSE);
client = up_client_new_full (NULL, &error);
@ -322,34 +231,64 @@ main (int argc, char **argv)
}
if (opt_version) {
g_autofree gchar *daemon_version = NULL;
gchar *daemon_version;
g_object_get (client,
"daemon-version", &daemon_version,
NULL);
g_print ("UPower client version %s\n"
"UPower daemon version %s\n",
PACKAGE_VERSION, daemon_version);
return EXIT_SUCCESS;
g_free (daemon_version);
retval = 0;
goto out;
}
if (opt_enumerate)
return up_tool_output_enumerate (client);
if (opt_battery) {
device_filter = g_list_append (device_filter, GINT_TO_POINTER (UP_DEVICE_KIND_BATTERY));
opt_dump = TRUE;
}
if (opt_dump) {
retval = up_tool_output_device_dump (client, device_filter);
g_list_free (device_filter);
return retval;
if (opt_enumerate || opt_dump) {
GPtrArray *devices;
devices = up_client_get_devices2 (client);
if (!devices) {
g_print ("Failed to get device list\n");
goto out;
}
for (i=0; i < devices->len; i++) {
device = (UpDevice*) g_ptr_array_index (devices, i);
if (opt_enumerate) {
g_print ("%s\n", up_device_get_object_path (device));
} else {
g_print ("Device: %s\n", up_device_get_object_path (device));
text = up_device_to_text (device);
g_print ("%s\n", text);
g_free (text);
}
}
g_ptr_array_unref (devices);
device = up_client_get_display_device (client);
if (!device) {
g_print ("Failed to get display device\n");
goto out;
}
if (opt_enumerate) {
g_print ("%s\n", up_device_get_object_path (device));
} else {
g_print ("Device: %s\n", up_device_get_object_path (device));
text = up_device_to_text (device);
g_print ("%s\n", text);
g_free (text);
}
g_object_unref (device);
if (opt_dump) {
g_print ("Daemon:\n");
up_client_print (client);
}
retval = EXIT_SUCCESS;
goto out;
}
if (opt_monitor || opt_monitor_detail) {
if (!up_tool_do_monitor (client))
return EXIT_FAILURE;
return EXIT_SUCCESS;
goto out;
retval = EXIT_SUCCESS;
goto out;
}
if (opt_show_info != NULL) {
@ -364,6 +303,10 @@ main (int argc, char **argv)
g_free (text);
}
g_object_unref (device);
return EXIT_SUCCESS;
retval = EXIT_SUCCESS;
goto out;
}
out:
g_object_unref (client);
return retval;
}