-
Notifications
You must be signed in to change notification settings - Fork 0
/
xwayland.mod.nix
83 lines (76 loc) · 2.99 KB
/
xwayland.mod.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{
personal.modules = [
({lib, ...}: {
nixpkgs.overlays = [
(final: prev: {
sodi-x-run-env = let
wl-copy = lib.getExe' final.wl-clipboard "wl-copy";
wl-paste = lib.getExe' final.wl-clipboard "wl-paste";
xclip = lib.getExe final.xclip;
clipnotify = lib.getExe final.clipnotify;
metacity = lib.getExe final.metacity;
in
# Here, we use xclip over xsel because it supports binary data.
# Additionally, we sha256sum that binary data so no shell fuckery happens to null bytes.
# Doing so ensures we don't overwrite image/png data, among others.
# See also: https://gaysex.cloud/notes/9v1o3sc3q66f0mrr
final.writeShellScriptBin "x-run-env" ''
primary-wl-to-x () {
while read; do
if [[ "$(${wl-paste} --primary --no-newline | sha256sum)" != "$(${xclip} -selection primary -out | sha256sum)" ]]; then
echo "syncing primary wl->x"
${wl-paste} --primary --no-newline | ${xclip} -selection primary -in
fi
done < <(${wl-paste} --primary --watch echo)
}
primary-x-to-wl () {
while ${clipnotify} -s primary; do
if [[ "$(${wl-paste} --primary --no-newline | sha256sum)" != "$(${xclip} -selection primary -out | sha256sum)" ]]; then
echo "syncing primary x->wl"
${xclip} -selection primary -out | ${wl-copy} --primary
fi
done
}
clipboard-wl-to-x () {
while read; do
if [[ "$(${wl-paste} --no-newline | sha256sum)" != "$(${xclip} -selection clipboard -out | sha256sum)" ]]; then
echo "syncing clipboard wl->x"
${wl-paste} --no-newline | ${xclip} -selection clipboard -in
fi
done < <(${wl-paste} --watch echo)
}
clipboard-x-to-wl () {
while ${clipnotify} -s clipboard; do
if [[ "$(${wl-paste} --no-newline | sha256sum)" != "$(${xclip} -selection clipboard -out | sha256sum)" ]]; then
echo "syncing clipboard x->wl"
${xclip} -selection clipboard -out | ${wl-copy}
fi
done
}
clipboard-wl-to-x &
clipboard-x-to-wl &
primary-wl-to-x &
primary-x-to-wl &
${metacity} &
"$@"
'';
sodi-x-run = final.writeShellScriptBin "x-run" ''
${lib.getExe final.xwayland-run} -- ${lib.getExe final.sodi-x-run-env} "$@"
'';
})
];
})
];
personal.home_modules = [
({pkgs, ...}: {
home.packages = with pkgs; [
xwayland
xwayland-run
xsel
xclip
metacity
sodi-x-run
];
})
];
}