summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Collins <solemnwarning@solemnwarning.net>2025-04-16 19:07:54 +0100
committerSlávek Banko <slavek.banko@axis.cz>2025-06-30 19:26:53 +0200
commit8dc325fb3fb85d0ab76092db66deaee26145f863 (patch)
treeff2d49b27e8a4d4646dc5c2bdc95e0f9930562d6
parenteea2e3baf09d75d646cb5647775b06decbe7ec5c (diff)
downloadtdenetwork-r14.1.x.tar.gz
tdenetwork-r14.1.x.zip
Add "Paste" command to krdc (#102).r14.1.x
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). (cherry picked from commit 123ecc2bd9b3e470a34dd3aa3b0f6b66e74d6c76)
-rw-r--r--krdc/krdc.cpp25
-rw-r--r--krdc/krdc.h1
-rw-r--r--krdc/kremoteview.cpp6
-rw-r--r--krdc/kremoteview.h12
-rw-r--r--krdc/vnc/kvncview.cpp51
-rw-r--r--krdc/vnc/kvncview.h2
6 files changed, 97 insertions, 0 deletions
diff --git a/krdc/krdc.cpp b/krdc/krdc.cpp
index 1e86891d..0206a37d 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 30cb2356..223cd5cc 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: