Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wayland support #10

Open
hyuri opened this issue Feb 7, 2024 · 6 comments
Open

Wayland support #10

hyuri opened this issue Feb 7, 2024 · 6 comments

Comments

@hyuri
Copy link

hyuri commented Feb 7, 2024

Hi!

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

@Jiogo18
Copy link
Contributor

Jiogo18 commented Mar 3, 2024

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.

QProcess::startDetached("xdotool", QStringList{"key", "ctrl+v"});

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

@alex1701c
Copy link
Owner

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

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

@alex1701c
Copy link
Owner

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
Copy link
Contributor

Jiogo18 commented Apr 22, 2024

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:

  • ydotool type "Hello 🏃!" doesn't work with emojis

  • ydotool key 135:1 135:0 (KEY_PASTE)

    • works in firefox by default
    • works in other applications only after adding "Paste" as a custom shortcut for Paste in the system manager or the application settings for konsole (hmm).
    • (works only in firefox when using QProcess startDetached?) run with a delay
QProcess::startDetached("sh", QStringList{"-c", "sleep 0.2; ydotool key 135:1 135:0"});
  • ydotool key 29:1 47:1 47:0 29:0 (KEY_LEFTCTRL KEY_V)
  • ydotool key 54:1 110:1 110:0 54:0 (KEY_LEFTSHIFT KEY_INSERT)
    • works, even in QProcess, without changing the settings
    • doesn't work when the application uses the other clipboard (XTerm, the terminal in VSCode)

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
Copy link
Owner

alex1701c commented Jun 26, 2024

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
Copy link
Contributor

veger commented Jun 27, 2024

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

Maybe xdotool gained Wayland support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants