naelstrof / maim

maim (make image) takes screenshots of your desktop. It has options to take only a region, and relies on slop to query for regions. maim is supposed to be an improved scrot.
Other
2.15k stars 78 forks source link

Is there a way to capture menus, popups, etc. when using `--select`? #254

Open adam-nielsen opened 2 years ago

adam-nielsen commented 2 years ago

Is there a way to use --select but not have windows lose focus? It appears to be impossible to take a screenshot of menus, drop-down boxes, or other UI elements that hide themselves once they lose focus.

Screenshots can be taken without --select and these elements captured, but the image must be cropped manually afterwards. It would be great if these sorts of screenshots could also be captured when --select is in use.

I'm not sure how you'd accomplish it though, other than taking a full-screen screenshot and then having the selection box drawn over that temporary screenshot instead of the actual display.

foxpy commented 2 years ago

TL;DR: To be honest, I don't think there could be a nice solution for Xorg. If you know a screenshot application which doesn't have this issue, please let me know.

Long answer: there are various options to fix this, but each one is ugly.

  1. it is possible to freeze X server before taking screenshot, however, this could make some applications misbehave (e.g. Firefox stops playing audio from its video frame) because we are essentially pausing X server and making all applications wait. And, at the same time, this method doesn't give any guarantees, because we have to spawn our own X client first before freezing X server, and spawning a client may mess with popup window/context menu/etc.
  2. it is possible to take a screenshot, pop it up in a fullscreen window (maybe it would be fullscreened on every monitor, too), but this is slow (we need to spawn a window and wait until it fills whole display).
  3. maybe it is possible to write a screenshot daemon which is always ready to perform approach 2 fast enough, but this would be a different application.
alvv-z commented 2 years ago

A workaround might be to take a full screenshot and then crop it to the desired region (via ImageMagick + slop or something similar). Still has its drawbacks, like not being able to see the menu once you click, but I think it would be the simplest option.

0Karakurt0 commented 1 year ago

I'm working on it right now, but there seems to be an issue in maim itself (#265)

Here's an almost working example (works with scrot, and in the same situation on wayland with grim)

{ cat ~/pipe.tmp |\
  tee ~/Images/Screenshots/$(date +%F_%T).png |\
  xclip -selection clipboard -t image/png
} &
maim -u | feh -F -                      &
background=$!
maim -s -k - > ~/pipe.tmp               &
selectoin=$!
wait $selectoin
kill $background

Ofc, you need to set up named pipe yourself

0Karakurt0 commented 1 year ago
  1. it is possible to freeze X server before taking screenshot

That sounds interesting.... Doesn't scrot use this feature for it's --freeze option?

I'll take a look, but I'm not hopeful to understand

0Karakurt0 commented 1 year ago

I seem to be correct https://github.com/resurrecting-open-source-projects/scrot/blob/fdaedca7d44b388f3204856fed0720116d5087d0/src/selection_classic.c#L83

foxpy commented 1 year ago
  1. it is possible to freeze X server before taking screenshot

That sounds interesting.... Doesn't scrot use this feature for it's --freeze option?

It does, and if we want to have this functionality to maim, it should probably be implemented in slop.

I have tried freezing X11 server from maim before calling slop, and that actually made slop fail.

foxpy commented 1 year ago

It does, and if we want to have this functionality to maim, it should probably be implemented in slop.

Actually, if someone wants to try patching maim to freeze screen before taking screenshot, I suggest trying it this way.

Maybe I will try that myself later, when I have more free time, but no guarantees!

Dich0tomy commented 1 year ago

Windows' Win+Shift+S somehow doesnt freeze anything except the image that was on the screen at the point of invoking that shortcut and then lets one capture that, isn't it possible to make some kind of overlays with max Z level on linux?

Dich0tomy commented 1 year ago

So I found out that spectacle can do that https://github.com/KDE/spectacle

0Karakurt0 commented 1 year ago

except the image that was on the screen

This is exactly what we where talking about, and what scrot is using