fcitx / fcitx5

maybe a new fcitx.
1.62k stars 118 forks source link

Tray icon for `Mozc` disappears when input field is not focused #849

Closed musjj closed 1 year ago

musjj commented 1 year ago

Describe the bug The system tray for Mozc disappears when the input field is unfocused.

When focused: focused

When unfocused: unfocused

The default input method (Keyboard - English (US)) doesn't suffer from this problem.

To Reproduce

  1. Focus the input field
  2. Switch to the Mozc input method
  3. Unfocus the input field

Expected behavior The icon should stay visible even when unfocused

Desktop (please complete the following information):

Additional context I'm using papirus-icon-theme.

wengxt commented 1 year ago

What's your distro? I wonder whether they package mozc icon correctly.

Can you list all the files for fcitx5-mozc package?

Also what's the version of fcitx5 and fcitx5-mozc?

musjj commented 1 year ago

I'm using NixOS.

List of files for `fcitx5-mozc` ``` . ├── lib │   ├── fcitx5 │   │   └── fcitx5-mozc.so │   └── mozc │   ├── mozc_server │   └── mozc_tool └── share ├── doc │   └── mozc │   └── credits_en.html ├── fcitx5 │   ├── addon │   │   └── mozc.conf │   └── inputmethod │   └── mozc.conf ├── icons │   └── hicolor │   ├── 128x128 │   │   └── apps │   │   ├── fcitx-mozc.png -> org.fcitx.Fcitx5.fcitx-mozc.png │   │   └── org.fcitx.Fcitx5.fcitx-mozc.png │   ├── 32x32 │   │   └── apps │   │   ├── fcitx-mozc.png -> org.fcitx.Fcitx5.fcitx-mozc.png │   │   └── org.fcitx.Fcitx5.fcitx-mozc.png │   └── 48x48 │   └── apps │   ├── fcitx-mozc-alpha-full.png -> org.fcitx.Fcitx5.fcitx-mozc-alpha-full.png │   ├── fcitx-mozc-alpha-half.png -> org.fcitx.Fcitx5.fcitx-mozc-alpha-half.png │   ├── fcitx-mozc-dictionary.png -> org.fcitx.Fcitx5.fcitx-mozc-dictionary.png │   ├── fcitx-mozc-direct.png -> org.fcitx.Fcitx5.fcitx-mozc-direct.png │   ├── fcitx-mozc-hiragana.png -> org.fcitx.Fcitx5.fcitx-mozc-hiragana.png │   ├── fcitx-mozc-katakana-full.png -> org.fcitx.Fcitx5.fcitx-mozc-katakana-full.png │   ├── fcitx-mozc-katakana-half.png -> org.fcitx.Fcitx5.fcitx-mozc-katakana-half.png │   ├── fcitx-mozc-properties.png -> org.fcitx.Fcitx5.fcitx-mozc-properties.png │   ├── fcitx-mozc-tool.png -> org.fcitx.Fcitx5.fcitx-mozc-tool.png │   ├── org.fcitx.Fcitx5.fcitx-mozc-alpha-full.png │   ├── org.fcitx.Fcitx5.fcitx-mozc-alpha-half.png │   ├── org.fcitx.Fcitx5.fcitx-mozc-dictionary.png │   ├── org.fcitx.Fcitx5.fcitx-mozc-direct.png │   ├── org.fcitx.Fcitx5.fcitx-mozc-hiragana.png │   ├── org.fcitx.Fcitx5.fcitx-mozc-katakana-full.png │   ├── org.fcitx.Fcitx5.fcitx-mozc-katakana-half.png │   ├── org.fcitx.Fcitx5.fcitx-mozc-properties.png │   └── org.fcitx.Fcitx5.fcitx-mozc-tool.png ├── licenses │   └── fcitx5-mozc │   ├── credits_en.html │   └── LICENSE ├── locale │   ├── ca │   │   └── LC_MESSAGES │   │   └── fcitx5-mozc.mo │   ├── da │   │   └── LC_MESSAGES │   │   └── fcitx5-mozc.mo │   ├── de │   │   └── LC_MESSAGES │   │   └── fcitx5-mozc.mo │   ├── he │   │   └── LC_MESSAGES │   │   └── fcitx5-mozc.mo │   ├── ja │   │   └── LC_MESSAGES │   │   └── fcitx5-mozc.mo │   ├── ko │   │   └── LC_MESSAGES │   │   └── fcitx5-mozc.mo │   ├── ru │   │   └── LC_MESSAGES │   │   └── fcitx5-mozc.mo │   ├── zh_CN │   │   └── LC_MESSAGES │   │   └── fcitx5-mozc.mo │   └── zh_TW │   └── LC_MESSAGES │   └── fcitx5-mozc.mo └── metainfo └── org.fcitx.Fcitx5.Addon.Mozc.metainfo.xml 40 directories, 40 files ```

