Skip to content

Commit

Permalink
scrotGrabMousePointer: error in case of failure
Browse files Browse the repository at this point in the history
if the user asks us to grab the pointer, we should either do that
otherwise fail rather than continuing on.

also remove a redundant comment, it should be clear that a function
named XFixesGetCursorImage is indeed returning back a cursor image.

ref: #272
  • Loading branch information
N-R-K committed May 30, 2023
1 parent c3bc2ba commit e0589e4
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/scrot.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,9 @@ Window scrotGetWindow(Display *display, Window window, int x, int y)
void scrotGrabMousePointer(Imlib_Image image, const int xOffset,
const int yOffset)
{
XFixesCursorImage *xcim = NULL;
/* Get the X cursor and the information we want. */
if ((xcim = XFixesGetCursorImage(disp)) == NULL) {
warnx("Can't get the cursor from X");
goto end;
}
XFixesCursorImage *xcim = XFixesGetCursorImage(disp);
if (!xcim)
errx(EXIT_FAILURE, "Can't get the cursor from X");
const unsigned short width = xcim->width;
const unsigned short height = xcim->height;
const size_t pixcnt = (size_t)width*height;
Expand All @@ -499,10 +496,8 @@ void scrotGrabMousePointer(Imlib_Image image, const int xOffset,
}

Imlib_Image imcursor = imlib_create_image_using_data(width, height, pixels);
if (!imcursor) {
warnx("Can't create cursor image");
goto end;
}
if (!imcursor)
errx(EXIT_FAILURE, "Can't create cursor image");

/* Overlay the cursor into `image`. */
const int x = (xcim->x - xcim->xhot) - xOffset;
Expand All @@ -514,8 +509,6 @@ void scrotGrabMousePointer(Imlib_Image image, const int xOffset,
height);
imlib_context_set_image(imcursor);
imlib_free_image();

end:
XFree(xcim);
}

Expand Down

0 comments on commit e0589e4

Please sign in to comment.