mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-16 13:08:25 +00:00
Allow resizing docks
Docks can now be resized in whole cells by dragging their inner border, with the resize_window action and with kitten @ resize-window, where wider or taller always means bigger whatever the edge of the dock. A dock keeps at least one cell and grows only into the content it is docked to, so the docks inside it are never shrunk. OS window docks do not shrink the tab docks of any tab, and when dragged, the other tabs are re-laid out once, at the end of the drag. Percentage sizes stay percentages. The new size is stored in the DockSpec, so it is reported by kitten @ ls and saved in sessions. Resetting window sizes does not change docks, as they are not part of the layout. Previously the inner border of a dock showed a resize pointer but dragging it did nothing, or in the Tall layout moved a layout divider. Fixes #10857
This commit is contained in:
parent
3fe8677c4d
commit
11cbfdce23
9 changed files with 328 additions and 7 deletions
|
|
@ -129,6 +129,10 @@ Detailed list of changes
|
|||
with :code:`launch --type=os-window-dock`. The dock is shown in every tab of
|
||||
the OS window, see :ref:`docks` (:iss:`10854`)
|
||||
|
||||
- Allow resizing docks by dragging their inner border or with the
|
||||
:ac:`resize_window` action and :code:`kitten @ resize-window`, see :ref:`docks`
|
||||
(:iss:`10857`)
|
||||
|
||||
- :doc:`Custom shaders <custom-shaders>`: Add ``screen-shake`` shaders that shake
|
||||
a window on bell and new events and uniforms for command start/finish and
|
||||
alternate screen enter/exit
|
||||
|
|
|
|||
|
|
@ -329,6 +329,15 @@ percentage of the window, tab or OS window being docked to. When there are sever
|
|||
at an edge, later docks are placed inside earlier ones. When there is not
|
||||
enough space for all the docks, the docks created last are made smaller first.
|
||||
|
||||
Docks can be resized in whole cells by dragging their inner border with the
|
||||
mouse, or with the :ac:`resize_window` action and :ref:`kitten @ resize-window
|
||||
<at-resize-window>`, where wider or taller always means bigger, whatever the
|
||||
edge of the dock. Only the size along the axis of the dock can be changed. A
|
||||
size that was a percentage stays a percentage. The new size is used from then
|
||||
on, including in :ref:`kitten @ ls <at-ls>` and in saved sessions. Resetting
|
||||
window sizes does not change the size of docks, as they are not part of the
|
||||
layout.
|
||||
|
||||
A :code:`window-dock` belongs to the window it is docked to. It is shown
|
||||
whenever that window is shown, moves with it when it is moved to another tab
|
||||
and is closed when it is closed. A :code:`tab-dock` is closed when the last
|
||||
|
|
|
|||
|
|
@ -3090,7 +3090,7 @@ class Boss:
|
|||
cell_height: int,
|
||||
) -> bool:
|
||||
if (w := self.window_id_map.get(window_id)) and (tab := w.tabref()):
|
||||
data = tab.current_layout.drag_resize_target_windows(w, x, y, edges, tab.windows)
|
||||
data = tab.drag_resize_target_windows(w, x, y, edges)
|
||||
if not edges & (LEFT_EDGE | RIGHT_EDGE):
|
||||
data = data._replace(horizontal_id=None)
|
||||
if not edges & (TOP_EDGE | BOTTOM_EDGE):
|
||||
|
|
@ -3124,20 +3124,21 @@ class Boss:
|
|||
step_x = int((x - r.initial_x) / r.cell_width) * mult
|
||||
dx = step_x - r.last_step_x
|
||||
if dx != 0:
|
||||
if applied := tab.drag_resize_window(h, dx, True):
|
||||
if applied := tab.drag_resize_window(h, dx, True, r.data.is_dock):
|
||||
self.drag_resize_of_window = r = r._replace(last_step_x=r.last_step_x + applied)
|
||||
if (v := r.data.vertical_id) is not None:
|
||||
mult = 1 if r.data.height_increases_downwards else -1
|
||||
step_y = int((y - r.initial_y) / r.cell_height) * mult
|
||||
dy = step_y - r.last_step_y
|
||||
if dy != 0:
|
||||
if applied := tab.drag_resize_window(v, dy, False):
|
||||
if applied := tab.drag_resize_window(v, dy, False, r.data.is_dock):
|
||||
self.drag_resize_of_window = r._replace(last_step_y=r.last_step_y + applied)
|
||||
|
||||
def drag_resize_end(self) -> None:
|
||||
if tab := self.tab_for_id(self.drag_resize_of_window.tab_id):
|
||||
for cw in tab:
|
||||
cw.pause_resize_notifications_to_child(pause=False)
|
||||
tab.drag_resize_ended(self.drag_resize_of_window.data)
|
||||
self.drag_resize_of_window = WindowResizeDrag()
|
||||
|
||||
def open_kitty_website(self) -> None:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ class BorderLine(NamedTuple):
|
|||
horizontal: bool = False
|
||||
|
||||
|
||||
class DockMetrics(NamedTuple):
|
||||
# The size of the dock, the room left for the content it is docked to and
|
||||
# the size of the area it is docked into, in pixels, along the axis of the dock
|
||||
size: int
|
||||
room: int
|
||||
total: int
|
||||
cell: int
|
||||
decoration: int
|
||||
|
||||
|
||||
class LayoutOpts:
|
||||
def __init__(self, data: dict[str, str]):
|
||||
pass
|
||||
|
|
@ -374,6 +384,8 @@ class Layout:
|
|||
self.blank_rects: list[Rect] = []
|
||||
self.tab_dock_placements: list[tuple[WindowGroup, Region]] = []
|
||||
self.os_window_dock_placements: list[tuple[WindowGroup, Region]] = []
|
||||
# The areas the OS window docks and the tab docks are carved from
|
||||
self.os_window_dock_area = self.tab_dock_area = region(0, 0, 0, 0)
|
||||
# The blank strips at the edges of the layout area when margins are collapsed
|
||||
self.collapsed_margin_rects: list[Rect] = []
|
||||
self.layout_opts = self.parse_layout_opts(layout_opts)
|
||||
|
|
@ -677,9 +689,11 @@ class Layout:
|
|||
# the layout. Space for the OS window docks is reserved even in the tabs
|
||||
# that do not currently host them, so that their windows are not resized
|
||||
# when switching tabs.
|
||||
self.os_window_dock_area = full_area
|
||||
tab_area, self.os_window_dock_placements = carve_docks(full_area, all_windows.os_window_docks, lgd.cell_width, lgd.cell_height)
|
||||
if not all_windows.hosts_os_window_docks:
|
||||
self.os_window_dock_placements = []
|
||||
self.tab_dock_area = tab_area
|
||||
lgd.central, self.tab_dock_placements = carve_docks(tab_area, all_windows.tab_docks, lgd.cell_width, lgd.cell_height)
|
||||
# Update lgd.draw_minimal_borders based on the current number of visible windows
|
||||
# and the draw_window_borders_for_single_window option
|
||||
|
|
@ -731,6 +745,89 @@ class Layout:
|
|||
for dock, area in placements:
|
||||
self.layout_docked_group(dock, area)
|
||||
|
||||
def tab_content_area(self, all_windows: WindowList) -> Region:
|
||||
"The area left for the layout after the OS window docks and the tab docks, as of the last call to _set_dimensions()"
|
||||
tab_area = carve_docks(self.os_window_dock_area, all_windows.os_window_docks, lgd.cell_width, lgd.cell_height)[0]
|
||||
return carve_docks(tab_area, all_windows.tab_docks, lgd.cell_width, lgd.cell_height)[0]
|
||||
|
||||
def room_for_os_window_docks(self, all_windows: WindowList, is_horizontal: bool) -> int:
|
||||
"The space along an axis that the OS window docks can grow into without shrinking the tab docks of this tab"
|
||||
self._set_dimensions(all_windows)
|
||||
content = self.tab_content_area(all_windows)
|
||||
return content.height if is_horizontal else content.width
|
||||
|
||||
def dock_metrics(self, all_windows: WindowList, dock: WindowGroup) -> DockMetrics | None:
|
||||
"The size of a docked group along its axis, as carved from the area it is docked into"
|
||||
if dock.dock is None:
|
||||
return None
|
||||
is_os_window_dock = False
|
||||
if (owner := all_windows.dock_owner(dock)) is not None:
|
||||
if owner.allocated_geometry is None:
|
||||
return None
|
||||
area, docks = outer_region_of(owner.allocated_geometry), owner.docks
|
||||
elif any(d is dock for d in all_windows.tab_docks):
|
||||
area, docks = self.tab_dock_area, all_windows.tab_docks
|
||||
elif any(d is dock for d in all_windows.hosted_os_window_docks()):
|
||||
area, docks, is_os_window_dock = self.os_window_dock_area, all_windows.os_window_docks, True
|
||||
else:
|
||||
return None
|
||||
content, placements = carve_docks(area, docks, lgd.cell_width, lgd.cell_height)
|
||||
r = next((r for g, r in placements if g is dock), None)
|
||||
if r is None:
|
||||
return None
|
||||
if is_os_window_dock:
|
||||
# The tab docks are inside the OS window docks, so only the area
|
||||
# left for the layout is room to grow into
|
||||
content = self.tab_content_area(all_windows)
|
||||
if dock.dock.is_horizontal:
|
||||
return DockMetrics(r.height, content.height, area.height, lgd.cell_height, dock.decoration('top') + dock.decoration('bottom'))
|
||||
return DockMetrics(r.width, content.width, area.width, lgd.cell_width, dock.decoration('left') + dock.decoration('right'))
|
||||
|
||||
def resize_dock(self, all_windows: WindowList, dock: WindowGroup, increment: int, fraction: float = 0, max_room: int | None = None) -> int:
|
||||
"""
|
||||
Resize a docked group along its axis by a number of cells, positive
|
||||
values make it bigger, whatever its edge. Returns the number of cells
|
||||
actually applied. A dock keeps at least one cell and grows only into the
|
||||
content it is docked to, which keeps space for at least one cell, so
|
||||
that the docks inside it are not shrunk. max_room further limits the
|
||||
number of pixels the dock can grow by. With a non-zero fraction, that
|
||||
fraction of the possible steps of size increment is taken, the last
|
||||
step being partial if needed.
|
||||
"""
|
||||
if (spec := dock.dock) is None or not increment:
|
||||
return 0
|
||||
# The layout global data is shared by all tabs, so refresh it
|
||||
self._set_dimensions(all_windows)
|
||||
if (m := self.dock_metrics(all_windows, dock)) is None or m.cell < 1:
|
||||
return 0
|
||||
cells = max(1, (m.size - m.decoration) // m.cell)
|
||||
if increment > 0:
|
||||
room = m.room if max_room is None else min(m.room, max_room)
|
||||
# Windows share their margin, border and padding settings, so the
|
||||
# decoration of the dock estimates that of the window(s) in the content
|
||||
limit = max(0, (room - m.decoration) // m.cell - 1)
|
||||
else:
|
||||
limit = cells - 1
|
||||
step = abs(increment)
|
||||
if fraction:
|
||||
steps = min(limit, fractional_resize_steps(ceil(limit / step), fraction) * step)
|
||||
else:
|
||||
steps = min(step, limit)
|
||||
if not steps:
|
||||
return 0
|
||||
applied = steps if increment > 0 else -steps
|
||||
if spec.size_is_percent:
|
||||
if m.total < 1:
|
||||
return 0
|
||||
# Aim for the middle of the pixel so that carve_docks() rounds down
|
||||
# to it. Rounding keeps the percentage exact when serialized, see
|
||||
# DockSpec.size_as_string, while staying within the pixel.
|
||||
pixels = (cells + applied) * m.cell + m.decoration
|
||||
dock.dock = spec._replace(size=min(100, round((pixels + 0.5) * 100 / m.total, 3)))
|
||||
else:
|
||||
dock.dock = spec._replace(size=cells + applied)
|
||||
return applied
|
||||
|
||||
def layout_docked_group(self, dock: WindowGroup, area: Region) -> None:
|
||||
xdecoration_pairs = ((dock.decoration('left'), dock.decoration('right')),)
|
||||
ydecoration_pairs = ((dock.decoration('top'), dock.decoration('bottom')),)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ class ResizeWindow(RemoteCommand):
|
|||
"""
|
||||
|
||||
short_desc = 'Resize the specified windows'
|
||||
desc = 'Resize the specified windows in the current layout. Note that not all layouts can resize all windows in all directions.'
|
||||
desc = (
|
||||
'Resize the specified windows in the current layout. Note that not all layouts can resize all windows in all directions.'
|
||||
' Docked windows are resized along the axis of their dock, with a positive increment making the dock bigger, whatever its edge.'
|
||||
)
|
||||
options_spec = (
|
||||
MATCH_WINDOW_OPTION
|
||||
+ """\n
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ from .layout.base import DragOverlayMode, Layout
|
|||
from .layout.interface import all_layouts, create_layout_object_for, evict_cached_layouts
|
||||
from .progress import ProgressState
|
||||
from .tab_bar import TabBar, TabBarData, WindowDropTarget, apply_title_template
|
||||
from .types import CloseEvent, DockSpec, ac
|
||||
from .types import CloseEvent, DockSpec, WindowResizeDragData, ac
|
||||
from .typing_compat import EdgeLiteral, SessionTab, SessionType, TypedDict
|
||||
from .utils import cmdline_for_hold, color_as_int, log_error, natsort_key, platform_window_id, resolved_shell, shlex_split, which
|
||||
from .window import CwdRequest, Watchers, Window, WindowCreationSpec, WindowDict, global_watchers
|
||||
|
|
@ -806,6 +806,11 @@ class Tab: # {{{
|
|||
self.goto_layout(layout_name)
|
||||
|
||||
def resize_window_by(self, window_id: int, increment: float, is_horizontal: bool, fraction: float = 0) -> str | None:
|
||||
if (dock := self.windows.dock_for_window_id(window_id)) is not None and dock.dock is not None:
|
||||
if is_horizontal == dock.dock.is_horizontal:
|
||||
which = 'taller or shorter' if dock.dock.is_horizontal else 'wider or narrower'
|
||||
return f'A dock at the {dock.dock.edge} edge can only be made {which}'
|
||||
return None if self.resize_dock(dock, increment, fraction) else 'Could not resize'
|
||||
increment_as_percent = self.current_layout.bias_increment_for_cell(self.windows, is_horizontal) * increment
|
||||
if fraction:
|
||||
changed = self.current_layout.modify_size_of_window_by_fraction(self.windows, window_id, increment_as_percent, is_horizontal, fraction)
|
||||
|
|
@ -816,11 +821,48 @@ class Tab: # {{{
|
|||
return None
|
||||
return 'Could not resize'
|
||||
|
||||
def drag_resize_window(self, object_id: int, increment: float, is_horizontal: bool) -> float:
|
||||
def resize_dock(self, dock: WindowGroup, increment: float, fraction: float = 0, relayout_other_tabs: bool = True) -> int:
|
||||
"Resize a docked group by a number of cells, see Layout.resize_dock()"
|
||||
# Round away from zero, so that fractional increments still resize
|
||||
cells = int(math.copysign(math.ceil(abs(increment)), increment))
|
||||
is_os_window_dock = self.windows.is_os_window_dock(dock)
|
||||
max_room: int | None = None
|
||||
if is_os_window_dock and cells > 0 and dock.dock is not None and (tm := self.tab_manager_ref()) is not None:
|
||||
# Growing an OS window dock must not shrink the tab docks of the other tabs either
|
||||
is_horizontal = dock.dock.is_horizontal
|
||||
max_room = min((t.current_layout.room_for_os_window_docks(t.windows, is_horizontal) for t in tm if t is not self), default=None)
|
||||
applied = self.current_layout.resize_dock(self.windows, dock, cells, fraction, max_room)
|
||||
if applied:
|
||||
self.relayout()
|
||||
if is_os_window_dock and relayout_other_tabs:
|
||||
self.os_window_docks_changed()
|
||||
return applied
|
||||
|
||||
def drag_resize_target_windows(self, window: Window, x: float, y: float, edges: int) -> WindowResizeDragData:
|
||||
if (dock := self.windows.dock_for_window_id(window.id)) is None or dock.dock is None:
|
||||
return self.current_layout.drag_resize_target_windows(window, x, y, edges, self.windows)
|
||||
# A dock has a border only on its inner edge, its outer edges stay put
|
||||
edge = dock.dock.edge
|
||||
if dock.dock.is_horizontal:
|
||||
return WindowResizeDragData(vertical_id=window.id, height_increases_downwards=edge == 'top', is_dock=True)
|
||||
return WindowResizeDragData(horizontal_id=window.id, width_increases_rightwards=edge == 'left', is_dock=True)
|
||||
|
||||
def drag_resize_window(self, object_id: int, increment: float, is_horizontal: bool, is_dock: bool = False) -> float:
|
||||
if is_dock:
|
||||
# The other tabs are re-laid out once, when the drag ends, see drag_resize_ended()
|
||||
dock = self.windows.dock_for_window_id(object_id)
|
||||
return 0 if dock is None else self.resize_dock(dock, increment, relayout_other_tabs=False)
|
||||
if resized := self.current_layout.drag_resize_window(self.windows, object_id, increment, is_horizontal):
|
||||
self.relayout()
|
||||
return resized
|
||||
|
||||
def drag_resize_ended(self, data: WindowResizeDragData) -> None:
|
||||
if data.is_dock:
|
||||
for wid in (data.horizontal_id, data.vertical_id):
|
||||
if wid is not None and (dock := self.windows.dock_for_window_id(wid)) is not None and self.windows.is_os_window_dock(dock):
|
||||
self.os_window_docks_changed()
|
||||
break
|
||||
|
||||
@ac(
|
||||
'win',
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -326,6 +326,8 @@ class WindowResizeDragData(NamedTuple):
|
|||
width_increases_rightwards: bool = True
|
||||
vertical_id: int | None = None
|
||||
height_increases_downwards: bool = True
|
||||
# The ids are window ids of a docked window, rather than layout specific ids
|
||||
is_dock: bool = False
|
||||
|
||||
|
||||
class WindowResizeDrag(NamedTuple):
|
||||
|
|
|
|||
|
|
@ -584,6 +584,12 @@ class WindowList:
|
|||
return g
|
||||
return None
|
||||
|
||||
def dock_for_window_id(self, window_id: int) -> WindowGroup | None:
|
||||
"The docked group containing the window, None if the window is not docked or not in this list"
|
||||
if (w := self.id_map.get(window_id)) is not None and (g := self.group_for_window(w)) is not None and g.dock is not None:
|
||||
return g
|
||||
return None
|
||||
|
||||
def group_for_id(self, gid: int) -> WindowGroup | None:
|
||||
for g in self.iter_all_groups():
|
||||
if g.id == gid:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
# License: GPL v3 Copyright: 2026, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from math import ceil
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from kitty.boss import Boss
|
||||
from kitty.fast_data_types import Region
|
||||
from kitty.fast_data_types import BOTTOM_EDGE, LEFT_EDGE, RIGHT_EDGE, TOP_EDGE, Region
|
||||
from kitty.layout.base import carve_docks, lgd, outer_region_of
|
||||
from kitty.layout.interface import Splits, Stack, Tall
|
||||
from kitty.tabs import DetachedGroup
|
||||
|
|
@ -64,6 +65,13 @@ class OSWindowTab:
|
|||
_last_used_layout = None
|
||||
_current_layout_name = ''
|
||||
take_over_from = RealTab.take_over_from
|
||||
os_window_docks_changed = RealTab.os_window_docks_changed
|
||||
resize_window_by = RealTab.resize_window_by
|
||||
resize_dock = RealTab.resize_dock
|
||||
drag_resize_window = RealTab.drag_resize_window
|
||||
drag_resize_target_windows = RealTab.drag_resize_target_windows
|
||||
drag_resize_ended = RealTab.drag_resize_ended
|
||||
reset_window_sizes = RealTab.reset_window_sizes
|
||||
|
||||
def mark_tab_bar_dirty(self):
|
||||
pass
|
||||
|
|
@ -97,6 +105,9 @@ class OSWindowTabManager:
|
|||
def __len__(self):
|
||||
return len(self.tabs)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.tabs)
|
||||
|
||||
|
||||
def make_layout(cls):
|
||||
ans = cls(1, 1)
|
||||
|
|
@ -673,3 +684,149 @@ class TestDocks(BaseTest):
|
|||
t1.windows.remove_window(top)
|
||||
t2.relayout()
|
||||
self.ae(rect(lgd.central), (0, 0, 1000, 300))
|
||||
|
||||
def test_resizing_docks(self):
|
||||
reset_group_id_counter()
|
||||
tm = OSWindowTabManager()
|
||||
self.patch_c_calls()
|
||||
t1, t2 = OSWindowTab(tm, 101, 1, 2), OSWindowTab(tm, 102, 3)
|
||||
tm.active_tab = t1
|
||||
tm.sync_os_window_docks()
|
||||
windows = t1.windows
|
||||
side = add_dock(t1.current_layout, windows, 10, 'left', '3')
|
||||
status = add_dock(t1.current_layout, windows, 11, 'bottom', '1', focusable=False)
|
||||
t1.relayout()
|
||||
layout_state = t1.current_layout.layout_state()
|
||||
|
||||
def spec(w):
|
||||
return windows.group_for_window(w).dock
|
||||
|
||||
def width(w):
|
||||
return outer_region_of(w.geometry).width
|
||||
|
||||
def height(w):
|
||||
return outer_region_of(w.geometry).height
|
||||
|
||||
# Docks resize along their axis only, wider means bigger whatever the edge
|
||||
self.assertIsNone(t1.resize_window_by(side.id, 2, True))
|
||||
self.ae(spec(side), DockSpec('left', 5, False, True))
|
||||
self.ae(width(side), 5 * CELL_WIDTH + 2 * DECORATION)
|
||||
self.assertIn('wider or narrower', t1.resize_window_by(side.id, 1, False))
|
||||
self.assertIn('taller or shorter', t1.resize_window_by(status.id, 1, True))
|
||||
self.assertIsNone(t1.resize_window_by(status.id, 2, False))
|
||||
self.ae(spec(status).size, 3)
|
||||
self.ae(height(status), 3 * CELL_HEIGHT + 2 * DECORATION)
|
||||
# A dock keeps at least one cell
|
||||
self.assertIsNone(t1.resize_window_by(side.id, -100, True))
|
||||
self.ae(spec(side).size, 1)
|
||||
self.ae(t1.resize_window_by(side.id, -1, True), 'Could not resize')
|
||||
# and grows only into the content, which keeps space for at least one cell
|
||||
self.assertIsNone(t1.resize_window_by(side.id, 1000, True))
|
||||
self.ae(rect(lgd.central)[2] - rect(lgd.central)[0], 1000 - width(side))
|
||||
self.assertGreaterEqual(1000 - width(side), CELL_WIDTH + 2 * DECORATION)
|
||||
self.assertLess(1000 - width(side), 2 * CELL_WIDTH + 2 * DECORATION)
|
||||
self.ae(t1.resize_window_by(side.id, 1, True), 'Could not resize')
|
||||
self.check_no_overlaps(windows)
|
||||
# Taking a fraction of the remaining steps
|
||||
self.assertIsNone(t1.resize_window_by(side.id, -1, True, fraction=1))
|
||||
self.ae(spec(side).size, 1)
|
||||
possible_steps = (1000 - width(side) - 2 * DECORATION) // CELL_WIDTH - 1
|
||||
self.assertIsNone(t1.resize_window_by(side.id, 1, True, fraction=0.5))
|
||||
self.ae(spec(side).size, 1 + (possible_steps + 1) // 2)
|
||||
# The increment is the size of the steps, the last one can be partial
|
||||
self.assertIsNone(t1.resize_window_by(side.id, -100, True))
|
||||
self.assertIsNone(t1.resize_window_by(side.id, 4, True, fraction=0.5))
|
||||
self.ae(spec(side).size, 1 + 4 * ceil(ceil(possible_steps / 4) / 2))
|
||||
self.assertIsNone(t1.resize_window_by(side.id, 40, True, fraction=1))
|
||||
self.ae(spec(side).size, 1 + possible_steps)
|
||||
# Fractional increments resize by at least a cell
|
||||
self.assertIsNone(t1.resize_window_by(side.id, -0.5, True))
|
||||
self.ae(spec(side).size, possible_steps)
|
||||
# Resizing docks does not change the layout and resetting the layout does not change docks
|
||||
self.ae(t1.current_layout.layout_state(), layout_state)
|
||||
t1.current_layout.modify_size_of_window(windows, 1, 0.1)
|
||||
self.assertNotEqual(t1.current_layout.layout_state(), layout_state)
|
||||
docks = spec(side), spec(status)
|
||||
t1.reset_window_sizes()
|
||||
self.ae(t1.current_layout.layout_state(), layout_state)
|
||||
self.ae((spec(side), spec(status)), docks)
|
||||
|
||||
self.assertIsNone(t1.resize_window_by(side.id, -100, True))
|
||||
# A percentage stays a percentage, of the area docked into, and is
|
||||
# resized in whole cells
|
||||
right = add_dock(t1.current_layout, windows, 12, 'right', '20%', owner=windows.groups[1])
|
||||
t1.relayout()
|
||||
owner_width = outer_region_of(windows.groups[1].allocated_geometry).width
|
||||
before = width(right)
|
||||
self.assertIsNone(t1.resize_window_by(right.id, 1, True))
|
||||
self.assertTrue(spec(right).size_is_percent)
|
||||
cells = (before - 2 * DECORATION) // CELL_WIDTH + 1
|
||||
self.ae(width(right), cells * CELL_WIDTH + 2 * DECORATION)
|
||||
self.ae(int(owner_width * spec(right).size / 100), width(right))
|
||||
# The new size is what is serialized
|
||||
self.ae(parse_dock_spec('right', windows.group_for_window(right).as_simple_dict()['dock']['size']), spec(right))
|
||||
self.check_no_overlaps(windows)
|
||||
|
||||
# Dragging the inner border of a dock
|
||||
boss = SimpleNamespace(window_id_map={w.id: w for w in windows}, tab_for_id=lambda tab_id: t1, drag_resize_of_window=None)
|
||||
for w in windows:
|
||||
w.tabref = lambda: t1
|
||||
w.pause_resize_notifications_to_child = lambda pause=True: None
|
||||
t1.current_layout.drag_resize_target_windows = Mock(side_effect=AssertionError('docks are not part of the layout'))
|
||||
start, update = Boss.drag_resize_start.__get__(boss), Boss.drag_resize_update.__get__(boss)
|
||||
self.ae(spec(side).size, 1)
|
||||
x = width(side)
|
||||
self.assertTrue(start(RIGHT_EDGE, x, 300, side.id, CELL_WIDTH, CELL_HEIGHT))
|
||||
update(x + 2.5 * CELL_WIDTH, 300)
|
||||
self.ae(spec(side).size, 3)
|
||||
update(x - 5 * CELL_WIDTH, 300)
|
||||
self.ae(spec(side).size, 1)
|
||||
# coming back out of the minimum keeps the border locked to the pointer
|
||||
update(x + CELL_WIDTH, 300)
|
||||
self.ae(spec(side).size, 2)
|
||||
y = outer_region_of(status.geometry).top
|
||||
size = spec(status).size
|
||||
self.assertTrue(start(TOP_EDGE, 500, y, status.id, CELL_WIDTH, CELL_HEIGHT))
|
||||
update(500, y - 2 * CELL_HEIGHT)
|
||||
self.ae(spec(status).size, size + 2)
|
||||
before = width(right)
|
||||
self.assertTrue(start(LEFT_EDGE, 900, 100, right.id, CELL_WIDTH, CELL_HEIGHT))
|
||||
update(900 - CELL_WIDTH, 100)
|
||||
self.ae(width(right), ((before - 2 * DECORATION) // CELL_WIDTH + 1) * CELL_WIDTH + 2 * DECORATION)
|
||||
t1.current_layout.drag_resize_target_windows.assert_not_called()
|
||||
|
||||
# Resizing an OS window dock changes the space reserved for it in every
|
||||
# tab and does not shrink the tab docks of any tab
|
||||
t1.current_layout.drag_resize_target_windows.reset_mock()
|
||||
os_dock = add_os_window_dock(t1, 20, 'top', '1')
|
||||
other_status = add_dock(t2.current_layout, t2.windows, 30, 'bottom', '10')
|
||||
t1.relayout(), t2.relayout()
|
||||
self.ae(rect(lgd.central)[1], CELL_HEIGHT + 2 * DECORATION)
|
||||
self.assertIsNone(t1.resize_window_by(os_dock.id, 1, False))
|
||||
self.ae(spec(os_dock).size, 2)
|
||||
self.ae(rect(lgd.central)[1], 2 * CELL_HEIGHT + 2 * DECORATION)
|
||||
self.ae(height(os_dock), 2 * CELL_HEIGHT + 2 * DECORATION)
|
||||
status_height, other_status_height = height(status), height(other_status)
|
||||
self.assertIsNone(t1.resize_window_by(os_dock.id, 1000, False))
|
||||
t1.relayout()
|
||||
self.ae(height(status), status_height)
|
||||
t2.relayout()
|
||||
self.ae(height(other_status), other_status_height)
|
||||
self.assertGreaterEqual(rect(lgd.central)[3] - rect(lgd.central)[1], CELL_HEIGHT + 2 * DECORATION)
|
||||
self.assertLess(rect(lgd.central)[3] - rect(lgd.central)[1], 2 * CELL_HEIGHT + 2 * DECORATION)
|
||||
# Dragging it re-lays out the other tabs only once, when the drag ends
|
||||
self.assertIsNone(t1.resize_window_by(os_dock.id, -1000, False))
|
||||
boss.window_id_map[os_dock.id] = os_dock
|
||||
os_dock.tabref = lambda: t1
|
||||
os_dock.pause_resize_notifications_to_child = lambda pause=True: None
|
||||
t2.relayout = Mock(side_effect=t2.relayout)
|
||||
# The dock is at the top of the OS window, so its inner border is at its height
|
||||
y = height(os_dock)
|
||||
self.assertTrue(start(BOTTOM_EDGE, 500, y, os_dock.id, CELL_WIDTH, CELL_HEIGHT))
|
||||
for i in range(1, 4):
|
||||
update(500, y + i * CELL_HEIGHT)
|
||||
self.ae(spec(os_dock).size, 4)
|
||||
t2.relayout.assert_not_called()
|
||||
Boss.drag_resize_end.__get__(boss)()
|
||||
t2.relayout.assert_called_once()
|
||||
t1.current_layout.drag_resize_target_windows.assert_not_called()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue