Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 83 additions & 8 deletions guake/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

gi.require_version("Vte", "2.91") # vte-0.42
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import GObject
from gi.repository import Gdk
from gi.repository import Gio
Expand Down Expand Up @@ -43,6 +44,15 @@ def iter_terminals(self):
def replace_child(self, old, new):
raise NotImplementedError

def get_child_position(self, child):
raise NotImplementedError

def detach_child(self, child, temporary_parent):
raise NotImplementedError

def attach_detached_child(self, position, child):
raise NotImplementedError

def get_guake(self):
raise NotImplementedError

Expand Down Expand Up @@ -170,10 +180,17 @@ def iter_terminals(self):
yield from self.get_child().iter_terminals()

def replace_child(self, old, new):
position = self.get_child_position(old)
self.remove(old)
self.set_child(new)
self.child = None
self._set_child_at_position(position, new)

def set_child(self, terminal_holder):
self._set_child_at_position(0, terminal_holder)

def _set_child_at_position(self, position, terminal_holder):
if position != 0:
raise RuntimeError(f"Error adding child at root position {position}")
if isinstance(terminal_holder, TerminalHolder):
self.child = terminal_holder
self.add(self.child)
Expand All @@ -183,6 +200,23 @@ def set_child(self, terminal_holder):
def get_child(self):
return self.child

def get_child_position(self, child):
if self.child is child:
return 0
raise RuntimeError("RootTerminalBox: unknown child")

def detach_child(self, child, temporary_parent):
position = self.get_child_position(child)
child.reparent(temporary_parent)
self.child = None
return position

def attach_detached_child(self, position, child):
if position != 0:
raise RuntimeError(f"Error adding child at root position {position}")
self.child = child
child.reparent(self)

def get_guake(self):
return self.guake

Expand Down Expand Up @@ -587,14 +621,32 @@ def iter_terminals(self):
yield from self.get_child2().iter_terminals()

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)
position = self.get_child_position(old)
self.remove(old)
self._set_child_at_position(position, new)

def get_child_position(self, child):
if self.get_child1() is child:
return 1
if self.get_child2() is child:
return 2
raise RuntimeError("DualTerminalBox: unknown child")

def detach_child(self, child, temporary_parent):
position = self.get_child_position(child)
child.reparent(temporary_parent)
return position

def attach_detached_child(self, position, child):
child.reparent(self)

def _set_child_at_position(self, position, child):
if position == 1:
self.set_child_first(child)
elif position == 2:
self.set_child_second(child)
else:
print("I have never seen this widget!")
raise RuntimeError(f"DualTerminalBox: unknown child position {position}")

def get_guake(self):
return self.get_parent().get_guake()
Expand Down Expand Up @@ -636,6 +688,29 @@ def remove_dead_child(self, child):
print("I have never seen this widget!")


@save_tabs_when_changed
def swap_terminal_boxes(first, second):
if first is second:
return

temporary_parent = Gtk.Box()
first_parent = first.get_parent()
second_parent = second.get_parent()
first_position = first_parent.detach_child(first, temporary_parent)
second_position = second_parent.detach_child(second, temporary_parent)

if first_parent is second_parent:
reattachments = (
(first_position, second),
(second_position, first),
)
for position, child in sorted(reattachments, key=lambda item: item[0]):
first_parent.attach_detached_child(position, child)
else:
first_parent.attach_detached_child(first_position, second)
second_parent.attach_detached_child(second_position, first)


class TabLabelEventBox(Gtk.EventBox):
def __init__(self, notebook, text, settings):
super().__init__()
Expand Down
21 changes: 21 additions & 0 deletions guake/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import gi

gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk
from gi.repository import Gtk
from guake.about import AboutDialog
Expand Down Expand Up @@ -93,6 +94,26 @@ def on_split_vertical(self, *args):
def on_split_horizontal(self, *args):
self.terminal.get_parent().split_h(50)

def on_move_pane_up(self, *args):
from guake.split_utils import PaneMover

PaneMover(self.window).move_up(self.terminal)

def on_move_pane_down(self, *args):
from guake.split_utils import PaneMover

PaneMover(self.window).move_down(self.terminal)

def on_move_pane_left(self, *args):
from guake.split_utils import PaneMover

PaneMover(self.window).move_left(self.terminal)

