Windows and display screenshot doens't working with swappy in hyprland

Hi.

I checked the " /etc/skel/.config/hypr/hyprland.conf", I saw a new screenshot settings. I installed the missing package and copied the scripts and i want to try.

# Change to swappy https://github.com/jtheoof/swappy
# Old functions only commented out to make it easier for the user to change if necessary.

# Snip a selection and pipe to swappy
bind = ,Print, exec, grim -g "$(slurp)" - | swappy -f -
# Screenshot a window and pipe to swappy
bind = CTRL, Print, exec, .config/hypr/scripts/screenshot_window.sh
# Screenshot the current display and pipe to swappy
bind = SHIFT, Print, exec, .config/hypr/scripts/screenshot_display.sh

The the first is working fine, but the “screenshot a window” and “screenshot the current display” are not. I checked the scripts but i cant find what is wrong with it.

here is the script output:

./screenshot_display.sh 
jq: parse error: Invalid numeric literal at line 1, column 6
unknown output '-'
unable to load file: /tmp/swappy-stdin-XV0IJ2.png - reason: Image file “/tmp/swappy-stdin-XV0IJ2.png” contains no data

and

./screenshot_window.sh 
jq: parse error: Invalid numeric literal at line 1, column 6
selection cancelled
invalid geometry
unable to load file: /tmp/swappy-stdin-86FQJ2.png - reason: Image file “/tmp/swappy-stdin-86FQJ2.png” contains no data
[robi@vostro-garuda scripts]$ 

the “screenshot_windows.sh” working same like i press only the print screen button.

here is the 2 files:

#!/bin/bash
# .config/hypr/scripts/screenshot_display.sh
# Screenshot the current display Shift+Print

output_id=$(hyprctl -t get_outputs | jq -r '.[] | select(.focused).name')
grim -o $output_id - | swappy -f -
#!/bin/bash
# .config/hypr/scripts/screenshot_window.sh
# Screenshot a window Ctrl+Print

grim -g "$(hyprctl -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp)" - | swappy -f -

any suggestion?

Thank you.

inxi:

 ╰─λ garuda-inxi
System:
  Kernel: 6.6.18-1-lts arch: x86_64 bits: 64 compiler: gcc v: 13.2.1
    clocksource: tsc avail: acpi_pm
    parameters: BOOT_IMAGE=/@/boot/vmlinuz-linux-lts
    root=UUID=095c9f1d-4e23-42b2-aa42-36402880711e rw rootflags=subvol=@
    quiet resume=UUID=4b8a0d61-7df0-445b-9329-0c5cf2f2c346 loglevel=3 ibt=off
  Desktop: Hyprland v: 0.35.0-84-gf389f770 with: waybar tools: swayidle
    avail: swaylock vt: 1 dm: SDDM Distro: Garuda base: Arch Linux
Machine:
  Type: Laptop System: Dell product: Vostro 3580 v: N/A
    serial: <superuser required> Chassis: type: 10 serial: <superuser required>
  Mobo: Dell model: 0PMTCG v: A00 serial: <superuser required> part-nu: 08CB
    uuid: <superuser required> UEFI: Dell v: 1.27.0 date: 11/16/2023
Battery:
  ID-1: BAT0 charge: 29.3 Wh (100.0%) condition: 29.3/42.0 Wh (69.8%)
    volts: 12.6 min: 11.4 model: BYD DELL 1VX1H97 type: Li-ion serial: <filter>
    status: full
  Device-1: hidpp_battery_0 model: Logitech Wireless Keyboard
    serial: <filter> charge: 55% (should be ignored) rechargeable: yes
    status: discharging
CPU:
  Info: model: Intel Core i5-8265U bits: 64 type: MT MCP
    arch: Comet/Whiskey Lake note: check gen: core 8 level: v3 note: check
    built: 2018 process: Intel 14nm family: 6 model-id: 0x8E (142)
    stepping: 0xC (12) microcode: 0xF8
  Topology: cpus: 1x cores: 4 tpc: 2 threads: 8 smt: enabled cache:
    L1: 256 KiB desc: d-4x32 KiB; i-4x32 KiB L2: 1024 KiB desc: 4x256 KiB
    L3: 6 MiB desc: 1x6 MiB
  Speed (MHz): avg: 1600 high: 1601 min/max: 400/3900 scaling:
    driver: intel_pstate governor: performance cores: 1: 1600 2: 1600 3: 1601
    4: 1600 5: 1600 6: 1600 7: 1600 8: 1600 bogomips: 28808
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
  Vulnerabilities: <filter>
