[vte] widget: Add setting to disable input



commit 3868467b2d4613e5aa5f34c0d8e74abc3a38ef16
Author: Christian Persch <chpe gnome org>
Date:   Fri Apr 18 11:00:28 2014 +0200

    widget: Add setting to disable input
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687118

 src/app.ui        |   17 ++++++++-
 src/app.vala      |    3 +
 src/vte-private.h |    1 +
 src/vte.c         |  106 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/vte.h         |    5 ++
 5 files changed, 128 insertions(+), 4 deletions(-)
---
diff --git a/src/app.ui b/src/app.ui
index ac7752e..f3cc4f8 100644
--- a/src/app.ui
+++ b/src/app.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.0 on Sun Apr 13 22:39:56 2014 -->
+<!-- Generated with glade 3.16.0 on Fri Apr 18 10:59:58 2014 -->
 <interface>
   <!-- interface-requires gtk+ 3.10 -->
   <object class="GtkBox" id="main-box">
@@ -51,6 +51,21 @@
             <property name="homogeneous">False</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkToggleToolButton" id="input-enabled-toolbutton">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="tooltip_text" translatable="yes">Toggle input enabled setting</property>
+            <property name="is_important">True</property>
+            <property name="action_name">win.input-enabled</property>
+            <property name="label" translatable="yes">Input</property>
+            <property name="icon_name">input-keyboard</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="homogeneous">False</property>
+          </packing>
+        </child>
       </object>
       <packing>
         <property name="expand">False</property>
diff --git a/src/app.vala b/src/app.vala
index b9d7728..f190f1d 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -137,6 +137,9 @@ class Window : Gtk.ApplicationWindow
                if (App.Options.dingus != null)
                        add_dingus(App.Options.dingus);
 
+               /* Property actions */
+               add_action(new GLib.PropertyAction ("input-enabled", terminal, "input-enabled"));
+
                /* Done! */
                box.pack_start(terminal);
                terminal.show();