I'd expect the icon to be the same whether a field is focused or not. Is there at least a way to know what icon is it trying to load?

wengxt commented 1 year ago

can you try again with latest mozc? 2.26.4220 is pretty old, almost 3 years old.

latest mozc should show different mode icon for hirigana/katakana/direct input/ etc.

wengxt commented 1 year ago

I can't provide any support for a out-of-date version.

Here's what it looks like on latest version.

https://github.com/fcitx/fcitx5/assets/259684/2b903762-96cb-4da4-ac8c-123cbcb65cd2

musjj commented 1 year ago

Yeah, it looks like that the package on NixOS is outdated, I'll try to make a package out of the latest version and see if it works.

musjj commented 1 year ago

Tested the latest version, and it works now. Thanks for the help.

musjj commented 1 year ago

Looks like the icon disappearing issue returned in a different form.

On the first startup, fcitx will display a blank icon until you focus on any input field or type on an already focused one.

You can reproduce this by restarting the fcitx5 daemon.

My default input method is Keyboard - English (US), so I don't think this is a Mozc issue anymore.

wengxt commented 1 year ago

@musjj the default icon is input keyboard

musjj commented 1 year ago

What is the name/path of that icon? I can't find it in src/data/images:

https://github.com/fcitx/mozc/tree/fcitx/src/data/images/unix

Does it come from somewhere else?

rocka commented 1 year ago

input-keyboard is a standard XDG icon name, which should be provided by your DE's default icon theme. Breeze Icons (KDE) and Adwaita (GNOME) both include it.

https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html

musjj commented 1 year ago

I see.

I'm guessing that this is a NixOS-specific issue, so closing this for now.

musjj commented 1 year ago

Actually, can you please explain the mechanism fcitx5 uses to retrieve the icons? My problem is that the icon is not affected by my icon themes at all (other tray icons works fine).

I found a few relevant issues across the net:

https://forums.linuxmint.com/viewtopic.php?t=328191 https://forums.linuxmint.com/viewtopic.php?f=47&t=328047

https://fr2.rpmfind.net/linux/RPM/opensuse/15.4/s390x/fcitx-table-4.2.9.8-bp154.1.200.s390x.html

fcitx switched to DBus mechanism to select systray icon which made it impossible to customize systray icon in fcitx's themes. When the KDE default keyboard icon was used, it was ugly-looking and invisible on small screens.

rocka commented 1 year ago

It depends on what does the engine provide for the icon (eg. an absolute path or an icon name), and what do you use for system tray.


For the keyboard addon, it just provides input-keyboard for icon name.

https://github.com/fcitx/fcitx5/blob/732b96df2efdbd86cdfd0add73ee648bbbaf626e/src/im/keyboard/keyboard.cpp#L242


If you are using Freedesktop StatusNotifierItem compatible system tray, such as KDE's default systray plasmoid or https://github.com/ubuntu/gnome-shell-extension-appindicator , it's the tray's responsibility to locate and render the icon. Fcitx5 just provide the icon name (or absolute path) to the tray via DBus; or current input method label (usually 1~2 characters) rendered as bitmap if "Prefer Text Icon" was enabled in "Classic User Interface" addon.

https://github.com/fcitx/fcitx5/blob/4182bb2b7024e84581864d25bfea270d2e247ffb/src/modules/notificationitem/notificationitem.cpp#L146-L154


