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: resurrecting-open-source-projects#272
  • Loading branch information
N-R-K committed May 25, 2023
1 parent 14ed018 commit f93a551
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 @@ -448,12 +448,9 @@ Window scrotGetWindow(Display *display, Window window, int x, int y)
void scrotGrabMousePointer(const 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 @@ -467,10 +464,8 @@ void scrotGrabMousePointer(const 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 @@ -482,8 +477,6 @@ void scrotGrabMousePointer(const Imlib_Image image, const int xOffset,
height);
imlib_context_set_image(imcursor);
imlib_free_image();

end:
XFree(xcim);
}

Expand Down

0 comments on commit f93a551

Please sign in to comment.