Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Fails when application has control over cursor #1

Closed
Brottweiler opened this issue Dec 17, 2013 · 9 comments
Closed

Fails when application has control over cursor #1

Brottweiler opened this issue Dec 17, 2013 · 9 comments
Labels

Comments

@Brottweiler
Copy link

This script works fine, except when the cursor is occupied by another application or similar.
Basically, when I have a game like Minecraft open, Minecraft is using the cursor. When I run this script from a hotkey, scrot(?) cannot get a hold of the cursor so it fails. The cursor has to be free, as if I were to pause the game.

Opening a terminal first makes minecraft loose focus and I get my cursor, which works, but I'd rather have it bind to a key.

Is there a way for the script to make what is having the mouse occupied to free the cursor? Or is there some other way I can fix this?

@jomo
Copy link
Owner

jomo commented Dec 17, 2013

It is indeed scrot which is unable to use the cursor for selection and exits with an error code.

Maybe xdotool could unfocus the currently active window?

Another option might be to free the mouse. I'm unsure how to do that that though.

For a dirty quick fix you could add a line before scrot to open (and close) a program that takes the focus.

@Brottweiler
Copy link
Author

  • Another option might be to free the mouse. I'm unsure how to do that that though.

That's exactly what I want to do. Minecraft specifically will bring up the pause screen when lost focus, which I have disabled in the config. So if the script can make the cursor loose focus from minecraft before it runs scrot -s it's solved.

@Brottweiler
Copy link
Author

I "solved" it. So, scrot has an -u, --focused option. I changed if ! scrot -s "$img" on line 27 to if ! scrot -u "$img" and it did exactly what I wanted. It took a screenshot of the window I had focused (that had control over the mouse) and uploaded it to imgur, and copied the link to my clipboard.

I went ahead and did a copy of imgur-screenshot.sh and named it imgur-screenshot-focus.sh and bound that to Alt + PrntScrn. I got the normal script bound to PrntScrn.

Problem is, I have to have 2 scripts. Is there a way to integrate this into the script? Can the script see if the mouse cursor is avaible? Maybe, if the scrot -s fails because another application has control over the cursor, it runs scrot -u instead?

Just a note: the scrot version I had (scrot 0.8-6) did not have this feature, so I installed scrot-patched 0.8-13 which had the feature and it works great.

@jomo
Copy link
Owner

jomo commented Jan 16, 2014

You can still do this:

if ! $(scrot -s); then
if ! $(scrot -u); then
// Error
fi
fi
// code

That will try to use -s and if that fails it will use -u. When that fails, too, we have an error.

@Brottweiler
Copy link
Author

Thanks! I ended up doing this and it worked like intended!

if ! scrot -s "$img" #takes a screenshot with selection
then
  if ! scrot -u "$img"
  then
  echo "Error for image '$img'! Try increasing the sleep time. For more information visit https://github.com/JonApps/imgur-screenshot#troubleshooting" >> "$log"
  echo "Something went wrong."
  notify-send -a ImgurScreenshot -u critical -c "im.error" -i "$ico" -t 500 "Something went wrong :(" "Information logged to $log"
  exit 1
  fi
fi

@jomo
Copy link
Owner

jomo commented Jan 16, 2014

👍
yup, that's what i meant. It will be an option in the next version to behave like this until the actual problem is fixed (untrapping the mouse)

@jomo
Copy link
Owner

jomo commented Jan 20, 2014

FYI: this is in the new version.
I'm leaving this issue open because it doesn't really fix it, it's just a workaround.

@Brottweiler
Copy link
Author

  if ! (scrot -s "$1" &>/dev/null || screencapture -s "$1" &>/dev/null); then #takes a screenshot with selection
    echo "Couldn't make selective shot (mouse trapped?). Tryinig to grab active window instead"
    if ! (scrot -s "$1" &>/dev/null || screencapture -oWa "$1" &>/dev/null); then
      echo "Error for image '$1'! For more information visit https://github.com/JonApps/imgur-screenshot#troubleshooting" >> "$log_file"
      echo "Something went wrong. Check the log."
      notify error "Something went wrong :(" "Information logged to $log_file"
      exit 1
    fi
  fi

Shouldn't the 3rd line say scrot -u and not scrot -s?

@jomo
Copy link
Owner

jomo commented Jan 20, 2014

It should. Was a bit tired when i pushed ;)
My phone won't let me edit it but i will fix asap.
Thanks

@jomo jomo closed this as completed in aff5f0b Apr 21, 2014
@ghost ghost mentioned this issue May 15, 2014
@jomo jomo mentioned this issue Dec 21, 2014
jomo added a commit that referenced this issue Apr 3, 2019
When true, will open the full screenshot in specified editor after a selective screenshot failed
That's all I can do, all other needs to be fixed by the scrot authors.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants