[mutter] monitor-config-store: Add parsing support for "maxbpc" in monitors.xml



commit 03336788fb079cb8aa203e031f85d039a87832ce
Author: Daniel van Vugt <daniel van vugt canonical com>
Date:   Thu Jun 9 18:50:52 2022 +0800

    monitor-config-store: Add parsing support for "maxbpc" in monitors.xml
    
    For example:
    
      <monitor>
        ...
        <maxbpc>8</maxbpc>
      </monitor>
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2412>

 src/backends/meta-monitor-config-store.c | 49 ++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
---
diff --git a/src/backends/meta-monitor-config-store.c b/src/backends/meta-monitor-config-store.c
index 4f6d03d670..377d8debf0 100644
--- a/src/backends/meta-monitor-config-store.c
+++ b/src/backends/meta-monitor-config-store.c
@@ -167,6 +167,7 @@ typedef enum
   STATE_MONITOR_MODE_RATE,
   STATE_MONITOR_MODE_FLAG,
   STATE_MONITOR_UNDERSCANNING,
+  STATE_MONITOR_MAXBPC,
   STATE_DISABLED,
   STATE_POLICY,
   STATE_STORES,
@@ -451,6 +452,10 @@ handle_start_element (GMarkupParseContext  *context,
           {
             parser->state = STATE_MONITOR_UNDERSCANNING;
           }
+        else if (g_str_equal (element_name, "maxbpc"))
+          {
+            parser->state = STATE_MONITOR_MAXBPC;
+          }
         else
           {
             g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
@@ -544,6 +549,13 @@ handle_start_element (GMarkupParseContext  *context,
         return;
       }
 
+    case STATE_MONITOR_MAXBPC:
+      {
+        g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
+                     "Invalid element '%s' under maxbpc", element_name);
+        return;
+      }
+
     case STATE_DISABLED:
       {
         if (!g_str_equal (element_name, "monitorspec"))
@@ -818,6 +830,14 @@ handle_end_element (GMarkupParseContext  *context,
         return;
       }
 
+    case STATE_MONITOR_MAXBPC:
+      {
+        g_assert (g_str_equal (element_name, "maxbpc"));
+
+        parser->state = STATE_MONITOR;
+        return;
+      }
+
     case STATE_MONITOR:
       {
         MetaLogicalMonitorConfig *logical_monitor_config;
@@ -1309,6 +1329,29 @@ handle_text (GMarkupParseContext *context,
         return;
       }
 
+    case STATE_MONITOR_MAXBPC:
+      {
+        int signed_max_bpc;
+
+        if (read_int (text, text_len, &signed_max_bpc, error))
+          {
+            if (signed_max_bpc >= 0)
+              {
+                parser->current_monitor_config->has_max_bpc = TRUE;
+                parser->current_monitor_config->max_bpc = signed_max_bpc;
+              }
+            else
+              {
+                g_set_error (error, G_MARKUP_ERROR,
+                             G_MARKUP_ERROR_INVALID_CONTENT,
+                             "Invalid negative maxbpc value \"%s\"",
+                             text);
+              }
+          }
+
+        return;
+      }
+
     case STATE_STORE:
       {
         MetaConfigStore store;
@@ -1480,6 +1523,12 @@ append_monitors (GString *buffer,
       g_string_append (buffer, "        </mode>\n");
       if (monitor_config->enable_underscanning)
         g_string_append (buffer, "        <underscanning>yes</underscanning>\n");
+
+      if (monitor_config->has_max_bpc)
+        {
+          g_string_append_printf (buffer, "        <maxbpc>%u</maxbpc>\n",
+                                  monitor_config->max_bpc);
+        }
       g_string_append (buffer, "      </monitor>\n");
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]