diff --git a/docs/changelog.rst b/docs/changelog.rst index 12544ae22..b9f054386 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -112,6 +112,8 @@ Detailed list of changes - macOS: Fix a regression causing a crash when using :opt:`focus_follows_mouse` (:iss:`8437`) +- OSC 52: Fix specifying both clipboard and primary in OSC 52 requests not supported + 0.40.0 [2025-03-08] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/clipboard.py b/kitty/clipboard.py index 4ccc33ab0..6401fb9af 100644 --- a/kitty/clipboard.py +++ b/kitty/clipboard.py @@ -76,11 +76,15 @@ TARGETS_MIME = '.' class ClipboardType(IntEnum): clipboard = GLFW_CLIPBOARD primary_selection = GLFW_PRIMARY_SELECTION + unknown = -311 @staticmethod def from_osc52_where_field(where: str) -> 'ClipboardType': - where = where or 's0' - return ClipboardType.clipboard if 'c' in where or 's' in where else ClipboardType.primary_selection + if where in ('c', 's'): + return ClipboardType.clipboard + if where == 'p': + return ClipboardType.primary_selection + return ClipboardType.unknown class Clipboard: @@ -394,18 +398,22 @@ class ClipboardRequestManager: else: where = str(data, "utf-8", 'replace') data = data[len(data):] + destinations = {ClipboardType.from_osc52_where_field(where) for where in where} + destinations.discard(ClipboardType.unknown) if len(data) == 1 and data.tobytes() == b'?': - rr = ReadRequest(is_primary_selection=ClipboardType.from_osc52_where_field(where) is ClipboardType.primary_selection) - self.handle_read_request(rr) + for d in destinations: + rr = ReadRequest(is_primary_selection=d is ClipboardType.primary_selection) + self.handle_read_request(rr) else: - wr = self.in_flight_write_request - if wr is None: - wr = self.in_flight_write_request = WriteRequest(ClipboardType.from_osc52_where_field(where) is ClipboardType.primary_selection) - wr.add_base64_data(data) - if is_partial: - return - self.in_flight_write_request = None - self.handle_write_request(wr) + for d in destinations: + wr = self.in_flight_write_request + if wr is None: + wr = self.in_flight_write_request = WriteRequest(d is ClipboardType.primary_selection) + wr.add_base64_data(data) + if is_partial: + return + self.in_flight_write_request = None + self.handle_write_request(wr) def handle_write_request(self, wr: WriteRequest) -> None: wr.flush_base64_data()