2022-04-25 18:16:46 +00:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.programs.my-sway;
|
|
|
|
|
|
|
|
# Set up an ibus script
|
|
|
|
ibusNext = (
|
|
|
|
let
|
|
|
|
input-methods = [ "xkb:us::eng" "mozc-jp" "Bamboo" ];
|
|
|
|
next = m:
|
|
|
|
let
|
|
|
|
nextRec = l:
|
|
|
|
if (length l == 1)
|
|
|
|
then head input-methods
|
|
|
|
else if (m == head l)
|
|
|
|
then (head (tail l))
|
|
|
|
else nextRec (tail l);
|
|
|
|
in
|
|
|
|
nextRec input-methods;
|
2022-09-21 06:12:23 +00:00
|
|
|
changeTo = m: ''
|
|
|
|
${pkgs.libnotify}/bin/notify-send \
|
|
|
|
-a ibus \
|
|
|
|
-u low \
|
|
|
|
-t 3000 \
|
|
|
|
"${m}" \
|
|
|
|
"Input engine changed"
|
|
|
|
${pkgs.ibus}/bin/ibus engine ${m}
|
|
|
|
'';
|
2022-04-25 18:16:46 +00:00
|
|
|
inputCase = m: ''
|
2022-09-21 06:12:23 +00:00
|
|
|
case "${m}"
|
|
|
|
${changeTo (next m)}
|
2022-04-25 18:16:46 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
pkgs.writeScriptBin "ibus-next-engine" ''
|
|
|
|
#! ${pkgs.fish}/bin/fish
|
|
|
|
|
|
|
|
set current (${pkgs.ibus}/bin/ibus engine)
|
|
|
|
|
2022-09-21 06:12:23 +00:00
|
|
|
switch $current
|
|
|
|
${strings.concatMapStrings inputCase input-methods}
|
|
|
|
case '*'
|
|
|
|
${changeTo (head input-methods)}
|
|
|
|
end
|
2022-04-25 18:16:46 +00:00
|
|
|
''
|
|
|
|
);
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
wayland.windowManager.sway.config.keybindings = mkOptionDefault {
|
|
|
|
"${config.wayland.windowManager.sway.config.modifier}+z" = "exec ${ibusNext}/bin/ibus-next-engine";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|