From f546f737fe5aeedce3e84bf3d18fa799270e4e43 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sat, 10 Jul 2021 16:27:26 +0200 Subject: [PATCH] sway: Enable screencasts via xdg-desktop-portal-wlr This also adds a blinking indicator to the status bar so it is obvious when the screen is shared. --- modules/gui.nix | 11 ++++++++ users/simon/files/waybar/style.css | 10 +++++++ users/simon/modules/sway.nix | 43 +++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/modules/gui.nix b/modules/gui.nix index d4cc32b..e8e2097 100644 --- a/modules/gui.nix +++ b/modules/gui.nix @@ -8,6 +8,17 @@ lib.mkIf config.sbruder.gui.enable { extraPackages = [ ]; }; + xdg = { + portal = { + enable = true; + extraPortals = with pkgs; [ + xdg-desktop-portal-wlr + xdg-desktop-portal-gtk + ]; + gtkUsePortal = true; + }; + }; + # steam (and other high quality software) still ships 32 bit binaries hardware.opengl.driSupport32Bit = lib.mkDefault pkgs.stdenv.isx86_64; diff --git a/users/simon/files/waybar/style.css b/users/simon/files/waybar/style.css index 750085d..1c37e13 100644 --- a/users/simon/files/waybar/style.css +++ b/users/simon/files/waybar/style.css @@ -156,3 +156,13 @@ window#waybar { background-color: @base3@; color: @base03@; } + +#custom-screencast { + background-color: @red@; + color: @base03@; + animation-name: blink; + animation-duration: 0.5s; + animation-timing-function: cubic-bezier(1, 0, 0, 1); + animation-iteration-count: infinite; + animation-direction: alternate; +} diff --git a/users/simon/modules/sway.nix b/users/simon/modules/sway.nix index 155172e..e23cc93 100644 --- a/users/simon/modules/sway.nix +++ b/users/simon/modules/sway.nix @@ -343,9 +343,9 @@ lib.mkIf nixosConfig.sbruder.gui.enable { ]; modules-right = [ "tray" + "custom/screencast" "custom/redshift" "idle_inhibitor" - "custom/notification_inhibitor" "backlight" "mpd" "pulseaudio" @@ -386,6 +386,38 @@ lib.mkIf nixosConfig.sbruder.gui.enable { deactivated = " "; }; }; + "custom/screencast" = { + exec = pkgs.writeScript "screencast-monitor" '' + #!${pkgs.python3}/bin/python3 + import subprocess + import sys + + active_outputs = 0 + + with subprocess.Popen( + ["${pkgs.coreutils}/bin/stdbuf", "-o0", "${nixosConfig.services.pipewire.package}/bin/pw-link", "-m", "-o", "xdg-desktop-portal-wlr"], + stdout=subprocess.PIPE, + text=True, + ) as proc: + for line in proc.stdout: + action = line.split(" ")[0] + if action == "=" or action == "+": + active_outputs += 1 + elif action == "-": + active_outputs -= 1 + else: + print(f"Invalid action {action} (in line {line})", file=sys.stderr) + + if active_outputs > 0: + print("${lrm} ") + else: + print() + + sys.stdout.flush() + ''; + format = "{}"; + tooltip = false; + }; backlight = { format = "{percent}% {icon}"; format-icons = [ " " " " " " " " " " " " " " ]; @@ -596,4 +628,13 @@ lib.mkIf nixosConfig.sbruder.gui.enable { night = 3500; }; }; + + # screen recording/sharing with pipewire + xdg.configFile."xdg-desktop-portal-wlr/config".text = lib.generators.toINI { } { + screencast = { + max_fps = 30; + chooser_type = "simple"; + chooser_cmd = "slurp -f %o -or"; + }; + }; }