diff --git a/flake.nix b/flake.nix index 5d2010b..692c6b0 100644 --- a/flake.nix +++ b/flake.nix @@ -117,6 +117,7 @@ git.enable = true; nvim.enable = true; direnv.enable = true; + fcitx5.enable = true; }; }; }; diff --git a/modules/home/default.nix b/modules/home/default.nix index d1afad3..8666c77 100644 --- a/modules/home/default.nix +++ b/modules/home/default.nix @@ -8,6 +8,7 @@ ./git ./nvim ./direnv + ./fcitx5 ]; home.stateVersion = "22.11"; diff --git a/modules/home/eww/bar/battery/eww.yuck b/modules/home/eww/bar/battery/eww.yuck index cfe4a4e..43dccfb 100644 --- a/modules/home/eww/bar/battery/eww.yuck +++ b/modules/home/eww/bar/battery/eww.yuck @@ -2,7 +2,7 @@ (defpoll percent :interval "1s" "./bar/battery/get-battery.sh percent") (defwidget battery [] - (box :class "battery module floating" + (box :class "battery module floating ${percent < 18 ? "red" : ""}" :spacing 6 (label :valign "center" :class "icon" :text "${icon}") (label :valign "center" :class "percent" :text "${percent}%")) diff --git a/modules/home/eww/bar/eww.yuck b/modules/home/eww/bar/eww.yuck index 2a1ddc2..9b29d84 100644 --- a/modules/home/eww/bar/eww.yuck +++ b/modules/home/eww/bar/eww.yuck @@ -3,6 +3,7 @@ (include "./bar/window/eww.yuck") (include "./bar/notification/eww.yuck") (include "./bar/battery/eww.yuck") +(include "./bar/language/eww.yuck") (include "./bar/clock.yuck") (defwidget left [] @@ -19,6 +20,7 @@ :halign "end" (notification) (battery) + (language) (date) (clock) )) diff --git a/modules/home/eww/bar/language/eww.yuck b/modules/home/eww/bar/language/eww.yuck new file mode 100644 index 0000000..95b6c30 --- /dev/null +++ b/modules/home/eww/bar/language/eww.yuck @@ -0,0 +1,8 @@ +(defpoll lang :interval "1s" "./bar/language/language.sh") + +(defwidget language [] + (box :class "module floating" + :spacing 6 + (label :valign "center" :class "icon" :text "") + (label :valign "center" :class "percent" :text "${lang}"))) + diff --git a/modules/home/eww/bar/language/language.sh b/modules/home/eww/bar/language/language.sh new file mode 100755 index 0000000..0448740 --- /dev/null +++ b/modules/home/eww/bar/language/language.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +IMLIST_FILE="/tmp/fcitx5-imlist" + +# Print out identifier of current input method +current() { + dbus-send --session --print-reply \ + --dest=org.fcitx.Fcitx5 \ + /controller \ + org.fcitx.Fcitx.Controller1.CurrentInputMethod \ + | grep -Po '(?<=")[^"]+' +} + +# List all input methods added to Fcitx +imlist() { + if [ ! -f "${IMLIST_FILE}" ]; then + dbus-send --session --print-reply --dest=org.fcitx.Fcitx5 /controller org.fcitx.Fcitx.Controller1.AvailableInputMethods \ + | awk 'BEGIN{i=0}{ + if($0~/struct {/) i=0; + else if(i<6){gsub(/"/,"",$2); printf("%s,",$2); i++} + else if(i==6){printf("%s\n",$2); i++} + }' > ${IMLIST_FILE} + # Output like this: + # pinyin, 拼音, 拼音, fcitx-pinyin, 拼, zh_CN, true + # rime, 中州韻, , fcitx-rime, ㄓ, zh, true + # ...... + fi + cat ${IMLIST_FILE} +} + +# This script wait for events from `watch` and +# update the text by printing a new line. +# +# Strip `Keyboard - ` part from IM name then print +print_pretty_name() { + name=$(imlist | grep "^$(current)," | cut -d',' -f5) + if [[ -z "$name" ]]; then + return + fi + echo "${name}" +} + +react() { + print_pretty_name + + # Track input method changes. Each new line read is an event fired from IM switch + while true; do + # When read someting from dbus-monitor + read -r unused + print_pretty_name + done +} + +# Watch for events from Fcitx. +# Need --line-buffered to avoid messages being hold in buffer +# dbus-monitor --session destination=org.freedesktop.IBus | grep --line-buffered '65505\|65509' | react + +# Dbus watching does not seems to work so /shrug +print_pretty_name diff --git a/modules/home/eww/eww.scss b/modules/home/eww/eww.scss index 7600e66..0db9438 100644 --- a/modules/home/eww/eww.scss +++ b/modules/home/eww/eww.scss @@ -1,4 +1,6 @@ @import 'colors'; +@import "bar/eww"; +@import "panel/scss/_init.scss"; * { all: unset; @@ -23,7 +25,8 @@ } .red { - background-color: $base0E; + background-color: $base08; + color: $base02; } .red-txt { color: $base0E; @@ -44,5 +47,3 @@ } -@import "bar/eww"; -@import "panel/scss/_init.scss"; diff --git a/modules/home/fcitx5/default.nix b/modules/home/fcitx5/default.nix new file mode 100644 index 0000000..ef4062f --- /dev/null +++ b/modules/home/fcitx5/default.nix @@ -0,0 +1,49 @@ +{ + lib, + config, + pkgs, + ... +}: +with lib; let + cfg = config.modules.fcitx5; +in { + options.modules.fcitx5 = {enable = mkEnableOption "fcitx5";}; + + config = mkIf cfg.enable { + i18n = { + inputMethod = { + enabled = "fcitx5"; + fcitx5.addons = with pkgs; [ + fcitx5-mozc + ]; + }; + }; + + xdg.configFile."fcitx5/config".text = '' + [Hotkey/TriggerKeys] + 0=Super+N + + [Behavior] + ShowInputMethodInformation=False + CompactInputMethodInformation=False + ShowFirstInputMethodInformation=False + ''; + xdg.configFile."fcitx5/profile".text = '' + [Groups/0] + Name=Default + Default Layout=us + DefaultIM=mozc + + [Groups/0/Items/0] + Name=keyboard-us + Layout= + + [Groups/0/Items/1] + Name=mozc + Layout= + + [GroupOrder] + 0=Default + ''; + }; +} diff --git a/modules/home/hyprland/hyprland.conf b/modules/home/hyprland/hyprland.conf index 375e4ee..4b43db5 100644 --- a/modules/home/hyprland/hyprland.conf +++ b/modules/home/hyprland/hyprland.conf @@ -2,7 +2,7 @@ exec-once=xprop -root -f _XWAYLAND_GLOBAL_OUTPUT_SCALE 32c -set _XWAYLAND_GLOBAL exec-once=discord exec-once=eww open bar exec-once=fusuma -c /home/zoriya/.config/fusuma/config.yaml -exec-once=swayidle -w timeout 600 lock before-sleep lock +exec-once=swayidle -w timeout 1200 lock before-sleep lock exec-once=/home/zoriya/.config/hypr/wallpaper.sh init exec-once=kitty --class=scratchpad diff --git a/modules/home/hyprland/start.sh b/modules/home/hyprland/start.sh index e3c48bd..49e5a14 100755 --- a/modules/home/hyprland/start.sh +++ b/modules/home/hyprland/start.sh @@ -1,10 +1,13 @@ export GDK_SCALE=2 export XCURSOR_SIZE=24 -export GTK_IM_MODULE=ibus -export QT_IM_MODULE=ibus -export XMODIFIERS=@im=ibus -export SDL_IM_MODULE=ibus +export INPUT_METHOD=fcitx +export QT_IM_MODULE=fcitx +export GTK_IM_MODULE=fcitx +export XMODIFIERS=@im=fcitx +export XIM_SERVERS=fcitx export GLFW_IM_MODULE=ibus +fcitx5 -d + exec Hyprland diff --git a/modules/home/zsh/custom.zsh b/modules/home/zsh/custom.zsh index 04bf170..9e389fa 100644 --- a/modules/home/zsh/custom.zsh +++ b/modules/home/zsh/custom.zsh @@ -16,3 +16,7 @@ nixify() fi direnv allow } + +(whence -w run-help | grep -q alias) && unalias run-help +autoload run-help + diff --git a/modules/home/zsh/default.nix b/modules/home/zsh/default.nix index 15b0500..0fa94e2 100644 --- a/modules/home/zsh/default.nix +++ b/modules/home/zsh/default.nix @@ -56,8 +56,9 @@ in { s = "git status"; op = "xdg-open"; wp = "~/.config/hypr/wallpaper.sh"; - py = "nix-shell -p python3"; + py = "nix-shell -p python3 --command python3"; jctl = "sudo journalctl -n 1000 -fu"; + where = "where -s"; # Follow symlinks }; plugins = [ diff --git a/modules/nixos/fonts/default.nix b/modules/nixos/fonts/default.nix index 5f8dbd7..d610b93 100644 --- a/modules/nixos/fonts/default.nix +++ b/modules/nixos/fonts/default.nix @@ -40,12 +40,6 @@ in { }; }; }; - i18n = { - defaultLocale = "en_US.UTF-8"; - inputMethod = { - enabled = "ibus"; - ibus.engines = with pkgs.ibus-engines; [ mozc ]; - }; - }; + i18n.defaultLocale = "en_US.UTF-8"; }; }