[gnome-flashback] shell: fix monitor labels



commit 688cccd33fba41e6fea99dcbabe2bd65b876bd13
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Sep 28 19:12:43 2017 +0300

    shell: fix monitor labels

 gnome-flashback/gf-application.c                   |    4 +-
 gnome-flashback/libshell/Makefile.am               |    2 +-
 .../libshell/flashback-monitor-labeler.c           |  104 +++++++++++++++++++-
 .../libshell/flashback-monitor-labeler.h           |   24 +++--
 gnome-flashback/libshell/flashback-shell.c         |   36 ++++++-
 gnome-flashback/libshell/flashback-shell.h         |    9 +-
 gnome-flashback/libshell/org.gnome.Shell.xml       |    3 +
 7 files changed, 157 insertions(+), 25 deletions(-)
---
diff --git a/gnome-flashback/gf-application.c b/gnome-flashback/gf-application.c
index 2e45d0b..df366e0 100644
--- a/gnome-flashback/gf-application.c
+++ b/gnome-flashback/gf-application.c
@@ -136,8 +136,10 @@ settings_changed (GSettings   *settings,
                   gpointer     user_data)
 {
   GfApplication *application;
+  GfMonitorManager *monitor_manager;
 
   application = GF_APPLICATION (user_data);
+  monitor_manager = gf_backend_get_monitor_manager (application->backend);
 
 #define SETTING_CHANGED(variable_name, setting_name, function_name) \
   if (key == NULL || g_strcmp0 (key, setting_name) == 0)            \
@@ -180,7 +182,7 @@ settings_changed (GSettings   *settings,
                                           application->config);
 
   if (application->shell)
-    flashback_shell_set_display_config (application->shell, application->config);
+    flashback_shell_set_monitor_manager (application->shell, monitor_manager);
 }
 
 static void
diff --git a/gnome-flashback/libshell/Makefile.am b/gnome-flashback/libshell/Makefile.am
index d23df02..688c4bc 100644
--- a/gnome-flashback/libshell/Makefile.am
+++ b/gnome-flashback/libshell/Makefile.am
@@ -8,9 +8,9 @@ libshell_la_CPPFLAGS = \
        -DG_LOG_DOMAIN=\"shell\" \
        -DG_LOG_USE_STRUCTURED=1 \
        -I$(top_builddir)/gnome-flashback/libcommon \
-       -I$(top_builddir)/gnome-flashback/libdisplay-config \
        -I$(top_builddir)/gnome-flashback/libshell \
        -I$(top_srcdir)/gnome-flashback \
+       -I$(top_srcdir) \
        $(NULL)
 
 libshell_la_CFLAGS = \
