nakamura avatar nakamura committed f2f0e3a

[WIP] make Ctrl + Alt + h/j/k/l/Left/Down/Up/Right move terminal focus

Comments (0)

Files changed (1)

         self._eb.connect('button-release-event', self.do_eb_button_release)
         self._sync_check.connect('button-release-event',
                                  lambda *_: self.terminal.grab_focus())
+        self._sync_check.connect('focus-in-event',
+                                 lambda *_: self.terminal.grab_focus())
 
         self.terminal.connect('child-exited', self.do_terminal_child_exited)
         self.terminal.connect('key-press-event', self.do_terminal_key_press)
 
+        # to make child_focus work as expected
+        self.set_focus_chain([self.terminal])
+
     @property
     def width(self):
         xpad = 2 # border_width * 2
 
         self.connect('destroy', lambda *_: Gtk.main_quit())
 
-        # TODO: provide keyboard shortcut to move focus
         # TODO: highlights dffis of terminals
         # TODO: blur terminals that keyboard input will not send to
         # TODO: provide way to open new terminal
     def do_term_key_press(self, term_frame, event):
         keyname = Gdk.keyval_name(event.keyval)
 
+        if event.state == Gdk.ModifierType.CONTROL_MASK|Gdk.ModifierType.MOD1_MASK:
+            # Ctrl + Alt + ...
+            # TODO: scroll self._scrolled to selected terminal
+            if keyname in ('h', 'Left'):
+                self.child_focus(Gtk.DirectionType.LEFT)
+                return True
+
+            elif keyname in ('j', 'Down'):
+                self.child_focus(Gtk.DirectionType.DOWN)
+                return True
+
+            elif keyname in ('k', 'Up'):
+                self.child_focus(Gtk.DirectionType.UP)
+                return True
+
+            elif keyname in ('l', 'Right'):
+                self.child_focus(Gtk.DirectionType.RIGHT)
+                return True
+
+            elif keyname == 'w':
+                self.child_focus(Gtk.DirectionType.TAB_FORWARD)
+                return True
+
         # FIXME: wrap 80 chars
-        if event.state == Gdk.ModifierType.CONTROL_MASK|Gdk.ModifierType.MOD1_MASK|Gdk.ModifierType.SHIFT_MASK:
+        elif event.state == Gdk.ModifierType.CONTROL_MASK|Gdk.ModifierType.MOD1_MASK|Gdk.ModifierType.SHIFT_MASK:
             # Ctrl + Alt + Shift + ...
             if keyname == 'S':
                 self.sync_all(not term_frame.is_synced)
                 return True
 
+            elif keyname == 'W':
+                self.child_focus(Gtk.DirectionType.TAB_BACKWARD)
+                return True
+
     def sync_all(self, is_synced):
         for t in self.terminals:
             t.set_sync(is_synced)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.