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

[KDE/Wayland] Immediate deactivate event on keyboard shortcut for module #887

Closed
milas opened this issue Oct 28, 2023 · 5 comments
Closed

Comments

@milas
Copy link

milas commented Oct 28, 2023

Describe the bug
On KDE/Wayland with fcitx5, when a module is activated with a shortcut key, there's a deactivate immediately followed by a reactivate.

I'm trying to use im-emoji-picker, and this is causing it to not work in this configuration:

ok the only thing i can imagine at this point is that there must be some kind of bug with KDE (wayland) + fcitx5 because fcitx immediately sends the deactivate event after the window opens (which is obviously wrong) and then it goes dark.
if i start the fcitx daemon with QT_QPA_PLATFORM=xcb it kinda works but that's obviously no solution.

Is this the expected behavior from fcitx5? Or a kwin integration issue?

To Reproduce
Steps to reproduce the behavior:

  1. Run fcitx5 under KDE/Wayland
  2. Install im-emoji-picker module
  3. Press Ctrl-Alt-. in an input field to trigger it
  4. A window will spawn and very quickly disappear

Expected behavior
Module opens and remains open.

Desktop (please complete the following information):

  • Desktop: KDE 5.27.9
  • Display server type: Wayland

I'm running NixOS, so note that even though the fcitx5-diagnose log doesn't show the addon, it is actually picked up at runtime correctly.

Also, for what it's worth, if I switch into X11, everything works as expected.

fcitx5-diagnose.log
# System Info:
1.  `uname -a`:
    Linux hyperion 6.5.9 #1-NixOS SMP PREEMPT_DYNAMIC Wed Oct 25 10:16:30 UTC 2023 x86_64 GNU/Linux
  1. lsb_release:

    lsb_release not found.

  2. /etc/lsb-release:

    DISTRIB_CODENAME=tapir
    DISTRIB_DESCRIPTION="NixOS 23.11 (Tapir)"
    DISTRIB_ID=nixos
    DISTRIB_RELEASE="23.11"
    LSB_VERSION="23.11 (Tapir)"
    
  3. /etc/os-release:

    BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
    BUILD_ID="23.11.20231026.63678e9"
    DOCUMENTATION_URL="https://nixos.org/learn.html"
    HOME_URL="https://nixos.org/"
    ID=nixos
    LOGO="nix-snowflake"
    NAME=NixOS
    PRETTY_NAME="NixOS 23.11 (Tapir)"
    SUPPORT_URL="https://nixos.org/community.html"
    VERSION="23.11 (Tapir)"
    VERSION_CODENAME=tapir
    VERSION_ID="23.11"
    
  4. Desktop Environment:

    Desktop environment is kde.

  5. XDG SESSION TYPE:

    XDG_SESSION_TYPE='wayland'
    
  6. Bash Version:

    BASH_VERSION='5.2.15(1)-release'
    

Environment:

  1. DISPLAY:

    DISPLAY=':1'
    
    
    WAYLAND_DISPLAY='wayland-0'
    
  2. Keyboard Layout:

    1. setxkbmap:

      WARNING: Running setxkbmap against an Xwayland server
      xkb_keymap {
      	xkb_keycodes  { include "evdev+aliases(qwerty)"	};
      	xkb_types     { include "complete"	};
      	xkb_compat    { include "complete"	};
      	xkb_symbols   { include "pc+us+inet(evdev)"	};
      	xkb_geometry  { include "pc(pc105)"	};
      };
      
    2. xprop:

      _XKB_RULES_NAMES(STRING) = "evdev", "pc105", "us", "", ""
      
  3. Locale:

    1. All locales:

      C
      C.utf8
      en_US.utf8
      POSIX
      
    2. Current locale:

      LANG=en_US.UTF-8
      LC_CTYPE="en_US.UTF-8"
      LC_NUMERIC=en_US.UTF-8
      LC_TIME=en_US.UTF-8
      LC_COLLATE="en_US.UTF-8"
      LC_MONETARY=en_US.UTF-8
      LC_MESSAGES="en_US.UTF-8"
      LC_PAPER=en_US.UTF-8
      LC_NAME=en_US.UTF-8
      LC_ADDRESS=en_US.UTF-8
      LC_TELEPHONE=en_US.UTF-8
      LC_MEASUREMENT=en_US.UTF-8
      LC_IDENTIFICATION=en_US.UTF-8
      LC_ALL=
      
  4. Directories:

    1. Home:

      /home/milas
      
    2. ${XDG_CONFIG_HOME}:

      Environment variable XDG_CONFIG_HOME is not set.

      Current value of XDG_CONFIG_HOME is ~/.config (/home/milas/.config).

    3. Fcitx5 Settings Directory:

      Current fcitx5 settings directory is ~/.config/fcitx5 (/home/milas/.config/fcitx5).

  5. Current user:

    The script is run as milas (1000).

