From b1d1322e25459f1f7c79a866b2abf06fc5535e33 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 8 Dec 2022 16:12:00 +0100 Subject: tv pinentry-urxvt: show tinted screenshots --- tv/5pkgs/simple/pinentry-urxvt/default.nix | 74 ++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) (limited to 'tv/5pkgs/simple') diff --git a/tv/5pkgs/simple/pinentry-urxvt/default.nix b/tv/5pkgs/simple/pinentry-urxvt/default.nix index 65b76c07..6e4f6b00 100644 --- a/tv/5pkgs/simple/pinentry-urxvt/default.nix +++ b/tv/5pkgs/simple/pinentry-urxvt/default.nix @@ -20,7 +20,11 @@ let type = lib.types.str; }; display = lib.mkOption { - default = ":0"; + default = null; + type = lib.types.nullOr lib.types.str; + }; + xwud.className = lib.mkOption { + default = "PinentryUrxvtXwudFloat"; type = lib.types.str; }; }; @@ -30,12 +34,76 @@ let in + # pinentry-urxvt - A mechanism for PIN entry utilizing rxvt-unicode + # + # This spawns a PIN entry terminal on top of a tinted screenshot of the + # current display's root window. The display for spawning the terminal can + # be predefined, in which case both the current and the predefined display + # will show the screenshot. + # + # The purpose of the screenshot, aside from looking nice, is to prevent entry + # of the PIN into the wrong window, e.g. by accidentally moving the cursor + # while typing. If necessary, the screenshot can be closed by sending 'q', + # 'Q', or ctrl-c while its focused. + # pkgs.write "pinentry-urxvt" { "/bin/pinentry".link = pkgs.writeDash "pinentry-urxvt-wrapper" '' set -efu + + trap cleanup EXIT + + cleanup() { + rm "$screenshot" + # Kill process group in order to kill screenshot windows. + ${pkgs.utillinux}/bin/kill 0 + } + + screenshot=$(${pkgs.coreutils}/bin/mktemp -t pinentry-urxvt.screenshot.XXXXXXXX) + + ${pkgs.xorg.xwd}/bin/xwd -root | + ${pkgs.imagemagick}/bin/convert xwd:- -fill \#424242 -colorize 80% xwd:"$screenshot" + + show_screenshot() { + ${pkgs.exec "pinentry-urxvt.show_screenshot" { + filename = "${pkgs.xorg.xwud}/bin/xwud"; + argv = [ + cfg.xwud.className + "-noclick" + ]; + }} < "$screenshot" & + wait_for_screenshot $! + } + + # Wait for the xwud window by trying to intercept the call to munmap(). + # If it cannot be intercepted within 0.1s, assume that attaching strace + # wasn't fast enough or xwud doesn't call munmap() anymore. In either + # case fall back to search the window by class name, assuming there can + # be only one per display. + wait_for_screenshot() { + if ! \ + ${pkgs.coreutils}/bin/timeout 0.1 \ + ${pkgs.strace}/bin/strace -p "$1" -e munmap 2>&1 | + read -r _ + then + until ${pkgs.xdotool}/bin/xdotool search \ + --classname ${lib.shell.escape cfg.xwud.className} + do + ${pkgs.coreutils}/bin/sleep 0.1 + done + fi + } + + show_screenshot + + ${lib.optionalString (cfg.display != null) /* sh */ '' + if test "$DISPLAY" != ${lib.shell.escape cfg.display}; then + export DISPLAY=${lib.shell.escape cfg.display} + show_screenshot + fi + ''} + exec 3<&0 4>&1 5>&2 - export DISPLAY=${lib.shell.escape cfg.display} - exec ${pkgs.rxvt_unicode}/bin/urxvt \ + ${pkgs.rxvt_unicode}/bin/urxvt \ -name ${lib.shell.escape cfg.appName} \ -e ${pkgs.writeDash "pinentry-urxvt-tty" '' set -efu -- cgit v1.2.3 From 6d64096cd99db27357bf2d038bdfdfc2d3a3aeae Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 9 Dec 2022 01:31:56 +0100 Subject: tv: normalize lib imports --- tv/5pkgs/simple/bash-fzf-history.nix | 2 +- tv/5pkgs/simple/default.nix | 2 +- tv/5pkgs/simple/lib | 1 + tv/5pkgs/simple/pinentry-urxvt/default.nix | 3 +-- tv/5pkgs/simple/pinentry-urxvt/lib | 1 + tv/5pkgs/simple/q/default.nix | 4 ++-- tv/5pkgs/simple/q/lib | 1 + 7 files changed, 8 insertions(+), 6 deletions(-) create mode 120000 tv/5pkgs/simple/lib create mode 120000 tv/5pkgs/simple/pinentry-urxvt/lib create mode 120000 tv/5pkgs/simple/q/lib (limited to 'tv/5pkgs/simple') diff --git a/tv/5pkgs/simple/bash-fzf-history.nix b/tv/5pkgs/simple/bash-fzf-history.nix index 88a8e9e4..1166ec7f 100644 --- a/tv/5pkgs/simple/bash-fzf-history.nix +++ b/tv/5pkgs/simple/bash-fzf-history.nix @@ -1,4 +1,4 @@ -with import ; +with import ./lib; { pkgs , edit-key ? "ctrl-e" diff --git a/tv/5pkgs/simple/default.nix b/tv/5pkgs/simple/default.nix index 9fb45dd1..82a19a9b 100644 --- a/tv/5pkgs/simple/default.nix +++ b/tv/5pkgs/simple/default.nix @@ -1,4 +1,4 @@ -with import ../../../lib; +with import ./lib; self: super: diff --git a/tv/5pkgs/simple/lib b/tv/5pkgs/simple/lib new file mode 120000 index 00000000..dc598c56 --- /dev/null +++ b/tv/5pkgs/simple/lib @@ -0,0 +1 @@ +../lib \ No newline at end of file diff --git a/tv/5pkgs/simple/pinentry-urxvt/default.nix b/tv/5pkgs/simple/pinentry-urxvt/default.nix index 6e4f6b00..c768a9f5 100644 --- a/tv/5pkgs/simple/pinentry-urxvt/default.nix +++ b/tv/5pkgs/simple/pinentry-urxvt/default.nix @@ -1,8 +1,7 @@ +with import ./lib; { pkgs, ... }@args: let - lib = import ; - # config cannot be declared in the input attribute set because that would # cause callPackage to inject the wrong config. Instead, get it from ... # via args. diff --git a/tv/5pkgs/simple/pinentry-urxvt/lib b/tv/5pkgs/simple/pinentry-urxvt/lib new file mode 120000 index 00000000..dc598c56 --- /dev/null +++ b/tv/5pkgs/simple/pinentry-urxvt/lib @@ -0,0 +1 @@ +../lib \ No newline at end of file diff --git a/tv/5pkgs/simple/q/default.nix b/tv/5pkgs/simple/q/default.nix index e17282e1..2ae71db5 100644 --- a/tv/5pkgs/simple/q/default.nix +++ b/tv/5pkgs/simple/q/default.nix @@ -1,5 +1,5 @@ -{ pkgs, ... }: -with import ; +with import ./lib; +{ pkgs }: let q-cal = let diff --git a/tv/5pkgs/simple/q/lib b/tv/5pkgs/simple/q/lib new file mode 120000 index 00000000..dc598c56 --- /dev/null +++ b/tv/5pkgs/simple/q/lib @@ -0,0 +1 @@ +../lib \ No newline at end of file -- cgit v1.2.3 From 3996bc0804dcfb6176f407dc951d814407c47cf2 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 8 Dec 2022 22:45:09 +0100 Subject: tv: init alacritty-tv --- tv/5pkgs/simple/alacritty-font-size.nix | 67 ++++++++++++++++++++++++ tv/5pkgs/simple/alacritty-tv.nix | 93 +++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tv/5pkgs/simple/alacritty-font-size.nix create mode 100644 tv/5pkgs/simple/alacritty-tv.nix (limited to 'tv/5pkgs/simple') diff --git a/tv/5pkgs/simple/alacritty-font-size.nix b/tv/5pkgs/simple/alacritty-font-size.nix new file mode 100644 index 00000000..84bc3f61 --- /dev/null +++ b/tv/5pkgs/simple/alacritty-font-size.nix @@ -0,0 +1,67 @@ +{ pkgs }: + +pkgs.writeDashBin "font-size-alacritty" '' + # usage: font-size-alacritty (+N|-N|=N) + # Increase by, decrease by, or set font size to the value N. + + set -efu + + min_size=8 + + op=''${1%%[0-9]*} + op=''${op:-=} + + value=''${1#[=+-]} + + window_id=$(${pkgs.xdotool}/bin/xdotool getactivewindow) + + current_size=$( + ${pkgs.xorg.xprop}/bin/xprop -notype -id $window_id FONT_SIZE | + ${pkgs.gnused}/bin/sed -rn 's/.* = ([0-9]+)$/\1/p' + ) + + # usage: set_font_size WINDOW_ID FONT_SIZE + set_font_size() { + ${pkgs.alacritty}/bin/alacritty msg config -w $1 font.size=$2 + ${pkgs.xorg.xprop}/bin/xprop -id $1 -f FONT_SIZE 32c -set FONT_SIZE $2 + } + + # usage: reset_font_size WINDOW_ID + reset_font_size() { + ${pkgs.alacritty}/bin/alacritty msg config -w $1 font.size=$min_size + ${pkgs.xorg.xprop}/bin/xprop -id $1 -remove FONT_SIZE + } + + # usage: make_next_size + make_next_size() { + case $op in + -) next_size=$(expr $current_size - $value) ;; + =) next_size=$value ;; + +) + next_size=$(expr $current_size + $value) + test $next_size -ge $min_size || next_size=$min_size + ;; + esac + } + + if test -z "$current_size"; then + current_size=0 + make_next_size + if test $next_size -ge $min_size; then + ${pkgs.alacritty}/bin/alacritty msg config -w $window_id \ + font.normal.family='Input Mono' \ + font.normal.style=Condensed \ + font.bold.family='Input Mono' \ + font.bold.style=Bold + set_font_size $window_id $next_size + fi + else + make_next_size + if test $next_size -ge $min_size; then + set_font_size $window_id $next_size + else + ${pkgs.alacritty}/bin/alacritty msg config -w $window_id -r + reset_font_size $window_id + fi + fi +'' diff --git a/tv/5pkgs/simple/alacritty-tv.nix b/tv/5pkgs/simple/alacritty-tv.nix new file mode 100644 index 00000000..466ff27c --- /dev/null +++ b/tv/5pkgs/simple/alacritty-tv.nix @@ -0,0 +1,93 @@ +{ pkgs }: + +let + lib = import ./lib; + font-size = arg: { + program = "${pkgs.font-size-alacritty}/bin/font-size-alacritty"; + args = [arg]; + }; + config = { + bell.animation = "EaseOut"; + bell.duration = 50; + bell.color = "#ff00ff"; + colors.cursor.cursor = "#f042b0"; + colors.primary.background = "#202020"; + colors.primary.foreground = "#d0d7d0"; + colors.normal.black = "#000000"; + colors.normal.red = "#cd0000"; + colors.normal.green = "#00cd00"; + colors.normal.yellow = "#bc7004"; + colors.normal.blue = "#4343be"; + colors.normal.magenta = "#cb06cb"; + colors.normal.cyan = "#04c9c9"; + colors.normal.white = "#bebebe"; + colors.bright.black = "#727272"; + colors.bright.red = "#fb6262"; + colors.bright.green = "#72fb72"; + colors.bright.yellow = "#fbfb72"; + colors.bright.blue = "#7272fb"; + colors.bright.magenta = "#fb53fb"; + colors.bright.cyan = "#72fbfb"; + colors.bright.white = "#fbfbfb"; + draw_bold_text_with_bright_colors = true; + font.normal.family = "Clean"; + font.bold.family = "Clean"; + font.bold.style = "Regular"; + font.size = 10; + hints.enabled = [ + { + regex = "(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^\\u0000-\\u001F\\u007F-\\u009F<>\"\\s{-}\\^⟨⟩`]+"; + mouse.enabled = true; + post_processing = true; + action = "Select"; + } + ]; + key_bindings = [ + { key = "Up"; mods = "Shift|Control"; command = font-size "=14"; } + { key = "Up"; mods = "Control"; command = font-size "+1"; } + { key = "Down"; mods = "Control"; command = font-size "-1"; } + { key = "Down"; mods = "Shift|Control"; command = font-size "=0"; } + ]; + scrolling.multiplier = 8; + }; + config-file = pkgs.writeJSON "alacritty-tv.json" config; +in + +pkgs.symlinkJoin { + name = "alacritty-tv"; + paths = [ + (pkgs.writeDashBin "alacritty" '' + # usage: + # alacritty [--singleton] [ARGS...] + + set -efu + + # Use home so Alacritty can find the configuration without arguments. + # HOME will be reset once in Alacritty. + HOME=$TMPDIR/Alacritty + export HOME + + # Install stored configuration if it has changed. + # This allows for both declarative updates and runtime modifications. + ${pkgs.coreutils}/bin/mkdir -p "$HOME" + ref=$(${pkgs.coreutils}/bin/cat "$HOME"/ref) + if test "$ref" != ${config-file}; then + echo ${config-file} > "$HOME"/ref + ${pkgs.coreutils}/bin/cp ${config-file} "$HOME"/.alacritty.yml + fi + + case ''${1-} in + --singleton) + shift + if ! ${pkgs.alacritty}/bin/alacritty msg create-window "$@"; then + ${pkgs.alacritty}/bin/alacritty "$@" & + fi + ;; + *) + exec ${pkgs.alacritty}/bin/alacritty "$@" + ;; + esac + '') + pkgs.alacritty + ]; +} -- cgit v1.2.3 From fe01fe6bf411623582f8f21d5b8adb0e4729a7c1 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 9 Dec 2022 21:53:09 +0100 Subject: tv pinentry-urxvt: kill only screenshot displayers --- tv/5pkgs/simple/pinentry-urxvt/default.nix | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tv/5pkgs/simple') diff --git a/tv/5pkgs/simple/pinentry-urxvt/default.nix b/tv/5pkgs/simple/pinentry-urxvt/default.nix index c768a9f5..ad8039ff 100644 --- a/tv/5pkgs/simple/pinentry-urxvt/default.nix +++ b/tv/5pkgs/simple/pinentry-urxvt/default.nix @@ -52,25 +52,26 @@ in trap cleanup EXIT cleanup() { + ${pkgs.utillinux}/bin/kill -- $(${pkgs.coreutils}/bin/cat "$displayers") + rm "$displayers" rm "$screenshot" - # Kill process group in order to kill screenshot windows. - ${pkgs.utillinux}/bin/kill 0 } - screenshot=$(${pkgs.coreutils}/bin/mktemp -t pinentry-urxvt.screenshot.XXXXXXXX) + displayers=$(${pkgs.coreutils}/bin/mktemp -t pinentry-urxvt.$$.displayers.XXXXXXXX) + screenshot=$(${pkgs.coreutils}/bin/mktemp -t pinentry-urxvt.$$.screenshot.XXXXXXXX) ${pkgs.xorg.xwd}/bin/xwd -root | ${pkgs.imagemagick}/bin/convert xwd:- -fill \#424242 -colorize 80% xwd:"$screenshot" - show_screenshot() { - ${pkgs.exec "pinentry-urxvt.show_screenshot" { + display_screenshot() { + ${pkgs.exec "pinentry-urxvt.display_screenshot" { filename = "${pkgs.xorg.xwud}/bin/xwud"; argv = [ cfg.xwud.className "-noclick" ]; }} < "$screenshot" & - wait_for_screenshot $! + wait_for_screenshot $! && echo $! >>"$displayers" } # Wait for the xwud window by trying to intercept the call to munmap(). @@ -92,12 +93,12 @@ in fi } - show_screenshot + display_screenshot ${lib.optionalString (cfg.display != null) /* sh */ '' if test "$DISPLAY" != ${lib.shell.escape cfg.display}; then export DISPLAY=${lib.shell.escape cfg.display} - show_screenshot + display_screenshot fi ''} -- cgit v1.2.3