Skip to content

[Linux] Application does not get triggered when hot-key is pressed #93

Description

@ChetanKoneru

Hello,

I was able to build the application but I am not able to trigger it even though I can see the application running on task bar.

I tried multiple combinations without success, here are the combinations I tried to set in application settings -

ctrl+space
ctrl+`
ctrl+F1 [I tried all function keys]
Ctrl+space
Ctrl+`
Ctrl+F1 [I tried all function keys]
Just keys too.

Information:

  • Firmware Version: 1.93
  • OS Name: openSUSE Tumbleweed
  • OS Type: 64-bit
  • GNOME Version: 47
  • Windowing System: Wayland
  • Kernel Version: Linux 6.12.6-1-default

Activity

  1. theJayTea commented on Jan 3, 2025

    @theJayTea
    Owner

    Hi! Thanks for reaching out.

    @momokrono , would it be possible for you to take a look here?

  2. momokrono commented on Jan 3, 2025

    @momokrono
    Collaborator

    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.

  3. ChetanKoneru commented on Jan 5, 2025

    @ChetanKoneru
    Author

    @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.

  4. momokrono commented on Jan 5, 2025

    @momokrono
    Collaborator

    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.

  5. ChetanKoneru commented on Jan 6, 2025

    @ChetanKoneru
    Author

    @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.

    Screenshot_20250106_175124

  6. ChetanKoneru commented on Jan 7, 2025

    @ChetanKoneru
    Author

    Here is the screenshot on wayland with some content selected. I do not see any options except for the text box.

    Screenshot_20250106_190116

  7. theJayTea commented on Jan 7, 2025

    @theJayTea
    Owner

    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 :/

  8. momokrono commented on Jan 7, 2025

    @momokrono
    Collaborator

    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 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.

    Reopening for visibility

  9. ChetanKoneru commented on Jan 7, 2025

    @ChetanKoneru
    Author

    @theJayTea, @momokrono,

    I debugged this application this morning, looks like Ctrl+c cannot be simulated on wayland with pynput.

    This is the DEBUG log -

    2025-01-07 09:37:29,052 - DEBUG - Loading config from /home/mypc/git-repos/WritingTools/Windows_and_Linux/config.json
    2025-01-07 09:37:29,053 - DEBUG - Config loaded successfully
    2025-01-07 09:37:29,053 - DEBUG - Config found, setting up hotkey and tray icon
    2025-01-07 09:37:29,115 - DEBUG - Creating system tray icon
    2025-01-07 09:37:29,122 - DEBUG - Tray icon dark
    2025-01-07 09:37:29,122 - DEBUG - Tray icon displayed
    2025-01-07 09:37:29,122 - DEBUG - Registering hotkey
    2025-01-07 09:37:29,122 - DEBUG - Registering global hotkey for shortcut: <ctrl>+`
    2025-01-07 09:37:29,124 - DEBUG - Hotkey registered
    2025-01-07 09:37:34,126 - DEBUG - triggered hotkey
    2025-01-07 09:37:34,126 - DEBUG - Hotkey pressed
    2025-01-07 09:37:34,126 - DEBUG - Cancelling current provider's request
    2025-01-07 09:37:34,134 - DEBUG - Showing popup window
    2025-01-07 09:37:34,136 - DEBUG - Clipboard backup: "" (sleep: 0.2s)
    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()
    "
    2025-01-07 09:38:06,612 - DEBUG - Selected text: "        press_ctrl_c()
    

    As you can see, no text is being selected.

    Looks like pynput does not support wayland (yet).

    Here are some references -

    LOUDO2/PyMacroRecord#61
    streamdeck-linux-gui/streamdeck-linux-gui#103

    I tried to use kdotool by adding it to the path, but looks like it needs elevated permissions to dumpkeys.
    https://eco.kde.org/blog/2024-02-20-sok24-wayland_support_kdeecotest/
    https://github.com/jinliu/kdotool

  10. ChetanKoneru commented on Jan 8, 2025

    @ChetanKoneru
    Author

    Hello @momokrono and @theJayTea,

    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.

    Screenshot_20250107_200232

    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.

  11. momokrono commented on Jan 8, 2025

    @momokrono
    Collaborator

    @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 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.

  12. self-assigned this
    on Jan 8, 2025
  13. momokrono commented on Jan 8, 2025

    @momokrono
    Collaborator

    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.

  14. ChetanKoneru commented on Jan 8, 2025

    @ChetanKoneru
    Author

    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.

  15. theJayTea commented on Jan 21, 2025

    @theJayTea
    Owner

    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.

  16. theJayTea commented on Jan 21, 2025

    @theJayTea
    Owner

    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?

  17. ChetanKoneru commented on Jan 21, 2025

    @ChetanKoneru
    Author

    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.

  18. ankitp94 commented on Feb 22, 2025

    @ankitp94

    I would also like to vote for the Wayland support.

  19. lpuv commented on Mar 2, 2025

    @lpuv

    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!

  20. lpuv commented on Mar 2, 2025

    @lpuv

    I was doing a little bit of research and would a feature like this make it work in certain compositors?

  21. kareem-jalal commented on Nov 16, 2026

    @kareem-jalal

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions