Merge branch 'copilot/improve-window-dragging-feature' of https://github.com/kovidgoyal/kitty

This commit is contained in:
Kovid Goyal
2026-03-28 14:26:45 +05:30
3 changed files with 12 additions and 6 deletions

View File

@@ -201,6 +201,8 @@ Detailed list of changes
- Allow holding the :kbd:`Alt` key and triple-clicking to select from the first cell even if it is empty (:pull:`9758`) - Allow holding the :kbd:`Alt` key and triple-clicking to select from the first cell even if it is empty (:pull:`9758`)
- Window drag: Use a screenshot of the window contents as the drag thumbnail, just like tab dragging does
0.46.2 [2026-03-21] 0.46.2 [2026-03-21]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -1407,6 +1407,10 @@ class Boss:
if tm := self.os_window_map.get(os_window_id): if tm := self.os_window_map.get(os_window_id):
tm.start_tab_drag(pixels, width, height) tm.start_tab_drag(pixels, width, height)
def start_window_drag(self, os_window_id: int, window_id: int, pixels: bytes, width: int, height: int) -> None:
if tm := self.os_window_map.get(os_window_id):
tm.start_window_drag(pixels, width, height)
def on_window_resize(self, os_window_id: int, w: int, h: int, dpi_changed: bool) -> None: def on_window_resize(self, os_window_id: int, w: int, h: int, dpi_changed: bool) -> None:
if dpi_changed: if dpi_changed:
self.on_dpi_change(os_window_id) self.on_dpi_change(os_window_id)

View File

@@ -1812,7 +1812,7 @@ class TabManager: # {{{
dist_sq = (x - start_x)**2 + (y - start_y)**2 dist_sq = (x - start_x)**2 + (y - start_y)**2
if threshold and dist_sq > threshold * threshold: if threshold and dist_sq > threshold * threshold:
set_window_being_dragged(dragged_window_id, True, start_x, start_y) set_window_being_dragged(dragged_window_id, True, start_x, start_y)
self.start_window_drag(dragged_window_id) request_callback_with_thumbnail("start_window_drag", self.os_window_id, dragged_window_id)
return return
if button == GLFW_MOUSE_BUTTON_LEFT: if button == GLFW_MOUSE_BUTTON_LEFT:
@@ -1842,7 +1842,8 @@ class TabManager: # {{{
if len(self.recent_title_bar_mouse_events) > 5: if len(self.recent_title_bar_mouse_events) > 5:
self.recent_title_bar_mouse_events.popleft() self.recent_title_bar_mouse_events.popleft()
def start_window_drag(self, window_id: int) -> None: def start_window_drag(self, pixels: bytes, width: int, height: int) -> None:
window_id = get_window_being_dragged()[0]
boss = get_boss() boss = get_boss()
if (w := boss.window_id_map.get(window_id)) is None: if (w := boss.window_id_map.get(window_id)) is None:
set_window_being_dragged() set_window_being_dragged()
@@ -1859,10 +1860,9 @@ class TabManager: # {{{
title = str(w.title or '') title = str(w.title or '')
fg = color_as_int(opts.window_title_bar_active_foreground or opts.active_tab_foreground) fg = color_as_int(opts.window_title_bar_active_foreground or opts.active_tab_foreground)
bg = color_as_int(opts.window_title_bar_active_background or opts.active_tab_background) bg = color_as_int(opts.window_title_bar_active_background or opts.active_tab_background)
thumb_width = 480 title_pixels = draw_single_line_of_text(self.os_window_id, title, 0xff000000 | fg, 0xff000000 | bg, width)
title_pixels = draw_single_line_of_text(self.os_window_id, title, 0xff000000 | fg, 0xff000000 | bg, thumb_width) title_height = len(title_pixels) // (width * 4)
title_height = len(title_pixels) // (thumb_width * 4) thumbnails = ((title_pixels, width, title_height), (title_pixels + pixels, width, title_height + height))
thumbnails = ((title_pixels, thumb_width, title_height),)
drag_data = {f'application/net.kovidgoyal.kitty-window-{os.getpid()}': str(window_id).encode()} drag_data = {f'application/net.kovidgoyal.kitty-window-{os.getpid()}': str(window_id).encode()}
try: try:
start_drag_with_data(self.os_window_id, drag_data, thumbnails) start_drag_with_data(self.os_window_id, drag_data, thumbnails)