Fcitx State:

  1. executable:

    Found fcitx5 at /run/current-system/sw/bin/fcitx5.

  2. version:

    Fcitx version: 5.1.1

  3. process:

    Found 2 fcitx5 processes:

      61687 fcitx5
      66291 fcitx5-diagnose
    
  4. fcitx5-remote:

    fcitx5-remote works properly.

  5. DBus interface:

    Using dbus-send to check dbus.

    Owner of DBus name org.fcitx.Fcitx5 is :1.159.

    PID of DBus name org.fcitx.Fcitx5 owner is 61687.

    Debug information from dbus:

       Group [x11::1] has 1 InputContext(s)
      IC [870ab84af892441c85f871500710091d] program:java frontend:xim cap:4000000000 focus:1
    Group [wayland:] has 5 InputContext(s)
      IC [86733472f4f649c7939ad3a25077f9c5] program:firefox frontend:dbus cap:6001000032 focus:0
      IC [c735d514cc064db79c0550bccea48ed5] program:firefox frontend:dbus cap:6001000032 focus:0
      IC [6e914321d9f04b428f09f42f1c955494] program:firefox frontend:dbus cap:6001000032 focus:0
      IC [b0fec37164834ff98943165d05b563df] program:firefox frontend:dbus cap:e001000032 focus:0
      IC [4e9532a037bd47068d42f4727d286105] program:firefox frontend:dbus cap:e001000072 focus:0
    Input Context without group
    

Fcitx Configure UI:

  1. Config Tool Wrapper:

    Found fcitx5-configtool at /run/current-system/sw/bin/fcitx5-configtool.

  2. Config GUI for qt:

    Found fcitx5-config-qt at /run/current-system/sw/bin/fcitx5-config-qt.

  3. Config GUI for kde:

    Found fcitx5 kcm module.

    kcm_fcitx5                     - Configure Input Method
    

Frontends setup:

The environment variable checked by this script only shows the environment under current shell. It is still possible
that you did not set the environment to the whole graphic desktop session. You may inspect the actual environment
variable of a certain process by using xargs -0 -L1 /proc/$PID/environ for a certain process that you find not
working.

Xim:

  1. ${XMODIFIERS}:

    Environment variable XMODIFIERS is set to "@im=fcitx" correctly.
    Xim Server Name from Environment variable is fcitx.

  2. XIM_SERVERS on root window:

    Xim server name is the same with that set in the environment variable.

