mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Synchronize Clipboard with Primary Selection on Linux when copying (#1502)
* Introduce crossPlatformCopy() It sets the text of the clipboard and also syncs it with the selection clipboard if it is supported. Such behaviour is pretty common for X11 application on Unix-like Operating Systems. * Fix clang-format remarks * Fix weird clang-format config discrepancy between my machine and CI * Remove clipboard argument from crossPlatformCopy * Fix clang-format remarks
This commit is contained in:
parent
809b63bb5e
commit
00414eb779
5 changed files with 41 additions and 17 deletions
|
@ -210,6 +210,7 @@ SOURCES += \
|
||||||
src/singletons/TooltipPreviewImage.cpp \
|
src/singletons/TooltipPreviewImage.cpp \
|
||||||
src/singletons/Updates.cpp \
|
src/singletons/Updates.cpp \
|
||||||
src/singletons/WindowManager.cpp \
|
src/singletons/WindowManager.cpp \
|
||||||
|
src/util/Clipboard.cpp \
|
||||||
src/util/DebugCount.cpp \
|
src/util/DebugCount.cpp \
|
||||||
src/util/FormatTime.cpp \
|
src/util/FormatTime.cpp \
|
||||||
src/util/FunctionEventFilter.cpp \
|
src/util/FunctionEventFilter.cpp \
|
||||||
|
@ -412,6 +413,7 @@ HEADERS += \
|
||||||
src/singletons/Updates.hpp \
|
src/singletons/Updates.hpp \
|
||||||
src/singletons/WindowManager.hpp \
|
src/singletons/WindowManager.hpp \
|
||||||
src/util/Clamp.hpp \
|
src/util/Clamp.hpp \
|
||||||
|
src/util/Clipboard.hpp \
|
||||||
src/util/CombinePath.hpp \
|
src/util/CombinePath.hpp \
|
||||||
src/util/ConcurrentMap.hpp \
|
src/util/ConcurrentMap.hpp \
|
||||||
src/util/DebugCount.hpp \
|
src/util/DebugCount.hpp \
|
||||||
|
|
16
src/util/Clipboard.cpp
Normal file
16
src/util/Clipboard.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "util/Clipboard.hpp"
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
void crossPlatformCopy(const QString &text)
|
||||||
|
{
|
||||||
|
auto clipboard = QApplication::clipboard();
|
||||||
|
clipboard->setText(text);
|
||||||
|
if (clipboard->supportsSelection())
|
||||||
|
{
|
||||||
|
clipboard->setText(text, QClipboard::Selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
9
src/util/Clipboard.hpp
Normal file
9
src/util/Clipboard.hpp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
void crossPlatformCopy(const QString &text);
|
||||||
|
|
||||||
|
} // namespace chatterino
|
|
@ -28,6 +28,7 @@
|
||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
#include "singletons/TooltipPreviewImage.hpp"
|
#include "singletons/TooltipPreviewImage.hpp"
|
||||||
#include "singletons/WindowManager.hpp"
|
#include "singletons/WindowManager.hpp"
|
||||||
|
#include "util/Clipboard.hpp"
|
||||||
#include "util/DistanceBetweenPoints.hpp"
|
#include "util/DistanceBetweenPoints.hpp"
|
||||||
#include "util/IncognitoBrowser.hpp"
|
#include "util/IncognitoBrowser.hpp"
|
||||||
#include "widgets/Scrollbar.hpp"
|
#include "widgets/Scrollbar.hpp"
|
||||||
|
@ -64,9 +65,8 @@ namespace {
|
||||||
if (!image->isEmpty())
|
if (!image->isEmpty())
|
||||||
{
|
{
|
||||||
copyMenu->addAction(
|
copyMenu->addAction(
|
||||||
QString(scale) + "x link", [url = image->url()] {
|
QString(scale) + "x link",
|
||||||
QApplication::clipboard()->setText(url.string);
|
[url = image->url()] { crossPlatformCopy(url.string); });
|
||||||
});
|
|
||||||
openMenu->addAction(
|
openMenu->addAction(
|
||||||
QString(scale) + "x link", [url = image->url()] {
|
QString(scale) + "x link", [url = image->url()] {
|
||||||
QDesktopServices::openUrl(QUrl(url.string));
|
QDesktopServices::openUrl(QUrl(url.string));
|
||||||
|
@ -84,9 +84,8 @@ namespace {
|
||||||
openMenu->addSeparator();
|
openMenu->addSeparator();
|
||||||
|
|
||||||
copyMenu->addAction(
|
copyMenu->addAction(
|
||||||
"Copy " + name + " emote link", [url = emote.homePage] {
|
"Copy " + name + " emote link",
|
||||||
QApplication::clipboard()->setText(url.string); //
|
[url = emote.homePage] { crossPlatformCopy(url.string); });
|
||||||
});
|
|
||||||
openMenu->addAction(
|
openMenu->addAction(
|
||||||
"Open " + name + " emote link", [url = emote.homePage] {
|
"Open " + name + " emote link", [url = emote.homePage] {
|
||||||
QDesktopServices::openUrl(QUrl(url.string)); //
|
QDesktopServices::openUrl(QUrl(url.string)); //
|
||||||
|
@ -124,9 +123,8 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||||
});
|
});
|
||||||
|
|
||||||
auto shortcut = new QShortcut(QKeySequence("Ctrl+C"), this);
|
auto shortcut = new QShortcut(QKeySequence("Ctrl+C"), this);
|
||||||
QObject::connect(shortcut, &QShortcut::activated, [this] {
|
QObject::connect(shortcut, &QShortcut::activated,
|
||||||
QGuiApplication::clipboard()->setText(this->getSelectedText());
|
[this] { crossPlatformCopy(this->getSelectedText()); });
|
||||||
});
|
|
||||||
|
|
||||||
this->clickTimer_ = new QTimer(this);
|
this->clickTimer_ = new QTimer(this);
|
||||||
this->clickTimer_->setSingleShot(true);
|
this->clickTimer_->setSingleShot(true);
|
||||||
|
@ -1552,8 +1550,7 @@ void ChannelView::addContextMenuItems(
|
||||||
menu->addAction("Open link incognito",
|
menu->addAction("Open link incognito",
|
||||||
[url] { openLinkIncognito(url); });
|
[url] { openLinkIncognito(url); });
|
||||||
}
|
}
|
||||||
menu->addAction("Copy link",
|
menu->addAction("Copy link", [url] { crossPlatformCopy(url); });
|
||||||
[url] { QApplication::clipboard()->setText(url); });
|
|
||||||
|
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
}
|
}
|
||||||
|
@ -1561,9 +1558,8 @@ void ChannelView::addContextMenuItems(
|
||||||
// Copy actions
|
// Copy actions
|
||||||
if (!this->selection_.isEmpty())
|
if (!this->selection_.isEmpty())
|
||||||
{
|
{
|
||||||
menu->addAction("Copy selection", [this] {
|
menu->addAction("Copy selection",
|
||||||
QGuiApplication::clipboard()->setText(this->getSelectedText());
|
[this] { crossPlatformCopy(this->getSelectedText()); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
menu->addAction("Copy message", [layout] {
|
menu->addAction("Copy message", [layout] {
|
||||||
|
@ -1571,14 +1567,14 @@ void ChannelView::addContextMenuItems(
|
||||||
layout->addSelectionText(copyString, 0, INT_MAX,
|
layout->addSelectionText(copyString, 0, INT_MAX,
|
||||||
CopyMode::OnlyTextAndEmotes);
|
CopyMode::OnlyTextAndEmotes);
|
||||||
|
|
||||||
QGuiApplication::clipboard()->setText(copyString);
|
crossPlatformCopy(copyString);
|
||||||
});
|
});
|
||||||
|
|
||||||
menu->addAction("Copy full message", [layout] {
|
menu->addAction("Copy full message", [layout] {
|
||||||
QString copyString;
|
QString copyString;
|
||||||
layout->addSelectionText(copyString);
|
layout->addSelectionText(copyString);
|
||||||
|
|
||||||
QGuiApplication::clipboard()->setText(copyString);
|
crossPlatformCopy(copyString);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Open in new split.
|
// Open in new split.
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
#include "singletons/Theme.hpp"
|
#include "singletons/Theme.hpp"
|
||||||
#include "singletons/WindowManager.hpp"
|
#include "singletons/WindowManager.hpp"
|
||||||
|
#include "util/Clipboard.hpp"
|
||||||
#include "util/Shortcut.hpp"
|
#include "util/Shortcut.hpp"
|
||||||
#include "util/StreamLink.hpp"
|
#include "util/StreamLink.hpp"
|
||||||
#include "widgets/Notebook.hpp"
|
#include "widgets/Notebook.hpp"
|
||||||
|
@ -659,7 +660,7 @@ void Split::openSubPage()
|
||||||
|
|
||||||
void Split::copyToClipboard()
|
void Split::copyToClipboard()
|
||||||
{
|
{
|
||||||
QApplication::clipboard()->setText(this->view_->getSelectedText());
|
crossPlatformCopy(this->view_->getSelectedText());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Split::showSearch()
|
void Split::showSearch()
|
||||||
|
|
Loading…
Reference in a new issue