Skip to content

DinkyTrady/myshot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

myshot

A minimal Wayland screenshot tool with a true screen freeze built from scratch in C.

No swaybg, no swaylock, no wayfreeze, no grim for the freeze — pure Wayland protocol code.

How it works

Two components:

File Role
myfreeze.c C program: captures screen + displays frozen overlay
myshot.sh Shell script: drives the freeze + runs slurp/grim

Freeze mechanism (myfreeze)

  1. Connects to Wayland and binds all required protocols
  2. Queries the output's fractional scale via wp-fractional-scale-v1
  3. Captures the screen directly using zwlr_screencopy_frame_v1 into a wl_shm buffer backed by a memfd — no temp file, no grim
  4. Creates a zwlr_layer_surface_v1 on the OVERLAY layer stretched fullscreen
  5. Attaches a wp_viewport and sets destination = logical output size so the buffer maps 1:1 to physical pixels — pixel-perfect on HiDPI/fractional scaled displays
  6. Sets an empty input region so pointer/keyboard events pass through to slurp
  7. Registers a wl_surface.frame callback — waits until the compositor has actually rendered the frame (no blind sleep)
  8. Prints its PID to stdout so the shell knows the freeze is on screen
  9. Blocks on stdin — shell closes the pipe to unfreeze
  10. On unfreeze: destroys the layer surface, commits a null surface, two roundtrips so the compositor fully redraws the real desktop, exits

Screenshot flow (myshot.sh)

myfreeze (capture + freeze) -> slurp (select region) -> unfreeze -> grim (capture region)

Protocols used

Protocol Source Purpose
zwlr-screencopy-v1 wlr-protocols Capture screen content directly
zwlr-layer-shell-v1 wlr-protocols Fullscreen overlay surface
wp-fractional-scale-v1 wayland-protocols/staging Get exact HiDPI scale factor
wp-viewporter wayland-protocols/stable Pixel-perfect buffer-to-screen mapping
xdg-shell wayland-protocols/stable Required by wlr-layer-shell

Dependencies

Package Purpose
grim Area/fullscreen screenshot after selection
slurp Interactive region selector
wl-clipboard wl-copy for clipboard
wayland-client Wayland protocol library
wlr-protocols zwlr-screencopy + zwlr-layer-shell XMLs
wayland-protocols fractional-scale + viewporter + xdg-shell XMLs
wayland-scanner Generates C glue from protocol XMLs
notify-send Desktop notifications (libnotify)

Install dependencies (Arch)

sudo pacman -S wayland wayland-protocols wayland-utils grim slurp wl-clipboard
yay -S wlr-protocols

Build

make

This will:

  1. Auto-detect all protocol XML paths on your system using find
  2. Run wayland-scanner to generate C glue for all 5 protocols
  3. Compile myfreeze (only dependency: wayland-client)

One-command build + install

make autoinstall

Installs:

  • myfreeze~/.local/bin/myfreeze
  • myshot.sh~/.local/bin/myshot

One-command clean + uninstall

make autoclean

Other targets

make install    # install without rebuilding
make uninstall  # remove from ~/.local/bin/
make clean      # remove binary + generated protocol files

Usage

myshot          # fullscreen screenshot, save to ~/Pictures/ + copy to clipboard
myshot -c       # fullscreen, clipboard only
myshot -a       # area select, save to ~/Pictures/ + copy to clipboard
myshot -a -c    # area select, clipboard only

Output files are saved as ~/Pictures/Shot_YYYYMMDD_HHMMSS.png.

Keybind (mangoWC)

Add to your mangoWC config:

bind = SUPER SHIFT, p, exec, myshot -a
bind = SUPER SHIFT, s, exec, myshot

File structure

.
├── myfreeze.c    # screen capture + freeze overlay (C, Wayland native)
├── myshot.sh     # screenshot orchestration script (bash)
├── Makefile      # build system
└── README.md     # this file

The following files are generated by make and not tracked by git:

wlr-screencopy-unstable-v1-client-protocol.h
wlr-screencopy-unstable-v1-client-protocol.c
wlr-layer-shell-unstable-v1-client-protocol.h
wlr-layer-shell-unstable-v1-client-protocol.c
fractional-scale-v1-client-protocol.h
fractional-scale-v1-client-protocol.c
viewporter-client-protocol.h
viewporter-client-protocol.c
xdg-shell-client-protocol.h
xdg-shell-client-protocol.c
myfreeze

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors