mirror of
https://github.com/quickshell-mirror/quickshell.git
synced 2026-10-27 02:54:36 +00:00
core/qmlglobal: add clipboard support
This commit is contained in:
2 files changed
+36
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include "qmlglobal.hpp"
|
||||
#include <utility>
|
||||
|
||||
#include <qclipboard.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qcoreapplication.h>
|
||||
#include <qdir.h>
|
||||
@@ -17,6 +18,7 @@
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
#include <qwindowdefs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "generation.hpp"
|
||||
@@ -132,6 +134,13 @@ QuickshellGlobal::QuickshellGlobal(QObject* parent): QObject(parent) {
|
||||
|
||||
QObject::connect(QuickshellTracked::instance(), &QuickshellTracked::screensChanged, this, &QuickshellGlobal::screensChanged);
|
||||
// clang-format on
|
||||
|
||||
QObject::connect(
|
||||
static_cast<QGuiApplication*>(QGuiApplication::instance())->clipboard(), // NOLINT
|
||||
&QClipboard::changed,
|
||||
this,
|
||||
&QuickshellGlobal::onClipboardChanged
|
||||
);
|
||||
}
|
||||
|
||||
qint32 QuickshellGlobal::processId() const { // NOLINT
|
||||
@@ -190,6 +199,20 @@ void QuickshellGlobal::setWatchFiles(bool watchFiles) { // NOLINT
|
||||
QuickshellSettings::instance()->setWatchFiles(watchFiles);
|
||||
}
|
||||
|
||||
QString QuickshellGlobal::clipboardText() {
|
||||
return static_cast<QGuiApplication*>(QGuiApplication::instance())->clipboard()->text(); // NOLINT
|
||||
}
|
||||
|
||||
void QuickshellGlobal::setClipboardText(const QString& text) {
|
||||
return static_cast<QGuiApplication*>(QGuiApplication::instance()) // NOLINT
|
||||
->clipboard()
|
||||
->setText(text);
|
||||
}
|
||||
|
||||
void QuickshellGlobal::onClipboardChanged(QClipboard::Mode mode) {
|
||||
if (mode == QClipboard::Clipboard) emit this->clipboardTextChanged();
|
||||
}
|
||||
|
||||
QString QuickshellGlobal::dataDir() const { // NOLINT
|
||||
return QsPaths::instance()->shellDataDir().path();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <qclipboard.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qjsengine.h>
|
||||
#include <qobject.h>
|
||||
@@ -10,6 +11,7 @@
|
||||
#include <qtmetamacros.h>
|
||||
#include <qtypes.h>
|
||||
#include <qvariant.h>
|
||||
#include <qwindowdefs.h>
|
||||
|
||||
#include "qmlscreen.hpp"
|
||||
|
||||
@@ -108,6 +110,10 @@ class QuickshellGlobal: public QObject {
|
||||
/// If true then the configuration will be reloaded whenever any files change.
|
||||
/// Defaults to true.
|
||||
Q_PROPERTY(bool watchFiles READ watchFiles WRITE setWatchFiles NOTIFY watchFilesChanged);
|
||||
/// The system clipboard.
|
||||
///
|
||||
/// > [!WARNING] Under wayland the clipboard will be empty unless a quickshell window is focused.
|
||||
Q_PROPERTY(QString clipboardText READ clipboardText WRITE setClipboardText NOTIFY clipboardTextChanged);
|
||||
/// The per-shell data directory.
|
||||
///
|
||||
/// Usually `~/.local/share/quickshell/by-shell/<shell-id>`
|
||||
@@ -176,6 +182,9 @@ public:
|
||||
[[nodiscard]] bool watchFiles() const;
|
||||
void setWatchFiles(bool watchFiles);
|
||||
|
||||
[[nodiscard]] static QString clipboardText();
|
||||
static void setClipboardText(const QString& text);
|
||||
|
||||
[[nodiscard]] QString dataDir() const;
|
||||
[[nodiscard]] QString stateDir() const;
|
||||
[[nodiscard]] QString cacheDir() const;
|
||||
@@ -195,6 +204,10 @@ signals:
|
||||
void screensChanged();
|
||||
void workingDirectoryChanged();
|
||||
void watchFilesChanged();
|
||||
void clipboardTextChanged();
|
||||
|
||||
private slots:
|
||||
void onClipboardChanged(QClipboard::Mode mode);
|
||||
|
||||
private:
|
||||
QuickshellGlobal(QObject* parent = nullptr);
|
||||
|
||||
Reference in new issue
Block a user