diff --git a/gnome-flashback/libshell/flashback-monitor-labeler.c 
b/gnome-flashback/libshell/flashback-monitor-labeler.c
index 3d74d24..78aaf66 100644
--- a/gnome-flashback/libshell/flashback-monitor-labeler.c
+++ b/gnome-flashback/libshell/flashback-monitor-labeler.c
@@ -180,7 +180,7 @@ flashback_monitor_labeler_new (void)
 
 void
 flashback_monitor_labeler_show (FlashbackMonitorLabeler *labeler,
-                                FlashbackMonitorManager *manager,
+                                GfMonitorManager        *monitor_manager,
                                 const gchar             *sender,
                                 GVariant                *params)
 {
@@ -223,7 +223,107 @@ flashback_monitor_labeler_show (FlashbackMonitorLabeler *labeler,
 
       g_variant_get (v, "i", &number);
 
-      monitor = flashback_monitor_manager_get_monitor_for_output (manager, id);
+      monitor = gf_monitor_manager_get_monitor_for_output (monitor_manager, id);
+
+      if (monitor != -1)
+        {
+          GSList *list;
+          gboolean insert;
+
+          list = (GSList *) g_hash_table_lookup (monitors, GINT_TO_POINTER (monitor));
+          insert = (list == NULL);
+
+          list = g_slist_append (list, GINT_TO_POINTER (number));
+
+          if (insert)
+            g_hash_table_insert (monitors, GINT_TO_POINTER (monitor), list);
+        }
+
+      g_variant_unref (v);
+    }
+
+  keys = g_hash_table_get_keys (monitors);
+
+  labeler->n_windows = g_hash_table_size (monitors);
+  labeler->windows = g_new0 (GfLabelWindow *, labeler->n_windows);
+  i = 0;
+
+  for (key = keys; key; key = key->next)
+    {
+      GSList *labels;
+      GSList *label;
+      GString *string;
+      gchar *real_label;
+
+      labels = (GSList *) g_hash_table_lookup (monitors, key->data);
+      string = g_string_new ("");
+
+      for (label = labels; label; label = label->next)
+        g_string_append_printf (string, "%d ", GPOINTER_TO_INT (label->data));
+      g_string_set_size (string, string->len - 1);
+
+      g_slist_free (labels);
+
+      real_label = g_string_free (string, FALSE);
+      labeler->windows[i] = gf_label_window_new (GPOINTER_TO_INT (key->data),
+                                                 real_label);
+      g_free (real_label);
+
+      gf_label_window_show (labeler->windows[i]);
+
+      i++;
+    }
+
+  g_list_free (keys);
+  g_hash_table_destroy (monitors);
+}
+
+void
+flashback_monitor_labeler_show2 (FlashbackMonitorLabeler *labeler,
+                                 GfMonitorManager        *monitor_manager,
+                                 const gchar             *sender,
+                                 GVariant                *params)
+{
+  GVariantIter iter;
+  const gchar *connector;
+  gint number;
+  GVariant *v;
+  GHashTable *monitors;
+  GList *keys;
+  GList *key;
+  gint i;
+
+  if (labeler->hide_id > 0)
+    {
+      g_source_remove (labeler->hide_id);
+      labeler->hide_id = 0;
+    }
+
+  if (!track_client (labeler, sender))
+    return;
+
+  if (labeler->windows != NULL)
+    return;
+
+  /*if (labeler->windows != NULL)
+    {
+      for (i = 0; i < labeler->n_windows; i++)
+        gtk_widget_destroy (GTK_WIDGET (labeler->windows[i]));
+      g_free (labeler->windows);
+      labeler->windows = NULL;
+    }*/
+
+  g_variant_iter_init (&iter, params);
+
+  monitors = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+  while (g_variant_iter_next (&iter, "{&sv}", &connector, &v))
+    {
+      gint monitor;
+
+      g_variant_get (v, "i", &number);
+
+      monitor = gf_monitor_manager_get_monitor_for_connector (monitor_manager, connector);
 
       if (monitor != -1)
         {
diff --git a/gnome-flashback/libshell/flashback-monitor-labeler.h 
b/gnome-flashback/libshell/flashback-monitor-labeler.h
index de5f454..c7c8fda 100644
--- a/gnome-flashback/libshell/flashback-monitor-labeler.h
+++ b/gnome-flashback/libshell/flashback-monitor-labeler.h
@@ -18,24 +18,28 @@
 #ifndef FLASHBACK_MONITOR_LABELER_H
 #define FLASHBACK_MONITOR_LABELER_H
 
-#include <glib-object.h>
+#include "flashback-shell.h"
 
 G_BEGIN_DECLS
 
-typedef struct _FlashbackMonitorManager FlashbackMonitorManager;
-
 #define FLASHBACK_TYPE_MONITOR_LABELER flashback_monitor_labeler_get_type ()
 G_DECLARE_FINAL_TYPE (FlashbackMonitorLabeler, flashback_monitor_labeler,
                       FLASHBACK, MONITOR_LABELER, GObject)
 
-FlashbackMonitorLabeler *flashback_monitor_labeler_new  (void);
+FlashbackMonitorLabeler *flashback_monitor_labeler_new   (void);
+
+void                     flashback_monitor_labeler_show  (FlashbackMonitorLabeler *labeler,
+                                                          GfMonitorManager        *monitor_manager,
+                                                          const gchar             *sender,
+                                                          GVariant                *params);
+
+void                     flashback_monitor_labeler_show2 (FlashbackMonitorLabeler *labeler,
+                                                          GfMonitorManager        *monitor_manager,
+                                                          const gchar             *sender,
+                                                          GVariant                *params);
 
-void                     flashback_monitor_labeler_show (FlashbackMonitorLabeler *labeler,
-                                                         FlashbackMonitorManager *manager,
-                                                         const gchar             *sender,
-                                                         GVariant                *params);
-void                     flashback_monitor_labeler_hide (FlashbackMonitorLabeler *labeler,
-                                                         const gchar             *sender);
+void                     flashback_monitor_labeler_hide  (FlashbackMonitorLabeler *labeler,
+                                                          const gchar             *sender);
 
 G_END_DECLS
 
diff --git a/gnome-flashback/libshell/flashback-shell.c b/gnome-flashback/libshell/flashback-shell.c
index 53a10a2..81b3abf 100644
--- a/gnome-flashback/libshell/flashback-shell.c
+++ b/gnome-flashback/libshell/flashback-shell.c
@@ -46,8 +46,8 @@ struct _FlashbackShell
   GHashTable              *grabbers;
 
   /* monitor labeler */
+  GfMonitorManager        *monitor_manager;
   FlashbackMonitorLabeler *labeler;
-  FlashbackMonitorManager *manager;
 
   /* osd */
   FlashbackOsd            *osd;
@@ -232,9 +232,9 @@ handle_show_monitor_labels (FlashbackDBusShell    *dbus_shell,
   shell = FLASHBACK_SHELL (user_data);
   sender = g_dbus_method_invocation_get_sender (invocation);
 
-  g_assert (shell->manager != NULL);
+  g_assert (shell->monitor_manager != NULL);
 
-  flashback_monitor_labeler_show (shell->labeler, shell->manager,
+  flashback_monitor_labeler_show (shell->labeler, shell->monitor_manager,
                                   sender, params);
 
   flashback_dbus_shell_complete_show_monitor_labels (dbus_shell, invocation);
@@ -243,6 +243,28 @@ handle_show_monitor_labels (FlashbackDBusShell    *dbus_shell,
 }
 
 static gboolean
+handle_show_monitor_labels2 (FlashbackDBusShell    *dbus_shell,
+                             GDBusMethodInvocation *invocation,
+                             GVariant              *params,
+                             gpointer               user_data)
+{
+  FlashbackShell *shell;
+  const gchar *sender;
+
+  shell = FLASHBACK_SHELL (user_data);
+  sender = g_dbus_method_invocation_get_sender (invocation);
+
+  g_assert (shell->monitor_manager != NULL);
+
+  flashback_monitor_labeler_show2 (shell->labeler, shell->monitor_manager,
+                                   sender, params);
+
+  flashback_dbus_shell_complete_show_monitor_labels2 (dbus_shell, invocation);
+
+  return TRUE;
+}
+
+static gboolean
 handle_hide_monitor_labels (FlashbackDBusShell    *dbus_shell,
                             GDBusMethodInvocation *invocation,
                             gpointer               user_data)
@@ -390,6 +412,8 @@ name_appeared_handler (GDBusConnection *connection,
                     G_CALLBACK (handle_show_osd), shell);
   g_signal_connect (skeleton, "handle-show-monitor-labels",
                     G_CALLBACK (handle_show_monitor_labels), shell);
+  g_signal_connect (skeleton, "handle-show-monitor-labels2",
+                    G_CALLBACK (handle_show_monitor_labels2), shell);
   g_signal_connect (skeleton, "handle-hide-monitor-labels",
                     G_CALLBACK (handle_hide_monitor_labels), shell);
   g_signal_connect (skeleton, "handle-focus-app",
@@ -491,8 +515,8 @@ flashback_shell_new (void)
 }
 
 void
-flashback_shell_set_display_config (FlashbackShell         *shell,
-                                    FlashbackDisplayConfig *config)
+flashback_shell_set_monitor_manager (FlashbackShell   *shell,
+                                     GfMonitorManager *monitor_manager)
 {
-  shell->manager = flashback_display_config_get_monitor_manager (config);
+  shell->monitor_manager = monitor_manager;
 }
diff --git a/gnome-flashback/libshell/flashback-shell.h b/gnome-flashback/libshell/flashback-shell.h
index 53848ad..5e85b68 100644
--- a/gnome-flashback/libshell/flashback-shell.h
+++ b/gnome-flashback/libshell/flashback-shell.h
@@ -19,18 +19,17 @@
 #define FLASHBACK_SHELL_H
 
 #include <glib-object.h>
+#include "backends/gf-monitor-manager.h"
 
 G_BEGIN_DECLS
 
-typedef struct _FlashbackDisplayConfig FlashbackDisplayConfig;
-
 #define FLASHBACK_TYPE_SHELL flashback_shell_get_type ()
 G_DECLARE_FINAL_TYPE (FlashbackShell, flashback_shell, FLASHBACK, SHELL, GObject)
 
-FlashbackShell *flashback_shell_new                (void);
+FlashbackShell *flashback_shell_new                 (void);
 
-void            flashback_shell_set_display_config (FlashbackShell         *shell,
-                                                    FlashbackDisplayConfig *config);
+void            flashback_shell_set_monitor_manager (FlashbackShell   *shell,
+                                                     GfMonitorManager *monitor_manager);
 
 G_END_DECLS
 
diff --git a/gnome-flashback/libshell/org.gnome.Shell.xml b/gnome-flashback/libshell/org.gnome.Shell.xml
index e4af146..dbb9500 100644
--- a/gnome-flashback/libshell/org.gnome.Shell.xml
+++ b/gnome-flashback/libshell/org.gnome.Shell.xml
@@ -13,6 +13,9 @@
     <method name="ShowMonitorLabels">
       <arg type="a{uv}" direction="in" name="params" />
     </method>
+    <method name="ShowMonitorLabels2">
+      <arg type="a{sv}" direction="in" name="params" />
+    </method>
     <method name="HideMonitorLabels" />
     <method name="FocusApp">
       <arg type="s" direction="in" name="id" />


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