def on_move_pane_right(self, *args):
from guake.split_utils import PaneMover

PaneMover(self.window).move_right(self.terminal)

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

Expand Down
20 changes: 20 additions & 0 deletions guake/data/org.guake.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,26 @@
<summary>Focus terminal on the left.</summary>
<description>Focus terminal on the left.</description>
</key>
<key name="move-terminal-pane-up" type="s">
<default>''</default>
<summary>Move terminal pane up.</summary>
<description>Move terminal pane up.</description>
</key>
<key name="move-terminal-pane-down" type="s">
<default>''</default>
<summary>Move terminal pane down.</summary>
<description>Move terminal pane down.</description>
</key>
<key name="move-terminal-pane-left" type="s">
<default>''</default>
<summary>Move terminal pane left.</summary>
<description>Move terminal pane left.</description>
</key>
<key name="move-terminal-pane-right" type="s">
<default>''</default>
<summary>Move terminal pane right.</summary>
<description>Move terminal pane right.</description>
</key>
<key name="move-terminal-split-up" type="s">
<default>''</default>
<summary>Move the terminal split handle up.</summary>
Expand Down
38 changes: 38 additions & 0 deletions guake/keybindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import gi

gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk
from gi.repository import Gtk

from guake import notifier
from guake.common import pixmapfile
from guake.split_utils import FocusMover
from guake.split_utils import PaneMover
from guake.split_utils import SplitMover

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -157,6 +159,42 @@ def x(*args):
or True
),
),
(
"move-terminal-pane-up",
(
lambda *args: PaneMover(self.guake.window).move_up(
self.guake.get_notebook().get_current_terminal()
)
or True
),
),
(
"move-terminal-pane-down",
(
lambda *args: PaneMover(self.guake.window).move_down(
self.guake.get_notebook().get_current_terminal()
)
or True
),
),
(
"move-terminal-pane-left",
(
lambda *args: PaneMover(self.guake.window).move_left(
self.guake.get_notebook().get_current_terminal()
)
or True
),
),
(
"move-terminal-pane-right",
(
lambda *args: PaneMover(self.guake.window).move_right(
self.guake.get_notebook().get_current_terminal()
)
or True
),
),
(
"move-terminal-split-up",
(
Expand Down
14 changes: 14 additions & 0 deletions guake/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ def mk_terminal_context_menu(terminal, window, settings, callback_object):
mi = Gtk.MenuItem(_("Split |"))
mi.connect("activate", callback_object.on_split_vertical)
menu.add(mi)
menu.add(Gtk.SeparatorMenuItem())
mi = Gtk.MenuItem(_("Move pane up"))
mi.connect("activate", callback_object.on_move_pane_up)
menu.add(mi)
mi = Gtk.MenuItem(_("Move pane down"))
mi.connect("activate", callback_object.on_move_pane_down)
menu.add(mi)
mi = Gtk.MenuItem(_("Move pane left"))
mi.connect("activate", callback_object.on_move_pane_left)
menu.add(mi)
mi = Gtk.MenuItem(_("Move pane right"))
mi.connect("activate", callback_object.on_move_pane_right)
menu.add(mi)
menu.add(Gtk.SeparatorMenuItem())
mi = Gtk.MenuItem(_("Close terminal"))
mi.connect("activate", callback_object.on_close_terminal)
menu.add(mi)
Expand Down
5 changes: 5 additions & 0 deletions guake/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import gi

gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
gi.require_version("Vte", "2.91") # vte-0.38
from gi.repository import GLib
from gi.repository import Gdk
Expand Down Expand Up @@ -120,6 +121,10 @@
{"key": "focus-terminal-down", "label": _("Focus terminal below")},
{"key": "focus-terminal-left", "label": _("Focus terminal on the left")},
{"key": "focus-terminal-right", "label": _("Focus terminal on the right")},
{"key": "move-terminal-pane-up", "label": _("Move terminal pane up")},
{"key": "move-terminal-pane-down", "label": _("Move terminal pane down")},
{"key": "move-terminal-pane-left", "label": _("Move terminal pane left")},
{"key": "move-terminal-pane-right", "label": _("Move terminal pane right")},
{
"key": "move-terminal-split-up",
"label": _("Move the terminal split handle up"),
Expand Down
Loading