backend: Check if the gsettings scheme exists

Mutter makes use of a gsettings scheme that comes from
gnome-settings-daemon to check for the screen orientation.
In use cases where gnome-settings-daemon is not available,
this would lead to a crash as the key doesn't exists

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2398>
This commit is contained in:
Bilal Elmoussaoui 2022-05-03 12:40:13 +02:00
parent 8fdb80a718
commit c861101ae6

View File

@ -122,7 +122,8 @@ sync_state (MetaOrientationManager *self)
if (had_accel != self->has_accel) if (had_accel != self->has_accel)
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HAS_ACCELEROMETER]); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HAS_ACCELEROMETER]);
if (g_settings_get_boolean (self->settings, ORIENTATION_LOCK_KEY)) if (self->settings != NULL &&
g_settings_get_boolean (self->settings, ORIENTATION_LOCK_KEY))
return; return;
if (self->prev_orientation == self->curr_orientation) if (self->prev_orientation == self->curr_orientation)
@ -273,6 +274,8 @@ iio_sensor_vanished_cb (GDBusConnection *connection,
static void static void
meta_orientation_manager_init (MetaOrientationManager *self) meta_orientation_manager_init (MetaOrientationManager *self)
{ {
GSettingsSchemaSource *schema_source = g_settings_schema_source_get_default ();
self->iio_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM, self->iio_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
"net.hadess.SensorProxy", "net.hadess.SensorProxy",
G_BUS_NAME_WATCHER_FLAGS_NONE, G_BUS_NAME_WATCHER_FLAGS_NONE,
@ -281,11 +284,14 @@ meta_orientation_manager_init (MetaOrientationManager *self)
self, self,
NULL); NULL);
if (g_settings_schema_source_lookup (schema_source, CONF_SCHEMA, TRUE))
{
self->settings = g_settings_new (CONF_SCHEMA); self->settings = g_settings_new (CONF_SCHEMA);
g_signal_connect_object (self->settings, "changed::"ORIENTATION_LOCK_KEY, g_signal_connect_object (self->settings, "changed::"ORIENTATION_LOCK_KEY,
G_CALLBACK (orientation_lock_changed), self, 0); G_CALLBACK (orientation_lock_changed), self, 0);
sync_state (self); sync_state (self);
} }
}
static void static void
meta_orientation_manager_get_property (GObject *object, meta_orientation_manager_get_property (GObject *object,