Commit ed322d59 authored by Guido Gunther's avatar Guido Gunther
Browse files

proximity: Only use proximity sensor on active calls

See Librem5/calls#175

Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent 28b3b251
Pipeline #66693 passed with stages
in 51 minutes and 50 seconds
...@@ -19,13 +19,16 @@ ...@@ -19,13 +19,16 @@
* SECTION:proximity * SECTION:proximity
* @short_description: Proximity sensor handling * @short_description: Proximity sensor handling
* @Title: PhoshProximity * @Title: PhoshProximity
*
* #PhoshProximity handles enabling and disabling the proximity detection
* based on e.g. active calls.
*/ */
enum { enum {
PROP_0, PROP_0,
PROP_SENSOR_PROXY_MANAGER, PROP_SENSOR_PROXY_MANAGER,
PROP_LOCKSCREEN_MANAGER, PROP_CALLS_MANAGER,
LAST_PROP, LAST_PROP,
}; };
static GParamSpec *props[LAST_PROP]; static GParamSpec *props[LAST_PROP];
...@@ -35,7 +38,7 @@ typedef struct _PhoshProximity { ...@@ -35,7 +38,7 @@ typedef struct _PhoshProximity {
gboolean claimed; gboolean claimed;
PhoshSensorProxyManager *sensor_proxy_manager; PhoshSensorProxyManager *sensor_proxy_manager;
PhoshLockscreenManager *lockscreen_manager; PhoshCallsManager *calls_manager;
PhoshFader *fader; PhoshFader *fader;
} PhoshProximity; } PhoshProximity;
...@@ -119,8 +122,8 @@ on_has_proximity_changed (PhoshProximity *self, ...@@ -119,8 +122,8 @@ on_has_proximity_changed (PhoshProximity *self,
{ {
gboolean has_proximity; gboolean has_proximity;
/* Don't claim if locked to save power */ /* Don't claim if when no calls are active to save power */
if (phosh_lockscreen_manager_get_locked(self->lockscreen_manager)) if (!phosh_calls_manager_get_active_call (self->calls_manager))
return; return;
has_proximity = phosh_dbus_sensor_proxy_get_has_proximity ( has_proximity = phosh_dbus_sensor_proxy_get_has_proximity (
...@@ -130,17 +133,19 @@ on_has_proximity_changed (PhoshProximity *self, ...@@ -130,17 +133,19 @@ on_has_proximity_changed (PhoshProximity *self,
phosh_proximity_claim_proximity (self, has_proximity); phosh_proximity_claim_proximity (self, has_proximity);
} }
static void static void
on_lockscreen_manager_locked (PhoshProximity *self, GParamSpec *pspec, on_calls_manager_active_call_changed (PhoshProximity *self,
PhoshLockscreenManager *lockscreen_manager) GParamSpec *pspec,
PhoshCallsManager *calls_manager)
{ {
gboolean locked; gboolean active;
g_return_if_fail (PHOSH_IS_PROXIMITY (self)); g_return_if_fail (PHOSH_IS_PROXIMITY (self));
g_return_if_fail (PHOSH_IS_LOCKSCREEN_MANAGER (lockscreen_manager)); g_return_if_fail (PHOSH_IS_CALLS_MANAGER (calls_manager));
locked = phosh_lockscreen_manager_get_locked(self->lockscreen_manager); active = !!phosh_calls_manager_get_active_call(self->calls_manager);
phosh_proximity_claim_proximity (self, !locked); phosh_proximity_claim_proximity (self, active);
} }
...@@ -183,9 +188,9 @@ phosh_proximity_set_property (GObject *object, ...@@ -183,9 +188,9 @@ phosh_proximity_set_property (GObject *object,
/* construct only */ /* construct only */
self->sensor_proxy_manager = g_value_dup_object (value); self->sensor_proxy_manager = g_value_dup_object (value);
break; break;
case PROP_LOCKSCREEN_MANAGER: case PROP_CALLS_MANAGER:
/* construct only */ /* construct only */
self->lockscreen_manager = g_value_dup_object (value); self->calls_manager = g_value_dup_object (value);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
...@@ -206,8 +211,8 @@ phosh_proximity_get_property (GObject *object, ...@@ -206,8 +211,8 @@ phosh_proximity_get_property (GObject *object,
case PROP_SENSOR_PROXY_MANAGER: case PROP_SENSOR_PROXY_MANAGER:
g_value_set_object (value, self->sensor_proxy_manager); g_value_set_object (value, self->sensor_proxy_manager);
break; break;
case PROP_LOCKSCREEN_MANAGER: case PROP_CALLS_MANAGER:
g_value_set_object (value, self->lockscreen_manager); g_value_set_object (value, self->calls_manager);
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
...@@ -221,9 +226,9 @@ phosh_proximity_constructed (GObject *object) ...@@ -221,9 +226,9 @@ phosh_proximity_constructed (GObject *object)
{ {
PhoshProximity *self = PHOSH_PROXIMITY (object); PhoshProximity *self = PHOSH_PROXIMITY (object);
g_signal_connect_swapped (self->lockscreen_manager, g_signal_connect_swapped (self->calls_manager,
"notify::locked", "notify::active-call",
G_CALLBACK (on_lockscreen_manager_locked), G_CALLBACK (on_calls_manager_active_call_changed),
self); self);
g_signal_connect_swapped (self->sensor_proxy_manager, g_signal_connect_swapped (self->sensor_proxy_manager,
...@@ -254,10 +259,10 @@ phosh_proximity_dispose (GObject *object) ...@@ -254,10 +259,10 @@ phosh_proximity_dispose (GObject *object)
g_clear_object (&self->sensor_proxy_manager); g_clear_object (&self->sensor_proxy_manager);
} }
if (self->lockscreen_manager) { if (self->calls_manager) {
g_signal_handlers_disconnect_by_data (self->lockscreen_manager, g_signal_handlers_disconnect_by_data (self->calls_manager,
self); self);
g_clear_object (&self->lockscreen_manager); g_clear_object (&self->calls_manager);
} }
g_clear_pointer (&self->fader, phosh_cp_widget_destroy); g_clear_pointer (&self->fader, phosh_cp_widget_destroy);
...@@ -284,12 +289,12 @@ phosh_proximity_class_init (PhoshProximityClass *klass) ...@@ -284,12 +289,12 @@ phosh_proximity_class_init (PhoshProximityClass *klass)
PHOSH_TYPE_SENSOR_PROXY_MANAGER, PHOSH_TYPE_SENSOR_PROXY_MANAGER,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_LOCKSCREEN_MANAGER] = props[PROP_CALLS_MANAGER] =
g_param_spec_object ( g_param_spec_object (
"lockscreen-manager", "calls-manager",
"Lockscren manager", "",
"The object managing the lock screen", "",
PHOSH_TYPE_LOCKSCREEN_MANAGER, PHOSH_TYPE_CALLS_MANAGER,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, props); g_object_class_install_properties (object_class, LAST_PROP, props);
...@@ -305,10 +310,10 @@ phosh_proximity_init (PhoshProximity *self) ...@@ -305,10 +310,10 @@ phosh_proximity_init (PhoshProximity *self)
PhoshProximity * PhoshProximity *
phosh_proximity_new (PhoshSensorProxyManager *sensor_proxy_manager, phosh_proximity_new (PhoshSensorProxyManager *sensor_proxy_manager,
PhoshLockscreenManager *lockscreen_manager) PhoshCallsManager *calls_manager)
{ {
return g_object_new (PHOSH_TYPE_PROXIMITY, return g_object_new (PHOSH_TYPE_PROXIMITY,
"sensor-proxy-manager", sensor_proxy_manager, "sensor-proxy-manager", sensor_proxy_manager,
"lockscreen-manager", lockscreen_manager, "calls-manager", calls_manager,
NULL); NULL);
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#pragma once #pragma once
#include "lockscreen-manager.h" #include "calls-manager.h"
#include "sensor-proxy-manager.h" #include "sensor-proxy-manager.h"
G_BEGIN_DECLS G_BEGIN_DECLS
...@@ -16,6 +16,6 @@ G_BEGIN_DECLS ...@@ -16,6 +16,6 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (PhoshProximity, phosh_proximity, PHOSH, PROXIMITY, GObject); G_DECLARE_FINAL_TYPE (PhoshProximity, phosh_proximity, PHOSH, PROXIMITY, GObject);
PhoshProximity *phosh_proximity_new (PhoshSensorProxyManager *sensor_proxy_manager, PhoshProximity *phosh_proximity_new (PhoshSensorProxyManager *sensor_proxy_manager,
PhoshLockscreenManager *lockscreen_manager); PhoshCallsManager *calls_manager);
G_END_DECLS G_END_DECLS
...@@ -505,9 +505,10 @@ setup_idle_cb (PhoshShell *self) ...@@ -505,9 +505,10 @@ setup_idle_cb (PhoshShell *self)
G_CONNECT_SWAPPED); G_CONNECT_SWAPPED);
phosh_shell_get_location_manager (self); phosh_shell_get_location_manager (self);
priv->calls_manager = phosh_calls_manager_get_default ();
if (priv->sensor_proxy_manager) { if (priv->sensor_proxy_manager) {
priv->proximity = phosh_proximity_new (priv->sensor_proxy_manager, priv->proximity = phosh_proximity_new (priv->sensor_proxy_manager,
priv->lockscreen_manager); priv->calls_manager);
phosh_monitor_manager_set_sensor_proxy_manager (priv->monitor_manager, phosh_monitor_manager_set_sensor_proxy_manager (priv->monitor_manager,
priv->sensor_proxy_manager); priv->sensor_proxy_manager);
} }
...@@ -521,7 +522,6 @@ setup_idle_cb (PhoshShell *self) ...@@ -521,7 +522,6 @@ setup_idle_cb (PhoshShell *self)
priv->gnome_shell_manager = phosh_gnome_shell_manager_get_default (); priv->gnome_shell_manager = phosh_gnome_shell_manager_get_default ();
priv->screenshot_manager = phosh_screenshot_manager_new (); priv->screenshot_manager = phosh_screenshot_manager_new ();
priv->calls_manager = phosh_calls_manager_get_default ();
priv->startup_finished = TRUE; priv->startup_finished = TRUE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment