Skip to content

Commit bb7cea7

Browse files
committed
rdesktop (GTK3 e PyQt6): il flag -K nella stringa -DNK istruisce rdesktop a non grabbarel la tastiera ("Keep window
manager key bindings"). In modalità esterna questo flag non c'era, quindi la tastiera funzionava. Rimosso: -DNK → -DN. xfreerdp (GTK3 e PyQt6): dopo xdotool windowreparent la finestra è fisicamente dentro il container, ma il protocollo XEMBED non viene usato — GTK/Qt non sanno a quale finestra X11 forwardare la tastiera. Fix: aggiunta xdotool windowfocus <wid> subito dopo il windowmap. In entrambe le versioni aggiunti anche: - Handler click sul socket/container → se si clicca nell'area RDP, il focus X11 torna sulla finestra embedded - GTK3: focus-in-event sul socket → stesso comportamento quando il widget GTK acquisisce focus - PyQt6: eventFilter sul container per intercettare MouseButtonPress
1 parent 6f136f1 commit bb7cea7

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

gtk3/rdp_widget.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ def _init_ui(self):
106106
self._socket.set_hexpand(True)
107107
self._socket.set_vexpand(True)
108108
self._socket.set_no_show_all(True)
109-
self._socket.connect("plug-added", self._on_plug_added)
110-
self._socket.connect("plug-removed", self._on_plug_removed)
109+
self._socket.set_can_focus(True)
110+
self._socket.connect("plug-added", self._on_plug_added)
111+
self._socket.connect("plug-removed", self._on_plug_removed)
112+
self._socket.connect("button-press-event", self._on_socket_click)
113+
self._socket.connect("focus-in-event", self._on_socket_focus_in)
111114
self.pack_start(self._socket, True, True, 0)
112115
else:
113116
lbl = Gtk.Label(label="Sessione RDP avviata in finestra esterna.")
@@ -255,7 +258,7 @@ def _avvia_rdesktop(self, host, port, user, pwd, domain, clips, drives):
255258
args = ["rdesktop",
256259
f"-X{xid}",
257260
f"-g{w}x{h}",
258-
"-a16", "-DNK"]
261+
"-a16", "-DN"]
259262
if user: args.append(f"-u{user}")
260263
if domain: args.append(f"-d{domain}")
261264
if pwd: args.append(f"-p{pwd}")
@@ -407,6 +410,13 @@ def _esegui_reparent(self, wid_rdp: str):
407410
subprocess.run(["xdotool", "windowmap", wid_rdp],
408411
timeout=3, capture_output=True)
409412

413+
time.sleep(0.15)
414+
415+
# Sposta il focus X11 sulla finestra embedded (senza XEMBED
416+
# GTK non lo fa automaticamente e la tastiera non funziona)
417+
subprocess.Popen(["xdotool", "windowfocus", wid_rdp],
418+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
419+
410420
self._reparented = True
411421
host = self._rdp_host
412422
self._info.set_text(f" ● RDP → {host}")
@@ -475,11 +485,28 @@ def _monitor_proc(self) -> bool:
475485

476486
def _on_plug_added(self, socket):
477487
self._info.set_text(f" ● RDP → {self._rdp_host}")
488+
# rdesktop usa XEMBED: appena il plug si connette, GTK può ricevere
489+
# il focus e forwardarlo correttamente all'embedded window
490+
GLib.idle_add(self._socket.grab_focus)
478491

479492
def _on_plug_removed(self, socket):
480493
self._info.set_text(f" ✖ RDP disconnesso")
481494
return True
482495

496+
def _on_socket_click(self, widget, event):
497+
"""Click sul socket → sposta il focus X11 alla finestra RDP embedded."""
498+
if self._wid_rdp:
499+
subprocess.Popen(["xdotool", "windowfocus", self._wid_rdp],
500+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
501+
return False
502+
503+
def _on_socket_focus_in(self, widget, event):
504+
"""Il socket GTK riceve il focus → re-forwardalo alla finestra RDP."""
505+
if self._wid_rdp:
506+
subprocess.Popen(["xdotool", "windowfocus", self._wid_rdp],
507+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
508+
return False
509+
483510
# ------------------------------------------------------------------
484511
# Cleanup
485512
# ------------------------------------------------------------------

pyqt6/rdp_widget.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def _init_ui(self):
9393
self.container.setAttribute(Qt.WidgetAttribute.WA_StyledBackground, True)
9494
self.container.setStyleSheet("background:#000000;")
9595
self.container.setVisible(False)
96+
self.container.installEventFilter(self)
9697
self._layout.addWidget(self.container, 1)
9798

9899
# ------------------------------------------------------------------
@@ -228,7 +229,7 @@ def _avvia_rdesktop(self, host, port, user, pwd, domain, clips, drives=False):
228229
f"-X{wid_container}", # embedding nel container Qt
229230
f"-g{w}x{h}", # dimensioni
230231
"-a16", # 16-bit colore
231-
"-DNK", # no decorazioni, no grab kbd
232+
"-DN", # no decorazioni
232233
]
233234
if user:
234235
args += [f"-u{user}"]
@@ -414,6 +415,13 @@ def _esegui_reparent(self, wid_rdp: str):
414415
subprocess.run(["xdotool", "windowmap", "--sync", wid_rdp],
415416
timeout=3, capture_output=True)
416417

418+
time.sleep(0.15)
419+
420+
# Sposta il focus X11 sulla finestra embedded (senza XEMBED
421+
# Qt non lo fa automaticamente e la tastiera non funziona)
422+
subprocess.Popen(["xdotool", "windowfocus", wid_rdp],
423+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
424+
417425
self._reparented = True
418426
self.barra_info.setStyleSheet(
419427
"background-color:#252525; color:#88cc88; "
@@ -532,6 +540,15 @@ def closeEvent(self, event):
532540
# Utility
533541
# ------------------------------------------------------------------
534542

543+
def eventFilter(self, obj, event):
544+
"""Click sul container → ridà il focus X11 alla finestra RDP embedded."""
545+
from PyQt6.QtCore import QEvent
546+
if obj is self.container and event.type() == QEvent.Type.MouseButtonPress:
547+
if self._wid_rdp:
548+
subprocess.Popen(["xdotool", "windowfocus", self._wid_rdp],
549+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
550+
return False
551+
535552
def _mostra_errore(self, msg: str):
536553
self._lbl_attesa.setVisible(True)
537554
self.container.setVisible(False)

0 commit comments

Comments
 (0)