[console/zbrown/term-intent-2: 2/4] term-intent: inital implementation
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [console/zbrown/term-intent-2: 2/4] term-intent: inital implementation
- Date: Mon, 1 Aug 2022 23:47:53 +0000 (UTC)
commit cd37aa84ffe0a921e8d3deda4516e6aed4c54a8c
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 | 98 +++++++++++++++++++++++++++++++++++-
src/kgx-application.h | 7 ++-
src/meson.build | 6 +++
src/org.freedesktop.Terminal1.xml | 15 ++++++
5 files changed, 123 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..0e63927 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -29,6 +29,7 @@
#include "kgx-config.h"
#include <glib/gi18n.h>
+#include <gio/gdesktopappinfo.h>
#include <vte/vte.h>
#include <unistd.h>
#include <sys/ioctl.h>
@@ -37,6 +38,7 @@
#include "kgx-application.h"
#include "kgx-window.h"
+#include "kgx-term-app-window.h"
#include "kgx-pages.h"
#include "kgx-simple-tab.h"
#include "kgx-resources.h"
@@ -330,8 +332,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 +389,98 @@ kgx_application_open (GApplication *app,
}
+static void
+handle_launch (XdgTerminal1 *xdg_term,
+ GDBusMethodInvocation *invocation,
+ const char *const *exec,
+ const char *working_directory,
+ const char *desktop_entry,
+ const char *const *env,
+ GVariant *options,
+ GVariant *platform_data,
+ KgxApplication *self)
+{
+ g_autofree char *title = NULL;
+ g_autoptr (GFile) working = NULL;
+ KgxWindow *window = NULL;
+ guint32 timezone = GDK_CURRENT_TIME;
+
+ if (working_directory) {
+ working = g_file_new_for_path (working_directory);
+ }
+
+ /* TODO: env */
+ /* TODO: options - keep open? */
+
+ if (desktop_entry && desktop_entry[0] != '\0') {
+ g_autoptr (GDesktopAppInfo) entry = NULL;
+
+ entry = g_desktop_app_info_new_from_filename (desktop_entry);
+
+ window = g_object_new (KGX_TYPE_TERM_APP_WINDOW,
+ "application", self,
+ "desktop-entry", entry,
+ NULL);
+
+ title = g_strdup (g_app_info_get_name (G_APP_INFO (entry)));
+ } else {
+ window = g_object_new (KGX_TYPE_WINDOW,
+ "application", self,
+ NULL);
+
+ title = g_path_get_basename (exec[0]);
+ }
+
+ kgx_application_add_terminal (self, window, timezone, working, (GStrv) exec, title);
+
+ 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 +723,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 a6f5eb9..73849ac 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -57,6 +57,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..0c30322
--- /dev/null
+++ b/src/org.freedesktop.Terminal1.xml
@@ -0,0 +1,15 @@
+<!DOCTYPE node PUBLIC
+ "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
+ "https://dbus.freedesktop.org/doc/introspect.dtd" >
+<node>
+ <interface name="org.freedesktop.Terminal1">
+ <method name="LaunchCommand">
+ <arg type='aay' 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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]