ExcCode screen_cursor_blend(int x, int y, Imlib_Image image) { xcb_xfixes_get_cursor_image_cookie_t cookie = xcb_xfixes_get_cursor_image(display); xcb_xfixes_get_cursor_image_reply_t *reply = xcb_xfixes_get_cursor_image_reply(display, cookie, NULL); if (reply == NULL) return 0; unsigned *cursor_data = xcb_xfixes_get_cursor_image_cursor_image(reply); if (cursor_data == NULL) return 0; Imlib_Image cursor = imlib_create_image_using_data( reply->width, reply->height, cursor_data); if (cursor == NULL) PANIC(ERR_IMAGE); imlib_context_set_image(cursor); imlib_image_set_has_alpha(1); imlib_context_set_image(image); imlib_blend_image_onto_image(cursor, 0, 0, 0, reply->width, reply->height, reply->x - reply->xhot - x, reply->y - reply->yhot - y, reply->width, reply->height); imlib_context_set_image(cursor); imlib_free_image_and_decache(); free(reply); return 0; }
void UpdateCursor(void) { xcb_xfixes_get_cursor_image_cookie_t cookie = xcb_xfixes_get_cursor_image(xcwm_context_get_connection(context)); xcb_xfixes_get_cursor_image_reply_t* reply = xcb_xfixes_get_cursor_image_reply(xcwm_context_get_connection(context), cookie, NULL); // DEBUG("Got cursor image, serial %d\n", reply->cursor_serial); WMUTIL_CURSOR cursor; memset(&cursor, 0, sizeof(cursor)); cursor.width = reply->width; cursor.height = reply->height; cursor.xhot = reply->xhot; cursor.yhot = reply->yhot; cursor.argb = xcb_xfixes_get_cursor_image_cursor_image(reply); hCursor = winXCursorToHCURSOR(&cursor); // XXX: We should only change the cursor if the cursor is within one of our windows... // it's hard to notice this as a problem, as windows don't normally try to change the cursor except in response to something being clicked... HCURSOR hPreviousCursor = SetCursor(hCursor); // DEBUG("cursor 0x%08x, previous cursor 0x%08x\n", hCursor, hPreviousCursor); DestroyCursor(hPreviousCursor); free(reply); }
/* * Create the cursor texture, either by updating if the new cursor has the same * size or by creating a new texture if the size is different */ static void xcb_xcursor_create(xcb_xcursor_t *data, xcb_xfixes_get_cursor_image_reply_t *xc) { uint32_t *pixels = xcb_xfixes_get_cursor_image_cursor_image(xc); if (!pixels) return; if (data->tex && data->last_height == xc->width && data->last_width == xc->height) { gs_texture_set_image(data->tex, (const uint8_t *) pixels, xc->width * sizeof(uint32_t), false); } else { if (data->tex) gs_texture_destroy(data->tex); data->tex = gs_texture_create(xc->width, xc->height, GS_BGRA, 1, (const uint8_t **) &pixels, GS_DYNAMIC); } data->last_serial = xc->cursor_serial; data->last_width = xc->width; data->last_height = xc->height; }