Qt:

  1. qt4 - ${QT4_IM_MODULE}:

    **Please set environment variable QT_IM_MODULE to "fcitx" using the tool your distribution provides or
    add export QT_IM_MODULE=fcitx to your ~/.xprofile.
    See Input Method Related Environment Variables: QT_IM_MODULE.
    **

    fcitx5-qt4-immodule-probing not found.

  2. qt5 - ${QT_IM_MODULE}:

    **Please set environment variable QT_IM_MODULE to "fcitx" using the tool your distribution provides or
    add export QT_IM_MODULE=fcitx to your ~/.xprofile.
    See Input Method Related Environment Variables: QT_IM_MODULE.
    **

    It is OK to use qt5 built-in Wayland im module if your compositor fully supports text-input protocol used by qt5.

    Using fcitx5-qt5-immodule-probing to check the actual im module to be used under current environment:

    QT_QPA_PLATFORM=wayland
    QT_IM_MODULE=
    IM_MODULE_CLASSNAME=QComposeInputContext
    
  3. qt6 - ${QT_IM_MODULE}:

    **Please set environment variable QT_IM_MODULE to "fcitx" using the tool your distribution provides or
    add export QT_IM_MODULE=fcitx to your ~/.xprofile.
    See Input Method Related Environment Variables: QT_IM_MODULE.
    **

    It is OK to use qt6 built-in Wayland im module if your compositor fully supports text-input protocol used by qt6.

    Using fcitx5-qt6-immodule-probing to check the actual im module to be used under current environment:

    QT_QPA_PLATFORM=xcb
    QT_IM_MODULE=
    IM_MODULE_CLASSNAME=QComposeInputContext
    
  4. Qt IM module files:

    Following error may not be accurate because guessing Qt version from path depends on how your distribution packages Qt. It is not a critical error if you do not use any Qt application with certain version of Qt or you are using text-input support by Qt under Wayland.
    Cannot find fcitx5 input method module for Qt4.
    Cannot find fcitx5 input method module for Qt5.
    Cannot find fcitx5 input method module for Qt6.

Gtk:

  1. gtk - ${GTK_IM_MODULE}:

    Environment variable GTK_IM_MODULE is set to "fcitx" correctly.

    fcitx5-gtk2-immodule-probing not found.

    Using fcitx5-gtk3-immodule-probing to check the actual im module to be used under current environment:

    GTK_IM_MODULE=fcitx
    

    Using fcitx5-gtk4-immodule-probing to check the actual im module to be used under current environment:

    GTK_IM_MODULE=fcitx
    
  2. gtk-query-immodules:

    1. gtk 2:

      Cannot find gtk-query-immodules for gtk 2

      Cannot find fcitx5 im module for gtk 2.

    2. gtk 3:

      Cannot find gtk-query-immodules for gtk 3

      Cannot find fcitx5 im module for gtk 3.

  3. Gtk IM module cache:

    1. gtk 2:

      Cannot find immodules cache for gtk 2

      Cannot find fcitx5 im module for gtk 2 in cache.

    2. gtk 3:

      Cannot find immodules cache for gtk 3

      Cannot find fcitx5 im module for gtk 3 in cache.

  4. Gtk IM module files:

    1. gtk 2:

      All found Gtk 2 immodule files exist.

    2. gtk 3:

      All found Gtk 3 immodule files exist.

    3. gtk 4:

      All found Gtk 4 immodule files exist.

Configuration:

Fcitx Addons:

  1. Addon Config Dir:

    Found fcitx5 addon config directory: /nix/store/2bx2by6530c35q0z8b3gj44x80c8bp99-fcitx5-5.1.1/share/fcitx5/addon.

  2. Addon List:

    1. Found 20 enabled addons:

      Classic User Interface 5.1.1
      Clipboard 5.1.1
      DBus 5.1.1
      DBus Frontend 5.1.1
      Emoji 5.1.1
      Fcitx4 Frontend 5.1.1
      IBus Frontend 5.1.1
      Input method selector 5.1.1
      Keyboard 5.1.1
      KDE Input Method Panel 5.1.1
      Status Notifier 5.1.1
      Notification 5.1.1
      Quick Phrase 5.1.1
      Spell 5.1.1
      Unicode 5.1.1
      DBus Virtual Keyboard 5.1.1
      Wayland 5.1.1
      Wayland Input method frontend 5.1.1
      XCB 5.1.1
      X Input Method Frontend 5.1.1
      
    2. Found 0 disabled addons:

  3. Addon Libraries:

    All libraries for all addons are found.

  4. User Interface:

    Found 3 enabled user interface addons:

    Classic User Interface
    KDE Input Method Panel
    DBus Virtual Keyboard
    

Input Methods:

  1. /home/milas/.config/fcitx5/profile:

    [Groups/0]
    # Group Name
    Name=Default
    # Layout
    Default Layout=us
    # Default Input Method
    DefaultIM=keyboard-us
    
    [Groups/0/Items/0]
    # Name
    Name=keyboard-us
    # Layout
    Layout=
    
    [GroupOrder]
    0=Default
    

