@@ -76,11 +76,15 @@ def chunker() -> bytes:
7676class 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
8690class 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