Skip to content

Commit 5754fa2

Browse files
committed
OSC 52: Fix specifying both clipboard and primary in OSC 52 requests not supported
1 parent 1696524 commit 5754fa2

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ Detailed list of changes
112112

113113
- macOS: Fix a regression causing a crash when using :opt:`focus_follows_mouse` (:iss:`8437`)
114114

115+
- OSC 52: Fix specifying both clipboard and primary in OSC 52 requests not supported
116+
115117
0.40.0 [2025-03-08]
116118
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117119

kitty/clipboard.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ def chunker() -> bytes:
7676
class ClipboardType(IntEnum):
7777
clipboard = GLFW_CLIPBOARD
7878
primary_selection = GLFW_PRIMARY_SELECTION
79+
unknown = -311
7980

8081
@staticmethod
8182
def from_osc52_where_field(where: str) -> 'ClipboardType':
82-
where = where or 's0'
83-
return ClipboardType.clipboard if 'c' in where or 's' in where else ClipboardType.primary_selection
83+
if where in ('c', 's'):
84+
return ClipboardType.clipboard
85+
if where == 'p':
86+
return ClipboardType.primary_selection
87+
return ClipboardType.unknown
8488

8589

8690
class Clipboard:
@@ -394,18 +398,22 @@ def parse_osc_52(self, data: memoryview, is_partial: bool = False) -> None:
394398
else:
395399
where = str(data, "utf-8", 'replace')
396400
data = data[len(data):]
401+
destinations = {ClipboardType.from_osc52_where_field(where) for where in where}
402+
destinations.discard(ClipboardType.unknown)
397403
if len(data) == 1 and data.tobytes() == b'?':
398-
rr = ReadRequest(is_primary_selection=ClipboardType.from_osc52_where_field(where) is ClipboardType.primary_selection)
399-
self.handle_read_request(rr)
404+
for d in destinations:
405+
rr = ReadRequest(is_primary_selection=d is ClipboardType.primary_selection)
406+
self.handle_read_request(rr)
400407
else:
401-
wr = self.in_flight_write_request
402-
if wr is None:
403-
wr = self.in_flight_write_request = WriteRequest(ClipboardType.from_osc52_where_field(where) is ClipboardType.primary_selection)
404-
wr.add_base64_data(data)
405-
if is_partial:
406-
return
407-
self.in_flight_write_request = None
408-
self.handle_write_request(wr)
408+
for d in destinations:
409+
wr = self.in_flight_write_request
410+
if wr is None:
411+
wr = self.in_flight_write_request = WriteRequest(d is ClipboardType.primary_selection)
412+
wr.add_base64_data(data)
413+
if is_partial:
414+
return
415+
self.in_flight_write_request = None
416+
self.handle_write_request(wr)
409417

410418
def handle_write_request(self, wr: WriteRequest) -> None:
411419
wr.flush_base64_data()

0 commit comments

Comments
 (0)