From dbe8ab92563cb96fe594d9bc31ce619a9bb46aca Mon Sep 17 00:00:00 2001 From: Tuomas Kangas Date: Fri, 13 Oct 2023 11:16:18 +0300 Subject: [PATCH] feat: Allow splitting terminal to specific size --- guake/boxes.py | 26 +++++++------- guake/callbacks.py | 4 +-- guake/dbusiface.py | 24 ++++++------- guake/main.py | 36 +++++++++++++------ .../command_improvement-e7fcdf2a28c0e488.yaml | 6 ++++ .../notes/save_zoom-8b8f54485b975e7c.yaml | 3 +- 6 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 releasenotes/notes/command_improvement-e7fcdf2a28c0e488.yaml diff --git a/guake/boxes.py b/guake/boxes.py index 5df32448a..5233b0cf9 100644 --- a/guake/boxes.py +++ b/guake/boxes.py @@ -456,30 +456,30 @@ def replace_child(self, old, new): def unset_terminal(self, *args): self.terminal = None - def split_h(self): - return self.split(DualTerminalBox.ORIENT_V) + def split_h(self, split_percentage: int = 50): + return self.split(DualTerminalBox.ORIENT_V, split_percentage) - def split_v(self): - return self.split(DualTerminalBox.ORIENT_H) + def split_v(self, split_percentage: int = 50): + return self.split(DualTerminalBox.ORIENT_H, split_percentage) - def split_h_no_save(self): - return self.split_no_save(DualTerminalBox.ORIENT_V) + def split_h_no_save(self, split_percentage: int = 50): + return self.split_no_save(DualTerminalBox.ORIENT_V, split_percentage) - def split_v_no_save(self): - return self.split_no_save(DualTerminalBox.ORIENT_H) + def split_v_no_save(self, split_percentage: int = 50): + return self.split_no_save(DualTerminalBox.ORIENT_H, split_percentage) @save_tabs_when_changed - def split(self, orientation): - self.split_no_save(orientation) + def split(self, orientation, split_percentage: int = 50): + self.split_no_save(orientation, split_percentage) - def split_no_save(self, orientation): + def split_no_save(self, orientation, split_percentage: int = 50): notebook = self.get_notebook() parent = self.get_parent() # RootTerminalBox if orientation == DualTerminalBox.ORIENT_H: - position = self.get_allocation().width / 2 + position = self.get_allocation().width * ((100 - split_percentage) / 100) else: - position = self.get_allocation().height / 2 + position = self.get_allocation().height * ((100 - split_percentage) / 100) terminal_box = TerminalBox() terminal = notebook.terminal_spawn() diff --git a/guake/callbacks.py b/guake/callbacks.py index 7f8da5558..661625c9c 100644 --- a/guake/callbacks.py +++ b/guake/callbacks.py @@ -88,10 +88,10 @@ def on_quit(self, *args): self.notebook.guake.accel_quit() def on_split_vertical(self, *args): - self.terminal.get_parent().split_v() + self.terminal.get_parent().split_v(50) def on_split_horizontal(self, *args): - self.terminal.get_parent().split_h() + self.terminal.get_parent().split_h(50) def on_close_terminal(self, *args): self.terminal.kill() diff --git a/guake/dbusiface.py b/guake/dbusiface.py index fc7d939e0..0ee005a82 100755 --- a/guake/dbusiface.py +++ b/guake/dbusiface.py @@ -194,22 +194,22 @@ def get_gtktab_name(self, tab_index=0): def get_selected_uuidtab(self): return self.guake.get_selected_uuidtab() - @dbus.service.method(DBUS_NAME) - def v_split_current_terminal(self): - self.guake.get_notebook().get_current_terminal().get_parent().split_v() + @dbus.service.method(DBUS_NAME, in_signature="i") + def v_split_current_terminal(self, split_percentage: int): + self.guake.get_notebook().get_current_terminal().get_parent().split_v(split_percentage) - @dbus.service.method(DBUS_NAME) - def h_split_current_terminal(self): - self.guake.get_notebook().get_current_terminal().get_parent().split_h() + @dbus.service.method(DBUS_NAME, in_signature="i") + def h_split_current_terminal(self, split_percentage: int): + self.guake.get_notebook().get_current_terminal().get_parent().split_h(split_percentage) - @dbus.service.method(DBUS_NAME, in_signature="s") - def v_split_current_terminal_with_command(self, command): - self.guake.get_notebook().get_current_terminal().get_parent().split_v() + @dbus.service.method(DBUS_NAME, in_signature="si") + def v_split_current_terminal_with_command(self, command, split_percentage: int): + self.guake.get_notebook().get_current_terminal().get_parent().split_v(split_percentage) self.guake.execute_command(command) - @dbus.service.method(DBUS_NAME, in_signature="s") - def h_split_current_terminal_with_command(self, command): - self.guake.get_notebook().get_current_terminal().get_parent().split_h() + @dbus.service.method(DBUS_NAME, in_signature="si") + def h_split_current_terminal_with_command(self, command, split_percentage: int): + self.guake.get_notebook().get_current_terminal().get_parent().split_h(split_percentage) self.guake.execute_command(command) @dbus.service.method(DBUS_NAME, in_signature="s", out_signature="i") diff --git a/guake/main.py b/guake/main.py index 4058c6b2c..f26c02f2b 100644 --- a/guake/main.py +++ b/guake/main.py @@ -240,17 +240,29 @@ def main(): parser.add_argument( "--split-vertical", dest="split_vertical", - action="store_true", - default=False, - help=_("Split the selected tab vertically."), + metavar="SPLIT_PERCENTAGE", + action="store", + type=int, + nargs="?", + const=50, + default=None, + choices=range(1, 100), + help=_("Split the selected tab vertically. Optional input split percentage for the width."), ) parser.add_argument( "--split-horizontal", dest="split_horizontal", - action="store_true", - default=False, - help=_("Split the selected tab horizontally."), + metavar="SPLIT_PERCENTAGE", + action="store", + type=int, + nargs="?", + const=50, + default=None, + choices=range(1, 100), + help=_( + "Split the selected tab horizontally. Optional input split percentage for the height." + ), ) parser.add_argument( @@ -553,16 +565,20 @@ def main(): if options.split_vertical: if options.command: - remote_object.v_split_current_terminal_with_command(options.command) + remote_object.v_split_current_terminal_with_command( + options.command, options.split_vertical + ) else: - remote_object.v_split_current_terminal() + remote_object.v_split_current_terminal(options.split_vertical) only_show_hide = options.show if options.split_horizontal: if options.command: - remote_object.h_split_current_terminal_with_command(options.command) + remote_object.h_split_current_terminal_with_command( + options.command, options.split_horizontal + ) else: - remote_object.h_split_current_terminal() + remote_object.h_split_current_terminal(options.split_horizontal) only_show_hide = options.show if options.selected_terminal: diff --git a/releasenotes/notes/command_improvement-e7fcdf2a28c0e488.yaml b/releasenotes/notes/command_improvement-e7fcdf2a28c0e488.yaml new file mode 100644 index 000000000..dce6104a0 --- /dev/null +++ b/releasenotes/notes/command_improvement-e7fcdf2a28c0e488.yaml @@ -0,0 +1,6 @@ +release_summary: > + Improved terminal splitting: Optional specified percentage now reflects the new pane's size when using --split-vertical or --split-horizontal. + +features: + - | + - Allow splitting terminal to specific size with --split-vertical or --split-horizontal #1931 diff --git a/releasenotes/notes/save_zoom-8b8f54485b975e7c.yaml b/releasenotes/notes/save_zoom-8b8f54485b975e7c.yaml index bab2c8c7c..5ece697b8 100644 --- a/releasenotes/notes/save_zoom-8b8f54485b975e7c.yaml +++ b/releasenotes/notes/save_zoom-8b8f54485b975e7c.yaml @@ -3,5 +3,4 @@ release_summary: > fixes: - | - - Opening a new tab resets the zoom level/ #2109 - + - Opening a new tab resets the zoom level/ #2109