mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-01-30 05:50:25 +01:00
Add a lid-is-present property
This commit is contained in:
parent
936c57bf60
commit
56881f8eaf
4 changed files with 71 additions and 6 deletions
|
|
@ -50,6 +50,7 @@ struct DkpClientPrivate
|
|||
gboolean lid_is_closed;
|
||||
gboolean on_battery;
|
||||
gboolean on_low_battery;
|
||||
gboolean lid_is_present;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
@ -67,7 +68,9 @@ enum {
|
|||
PROP_CAN_HIBERNATE,
|
||||
PROP_ON_BATTERY,
|
||||
PROP_ON_LOW_BATTERY,
|
||||
PROP_LID_IS_CLOSED
|
||||
PROP_LID_IS_CLOSED,
|
||||
PROP_LID_IS_PRESENT,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
static guint signals [DKP_CLIENT_LAST_SIGNAL] = { 0 };
|
||||
|
|
@ -293,6 +296,13 @@ dkp_client_ensure_properties (DkpClient *client)
|
|||
}
|
||||
client->priv->on_low_battery = g_value_get_boolean (value);
|
||||
|
||||
value = g_hash_table_lookup (props, "lid-is-present");
|
||||
if (value == NULL) {
|
||||
g_warning ("No 'lid-is-present' property");
|
||||
goto out;
|
||||
}
|
||||
client->priv->lid_is_present = g_value_get_boolean (value);
|
||||
|
||||
/* cached */
|
||||
client->priv->have_properties = TRUE;
|
||||
|
||||
|
|
@ -339,7 +349,7 @@ dkp_client_can_hibernate (DkpClient *client)
|
|||
*
|
||||
* Get whether the laptop lid is closed.
|
||||
*
|
||||
* Return value: TRUE if lid is closed FALSE other wise.
|
||||
* Return value: %TRUE if lid is closed or %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
dkp_client_lid_is_closed (DkpClient *client)
|
||||
|
|
@ -349,6 +359,22 @@ dkp_client_lid_is_closed (DkpClient *client)
|
|||
return client->priv->lid_is_closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_client_get_lid_is_present:
|
||||
* @client : a #DkpClient instance.
|
||||
*
|
||||
* Gets if the system has a lide device.
|
||||
*
|
||||
* Return value: %TRUE if system has a lid that can be closed or %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
dkp_client_get_lid_is_present (DkpClient *client)
|
||||
{
|
||||
g_return_val_if_fail (DKP_IS_CLIENT (client), FALSE);
|
||||
dkp_client_ensure_properties (client);
|
||||
return client->priv->lid_is_present;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_client_can_suspend:
|
||||
* @client : a #DkpClient instance.
|
||||
|
|
@ -479,18 +505,21 @@ dkp_client_get_property (GObject *object,
|
|||
case PROP_CAN_SUSPEND:
|
||||
g_value_set_boolean (value, client->priv->can_suspend);
|
||||
break;
|
||||
case PROP_CAN_HIBERNATE:
|
||||
case PROP_CAN_HIBERNATE:
|
||||
g_value_set_boolean (value, client->priv->can_hibernate);
|
||||
break;
|
||||
case PROP_ON_BATTERY:
|
||||
g_value_set_boolean (value, client->priv->on_battery);
|
||||
break;
|
||||
case PROP_ON_LOW_BATTERY:
|
||||
case PROP_ON_LOW_BATTERY:
|
||||
g_value_set_boolean (value, client->priv->on_low_battery);
|
||||
break;
|
||||
case PROP_LID_IS_CLOSED:
|
||||
case PROP_LID_IS_CLOSED:
|
||||
g_value_set_boolean (value, client->priv->lid_is_closed);
|
||||
break;
|
||||
case PROP_LID_IS_PRESENT:
|
||||
g_value_set_boolean (value, client->priv->lid_is_present);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
@ -553,6 +582,13 @@ dkp_client_class_init (DkpClientClass *klass)
|
|||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_LID_IS_PRESENT,
|
||||
g_param_spec_boolean ("lid-is-present",
|
||||
NULL, NULL,
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
signals [DKP_DEVICE_ADDED] =
|
||||
g_signal_new ("device-added",
|
||||
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ gboolean dkp_client_lid_is_closed (DkpClient *client);
|
|||
gboolean dkp_client_can_suspend (DkpClient *client);
|
||||
gboolean dkp_client_on_battery (DkpClient *client);
|
||||
gboolean dkp_client_on_low_battery (DkpClient *client);
|
||||
gboolean dkp_client_get_lid_is_present (DkpClient *client);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ enum
|
|||
PROP_ON_BATTERY,
|
||||
PROP_ON_LOW_BATTERY,
|
||||
PROP_LID_IS_CLOSED,
|
||||
PROP_LID_IS_PRESENT,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
@ -82,6 +84,7 @@ struct DkpDaemonPrivate
|
|||
gboolean low_battery;
|
||||
DevkitClient *devkit_client;
|
||||
gboolean lid_is_closed;
|
||||
gboolean lid_is_present;
|
||||
};
|
||||
|
||||
static void dkp_daemon_class_init (DkpDaemonClass *klass);
|
||||
|
|
@ -220,6 +223,10 @@ dkp_daemon_get_property (GObject *object,
|
|||
g_value_set_boolean (value, daemon->priv->lid_is_closed);
|
||||
break;
|
||||
|
||||
case PROP_LID_IS_PRESENT:
|
||||
g_value_set_boolean (value, daemon->priv->lid_is_present);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
@ -281,6 +288,14 @@ dkp_daemon_class_init (DkpDaemonClass *klass)
|
|||
NULL,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_LID_IS_PRESENT,
|
||||
g_param_spec_boolean ("lid-is-present",
|
||||
"Is a laptop",
|
||||
"If this computer is probably a laptop",
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_CAN_SUSPEND,
|
||||
g_param_spec_boolean ("can-suspend",
|
||||
|
|
@ -334,6 +349,7 @@ dkp_daemon_init (DkpDaemon *daemon)
|
|||
{
|
||||
daemon->priv = DKP_DAEMON_GET_PRIVATE (daemon);
|
||||
daemon->priv->polkit = dkp_polkit_new ();
|
||||
daemon->priv->lid_is_present = FALSE;
|
||||
daemon->priv->lid_is_closed = FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -595,6 +611,9 @@ dkp_daemon_device_get (DkpDaemon *daemon, DevkitDevice *d)
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* we now have a lid */
|
||||
daemon->priv->lid_is_present = TRUE;
|
||||
|
||||
/* not a power device */
|
||||
dkp_device_list_insert (daemon->priv->managed_devices, d, G_OBJECT (input));
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,6 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
|
|||
|
||||
<!-- ************************************************************ -->
|
||||
|
||||
|
||||
<property name="daemon-version" type="s" access="read">
|
||||
<doc:doc><doc:description><doc:para>
|
||||
Version of the running daemon, e.g. <doc:tt>002</doc:tt>.
|
||||
|
|
@ -172,6 +171,16 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
|
|||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="lid-is-present" type="b" access="read">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
If the system has a lid device.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</property>
|
||||
|
||||
<signal name="Changed">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue