sway ptt&botamusique, wrap nix for nil lsp

This commit is contained in:
chayleaf 2023-05-23 11:33:32 +07:00
parent 3a46dc3c2a
commit 92dc5eb16e
7 changed files with 179 additions and 36 deletions

View file

@ -220,6 +220,15 @@ in
''; '';
wayland.windowManager.sway = { wayland.windowManager.sway = {
wrapperFeatures.gtk = true; wrapperFeatures.gtk = true;
package = pkgs.sway-unwrapped.overrideAttrs (old: {
patches = old.patches or [] ++ [
./sway.patch
/*(pkgs.fetchpatch {
url = "https://patch-diff.githubusercontent.com/raw/swaywm/sway/pull/6920.patch";
sha256 = "sha256-XgkysduhHbmprE334yeL65txpK0HNXeCmgCZMxpwsgU=";
})*/
];
});
extraConfig = '' extraConfig = ''
title_align center title_align center
''; '';
@ -248,7 +257,7 @@ in
"3" = [{ app_id = "org.keepassxc.KeePassXC"; }]; "3" = [{ app_id = "org.keepassxc.KeePassXC"; }];
}; };
keybindings = genKeybindings options.wayland.windowManager.sway (with pkgs.sway-contrib; keybindings = genKeybindings options.wayland.windowManager.sway (with pkgs.sway-contrib;
let /*let
modifiers = [ modifiers = [
"shift" "shift"
"lock" # caps lock "lock" # caps lock
@ -290,7 +299,9 @@ in
# mumble remembers the amount of times starttalking has been called, # mumble remembers the amount of times starttalking has been called,
# and if stoptalking isn't called for some reason, calling it one time stops being enough # and if stoptalking isn't called for some reason, calling it one time stops being enough
"exec ${pkgs.mumble}/bin/mumble rpc stoptalking && ${pkgs.mumble}/bin/mumble rpc stoptalking") "exec ${pkgs.mumble}/bin/mumble rpc stoptalking && ${pkgs.mumble}/bin/mumble rpc stoptalking")
// { //*/ {
"--inhibited --no-repeat --allow-other Scroll_Lock" = "exec ${pkgs.mumble}/bin/mumble rpc starttalking";
"--inhibited --no-repeat --allow-other --release Scroll_Lock" = "exec ${pkgs.mumble}/bin/mumble rpc stoptalking";
"${modifier}+c" = "exec ${rofiSway}/bin/rofi -show calc -no-show-match -no-sort -no-persist-history"; "${modifier}+c" = "exec ${rofiSway}/bin/rofi -show calc -no-show-match -no-sort -no-persist-history";
"${modifier}+Print" = "exec ${grimshot}/bin/grimshot copy area"; "${modifier}+Print" = "exec ${grimshot}/bin/grimshot copy area";
"${modifier}+Mod1+Print" = "exec ${grimshot}/bin/grimshot copy window"; "${modifier}+Mod1+Print" = "exec ${grimshot}/bin/grimshot copy window";
@ -354,8 +365,8 @@ in
]; ];
timeouts = [ timeouts = [
{ timeout = 300; { timeout = 300;
command = "${pkgs.sway}/bin/swaymsg \"output * power off\""; command = "${config.wayland.windowManager.sway.package}/bin/swaymsg \"output * power off\"";
resumeCommand = "${pkgs.sway}/bin/swaymsg \"output * power on\""; } resumeCommand = "${config.wayland.windowManager.sway.package}/bin/swaymsg \"output * power on\""; }
{ timeout = 600; { timeout = 600;
command = swaylock-start; } command = swaylock-start; }
]; ];

View file

@ -80,7 +80,6 @@
which-key = REQ "which-key"; which-key = REQ "which-key";
luasnip = REQ "luasnip"; luasnip = REQ "luasnip";
cmp = REQ "cmp";
compile' = name: stmts: compile name (L stmts); compile' = name: stmts: compile name (L stmts);
in { in {
enable = true; enable = true;
@ -428,33 +427,40 @@
on_attach client bufnr _ on_attach client bufnr _
]) ])
# BEGIN # BEGIN
(let setupLsp' = { name, settings ? {} }: (lsp name).setup { (let setupLsp = name: args: (lsp name).setup ({
inherit on_attach capabilities settings; inherit on_attach capabilities;
}; settings = { };
setupLsp = args: setupLsp' (if builtins.isString args then { name = args; } else args); } // args);
in on_attach_rust: L [ in on_attach_rust: L [
# vim.lsp.set_log_level "debug" _ # vim.lsp.set_log_level "debug" _
# see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md # see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
map setupLsp [ lib.mapAttrsToList setupLsp {
"bashls" bashls = {};
"clangd" clangd = {};
# https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md # https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md
{ name = "pylsp"; settings = { pylsp = {
settings = {
pylsp.plugins.pylsp_mypy.enabled = true; pylsp.plugins.pylsp_mypy.enabled = true;
}; } };
"svelte" };
"html" svelte = { };
"cssls" html = { };
"tsserver" cssls = { };
"jsonls" tsserver = { };
"nil_ls" jsonls = { };
"taplo" nil_ls = {
"marksman" settings = {
] _ nil.nix.binary = "${pkgs.writeShellScript "nil-nix-wrapper" ''
(lsp "rust_analyzer").setup { nix --allow-import-from-derivation "$@"
''}";
};
};
taplo = { };
marksman = { };
rust_analyzer = {
on_attach = on_attach_rust; on_attach = on_attach_rust;
settings = rust_settings; settings = rust_settings;
inherit capabilities; };
} _ } _
]) # END ]) # END
) _ # END ) _ # END

