@@ -67,12 +67,32 @@ def _wl_copy(self, text: str):
6767 import pyperclip
6868 pyperclip .copy (text )
6969
70+ def _type_text_directly (self , text : str ) -> bool :
71+ """Type text directly using Wayland input tool. Returns True on success."""
72+ try :
73+ if self ._paste_tool == 'wtype' :
74+ subprocess .run (['wtype' , '--' , text ], check = True , timeout = 10 )
75+ elif self ._paste_tool == 'dotool' :
76+ # dotool type command types text directly
77+ subprocess .run (['dotool' ], input = f'type { text } \n ' .encode (),
78+ check = True , timeout = 10 )
79+ elif self ._paste_tool == 'ydotool' :
80+ subprocess .run (['ydotool' , 'type' , '--' , text ],
81+ check = True , timeout = 10 )
82+ else :
83+ return False
84+ log .debug ("Text typed directly via" , tool = self ._paste_tool )
85+ return True
86+ except (subprocess .SubprocessError , OSError ) as e :
87+ log .warning ("Direct type failed" , tool = self ._paste_tool , error = str (e ))
88+ return False
89+
7090 def _simulate_paste_keystroke (self ):
7191 """Send Ctrl+V using the best available tool."""
7292 if IS_WAYLAND and self ._paste_tool :
7393 try :
7494 if self ._paste_tool == 'wtype' :
75- subprocess .run (['wtype' , '-M' , 'ctrl' , '-P ' , 'v' , '-m' , 'ctrl' ],
95+ subprocess .run (['wtype' , '-M' , 'ctrl' , '-k ' , 'v' , '-m' , 'ctrl' ],
7696 check = True , timeout = 5 )
7797 elif self ._paste_tool == 'dotool' :
7898 subprocess .run (['dotool' ], input = b'key ctrl+v\n ' ,
@@ -93,19 +113,26 @@ def paste_at_cursor(self, text: str):
93113 """Copy text to clipboard and paste at current cursor position."""
94114 log .debug ("Paste at cursor called" , text_length = len (text ))
95115
96- # Copy our text to clipboard
116+ # Always copy to clipboard so user can re-paste manually if needed
97117 self .copy_to_clipboard (text )
98118 log .debug ("Text copied to clipboard" )
99119
100- # Small delay to ensure clipboard is updated
120+ # On Wayland, type text directly — works in terminals (Ctrl+V doesn't)
121+ # and all other apps, regardless of their paste shortcut.
122+ if IS_WAYLAND and self ._paste_tool :
123+ if self ._type_text_directly (text ):
124+ log .debug ("Paste complete via direct type" )
125+ return
126+ # Direct type failed — fall through to Ctrl+V
127+ log .warning ("Direct type failed, falling back to Ctrl+V" )
128+
129+ # Small delay to ensure clipboard is ready
101130 time .sleep (0.1 )
102131
103- # Simulate Ctrl+V
104132 log .debug ("Simulating Ctrl+V" )
105133 self ._simulate_paste_keystroke ()
106134 log .debug ("Paste command sent" )
107135
108- # Small delay after paste
109136 time .sleep (0.1 )
110137
111138 def get_clipboard (self ) -> str :
0 commit comments