Skip to content

Commit

Permalink
Switch Cmd/Option via Karabiner instead of keyboards
Browse files Browse the repository at this point in the history
  • Loading branch information
shajra committed Jan 21, 2024
1 parent 5983ba9 commit ebeaeee
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 15 deletions.
25 changes: 11 additions & 14 deletions home/modules/base/gui/all/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@ in {

fonts.fontconfig.enable = true;

# DESIGN: Allows VSCode to override settings, but everything will be lost
# upon a home-manager switch.
#
# REVISIT: Might want to complicate logic to more easily catch changes or
# maybe save them off as backups.
#
home.activation.removeVscodeMutableUserSettings =
# DESIGN: Allows VSCode to override settings, but we catch changes when
# performing a home-manager switch.
home.activation.restoreImmutableVscodeUserSettings =
lib.hm.dag.entryBefore [ "checkLinkTargets" ] ''
$DRY_RUN_CMD rm -f "${vscodeSettings}"
DEST="${vscodeSettings}"
if test -e "$DEST" && test -e "$DEST.home-manager" \
&& "${pkgs.diffutils}/bin/diff" -q "$DEST" "$DEST.home-manager"
then $DRY_RUN_CMD mv "$DEST.home-manager" "$DEST"
fi
'';

home.activation.makeVscodeUserSettingsMutable =
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
$DRY_RUN_CMD rm -f "${vscodeSettings}"
$DRY_RUN_CMD cat \
${(pkgs.formats.json {}).generate
"vscode-settings.json"
config.programs.vscode.userSettings} \
> "${vscodeSettings}"
DEST="${vscodeSettings}"
$DRY_RUN_CMD mv "$DEST" "$DEST.home-manager"
$DRY_RUN_CMD cat "$DEST.home-manager" > "$DEST"
'';

home.extraPackages = build.pkgs.lists.base.gui.all;
Expand Down
2 changes: 2 additions & 0 deletions home/modules/base/tui/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@

# REVISIT: 23-12-21: pinned to stable because broot built was broken
programs.broot.package = build.infra.np.nixpkgs.stable.broot;

xdg.configFile = import xdg/configFile;
}
20 changes: 19 additions & 1 deletion home/modules/base/tui/darwin/home/activation/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
config: lib: nixpkgs:
config: lib: pkgs:

let
home = config.home.homeDirectory;
Expand All @@ -25,4 +25,22 @@ in
$DRY_RUN_CMD [ -e "$app_path" ] && rm -r "$app_path"
$DRY_RUN_CMD mv "$tmp_path" "$app_path"
'';

# DESIGN: Allows Karabiner to override settings, but we catch changes when
# performing a home-manager switch.
restoreImmutableKarabinerJson =
lib.hm.dag.entryBefore [ "checkLinkTargets" ] ''
DEST="${config.xdg.configHome}/karabiner/karabiner.json"
if test -e "$DEST" && test -e "$DEST.home-manager" \
&& "${pkgs.diffutils}/bin/diff" -q "$DEST" "$DEST.home-manager"
then $DRY_RUN_CMD mv "$DEST.home-manager" "$DEST"
fi
'';

