Skip to content

Commit

Permalink
window: handle os-window vs layout resizes
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Williams <[email protected]>
  • Loading branch information
williamspatrick committed Jul 8, 2021
1 parent db60c80 commit d3bc9e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
26 changes: 16 additions & 10 deletions kitty/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,24 @@ def title_changed(self, window: Window) -> None:
if tm is not None:
tm.title_changed(self)

def resize_from_window(self, window: Window, x: int, y: int) -> None:
if len(self.windows) != 1:
log_error('Unable to resize layout-ed windows.')
return
def resize_from_window(self, window: Window, os_window: bool, layout_window: bool, x: int, y: int, dx_cells: int, dy_cells: int) -> None:
if os_window:
# If there are multiple windows we can only resize if requested
# to modify layouts also.
if len(self.windows) != 1 and not layout_window:
return

if window is not self.active_window:
log_error('Unable to resize inactive window.')
return
tm = self.tab_manager_ref()
if tm is not None:
resize_os_window(tm.os_window_id, x, y)

tm = self.tab_manager_ref()
if tm is not None:
resize_os_window(tm.os_window_id, x, y)
# Tabs will resize as part of window resize event.

elif layout_window:
if dx_cells:
self.resize_window_by(window.id, dx_cells, True)
if dy_cells:
self.resize_window_by(window.id, dy_cells, False)

def on_bell(self, window: Window) -> None:
self.mark_tab_bar_dirty()
Expand Down
14 changes: 10 additions & 4 deletions kitty/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,18 @@ def resize_from_escape(self, cells: bool, os_window: bool, layout_window: bool,
if t is None:
return

cell_width, cell_height = cell_size_for_window(self.os_window_id)

if cells:
cell_width, cell_height = cell_size_for_window(self.os_window_id)
x = x * cell_width
y = y * cell_height
x, y = max(x, 10), max(y, 2)
cells_x, cells_y = x, y
x, y = x * cell_width, y * cell_height
else:
x, y = max(x, cell_width*10), max(y, cell_height*2)
cells_x, cells_y = int(x / cells_width), int(y / cells_height)

t.resize_from_window(self, x, y)
g = self.geometry
t.resize_from_window(self, os_window, layout_window, x, y, cells_x - g.xnum, cells_y - g.ynum)

def contains(self, x: int, y: int) -> bool:
g = self.geometry
Expand Down

0 comments on commit d3bc9e9

Please sign in to comment.