@@ -398,42 +398,50 @@ Window scrotGetWindow(Display *display, Window window, int x, int y)
398
398
return target ;
399
399
}
400
400
401
-
402
401
void scrotGrabMousePointer (const Imlib_Image image , const int xOffset ,
403
402
const int yOffset )
404
403
{
405
- XFixesCursorImage * xcim = XFixesGetCursorImage (disp );
406
-
407
- if (!xcim ) {
408
- warnx ("Failed to get mouse cursor image." );
409
- return ;
404
+ XFixesCursorImage * xcim = NULL ;
405
+ uint32_t * pixels = NULL ;
406
+ /* Get the X cursor and the information we want. */
407
+ if ((xcim = XFixesGetCursorImage (disp )) == NULL ) {
408
+ warnx ("Can't get the cursor from X" );
409
+ goto end ;
410
410
}
411
-
412
411
const unsigned short width = xcim -> width ;
413
412
const unsigned short height = xcim -> height ;
414
- const int x = (xcim -> x - xcim -> xhot ) - xOffset ;
415
- const int y = (xcim -> y - xcim -> yhot ) - yOffset ;
416
- DATA32 data [width * height ];
417
-
418
- for (size_t i = 0 ; i < width * height ; i ++ )
419
- data [i ] = xcim -> pixels [i ];
420
-
421
- Imlib_Image imcursor = imlib_create_image_using_data (width , height , data );
413
+ const size_t pixcnt = (size_t )width * height ;
422
414
423
- XFree (xcim );
415
+ /* xcim->pixels wouldn't be valid if sizeof(*pixels)*pixcnt wrapped around.
416
+ */
417
+ if ((pixels = malloc (sizeof (* pixels )* pixcnt )) == NULL ) {
418
+ warn ("malloc()" );
419
+ goto end ;
420
+ }
424
421
422
+ /* Convert an X cursor into the format imlib wants. */
423
+ for (size_t i = 0 ; i < pixcnt ; i ++ )
424
+ pixels [i ] = xcim -> pixels [i ];
425
+ Imlib_Image imcursor = imlib_create_image_using_data (width , height , pixels );
425
426
if (!imcursor ) {
426
- errx ( EXIT_FAILURE ,
427
- "scrotGrabMousePointer: Failed create image using data." ) ;
427
+ warnx ( "Can't create cursor image" );
428
+ goto end ;
428
429
}
429
430
431
+ /* Overlay the cursor into `image`. */
432
+ const int x = (xcim -> x - xcim -> xhot ) - xOffset ;
433
+ const int y = (xcim -> y - xcim -> yhot ) - yOffset ;
430
434
imlib_context_set_image (imcursor );
431
435
imlib_image_set_has_alpha (1 );
432
436
imlib_context_set_image (image );
433
437
imlib_blend_image_onto_image (imcursor , 0 , 0 , 0 , width , height , x , y , width ,
434
438
height );
435
439
imlib_context_set_image (imcursor );
436
440
imlib_free_image ();
441
+
442
+ end :
443
+ free (pixels );
444
+ XFree (xcim );
437
445
}
438
446
439
447
// It assumes that the local variable 'scrot.c:Imlib_Image image' is in context
0 commit comments