alex1701c / EmojiRunner

Search for emojis in Krunner and copy/paste them
GNU General Public License v3.0
47 stars 7 forks source link

Wayland support #10

Open hyuri opened 7 months ago

hyuri commented 7 months ago

Hi!

Does it work on Wayland, or any plans to add support? I noticed it uses xdotool, which doesn't support Wayland.

Jiogo18 commented 6 months ago

I am using it in a Wayland session with no problem (at least none related to Wayland).

xdotool works well for me (only used for ctrl+v). If you don't have it, the paste option will simply be deactivated (tested in a VM), so no problem. https://github.com/alex1701c/EmojiRunner/blob/5aaa24cfad7e7cee7553c532e3b6c77d1ae9798c/src/runner/emojirunner.cpp#L139

If needed, it could be changed to something like wl-paste.

alex1701c commented 6 months ago

If needed, it could be changed to something like wl-paste.

That seems like good idea, I will play around with it!

alex1701c commented 4 months ago
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 492f0cf..d662a69 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,7 +20,7 @@ include(ECMDeprecationSettings)

 # Find the required Libaries
 find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED CONFIG COMPONENTS Widgets Core)
-find_package(KF${QT_MAJOR_VERSION} ${KF_MIN_VERSION} REQUIRED COMPONENTS I18n Runner ConfigWidgets KCMUtils)
+find_package(KF${QT_MAJOR_VERSION} ${KF_MIN_VERSION} REQUIRED COMPONENTS I18n Runner KCMUtils WindowSystem)

 ecm_set_disabled_deprecation_versions(
    KF ${KF_MIN_VERSION}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1950175..9c7ead7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,7 +2,13 @@ add_definitions(-DTRANSLATION_DOMAIN=\"plasma_runner_org.kde.emojirunner\")
 set(CMAKE_AUTOUIC ON)

 kcoreaddons_add_plugin(emojirunner SOURCES runner/emojirunner.cpp core/Emoji.cpp core/FileReader.cpp INSTALL_NAMESPACE "kf${QT_MAJOR_VERSION}/krunner")
-target_link_libraries(emojirunner KF${QT_MAJOR_VERSION}::Runner KF${QT_MAJOR_VERSION}::I18n KF${QT_MAJOR_VERSION}::ConfigCore Qt::Widgets) # Widgets for QAction, this will change to Qt::Gui in Qt6
+target_link_libraries(emojirunner
+    KF${QT_MAJOR_VERSION}::Runner
+    KF${QT_MAJOR_VERSION}::WindowSystem
+    KF${QT_MAJOR_VERSION}::I18n
+    KF${QT_MAJOR_VERSION}::ConfigCore
+    Qt::Widgets # Widgets for QAction, this will change to Qt::Gui in Qt6
+)

 find_path(XDO_HEADER xdo.h)
 find_library(XDO_LIB "xdo")
@@ -28,7 +34,6 @@ target_link_libraries(kcm_krunner_emojirunner
     KF${QT_MAJOR_VERSION}::CoreAddons
     KF${QT_MAJOR_VERSION}::KCMUtils
     KF${QT_MAJOR_VERSION}::ConfigCore
-    KF${QT_MAJOR_VERSION}::ConfigWidgets
 )
 install(TARGETS kcm_krunner_emojirunner DESTINATION ${KDE_INSTALL_QTPLUGINDIR}/)
 install(FILES core/emojis.json DESTINATION ${KDE_INSTALL_DATADIR}/emojirunner/)
diff --git a/src/runner/emojirunner.cpp b/src/runner/emojirunner.cpp
index f5f8259..4e2caaa 100644
--- a/src/runner/emojirunner.cpp
+++ b/src/runner/emojirunner.cpp
@@ -6,6 +6,7 @@
 #include <KConfigGroup>
 #include <KLocalizedString>
 #include <KSharedConfig>
+#include <KWindowSystem>
 #include <krunner_version.h>

 #include <QApplication>
@@ -157,6 +158,13 @@ KRunner::QueryMatch EmojiRunner::createQueryMatch(const Emoji &emoji, const qrea

 void EmojiRunner::emitCTRLV()
 {
+    const static QString wlPaste = QStandardPaths::findExecutable("wl-paste");
+    if (KWindowSystem::isPlatformWayland() && !wlPaste.isEmpty()) {
+        QTimer::singleShot(50, []() {
+            QProcess::startDetached(wlPaste);
+        });
+        return;
+    }
 #ifdef XDO_LIB
     // Emit Ctrl+V to paste clipboard content
     xdo_send_keysequence_window(xdo, CURRENTWINDOW, "ctrl+v", 0);

Hmm, but wl-paste sends it not to the focussed window :(

Jiogo18 commented 4 months ago

Giving a closer look at wl-clipboard, it seems that pasting to another window is not a use case, despite what I though, sorry about that.

Rofimoji uses wtype. Unfortunatly, wtype requires https://wayland.app/protocols/virtual-keyboard-unstable-v1 which is not yet available in KDE (KWin 6.0.4 currently).

Using ydotool:

Side note: xdotool key ctrl+v still works in some applications (e.g. electron apps).

So, lots of possibilities... with a downside to each. wtype may be the way to go if supported. I will try shift+insert for now.

alex1701c commented 2 months ago

Side note: xdotool key ctrl+v still works in some applications (e.g. electron apps).

I think that is due to the xwayland stuff ;)

So, lots of possibilities... with a downside to each. wtype may be the way to go if supported.

Yeah ... not really sure what to do

veger commented 2 months ago

I am using Wayland as well, and the AUR package I build uses xdotool (library) and it works fine.

Maybe xdotool gained Wayland support?