1
1
Fork 0

clipnotify: fix wayland->x11 duplicating copy

Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
Myned 2025-02-02 19:29:56 -06:00
parent 627e90b07f
commit 589c64bbf9
Signed by: Myned
GPG key ID: C7224454F7881A34
2 changed files with 10 additions and 7 deletions

View file

@ -8,14 +8,11 @@ with lib; let
cfg = config.custom.desktops.niri.misc;
hm = config.home-manager.users.${config.custom.username};
_1password = "${config.programs._1password-gui.package}/bin/1password";
audio = config.home-manager.users.${config.custom.username}.home.file.".local/bin/audio".source;
niri = "${config.programs.niri.package}/bin/niri";
rm = "${pkgs.coreutils}/bin/rm";
sway-audio-idle-inhibit = "${pkgs.sway-audio-idle-inhibit}/bin/sway-audio-idle-inhibit";
wallpaper = "${config.home-manager.users.${config.custom.username}.home.file.".local/bin/wallpaper".source}";
wl-paste = "${pkgs.wl-clipboard}/bin/wl-paste";
xclip = "${pkgs.xclip}/bin/xclip";
in {
options.custom.desktops.niri.misc = {
enable = mkOption {default = false;};
@ -33,6 +30,7 @@ in {
theme = name;
# BUG: Heavily increases CPU usage with cursor movement
# https://github.com/YaLTeR/niri/issues/1037
#// hide-after-inactive-ms = 1000 * 15; # Milliseconds
#// hide-when-typing = true;
};
@ -61,9 +59,6 @@ in {
]
++ optionals config.custom.wallpaper [
{command = [wallpaper];}
]
++ optionals config.custom.desktops.niri.xwayland [
{command = [wl-paste "--watch" xclip "-selection" "clipboard"];} # Sync (X)wayland clipboard
];
# https://github.com/sodiboo/niri-flake/blob/main/docs.md#programsnirisettingsswitch-eventslid-close

View file

@ -9,6 +9,7 @@ with lib; let
clipnotify = getExe pkgs.clipnotify;
wl-copy = getExe' pkgs.wl-clipboard "wl-copy";
wl-paste = getExe' pkgs.wl-clipboard "wl-paste";
xclip = getExe pkgs.xclip;
in {
options.custom.services.clipsync = {
@ -33,8 +34,15 @@ in {
Type = "simple";
ExecStart = pkgs.writeShellScript "clipsync" ''
# Push Wayland clipboard to X11
${wl-paste} --watch ${xclip} -selection clipboard &
# When X11 clipboard changes
while ${clipnotify}; do
${xclip} -selection clipboard -out | ${wl-copy}
# Push X11 clipboard to Wayland if not a duplicate
if [[ "$(${wl-paste})" != "$(${xclip} -selection clipboard -out)" ]]; then
${xclip} -selection clipboard -out | ${wl-copy}
fi
done
'';
};