libzvt backspace/delete



Hi,

This patch allows the current gnome-terminal bs/delete Glade UI to be
hooked up. If it doesn't go in I can do four radio items instead of the
current two option menus:

 (*) Backspace is ASCII DEL and Delete is escape sequence
 ( ) Backspace is ASCII DEL and Delete is control-H
 ( ) Backspace is control-H and Delete is ASCII DEL
 ( ) Backspace is control-H and Delete is escape sequence

But I would fully expect to get bug reports asking why only those four
combinations are available.

The patch leaves current defaults and API unchanged.

In looking at open bugs, the other one I've noticed is that the
crack-laden xterm selection method (two extra clicks) makes people -
including me for the last year or two - think that the right-click menu on
the terminal is broken/flaky. So I'd like to see libzvt just nuke this
feature, or alternatively have one more new API entry point
"zvt_term_set_has_xterm_selection()" and then add a preference "enable
xterm-style selection" or something. (What a bad idea...)

Havoc

Index: libzvt/ChangeLog
===================================================================
RCS file: /cvs/gnome/libzvt/libzvt/ChangeLog,v
retrieving revision 1.320
diff -u -p -u -r1.320 ChangeLog
--- libzvt/ChangeLog	2002/02/13 18:15:09	1.320
+++ libzvt/ChangeLog	2002/02/15 22:00:54
@@ -1,3 +1,11 @@
+2002-02-15  Havoc Pennington  <hp pobox com>
+
+	* zvtterm.c (zvt_term_set_backspace_binding):
+	(zvt_term_set_delete_binding): new functions to allow a reasonable
+	UI and API for the backspace/delete mess. The old swap_del_key and
+	del_is_del settings still work by setting certain combinations of
+	backspace/delete binding.
+
 2002-02-13  jacob berkman  <jacob ximian com>

 	* zvtterm.c (zvt_term_class_init): s/GTK_TYPE_INT/G_TYPE_INT/
Index: libzvt/libzvt.h
===================================================================
RCS file: /cvs/gnome/libzvt/libzvt/libzvt.h,v
retrieving revision 1.8
diff -u -p -u -r1.8 libzvt.h
--- libzvt/libzvt.h	2002/02/12 16:32:20	1.8
+++ libzvt/libzvt.h	2002/02/15 22:00:54
@@ -69,6 +69,13 @@ G_BEGIN_DECLS
 /* zvt can match regular expressions and return signals when they're clicked on */
 #define ZVT_TERM_MATCH_SUPPORT		0x10

+typedef enum
+{
+  ZVT_ERASE_CONTROL_H, /* same as ASCII backspace */
+  ZVT_ERASE_ESCAPE_SEQUENCE,
+  ZVT_ERASE_ASCII_DEL
+} ZvtEraseBinding;
+
 typedef struct _ZvtTerm        ZvtTerm;
 typedef struct _ZvtTermClass   ZvtTermClass;

@@ -132,6 +139,9 @@ struct _ZvtTerm
 		     */
   } background__dummy;

+  ZvtEraseBinding backspace_binding;
+  ZvtEraseBinding delete_binding;
+
   /* bitfield flags -- keep at end of structure */
   unsigned int cursor_on:1;	      /* on/off cursor */
   unsigned int cursor_filled:1;	      /* is the cursor filled? */
@@ -250,6 +260,9 @@ void         zvt_term_set_del_key_swap
 void         zvt_term_set_del_is_del           (ZvtTerm *term, int state);
 void	     zvt_term_set_wordclass	       (ZvtTerm *term, unsigned char *klass);
 void	     zvt_term_set_auto_window_hint     (ZvtTerm *term, int state);
