Repository navigation
Seed fcitx5 DefaultIM from vconsole XKBLAYOUT #12920
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
Closed
chessing234
wants to merge
5
commits into
omacom:quattro
from
chessing234:fix/fcitx5-seed-vconsole-layout
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a66e354
Seed fcitx5 DefaultIM from vconsole XKBLAYOUT.
chessing234 f28b265
Stop fcitx5 before rewriting the profile.
chessing234 f58750f
abort seed if fcitx5 is still running after stop
chessing234 cc07f76
fix: scope fcitx5 migration to the user and restore its service
chessing234 033894f
Preserve custom input profiles and stopped service state
chessing234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Seed fcitx5 DefaultIM from /etc/vconsole.conf XKBLAYOUT. | ||
| # omarchy:group=config | ||
| # omarchy:hidden=true | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Hyprland already reads XKBLAYOUT from vconsole for kb_layout. fcitx5 ships its | ||
| # own default profile with keyboard-us, and Qt lock-screen fields take that IM's | ||
| # keymap even when the compositor layout is correct (#8060). | ||
|
|
||
| vconsole_file=${OMARCHY_VCONSOLE:-/etc/vconsole.conf} | ||
| profile=${OMARCHY_FCITX5_PROFILE:-$HOME/.config/fcitx5/profile} | ||
|
|
||
| vconsole_value() { | ||
| local key="$1" | ||
|
|
||
| [[ -f $vconsole_file ]] || return 0 | ||
|
|
||
| awk -v key="$key" ' | ||
| { | ||
| line = $0 | ||
| sub(/#.*/, "", line) | ||
| sub(/^[[:space:]]+/, "", line) | ||
| sub(/[[:space:]]+$/, "", line) | ||
| if (line == "") next | ||
| eq = index(line, "=") | ||
| if (eq == 0) next | ||
| name = substr(line, 1, eq - 1) | ||
| sub(/[[:space:]]+$/, "", name) | ||
| if (name != key) next | ||
| value = substr(line, eq + 1) | ||
| sub(/^[[:space:]]+/, "", value) | ||
| sub(/[[:space:]]+$/, "", value) | ||
| gsub(/^"/, "", value) | ||
| gsub(/"$/, "", value) | ||
| gsub(/^'\''/, "", value) | ||
| gsub(/'\''$/, "", value) | ||
| print value | ||
| exit | ||
| } | ||
| ' "$vconsole_file" | ||
| } | ||
|
|
||
| # First entry only — same slice Hyprland / mkinitcpio use for the console layout. | ||
| layout=$(vconsole_value XKBLAYOUT) | ||
| variant=$(vconsole_value XKBVARIANT) | ||
| layout=${layout%%,*} | ||
| variant=${variant%%,*} | ||
| layout=${layout:-us} | ||
|
|
||
| if [[ -n $variant ]]; then | ||
| default_layout="$layout-$variant" | ||
| im="keyboard-$layout-$variant" | ||
| else | ||
| default_layout="$layout" | ||
| im="keyboard-$layout" | ||
| fi | ||
|
|
||
| write_profile() { | ||
| mkdir -p "$(dirname "$profile")" | ||
| cat >"$profile" <<EOF | ||
| [Groups/0] | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| Name=Default | ||
| Default Layout=$default_layout | ||
| DefaultIM=$im | ||
|
|
||
| [Groups/0/Items/0] | ||
| Name=$im | ||
| Layout= | ||
|
|
||
| [GroupOrder] | ||
| 0=Default | ||
| EOF | ||
| } | ||
|
|
||
| profile_default_im() { | ||
| [[ -f $profile ]] || return 0 | ||
|
|
||
| awk ' | ||
| { | ||
| line = $0 | ||
| sub(/#.*/, "", line) | ||
| sub(/^[[:space:]]+/, "", line) | ||
| sub(/[[:space:]]+$/, "", line) | ||
| if (line ~ /^\[/) section = line | ||
| if (section == "[Groups/0]" && line ~ /^DefaultIM=/) { | ||
| print substr(line, 11) | ||
| exit | ||
| } | ||
| } | ||
| ' "$profile" | ||
| } | ||
|
|
||
| # Stock first-run profile from fcitx5: one group, one keyboard-us item. | ||
| is_stock_keyboard_us_profile() { | ||
| [[ -f $profile ]] || return 1 | ||
|
|
||
| awk ' | ||
| { | ||
| line = $0 | ||
| sub(/#.*/, "", line) | ||
| sub(/^[[:space:]]+/, "", line) | ||
| sub(/[[:space:]]+$/, "", line) | ||
| if (line == "") next | ||
| if (line ~ /^\[/) { | ||
| section = line | ||
| if (section ~ /^\[Groups\/[1-9]/) multi = 1 | ||
| next | ||
| } | ||
| if (section == "[Groups/0]") { | ||
| if (line ~ /^DefaultIM=/) im = substr(line, 11) | ||
| if (line ~ /^Default Layout=/) layout = substr(line, 16) | ||
| } | ||
| if (section ~ /^\[Groups\/0\/Items\// && line ~ /^Name=/) { | ||
| items[++n] = substr(line, 6) | ||
| } | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| END { | ||
| if (multi) exit 1 | ||
| if (im != "keyboard-us") exit 1 | ||
| if (layout != "" && layout != "us") exit 1 | ||
| if (n != 1 || items[1] != "keyboard-us") exit 1 | ||
| exit 0 | ||
| } | ||
| ' "$profile" | ||
| } | ||
|
|
||
| # US console layout: leave missing profiles for fcitx5, and leave stock alone. | ||
| if [[ $im == "keyboard-us" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [[ -f $profile ]]; then | ||
| [[ $(profile_default_im) == "$im" ]] && exit 0 | ||
| is_stock_keyboard_us_profile || exit 0 | ||
| fi | ||
|
|
||
| # A live fcitx5 flushes its in-memory profile on shutdown and would overwrite | ||
| # the seed we are about to write. Stop it first, and restore the session | ||
| # service on every exit, including a failed stop or profile write. | ||
| restore_fcitx5() { | ||
| if systemctl --user is-active --quiet graphical-session.target; then | ||
| systemctl --user start omarchy-fcitx5.service >/dev/null 2>&1 || true | ||
| fi | ||
| } | ||
| trap restore_fcitx5 EXIT | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| if systemctl --user is-active --quiet omarchy-fcitx5.service 2>/dev/null || | ||
| pgrep -u "$UID" -x fcitx5 >/dev/null 2>&1; then | ||
| systemctl --user stop omarchy-fcitx5.service 2>/dev/null || true | ||
| pkill -u "$UID" -x fcitx5 >/dev/null 2>&1 || true | ||
| # Wait for the process to finish saving so our write is the last one. | ||
| for _ in 1 2 3 4 5 6 7 8 9 10; do | ||
| pgrep -u "$UID" -x fcitx5 >/dev/null 2>&1 || break | ||
| sleep 0.1 | ||
| done | ||
| if pgrep -u "$UID" -x fcitx5 >/dev/null 2>&1; then | ||
| echo "fcitx5 still running after stop; not rewriting profile" >&2 | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| write_profile | ||
| printf 'changed\n' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Align fcitx5 DefaultIM with the console layout Hyprland already reads. | ||
| # Fresh installs otherwise keep fcitx5's stock keyboard-us profile (#8060). | ||
| omarchy-fcitx5-seed-layout >/dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| echo "Seed fcitx5 DefaultIM from the console keyboard layout" | ||
|
|
||
| # fcitx5 defaults to keyboard-us. On a non-US install that IM wins for Qt | ||
| # fields (lock screen password) even when Hyprland's kb_layout from | ||
| # /etc/vconsole.conf is correct. Rewrite only the stock single-IM us profile; | ||
| # multi-IM setups are left alone. Fresh installs get the same seed from | ||
| # install/user/fcitx5-layout.sh. | ||
|
|
||
| # The helper stops this user's daemon before writing and restores it on exit | ||
| # when a graphical session is active, including on failure. | ||
| omarchy-fcitx5-seed-layout >/dev/null |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.