makeKarabinerJsonSettingsMutable =
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
DEST="${config.xdg.configHome}/karabiner/karabiner.json"
$DRY_RUN_CMD mv "$DEST" "$DEST.home-manager"
$DRY_RUN_CMD cat "$DEST.home-manager" > "$DEST"
'';
}
3 changes: 3 additions & 0 deletions home/modules/base/tui/darwin/xdg/configFile/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"karabiner/karabiner.json".source = ./karabiner.json;
}
283 changes: 283 additions & 0 deletions home/modules/base/tui/darwin/xdg/configFile/karabiner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
{
"global": {
"ask_for_confirmation_before_quitting": true,
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false,
"unsafe_ui": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
"basic.simultaneous_threshold_milliseconds": 50,
"basic.to_delayed_action_delay_milliseconds": 500,
"basic.to_if_alone_timeout_milliseconds": 1000,
"basic.to_if_held_down_threshold_milliseconds": 500,
"mouse_motion_to_scroll.speed": 100
},
"rules": []
},
"devices": [
{
"disable_built_in_keyboard_if_exists": false,
"fn_function_keys": [],
"identifiers": {
"is_keyboard": true,
"is_pointing_device": false,
"product_id": 833,
"vendor_id": 1452
},
"ignore": false,
"manipulate_caps_lock_led": true,
"simple_modifications": [],
"treat_as_built_in_keyboard": false
},
{
"disable_built_in_keyboard_if_exists": false,
"fn_function_keys": [],
"identifiers": {
"is_keyboard": false,
"is_pointing_device": true,
"product_id": 833,
"vendor_id": 1452
},
"ignore": true,
"manipulate_caps_lock_led": false,
"simple_modifications": [],
"treat_as_built_in_keyboard": false
},
{
"disable_built_in_keyboard_if_exists": false,
"fn_function_keys": [],
"identifiers": {
"is_keyboard": false,
"is_pointing_device": true,
"product_id": 407,
"vendor_id": 6780
},
"ignore": true,
"manipulate_caps_lock_led": false,
"simple_modifications": [],
"treat_as_built_in_keyboard": false
},
{
"disable_built_in_keyboard_if_exists": false,
"fn_function_keys": [],
"identifiers": {
"is_keyboard": true,
"is_pointing_device": false,
"product_id": 6,
"vendor_id": 13462
},
"ignore": false,
"manipulate_caps_lock_led": true,
"simple_modifications": [
{
"from": {
"key_code": "left_command"
},
"to": [
{
"key_code": "left_option"
}
]
},
{
"from": {
"key_code": "left_option"
},
"to": [
{
"key_code": "left_command"
}
]
},
{
"from": {
"key_code": "right_command"
},
"to": [
{
"key_code": "right_option"
}
]
},
{
"from": {
"key_code": "right_option"
},
"to": [
{
"key_code": "right_command"
}
]
}
],
"treat_as_built_in_keyboard": false
},
{
"disable_built_in_keyboard_if_exists": false,
"fn_function_keys": [],
"identifiers": {
"is_keyboard": false,
"is_pointing_device": true,
"product_id": 6,
"vendor_id": 13462
},
"ignore": true,
"manipulate_caps_lock_led": false,
"simple_modifications": [],
"treat_as_built_in_keyboard": false
},
{
"disable_built_in_keyboard_if_exists": false,
"fn_function_keys": [],
"identifiers": {
"is_keyboard": true,
"is_pointing_device": false,
"product_id": 34304,
"vendor_id": 1452
},
"ignore": false,
"manipulate_caps_lock_led": true,
"simple_modifications": [],
"treat_as_built_in_keyboard": false
}
],
"fn_function_keys": [
{
"from": {
"key_code": "f1"
},
"to": [
{
"consumer_key_code": "display_brightness_decrement"
}
]
},
{
"from": {
"key_code": "f2"
},
"to": [
{
"consumer_key_code": "display_brightness_increment"
}
]
},
{
"from": {
"key_code": "f3"
},
"to": [
{
"apple_vendor_keyboard_key_code": "mission_control"
}
]
},
{
"from": {
"key_code": "f4"
},
"to": [
{
"apple_vendor_keyboard_key_code": "spotlight"
}
]
},
{
"from": {
"key_code": "f5"
},
"to": [
{
"consumer_key_code": "dictation"
}
]
},
{
"from": {
"key_code": "f6"
},
"to": [
{
"key_code": "f6"
}
]
},
{
"from": {
"key_code": "f7"
},
"to": [
{
"consumer_key_code": "rewind"
}
]
},
{
"from": {
"key_code": "f8"
},
"to": [
{
"consumer_key_code": "play_or_pause"
}
]
},
{
"from": {
"key_code": "f9"
},
"to": [
{
"consumer_key_code": "fast_forward"
}
]
},
{
"from": {
"key_code": "f10"
},
"to": [
{
"consumer_key_code": "mute"
}
]
},
{
"from": {
"key_code": "f11"
},
"to": [
{
"consumer_key_code": "volume_decrement"
}
]
},
{
"from": {
"key_code": "f12"
},
"to": [
{
"consumer_key_code": "volume_increment"
}
]
}
],
"name": "Default",
"parameters": {
"delay_milliseconds_before_open_device": 1000
},
"selected": true,
"simple_modifications": [],
"virtual_hid_keyboard": {
"country_code": 0,
"indicate_sticky_modifier_keys_state": true,
"mouse_key_xy_scale": 100
}
}
]
}

0 comments on commit ebeaeee

Please sign in to comment.