diff --git a/src/vte-private.h b/src/vte-private.h
index 9cc89a0..db3ae03 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -321,6 +321,7 @@ struct _VteTerminalPrivate {
        gboolean has_focus;               /* is the terminal window focused */
 
        /* Input device options. */
+        gboolean input_enabled;
        time_t last_keypress_time;
 
        int mouse_tracking_mode; /* this is of type MouseTrackingMode,
diff --git a/src/vte.c b/src/vte.c
index aa654fa..3888922 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -160,6 +160,7 @@ enum {
         PROP_FONT_DESC,
         PROP_FONT_SCALE,
         PROP_ICON_TITLE,
+        PROP_INPUT_ENABLED,
         PROP_MOUSE_POINTER_AUTOHIDE,
         PROP_PTY,
         PROP_REWRAP_ON_RESIZE,
@@ -3357,6 +3358,8 @@ _vte_terminal_connect_pty_write(VteTerminal *terminal)
         VteTerminalPrivate *pvt = terminal->pvt;
 
         g_assert(pvt->pty != NULL);
+        g_warn_if_fail(pvt->input_enabled);
+
        if (terminal->pvt->pty_channel == NULL) {
                pvt->pty_channel =
                        g_io_channel_unix_new(vte_pty_get_fd(pvt->pty));
@@ -4381,6 +4384,9 @@ vte_terminal_send(VteTerminal *terminal, const char *encoding,
        g_assert(VTE_IS_TERMINAL(terminal));
        g_assert(encoding && strcmp(encoding, "UTF-8") == 0);
 
+        if (!terminal->pvt->input_enabled)
+                return;
+
        conv = VTE_INVALID_CONV;
        if (strcmp(encoding, "UTF-8") == 0) {
                conv = terminal->pvt->outgoing_conv;
@@ -4497,6 +4503,10 @@ void
 vte_terminal_feed_child(VteTerminal *terminal, const char *text, gssize length)
 {
        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+        if (!terminal->pvt->input_enabled)
+                return;
+
        if (length == -1) {
                length = strlen(text);
        }
@@ -4519,7 +4529,10 @@ vte_terminal_feed_child(VteTerminal *terminal, const char *text, gssize length)
 void
 vte_terminal_feed_child_binary(VteTerminal *terminal, const guint8 *data, gsize length)
 {
-       g_assert(VTE_IS_TERMINAL(terminal));
+       g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+        if (!terminal->pvt->input_enabled)
+                return;
 
        /* Tell observers that we're sending this to the child. */
        if (length > 0) {
@@ -4945,7 +4958,7 @@ vte_terminal_key_press(GtkWidget *widget, GdkEventKey *event)
        modifiers = terminal->pvt->modifiers;
 
        /* Let the input method at this one first. */
-       if (!steal) {
+       if (!steal && terminal->pvt->input_enabled) {
                if (gtk_widget_get_realized (&terminal->widget)
                                && gtk_im_context_filter_keypress (terminal->pvt->im_context, event)) {
                        _vte_debug_print(VTE_DEBUG_EVENTS,
@@ -8273,6 +8286,8 @@ vte_terminal_init(VteTerminal *terminal)
         pvt->rewrap_on_resize = TRUE;
        vte_terminal_set_default_tabstops(terminal);
 
+        pvt->input_enabled = TRUE;
+
        /* Cursor shape. */
        pvt->cursor_shape = VTE_CURSOR_SHAPE_BLOCK;
         pvt->cursor_aspect_ratio = 0.04;
@@ -10815,6 +10830,9 @@ vte_terminal_get_property (GObject *object,
                 case PROP_ICON_TITLE:
                         g_value_set_string (value, vte_terminal_get_icon_title (terminal));
                         break;
+                case PROP_INPUT_ENABLED:
+                        g_value_set_boolean (value, vte_terminal_get_input_enabled (terminal));
+                        break;
                 case PROP_MOUSE_POINTER_AUTOHIDE:
                         g_value_set_boolean (value, vte_terminal_get_mouse_autohide (terminal));
                         break;
@@ -10904,6 +10922,9 @@ vte_terminal_set_property (GObject *object,
                 case PROP_FONT_SCALE:
                         vte_terminal_set_font_scale (terminal, g_value_get_double (value));
                         break;
+                case PROP_INPUT_ENABLED:
+                        vte_terminal_set_input_enabled (terminal, g_value_get_boolean (value));
+                        break;
                 case PROP_MOUSE_POINTER_AUTOHIDE:
                         vte_terminal_set_mouse_autohide (terminal, g_value_get_boolean (value));
                         break;
@@ -11762,7 +11783,21 @@ vte_terminal_class_init(VteTerminalClass *klass)
                  g_param_spec_string ("icon-title", NULL, NULL,
                                       NULL,
                                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-     
+
+        /**
+         * VteTerminal:input-enabled:
+         *
+         * Controls whether the terminal allows user input. When user input is disabled,
+         * key press and mouse button press and motion events are not sent to the
+         * terminal's child.
+         */
+        g_object_class_install_property
+                (gobject_class,
+                 PROP_INPUT_ENABLED,
+                 g_param_spec_boolean ("input-enabled", NULL, NULL,
+                                       TRUE,
+                                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
         /**
          * VteTerminal:pointer-autohide:
          *
@@ -14070,3 +14105,68 @@ vte_terminal_set_geometry_hints_for_window(VteTerminal *terminal,
                                       GDK_HINT_MIN_SIZE |
                                       GDK_HINT_BASE_SIZE);
 }
+
+/**
+ * vte_terminal_set_input_enabled:
+ * @terminal: a #VteTerminal
+ * @enabled: whether to enable user input
+ *
+ * Enables or disables user input. When user input is disabled,
+ * the terminal's child will not receive any key press, or mouse button
+ * press or motion events sent to it.
+ */
+void
+vte_terminal_set_input_enabled (VteTerminal *terminal,
+                                gboolean enabled)
+{
+        VteTerminalPrivate *pvt;
+        GtkWidget *widget;
+        GtkStyleContext *context;
+
+        g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+        pvt = terminal->pvt;
+        widget = &terminal->widget;
+
+        enabled = enabled != FALSE;
+        if (enabled == terminal->pvt->input_enabled)
+                return;
+
+        pvt->input_enabled = enabled;
+
+        context = gtk_widget_get_style_context (widget);
+
+        /* FIXME: maybe hide cursor when input disabled, too? */
+
+        if (enabled) {
+                if (gtk_widget_has_focus(widget))
+                        gtk_im_context_focus_in(pvt->im_context);
+
+                gtk_style_context_remove_class (context, GTK_STYLE_CLASS_READ_ONLY);
+        } else {
+                vte_terminal_im_reset(terminal);
+                if (gtk_widget_has_focus(widget))
+                        gtk_im_context_focus_out(pvt->im_context);
+
+                _vte_terminal_disconnect_pty_write(terminal);
+                _vte_byte_array_clear(pvt->outgoing);
+
+                gtk_style_context_add_class (context, GTK_STYLE_CLASS_READ_ONLY);
+        }
+
+        g_object_notify(G_OBJECT(terminal), "input-enabled");
+}
+
+/**
+ * vte_terminal_get_input_enabled:
+ * @terminal: a #VteTerminal
+ *
+ * Returns whether the terminal allow user input.
+ */
+gboolean
+vte_terminal_get_input_enabled (VteTerminal *terminal)
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), FALSE);
+
+        return terminal->pvt->input_enabled;
+}
diff --git a/src/vte.h b/src/vte.h
index eb9c5e9..656d519 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -387,6 +387,11 @@ const char *vte_terminal_get_icon_title(VteTerminal *terminal);
 const char *vte_terminal_get_current_directory_uri(VteTerminal *terminal);
 const char *vte_terminal_get_current_file_uri(VteTerminal *terminal);
 
+/* misc */
+void vte_terminal_set_input_enabled (VteTerminal *terminal,
+                                     gboolean enabled);
+gboolean vte_terminal_get_input_enabled (VteTerminal *terminal);
+
 /* Window geometry helpers */
 void vte_terminal_get_geometry_hints(VteTerminal *terminal,
                                      GdkGeometry *hints,


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