Skip to content

Commit

Permalink
split terminal
Browse files Browse the repository at this point in the history
sem-ver: feature
  • Loading branch information
aichingm authored and gsemet committed Sep 21, 2018
1 parent 7665e4e commit 04e3c58
Show file tree
Hide file tree
Showing 11 changed files with 502 additions and 46 deletions.
55 changes: 55 additions & 0 deletions data/org.guake.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,61 @@
<summary>Last tab.</summary>
<description>Switch to the last tab.</description>
</key>
<key name="split-tab-vertical" type="s">
<default>'&lt;Super&gt;less'</default>
<summary>Split tab vertical.</summary>
<description>Split tab vertical.</description>
</key>
<key name="split-tab-horizontal" type="s">
<default>'&lt;Super&gt;minus'</default>
<summary>Split tab horizontal.</summary>
<description>Split tab horizontal.</description>
</key>
<key name="close-terminal" type="s">
<default>'&lt;Super&gt;x'</default>
<summary>Close terminal.</summary>
<description>Close the currently focused terminal.</description>
</key>
<key name="focus-terminal-up" type="s">
<default>'&lt;Super&gt;&lt;Shift&gt;Up'</default>
<summary>Focus terminal above.</summary>
<description>Focus terminal above.</description>
</key>
<key name="focus-terminal-down" type="s">
<default>'&lt;Super&gt;&lt;Shift&gt;Down'</default>
<summary>Focus terminal below.</summary>
<description>Focus terminal below.</description>
</key>
<key name="focus-terminal-right" type="s">
<default>'&lt;Super&gt;&lt;Shift&gt;Right'</default>
<summary>Focus terminal on the right.</summary>
<description>Focus terminal on the right.</description>
</key>
<key name="focus-terminal-left" type="s">
<default>'&lt;Super&gt;&lt;Shift&gt;Left'</default>
<summary>Focus terminal on the left.</summary>
<description>Focus terminal on the left.</description>
</key>
<key name="move-terminal-split-up" type="s">
<default>''</default>
<summary>Move the terminal split handle up.</summary>
<description>Move the terminal split handle up.</description>
</key>
<key name="move-terminal-split-down" type="s">
<default>''</default>
<summary>Move the terminal split handle down.</summary>
<description>Move the terminal split handle down.</description>
</key>
<key name="move-terminal-split-left" type="s">
<default>''</default>
<summary>Move the terminal split handle left.</summary>
<description>Move the terminal split handle left.</description>
</key>
<key name="move-terminal-split-right" type="s">
<default>''</default>
<summary>Move the terminal split handle right.</summary>
<description>Move the terminal split handle right.</description>
</key>
</schema>
<schema id="guake.hooks" path="/apps/guake/hooks/">
<key name="show" type="s">
Expand Down
84 changes: 76 additions & 8 deletions guake/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@


class TerminalHolder():
UP = 0
DOWN = 1
RIGHT = 2
LEFT = 3

def get_terminals(self):
pass
Expand All @@ -45,6 +49,12 @@ def get_settings(self):
def get_root_box(self):
pass

def get_notebook(self):
pass

def remove_dead_child(self, child):
pass


class RootTerminalBox(Gtk.Box, TerminalHolder):

Expand All @@ -64,7 +74,7 @@ def iter_terminals(self):

def replace_child(self, old, new):
self.remove(old)
self.set_child(new_child)
self.set_child(new)

def set_child(self, terminal_holder):
if isinstance(terminal_holder, TerminalHolder) or True:
Expand Down Expand Up @@ -99,6 +109,19 @@ def set_last_terminal_focused(self, terminal):
self.last_terminal_focused = terminal
self.guake.notebook.set_last_terminal_focused(terminal)

def get_last_terminal_focused(self, terminal):
return self.last_terminal_focused

def get_notebook(self):
return self.guake.notebook

def remove_dead_child(self, child):
page_num = self.guake.notebook.page_num(self)
self.guake.notebook.remove_page(page_num)

def move_focus(self, direction, fromChild):
pass


class TerminalBox(Gtk.Box, TerminalHolder):

Expand All @@ -117,6 +140,8 @@ def set_terminal(self, terminal):
self.terminal = terminal
self.terminal.connect("grab-focus", self.on_terminal_focus)
self.terminal.connect("button-press-event", self.on_button_press, None)
self.terminal.connect('child-exited', self.on_terminal_exited)

self.pack_start(self.terminal, True, True, 0)
self.terminal.show()
self.add_scroll_bar()
Expand Down Expand Up @@ -149,17 +174,31 @@ def unset_terminal(self, *args):
self.terminal = None

def split_h(self):
self.split(DualTerminalBox.ORIENT_H)
self.split(DualTerminalBox.ORIENT_V)

def split_v(self):
self.split(DualTerminalBox.ORIENT_V)
self.split(DualTerminalBox.ORIENT_H)

def split(self, orientation):
print("in split")
notebook = self.get_notebook()
parent = self.get_parent()
if orientation == DualTerminalBox.ORIENT_H:
position = self.get_allocation().width / 2
else:
position = self.get_allocation().height / 2

terminal_box = TerminalBox()
terminal = notebook.terminal_spawn()
terminal_box.set_terminal(terminal)
dual_terminal_box = DualTerminalBox(orientation)
dual_terminal_box.set_position(position)
parent.replace_child(self, dual_terminal_box)
dual_terminal_box.set_child_first(self)
dual_terminal_box.set_child_second(GuakeTerminal())
dual_terminal_box.set_child_second(terminal_box)
dual_terminal_box.show()
dual_terminal_box.show_all()
notebook.terminal_attached(terminal)

