From 0bafc0bdf7871e2ebbb0bf7c57765081eaa18819 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Mar 2026 08:47:23 +0000 Subject: [PATCH] Improve window drag thumbnail to include window content screenshot Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/d929ed68-51ad-414b-8c7e-139aa52cb506 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- docs/changelog.rst | 2 ++ kitty/boss.py | 4 ++++ kitty/tabs.py | 12 ++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 0e443f10d..3bf8fd757 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -196,6 +196,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`) +- Window drag: Use a screenshot of the window contents as the drag thumbnail, just like tab dragging does + 0.46.2 [2026-03-21] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/boss.py b/kitty/boss.py index 5ef07c253..a010db4b1 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1407,6 +1407,10 @@ class Boss: if tm := self.os_window_map.get(os_window_id): 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: if dpi_changed: self.on_dpi_change(os_window_id) diff --git a/kitty/tabs.py b/kitty/tabs.py index 2bc71ce90..4c822d445 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -1812,7 +1812,7 @@ class TabManager: # {{{ dist_sq = (x - start_x)**2 + (y - start_y)**2 if threshold and dist_sq > threshold * threshold: 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 if button == GLFW_MOUSE_BUTTON_LEFT: @@ -1842,7 +1842,8 @@ class TabManager: # {{{ if len(self.recent_title_bar_mouse_events) > 5: 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() if (w := boss.window_id_map.get(window_id)) is None: set_window_being_dragged() @@ -1859,10 +1860,9 @@ class TabManager: # {{{ title = str(w.title or '') 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) - thumb_width = 480 - title_pixels = draw_single_line_of_text(self.os_window_id, title, 0xff000000 | fg, 0xff000000 | bg, thumb_width) - title_height = len(title_pixels) // (thumb_width * 4) - thumbnails = ((title_pixels, thumb_width, title_height),) + title_pixels = draw_single_line_of_text(self.os_window_id, title, 0xff000000 | fg, 0xff000000 | bg, width) + title_height = len(title_pixels) // (width * 4) + thumbnails = ((title_pixels, width, title_height), (title_pixels + pixels, width, title_height + height)) drag_data = {f'application/net.kovidgoyal.kitty-window-{os.getpid()}': str(window_id).encode()} try: start_drag_with_data(self.os_window_id, drag_data, thumbnails)