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




commit 74832b9a9d88edc17cbca999941b7460f069ab1d
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                | 74 +++++++++++++++++++++++++++++++++++-
 src/kgx-application.h                |  7 +++-
 src/meson.build                      |  6 +++
 src/org.freedesktop.Terminal1.xml    | 15 ++++++++
 5 files changed, 99 insertions(+), 4 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 f2a0f7f..c1352db 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -330,8 +330,6 @@ kgx_application_startup (GApplication *app)
   const char *const zoom_out_accels[] = { "<primary>minus", NULL };
   const char *const zoom_normal_accels[] = { "<primary>0", NULL };
 
-  g_set_prgname (g_application_get_application_id (app));
-
   g_resources_register (kgx_get_resource ());
 
   g_type_ensure (KGX_TYPE_TERMINAL);
@@ -389,6 +387,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,
@@ -631,6 +699,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 fa401cd..1c022ab 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"
@@ -70,8 +72,7 @@ struct ProcessWatch {
  *
  * Stability: Private
  */
-struct _KgxApplication
-{
+struct _KgxApplication {
   /*< private >*/
   AdwApplication            parent_instance;
 
@@ -80,6 +81,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 f8d5358..3376968 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -55,6 +55,12 @@ kgx_sources += gnome.compile_resources('kgx-resources',
   c_name: 'kgx'
 )
 
+kgx_sources += gnome.gdbus_codegen('xdg-term1',
+           sources: 'org.freedesktop.Terminal1.xml',
+  interface_prefix: 'org.freedesktop.',
+         namespace: 'Xdg',
+)
+
 kgx_enums = gnome.mkenums_simple('kgx-enums',
                                     sources: [
                                       'kgx-close-dialog.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]