Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
31 changes: 31 additions & 0 deletions bin/omarchy-font-cjk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# omarchy:summary=Show or set the glyph forms for Chinese, Japanese, and Korean text
# omarchy:args=[jp|kr|sc|tc|hk|default]
# omarchy:examples=omarchy font cjk | omarchy font cjk jp | omarchy font cjk default

set -euo pipefail

# Also seeded by the first CJK input method or language chosen. Tagged text and
# a CJK session language keep their own forms regardless.
preference=${XDG_CONFIG_HOME:-$HOME/.config}/fontconfig/conf.d/50-omarchy-input-method.conf

case "${1:-}" in
"")
variant=""
if [[ -f $preference ]]; then
variant=$(sed -n 's|.*<family>Noto Sans CJK \([A-Z]*\)</family>.*|\1|p' "$preference" | head -n 1)
fi
variant=${variant,,}
echo "${variant:-default}"
;;
jp | kr | sc | tc | hk | default)
/usr/bin/python3 "$OMARCHY_PATH/default/input-methods/configure.py" font "$1"
omarchy-restart-shell
omarchy-notification-send -g  "$(omarchy-i18n font.cjkChanged)" "$(omarchy-i18n font.restartAppsToSeeChange)"
;;
*)
echo "Usage: omarchy-font-cjk [jp|kr|sc|tc|hk|default]" >&2
exit 1
;;
esac
15 changes: 15 additions & 0 deletions bin/omarchy-language
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ apply_session_locale() {
dbus-update-activation-environment --systemd "LANG=$locale" >/dev/null 2>&1 || true
}

# A Chinese, Japanese or Korean language brings its input method and glyph
# forms, unless the user already has an input method or chose the forms.
seed_typing() {
local method
case $1 in
ja) method=mozc ;;
ko) method=hangul ;;
zh-CN) method=pinyin ;;
zh-TW) method=chewing ;;
*) return 0 ;;
esac
/usr/bin/python3 "$OMARCHY_PATH/default/input-methods/typing_setup.py" seed-language "$method" || true
}

