[mutter/wip/tablet-protocol-v2: 63/65] core: Add meta_display_request_pad_osd() function



commit 609a1c24bda624e05ebc69ad243861c6b360c09a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 22 19:17:40 2016 +0200

    core: Add meta_display_request_pad_osd() function
    
    There may be external/compositor-specific reasons to trigger the
    pad OSD. Expose this call so the pad OSD can be triggered looking
    up the right settings, monitor, etc...

 src/core/display-private.h |    2 +
 src/core/display.c         |   95 +++++++++++++++++++++++++++++++++++++++++++-
 src/meta/display.h         |    3 +
 3 files changed, 98 insertions(+), 2 deletions(-)
---
diff --git a/src/core/display-private.h b/src/core/display-private.h
index 531c6f7..fa5fff4 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -277,6 +277,8 @@ struct _MetaDisplay
   int xinput_event_base;
   int xinput_opcode;
 
+  ClutterActor *current_pad_osd;
+
   MetaStartupNotification *startup_notification;
 
   int xsync_event_base;
diff --git a/src/core/display.c b/src/core/display.c
index 114ea91..ea5b3c9 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -351,7 +351,9 @@ meta_display_class_init (MetaDisplayClass *klass)
    * @display: the #MetaDisplay instance
    * @pad: the pad device
    * @settings: the pad device settings
+   * @layout_path: path to the layout image
    * @edition_mode: Whether the OSD should be shown in edition mode
+   * @monitor_idx: Monitor to show the OSD on
    *
    * Requests the pad button mapping OSD to be shown.
    *
@@ -362,8 +364,8 @@ meta_display_class_init (MetaDisplayClass *klass)
                   G_TYPE_FROM_CLASS (klass),
                   G_SIGNAL_RUN_LAST,
                   0, NULL, NULL, NULL,
-                  CLUTTER_TYPE_ACTOR, 3, CLUTTER_TYPE_INPUT_DEVICE,
-                  G_TYPE_SETTINGS, G_TYPE_BOOLEAN);
+                  CLUTTER_TYPE_ACTOR, 5, CLUTTER_TYPE_INPUT_DEVICE,
+                  G_TYPE_SETTINGS, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT);
 
   g_object_class_install_property (object_class,
                                    PROP_FOCUS_WINDOW,
@@ -542,6 +544,27 @@ on_startup_notification_changed (MetaStartupNotification *sn,
   g_signal_emit_by_name (display->screen, "startup-sequence-changed", sequence);
 }
 
+static void
+check_pad_removed (MetaDisplay          *display,
+                   ClutterInputDevice   *device,
+                   ClutterDeviceManager *device_manager)
+{
+  ClutterInputDevice *pad;
+
+  if (!display->current_pad_osd)
+    return;
+
+  pad = g_object_get_data (G_OBJECT (display->current_pad_osd),
+                           "meta-pad-osd-device");
+
+  if (pad == device)
+    {
+      /* Close pad OSD */
+      clutter_actor_destroy (display->current_pad_osd);
+      display->current_pad_osd = NULL;
+    }
+}
+
 /**
  * meta_display_open:
  *
@@ -986,6 +1009,10 @@ meta_display_open (void)
 
   meta_idle_monitor_init_dbus ();
 
+  g_signal_connect_swapped (clutter_device_manager_get_default (),
+                            "device-removed", G_CALLBACK (check_pad_removed),
+                            display);
+
   /* Done opening new display */
   display->display_opening = FALSE;
 
@@ -3103,6 +3130,70 @@ meta_display_set_alarm_filter (MetaDisplay    *display,
   display->alarm_filter_data = data;
 }
 
+void
+meta_display_request_pad_osd (MetaDisplay        *display,
+                              ClutterInputDevice *pad,
+                              gboolean            edition_mode)
+{
+  MetaInputSettings *input_settings;
+  const gchar *layout_path = NULL;
+  ClutterActor *osd;
+  MetaOutput *output;
+  gint monitor_idx;
+  GSettings *settings;
+#ifdef HAVE_LIBWACOM
+  WacomDevice *wacom_device;
+#endif
+
+  input_settings = meta_input_settings_get ();
+
+  if (display->current_pad_osd)
+    {
+      clutter_actor_destroy (display->current_pad_osd);
+      display->current_pad_osd = NULL;
+    }
+
+  if (input_settings)
+    {
+      settings = meta_input_settings_get_tablet_settings (input_settings, pad);
+      output = meta_input_settings_get_tablet_output (input_settings, pad);
+#ifdef HAVE_LIBWACOM
+      wacom_device = meta_input_settings_get_tablet_wacom_device (input_settings,
+                                                                  pad);
+      layout_path = libwacom_get_layout_filename (wacom_device);
+#endif
+    }
+
+  if (!layout_path || !settings)
+    return;
+
+  if (output && output->crtc)
+    {
+      monitor_idx = meta_screen_get_monitor_index_for_rect (display->screen,
+                                                            &output->crtc->rect);
+    }
+  else
+    {
+      monitor_idx = meta_screen_get_current_monitor (display->screen);
+    }
+
+  g_signal_emit (display, display_signals[SHOW_PAD_OSD], 0,
+                 pad, settings, layout_path,
+                 edition_mode, monitor_idx, &osd);
+
+  if (osd)
+    {
+      display->current_pad_osd = osd;
+      g_object_set_data (G_OBJECT (display->current_pad_osd),
+                         "meta-pad-osd-device", pad);
+      g_object_add_weak_pointer (G_OBJECT (display->current_pad_osd),
+                                 (gpointer *) &display->current_pad_osd);
+      clutter_actor_grab_key_focus (osd);
+    }
+
+  g_object_unref (settings);
+}
+
 gchar *
 meta_display_get_pad_action_label (MetaDisplay        *display,
                                    ClutterInputDevice *pad,
diff --git a/src/meta/display.h b/src/meta/display.h
index e6d8ba9..3d70d8d 100644
--- a/src/meta/display.h
+++ b/src/meta/display.h
@@ -188,6 +188,9 @@ void meta_display_unfreeze_keyboard (MetaDisplay *display,
 gboolean meta_display_is_pointer_emulating_sequence (MetaDisplay          *display,
                                                      ClutterEventSequence *sequence);
 
+void    meta_display_request_pad_osd      (MetaDisplay        *display,
+                                           ClutterInputDevice *pad,
+                                           gboolean            edition_mode);
 gchar * meta_display_get_pad_action_label (MetaDisplay        *display,
                                            ClutterInputDevice *pad,
                                            MetaPadActionType   action_type,


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