IBus: Difference between revisions

imported>Symphorien
ibus with custom emoji
 
imported>Symphorien
Custom emojis: simplify
Line 26: Line 26:


==== Custom emojis ====
==== Custom emojis ====
Custom emojis can be added to the emoji selection dialog of IBus. This can be used to workaround the fact that GTK does not support compose rules which output more than one unicode codepoint. The core of the method is to set the following hidden gsettings:
Custom emojis can be added to the emoji selection dialog of IBus. This can be used to workaround the fact that GTK does not support compose rules which output more than one unicode codepoint. Here an example [[Home Manager]] module:
{{Commands|
gsettings set org.freedesktop.ibus.panel.emoji favorite-annotations "['shrug']"
gsettings set org.freedesktop.ibus.panel.emoji favorites "['¯\_(ツ)_/¯']"
}}
Then, typing <code>Ctrl+Shift+e</code> and then <code>shrug</code>, Space and Return will insert <code>¯\_(ツ)_/¯</code>.
 
But on NixOS, gsettings cannot access schemas without wrapping. In order to workaround this, and make this declarative, here is a possible [[Home Manager]] module.
{{file|~/.config/nixpkgs/home.nix|nix|<nowiki>
{{file|~/.config/nixpkgs/home.nix|nix|<nowiki>
{ pkgs, lib, config, ... }:
{ pkgs, lib, config, ... }:
Line 40: Line 33:
   fav = {
   fav = {
     shrug = ''¯\_(ツ)_/¯'';
     shrug = ''¯\_(ツ)_/¯'';
    "markdown-shrug" = ''¯\\\_(ツ)\_/¯'';
     flip = ''(╯°□°)╯︵ ┻━┻'';
     flip = ''(╯°□°)╯︵ ┻━┻'';
   };
   };
  /* end */
  listToFile = l: builtins.toFile "fav" (builtins.toJSON l);
  /* gsettings needs to be wrapped with ibus to find the schemas */
  gsettings = pkgs.stdenv.mkDerivation {
    name = "gsettings-for-ibus";
    buildInputs = [ pkgs.ibus ];
    nativeBuildInputs = [ pkgs.wrapGAppsHook ];
    dontUnpack = true;
    dontBuild = true;
    installPhase = ''
      mkdir -p $out/bin
      ln -s ${pkgs.glib.bin}/bin/gsettings $out/bin
    '';
  };
  /* this script applies our modifications */
  applyScript = pkgs.writeShellScript "apply-emoji-prefs" ''
    ${gsettings}/bin/gsettings set org.freedesktop.ibus.panel.emoji favorites "$(${pkgs.coreutils}/bin/cat ${listToFile (lib.attrValues fav)})"
    ${gsettings}/bin/gsettings set org.freedesktop.ibus.panel.emoji favorite-annotations "$(${pkgs.coreutils}/bin/cat ${listToFile (lib.attrNames fav)})"
  '';
in
in
{
{
   systemd.user.services.ibus-favorite = {
   dconf.settings."desktop/ibus/panel/emoji" = with lib.hm.gvariant; {
    Unit = {
     favorite-annotations = mkArray type.string (lib.attrNames fav);
      Description = "Set ibus favorite emoji";
     favorites = mkArray type.string (lib.attrValues fav);
     };
    Install = {
      WantedBy = [ "graphical-session.target" ];
     };
    Service = {
      ExecStart = "${applyScript}";
      Type = "oneshot";
      RemainAfterExit = true;
    };
   };
   };
}
}
</nowiki>}}


</nowiki>}}
 
Then, typing <code>Ctrl+Shift+e</code> and then <code>shrug</code>, Space and Return will insert <code>¯\_(ツ)_/¯</code>.