[console/zbrown/term-intent: 2/6] term-intent: inital implementation




commit 0e45decfb9c8dac33013ff07483e2f8a3edbe7e2
Author: Zander Brown <zbrown gnome org>
Date:   Tue May 11 23:10:13 2021 +0100

    term-intent: inital implementation

 data/org.gnome.Console.desktop.in.in |  1 +
 src/kgx-application.c                | 72 ++++++++++++++++++++++++++++++++++++
 src/kgx-application.h                |  7 +++-
 src/meson.build                      |  8 +++-
 src/org.freedesktop.Terminal1.xml    | 15 ++++++++
 5 files changed, 100 insertions(+), 3 deletions(-)
---
diff --git a/data/org.gnome.Console.desktop.in.in b/data/org.gnome.Console.desktop.in.in
index 69b57e8..61b1071 100644
--- a/data/org.gnome.Console.desktop.in.in
+++ b/data/org.gnome.Console.desktop.in.in
@@ -14,6 +14,7 @@ X-GNOME-UsesNotifications=true
 Actions=new-window;new-tab;
 # Translators: Do NOT translate or transliterate this text (these are enum types)!
 X-Purism-FormFactor=Workstation;Mobile;
+Implements=org.freedesktop.Terminal1
 
 [Desktop Action new-window]
 Exec=@BIN_NAME@
diff --git a/src/kgx-application.c b/src/kgx-application.c
index 753f37e..e146ad3 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -424,6 +424,76 @@ kgx_application_open (GApplication  *app,
 }
 
 
+static void
+handle_launch (XdgTerminal1          *xdg_term,
+               GDBusMethodInvocation *invocation,
+               const char            *exec,
+               const char            *working_directory,
+               const char            *desktop_entry,
+               const char *const     *env,
+               GVariant              *options,
+               GVariant              *platform_data,
+               KgxApplication        *self)
+{
+  /* TODO: entry - new instance? title? */
+  /* TODO: env */
+  /* TODO: options - keep open? */
+
+  kgx_application_add_terminal (self,
+                                NULL,
+                                -1,
+                                g_file_new_for_path (working_directory),
+                                exec,
+                                NULL);
+
+  xdg_terminal1_complete_launch_command (xdg_term, invocation);
+}
+
+
+static gboolean
+kgx_application_dbus_register (GApplication     *app,
+                               GDBusConnection  *connection,
+                               const char       *object_path,
+                               GError          **error)
+{
+  KgxApplication *self = KGX_APPLICATION (app);
+
+  self->xdg_term = xdg_terminal1_skeleton_new ();
+
+  g_signal_connect (self->xdg_term,
+                    "handle-launch-command", G_CALLBACK (handle_launch),
+                    self);
+
+  if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->xdg_term),
+                                         connection,
+                                         object_path,
+                                         error)) {
+    return FALSE;
+  }
+
+  return G_APPLICATION_CLASS (kgx_application_parent_class)->dbus_register (app,
+                                                                            connection,
+                                                                            object_path,
+                                                                            error);
+}
+
+
+static void
+kgx_application_dbus_unregister (GApplication    *app,
+                                 GDBusConnection *connection,
+                                 const char      *object_path)
+{
+  KgxApplication *self = KGX_APPLICATION (app);
+
+  g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->xdg_term));
+  g_clear_object (&self->xdg_term);
+
+  return G_APPLICATION_CLASS (kgx_application_parent_class)->dbus_unregister (app,
+                                                                              connection,
+                                                                              object_path);
+}
+
+
 static int
 kgx_application_local_command_line (GApplication   *app,
                                     char         ***arguments,
@@ -666,6 +736,8 @@ kgx_application_class_init (KgxApplicationClass *klass)
   app_class->activate = kgx_application_activate;
   app_class->startup = kgx_application_startup;
   app_class->open = kgx_application_open;
+  app_class->dbus_register = kgx_application_dbus_register;
+  app_class->dbus_unregister = kgx_application_dbus_unregister;
   app_class->local_command_line = kgx_application_local_command_line;
   app_class->command_line = kgx_application_command_line;
   app_class->handle_local_options = kgx_application_handle_local_options;
diff --git a/src/kgx-application.h b/src/kgx-application.h
index 5b3162e..3259a73 100644
--- a/src/kgx-application.h
+++ b/src/kgx-application.h
@@ -20,6 +20,8 @@
 
 #include <gtk/gtk.h>
 
+#include "xdg-term1.h"
+
 #include "kgx-process.h"
 #include "kgx-window.h"
 #include "kgx-terminal.h"
@@ -74,8 +76,7 @@ struct ProcessWatch {
  *
  * Stability: Private
  */
-struct _KgxApplication
-{
+struct _KgxApplication {
   /*< private >*/
   GtkApplication            parent_instance;
 
@@ -84,6 +85,8 @@ struct _KgxApplication
   double                    scale;
   gint64                    scrollback_lines;
 
+  XdgTerminal1             *xdg_term;
+
   GSettings                *settings;
   GSettings                *desktop_interface;
 
diff --git a/src/meson.build b/src/meson.build
index f1a16be..f5b9184 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -58,7 +58,13 @@ kgx_sources += gnome.compile_resources('kgx-resources',
   dependencies: style_deps
 )
 
-kgx_enums = gnome.mkenums_simple('kgx-enums',
+kgx_sources += gnome.gdbus_codegen('xdg-term1',
+           sources: 'org.freedesktop.Terminal1.xml',
+  interface_prefix: 'org.freedesktop.',
+         namespace: 'Xdg',
+)
+
+kgx_sources += gnome.mkenums_simple('kgx-enums',
                                     sources: [
                                       'kgx-close-dialog.h',
                                       'kgx-terminal.h',
diff --git a/src/org.freedesktop.Terminal1.xml b/src/org.freedesktop.Terminal1.xml
new file mode 100644
index 0000000..4932238
--- /dev/null
+++ b/src/org.freedesktop.Terminal1.xml
@@ -0,0 +1,15 @@
+<!DOCTYPE node PUBLIC
+  "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+  "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"; >
+<node>
+  <interface name="org.freedesktop.Terminal1">
+    <method name="LaunchCommand">
+      <arg type='ay' name='exec' direction='in' />
+      <arg type='ay' name='working_directory' direction='in' />
+      <arg type='ay' name='desktop_entry' direction='in' />
+      <arg type='aay' name='env' direction='in' />
+      <arg type='a{sv}' name='options' direction='in' />
+      <arg type='a{sv}' name='platform_data' direction='in' />
+    </method>
+  </interface>
+</node>
\ No newline at end of file


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