Set up an ibus switch

This commit is contained in:
Natsu Kagami 2022-04-25 14:16:46 -04:00
parent 841c5180ba
commit 7dc4a387ef
Signed by: nki
GPG key ID: 7306B3D3C3AD6E51
3 changed files with 52 additions and 1 deletions

View file

@ -7,7 +7,7 @@ with lib;
package = pkgs.unstable.alacritty;
settings = {
window.opacity = 0.95;
window.opacity = 0.8;
font = {
size = 14.0;
normal.family = "Fantasque Sans Mono Nerd Font";

View file

@ -31,6 +31,8 @@ let
in
{
imports = [ ./ibus.nix ];
options.programs.my-sway = {
enable = mkEnableOption "Enable the sway configuration";
fontSize = mkOption {

View file

@ -0,0 +1,49 @@
{ 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;
inputCase = m: ''
if test $current = "${m}"
${pkgs.libnotify}/bin/notify-send \
-a ibus \
-u low \
-t 3000 \
"${next m}" \
"Input engine changed"
${pkgs.ibus}/bin/ibus engine ${next m}
end
'';
in
pkgs.writeScriptBin "ibus-next-engine" ''
#! ${pkgs.fish}/bin/fish
set current (${pkgs.ibus}/bin/ibus engine)
${strings.concatMapStrings inputCase input-methods}
''
);
in
{
config = mkIf cfg.enable {
wayland.windowManager.sway.config.keybindings = mkOptionDefault {
"${config.wayland.windowManager.sway.config.modifier}+z" = "exec ${ibusNext}/bin/ibus-next-engine";
};
};
}