def get_guake(self):
return self.get_parent().get_guake()
Expand All @@ -171,11 +210,20 @@ def get_settings(self):
return self.get_parent().get_settings()

def get_root_box(self):
return self.get_parent()
return self.get_parent().get_root_box()

def get_notebook(self):
return self.get_parent().get_notebook()

def remove_dead_child(self, child):
print("Can't do, have no \"child\"")

def on_terminal_focus(self, *args):
self.get_root_box().set_last_terminal_focused(self.terminal)

def on_terminal_exited(self, *args):
self.get_parent().remove_dead_child(self)

def on_button_press(self, target, event, user_data):
if event.button == 3:
# First send to background process if handled, do nothing else
Expand Down Expand Up @@ -211,6 +259,7 @@ class DualTerminalBox(Gtk.Paned, TerminalHolder):
def __init__(self, orientation):
super().__init__()

self.orient = orientation
if orientation is DualTerminalBox.ORIENT_H:
self.set_orientation(orientation=Gtk.Orientation.HORIZONTAL)
else:
Expand All @@ -232,13 +281,17 @@ def get_terminals(self):
return self.get_child1().get_terminals() + self.get_child2().get_terminals()

def iter_terminals(self):
self.get_child1().iter_terminals(self)
self.get_child2().iter_terminals(self)
for t in self.get_child1().iter_terminals():
yield t
for t in self.get_child2().iter_terminals():
yield t

def replace_child(self, old, new):
if self.get_child1() is old:
self.remove(old)
self.set_child_first(new)
elif self.get_child2() is old:
self.remove(old)
self.set_child_second(new)
else:
print("I have never seen this widget!")
Expand All @@ -253,7 +306,22 @@ def get_settings(self):
return self.get_parent().get_settings()

def get_root_box(self):
return self.get_parent()
return self.get_parent().get_root_box()

def get_notebook(self):
return self.get_parent().get_notebook()

def remove_dead_child(self, child):
if self.get_child1() is child:
livingChild = self.get_child2()
self.remove(livingChild)
self.get_parent().replace_child(self, livingChild)
elif self.get_child2() is child:
livingChild = self.get_child1()
self.remove(livingChild)
self.get_parent().replace_child(self, livingChild)
else:
print("I have never seen this widget!")


class TabLabelEventBox(Gtk.EventBox):
Expand Down
9 changes: 9 additions & 0 deletions guake/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ def on_show_about(self, *args):
def on_quit(self, *args):
self.notebook.guake.accel_quit()

def on_split_vertical(self, *args):
self.terminal.get_parent().split_v()

def on_split_horizontal(self, *args):
self.terminal.get_parent().split_h()

def on_close_terminal(self, *args):
self.terminal.kill()


class NotebookScrollCallback():

Expand Down
30 changes: 5 additions & 25 deletions guake/guake_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,8 @@ def execute_command(self, command, tab=None):
if command[-1] != '\n':
command += '\n'

index = self.notebook.get_current_page()
index = tab or self.notebook.get_current_page()
for terminal in self.notebook.get_terminals_for_page(index): # TODO NOTEBOOK
# this is a stupid quick fix I did while rewriting the notebook to
# make it work some how but running the command on all terminals in a
# page might be a bad idea...
terminal.feed_child(command)
break
terminal = self.notebook.get_last_terminal_focused()
terminal.feed_child(command)

def execute_command_by_uuid(self, tab_uuid, command):
# TODO DBUS_ONLY
Expand Down Expand Up @@ -437,6 +431,7 @@ def show_prefs(self, *args):
PrefsDialog(self.settings).show()

def is_iconified(self):
# TODO this is "dead" code only gets called to log output or in out commented code
if self.window:
cur_state = int(self.window.get_state())
return bool(cur_state & GDK_WINDOW_STATE_ICONIFIED)
Expand Down Expand Up @@ -711,11 +706,10 @@ def accel_quit(self, *args):
def accel_reset_terminal(self, *args):
# TODO KEYBINDINGS ONLY
"""Callback to reset and clean the terminal"""
# TODO PREVENTHIDE remove
# self.preventHide = True
HidePrevention(self.window).prevent()
current_term = self.notebook.get_current_terminal()
current_term.reset(True, True)
# self.preventHide = False
HidePrevention(self.window).allow()
return True

def accel_zoom_in(self, *args):
Expand Down Expand Up @@ -878,19 +872,6 @@ def unfullscreen(self):

# -- callbacks --

def on_terminal_exited(self, term, status, term1):
"""When a terminal is closed, shell process should be killed,
this is the method that does that, or, at least calls
`delete_tab' method to do the work.
"""
log.debug("Terminal exited: %s", term)
page_num = self.notebook.find_page_index_by_terminal(term)
# if page_num is -1 it means that the terminal is already removed from the
# page (or its children) and that the terminal-destroy was triggered by a
# TerminalNotebook.delete_page call, so skill deleting the page
if page_num != -1:
self.notebook.delete_page(page_num, kill=False, prompt=False)

def recompute_tabs_titles(self):
"""Updates labels on all tabs. This is required when `self.abbreviate`
changes
Expand Down Expand Up @@ -975,7 +956,6 @@ def rename_current_tab(self, new_text, user_set=False):

def terminal_spawned(self, notebook, terminal, pid):
self.load_config()
terminal.connect('child-exited', self.on_terminal_exited, terminal)
terminal.connect('window-title-changed', self.on_terminal_title_changed, terminal)

def add_tab(self, directory=None):
Expand Down
Loading

0 comments on commit 04e3c58

Please sign in to comment.