Log:

  1. date:

    Fri Oct 27 10:04:32 PM EDT 2023
    
  2. /home/milas/.config/fcitx5/crash.log:

    =========================
    Fcitx 5.1.1 -- Get Signal No.: 11
    Date: try "date -d @1698457868" if you are using GNU date ***
    ProcessID: 53663
    fcitx5[0x411ced]
    /nix/store/gqghjch4p1s69sv4mcjksb2kb65rwqjy-glibc-2.38-23/lib/libc.so.6(+0x3da70)[0x7f0fb7255a70]
    /nix/store/2bx2by6530c35q0z8b3gj44x80c8bp99-fcitx5-5.1.1/lib/libFcitx5Core.so.7(_ZNK5fcitx12InputContext7programB5cxx11Ev+0x0)[0x7f0fb7973470]
    /nix/store/mscqwh14r84d08hwx8zniifwd80f62lz-fcitx5-with-addons-5.1.1/lib/fcitx5/libclassicui.so(+0x87f68)[0x7f0fa515ff68]
    /nix/store/mscqwh14r84d08hwx8zniifwd80f62lz-fcitx5-with-addons-5.1.1/lib/fcitx5/libclassicui.so(+0x62f59)[0x7f0fa513af59]
    /nix/store/2bx2by6530c35q0z8b3gj44x80c8bp99-fcitx5-5.1.1/lib/libFcitx5Core.so.7(_ZNK5fcitx8Instance9postEventERNS_5EventE+0x357)[0x7f0fb7949df7]
    /nix/store/2bx2by6530c35q0z8b3gj44x80c8bp99-fcitx5-5.1.1/lib/libFcitx5Core.so.7(_ZN5fcitx10FocusGroup22setFocusedInputContextEPNS_12InputContextE+0xa1)[0x7f0fb79724c1]
    /nix/store/mscqwh14r84d08hwx8zniifwd80f62lz-fcitx5-with-addons-5.1.1/lib/fcitx5/libdbusfrontend.so(+0x1abc4)[0x7f0fb60afbc4]
    /nix/store/2bx2by6530c35q0z8b3gj44x80c8bp99-fcitx5-5.1.1/lib/libFcitx5Utils.so.2(+0x4b715)[0x7f0fb784f715]
    /nix/store/vapnrxrw3b21c7ji61bmnbzl2cj1vl96-systemd-254.3/lib/libsystemd.so.0(+0x37937)[0x7f0fb714f937]
    /nix/store/vapnrxrw3b21c7ji61bmnbzl2cj1vl96-systemd-254.3/lib/libsystemd.so.0(+0x38d3b)[0x7f0fb7150d3b]
    /nix/store/vapnrxrw3b21c7ji61bmnbzl2cj1vl96-systemd-254.3/lib/libsystemd.so.0(+0x4bac6)[0x7f0fb7163ac6]
    /nix/store/vapnrxrw3b21c7ji61bmnbzl2cj1vl96-systemd-254.3/lib/libsystemd.so.0(+0x4c598)[0x7f0fb7164598]
    /nix/store/vapnrxrw3b21c7ji61bmnbzl2cj1vl96-systemd-254.3/lib/libsystemd.so.0(+0x84941)[0x7f0fb719c941]
    /nix/store/vapnrxrw3b21c7ji61bmnbzl2cj1vl96-systemd-254.3/lib/libsystemd.so.0(sd_event_dispatch+0x10d)[0x7f0fb719cc5d]
    /nix/store/vapnrxrw3b21c7ji61bmnbzl2cj1vl96-systemd-254.3/lib/libsystemd.so.0(sd_event_run+0xb8)[0x7f0fb719d478]
    /nix/store/vapnrxrw3b21c7ji61bmnbzl2cj1vl96-systemd-254.3/lib/libsystemd.so.0(sd_event_loop+0x57)[0x7f0fb719d697]
    /nix/store/2bx2by6530c35q0z8b3gj44x80c8bp99-fcitx5-5.1.1/lib/libFcitx5Utils.so.2(_ZN5fcitx9EventLoop4execEv+0x11)[0x7f0fb7850c11]
    /nix/store/2bx2by6530c35q0z8b3gj44x80c8bp99-fcitx5-5.1.1/lib/libFcitx5Core.so.7(_ZN5fcitx8Instance4execEv+0x54)[0x7f0fb79531f4]
    fcitx5[0x410510]
    /nix/store/gqghjch4p1s69sv4mcjksb2kb65rwqjy-glibc-2.38-23/lib/libc.so.6(+0x27fce)[0x7f0fb723ffce]
    /nix/store/gqghjch4p1s69sv4mcjksb2kb65rwqjy-glibc-2.38-23/lib/libc.so.6(__libc_start_main+0x89)[0x7f0fb7240089]
    fcitx5[0x410c95]
    

