Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions bin/omarchy-fcitx5-seed-layout
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%%,*}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
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]
Comment thread
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)
}
Comment thread
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
Comment thread
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'
2 changes: 1 addition & 1 deletion docs/file-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ It only does the things `/etc/skel` can't:
- `xdg-settings set default-web-browser chromium.desktop` and
`xdg-mime default HEY.desktop x-scheme-handler/mailto` (XDG-aware paths).
- `omarchy-refresh-applications` (composes generated `.desktop` launchers).
- Sources `install/user/all.sh` — theme, chromium, git, xcompose, mise,
- Sources `install/user/all.sh` — theme, chromium, git, xcompose, fcitx5 layout seeding, mise,
keyring, per-user hardware quirks (asus mic/mixer, framework f13 audio, …).
- On `--first-install`, marks every shipped user migration as already applied
for the freshly-created user.
Expand Down
1 change: 1 addition & 0 deletions install/user/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ run_logged "$OMARCHY_INSTALL/user/theme.sh"
run_logged "$OMARCHY_INSTALL/user/chromium.sh"
run_logged "$OMARCHY_INSTALL/user/git.sh"
run_logged "$OMARCHY_INSTALL/user/xcompose.sh"
run_logged "$OMARCHY_INSTALL/user/fcitx5-layout.sh"
run_logged "$OMARCHY_INSTALL/user/mise-work.sh"

run_logged "$OMARCHY_INSTALL/user/hardware/asus/fix-audio-mixer.sh"
Expand Down
3 changes: 3 additions & 0 deletions install/user/fcitx5-layout.sh
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
11 changes: 11 additions & 0 deletions migrations/1790096150.sh
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
Loading