You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Linux] Application does not get triggered when hot-key is pressed #93
As a note, in theory if you run a wayland session, all apps running via xwayland (stuff like IDEs, discord, slack and so on) will work, since the apps run inside an Xorg server and so global hotkeys will trigger correctly, but only inside those apps. KDE Plasma 6 has released an initial support for global hotkeys in wayland not long ago, if you need wayland (for stuff like screen tearing, HDR etc) you can try it.
And yes, the README is outdated and needs some updated info, I'll add these things as soon as I can. Thank you for pointing this out.
@momokrono, I've managed to get the app working on Wayland, albeit with a generous interpretation of that term, using KDE Plasma 6.2.5 and the global hotkeys.
In contrast, when running on X11 (using xorg), I can see AI options available. However, on Wayland, all I see is a text box even when a paragraph is selected, the options in the highlighted red box do not appear.
Hi @CsBigDataHub .
That’s happening because Writing Tools is not able to detect any selected text (and is opening in chat mode, which shows when you invoke it without selecting text).
Internally, it emulates a ctrl+c and then tries to read the clipboard to get a hold of the selected text (and also does this without messing with your existing clipboard content by saving & putting that back in milliseconds).
However, it looks like Wayland isn’t allowing that to work. Welp :/
if you run the app from the terminal, when you spawn the window after selecting some text you should see some logs with the backup of the clipboard and the text copied.
Do you see any errors? Is the clipboard accessed correctly? Does the program complain about missing packages?
For example, on a fresh arch installation, I had to install xclip as a necessary dependency. This package is used by pyperclip (the library used to handle the clipboard) to correctly grab the content you selected.
I have identified a potential workaround for the issue on wayland. My web browsers are installed as flatpaks. By utilizing Flatseal to manage flatpak permissions, I disabled the wayland socket, which resolved the problem.
I am now investigating whether a similar approach can be applied to native applications. I attempted to launch kmail with the command XDG_SESSION_TYPE=x11 kmail from the terminal. Although kmail launched and functioned correctly, the Writing-tools application was still unable to simulate Ctrl+c.
I honestly have no clue why it's not working properly, and right now I'm installing Tumbleweed inside a VM to play with it and see if I can help you solve this.
I know flatpacks run sandboxed but I would have never guessed even emulating ctrl+c would be troublesome.
I've read online some users suggest adding yourself to the input group, but I personally didn't need to do so and the app works correctly anyway.
Also, from the logs you provided the app did in fact copy the clipboard:
2025-01-07 09:37:34,136 - DEBUG - Clipboard backup: "" (sleep: 0.2s) <--- your clipboard was empty, so the backup is the empy string
2025-01-07 09:37:34,137 - DEBUG - Simulating Ctrl+C
2025-01-07 09:37:48,312 - DEBUG - Waited 0.2s for clipboard
2025-01-07 09:37:57,692 - DEBUG - Selected text: " press_ctrl_c() <--- this is what you copied from the clipboard
"
so, the app is copying something and this should spawn the popup with the different options. If it doesn't, then there's another bug I should investigate.
Update:
inside the VM, I was able to replicate what I said some messages ago: I installed discord, which I knew runs via xwayland (you can use the command xlsclients to list all apps running via xwayland, get it with sudo zypper install xlsclients) and in this case WritingTools correctly grabs what you select. Outside of xwayland apps, the app spawns the chat popup and works in chat mode, but is unable to correctly grab the selected text.
This is very likely a problem with pynput I need to investigate/fix. I will probably need to switch to python-uinput to have Wayland working correctly, but this will require some refactoring.
For now, Xorg seems to be the only viable session to correctly use the app.
Clipboard backup: "" (sleep: 0.2s) <--- your clipboard was empty, so the backup is the empty string
might not be the case. I have a clipboard history enabled and I am using clipboard history plugin to navigate my clipboard.
2025-01-07 09:37:57,692 - DEBUG - Selected text: " press_ctrl_c() <--- this is what you copied from the clipboard
Yes when Ctrl+c is simulated, the Writing-tools does not recognize the selected text on any application running on Wayland. If the application runs on XWayland, Writing-tools seems to working with out any issue.
I'm curious — @momokrono @CsBigDataHub , if we're able to compile Writing Tools into a Flatpak, and then turn off Wayland for it with Flatseal, would things magically work haha?
Only one way to find out :).
Let me try and compile it Flatpak.
But I want to point out that, compiling the app and using it have been finicky. So I am running the app with python main.py in a venv, which has been more stable.
I opened #292, which adds native Wayland support: the hotkey goes through the global shortcuts portal and text capture uses wl-clipboard + ydotool/wtype, so it works in native Wayland apps without XWayland or Flatseal. It's tested on KDE Plasma 6. If you're on GNOME or Hyprland, it would help to hear whether it works there.
Activity
theJayTea commentedon Jan 3, 2025
Hi! Thanks for reaching out.
@momokrono , would it be possible for you to take a look here?
momokrono commentedon Jan 3, 2025
Hi!
This is probably a problem related to wayland, since by default it does not allow apps to listen to keypresses unless they are in focus.
So, to debug your problem, I would start by logging into an Xorg session, check if the app works there and then try to make it work in wayland.
To login into an Xorg session you should select something like Gnome legacy or Gnome on X or anything along this line in your login manager.
ChetanKoneru commentedon Jan 5, 2025
@momokrono,
You are spot on. Issue is with Wayland. Switched to Xorg and it has been working fine.
Maybe a note in README might help other users.
momokrono commentedon Jan 5, 2025
Well, glad to have "solved" your issue ^^"
As a note, in theory if you run a wayland session, all apps running via xwayland (stuff like IDEs, discord, slack and so on) will work, since the apps run inside an Xorg server and so global hotkeys will trigger correctly, but only inside those apps. KDE Plasma 6 has released an initial support for global hotkeys in wayland not long ago, if you need wayland (for stuff like screen tearing, HDR etc) you can try it.
And yes, the README is outdated and needs some updated info, I'll add these things as soon as I can. Thank you for pointing this out.
ChetanKoneru commentedon Jan 6, 2025
@momokrono, I've managed to get the app working on Wayland, albeit with a generous interpretation of that term, using KDE Plasma 6.2.5 and the global hotkeys.
In contrast, when running on X11 (using xorg), I can see AI options available. However, on Wayland, all I see is a text box even when a paragraph is selected, the options in the highlighted red box do not appear.
ChetanKoneru commentedon Jan 7, 2025
Here is the screenshot on wayland with some content selected. I do not see any options except for the text box.
theJayTea commentedon Jan 7, 2025
Hi @CsBigDataHub .
That’s happening because Writing Tools is not able to detect any selected text (and is opening in chat mode, which shows when you invoke it without selecting text).
Internally, it emulates a ctrl+c and then tries to read the clipboard to get a hold of the selected text (and also does this without messing with your existing clipboard content by saving & putting that back in milliseconds).
However, it looks like Wayland isn’t allowing that to work. Welp :/
momokrono commentedon Jan 7, 2025
Hello @CsBigDataHub
if you run the app from the terminal, when you spawn the window after selecting some text you should see some logs with the backup of the clipboard and the text copied.
Do you see any errors? Is the clipboard accessed correctly? Does the program complain about missing packages?
For example, on a fresh arch installation, I had to install
xclipas a necessary dependency. This package is used by pyperclip (the library used to handle the clipboard) to correctly grab the content you selected.Reopening for visibility
ChetanKoneru commentedon Jan 7, 2025
@theJayTea, @momokrono,
I debugged this application this morning, looks like
Ctrl+ccannot be simulated onwaylandwith pynput.This is the DEBUG log -
As you can see, no text is being selected.
Looks like
pynputdoes not supportwayland(yet).Here are some references -
LOUDO2/PyMacroRecord#61
streamdeck-linux-gui/streamdeck-linux-gui#103
I tried to use
kdotoolby adding it to the path, but looks like it needs elevated permissions todumpkeys.https://eco.kde.org/blog/2024-02-20-sok24-wayland_support_kdeecotest/
https://github.com/jinliu/kdotool
ChetanKoneru commentedon Jan 8, 2025
Hello @momokrono and @theJayTea,
I have identified a potential workaround for the issue on
wayland. My web browsers are installed asflatpaks. By utilizing Flatseal to manageflatpakpermissions, I disabled thewaylandsocket, which resolved the problem.I am now investigating whether a similar approach can be applied to native applications. I attempted to launch
kmailwith the commandXDG_SESSION_TYPE=x11 kmailfrom the terminal. Althoughkmaillaunched and functioned correctly, theWriting-toolsapplication was still unable to simulateCtrl+c.momokrono commentedon Jan 8, 2025
@CsBigDataHub
I honestly have no clue why it's not working properly, and right now I'm installing Tumbleweed inside a VM to play with it and see if I can help you solve this.
I know flatpacks run sandboxed but I would have never guessed even emulating ctrl+c would be troublesome.
I've read online some users suggest adding yourself to the
inputgroup, but I personally didn't need to do so and the app works correctly anyway.Also, from the logs you provided the app did in fact copy the clipboard:
so, the app is copying something and this should spawn the popup with the different options. If it doesn't, then there's another bug I should investigate.
momokrono commentedon Jan 8, 2025
Update:
inside the VM, I was able to replicate what I said some messages ago: I installed discord, which I knew runs via xwayland (you can use the command
xlsclientsto list all apps running via xwayland, get it withsudo zypper install xlsclients) and in this case WritingTools correctly grabs what you select. Outside of xwayland apps, the app spawns the chat popup and works in chat mode, but is unable to correctly grab the selected text.This is very likely a problem with pynput I need to investigate/fix. I will probably need to switch to python-uinput to have Wayland working correctly, but this will require some refactoring.
For now, Xorg seems to be the only viable session to correctly use the app.
ChetanKoneru commentedon Jan 8, 2025
might not be the case. I have a clipboard history enabled and I am using
clipboard historyplugin to navigate my clipboard.Yes when
Ctrl+cis simulated, theWriting-toolsdoes not recognize the selected text on any application running on Wayland. If the application runs onXWayland,Writing-toolsseems to working with out any issue.theJayTea commentedon Jan 21, 2025
As a summary:
Currently, Writing Tools only works on Wayland if you:
This is due to Wayland's security architecture — non-active windows can't intercept hotkeys.
In the future, we could look into implementing KDE's global shortcuts API so things work smoothly on Wayland with KDE.
theJayTea commentedon Jan 21, 2025
I'm curious — @momokrono @CsBigDataHub , if we're able to compile Writing Tools into a Flatpak, and then turn off Wayland for it with Flatseal, would things magically work haha?
ChetanKoneru commentedon Jan 21, 2025
Only one way to find out :).
Let me try and compile it Flatpak.
But I want to point out that, compiling the app and using it have been finicky. So I am running the app with
python main.pyin avenv, which has been more stable.ankitp94 commentedon Feb 22, 2025
I would also like to vote for the Wayland support.
lpuv commentedon Mar 2, 2025
hi! i hope this gets figured out, wayland is a must for me but as soon as this gets sorted i'd love to start using it!
lpuv commentedon Mar 2, 2025
I was doing a little bit of research and would a feature like this make it work in certain compositors?
kareem-jalal commentedon Nov 16, 2026
I opened #292, which adds native Wayland support: the hotkey goes through the global shortcuts portal and text capture uses wl-clipboard + ydotool/wtype, so it works in native Wayland apps without XWayland or Flatseal. It's tested on KDE Plasma 6. If you're on GNOME or Hyprland, it would help to hear whether it works there.