111
home/common/sway.patch Normal file
View file

@ -0,0 +1,111 @@
diff --git a/include/sway/config.h b/include/sway/config.h
index aa58da53..223efae0 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -50,6 +50,7 @@ enum binding_flags {
BINDING_INHIBITED = 1 << 7, // keyboard only: ignore shortcut inhibitor
BINDING_NOREPEAT = 1 << 8, // keyboard only; do not trigger when repeating a held key
BINDING_EXACT = 1 << 9, // gesture only; only trigger on exact match
+ BINDING_ALLOWOTHER = 1 << 10, // keyboard only; allow other keys to be pressed at the same time
};
/**
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index 979e178f..d17458ea 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -377,6 +377,8 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
warn = false;
} else if (strcmp("--no-repeat", argv[0]) == 0) {
binding->flags |= BINDING_NOREPEAT;
+ } else if (strcmp("--allow-other", argv[0]) == 0) {
+ binding->flags |= BINDING_ALLOWOTHER;
} else {
break;
}
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index c3bf4fbb..78ef8e61 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -162,8 +162,9 @@ static void get_active_binding(const struct sway_shortcut_state *state,
bool binding_locked = (binding->flags & BINDING_LOCKED) != 0;
bool binding_inhibited = (binding->flags & BINDING_INHIBITED) != 0;
bool binding_release = binding->flags & BINDING_RELEASE;
+ bool binding_allowother = (binding->flags & BINDING_ALLOWOTHER) != 0;
- if (modifiers ^ binding->modifiers ||
+ if ((binding_allowother ? (binding->modifiers & modifiers) : modifiers) ^ binding->modifiers ||
release != binding_release ||
locked > binding_locked ||
inhibited > binding_inhibited ||
@@ -175,7 +176,42 @@ static void get_active_binding(const struct sway_shortcut_state *state,
}
bool match = false;
- if (state->npressed == (size_t)binding->keys->length) {
+ if (binding_allowother) {
+ /*
+ * Make sure all keys match, but also allow other keys to be pressed.
+ * In case of a press (as opposed to release), make sure at least one
+ * of the keys is the current key, otherwise the binding would be
+ * triggered twice. In case of release, the keys are considered released
+ * all at once so no check is necessary.
+ */
+ bool one_key_is_current = false;
+
+ match = binding->keys->length != 0;
+
+ for (int j = 0; j < binding->keys->length; j++) {
+ bool key_match = false;
+ uint32_t key = *(uint32_t *)binding->keys->items[j];
+
+ for (size_t k = 0; k < state->npressed; k++) {
+ if (key == state->pressed_keys[k]) {
+ key_match = true;
+ break;
+ }
+ }
+
+ if (!key_match) {
+ match = false;
+ break;
+ }
+ if (key == state->current_key) {
+ one_key_is_current = true;
+ }
+ }
+
+ if (!release && !one_key_is_current) {
+ match = false;
+ }
+ } else if (state->npressed == (size_t)binding->keys->length) {
match = true;
for (size_t j = 0; j < state->npressed; j++) {
uint32_t key = *(uint32_t *)binding->keys->items[j];
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 25082c41..268e0526 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -389,8 +389,8 @@ runtime.
for_window <criteria> move container to output <output>
*bindsym* [--whole-window] [--border] [--exclude-titlebar] [--release] [--locked] \
-[--to-code] [--input-device=<device>] [--no-warn] [--no-repeat] [Group<1-4>+]<key combo> \
-<command>
+[--to-code] [--input-device=<device>] [--no-warn] [--no-repeat] [--allow-other] \
+[Group<1-4>+]<key combo> <command>
Binds _key combo_ to execute the sway command _command_ when pressed. You
may use XKB key names here (*wev*(1) is a good tool for discovering these).
With the flag _--release_, the command is executed when the key combo is
@@ -419,6 +419,11 @@ runtime.
repeatedly when the key is held, according to the repeat
settings specified in the input configuration.
+ If _--allow-other_ is set, any key sequence containing this key sequence
+ may trigger this binding. For example, a single-key binding with
+ _--allow-other_ set may be executed upon the simultaneous press of one
+ or more keys, one of which is the binding's key.
+
Bindings to keysyms are layout-dependent. This can be changed with the
_--to-code_ flag. In this case, the keysyms will be translated into the
corresponding keycodes in the first configured layout.

View file

@ -60,17 +60,17 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1682202201, "lastModified": 1684668267,
"narHash": "sha256-3r5izcrgfO2RxV1gU7aWQnGAky5Ek3wyzM+9eQtG4M4=", "narHash": "sha256-AKnX12OwVEqXDv8Th2QDT96MPvC8Zv5KCtVdqc7l3hY=",
"owner": "chayleaf", "owner": "chayleaf",
"repo": "notlua", "repo": "notlua",
"rev": "cd89a08083cc43a07ac1f6ced0594fa7f49c5cf2", "rev": "469652092f4f2e951b0db29027b05346b32d8122",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "chayleaf", "owner": "chayleaf",
"ref": "master",
"repo": "notlua", "repo": "notlua",
"rev": "469652092f4f2e951b0db29027b05346b32d8122",
"type": "github" "type": "github"
} }
}, },