Graphics:
  Device-1: Intel WhiskeyLake-U GT2 [UHD Graphics 620] vendor: Dell
    driver: i915 v: kernel arch: Gen-9.5 process: Intel 14nm built: 2016-20
    ports: active: HDMI-A-1,eDP-1 empty: DP-1,HDMI-A-2 bus-ID: 00:02.0
    chip-ID: 8086:3ea0 class-ID: 0300
  Device-2: Sunplus Innovation Integrated_Webcam_HD driver: uvcvideo
    type: USB rev: 2.0 speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 1-6:3
    chip-ID: 1bcf:2b98 class-ID: 0e02
  Display: wayland server: X.org v: 1.21.1.11 with: Xwayland v: 23.2.4
    compositor: Hyprland v: 0.35.0-84-gf389f770 driver: X: loaded: modesetting
    alternate: fbdev,intel,vesa dri: iris gpu: i915 d-rect: 4480x1080
    display-ID: 1
  Monitor-1: HDMI-A-1 pos: right model: LG (GoldStar) ULTRAWIDE
    serial: <filter> built: 2014 res: 2560x1080 hz: 60 dpi: 112 gamma: 1.2
    scale: 1 size: 677x290mm (26.65x11.42") diag: 628mm (24.7") modes:
    max: 2560x1080 min: 720x400
  Monitor-2: eDP-1 pos: primary,left model: AU Optronics 0x38ed built: 2015
    res: 1920x1080 hz: 60 dpi: 142 gamma: 1.2 scale: 1
    size: 344x193mm (13.54x7.6") diag: 394mm (15.5") ratio: 16:9
    modes: 1920x1080
  API: Vulkan v: 1.3.276 layers: 3 device: 0 type: integrated-gpu name: Intel
    UHD Graphics 620 (WHL GT2) driver: mesa intel v: 24.0.1-arch1.1
    device-ID: 8086:3ea0 surfaces: xcb,xlib,wayland device: 1 type: cpu
    name: llvmpipe (LLVM 16.0.6 256 bits) driver: mesa llvmpipe
    v: 24.0.1-arch1.1 (LLVM 16.0.6) device-ID: 10005:0000
    surfaces: xcb,xlib,wayland
  API: EGL Message: EGL data requires eglinfo. Check --recommends.
Audio:
  Device-1: Intel Cannon Point-LP High Definition Audio vendor: Dell
    driver: snd_hda_intel v: kernel alternate: snd_soc_skl,snd_sof_pci_intel_cnl
    bus-ID: 00:1f.3 chip-ID: 8086:9dc8 class-ID: 0403
  API: ALSA v: k6.6.18-1-lts status: kernel-api tools: N/A
  Server-1: sndiod v: N/A status: off tools: aucat,midicat,sndioctl
  Server-2: PipeWire v: 1.0.3 status: active with: 1: pipewire-pulse
    status: active 2: wireplumber status: active 3: pipewire-alsa type: plugin
    4: pw-jack type: plugin tools: pactl,pw-cat,pw-cli,wpctl
Network:
  Device-1: Realtek RTL8111/8168/8211/8411 PCI Express Gigabit Ethernet
    vendor: Dell RTL8111/8168/8411 driver: r8169 v: kernel pcie: gen: 1
    speed: 2.5 GT/s lanes: 1 port: 3000 bus-ID: 01:00.0 chip-ID: 10ec:8168
    class-ID: 0200
  IF: enp1s0 state: down mac: <filter>
  Device-2: Qualcomm Atheros QCA9377 802.11ac Wireless Network Adapter
    vendor: Dell driver: ath10k_pci v: kernel pcie: gen: 1 speed: 2.5 GT/s
    lanes: 1 bus-ID: 02:00.0 chip-ID: 168c:0042 class-ID: 0280
  IF: wlp2s0 state: up mac: <filter>
  IF-ID-1: virbr0 state: down mac: <filter>
  IF-ID-2: wguk133t state: unknown speed: N/A duplex: N/A mac: N/A
  Info: services: NetworkManager, systemd-timesyncd, wpa_supplicant
Bluetooth:
  Device-1: Qualcomm Atheros driver: btusb v: 0.8 type: USB rev: 2.0
    speed: 12 Mb/s lanes: 1 mode: 1.1 bus-ID: 1-10:4 chip-ID: 0cf3:e009
    class-ID: e001
  Report: btmgmt ID: hci0 rfk-id: 0 state: up address: <filter> bt-v: 4.2
    lmp-v: 8 status: discoverable: no pairing: no class-ID: 6c010c
Drives:
  Local Storage: total: 1.36 TiB used: 571.5 GiB (41.0%)
  SMART Message: Required tool smartctl not installed. Check --recommends
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Toshiba
    model: KBG40ZNS256G NVMe 256GB size: 238.47 GiB block-size: physical: 512 B
    logical: 512 B speed: 31.6 Gb/s lanes: 4 tech: SSD serial: <filter>
    fw-rev: 10410106 temp: 23.9 C scheme: GPT
  ID-2: /dev/sda maj-min: 8:0 vendor: A-Data model: SU630 size: 223.57 GiB
    block-size: physical: 512 B logical: 512 B speed: 6.0 Gb/s tech: SSD
    serial: <filter> fw-rev: 3R17 scheme: GPT
  ID-3: /dev/sdb maj-min: 8:16 vendor: Samsung model: ST1000LM 024 HN-M101M
    size: 931.51 GiB block-size: physical: 4096 B logical: 512 B type: USB
    rev: 3.0 spd: 5 Gb/s lanes: 1 mode: 3.2 gen-1x1 tech: N/A serial: <filter>
    fw-rev: 2AR2 scheme: MBR
