[gnome-terminal/wip/command-notify: 1/2] Support desktop notifications from OSC 777
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/wip/command-notify: 1/2] Support desktop notifications from OSC 777
- Date: Tue, 27 Jan 2015 18:55:01 +0000 (UTC)
commit 5d161dd1f56424e777a992b96a04862b6c394807
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Jan 27 18:40:13 2015 +0100
Support desktop notifications from OSC 777
src/terminal-app.c | 32 ++++++++++++++++++++++++++
src/terminal-screen.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/src/terminal-app.c b/src/terminal-app.c
index 8a9434f..3d09914 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -299,6 +299,31 @@ app_menu_quit_cb (GSimpleAction *action,
gtk_widget_destroy (GTK_WIDGET (window));
}
+/* Other action callbacks */
+
+static void
+action_activate_tab_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+ GtkWidget *toplevel;
+ TerminalScreen *screen;
+ const char *uuid;
+
+ g_variant_get (parameter, "&s", &uuid);
+ screen = terminal_app_get_screen_by_uuid (TERMINAL_APP (application), uuid);
+ if (screen == NULL)
+ return;
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (screen));
+ if (!gtk_widget_is_toplevel (toplevel))
+ return;
+
+ terminal_window_switch_screen (TERMINAL_WINDOW (toplevel), screen);
+ gtk_window_present (GTK_WINDOW (toplevel));
+}
+
/* Class implementation */
G_DEFINE_TYPE (TerminalApp, terminal_app, GTK_TYPE_APPLICATION)
@@ -321,6 +346,10 @@ terminal_app_startup (GApplication *application)
{ "quit", app_menu_quit_cb, NULL, NULL, NULL }
};
+ const GActionEntry other_actions[] = {
+ { "activate-tab", action_activate_tab_cb, "s", NULL, NULL }
+ };
+
gs_unref_object GtkBuilder *builder;
GError *error = NULL;
@@ -332,6 +361,9 @@ terminal_app_startup (GApplication *application)
g_action_map_add_action_entries (G_ACTION_MAP (application),
app_menu_actions, G_N_ELEMENTS (app_menu_actions),
application);
+ g_action_map_add_action_entries (G_ACTION_MAP (application),
+ other_actions, G_N_ELEMENTS (other_actions),
+ application);
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder,
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 9f63239..b490a1a 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -48,6 +48,7 @@
#include "terminal-marshal.h"
#include "terminal-schemas.h"
#include "terminal-screen-container.h"
+#include "terminal-tab-label.h"
#include "terminal-util.h"
#include "terminal-window.h"
#include "terminal-info-bar.h"
@@ -136,6 +137,9 @@ static gboolean terminal_screen_do_exec (TerminalScreen *screen,
GError **error);
static void terminal_screen_child_exited (VteTerminal *terminal,
int status);
+static void terminal_screen_notification_received (VteTerminal *terminal,
+ const char *summary,
+ const char *body);
static void terminal_screen_window_title_changed (VteTerminal *vte_terminal,
TerminalScreen *screen);
@@ -440,6 +444,7 @@ terminal_screen_class_init (TerminalScreenClass *klass)
widget_class->popup_menu = terminal_screen_popup_menu;
terminal_class->child_exited = terminal_screen_child_exited;
+ terminal_class->notification_received = terminal_screen_notification_received;
signals[PROFILE_SET] =
g_signal_new (I_("profile-set"),
@@ -561,6 +566,10 @@ terminal_screen_dispose (GObject *object)
TerminalScreen *screen = TERMINAL_SCREEN (object);
TerminalScreenPrivate *priv = screen->priv;
GtkSettings *settings;
+ TerminalApp *app;
+
+ app = terminal_app_get ();
+ g_application_withdraw_notification (G_APPLICATION (app), priv->uuid);
settings = gtk_widget_get_settings (GTK_WIDGET (screen));
g_signal_handlers_disconnect_matched (settings, G_SIGNAL_MATCH_DATA,
@@ -1596,6 +1605,57 @@ terminal_screen_child_exited (VteTerminal *terminal,
}
static void
+terminal_screen_notification_received (VteTerminal *terminal,
+ const char *summary,
+ const char *body)
+{
+ TerminalScreen *screen = TERMINAL_SCREEN (terminal);
+ TerminalScreenPrivate *priv = screen->priv;
+ TerminalWindow *window;
+
+ window = terminal_screen_get_window (screen);
+ if (window == NULL)
+ return;
+
+ if (gtk_window_is_active (GTK_WINDOW (window)))
+ {
+ GtkWidget *mdi_container;
+ TerminalScreenContainer *screen_container;
+
+ if (screen == terminal_window_get_active (window))
+ return;
+
+ screen_container = terminal_screen_container_get_from_screen (screen);
+ if (screen_container == NULL)
+ return;
+
+ mdi_container = terminal_window_get_mdi_container (window);
+ /* FIXME: add interface method to retrieve tab label */
+ if (GTK_IS_NOTEBOOK (mdi_container))
+ {
+ GtkWidget *tab_label;
+
+ tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (mdi_container), GTK_WIDGET
(screen_container));
+ terminal_tab_label_set_bold (TERMINAL_TAB_LABEL (tab_label), TRUE);
+ }
+ }
+ else
+ {
+ gs_unref_object GNotification *notification = NULL;
+ TerminalApp *app;
+ gs_free char *detailed_action = NULL;
+
+ notification = g_notification_new (summary);
+ g_notification_set_body (notification, body);
+ detailed_action = g_strdup_printf ("app.activate-tab::%s", priv->uuid);
+ g_notification_set_default_action (notification, detailed_action);
+
+ app = terminal_app_get ();
+ g_application_send_notification (G_APPLICATION (app), priv->uuid, notification);
+ }
+}
+
+static void
terminal_screen_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]