diff options
| -rw-r--r-- | flake.lock | 24 | ||||
| -rw-r--r-- | modules/scripts/default.nix | 2 | ||||
| -rw-r--r-- | modules/scripts/screen-recording.sh | 85 | ||||
| -rw-r--r-- | modules/tools/default.nix | 1 | ||||
| -rw-r--r-- | modules/tools/slop/default.nix | 18 | ||||
| -rw-r--r-- | users/arpit.nix | 1 |
6 files changed, 104 insertions, 27 deletions
@@ -99,11 +99,11 @@ ] }, "locked": { - "lastModified": 1774379316, - "narHash": "sha256-0nGNxWDUH2Hzlj/R3Zf4FEK6fsFNB/dvewuboSRZqiI=", + "lastModified": 1774898676, + "narHash": "sha256-0Utnqo+FbB+0CVUi0MI3oonF0Kuzy9VcgRkxl53Euvk=", "owner": "nix-community", "repo": "home-manager", - "rev": "1eb0549a1ab3fe3f5acf86668249be15fa0e64f7", + "rev": "a184bd2f8426087bae93f203403cd4b86c99e57d", "type": "github" }, "original": { @@ -115,11 +115,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1774106199, - "narHash": "sha256-US5Tda2sKmjrg2lNHQL3jRQ6p96cgfWh3J1QBliQ8Ws=", + "lastModified": 1774709303, + "narHash": "sha256-D3Q07BbIA2KnTcSXIqqu9P586uWxN74zNoCH3h2ESHg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "6c9a78c09ff4d6c21d0319114873508a6ec01655", + "rev": "8110df5ad7abf5d4c0f6fb0f8f978390e77f9685", "type": "github" }, "original": { @@ -168,11 +168,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1774309640, - "narHash": "sha256-8oWL7YLwElBY9ebYri1LlSlhf/gd1Qoqj0nbBwG2yso=", + "lastModified": 1774802402, + "narHash": "sha256-L1UJ/zxKTyyaGGmytH6OYlgQ0HGSMhvPkvU+iz4Mkb8=", "owner": "nix-community", "repo": "nixvim", - "rev": "28c58bf023bf537354f78d6e496a349d7a0ed554", + "rev": "cbd8536a05d1aae2593cb5c9ace1010c8c5845cb", "type": "github" }, "original": { @@ -188,11 +188,11 @@ "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1774104215, - "narHash": "sha256-EAtviqz0sEAxdHS4crqu7JGR5oI3BwaqG0mw7CmXkO8=", + "lastModified": 1774861927, + "narHash": "sha256-FB1fbeJQjaTMI2JFAa0LNMaYXiShiYbJA6puGQC4xdg=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "f799ae951fde0627157f40aec28dec27b22076d0", + "rev": "9c4469b68b62e122c3b3d2ab0ed3caeb04ff1ac4", "type": "github" }, "original": { diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix index 734243f..ca555c7 100644 --- a/modules/scripts/default.nix +++ b/modules/scripts/default.nix @@ -24,7 +24,7 @@ in { "scripts/deep-clean" = shellScript ./deep-clean.sh; - "scripts/screen-recording" = lib.mkIf config.tools.ffmpeg.enable ( + "scripts/screen-recording" = lib.mkIf (config.tools.ffmpeg.enable && config.tools.slop.enable) ( shellScript ./screen-recording.sh ); "scripts/system-monitor" = lib.mkIf ( diff --git a/modules/scripts/screen-recording.sh b/modules/scripts/screen-recording.sh index a5968a1..374e2cb 100644 --- a/modules/scripts/screen-recording.sh +++ b/modules/scripts/screen-recording.sh @@ -1,18 +1,75 @@ -PID_FILE="/tmp/ffmpeg-screenrecord.pid" OUT_DIR="$HOME/Videos/Recordings" +mkdir -p "$OUT_DIR" -if [ -f "$PID_FILE" ]; then - kill -INT "$(cat "$PID_FILE")" && rm "$PID_FILE" - echo "Stopping screen recording" +# Colors +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +NC='\033[0m' + +# --- 1. ARGUMENT PARSING --- +SELECT_MODE=false +while [[ "$#" -gt 0 ]]; do + case $1 in + -s|--select) SELECT_MODE=true ;; + esac + shift +done + +# --- 2. GEOMETRY SELECTION --- +# Attempt to get screen resolution using xwininfo, fallback to a safe default if it fails +if command -v xwininfo >/dev/null 2>&1; then + WIDTH=$(xwininfo -root | grep 'Width:' | awk '{print $2}') + HEIGHT=$(xwininfo -root | grep 'Height:' | awk '{print $2}') else - mkdir -p "$OUT_DIR" - echo "Starting screen recording" - ffmpeg \ - -f x11grab \ - -i "$DISPLAY" \ - -framerate 30 \ - -c:v libx264 \ - -preset ultrafast \ - -crf 23 \ - "$OUT_DIR/recording-$(date +%Y%m%d-%H%M%S).mp4" + # Fallback: Try to use a common default or let ffmpeg handle it + # If xwininfo is missing, we'll just omit -video_size for full screen + WIDTH="" + HEIGHT="" +fi + +X_OFF=0 +Y_OFF=0 + +if [ "$SELECT_MODE" = true ]; then + if command -v slop >/dev/null 2>&1; then + echo -e "${YELLOW}Select a window or draw a box...${NC}" + read -r WIDTH HEIGHT X_OFF Y_OFF < <(slop -f "%w %h %x %y" --nokeyboard) + [ -z "$WIDTH" ] && exit 1 + else + echo -e "${RED}Error: 'slop' is not installed. Cannot select area.${NC}" + echo "Defaulting to full screen..." + sleep 1 + fi fi + +# Construct the video size argument only if we have values +SIZE_ARG="" +if [ -n "$WIDTH" ] && [ -n "$HEIGHT" ]; then + # Ensure even dimensions + WIDTH=$(( WIDTH + WIDTH % 2 )) + HEIGHT=$(( HEIGHT + HEIGHT % 2 )) + SIZE_ARG="-video_size ${WIDTH}x${HEIGHT}" +fi + +# --- 3. START RECORDING --- +FILENAME="$OUT_DIR/recording-$(date +%Y%m%d-%H%M%S).mp4" + +echo -e "${GREEN}Recording started!${NC}" +echo -e "Press ${YELLOW}'q'${NC} in this terminal to stop." +echo "File: $FILENAME" +echo "------------------------------------------------" + +# Using ${DISPLAY:-:0} to ensure we have a display target +ffmpeg -hide_banner \ + -f x11grab \ + $SIZE_ARG \ + -framerate 30 \ + -i "${DISPLAY:-:0.0}+${X_OFF},${Y_OFF}" \ + -c:v libx264 \ + -preset ultrafast \ + -crf 23 \ + -pix_fmt yuv420p \ + "$FILENAME" + +echo -e "\n${GREEN}Done!${NC} Video saved to $FILENAME" diff --git a/modules/tools/default.nix b/modules/tools/default.nix index 5080743..deabe2f 100644 --- a/modules/tools/default.nix +++ b/modules/tools/default.nix @@ -29,6 +29,7 @@ ./pamixer ./playerctl ./rofi + ./slop ./starship ./systemctl-tui ./tmux diff --git a/modules/tools/slop/default.nix b/modules/tools/slop/default.nix new file mode 100644 index 0000000..3196251 --- /dev/null +++ b/modules/tools/slop/default.nix @@ -0,0 +1,18 @@ +{ + config, + lib, + pkgs, + ... +}: + +{ + options.tools.slop = { + enable = lib.mkEnableOption "Enables slop."; + }; + + config = lib.mkIf config.tools.slop.enable { + home.packages = with pkgs; [ + slop + ]; + }; +} diff --git a/users/arpit.nix b/users/arpit.nix index 2be735c..95c2542 100644 --- a/users/arpit.nix +++ b/users/arpit.nix @@ -40,6 +40,7 @@ tools.pamixer.enable = true; tools.playerctl.enable = true; tools.rofi.enable = true; + tools.slop.enable = true; tools.starship.enable = true; tools.systemctl-tui.enable = true; tools.tmux.enable = true; |
