[vte/wip/egmont/bidi: 7/8] emulation, bidi: Add keyboard swapping mode



commit 59b2c548a4263f39d4a979c6ee19df4f58af727b
Author: Egmont Koblinger <egmont gmail com>
Date:   Sat Jun 1 15:58:52 2019 +0200

    emulation,bidi: Add keyboard swapping mode
    
    If the corresponding mode is enabled and the cursor stands within an
    RTL paragraph, the Left and Right keys of the keyboard swap their
    generated escape sequence.

 src/vte.cc | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
---
diff --git a/src/vte.cc b/src/vte.cc
index a4796b1c..7aaff76f 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -5090,6 +5090,38 @@ Terminal::widget_key_press(GdkEventKey *event)
                /* If the above switch statement didn't do the job, try mapping
                 * it to a literal or capability name. */
                 if (handled == FALSE) {
+                        if (G_UNLIKELY (m_modes_private.VTE_BIDI_SWAP_ARROW_KEYS() &&
+                                        (keyval == GDK_KEY_Left ||
+                                         keyval == GDK_KEY_Right ||
+                                         keyval == GDK_KEY_KP_Left ||
+                                         keyval == GDK_KEY_KP_Right))) {
+                                /* In keyboard arrow swapping mode, the left and right arrows are swapped
+                                 * if the cursor stands inside a (possibly autodetected) RTL paragraph.
+                                 * m_ringview is for the onscreen contents and the cursor may be offscreen.
+                                 * Better leave that alone and use a temporary ringview for the cursor's 
row. */
+                                vte::base::RingView ringview;
+                                ringview.set_ring(m_screen->row_data);
+                                ringview.set_rows(m_screen->cursor.row, 1);
+                                ringview.set_width(m_column_count);
+                                ringview.update();
+                                if (ringview.get_bidirow(m_screen->cursor.row)->base_is_rtl()) {
+                                        switch (keyval) {
+                                        case GDK_KEY_Left:
+                                                keyval = GDK_KEY_Right;
+                                                break;
+                                        case GDK_KEY_Right:
+                                                keyval = GDK_KEY_Left;
+                                                break;
+                                        case GDK_KEY_KP_Left:
+                                                keyval = GDK_KEY_KP_Right;
+                                                break;
+                                        case GDK_KEY_KP_Right:
+                                                keyval = GDK_KEY_KP_Left;
+                                                break;
+                                        }
+                                }
+                        }
+
                        _vte_keymap_map(keyval, m_modifiers,
                                         m_modes_private.DEC_APPLICATION_CURSOR_KEYS(),
                                         m_modes_private.DEC_APPLICATION_KEYPAD(),


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