From bce7db5f8ded392d41fbeb4c3b31d77460e3c2ee Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 2 Sep 2022 20:28:50 +0200 Subject: [PATCH] added menu-qalc --- common.nix | 1 + flake.nix | 4 +- modules/desktop.nix | 88 +++++---------------------- scripts/desktop/desktop-ctl.sh | 21 +++++++ scripts/desktop/macros/play-loop.sh | 7 +++ scripts/desktop/macros/play.sh | 3 + scripts/desktop/macros/record.sh | 10 +++ scripts/desktop/menu-qalc.sh | 87 ++++++++++++++++++++++++++ scripts/desktop/ocr-screenshot.sh | 26 ++++++++ scripts/desktop/window-screenshot.sh | 8 +++ scripts/desktop/window_screenshot.nix | 1 - 11 files changed, 180 insertions(+), 76 deletions(-) create mode 100644 scripts/desktop/desktop-ctl.sh create mode 100644 scripts/desktop/macros/play-loop.sh create mode 100644 scripts/desktop/macros/play.sh create mode 100644 scripts/desktop/macros/record.sh create mode 100644 scripts/desktop/menu-qalc.sh create mode 100644 scripts/desktop/ocr-screenshot.sh create mode 100644 scripts/desktop/window-screenshot.sh delete mode 100644 scripts/desktop/window_screenshot.nix diff --git a/common.nix b/common.nix index bc3afe3..751303c 100644 --- a/common.nix +++ b/common.nix @@ -107,6 +107,7 @@ with builtins; fzf openrgb krita gimp inkscape blender virglrenderer ddccontrol-db glab firebird-emu discord + # experimental ]; environment.pathsToLink = [ diff --git a/flake.nix b/flake.nix index 4a3ed2d..b1c70d2 100644 --- a/flake.nix +++ b/flake.nix @@ -2,17 +2,15 @@ description = "home manager config apparently"; inputs = { - # nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small"; nixpkgs.url = "github:kekrby/nixpkgs/add-fetchpartial"; home-manager = { url = "github:nix-community/home-manager"; inputs.nixpks.follows = "nixpkgs"; }; nixos-hardware.url = "github:kekrby/nixos-hardware"; - # nixpkgs-fetchpartial.url = "github:kekrby/nixpkgs"; }; - outputs = { self, nixpkgs, home-manager, nixos-hardware, ... }: { + outputs = { self, nixpkgs, home-manager, nixos-hardware,... }: { nixosConfigurations = { monosodium-glutamate-g = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; diff --git a/modules/desktop.nix b/modules/desktop.nix index df0dcee..1baa5d0 100644 --- a/modules/desktop.nix +++ b/modules/desktop.nix @@ -2,71 +2,14 @@ let cfg = config.jade.desktop; - # Screenshot scripts {{{ - window-screenshot = pkgs.writeShellScriptBin "window-screenshot.sh" '' - unset x y w h - eval $(xwininfo -id $(xdotool getactivewindow) | - sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \ - -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \ - -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \ - -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" ) - echo -n "''$x ''$y ''$w ''$h" - flameshot gui --region "''${w}x''${h}+''${x}+''${y}" -c -p ~/Pictures/screenshots/ - ''; - # }}} - # Desktop ctl {{{ - desktop-ctl = pkgs.writeShellScriptBin "desktop-ctl.sh" '' - items="lock screen;log out;toggle picom;shut down;reboot;update all" - - selection=$(echo $items | rofi -sep ";" -dmenu) - - case $selection in - "lock screen") - i3lock-fancy - ;; - "log out") - pkill i3 - ;; - "toggle picom") - pkill picom || picom --experimental-backend -b - ;; - "shut down") - shutdown now - ;; - "reboot") - systemctl reboot - ;; - esac - ''; - # }}} - # Macro scripts {{{ - em-record = pkgs.writeShellScriptBin "em-record.sh" '' - register=$(ls $HOME/xmacros | rofi -dmenu) - count=$(echo "2;5;10;20;50;100" | rofi -dmenu -sep ";" -l 5) - - for i in $(seq $count); do - echo $i - xmacroplay "$DISPLAY" < $HOME/xmacros/$register - done - register=$(ls $HOME/xmacros | rofi -dmenu) - - xmacrorec2 > $HOME/xmacros/$register - ''; - em-play = pkgs.writeShellScriptBin "em-play.sh" '' - register=$(ls $HOME/xmacros | rofi -dmenu) - - xmacroplay "$DISPLAY" < $HOME/xmacros/$register - ''; - em-play-loop = pkgs.writeShellScriptBin "em-play-loop.sh" '' - register=$(ls $HOME/xmacros | rofi -dmenu) - count=$(echo "2;5;10;20;50;100" | rofi -dmenu -sep ";" -l 5) - - for i in $(seq $count); do - echo $i - xmacroplay "$DISPLAY" < $HOME/xmacros/$register - done - ''; - # }}} + window-screenshot = pkgs.writeShellScriptBin "window-screenshot.sh" (builtins.readFile ../scripts/desktop/window-screenshot.sh); + desktop-ctl = pkgs.writeShellScriptBin "desktop-ctl.sh" (builtins.readFile ../scripts/desktop/desktop-ctl.sh); + em-record = pkgs.writeShellScriptBin "em-record.sh" (builtins.readFile ../scripts/desktop/macros/record.sh); + em-play = pkgs.writeShellScriptBin "em-play.sh" (builtins.readFile ../scripts/desktop/macros/play.sh); + em-play-loop = pkgs.writeShellScriptBin "em-play-loop.sh" (builtins.readFile ../scripts/desktop/macros/play-loop.sh); + ocr-screenshot = pkgs.writeShellScriptBin "ocr-screenshot.sh" (builtins.readFile ../scripts/desktop/ocr-screenshot.sh); + # rofi calculator copied from https://github.com/barbuk/menu-qalc + menu-qalc = pkgs.writeShellScriptBin "menu-qalc" (builtins.readFile ../scripts/desktop/menu-qalc.sh); in with lib; { options.jade.desktop = { enable = mkEnableOption "Enable the i3 setup"; @@ -79,12 +22,13 @@ in with lib; { i3lock-fancy rofi rofimoji volumeicon feh xorg.xinput dunst arandr lxappearance gruvbox-dark-gtk gruvbox-dark-icons-gtk gruvterial-theme flameshot tesseract5 imagemagick xclip polybar kitty - xkeysnail gtk-engine-murrine playerctl xmacro + xkeysnail gtk-engine-murrine playerctl xmacro pa_applet brightnessctl + libqalculate # needed by menu-qalc # custom scripts - window-screenshot desktop-ctl em-record em-play em-play-loop - pa_applet - brightnessctl gruvbox-dark-icons-gtk - gruvbox-dark-gtk + window-screenshot desktop-ctl em-record em-play em-play-loop ocr-screenshot menu-qalc + + # themes + gruvbox-dark-gtk gruvbox-dark-icons-gtk ]; # i3 {{{ xsession = { @@ -162,13 +106,13 @@ in with lib; { "${mod}+w" = "exec window-screenshot.sh"; "${mod}+s" = "exec flameshot gui -c -p $HOME/Pictures/screenshots"; "${mod}+a" = "exec flameshot screen -c -p $HOME/Pictures/screenshots"; + "${mod}+t" = "exec ocr-screenshot.sh"; # rofi fuckery "${mod}+d" = "exec --no-startup-id rofi -show drun"; "${mod}+space" = "exec --no-startup-id -show window"; "${mod}+i" = "exec --no-startup-id rofimoji -f alchemical_symbols emojis braille_patterns box_drawing chess_symbols emoticons geometric_shapes gothic greek_extended math mathematical_alphanumeric_symbols mathematical_operators miscellaneous_symbols miscellaneous_mathematical_symbols-a miscellaneous_mathematical_symbols-b miscellaneous_symbols_and_arrows miscellaneous_symbols_and_pictographs miscellaneous_technical modi modifier_tone_letters musical_symbols nerd_font number_forms shorthand_format_controls specials variation_selectors vertical_forms -a copy"; "${mod}+Shift+e" = "exec --no-startup-id desktop-ctl.sh"; - # rofi calculator, https://github.com/barbuk/menu-qalc - # "${mod}+m" = "exec --no-startup-id =" + "${mod}+m" = "exec --no-startup-id menu-qalc"; # audio "XF86AudioRaiseVolume" = "exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +10% && $refresh_i3status"; diff --git a/scripts/desktop/desktop-ctl.sh b/scripts/desktop/desktop-ctl.sh new file mode 100644 index 0000000..34d72be --- /dev/null +++ b/scripts/desktop/desktop-ctl.sh @@ -0,0 +1,21 @@ +items="lock screen;log out;toggle picom;shut down;reboot;update all" + +selection=$(echo $items | rofi -sep ";" -dmenu) + +case $selection in + "lock screen") + i3lock-fancy + ;; + "log out") + pkill i3 + ;; + "toggle picom") + pkill picom || picom --experimental-backend -b + ;; + "shut down") + shutdown now + ;; + "reboot") + systemctl reboot + ;; +esac diff --git a/scripts/desktop/macros/play-loop.sh b/scripts/desktop/macros/play-loop.sh new file mode 100644 index 0000000..d5b23c7 --- /dev/null +++ b/scripts/desktop/macros/play-loop.sh @@ -0,0 +1,7 @@ +register=$(ls $HOME/xmacros | rofi -dmenu) +count=$(echo "2;5;10;20;50;100" | rofi -dmenu -sep ";" -l 5) + +for i in $(seq $count); do + echo $i + xmacroplay "$DISPLAY" < $HOME/xmacros/$register +done diff --git a/scripts/desktop/macros/play.sh b/scripts/desktop/macros/play.sh new file mode 100644 index 0000000..6063fef --- /dev/null +++ b/scripts/desktop/macros/play.sh @@ -0,0 +1,3 @@ +register=$(ls $HOME/xmacros | rofi -dmenu) + +xmacroplay "$DISPLAY" < $HOME/xmacros/$register diff --git a/scripts/desktop/macros/record.sh b/scripts/desktop/macros/record.sh new file mode 100644 index 0000000..082f0cc --- /dev/null +++ b/scripts/desktop/macros/record.sh @@ -0,0 +1,10 @@ +register=$(ls $HOME/xmacros | rofi -dmenu) +count=$(echo "2;5;10;20;50;100" | rofi -dmenu -sep ";" -l 5) + +for i in $(seq $count); do + echo $i + xmacroplay "$DISPLAY" < $HOME/xmacros/$register +done +register=$(ls $HOME/xmacros | rofi -dmenu) + +xmacrorec2 > $HOME/xmacros/$register diff --git a/scripts/desktop/menu-qalc.sh b/scripts/desktop/menu-qalc.sh new file mode 100644 index 0000000..ae6c153 --- /dev/null +++ b/scripts/desktop/menu-qalc.sh @@ -0,0 +1,87 @@ +# Copy-pasted from https://raw.githubusercontent.com/BarbUk/menu-qalc/master/%3D +# I hope this is even legal but OH WELL + +# https://github.com/onespaceman/menu-calc +# Calculator for use with rofi/dmenu(2) +# Copying to the clipboard requires xclip + +usage() { + echo "$(tput bold)menu-calc$(tput sgr0)" + echo "A calculator for Rofi/dmenu(2)" + echo + echo "$(tput bold)Usage:$(tput sgr0)" + echo " = 4+2" + echo " = (4+2)/(4+3)" + echo " = 4^2" + echo " = sqrt(4)" + echo " = c(2)" + echo + echo "$(tput bold)Force Rofi/dmenu(2):$(tput sgr0)" + echo "By default, if rofi exists, it will be used. To force menu-calc to" + echo "use one or the other, use the --dmenu argument" + echo + echo " = --dmenu=" + echo + echo "$(tput bold)Passing arguments to Rofi/dmenu(2):$(tput sgr0)" + echo "Any parameters after ' -- ' will be passed to Rofi/dmenu(2)." + echo + echo " = -- " + echo + echo "The answer can be copied to the clipboard and used for further calculations inside (or outside) Rofi/dmenu." + echo + echo "If launched outside of Rofi/dmenu the expression may need quotation marks." + exit +} + +# Process CLI parameters +for var in "$@" +do + case $var in + -h|--help) usage ;; + -d=*|--dmenu=*) + menu=$(echo $var | cut -d'=' -f 2); + ;; + --) break ;; + esac +done + +# Grab the answer +if [ -n "$1" ]; then + answer=$(echo "$1" | qalc +u8 -color=never -terse | awk '!/^>/ && !/^$/ {gsub(/^[ \t]+|[ \t]+$/, "", $0); print}') +fi + +# Path to menu application +if [ -z "${menu+1}" ]; then + if [[ -n $(command -v rofi) ]]; then + menu="$(command -v rofi)" + elif [[ -n $(command -v dmenu) ]]; then + menu=$(command -v dmenu) + else + >&2 echo "Rofi or dmenu not found" + exit + fi +fi + +# If using rofi, add the necessary parameters +if [[ $menu == "rofi" || $menu == $(command -v rofi) ]]; then + menu="$menu -dmenu -lines 3" +elif [[ $menu == "dmenu" || $menu == $(command -v dmenu) ]]; then + menu="$menu ""$DMENU_OPTIONS" +fi + +# Determine args to pass to dmenu/rofi +while [[ $# -gt 0 && $1 != "--" ]]; do + shift +done +[[ $1 == "--" ]] && shift + +action=$(echo -e "Copy to clipboard\nClear\nClose" | $menu "$@" -p "= $answer") + +case $action in + "Clear") $0 ;; + "Copy to clipboard") echo -n "$answer" | xclip -selection clipboard ;; + "Close") ;; + "") ;; + *) $0 "$answer $action" "--dmenu=$menu" "--" "$@" ;; +esac + diff --git a/scripts/desktop/ocr-screenshot.sh b/scripts/desktop/ocr-screenshot.sh new file mode 100644 index 0000000..cd5b4fe --- /dev/null +++ b/scripts/desktop/ocr-screenshot.sh @@ -0,0 +1,26 @@ +langs="eng deu spa osd" +langs=$(tesseract --list-langs | tail +2) +first_menu="$langs exit" +selection_menu1=$(echo $first_menu | rofi -sep " " -dmenu) + +tmp_img=`mktemp` +trap "rm $tmp_img*" EXIT + + +echo $selection_menu1 + +case $selection_menu1 in + "eng"|"deu"|"spa"|"osd"|"fra") + tesseract_lang=$selection_menu1 + flameshot gui -p $tmp_img.png -d 100 + mogrify -modulate 100,0 -resize 400% $tmp_img.png + ;; + "exit") + exit + ;; +esac + +tesseract $tmp_img.png $tmp_img &> /dev/null +xclip -i $tmp_img.txt -selection clipboard +exit + diff --git a/scripts/desktop/window-screenshot.sh b/scripts/desktop/window-screenshot.sh new file mode 100644 index 0000000..b337a26 --- /dev/null +++ b/scripts/desktop/window-screenshot.sh @@ -0,0 +1,8 @@ +unset x y w h +eval $(xwininfo -id $(xdotool getactivewindow) | + sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/x=\1/p" \ + -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/y=\1/p" \ + -e "s/^ \+Width: \+\([0-9]\+\).*/w=\1/p" \ + -e "s/^ \+Height: \+\([0-9]\+\).*/h=\1/p" ) +echo -n "''$x ''$y ''$w ''$h" +flameshot gui --region "''${w}x''${h}+''${x}+''${y}" -c -p ~/Pictures/screenshots/ diff --git a/scripts/desktop/window_screenshot.nix b/scripts/desktop/window_screenshot.nix deleted file mode 100644 index d59b422..0000000 --- a/scripts/desktop/window_screenshot.nix +++ /dev/null @@ -1 +0,0 @@ -with import {};