[vte/vte-0-50-ntfy-scroll: 1/5] Add sequences and signals for desktop notification



commit 7e610a3fcc67f9ed642d14efa4e7b0a076ce5bab
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jan 7 16:01:00 2015 +0100

    Add sequences and signals for desktop notification
    
    Add sequences
      OSC 777 ; notify ; SUMMARY ; BODY BEL
      OSC 777 ; notify ; SUMMARY BEL
      OSC 777 ; notify ; SUMMARY ; BODY ST
      OSC 777 ; notify ; SUMMARY ST
    
    that let terminal applications send a notification to the desktop
    environment.
    
    Based on Enlightenment's Terminology:
    https://phab.enlightenment.org/T1765
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711059

 src/caps.cc           |    4 ++
 src/marshal.list      |    1 +
 src/vte.cc            |   12 ++++++
 src/vte/vteterminal.h |    4 ++-
 src/vtegtk.cc         |   21 +++++++++++
 src/vtegtk.hh         |    1 +
 src/vteinternal.hh    |    5 +++
 src/vteseq-n.gperf    |    1 +
 src/vteseq.cc         |   90 +++++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 138 insertions(+), 1 deletions(-)
---
diff --git a/src/caps.cc b/src/caps.cc
index 1f9cd1e..7262aeb 100644
--- a/src/caps.cc
+++ b/src/caps.cc
@@ -257,6 +257,8 @@ const char _vte_xterm_capability_strings[] =
         ENTRY(OSC "119" BEL, "reset-highlight-foreground-color")
         ENTRY(OSC "133;%s" BEL, "iterm2-133")
         ENTRY(OSC "777;%s" BEL, "urxvt-777")
+        ENTRY(OSC "777;%s;%s;%s" BEL, "send-notification")
+        ENTRY(OSC "777;%s;%s" BEL, "send-notification")
         ENTRY(OSC "1337;%s" BEL, "iterm2-1337")
 
         COMMENT(/* Set text parameters, ST-terminated versions. */)
@@ -296,6 +298,8 @@ const char _vte_xterm_capability_strings[] =
         ENTRY(OSC "119" ST, "reset-highlight-foreground-color")
         ENTRY(OSC "133;%s" ST, "iterm2-133")
         ENTRY(OSC "777;%s" ST, "urxvt-777")
+        ENTRY(OSC "777;%s;%s;%s" ST, "send-notification")
+        ENTRY(OSC "777;%s;%s" ST, "send-notification")
         ENTRY(OSC "1337;%s" ST, "iterm2-1337")
 
         COMMENT(/* These may be bogus, I can't find docs for them anywhere (#104154). */)
diff --git a/src/marshal.list b/src/marshal.list
index 1e4d0c1..3385b47 100644
--- a/src/marshal.list
+++ b/src/marshal.list
@@ -1,5 +1,6 @@
 VOID:INT,INT
 VOID:OBJECT,OBJECT
 VOID:STRING,BOXED
+VOID:STRING,STRING
 VOID:STRING,UINT
 VOID:UINT,UINT
diff --git a/src/vte.cc b/src/vte.cc
index e52f726..f3b8664 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -8552,6 +8552,9 @@ VteTerminalPrivate::~VteTerminalPrivate()
 
        remove_update_timeout(this);
 
+       g_free (m_notification_summary);
+       g_free (m_notification_body);
+
        /* discard title updates */
         g_free(m_window_title);
         g_free(m_window_title_changed);
@@ -10632,6 +10635,15 @@ VteTerminalPrivate::emit_pending_signals()
 
        emit_adjustment_changed();
 
+       if (m_notification_received) {
+                _vte_debug_print (VTE_DEBUG_SIGNALS,
+                                  "Emitting `notification-received'.\n");
+                g_signal_emit(object, signals[SIGNAL_NOTIFICATION_RECEIVED], 0,
+                              m_notification_summary,
+                              m_notification_body);
+                m_notification_received = FALSE;
+       }
+
        if (m_window_title_changed) {
                g_free (m_window_title);
                m_window_title = m_window_title_changed;
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index cfd5a91..b3c6978 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -104,8 +104,10 @@ struct _VteTerminalClass {
 
        void (*bell)(VteTerminal* terminal);
 
+       void (*notification_received)(VteTerminal* terminal, const gchar *summary, const gchar *body);
+
         /* Padding for future expansion. */
-        gpointer padding[16];
+        gpointer padding[15];
 
         VteTerminalClassPrivate *priv;
 };
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 18a4b1b..4ccc4ff 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -679,6 +679,7 @@ vte_terminal_class_init(VteTerminalClass *klass)
        klass->child_exited = NULL;
        klass->encoding_changed = NULL;
        klass->char_size_changed = NULL;
+       klass->notification_received = NULL;
        klass->window_title_changed = NULL;
        klass->icon_title_changed = NULL;
        klass->selection_changed = NULL;
@@ -755,6 +756,26 @@ vte_terminal_class_init(VteTerminalClass *klass)
                              1, G_TYPE_INT);
 
         /**
+         * VteTerminal::notification-received:
+         * @vteterminal: the object which received the signal
+         * @summary: The summary
+         * @body: (allow-none): Extra optional text
+         *
+         * Emitted when a process running in the terminal wants to
+         * send a notification to the desktop environment.
+         */
+        signals[SIGNAL_NOTIFICATION_RECEIVED] =
+                g_signal_new(I_("notification-received"),
+                             G_OBJECT_CLASS_TYPE(klass),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET(VteTerminalClass, notification_received),
+                             NULL,
+                             NULL,
+                             _vte_marshal_VOID__STRING_STRING,
+                             G_TYPE_NONE,
+                             2, G_TYPE_STRING, G_TYPE_STRING);
+
+        /**
          * VteTerminal::window-title-changed:
          * @vteterminal: the object which received the signal
          *
diff --git a/src/vtegtk.hh b/src/vtegtk.hh
index d1ade94..07c714e 100644
--- a/src/vtegtk.hh
+++ b/src/vtegtk.hh
@@ -56,6 +56,7 @@ enum {
         SIGNAL_TEXT_INSERTED,
         SIGNAL_TEXT_MODIFIED,
         SIGNAL_TEXT_SCROLLED,
+        SIGNAL_NOTIFICATION_RECEIVED,
         SIGNAL_WINDOW_TITLE_CHANGED,
         LAST_SIGNAL
 };
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index 0cd686b..f7faa7a 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -496,6 +496,11 @@ public:
         gboolean m_cursor_moved_pending;
         gboolean m_contents_changed_pending;
 
+       /* desktop notification */
+       gboolean m_notification_received;
+       gchar *m_notification_summary;
+       gchar *m_notification_body;
+
        /* window name changes */
         char* m_window_title;
         char* m_window_title_changed;