+
+void         zvt_term_set_backspace_binding    (ZvtTerm *term, ZvtEraseBinding binding);
+void         zvt_term_set_delete_binding       (ZvtTerm *term, ZvtEraseBinding binding);

 /* regular expression matching - automagically! */
 int	     zvt_term_match_add		       (ZvtTerm *term, char *regex,
Index: libzvt/zvtterm.c
===================================================================
RCS file: /cvs/gnome/libzvt/libzvt/zvtterm.c,v
retrieving revision 1.175
diff -u -p -u -r1.175 zvtterm.c
--- libzvt/zvtterm.c	2002/02/13 18:10:25	1.175
+++ libzvt/zvtterm.c	2002/02/15 22:00:55
@@ -327,7 +327,7 @@ zvt_term_class_init (ZvtTermClass *class
   term_class->paste_clipboard = zvt_term_real_paste_clipboard;
   term_class->scroll = zvt_term_scroll;
   term_class->selection_changed = zvt_term_real_selection_changed;
-
+
   /* Setup default key bindings */
   binding_set = gtk_binding_set_by_class(term_class);
 #if defined(sparc) || defined(__sparc__)
@@ -408,6 +408,12 @@ term->vx->cursor_state = vt_cursor_state
   term->transparent = 0;
   term->shaded = 0;

+  /* The correct defaults are backspace=ASCII_DEL
+   * delete=ESCAPE_SEQUENCE, but we have this for backward compat.
+   */
+  term->backspace_binding = ZVT_ERASE_CONTROL_H;
+  term->delete_binding = ZVT_ERASE_ASCII_DEL;
+
   /* private data - set before calling functions */
   zp = g_malloc(sizeof(*zp));
   zp->scrollselect_id = -1;
@@ -542,8 +548,53 @@ zvt_term_set_auto_window_hint (ZvtTerm *
   zp->auto_hint = state;
 }

+/**
+ * zvt_term_set_backspace_binding:
+ * @term: a #ZvtTerm
+ * @binding: what the backspace key should send
+ *
+ * Determines the effect of the backspace key. The correct setting is
+ * #ZVT_ERASE_ASCII_DEL. The other settings are all broken and only
+ * provided for compatibility with broken applications that may be
+ * running inside the terminal.
+ *
+ * #ZvtTerm defaults to #ZVT_ERASE_CONTROL_H for Backspace, which
+ * is wrong, so all apps using #ZvtTerm need to call this function
+ * to fix it.
+ *
+ **/
+void
+zvt_term_set_backspace_binding (ZvtTerm *term, ZvtEraseBinding binding)
+{
+  g_return_if_fail (ZVT_IS_TERM (term));
+
+  term->backspace_binding = binding;
+}

 /**
+ * zvt_term_set_delete_binding:
+ * @term: a #ZvtTerm
+ * @binding: what the delete key should send
+ *
+ * Determines the effect of the delete key. The correct setting is
+ * #ZVT_ERASE_ESCAPE_SEQUENCE. The other settings are all broken and
+ * only provided for compatibility with broken applications that may
+ * be running inside the terminal.
+ *
+ * #ZvtTerm defaults to #ZVT_ERASE_ASCII_DEL for Delete, which
+ * is wrong, so all apps using #ZvtTerm need to call this function
+ * to fix it.
+ *
+ **/
+void
+zvt_term_set_delete_binding (ZvtTerm *term, ZvtEraseBinding binding)
+{
+  g_return_if_fail (ZVT_IS_TERM (term));
+
+  term->delete_binding = binding;
+}
+
+/**
  * zvt_term_set_wordclass:
  * @term: A &ZvtTerm widget.
  * @class: A string of characters to consider a "word" character.
@@ -2385,6 +2436,27 @@ zvt_term_scroll (ZvtTerm *term, int n)
 static unsigned char f5_f20_remap[] =
    {15,17,18,19,20,21,23,24,25,26,28,29,31,32,33,34};

+static void
+append_erase (ZvtEraseBinding binding,
+              char          **pp)
+{
+  switch (binding)
+    {
+    case ZVT_ERASE_CONTROL_H:
+      g_assert (('H' - 64) == 8);
+      *(*pp)++ = 8;
+      break;
+
+    case ZVT_ERASE_ESCAPE_SEQUENCE:
+      (*pp) += sprintf ((*pp), "\033[3~");
+      break;
+
+    case ZVT_ERASE_ASCII_DEL:
+      *(*pp)++ = '\177';
+      break;
+    }
+}
+
 static gint
 zvt_term_key_press (GtkWidget *widget, GdkEventKey *event)
 {
@@ -2411,18 +2483,18 @@ zvt_term_key_press (GtkWidget *widget, G
   handled = TRUE;

   if(!gtk_bindings_activate(GTK_OBJECT(widget),
- 					 event->keyval,
- 					 event->state)){
+                            event->keyval,
+                            event->state)){

   switch (event->keyval) {
   case GDK_BackSpace:
-    if (event->state & GDK_MOD1_MASK)
-      *p++ = '\033';
-
-    if (term->swap_del_key)
-      *p++ = '\177';
-    else
-      *p++ = 8;
+    if (term->backspace_binding == ZVT_ERASE_CONTROL_H ||
+        term->backspace_binding == ZVT_ERASE_ASCII_DEL)
+      {
+        if (event->state & GDK_MOD1_MASK)
+          *p++ = '\033';
+      }
+    append_erase (term->backspace_binding, &p);
     break;
   case GDK_KP_Right:
   case GDK_Right:
@@ -2454,16 +2526,13 @@ zvt_term_key_press (GtkWidget *widget, G
     }
     break;
   case GDK_Delete:
-    if (term->del_is_del){
-      if (event->state & GDK_MOD1_MASK)
-	*p++ = '\033';
-      if (term->swap_del_key)
-	*p++ = 8;
-      else
-	*p++ = '\177';
-    } else {
-      p+=sprintf (p, "\033[3~");
-    }
+    if (term->delete_binding == ZVT_ERASE_CONTROL_H ||
+        term->delete_binding == ZVT_ERASE_ASCII_DEL)
+      {
+        if (event->state & GDK_MOD1_MASK)
+          *p++ = '\033';
+      }
+    append_erase (term->delete_binding, &p);
     break;
   case GDK_KP_Delete:
     p+=sprintf (p, "\033[3~");
@@ -3439,8 +3508,22 @@ zvt_term_real_selection_changed (ZvtTerm
  * zvt_term_set_del_key_swap:
  * @term:   A &ZvtTerm widget.
  * @state:  If true it swaps the del/backspace definitions
+ *          from the broken defaults to another broken setting
  *
- * Sets the mode for interpreting the DEL and Backspace keys.
+ * Sets the mode for interpreting the Delete and Backspace keys.  If
+ * @state is %TRUE, equivalent to setting the delete binding to
+ * #ZVT_ERASE_CONTROL_H and backspace to #ZVT_ERASE_ASCII_DEL.  If
+ * %FALSE, the keys are set to swapped values. If
+ * zvt_term_set_del_is_del() has been called to set the "del_is_del"
+ * setting to %FALSE, Delete will always be #ZVT_ERASE_ESCAPE_SEQUENCE
+ * rather than one of the ASCII characters.
+ *
+ * The correct defaults are #ZVT_ERASE_ASCII_DEL for the Backspace
+ * key, and #ZVT_ERASE_ESCAPE_SEQUENCE for the Delete key. Any app
+ * using ZvtTerm should set these, because ZvtTerm itself has
+ * the wrong defaults for historical reasons. It's best to use
+ * zvt_term_set_delete_binding() and zvt_term_set_backspace_binding()
+ * instead of this function.
  **/
 void
 zvt_term_set_del_key_swap (ZvtTerm *term, int state)
@@ -3449,14 +3532,41 @@ zvt_term_set_del_key_swap (ZvtTerm *term
   g_return_if_fail (ZVT_IS_TERM (term));

   term->swap_del_key = state != 0;
+  if (term->swap_del_key)
+    {
+      zvt_term_set_backspace_binding (term, ZVT_ERASE_ASCII_DEL);
+      if (term->del_is_del)
+        zvt_term_set_delete_binding (term, ZVT_ERASE_CONTROL_H);
+      else
+        zvt_term_set_delete_binding (term, ZVT_ERASE_ESCAPE_SEQUENCE);
+    }
+  else
+    {
+      zvt_term_set_backspace_binding (term, ZVT_ERASE_CONTROL_H);
+      if (term->del_is_del)
+        zvt_term_set_delete_binding (term, ZVT_ERASE_ASCII_DEL);
+      else
+        zvt_term_set_delete_binding (term, ZVT_ERASE_ESCAPE_SEQUENCE);
+    }
 }

 /**
  * zvt_term_set_del_is_del:
  * @term:   A &ZvtTerm widget.
- * @state:  If true it uses DEL/^H for Delete key
+ * @state:  %FALSE if delete key sends an escape sequence
+ *
+ * If @state is %TRUE, then the Delete key sends %ZVT_ERASE_ASCII_DEL if
+ * delete and backspace aren't swapped, and %ZVT_ERASE_CONTROL_H if they
+ * are swapped. If @state is %FALSE then the Delete key always sends
+ * %ZVT_ERASE_ESCAPE_SEQUENCE.
+ *
+ * The correct defaults are #ZVT_ERASE_ASCII_DEL for the Backspace
+ * key, and #ZVT_ERASE_ESCAPE_SEQUENCE for the Delete key. Any app
+ * using ZvtTerm should set these, because ZvtTerm itself has
+ * the wrong defaults for historical reasons. It's best to use
+ * zvt_term_set_delete_binding() and zvt_term_set_backspace_binding()
+ * instead of this function.
  *
- * Sets Delete code to DEL/^H or Esc[3~ sequences.
  **/
 void
 zvt_term_set_del_is_del (ZvtTerm *term, int state)
@@ -3465,6 +3575,18 @@ zvt_term_set_del_is_del (ZvtTerm *term,
   g_return_if_fail (ZVT_IS_TERM (term));

   term->del_is_del = state != 0;
+
+  if (term->del_is_del)
+    {
+      if (term->swap_del_key)
+        zvt_term_set_delete_binding (term, ZVT_ERASE_CONTROL_H);
+      else
+        zvt_term_set_delete_binding (term, ZVT_ERASE_ASCII_DEL);
+    }
+  else
+    {
+      zvt_term_set_delete_binding (term, ZVT_ERASE_ESCAPE_SEQUENCE);
+    }
 }

 /*





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