[gnome-flashback] monitor-config-store: allow changing D-Bus configuration policy
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] monitor-config-store: allow changing D-Bus configuration policy
- Date: Mon, 7 Mar 2022 20:15:56 +0000 (UTC)
commit c405b17780cbbc6f9ef9c05de59e3388ea048d59
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Mar 7 19:50:16 2022 +0200
monitor-config-store: allow changing D-Bus configuration policy
Adding a <dbus/> element containing a boolean (yes/no) determines
whether org.gnome.Mutter.DisplayConfig ApplyMonitorsConfig will be
callable. The state is also introspectable via the
ApplyMonitorsConfigAllowed property on the same interface.
For example
<monitors version="2">
<policy>
<dbus>no</dbus>
</policy>
</monitors>
Based on mutter commit:
https://gitlab.gnome.org/GNOME/mutter/-/commit/b49421d8e8c73447872de571620649309e774708#0af849d1b55c8cda122fef9c39eefc5e733c4436
backends/gf-monitor-config-store-private.h | 37 +++++++-----
backends/gf-monitor-config-store.c | 90 +++++++++++++++++++++++++----
backends/gf-monitor-manager.c | 22 +++++++
backends/org.gnome.Mutter.DisplayConfig.xml | 7 +++
4 files changed, 131 insertions(+), 25 deletions(-)
---
diff --git a/backends/gf-monitor-config-store-private.h b/backends/gf-monitor-config-store-private.h
index be4bff0..5c866dd 100644
--- a/backends/gf-monitor-config-store-private.h
+++ b/backends/gf-monitor-config-store-private.h
@@ -26,32 +26,39 @@
G_BEGIN_DECLS
+typedef struct
+{
+ gboolean enable_dbus;
+} GfMonitorConfigPolicy;
+
#define GF_TYPE_MONITOR_CONFIG_STORE (gf_monitor_config_store_get_type ())
G_DECLARE_FINAL_TYPE (GfMonitorConfigStore, gf_monitor_config_store,
GF, MONITOR_CONFIG_STORE, GObject)
-GfMonitorConfigStore *gf_monitor_config_store_new (GfMonitorManager *monitor_manager);
+GfMonitorConfigStore *gf_monitor_config_store_new (GfMonitorManager
*monitor_manager);
+
+GfMonitorsConfig *gf_monitor_config_store_lookup (GfMonitorConfigStore
*config_store,
+ GfMonitorsConfigKey *key);
-GfMonitorsConfig *gf_monitor_config_store_lookup (GfMonitorConfigStore *config_store,
- GfMonitorsConfigKey *key);
+void gf_monitor_config_store_add (GfMonitorConfigStore
*config_store,
+ GfMonitorsConfig *config);
-void gf_monitor_config_store_add (GfMonitorConfigStore *config_store,
- GfMonitorsConfig *config);
+void gf_monitor_config_store_remove (GfMonitorConfigStore
*config_store,
+ GfMonitorsConfig *config);
-void gf_monitor_config_store_remove (GfMonitorConfigStore *config_store,
- GfMonitorsConfig *config);
+gboolean gf_monitor_config_store_set_custom (GfMonitorConfigStore
*config_store,
+ const gchar *read_path,
+ const gchar *write_path,
+ GfMonitorsConfigFlag flags,
+ GError **error);
-gboolean gf_monitor_config_store_set_custom (GfMonitorConfigStore *config_store,
- const gchar *read_path,
- const gchar *write_path,
- GfMonitorsConfigFlag flags,
- GError **error);
+gint gf_monitor_config_store_get_config_count (GfMonitorConfigStore
*config_store);
-gint gf_monitor_config_store_get_config_count (GfMonitorConfigStore *config_store);
+GfMonitorManager *gf_monitor_config_store_get_monitor_manager (GfMonitorConfigStore
*config_store);
-GfMonitorManager *gf_monitor_config_store_get_monitor_manager (GfMonitorConfigStore *config_store);
+void gf_monitor_config_store_reset (GfMonitorConfigStore
*config_store);
-void gf_monitor_config_store_reset (GfMonitorConfigStore *config_store);
+const GfMonitorConfigPolicy *gf_monitor_config_store_get_policy (GfMonitorConfigStore
*config_store);
G_END_DECLS
diff --git a/backends/gf-monitor-config-store.c b/backends/gf-monitor-config-store.c
index 63d2b02..2bb0aa5 100644
--- a/backends/gf-monitor-config-store.c
+++ b/backends/gf-monitor-config-store.c
@@ -100,20 +100,23 @@
struct _GfMonitorConfigStore
{
- GObject parent;
+ GObject parent;
- GfMonitorManager *monitor_manager;
+ GfMonitorManager *monitor_manager;
- GHashTable *configs;
+ GHashTable *configs;
- GCancellable *save_cancellable;
+ GCancellable *save_cancellable;
- GFile *user_file;
- GFile *custom_read_file;
- GFile *custom_write_file;
+ GFile *user_file;
+ GFile *custom_read_file;
+ GFile *custom_write_file;
- gboolean has_stores_policy;
- GList *stores_policy;
+ gboolean has_stores_policy;
+ GList *stores_policy;
+
+ gboolean has_dbus_policy;
+ GfMonitorConfigPolicy policy;
};
enum
@@ -158,7 +161,8 @@ typedef enum
STATE_DISABLED,
STATE_POLICY,
STATE_STORES,
- STATE_STORE
+ STATE_STORE,
+ STATE_DBUS
} ParserState;
typedef enum
@@ -190,9 +194,13 @@ typedef struct
gboolean seen_policy;
gboolean seen_stores;
+ gboolean seen_dbus;
GfConfigStore pending_store;
GList *stores;
+ gboolean enable_dbus_set;
+ gboolean enable_dbus;
+
ParserState unknown_state_root;
int unknown_level;
@@ -619,6 +627,19 @@ handle_start_element (GMarkupParseContext *context,
parser->seen_stores = TRUE;
parser->state = STATE_STORES;
}
+ else if (g_str_equal (element_name, "dbus"))
+ {
+ if (parser->seen_dbus)
+ {
+ g_set_error (error,
+ G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ "Multiple dbus elements under policy");
+ return;
+ }
+
+ parser->seen_dbus = TRUE;
+ parser->state = STATE_DBUS;
+ }
else
{
enter_unknown_element (parser,
@@ -654,6 +675,13 @@ handle_start_element (GMarkupParseContext *context,
return;
}
+ case STATE_DBUS:
+ {
+ g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+ "Invalid dbus sub element '%s'", element_name);
+ return;
+ }
+
default:
break;
}
@@ -766,6 +794,7 @@ finish_monitor_spec (ConfigParser *parser)
case STATE_POLICY:
case STATE_STORES:
case STATE_STORE:
+ case STATE_DBUS:
default:
g_assert_not_reached ();
break;
@@ -1029,6 +1058,23 @@ handle_end_element (GMarkupParseContext *context,
parser->state = STATE_POLICY;
return;
+ case STATE_DBUS:
+ if (!parser->config_store->has_dbus_policy)
+ {
+ parser->config_store->has_dbus_policy = TRUE;
+ parser->config_store->policy.enable_dbus = parser->enable_dbus;
+ parser->enable_dbus_set = FALSE;
+ }
+ else
+ {
+ g_warning ("Policy for monitor configuration via D-Bus "
+ "has already been set, ignoring policy from '%s'",
+ g_file_get_path (parser->file));
+ }
+
+ parser->state = STATE_POLICY;
+ return;
+
case STATE_POLICY:
g_assert (g_str_equal (element_name, "policy"));
@@ -1362,6 +1408,15 @@ handle_text (GMarkupParseContext *context,
return;
}
+ case STATE_DBUS:
+ {
+ parser->enable_dbus_set = TRUE;
+ read_bool (text, text_len,
+ &parser->enable_dbus,
+ error);
+ return;
+ }
+
default:
break;
}
@@ -1731,6 +1786,11 @@ gf_monitor_config_store_save (GfMonitorConfigStore *config_store)
return;
}
+ if (config_store->has_stores_policy &&
+ !g_list_find (config_store->stores_policy,
+ GINT_TO_POINTER (GF_CONFIG_STORE_USER)))
+ return;
+
config_store->save_cancellable = g_cancellable_new ();
buffer = generate_config_xml (config_store);
@@ -1875,6 +1935,8 @@ gf_monitor_config_store_init (GfMonitorConfigStore *config_store)
config_store->configs = g_hash_table_new_full (gf_monitors_config_key_hash,
gf_monitors_config_key_equal,
NULL, g_object_unref);
+
+ config_store->policy.enable_dbus = TRUE;
}
GfMonitorConfigStore *
@@ -1932,6 +1994,8 @@ gf_monitor_config_store_set_custom (GfMonitorConfigStore *config_store,
g_clear_pointer (&config_store->stores_policy, g_list_free);
config_store->has_stores_policy = FALSE;
+ config_store->policy.enable_dbus = TRUE;
+ config_store->has_dbus_policy = FALSE;
if (!read_config_file (config_store,
config_store->custom_read_file,
@@ -2089,3 +2153,9 @@ gf_monitor_config_store_reset (GfMonitorConfigStore *config_store)
g_clear_pointer (&user_configs, g_hash_table_unref);
g_free (user_file_path);
}
+
+const GfMonitorConfigPolicy *
+gf_monitor_config_store_get_policy (GfMonitorConfigStore *config_store)
+{
+ return &config_store->policy;
+}
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index 969ac0d..eb41ce3 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -33,6 +33,7 @@
#include "gf-crtc-private.h"
#include "gf-logical-monitor-private.h"
#include "gf-monitor-config-manager-private.h"
+#include "gf-monitor-config-store-private.h"
#include "gf-monitor-manager-private.h"
#include "gf-monitor-normal-private.h"
#include "gf-monitor-private.h"
@@ -1989,6 +1990,8 @@ gf_monitor_manager_handle_apply_monitors_config (GfDBusDisplayConfig *skeleton
GVariant *properties_variant,
GfMonitorManager *manager)
{
+ GfMonitorConfigStore *config_store;
+ const GfMonitorConfigPolicy *policy;
GfMonitorManagerCapability capabilities;
GVariant *layout_mode_variant;
GfLogicalMonitorLayoutMode layout_mode;
@@ -2005,6 +2008,17 @@ gf_monitor_manager_handle_apply_monitors_config (GfDBusDisplayConfig *skeleton
return TRUE;
}
+ config_store = gf_monitor_config_manager_get_store (manager->config_manager);
+ policy = gf_monitor_config_store_get_policy (config_store);
+
+ if (!policy->enable_dbus)
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
+ G_DBUS_ERROR_ACCESS_DENIED,
+ "Monitor configuration via D-Bus is disabled");
+ return TRUE;
+ }
+
capabilities = gf_monitor_manager_get_capabilities (manager);
layout_mode_variant = NULL;
logical_monitor_configs = NULL;
@@ -2465,6 +2479,8 @@ gf_monitor_manager_setup (GfMonitorManager *manager)
{
GfMonitorManagerPrivate *priv;
GfMonitorManagerClass *manager_class;
+ GfMonitorConfigStore *config_store;
+ const GfMonitorConfigPolicy *policy;
priv = gf_monitor_manager_get_instance_private (manager);
manager_class = GF_MONITOR_MANAGER_GET_CLASS (manager);
@@ -2476,6 +2492,12 @@ gf_monitor_manager_setup (GfMonitorManager *manager)
gf_monitor_manager_read_current_state (manager);
manager_class->ensure_initial_config (manager);
+ config_store = gf_monitor_config_manager_get_store (manager->config_manager);
+ policy = gf_monitor_config_store_get_policy (config_store);
+
+ gf_dbus_display_config_set_apply_monitors_config_allowed (manager->display_config,
+ policy->enable_dbus);
+
priv->in_init = FALSE;
}
diff --git a/backends/org.gnome.Mutter.DisplayConfig.xml b/backends/org.gnome.Mutter.DisplayConfig.xml
index 1c6f05b..d0afd23 100644
--- a/backends/org.gnome.Mutter.DisplayConfig.xml
+++ b/backends/org.gnome.Mutter.DisplayConfig.xml
@@ -231,6 +231,13 @@
-->
<property name="PanelOrientationManaged" type="b" access="read" />
+ <!--
+ ApplyMonitorsConfigAllowed:
+
+ Whether calling the ApplyMonitorsConfig method is allowed.
+ -->
+ <property name="ApplyMonitorsConfigAllowed" type="b" access="read" />
+
<!--
MonitorsChanged:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]