From 715de37954c3bd398a592abaeef2abbae7e54c18 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 27 Feb 2024 21:20:12 +0000 Subject: [PATCH] rofi: fix files to be opened with xdg-open --- hosts/common/programs/rofi/config.rasi | 5 ++-- hosts/common/programs/rofi/default.nix | 17 +++++++++++-- hosts/common/programs/rofi/rofi-run-command | 27 +++++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100755 hosts/common/programs/rofi/rofi-run-command diff --git a/hosts/common/programs/rofi/config.rasi b/hosts/common/programs/rofi/config.rasi index 1b2a7509..b3dc269f 100644 --- a/hosts/common/programs/rofi/config.rasi +++ b/hosts/common/programs/rofi/config.rasi @@ -16,6 +16,7 @@ configuration { directory: "/home"; /* display-name: text to prepend in combi mode */ display-name: "/"; + /* `command` is the prefix to prepend (along with a space) *before* passing it off to `run-command` */ command: "xdg-open"; } drun { @@ -28,8 +29,8 @@ configuration { /* combi-display-format: "{text}"; */ combi-display-format: "{mode}{text}"; - /* launch applications via xdg-desktop-portal */ - run-command: "gdbus call --session --timeout 10 --dest org.freedesktop.portal.Desktop --object-path /org/freedesktop/portal/desktop --method org.freedesktop.portal.DynamicLauncher.Launch {app_id}.desktop {}"; + /* launch applications via my own launcher, which directs them through to xdg-desktop-portal */ + run-command: "rofi-run-command '{app_id}.desktop' {cmd}"; drun-use-desktop-cache: true; } diff --git a/hosts/common/programs/rofi/default.nix b/hosts/common/programs/rofi/default.nix index 93406588..c773b93f 100644 --- a/hosts/common/programs/rofi/default.nix +++ b/hosts/common/programs/rofi/default.nix @@ -50,8 +50,7 @@ }; suggestedPrograms = [ - "xdg-utils" - "gdbus" + "rofi-run-command" ]; sandbox.method = "bwrap"; @@ -78,4 +77,18 @@ ".cache/rofi" ]; }; + + sane.programs.rofi-run-command = { + packageUnwrapped = pkgs.static-nix-shell.mkBash { + pname = "rofi-run-command"; + srcRoot = ./.; + pkgs = [ "glib" "xdg-utils" ]; + }; + sandbox.enable = false; #< trivial script, and all our deps are sandboxed + + suggestedPrograms = [ + "gdbus" + "xdg-utils" + ]; + }; } diff --git a/hosts/common/programs/rofi/rofi-run-command b/hosts/common/programs/rofi/rofi-run-command new file mode 100755 index 00000000..e2e66ce1 --- /dev/null +++ b/hosts/common/programs/rofi/rofi-run-command @@ -0,0 +1,27 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p glib -p xdg-utils + +# use: +# rofi-run-command .desktop [cmd [args ...]] +# if a non-empty desktop file is provided, we'll just launch that. +# else, if the cmd is `xdg-open`, then we'll treat `args` as a URI and forward that to xdg-open. +# nothing else is as-yet supported. + +desktop="$1" +shift +binary="$1" +shift +binArgs=("$@") + +if [ "$desktop" != .desktop ]; then + exec gdbus call --session --timeout 10 \ + --dest org.freedesktop.portal.Desktop \ + --object-path /org/freedesktop/portal/desktop \ + --method org.freedesktop.portal.DynamicLauncher.Launch \ + "$desktop" {} +elif [ "$binary" = "xdg-open" ]; then + exec xdg-open "$@" +fi + +printf "no .desktop file, and unexpected binary; not invoking: %s %s" "$binary" "${binArgs[*]}" > /dev/null +exit 1