bonsaid: configure via nix
This commit is contained in:
parent
04d3ea97f3
commit
644983d27a
|
@ -1,6 +1,122 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.sane.gui.sxmo.bonsaid;
|
||||
|
||||
delayType = with lib; types.submodule {
|
||||
options = {
|
||||
type = mkOption {
|
||||
type = types.enum [ "delay" ];
|
||||
# default = "delay";
|
||||
};
|
||||
delay_duration = mkOption {
|
||||
type = types.int;
|
||||
description = ''
|
||||
used for "delay" types only.
|
||||
nanoseconds until the event is finalized.
|
||||
'';
|
||||
};
|
||||
transitions = mkOption {
|
||||
type = types.listOf transitionType;
|
||||
default = null;
|
||||
description = ''
|
||||
list of transitions out of this state.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
eventType = with lib; types.submodule {
|
||||
options = {
|
||||
type = mkOption {
|
||||
type = types.enum [ "event" ];
|
||||
# default = "event";
|
||||
};
|
||||
event_name = mkOption {
|
||||
type = types.str;
|
||||
description = ''
|
||||
name of event which this transition applies to.
|
||||
'';
|
||||
};
|
||||
transitions = mkOption {
|
||||
type = types.listOf transitionType;
|
||||
description = ''
|
||||
list of transitions out of this state.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
execType = with lib; types.submodule {
|
||||
options = {
|
||||
type = mkOption {
|
||||
type = types.enum [ "exec" ];
|
||||
# default = "exec";
|
||||
};
|
||||
command = mkOption {
|
||||
type = types.listOf types.str;
|
||||
description = ''
|
||||
command to run when the event is triggered.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
isDelay = x: delayType.check x && x.type == "delay";
|
||||
isEvent = x: eventType.check x && x.type == "event";
|
||||
isExec = x: execType.check x && x.type == "exec";
|
||||
# unfortunately, `types.oneOf` is naive about submodules, so we need our own type.
|
||||
# transitionType = lib.types.oneOf [ delayType eventType execType ];
|
||||
transitionType = with lib.types; mkOptionType {
|
||||
name = "transition";
|
||||
check = x: isDelay x || isEvent x || isExec x;
|
||||
merge = loc: defs: let
|
||||
defList = builtins.map (d: d.value) defs;
|
||||
in
|
||||
if builtins.all isDelay defList then
|
||||
delayType.merge loc defs
|
||||
else if builtins.all isEvent defList then
|
||||
eventType.merge loc defs
|
||||
else if builtins.all isExec defList then
|
||||
execType.merge loc defs
|
||||
else
|
||||
mergeOneOption loc defs
|
||||
;
|
||||
};
|
||||
|
||||
# transitionType = with lib; types.submodule {
|
||||
# options = {
|
||||
# type = mkOption {
|
||||
# type = types.enum [ "delay" "event" "exec" ];
|
||||
# };
|
||||
# delay_duration = mkOption {
|
||||
# type = types.nullOr types.int;
|
||||
# default = null;
|
||||
# description = ''
|
||||
# used for "delay" types only.
|
||||
# nanoseconds until the event is finalized.
|
||||
# '';
|
||||
# };
|
||||
# event_name = mkOption {
|
||||
# type = types.nullOr types.str;
|
||||
# default = null;
|
||||
# description = ''
|
||||
# name of event which this transition applies to.
|
||||
# '';
|
||||
# };
|
||||
# transitions = mkOption {
|
||||
# type = types.nullOr (types.listOf transitionType);
|
||||
# default = null;
|
||||
# description = ''
|
||||
# list of transitions out of this state.
|
||||
# '';
|
||||
# };
|
||||
# command = mkOption {
|
||||
# type = types.nullOr (types.listOf types.str);
|
||||
# default = null;
|
||||
# description = ''
|
||||
# used for "exec" types only.
|
||||
# command to run when the event is triggered.
|
||||
# '';
|
||||
# };
|
||||
# };
|
||||
# };
|
||||
in
|
||||
{
|
||||
options = with lib; {
|
||||
|
@ -8,13 +124,25 @@ in
|
|||
type = types.package;
|
||||
default = pkgs.bonsai;
|
||||
};
|
||||
sane.gui.sxmo.bonsaid.transitions = mkOption {
|
||||
type = types.listOf transitionType;
|
||||
default = [];
|
||||
};
|
||||
sane.gui.sxmo.bonsaid.configFile = mkOption {
|
||||
type = types.path;
|
||||
default = pkgs.writeText "bonsai_tree.json" (builtins.toJSON cfg.transitions);
|
||||
description = ''
|
||||
configuration file to pass to bonsai.
|
||||
usually auto-generated from the sibling options; exposed mainly for debugging or convenience.
|
||||
'';
|
||||
};
|
||||
};
|
||||
config = {
|
||||
sane.user.services.bonsaid = {
|
||||
description = "programmable input dispatcher";
|
||||
script = ''
|
||||
${pkgs.coreutils}/bin/rm -f $XDG_RUNTIME_DIR/bonsai
|
||||
exec ${cfg.package}/bin/bonsaid -t $XDG_CONFIG_HOME/sxmo/bonsai_tree.json
|
||||
exec ${cfg.package}/bin/bonsaid -t ${cfg.configFile}
|
||||
'';
|
||||
serviceConfig.Type = "simple";
|
||||
serviceConfig.Restart = "always";
|
||||
|
|
|
@ -408,6 +408,69 @@ in
|
|||
cfg.settings
|
||||
);
|
||||
|
||||
|
||||
sane.gui.sxmo.bonsaid.transitions = let
|
||||
doExec = inputName: {
|
||||
type = "exec";
|
||||
command = [
|
||||
"setsid"
|
||||
"-f"
|
||||
"sxmo_hook_inputhandler.sh"
|
||||
inputName
|
||||
];
|
||||
};
|
||||
onIdle = inputName: {
|
||||
type = "delay";
|
||||
delay_duration = 400000000;
|
||||
transitions = [
|
||||
(doExec inputName)
|
||||
];
|
||||
};
|
||||
onEvent = eventName: transitions: {
|
||||
type = "event";
|
||||
event_name = eventName;
|
||||
inherit transitions;
|
||||
};
|
||||
in [
|
||||
# define mappings for 1, 2, or 3 repeat presses of each primary button
|
||||
(onEvent "power_pressed" [
|
||||
(onIdle "powerbutton_three")
|
||||
(onEvent "power_released" [
|
||||
(onIdle "powerbutton_one")
|
||||
(onEvent "power_released" [
|
||||
(onIdle "powerbutton_two")
|
||||
(onEvent "power_released" [
|
||||
(doExec "powerbutton_three")
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
(onEvent "voldown_pressed" [
|
||||
(onIdle "voldown_three")
|
||||
(onEvent "voldown_released" [
|
||||
(onIdle "voldown_one")
|
||||
(onEvent "voldown_released" [
|
||||
(onIdle "voldown_two")
|
||||
(onEvent "voldown_released" [
|
||||
(doExec "voldown_three")
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
(onEvent "volup_pressed" [
|
||||
(onIdle "volup_three")
|
||||
(onEvent "volup_released" [
|
||||
(onIdle "volup_one")
|
||||
(onEvent "volup_released" [
|
||||
(onIdle "volup_two")
|
||||
(onEvent "volup_released" [
|
||||
(doExec "volup_three")
|
||||
])
|
||||
])
|
||||
])
|
||||
])
|
||||
];
|
||||
|
||||
# sxmo puts in /share/sxmo:
|
||||
# - profile.d/sxmo_init.sh
|
||||
# - appcfg/
|
||||
|
|
Loading…
Reference in New Issue
Block a user