Warning: the output of fcitx5-diagnose contains sensitive information, including the distribution name, kernel
version, name of currently running programs, etc.

Though such information can be helpful to developers for diagnostic purpose, please double check and remove as
necessary before posting it online publicly.

Additional context

instance.cpp:2275] Instance::activateInputMethod
instance.cpp:2280] Activate: [Last]: [Activating]:keyboard-us
instance.cpp:904] KeyEvent: Key(Alt_L states=0) rawKey: Key(Alt_L states=0) origKey: Key(Alt_L states=0) Release:0
inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
instance.cpp:904] KeyEvent: Key(Alt+Control_L states=8) rawKey: Key(Alt+Control_L states=8) origKey: Key(Alt+Control_L states=8) Release:0
inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
instance.cpp:904] KeyEvent: Key(Control+Alt+period states=12) rawKey: Key(Control+Alt+period states=12) origKey: Key(Control+Alt+period states=12) Release:0
inputcontext.cpp:320] KeyEvent handling time: 0ms result:1
instance.cpp:2317] Instance::deactivateInputMethod event_type=4100
instance.cpp:2335] Deactivate: [Last]:keyboard-us [Deactivating]:keyboard-us
instance.cpp:2275] Instance::activateInputMethod
instance.cpp:2280] Activate: [Last]: [Activating]:keyboard-us
instance.cpp:904] KeyEvent: Key(Control+Alt+period states=12) rawKey: Key(Control+Alt+period states=12) origKey: Key(Control+Alt+period states=12) Release:1
inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
instance.cpp:904] KeyEvent: Key(Control+Alt+Alt_L states=12) rawKey: Key(Control+Alt+Alt_L states=12) origKey: Key(Control+Alt+Alt_L states=12) Release:1
inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
instance.cpp:904] KeyEvent: Key(Control+Control_L states=4) rawKey: Key(Control+Control_L states=4) origKey: Key(Control+Control_L states=4) Release:1
inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
instance.cpp:2317] Instance::deactivateInputMethod event_type=4100
instance.cpp:2335] Deactivate: [Last]:keyboard-us [Deactivating]:keyboard-us
@wengxt
Copy link
Member

wengxt commented Oct 28, 2023

That's however, not a solvable issue from fcitx side.

Mainly it's because that the emoji picker itself embeds Qt and it will grab the focus away on wayland. that's why you see the deactivate event.

@wengxt wengxt closed this as completed Oct 28, 2023
@milas
Copy link
Author

milas commented Oct 28, 2023

Thanks for the quick response!

Do you have any idea why the (de)activation behavior is different in X11?

Here's a log from me trigger it in Plasma/X11 in Firefox (where it works as expected):