Partition:
  ID-1: / raw-size: 60 GiB size: 60 GiB (100.00%) used: 14.29 GiB (23.8%)
    fs: btrfs dev: /dev/nvme0n1p3 maj-min: 259:3
  ID-2: /boot/efi raw-size: 300 MiB size: 299.4 MiB (99.80%)
    used: 584 KiB (0.2%) fs: vfat dev: /dev/nvme0n1p2 maj-min: 259:2
  ID-3: /home raw-size: 162.16 GiB size: 162.16 GiB (100.00%)
    used: 6.97 GiB (4.3%) fs: btrfs dev: /dev/nvme0n1p4 maj-min: 259:4
  ID-4: /var/log raw-size: 60 GiB size: 60 GiB (100.00%)
    used: 14.29 GiB (23.8%) fs: btrfs dev: /dev/nvme0n1p3 maj-min: 259:3
  ID-5: /var/tmp raw-size: 60 GiB size: 60 GiB (100.00%)
    used: 14.29 GiB (23.8%) fs: btrfs dev: /dev/nvme0n1p3 maj-min: 259:3
Swap:
  Kernel: swappiness: 133 (default 60) cache-pressure: 100 (default) zswap: no
  ID-1: swap-1 type: partition size: 16.01 GiB used: 0 KiB (0.0%)
    priority: -2 dev: /dev/nvme0n1p5 maj-min: 259:5
  ID-2: swap-2 type: zram size: 7.63 GiB used: 955 MiB (12.2%) priority: 100
    comp: zstd avail: lzo,lzo-rle,lz4,lz4hc,842 max-streams: 8 dev: /dev/zram0
Sensors:
  System Temperatures: cpu: 62.0 C pch: 58.0 C mobo: 38.0 C
  Fan Speeds (rpm): cpu: 0
Info:
  Memory: total: 8 GiB available: 7.64 GiB used: 5.16 GiB (67.6%)
  Processes: 297 Power: uptime: 1d 14m states: freeze,mem,disk suspend: deep
    avail: s2idle wakeups: 8 hibernate: platform avail: shutdown, reboot,
    suspend, test_resume image: 3.04 GiB services: thermald,upowerd
    Init: systemd v: 255 default: graphical tool: systemctl
  Packages: pm: pacman pkgs: 1491 libs: 438 tools: octopi,pacseek,paru
    Compilers: gcc: 13.2.1 Shell: garuda-inxi default: fish v: 3.7.0
    running-in: foot inxi: 3.3.33
Garuda (2.6.23-1):
  System install date:     2024-01-21
  Last full system update: 2024-02-24 ↻
  Is partially upgraded:   No
  Relevant software:       snapper NetworkManager dracut
  Windows dual boot:       Probably (Run as root to verify)
  Failed units:            [email protected] 

hyprctl -j monitors
try to replace the above with this?

i replaced but now

./screenshot_window.sh 
jq: parse error: Invalid numeric literal at line 1, column 8
selection cancelled
invalid geometry
unable to load file: /tmp/swappy-stdin-WUWAJ2.png - reason: Image file “/tmp/swappy-stdin-WUWAJ2.png” contains no data

this above will give a same result as the print screen button…

./screenshot_display.sh 
jq: parse error: Invalid numeric literal at line 1, column 8
unknown output '-'
unable to load file: /tmp/swappy-stdin-Q3OEJ2.png - reason: Image file “/tmp/swappy-stdin-Q3OEJ2.png” contains no data
[robi@vostro-garuda scripts]$ 

strange you get the error. I get the initial message since the command being fed to hyprctl is not a real command.

#!/bin/bash
# .config/hypr/scripts/screenshot_display.sh
# Screenshot the current display Shift+Print

output_id=$(hyprctl -j monitors | jq -r '.[] | select(.focused).name')
grim -o $output_id | swappy -f -

Try this?

./screenshot_display.sh 
unable to load file: /tmp/swappy-stdin-BSDGJ2.png - reason: Image file “/tmp/swappy-stdin-BSDGJ2.png” contains no data

Welp I am out of ideas. :person_shrugging: Hopefully SGS or Ankur the one’s who likely wrote and maintain this can reply. :eyes:

Thanks, i will wait and try find solution.

I tried

 ╰─ hyprctl -j activewindow | jq '.at, .size'
[
  12,
  52
]
[
  1896,
  1016
]

didn’t know how to process it further, then I realised hey grimblast is much more straight forward. :grinning: