Compare commits

...

4 Commits

Author SHA1 Message Date
Carlos Garnacho
566e24d8a1 backends: Hook ClutterSeat::touch-mode to PanelOrientationManaged
We only want the panel autorotation to happen if the laptop has an
accelerometer, and is in tablet mode. Regular laptop mode should
lock the orientation, and let it be configured manually.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1311
2020-06-23 13:04:13 +02:00
Carlos Garnacho
a9cd81cb93 backends: Check panel autorotation state before applying autorotation
So far, we've expected this signal to not happen whenever autorotation
shouldn't apply (no accelerometer is a strong reason). In future commits
we'll add further checks to this policy, so prevent autorotation to
change the display configuration if the MetaOrientationManager signal
happens but it should be ignored.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1311
2020-06-23 13:04:13 +02:00
Carlos Garnacho
4bb880f8ac backends: Centralize panel autorotation in a DisplayConfig property
Instead of having everyone check net.hadess.SensorProxy themselves, have
this all controlled by the MetaOrientationManager, and proxied everywhere
else via a readonly property in org.gnome.Mutter.DisplayConfig.

We want to attach more complex policies here, and it seems better to
centralize the handling of the autorotation feature rather than
implementing policy changes all over the place.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1311
2020-06-23 13:04:13 +02:00
Carlos Garnacho
270892d9a6 backends: Add method/property to get accelerometer availability
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1311
2020-06-23 13:04:13 +02:00
7 changed files with 152 additions and 6 deletions

View File

@ -573,6 +573,8 @@ meta_backend_real_post_init (MetaBackend *backend)
reset_pointer_position (backend);
priv->is_pointer_position_initialized = TRUE;
}
meta_monitor_manager_post_init (priv->monitor_manager);
}
static gboolean

View File

@ -129,6 +129,8 @@ struct _MetaMonitorManager
int persistent_timeout_id;
guint panel_orientation_managed : 1;
MetaMonitorConfigManager *config_manager;
GnomePnpIds *pnp_ids;
@ -405,4 +407,6 @@ meta_find_output_assignment (MetaOutputAssignment **outputs,
return NULL;
}
void meta_monitor_manager_post_init (MetaMonitorManager *manager);
#endif /* META_MONITOR_MANAGER_PRIVATE_H */

View File

