diff options
author | Daniel Collins <solemnwarning@solemnwarning.net> | 2025-04-16 19:07:54 +0100 |
---|---|---|
committer | Daniel Collins <solemnwarning@solemnwarning.net> | 2025-05-01 22:42:57 +0100 |
commit | 5075ac20f541297a6f62102e397e5d146e8ab4e8 (patch) | |
tree | 317405fa6096e24c34424d9d5d58151f2921b1e2 | |
parent | 40e3e626e4cc8bb2d65788e3c097ddae4192c4d8 (diff) | |
download | tdenetwork-feat/krdc-paste.tar.gz tdenetwork-feat/krdc-paste.zip |
Add "Paste" command to krdc (#102).feat/krdc-paste
This adds a "Paste" command to the toolbar which sends the current
clipboard content to the remote host as key presses.
Not implemented for RDP as we appear to defer to rdesktop and I'm not
sure if we can reliably do it there (also krdc RDP isn't working for me
right now).
-rw-r--r-- | krdc/krdc.cpp | 25 | ||||
-rw-r--r-- | krdc/krdc.h | 1 | ||||
-rw-r--r-- | krdc/kremoteview.cpp | 6 | ||||
-rw-r--r-- | krdc/kremoteview.h | 12 | ||||
-rw-r--r-- | krdc/vnc/kvncview.cpp | 51 | ||||
-rw-r--r-- | krdc/vnc/kvncview.h | 2 |
6 files changed, 97 insertions, 0 deletions
diff --git a/krdc/krdc.cpp b/krdc/krdc.cpp index b50cde3d..7f7ec081 100644 --- a/krdc/krdc.cpp +++ b/krdc/krdc.cpp @@ -33,6 +33,7 @@ #include <tdemessagebox.h> #include <twin.h> #include <tdestartupinfo.h> +#include <tqclipboard.h> #include <tqdockarea.h> #include <tqlabel.h> @@ -51,6 +52,7 @@ const int FS_HOSTLABEL_ID = 4; const int FS_ADVANCED_ID = 5; const int FS_ICONIFY_ID = 6; const int FS_CLOSE_ID = 7; +const int FS_PASTE_ID = 8; const int KRDC::TOOLBAR_AUTOHIDE_TIMEOUT = 1000; const int KRDC::TOOLBAR_FPS_1000 = 10000; @@ -373,6 +375,13 @@ void KRDC::enableFullscreen(bool on) m_view->switchFullscreen(on); } +void KRDC::paste() +{ + TQClipboard *cb = TQApplication::clipboard(); + TQString text = cb->text(TQClipboard::Clipboard); + m_view->sendString(text); +} + TQSize KRDC::sizeHint() { if ((m_isFullscreen != WINDOW_MODE_FULLSCREEN) && m_toolbar) { @@ -499,6 +508,14 @@ void KRDC::switchToFullscreen(bool scaling) t->setButton(FS_FULLSCREEN_ID, true); t->addConnection(FS_FULLSCREEN_ID, TQ_SIGNAL(toggled(bool)), this, TQ_SLOT(enableFullscreen(bool))); + if(m_view->supportsSendString()) + { + t->insertButton("edit-paste", FS_PASTE_ID); + TDEToolBarButton *pasteButton = t->getButton(FS_PASTE_ID); + TQToolTip::add(pasteButton, i18n("Sends clipboard text to the remote system as key presses")); + t->addConnection(FS_PASTE_ID, TQ_SIGNAL(clicked()), this, TQ_SLOT(paste())); + } + m_popup = createPopupMenu(t); t->insertButton("configure", FS_ADVANCED_ID, m_popup, true, i18n("Advanced options")); TDEToolBarButton *advancedButton = t->getButton(FS_ADVANCED_ID); @@ -621,6 +638,14 @@ void KRDC::switchToNormal(bool scaling) m_popup = 0; } + if(m_view->supportsSendString()) + { + t->insertButton("edit-paste", 4, true, i18n("Paste")); + TDEToolBarButton *pasteButton = t->getButton(4); + TQToolTip::add(pasteButton, i18n("Sends clipboard text to the remote system as key presses")); + t->addConnection(4, TQ_SIGNAL(clicked()), this, TQ_SLOT(paste())); + } + m_popup = createPopupMenu(t); t->insertButton("configure", 3, m_popup, true, i18n("Advanced")); TDEToolBarButton *advancedButton = t->getButton(3); diff --git a/krdc/krdc.h b/krdc/krdc.h index b84741d9..b72a5378 100644 --- a/krdc/krdc.h +++ b/krdc/krdc.h @@ -163,6 +163,7 @@ private slots: public slots: void quit(); void enableFullscreen(bool full = false); + void paste(); void switchToNormal(bool scaling = false); void switchToFullscreen(bool scaling = false); void viewOnlyToggled(); diff --git a/krdc/kremoteview.cpp b/krdc/kremoteview.cpp index 76ae6267..e53fb918 100644 --- a/krdc/kremoteview.cpp +++ b/krdc/kremoteview.cpp @@ -86,4 +86,10 @@ void KRemoteView::enableScaling(bool) { void KRemoteView::switchFullscreen(bool) { } +bool KRemoteView::supportsSendString() const { + return false; +} + +void KRemoteView::sendString(const TQString &s) {} + #include "kremoteview.moc" diff --git a/krdc/kremoteview.h b/krdc/kremoteview.h index 9510153f..a735ebe0 100644 --- a/krdc/kremoteview.h +++ b/krdc/kremoteview.h @@ -227,6 +227,18 @@ public slots: */ virtual void pressKey(XEvent *k) = 0; + /** + * Checks whether the backend sending a string of characters. + * Default implementation returns false. + */ + virtual bool supportsSendString() const; + + /** + * Sends a string of characters to the remote server as key presses. + * Default implementation does nothing. + */ + virtual void sendString(const TQString &s); + signals: /** * Emitted when the size of the remote screen changes. Also diff --git a/krdc/vnc/kvncview.cpp b/krdc/vnc/kvncview.cpp index b4025c2d..3a69cdd2 100644 --- a/krdc/vnc/kvncview.cpp +++ b/krdc/vnc/kvncview.cpp @@ -645,6 +645,57 @@ void KVncView::pressKey(XEvent *xe) { m_mods.clear(); } +bool KVncView::supportsSendString() const +{ + return true; +} + +void KVncView::sendString(const TQString &s) +{ + if (m_status != REMOTE_VIEW_CONNECTED) + return; + if (m_viewOnly) + return; + + for(uint i = 0; i < s.length(); ++i) + { + /* X11 reserves keysyms 0x01000000 to 0x0110FFFF for Unicode code-points + * (see keysymdef.h). + */ + uint sym = s[i].unicode() + 0x01000000; + + /* Convert line breaks to return (enter). */ + if(s[i] == '\n') + { + sym = XK_Return; + } + + /* If the character is upper-case and below code-point 0x3000 (most western + * languages), assume the shift key is required (based on kkeyserver_x11.cpp). + */ + bool shift = false; + if(s[i].unicode() < 0x3000 && s[i].isLetter() && s[i].lower() != s[i].upper() && s[i] == s[i].upper()) + { + m_cthreadObject.queueKeyEvent(XK_Shift_L, true); + shift = true; + } + + m_cthreadObject.queueKeyEvent(sym, true); + m_cthreadObject.queueKeyEvent(sym, false); + + if(shift) + { + m_cthreadObject.queueKeyEvent(XK_Shift_L, false); + } + + #if 0 + fprintf(stderr, "Sent character: '%s' (sym = %u, shift = %s)\n", + (const char*)(TQString(s[i]).local8Bit()), + (unsigned)(sym), (shift ? "yes" : "no")); + #endif + } +} + bool KVncView::x11Event(XEvent *e) { bool pressed; if (e->type == KeyPress) diff --git a/krdc/vnc/kvncview.h b/krdc/vnc/kvncview.h index f62b8819..7737ba7f 100644 --- a/krdc/vnc/kvncview.h +++ b/krdc/vnc/kvncview.h @@ -114,6 +114,8 @@ public slots: virtual void enableScaling(bool s); virtual void setViewOnly(bool s); virtual void pressKey(XEvent *k); + virtual bool supportsSendString() const; + virtual void sendString(const TQString &s); private slots: |