mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:31:16 -07:00
Add UTF-8 clipboard support
Changes: - Use rfbSendServerCutTextUTF8() to send clipboard text in UTF-8, falling back to Latin1 if UTF-8 is not supported. - Implement setXCutTextUTF8() to handle received UTF-8 clipboard content. CCBUG: 430339
This commit is contained in:
@@ -92,6 +92,7 @@ bool RfbServer::start()
|
|||||||
d->screen->ptrAddEvent = pointerHook;
|
d->screen->ptrAddEvent = pointerHook;
|
||||||
d->screen->passwordCheck = passwordCheck;
|
d->screen->passwordCheck = passwordCheck;
|
||||||
d->screen->setXCutText = clipboardHook;
|
d->screen->setXCutText = clipboardHook;
|
||||||
|
d->screen->setXCutTextUTF8 = clipboardHookUtf8;
|
||||||
} else {
|
} else {
|
||||||
//if we already have a screen, stop listening first
|
//if we already have a screen, stop listening first
|
||||||
rfbShutdownServer(d->screen, false);
|
rfbShutdownServer(d->screen, false);
|
||||||
@@ -220,8 +221,10 @@ void RfbServer::krfbSendServerCutText()
|
|||||||
{
|
{
|
||||||
if (d->screen) {
|
if (d->screen) {
|
||||||
QString text = QApplication::clipboard()->text();
|
QString text = QApplication::clipboard()->text();
|
||||||
rfbSendServerCutText(d->screen,
|
QByteArray utf8Bytes = text.toUtf8();
|
||||||
text.toLocal8Bit().data(),text.length());
|
QByteArray latin1Bytes = text.toLatin1();
|
||||||
|
// Try to send the clipboard text to the client in UTF-8. Use Latin1 if UTF-8 is not supported.
|
||||||
|
rfbSendServerCutTextUTF8(d->screen, utf8Bytes.data(), utf8Bytes.length(), latin1Bytes.data(), latin1Bytes.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,5 +290,13 @@ void RfbServer::pointerHook(int bm, int x, int y, rfbClientPtr cl)
|
|||||||
//static
|
//static
|
||||||
void RfbServer::clipboardHook(char *str, int len, rfbClientPtr /*cl*/)
|
void RfbServer::clipboardHook(char *str, int len, rfbClientPtr /*cl*/)
|
||||||
{
|
{
|
||||||
QApplication::clipboard()->setText(QString::fromLocal8Bit(str,len));
|
QString text = QString::fromLatin1(str, len);
|
||||||
|
QApplication::clipboard()->setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RfbServer::clipboardHookUtf8(char *str, int len, rfbClientPtr /*cl*/)
|
||||||
|
{
|
||||||
|
// The last byte is a null terminator
|
||||||
|
QString text = QString::fromUtf8(str, len - 1);
|
||||||
|
QApplication::clipboard()->setText(text);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ private:
|
|||||||
static void keyboardHook(rfbBool down, rfbKeySym keySym, rfbClientPtr cl);
|
static void keyboardHook(rfbBool down, rfbKeySym keySym, rfbClientPtr cl);
|
||||||
static void pointerHook(int bm, int x, int y, rfbClientPtr cl);
|
static void pointerHook(int bm, int x, int y, rfbClientPtr cl);
|
||||||
static void clipboardHook(char *str, int len, rfbClientPtr cl);
|
static void clipboardHook(char *str, int len, rfbClientPtr cl);
|
||||||
|
static void clipboardHookUtf8(char *str, int len, rfbClientPtr cl);
|
||||||
|
|
||||||
Q_DISABLE_COPY(RfbServer)
|
Q_DISABLE_COPY(RfbServer)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user