@ -67,6 +67,7 @@ enum
PROP_0,
PROP_BACKEND,
PROP_PANEL_ORIENTATION_MANAGED,
PROP_LAST
};
@ -684,6 +685,9 @@ orientation_changed (MetaOrientationManager *orientation_manager,
GError *error = NULL;
MetaMonitorsConfig *config;
if (!manager->panel_orientation_managed)
return;
switch (meta_orientation_manager_get_orientation (orientation_manager))
{
case META_ORIENTATION_NORMAL:
@ -748,6 +752,34 @@ experimental_features_changed (MetaSettings *settings,
meta_settings_update_ui_scaling_factor (settings);
}
static void
update_panel_orientation_managed (MetaMonitorManager *manager)
{
MetaOrientationManager *orientation_manager;
ClutterBackend *clutter_backend;
ClutterSeat *seat;
gboolean panel_orientation_managed;
clutter_backend = meta_backend_get_clutter_backend (manager->backend);
seat = clutter_backend_get_default_seat (clutter_backend);
orientation_manager = meta_backend_get_orientation_manager (manager->backend);
panel_orientation_managed =
(clutter_seat_get_touch_mode (seat) &&
meta_orientation_manager_has_accelerometer (orientation_manager));
if (manager->panel_orientation_managed == panel_orientation_managed)
return;
manager->panel_orientation_managed = panel_orientation_managed;
g_object_notify_by_pspec (G_OBJECT (manager),
obj_props[PROP_PANEL_ORIENTATION_MANAGED]);
meta_dbus_display_config_set_panel_orientation_managed (manager->display_config,
manager->panel_orientation_managed);
}
void
meta_monitor_manager_setup (MetaMonitorManager *manager)
{
@ -788,6 +820,11 @@ meta_monitor_manager_constructed (GObject *object)
G_CALLBACK (orientation_changed),
manager, 0);
g_signal_connect_object (meta_backend_get_orientation_manager (backend),
"notify::has-accelerometer",
G_CALLBACK (update_panel_orientation_managed), manager,
G_CONNECT_SWAPPED);
g_signal_connect_object (backend,
"lid-is-closed-changed",
G_CALLBACK (lid_is_closed_changed),
@ -848,6 +885,7 @@ meta_monitor_manager_set_property (GObject *object,
case PROP_BACKEND:
manager->backend = g_value_get_object (value);
break;
case PROP_PANEL_ORIENTATION_MANAGED:
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -866,6 +904,9 @@ meta_monitor_manager_get_property (GObject *object,
case PROP_BACKEND:
g_value_set_object (value, manager->backend);
break;
case PROP_PANEL_ORIENTATION_MANAGED:
g_value_set_boolean (value, manager->panel_orientation_managed);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@ -925,6 +966,15 @@ meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_props[PROP_PANEL_ORIENTATION_MANAGED] =
g_param_spec_boolean ("panel-orientation-managed",
"Panel orientation managed",
"Panel orientation is managed",
FALSE,
G_PARAM_READABLE |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
}
@ -3175,3 +3225,25 @@ meta_monitor_manager_get_vendor_name (MetaMonitorManager *manager,
return gnome_pnp_ids_get_pnp_id (manager->pnp_ids, vendor);
}
gboolean
meta_monitor_manager_get_panel_orientation_managed (MetaMonitorManager *manager)
{
g_return_val_if_fail (META_IS_MONITOR_MANAGER (manager), FALSE);
return manager->panel_orientation_managed;
}
void
meta_monitor_manager_post_init (MetaMonitorManager *manager)
{
ClutterBackend *clutter_backend;
ClutterSeat *seat;
clutter_backend = meta_backend_get_clutter_backend (manager->backend);
seat = clutter_backend_get_default_seat (clutter_backend);
g_signal_connect_object (seat, "notify::touch-mode",
G_CALLBACK (update_panel_orientation_managed), manager,
G_CONNECT_SWAPPED);
}

View File

@ -34,6 +34,17 @@ enum
static guint signals[N_SIGNALS];
enum
{
PROP_0,
PROP_HAS_ACCELEROMETER,
PROP_LAST
};
static GParamSpec *props[PROP_LAST];
struct _MetaOrientationManager
{
GObject parent_instance;
@ -44,6 +55,7 @@ struct _MetaOrientationManager
GDBusProxy *iio_proxy;
MetaOrientation prev_orientation;
MetaOrientation curr_orientation;
guint has_accel : 1;
GSettings *settings;
};
@ -71,22 +83,24 @@ orientation_from_string (const char *orientation)
static void
read_iio_proxy (MetaOrientationManager *self)
{
gboolean has_accel = FALSE;
GVariant *v;
self->curr_orientation = META_ORIENTATION_UNDEFINED;
if (!self->iio_proxy)
return;
{
self->has_accel = FALSE;
return;
}
v = g_dbus_proxy_get_cached_property (self->iio_proxy, "HasAccelerometer");
if (v)
{
has_accel = g_variant_get_boolean (v);
self->has_accel = !!g_variant_get_boolean (v);
g_variant_unref (v);
}
if (has_accel)
if (self->has_accel)
{
v = g_dbus_proxy_get_cached_property (self->iio_proxy, "AccelerometerOrientation");
if (v)
@ -100,11 +114,16 @@ read_iio_proxy (MetaOrientationManager *self)
static void
sync_state (MetaOrientationManager *self)
{
if (g_settings_get_boolean (self->settings, ORIENTATION_LOCK_KEY))
return;
gboolean had_accel = self->has_accel;
read_iio_proxy (self);
if (had_accel != self->has_accel)
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HAS_ACCELEROMETER]);
if (g_settings_get_boolean (self->settings, ORIENTATION_LOCK_KEY))
return;
if (self->prev_orientation == self->curr_orientation)
return;
@ -241,6 +260,25 @@ meta_orientation_manager_init (MetaOrientationManager *self)
sync_state (self);
}
static void
meta_orientation_manager_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MetaOrientationManager *self = META_ORIENTATION_MANAGER (object);
switch (prop_id)
{
case PROP_HAS_ACCELEROMETER:
g_value_set_boolean (value, self->has_accel);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_orientation_manager_finalize (GObject *object)
{
@ -263,6 +301,7 @@ meta_orientation_manager_class_init (MetaOrientationManagerClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = meta_orientation_manager_finalize;
gobject_class->get_property = meta_orientation_manager_get_property;
signals[ORIENTATION_CHANGED] =
g_signal_new ("orientation-changed",
@ -271,6 +310,16 @@ meta_orientation_manager_class_init (MetaOrientationManagerClass *klass)
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
props[PROP_HAS_ACCELEROMETER] =
g_param_spec_boolean ("has-accelerometer",
"Has accelerometer",
"Has accelerometer",
FALSE,
G_PARAM_READABLE |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, PROP_LAST, props);
}
MetaOrientation
@ -278,3 +327,9 @@ meta_orientation_manager_get_orientation (MetaOrientationManager *self)
{
return self->curr_orientation;
}
gboolean
meta_orientation_manager_has_accelerometer (MetaOrientationManager *self)
{
return self->has_accel;
}

View File

@ -39,4 +39,6 @@ G_DECLARE_FINAL_TYPE (MetaOrientationManager, meta_orientation_manager,
MetaOrientation meta_orientation_manager_get_orientation (MetaOrientationManager *self);
gboolean meta_orientation_manager_has_accelerometer (MetaOrientationManager *self);
#endif /* META_ORIENTATION_MANAGER_H */

View File

@ -62,4 +62,7 @@ MetaMonitorSwitchConfigType meta_monitor_manager_get_switch_config (MetaMonitorM
META_EXPORT
gint meta_monitor_manager_get_display_configuration_timeout (void);
META_EXPORT
gboolean meta_monitor_manager_get_panel_orientation_managed (MetaMonitorManager *manager);
#endif /* META_MONITOR_MANAGER_H */

View File

@ -282,6 +282,14 @@
-->
<property name="PowerSaveMode" type="i" access="readwrite" />
<!--
PanelOrientationManaged:
Whether the built-in panel orientation is automatically managed
by mutter.
-->
<property name="PanelOrientationManaged" type="b" access="read" />
<!--
MonitorsChanged: