summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Lievisse Adriaanse <jasper@humppa.nl>2014-04-20 20:15:36 +0200
committerRichard Hughes <richard@hughsie.com>2014-04-22 11:41:56 +0100
commit4bed9c99c1d459f0d1bc760716573e2a2af5e0e1 (patch)
treef15432a880e7512588df602f4d591c6e040c0503
parentb9cff29978113aefe3ad18521f383f12ab099a34 (diff)
downloadupower-4bed9c99c1d459f0d1bc760716573e2a2af5e0e1.tar.gz
Update lid status when updating ac status.
Signed-off-by: Richard Hughes <richard@hughsie.com>
-rw-r--r--src/openbsd/up-backend.c70
1 files changed, 68 insertions, 2 deletions
diff --git a/src/openbsd/up-backend.c b/src/openbsd/up-backend.c
index 40e381e..d00730b 100644
--- a/src/openbsd/up-backend.c
+++ b/src/openbsd/up-backend.c
@@ -34,6 +34,7 @@ static void up_backend_finalize (GObject *object);
static gboolean up_backend_apm_get_power_info(struct apm_power_info*);
UpDeviceState up_backend_apm_get_battery_state_value(u_char battery_state);
static void up_backend_update_acpibat_state(UpDevice*, struct sensordev);
+static void up_backend_update_lid_status(UpDaemon*);
static gboolean up_apm_device_get_on_battery (UpDevice *device, gboolean *on_battery);
static gboolean up_apm_device_get_online (UpDevice *device, gboolean *online);
@@ -128,10 +129,10 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
UpApmNative *acnative = NULL;
UpApmNative *battnative = NULL;
backend->priv->daemon = g_object_ref (daemon);
- /* XXX no way to get lid status atm */
- up_daemon_set_lid_is_present (backend->priv->daemon, FALSE);
+
if (backend->priv->is_laptop)
{
+ up_backend_update_lid_status(daemon);
acnative = up_apm_native_new("/ac");
if (!up_device_coldplug (backend->priv->ac, backend->priv->daemon, G_OBJECT(acnative)))
g_warning ("failed to coldplug ac");
@@ -215,6 +216,7 @@ up_backend_update_ac_state(UpDevice* device)
gboolean ret, new_is_online, cur_is_online;
struct apm_power_info a;
+ up_backend_update_lid_status(up_device_get_daemon(device));
ret = up_backend_apm_get_power_info(&a);
if (!ret)
return ret;
@@ -407,6 +409,70 @@ up_apm_device_refresh(UpDevice* device)
return ret;
}
+/*
+ * Check the lid status, return TRUE if one was found, FALSE otherwise.
+ */
+static void
+up_backend_update_lid_status(UpDaemon *daemon) {
+
+ /* Use hw.sensors.acpibtn0.indicator0=On (lid open) */
+ struct sensordev sensordev;
+ struct sensor sensor;
+ size_t sdlen, slen;
+ int dev, numt, mib[5] = {CTL_HW, HW_SENSORS, 0, 0, 0};
+ gboolean lid_found = FALSE;
+ gboolean lid_open = FALSE;
+
+ sdlen = sizeof(struct sensordev);
+ slen = sizeof(struct sensor);
+
+ /* go through all acpibtn devices, and check if one of the values match "lid"
+ if so, use that device.
+ */
+ for (dev = 0; SENSOR_MAX_TYPES; dev++) {
+ mib[2] = dev;
+ if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) {
+ if (errno == ENXIO)
+ continue;
+ if (errno == ENOENT)
+ break;
+ }
+
+ if (strstr(sensordev.xname, "acpibtn") != NULL) {
+ mib[3] = SENSOR_INDICATOR;
+ for (numt = 0; numt < sensordev.maxnumt[SENSOR_INDICATOR]; numt++) {
+ mib[4] = numt;
+ if (sysctl(mib, 5, &sensor, &slen, NULL, 0) == -1) {
+ if (errno != ENOENT) {
+ g_warning("failed to get sensor data from %s",
+ sensordev.xname);
+ continue;
+ }
+ }
+
+ /*
+ * Found an acpibtn device, now check if the
+ * description has got anything with a lid in it.
+ */
+ if (strstr(sensor.desc, "lid open") == NULL) {
+ g_warning ("nothing here for %s with %s\n",
+ sensordev.xname, sensor.desc);
+ continue;
+ } else {
+ lid_found = TRUE;
+ if (sensor.value)
+ lid_open = TRUE;
+ else
+ lid_open = FALSE;
+ }
+ }
+ }
+ }
+
+ up_daemon_set_lid_is_present (daemon, lid_found);
+ up_daemon_set_lid_is_closed (daemon, !lid_open);
+}
+
/* thread doing kqueue() on apm device */
static gpointer
up_backend_apm_event_thread(gpointer object)