diff --git a/src/vteseq-n.gperf b/src/vteseq-n.gperf
index 7cd1de5..e2cb3c9 100644
--- a/src/vteseq-n.gperf
+++ b/src/vteseq-n.gperf
@@ -171,5 +171,6 @@ struct vteseq_n_struct {
 "set-current-file-uri", VTE_SEQUENCE_HANDLER(vte_sequence_handler_set_current_file_uri)
 "set-current-hyperlink", VTE_SEQUENCE_HANDLER(vte_sequence_handler_set_current_hyperlink)
 "urxvt-777", VTE_SEQUENCE_HANDLER(vte_sequence_handler_urxvt_777)
+"send-notification", VTE_SEQUENCE_HANDLER(vte_sequence_handler_send_notification)
 "iterm2-133", VTE_SEQUENCE_HANDLER(vte_sequence_handler_iterm2_133)
 "iterm2-1337", VTE_SEQUENCE_HANDLER(vte_sequence_handler_iterm2_1337)
diff --git a/src/vteseq.cc b/src/vteseq.cc
index 6876341..01c8160 100644
--- a/src/vteseq.cc
+++ b/src/vteseq.cc
@@ -2352,6 +2352,96 @@ vte_sequence_handler_return_terminal_id (VteTerminalPrivate *that, GValueArray *
        vte_sequence_handler_send_primary_device_attributes (that, params);
 }
 
+static void
+vte_sequence_handler_send_notification (VteTerminalPrivate *that, GValueArray *params)
+{
+       GValue *value;
+       const char *end;
+       char *option = NULL;
+       char *str = NULL;
+       char *p, *validated;
+
+       g_clear_pointer (&that->m_notification_summary, g_free);
+       g_clear_pointer (&that->m_notification_body, g_free);
+
+       value = g_value_array_get_nth (params, 0);
+       if (value == NULL) {
+               goto out;
+       }
+
+       if (G_VALUE_HOLDS_STRING (value)) {
+               option = g_value_dup_string (value);
+       } else if (G_VALUE_HOLDS_POINTER (value)) {
+               option = that->ucs4_to_utf8 ((const guchar *)g_value_get_pointer (value));
+       } else {
+               goto out;
+       }
+
+       if (g_strcmp0 (option, "notify") != 0) {
+               goto out;
+       }
+
+       value = g_value_array_get_nth (params, 1);
+       if (value == NULL) {
+               goto out;
+       }
+
+       if (G_VALUE_HOLDS_STRING (value)) {
+               str = g_value_dup_string (value);
+       } else if (G_VALUE_HOLDS_POINTER (value)) {
+               str = that->ucs4_to_utf8 ((const guchar *)g_value_get_pointer (value));
+       } else {
+               goto out;
+       }
+
+       g_utf8_validate (str, strlen (str), &end);
+       validated = g_strndup (str, end - str);
+
+       /* No control characters allowed. */
+       for (p = validated; *p != '\0'; p++) {
+               if ((*p & 0x1f) == *p) {
+                       *p = ' ';
+               }
+       }
+
+       that->m_notification_summary = validated;
+       g_free (str);
+
+       that->m_notification_received = TRUE;
+       if (params->n_values == 2) {
+               goto out;
+       }
+
+       value = g_value_array_get_nth (params, 2);
+       if (value == NULL) {
+               goto out;
+       }
+
+       if (G_VALUE_HOLDS_STRING (value)) {
+               str = g_value_dup_string (value);
+       } else if (G_VALUE_HOLDS_POINTER (value)) {
+               str = that->ucs4_to_utf8 ((const guchar *)g_value_get_pointer (value));
+       } else {
+               goto out;
+       }
+
+       g_utf8_validate (str, strlen (str), &end);
+       validated = g_strndup (str, end - str);
+
+       /* No control characters allowed. */
+       for (p = validated; *p != '\0'; p++) {
+               if ((*p & 0x1f) == *p) {
+                       *p = ' ';
+               }
+       }
+
+       that->m_notification_body = validated;
+       g_free (str);
+
+ out:
+       g_free (option);
+}
+
 /* Send secondary device attributes. */
 static void
 vte_sequence_handler_send_secondary_device_attributes (VteTerminalPrivate *that, GValueArray *params)


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