If you are using old XEmbed based tray implementation (I suspect you are because of https://github.com/awesomeWM/awesome/issues/2995 ), things get a little complicated ... Fcitx5 also implemented something similar to XDG Icon Lookup in classicui addon.

https://github.com/fcitx/fcitx5/blob/4182bb2b7024e84581864d25bfea270d2e247ffb/src/lib/fcitx/icontheme.cpp#L437-L438

It read current icon theme name Net/IconThemeName from xsettings (you can confirm that with dump_xsettings command)

https://github.com/fcitx/fcitx5/blob/732b96df2efdbd86cdfd0add73ee648bbbaf626e/src/ui/classic/xcbui.cpp#L656-L661

and tries to locate the icon file based on current theme and XDG standard data dirs ($HOME/.icons, $XDG_DATA_DIRS/icons and $XDG_DATA_HOME/icons)

https://github.com/fcitx/fcitx5/blob/732b96df2efdbd86cdfd0add73ee648bbbaf626e/src/ui/classic/theme.cpp#L400

https://github.com/fcitx/fcitx5/blob/732b96df2efdbd86cdfd0add73ee648bbbaf626e/src/ui/classic/theme.cpp#L218

https://github.com/fcitx/fcitx5/blob/4182bb2b7024e84581864d25bfea270d2e247ffb/src/lib/fcitx/icontheme.cpp#L608-L620

and finally render the icon with cairo

https://github.com/fcitx/fcitx5/blob/732b96df2efdbd86cdfd0add73ee648bbbaf626e/src/ui/classic/xcbtraywindow.cpp#L371

musjj commented 1 year ago

Thanks for the detailed explanation!

Net/IconThemeName

I think this is the culprit. I don't have xsettingsd set up on my machine yet. Is there a reason why this method was chosen? Other tray apps seems to rely on the system's GTK settings instead, so they don't have this problem.

But I'll try to configure it and see if helps.

wengxt commented 1 year ago

@musjj I don’t think so, fcitx also parse gtk2 and gtk3 icon theme.

https://github.com/fcitx/fcitx5/blob/732b96df2efdbd86cdfd0add73ee648bbbaf626e/src/lib/fcitx/icontheme.cpp#L765C1-L765C1

wengxt commented 1 year ago

@musjj Is your tray xembed, or sni(dbus)?

if xembed, maybe try strace -f fcitx5 2>&1 | grep /icons/

and see what icon fcitx5 is loading.

The linux mint post seems to fcitx4 which is irrelevant.

musjj commented 1 year ago

That's interesting, it seems that when fcitx5 is run as a (user-level) systemd service, icons becomes missing. I'm not sure why it's happening though. This is what the service looks like:

[Install]
WantedBy=graphical-session.target

[Service]
ExecStart=/nix/store/bqzmvngb8zmk43w0vapj3nsbni9676wj-fcitx5-with-addons-5.0.23/bin/fcitx5

[Unit]
Description=Fcitx5 input method editor
PartOf=graphical-session.target

Any hints on what could be the cause?

musjj commented 1 year ago

It looks like that it should be able to read the icons. I ran your strace command as a user-level service and this is what was in the logs:

Service log ``` Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] newfstatat(AT_FDCWD, "/nix/store/0wq0dwqvh2bk8ra5q7j8irkimc5l6sk8-fcitx5-with-addons-5.0.23/share/icons/Papirus-Dark", 0x7ffea28cba80, 0) = -1 ENOENT (No such file or directory) Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] newfstatat(AT_FDCWD, "/nix/store/6ds58v5q1j1s4n0r6m9sb4n4iwqwrswa-fcitx5-5.0.23/share/icons/Papirus-Dark", 0x7ffea28cba80, 0) = -1 ENOENT (No such file or directory) Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] newfstatat(AT_FDCWD, "/home/$USER/.nix-profile/share/icons/Papirus-Dark/16x16/devices", {st_mode=S_IFDIR|0555, st_size=12288, ...}, 0) = 0 Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] access("/home/$USER/.nix-profile/share/icons/Papirus-Dark/16x16/devices", R_OK|X_OK) = 0 Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] newfstatat(AT_FDCWD, "/home/$USER/.nix-profile/share/icons/Papirus-Dark/16x16/devices/input-keyboard.svg", {st_mode=S_IFREG|0444, st_size=2022, ...}, 0) = 0 Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] access("/home/$USER/.nix-profile/share/icons/Papirus-Dark/16x16/devices/input-keyboard.svg", R_OK) = 0 Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] newfstatat(AT_FDCWD, "/home/$USER/.nix-profile/share/icons/Papirus-Dark/22x22/devices", {st_mode=S_IFDIR|0555, st_size=12288, ...}, 0) = 0 Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] access("/home/$USER/.nix-profile/share/icons/Papirus-Dark/22x22/devices", R_OK|X_OK) = 0 Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] newfstatat(AT_FDCWD, "/home/$USER/.nix-profile/share/icons/Papirus-Dark/22x22/devices/input-keyboard.svg", {st_mode=S_IFREG|0444, st_size=2298, ...}, 0) = 0 Aug 25 22:27:24 $HOST fcitx5-trace[401961]: [pid 401964] access("/home/$USER/.nix-profile/share/icons/Papirus-Dark/22x22/devices/input-keyboard.svg", R_OK) = 0 ```

I opened the icon paths inside an image viewer and they look correct, but they don't end up being rendered on the tray. This issue does not happen when I run fcitx5 outside of a service.

wengxt commented 1 year ago

when you say "This issue does not happen when I run fcitx5 outside of a service.", what does this mean?

Does it mean the icon works if it's not run as a systemd service?

since your icon is a svg file, do you know if your system installation works with svg file? The capability of loading svg file is through gdk-pixbuf2, but provided as a plugin by librsvg.

musjj commented 1 year ago

Thank you! That's basicaly it, the $GDK_PIXBUF_MODULE_FILE is not inherited when fcitx5 is run as a service.

Thanks for all the help!