[gnome-builder/wip/gtk4-port] libide/foundry: implement toggle for high-contrast



commit 6652bc444855ad8d31d0799441faf10a2761de96
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 27 12:44:49 2022 -0700

    libide/foundry: implement toggle for high-contrast
    
    This just leaves us a way to get RTL/LTR for now.
    
    Related #935

 src/libide/foundry/ide-run-manager.c | 44 ++++++++++++++++++++++++++++++++++++
 src/plugins/buildui/gtk/menus.ui     |  2 +-
 2 files changed, 45 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/foundry/ide-run-manager.c b/src/libide/foundry/ide-run-manager.c
index 64f5cd9a0..b78f30306 100644
--- a/src/libide/foundry/ide-run-manager.c
+++ b/src/libide/foundry/ide-run-manager.c
@@ -101,6 +101,8 @@ static void ide_run_manager_actions_default_run_command (IdeRunManager  *self,
                                                          GVariant       *param);
 static void ide_run_manager_actions_color_scheme        (IdeRunManager  *self,
                                                          GVariant       *param);
+static void ide_run_manager_actions_high_contrast       (IdeRunManager  *self,
+                                                         GVariant       *param);
 
 IDE_DEFINE_ACTION_GROUP (IdeRunManager, ide_run_manager, {
   { "run", ide_run_manager_actions_run },
@@ -109,6 +111,7 @@ IDE_DEFINE_ACTION_GROUP (IdeRunManager, ide_run_manager, {
   { "messages-debug-all", ide_run_manager_actions_messages_debug_all, NULL, "false" },
   { "default-run-command", ide_run_manager_actions_default_run_command, "s", "''" },
   { "color-scheme", ide_run_manager_actions_color_scheme, "s", "'follow'" },
+  { "high-contrast", ide_run_manager_actions_high_contrast, NULL, "false" },
 })
 
 G_DEFINE_TYPE_EXTENDED (IdeRunManager, ide_run_manager, IDE_TYPE_OBJECT, G_TYPE_FLAG_FINAL,
@@ -144,6 +147,20 @@ discover_state_free (gpointer data)
   g_slice_free (DiscoverState, state);
 }
 
+static void
+ide_run_manager_actions_high_contrast (IdeRunManager *self,
+                                       GVariant      *param)
+{
+  GVariant *state;
+
+  g_assert (IDE_IS_RUN_MANAGER (self));
+
+  state = ide_run_manager_get_action_state (self, "high-contrast");
+  ide_run_manager_set_action_state (self,
+                                    "high-contrast",
+                                    g_variant_new_boolean (!g_variant_get_boolean (state)));
+}
+
 static void
 ide_run_manager_actions_color_scheme (IdeRunManager *self,
                                       GVariant      *param)
@@ -574,6 +591,24 @@ apply_color_scheme (IdeEnvironment *env,
   IDE_EXIT;
 }
 
+static void
+apply_high_contrast (IdeEnvironment *env,
+                     gboolean        high_contrast)
+{
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_ENVIRONMENT (env));
+
+  g_debug ("Applying high-contrast %d", high_contrast);
+
+  if (high_contrast)
+    ide_environment_setenv (env, "ADW_DEBUG_HIGH_CONTRAST", "1");
+  else
+    ide_environment_setenv (env, "ADW_DEBUG_HIGH_CONTRAST", NULL);
+
+  IDE_EXIT;
+}
+
 static inline const char *
 get_action_state_string (IdeRunManager *self,
                          const char    *action_name)
@@ -582,6 +617,14 @@ get_action_state_string (IdeRunManager *self,
   return g_variant_get_string (state, NULL);
 }
 
+static inline gboolean
+get_action_state_bool (IdeRunManager *self,
+                       const char    *action_name)
+{
+  GVariant *state = ide_run_manager_get_action_state (self, action_name);
+  return g_variant_get_boolean (state);
+}
+
 static void
 create_runner_cb (GObject      *object,
                   GAsyncResult *result,
@@ -673,6 +716,7 @@ create_runner_cb (GObject      *object,
   /* Add debugging overrides */
   color_scheme = get_action_state_string (self, "color-scheme");
   apply_color_scheme (environment, color_scheme);
+  apply_high_contrast (environment, get_action_state_bool (self, "high-contrast"));
 
   g_signal_emit (self, signals [RUN], 0, runner);
 
diff --git a/src/plugins/buildui/gtk/menus.ui b/src/plugins/buildui/gtk/menus.ui
index 3ec86fe5d..ad877a46f 100644
--- a/src/plugins/buildui/gtk/menus.ui
+++ b/src/plugins/buildui/gtk/menus.ui
@@ -154,7 +154,7 @@
         <item>
           <attribute name="label" translatable="yes">High Contrast</attribute>
           <attribute name="role">check</attribute>
-          <attribute name="action">runui.high-contrast</attribute>
+          <attribute name="action">run-manager.high-contrast</attribute>
         </item>
         <item>
           <attribute name="label" translatable="yes">Right-to-Left</attribute>


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