set_language() {
local code=$1
if ! known_language "$code"; then
Expand All @@ -131,6 +145,7 @@ set_language() {
# password prompt cannot leave the interface switched with LANG behind it.
mkdir -p "$(dirname "$language_file")"
echo "$code" >"$language_file"
seed_typing "$code"

omarchy-notification-send -g  "$(omarchy-i18n language.changed "$name")" "$(omarchy-i18n language.newApps)"
}
Expand Down
30 changes: 26 additions & 4 deletions bin/omarchy-menu-keybindings
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,26 @@ declare -A LUA_BIND_ARG_MAP
# fixed platform root, which no environment variable moves.
key_names_file=/usr/share/omarchy-platform/key-names

# The leading layout and variant, which Hyprland resolves bindings against.
# Only names XKB could know pass, since they end up on a command line.
leading_keyboard() {
local option value
for option in kb_layout kb_variant; do
value=$(hyprctl -j getoption "input:$option" 2>/dev/null | jq -r '.str // empty' 2>/dev/null)
value=${value%%,*}
[[ $value =~ ^[A-Za-z0-9_-]*$ ]] || value=""
printf '%s\n' "$value"
done
}

# Hyprland reports XKB keycodes for code: bindings. Resolve them to symbols
# via the compiled keymap, with a small fallback for common keys so the menu
# remains readable if xkbcli cannot resolve a symbol.
parse_keycodes() {
awk -v key_names="$key_names_file" '
local layout variant
{ read -r layout; read -r variant; } < <(leading_keyboard)

awk -v key_names="$key_names_file" -v layout="$layout" -v variant="$variant" '
BEGIN {
while ((getline line < key_names) > 0) {
# Blanks around a line and a CRLF line end read the same, as in
Expand All @@ -34,8 +49,13 @@ parse_keycodes() {
keycode_symbol[substr(fallbacks[i], 1, separator - 1)] = substr(fallbacks[i], separator + 1)
}

# </dev/null keeps xkbcli from consuming the binding records on stdin
keymap_cmd = "xkbcli compile-keymap </dev/null"
# Name each key by what the leading layout prints on it: on JIS the key
# right of 0 is ^, not =. </dev/null keeps xkbcli from consuming the
# binding records on stdin.
keymap_cmd = "xkbcli compile-keymap"
if (layout != "") keymap_cmd = keymap_cmd " --layout " layout
if (layout != "" && variant != "") keymap_cmd = keymap_cmd " --variant " variant
keymap_cmd = keymap_cmd " </dev/null"
section = ""
while ((keymap_cmd | getline line) > 0) {
if (line ~ /xkb_keycodes/) { section = "codes"; continue }
Expand All @@ -55,6 +75,7 @@ parse_keycodes() {
# as the symbol printed on it whichever key the active layout puts it on.
for (code in keycode_symbol) {
if (keycode_symbol[code] == "GRAVE") keycode_symbol[code] = "~"
if (keycode_symbol[code] == "ASCIICIRCUM") keycode_symbol[code] = "^"
}

mouse_symbol["272"] = "LEFT MOUSE BUTTON"
Expand Down Expand Up @@ -588,7 +609,8 @@ output_binding_records_uncached() {

keybindings_cache_key() {
{
printf 'v16\n'
printf 'v17\n'
leading_keyboard
omarchy-language 2>/dev/null
cat "$OMARCHY_PATH/default/i18n/$(omarchy-language 2>/dev/null)/keybindings.json" 2>/dev/null
hyprctl devices 2>/dev/null | grep -F 'active keymap:'
Expand Down
6 changes: 3 additions & 3 deletions bin/omarchy-setup-input
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

# omarchy:summary=Select input methods for Japanese, Korean, or Chinese typing
# omarchy:args=[mozc|hangul|pinyin|chewing]
# omarchy:args=[mozc|hangul|pinyin|chewing|cangjie5]
# omarchy:examples=omarchy setup input | omarchy setup input mozc
# omarchy:requires-sudo=true

set -euo pipefail

if (( $# > 1 )); then
echo "Usage: omarchy setup input [mozc|hangul|pinyin|chewing]" >&2
echo "Usage: omarchy setup input [mozc|hangul|pinyin|chewing|cangjie5]" >&2
exit 1
fi

Expand All @@ -19,7 +19,7 @@ if [[ -z $method ]]; then
fi

case "$method" in
mozc | hangul | pinyin | chewing) ;;
mozc | hangul | pinyin | chewing | cangjie5) ;;
*) echo "Unknown input method: $method" >&2; exit 1 ;;
esac

Expand Down
1 change: 1 addition & 0 deletions bin/omarchy-theme-set
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ other_theme_commands=(
omarchy-theme-set-vscode
omarchy-theme-set-obsidian
omarchy-theme-set-keyboard
omarchy-theme-set-fcitx5
)

theme_still_current() {
Expand Down
88 changes: 88 additions & 0 deletions bin/omarchy-theme-set-fcitx5
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

# omarchy:summary=Sync the generated Omarchy theme to the Fcitx candidate window
# omarchy:args=[--activate]
# omarchy:hidden=true

set -euo pipefail

THEME_SOURCE="$HOME/.local/state/omarchy/current/theme/fcitx5-theme.conf"
THEME_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/fcitx5/themes/omarchy"
CLASSICUI_CONF="${XDG_CONFIG_HOME:-$HOME/.config}/fcitx5/conf/classicui.conf"
PACKAGED_THEME="${OMARCHY_FCITX5_PACKAGED_THEME:-/usr/share/fcitx5/themes/default}"
ACTIVATE=0

usage() {
echo "Usage: omarchy-theme-set-fcitx5 [--activate]"
}

for arg in "$@"; do
case "$arg" in
--activate)
ACTIVATE=1
;;
-h | --help)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
done

# Point classicui at the theme, unless the user picked one of their own. A
# configtool save writes Theme=default even when only the font changed, so the
# stock themes count as unpicked. Only activation does this, so a later choice
# of fcitx5's own theme sticks.
select_theme() {
local conf original updated key value

conf=$(realpath -m "$CLASSICUI_CONF")
original=$([[ -f $conf ]] && cat "$conf" || true)
updated=$original

for key in Theme DarkTheme; do
value=$(sed -n "s/^$key=//p" <<<"$updated" | tail -n 1)
if [[ -z $value ]]; then
updated+="${updated:+$'\n'}$key=omarchy"
elif [[ $value == "default" || $value == "default-dark" ]]; then
updated=$(sed "s/^$key=.*/$key=omarchy/" <<<"$updated")
fi
done

if [[ $updated != "$original" ]]; then
# Write through a dotfiles symlink rather than replacing it.
mkdir -p "${conf%/*}"
printf '%s\n' "$updated" >"$conf.omarchy-tmp"
mv "$conf.omarchy-tmp" "$conf"
fi
}

# Until activation there is no theme directory, and nothing to keep in step.
if (( ACTIVATE == 0 )) && [[ ! -d $THEME_DIR ]]; then
exit 0
fi

mkdir -p "$THEME_DIR"
if [[ -f $THEME_SOURCE ]]; then
tmp=$(mktemp "$THEME_DIR/theme.conf.XXXXXX")
cp "$THEME_SOURCE" "$tmp"
mv "$tmp" "$THEME_DIR/theme.conf"
fi

# Image= entries resolve inside the theme's own directory. fcitx5's page and
# menu glyphs are neutral grey, so the packaged ones suit every palette.
for glyph in "$PACKAGED_THEME"/*.svg; do
[[ -e $glyph ]] && ln -sfn "$glyph" "$THEME_DIR/${glyph##*/}"
done

if (( ACTIVATE == 1 )); then
select_theme
fi

# classicui reads its theme only when its config loads. Never start Fcitx just
# to tell it.
busctl --user --auto-start=no call org.fcitx.Fcitx5 /controller org.fcitx.Fcitx.Controller1 \
ReloadAddonConfig s classicui >/dev/null 2>&1 || true
44 changes: 44 additions & 0 deletions default/fontconfig/conf.avail/50-omarchy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,50 @@
</edit>
</match>

<!-- Han with no language, input method or chosen forms takes Japanese forms in every app, rather than
Korean in some and Japanese in others. Accepted here so a user's chosen forms, loaded later, insert ahead. -->
<alias>
<family>sans-serif</family>
<accept>
<family>Noto Sans CJK JP</family>
</accept>
</alias>

<alias>
<family>Liberation Sans</family>
<accept>
<family>Noto Sans CJK JP</family>
</accept>
</alias>

<alias>
<family>serif</family>
<accept>
<family>Noto Serif CJK JP</family>
</accept>
</alias>

<alias>
<family>Liberation Serif</family>
<accept>
<family>Noto Serif CJK JP</family>
</accept>
</alias>

<alias>
<family>monospace</family>
<accept>
<family>Noto Sans Mono CJK JP</family>
</accept>
</alias>

<alias>
<family>JetBrainsMono Nerd Font</family>
<accept>
<family>Noto Sans Mono CJK JP</family>
</accept>
</alias>

<alias>
<family>system-ui</family>
<prefer>
Expand Down
7 changes: 4 additions & 3 deletions default/hypr/keyboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ function keyboard.vconsole()
end

-- Choices whose console keymap is plain US but whose desktop layout is not:
-- Korean keeps US letters, and Lao is non-Latin, so US still leads.
local desktop_overrides = { kr = true, la = true }
-- Korean keeps US letters, and Lao is non-Latin, so US still leads. kr104 is
-- for keyboards whose 한/영 and 한자 keys send Right Alt and Right Ctrl.
local desktop_overrides = { kr = true, ["kr:kr104"] = true, la = true }

function keyboard.installed()
local values = keyboard.vconsole()
local override = read_values("/etc/omarchy/input-method").XKB_LAYOUT
if desktop_overrides[override]
and (values.XKBLAYOUT or "us") == "us"
and (values.XKBVARIANT or "") == "" then
values.XKBLAYOUT, values.XKBVARIANT = override, ""
values.XKBLAYOUT, values.XKBVARIANT = override:match("^([^:]*):?(.*)$")
end
return values
end
Expand Down
2 changes: 2 additions & 0 deletions default/i18n/en/cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
"drive.passwordThatOpens": "Encryption password that opens %1 now (the new one if the change went through)",
"drive.select": "Select drive",
"files.selectFile": "Select file",
"font.cjkChanged": "Chinese, Japanese, and Korean glyph forms changed",
"font.restartAppsToSeeChange": "Restart open apps to see the change",
"font.restartToSeeChange": "You must restart %1 to see font change",
"games.corePrompt": "RetroArch core",
"games.installed": "%1 installed",
Expand Down
22 changes: 22 additions & 0 deletions default/i18n/en/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,28 @@
"style.font": {
"label": "Font"
},
"style.font.cjk": {
"label": "Chinese, Japanese, Korean",
"title": "Chinese, Japanese, and Korean Glyphs"
},
"style.font.cjk.auto": {
"label": "Automatic"
},
"style.font.cjk.jp": {
"label": "Japanese"
},
"style.font.cjk.kr": {
"label": "Korean"
},
"style.font.cjk.sc": {
"label": "Simplified Chinese"
},
"style.font.cjk.tc": {
"label": "Taiwan"
},
"style.font.cjk.hk": {
"label": "Hong Kong"
},
"style.hyprland": {
"label": "Hyprland"
},
Expand Down
Loading
Loading