View file

@ -14,7 +14,7 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
notlua = { notlua = {
url = "github:chayleaf/notlua/master"; url = "github:chayleaf/notlua/469652092f4f2e951b0db29027b05346b32d8122";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };

View file

@ -12,6 +12,6 @@
boot = { boot = {
initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usb_storage" "sd_mod" "sr_mod" "rtsx_pci_sdmmc" ]; initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usb_storage" "sd_mod" "sr_mod" "rtsx_pci_sdmmc" ];
kernelModules = [ "kvm-intel" ]; kernelModules = [ "kvm-intel" ];
vfio.intelCpu = true;
}; };
vfio.intelCpu = true;
} }

View file

@ -1,4 +1,5 @@
{ config { config
, pkgs
, lib , lib
, ... }: , ... }:
@ -38,9 +39,23 @@ in {
services.botamusique = { services.botamusique = {
enable = true; enable = true;
# TODO: remove after next nixpkgs version bump
package = pkgs.botamusique.override {
python3Packages = pkgs.python3Packages // {
pymumble = pkgs.python3Packages.pymumble.overrideAttrs (old: rec {
version = "1.6.1";
src = pkgs.fetchFromGitHub {
owner = "azlux";
repo = "pymumble";
rev = "refs/tags/${version}";
hash = "sha256-+sT5pqdm4A2rrUcUUmvsH+iazg80+/go0zM1vr9oeuE=";
};
});
};
};
settings = { settings = {
youtube_dl = { youtube_dl = {
cookiefile = "/var/lib/botamusique/cookie_ydl"; cookiefile = "/var/lib/private/botamusique/cookie_ydl";
}; };
webinterface = { webinterface = {
enabled = true; enabled = true;
@ -59,7 +74,7 @@ in {
ducking = true; ducking = true;
ducking_volume = 0.75; ducking_volume = 0.75;
}; };
server.certificate = "/var/lib/botamusique/cert.pem"; server.certificate = "/var/lib/private/botamusique/botamusique.pem";
}; };
}; };
systemd.services.botamusique.wants = [ "murmur.service" ]; systemd.services.botamusique.wants = [ "murmur.service" ];