D2023-10-28 10:16:24.668370 instance.cpp:2275] Instance::activateInputMethod
D2023-10-28 10:16:24.668412 instance.cpp:2280] Activate: [Last]: [Activating]:keyboard-us
D2023-10-28 10:16:24.796243 classicui.cpp:490] Update component: 0 for IC program:firefox frontend:dbus display:x11::0 ui:x11::0
D2023-10-28 10:16:25.063851 instance.cpp:904] KeyEvent: Key(Alt_L states=0) rawKey: Key(Alt_L states=0) origKey: Key(Alt_L states=0) Release:0
D2023-10-28 10:16:25.063957 inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
D2023-10-28 10:16:25.166411 instance.cpp:904] KeyEvent: Key(Alt+Control_L states=8) rawKey: Key(Alt+Control_L states=8) origKey: Key(Alt+Control_L states=8) Release:0
D2023-10-28 10:16:25.166533 inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
D2023-10-28 10:16:25.513378 instance.cpp:904] KeyEvent: Key(Control+Alt+period states=12) rawKey: Key(Control+Alt+period states=12) origKey: Key(Control+Alt+period states=12) Release:0
D2023-10-28 10:16:25.513583 classicui.cpp:490] Update component: 0 for IC program:firefox frontend:dbus display:x11::0 ui:x11::0
D2023-10-28 10:16:25.513690 inputcontext.cpp:320] KeyEvent handling time: 0ms result:1
D2023-10-28 10:16:25.619328 instance.cpp:904] KeyEvent: Key(Control+Alt+period states=12) rawKey: Key(Control+Alt+period states=12) origKey: Key(Control+Alt+period states=12) Release:1
D2023-10-28 10:16:25.619455 inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
D2023-10-28 10:16:25.831094 instance.cpp:904] KeyEvent: Key(Control+Alt+Control_L states=12) rawKey: Key(Control+Alt+Control_L states=12) origKey: Key(Control+Alt+Control_L states=12) Release:1
D2023-10-28 10:16:25.831220 inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
D2023-10-28 10:16:25.853936 instance.cpp:904] KeyEvent: Key(Alt+Alt_L states=8) rawKey: Key(Alt+Alt_L states=8) origKey: Key(Alt+Alt_L states=8) Release:1
D2023-10-28 10:16:25.854039 inputcontext.cpp:320] KeyEvent handling time: 0ms result:0
D2023-10-28 10:16:26.578685 instance.cpp:2317] Instance::deactivateInputMethod event_type=4100
D2023-10-28 10:16:26.578755 instance.cpp:2335] Deactivate: [Last]:keyboard-us [Deactivating]:keyboard-us
D2023-10-28 10:16:26.578857 classicui.cpp:490] Update component: 0 for IC program:firefox frontend:dbus display:x11::0 ui:x11::0
D2023-10-28 10:16:26.595366 instance.cpp:2275] Instance::activateInputMethod
D2023-10-28 10:16:26.595406 instance.cpp:2280] Activate: [Last]: [Activating]:keyboard-us
D2023-10-28 10:16:26.602578 instance.cpp:2317] Instance::deactivateInputMethod event_type=4100
D2023-10-28 10:16:26.602640 instance.cpp:2335] Deactivate: [Last]:keyboard-us [Deactivating]:keyboard-us
D2023-10-28 10:16:26.602767 classicui.cpp:490] Update component: 0 for IC program:firefox frontend:dbus display:x11::0 ui:x11::0

Would this be something in kwin? Or is it a fundamental X11 vs Wayland difference?

Forgive all the questions - I'm trying to understand between kwin/fcitx5/im-emoji-picker where things need to change 😅

@wengxt
Copy link
Member

wengxt commented Oct 28, 2023

emoji picker, but I'm not very sure if it's doable.

X11 you have lots of freedom to create a specialized window, while under wayland you just don't have much choice. The API just don't let you do so.

Also, the way that how emoji picker is implemented just simply doesn't work on wayland. the wayland input method requires a special surface and protocol to be put the window at the right place. The cursor location API is meaningless on wayland.

If emoji picker want to display a on the spot window (a window besides the cursor) under wayland, I'd say it's simply impossible under it's current approach.

@wengxt
Copy link
Member

wengxt commented Oct 28, 2023

It's a very complex topic that is relevant to how wayland input method protocol works, how emoji picker is implemeneted, how Qt realize the wayland surface.

The only way I can see is to implement something on top of fcitx without using any Qt.

@milas
Copy link
Author

milas commented Oct 28, 2023

Thank you so much! That's really helpful info - I'll have to think about where to go from here 🤔

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

2 participants