forked from quickshell/quickshell
		
	core/qmlglobal: add clipboard support
This commit is contained in:
		
							parent
							
								
									325a51c82d
								
							
						
					
					
						commit
						4d7d06bb9b
					
				
					 2 changed files with 36 additions and 0 deletions
				
			
		| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#include "qmlglobal.hpp"
 | 
					#include "qmlglobal.hpp"
 | 
				
			||||||
#include <utility>
 | 
					#include <utility>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <qclipboard.h>
 | 
				
			||||||
#include <qcontainerfwd.h>
 | 
					#include <qcontainerfwd.h>
 | 
				
			||||||
#include <qcoreapplication.h>
 | 
					#include <qcoreapplication.h>
 | 
				
			||||||
#include <qdir.h>
 | 
					#include <qdir.h>
 | 
				
			||||||
| 
						 | 
					@ -17,6 +18,7 @@
 | 
				
			||||||
#include <qtmetamacros.h>
 | 
					#include <qtmetamacros.h>
 | 
				
			||||||
#include <qtypes.h>
 | 
					#include <qtypes.h>
 | 
				
			||||||
#include <qvariant.h>
 | 
					#include <qvariant.h>
 | 
				
			||||||
 | 
					#include <qwindowdefs.h>
 | 
				
			||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "generation.hpp"
 | 
					#include "generation.hpp"
 | 
				
			||||||
| 
						 | 
					@ -132,6 +134,13 @@ QuickshellGlobal::QuickshellGlobal(QObject* parent): QObject(parent) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QObject::connect(QuickshellTracked::instance(), &QuickshellTracked::screensChanged, this, &QuickshellGlobal::screensChanged);
 | 
						QObject::connect(QuickshellTracked::instance(), &QuickshellTracked::screensChanged, this, &QuickshellGlobal::screensChanged);
 | 
				
			||||||
	// clang-format on
 | 
						// clang-format on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						QObject::connect(
 | 
				
			||||||
 | 
						    static_cast<QGuiApplication*>(QGuiApplication::instance())->clipboard(), // NOLINT
 | 
				
			||||||
 | 
						    &QClipboard::changed,
 | 
				
			||||||
 | 
						    this,
 | 
				
			||||||
 | 
						    &QuickshellGlobal::onClipboardChanged
 | 
				
			||||||
 | 
						);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
qint32 QuickshellGlobal::processId() const { // NOLINT
 | 
					qint32 QuickshellGlobal::processId() const { // NOLINT
 | 
				
			||||||
| 
						 | 
					@ -190,6 +199,20 @@ void QuickshellGlobal::setWatchFiles(bool watchFiles) { // NOLINT
 | 
				
			||||||
	QuickshellSettings::instance()->setWatchFiles(watchFiles);
 | 
						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
 | 
					QString QuickshellGlobal::dataDir() const { // NOLINT
 | 
				
			||||||
	return QsPaths::instance()->shellDataDir().path();
 | 
						return QsPaths::instance()->shellDataDir().path();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <qclipboard.h>
 | 
				
			||||||
#include <qcontainerfwd.h>
 | 
					#include <qcontainerfwd.h>
 | 
				
			||||||
#include <qjsengine.h>
 | 
					#include <qjsengine.h>
 | 
				
			||||||
#include <qobject.h>
 | 
					#include <qobject.h>
 | 
				
			||||||
| 
						 | 
					@ -10,6 +11,7 @@
 | 
				
			||||||
#include <qtmetamacros.h>
 | 
					#include <qtmetamacros.h>
 | 
				
			||||||
#include <qtypes.h>
 | 
					#include <qtypes.h>
 | 
				
			||||||
#include <qvariant.h>
 | 
					#include <qvariant.h>
 | 
				
			||||||
 | 
					#include <qwindowdefs.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "qmlscreen.hpp"
 | 
					#include "qmlscreen.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -108,6 +110,10 @@ class QuickshellGlobal: public QObject {
 | 
				
			||||||
	/// If true then the configuration will be reloaded whenever any files change.
 | 
						/// If true then the configuration will be reloaded whenever any files change.
 | 
				
			||||||
	/// Defaults to true.
 | 
						/// Defaults to true.
 | 
				
			||||||
	Q_PROPERTY(bool watchFiles READ watchFiles WRITE setWatchFiles NOTIFY watchFilesChanged);
 | 
						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.
 | 
						/// The per-shell data directory.
 | 
				
			||||||
	///
 | 
						///
 | 
				
			||||||
	/// Usually `~/.local/share/quickshell/by-shell/<shell-id>`
 | 
						/// Usually `~/.local/share/quickshell/by-shell/<shell-id>`
 | 
				
			||||||
| 
						 | 
					@ -176,6 +182,9 @@ public:
 | 
				
			||||||
	[[nodiscard]] bool watchFiles() const;
 | 
						[[nodiscard]] bool watchFiles() const;
 | 
				
			||||||
	void setWatchFiles(bool watchFiles);
 | 
						void setWatchFiles(bool watchFiles);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[[nodiscard]] static QString clipboardText();
 | 
				
			||||||
 | 
						static void setClipboardText(const QString& text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] QString dataDir() const;
 | 
						[[nodiscard]] QString dataDir() const;
 | 
				
			||||||
	[[nodiscard]] QString stateDir() const;
 | 
						[[nodiscard]] QString stateDir() const;
 | 
				
			||||||
	[[nodiscard]] QString cacheDir() const;
 | 
						[[nodiscard]] QString cacheDir() const;
 | 
				
			||||||
| 
						 | 
					@ -195,6 +204,10 @@ signals:
 | 
				
			||||||
	void screensChanged();
 | 
						void screensChanged();
 | 
				
			||||||
	void workingDirectoryChanged();
 | 
						void workingDirectoryChanged();
 | 
				
			||||||
	void watchFilesChanged();
 | 
						void watchFilesChanged();
 | 
				
			||||||
 | 
						void clipboardTextChanged();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private slots:
 | 
				
			||||||
 | 
						void onClipboardChanged(QClipboard::Mode mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	QuickshellGlobal(QObject* parent = nullptr);
 | 
						QuickshellGlobal(QObject* parent = nullptr);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue