1 #include "ecore_xcb_private.h"
3 #include <xcb/xcb_image.h>
5 extern int _ecore_xcb_xcursor;
8 ecore_x_cursor_color_supported_get(void)
10 return _ecore_xcb_xcursor;
11 } /* ecore_x_cursor_color_supported_get */
14 ecore_x_cursor_new(Ecore_X_Window window,
21 Ecore_X_Cursor cursor = 0;
23 #ifdef ECORE_XCB_CURSOR
29 xci = XcursorImageCreate(w, h);
37 for (i = 0; i < (w * h); i++)
41 // a = (pixels[i] >> 24) & 0xff;
42 // r = (((pixels[i] >> 16) & 0xff) * a) / 0xff;
43 // g = (((pixels[i] >> 8 ) & 0xff) * a) / 0xff;
44 // b = (((pixels[i] ) & 0xff) * a) / 0xff;
45 xci->pixels[i] = pixels[i];
46 // (a << 24) | (r << 16) | (g << 8) | (b);
48 c = XcursorImageLoadCursor(_ecore_x_disp, xci);
49 XcursorImageDestroy(xci);
54 #endif /* ECORE_XCB_CURSOR */
56 const uint32_t dither[2][2] =
61 Ecore_X_Drawable draw;
62 Ecore_X_Pixmap pixmap;
73 uint32_t brightest = 0;
74 uint32_t darkest = 255 * 3;
79 pixmap = xcb_generate_id(_ecore_xcb_conn);
80 xcb_create_pixmap(_ecore_xcb_conn,
83 mask = xcb_generate_id(_ecore_xcb_conn);
84 xcb_create_pixmap(_ecore_xcb_conn,
88 image = xcb_image_create_native(_ecore_xcb_conn, w, h,
89 XCB_IMAGE_FORMAT_Z_PIXMAP,
91 image->data = malloc(image->size);
93 fr = 0x00; fg = 0x00; fb = 0x00;
94 br = 0xff; bg = 0xff; bb = 0xff;
95 pix = (uint32_t *)pixels;
96 for (y = 0; y < h; y++)
98 for (x = 0; x < w; x++)
102 a = (pix[0] >> 24) & 0xff;
103 r = (pix[0] >> 16) & 0xff;
104 g = (pix[0] >> 8) & 0xff;
108 if ((uint32_t)(r + g + b) > brightest)
110 brightest = r + g + b;
116 if ((uint32_t)(r + g + b) < darkest)
129 pix = (uint32_t *)pixels;
130 for (y = 0; y < h; y++)
132 for (x = 0; x < w; x++)
138 r = (pix[0] >> 16) & 0xff;
139 g = (pix[0] >> 8) & 0xff;
142 ((r - fr) * (r - fr)) +
143 ((g - fg) * (g - fg)) +
144 ((b - fb) * (b - fb));
146 ((r - br) * (r - br)) +
147 ((g - bg) * (g - bg)) +
148 ((b - bb) * (b - bb));
151 v = (((d2 * 255) / (d1 + d2)) * 5) / 256;
152 if (v > dither[x & 0x1][y & 0x1])
162 xcb_image_put_pixel(image, x, y, v);
167 gc = xcb_generate_id(_ecore_xcb_conn);
168 xcb_create_gc(_ecore_xcb_conn, gc, draw, 0, NULL);
169 xcb_image_put(_ecore_xcb_conn, draw, gc, image, 0, 0, 0);
170 xcb_free_gc(_ecore_xcb_conn, gc);
172 pix = (uint32_t *)pixels;
173 for (y = 0; y < h; y++)
175 for (x = 0; x < w; x++)
179 v = (((pix[0] >> 24) & 0xff) * 5) / 256;
180 if (v > dither[x & 0x1][y & 0x1])
185 xcb_image_put_pixel(image, x, y, v);
190 gc = xcb_generate_id(_ecore_xcb_conn);
191 xcb_create_gc (_ecore_xcb_conn, gc, draw, 0, NULL);
192 xcb_image_put(_ecore_xcb_conn, draw, gc, image, 0, 0, 0);
193 xcb_free_gc(_ecore_xcb_conn, gc);
197 xcb_image_destroy(image);
199 cursor = xcb_generate_id(_ecore_xcb_conn);
200 xcb_create_cursor (_ecore_xcb_conn, cursor,
210 xcb_free_pixmap(_ecore_xcb_conn, pixmap);
211 xcb_free_pixmap(_ecore_xcb_conn, mask);
217 } /* ecore_x_cursor_new */
220 ecore_x_cursor_free(Ecore_X_Cursor cursor)
222 xcb_free_cursor(_ecore_xcb_conn, cursor);
223 } /* ecore_x_cursor_free */
226 * Returns the cursor for the given shape.
227 * Note that the return value must not be freed with
228 * ecore_x_cursor_free()!
231 ecore_x_cursor_shape_get(int shape)
233 Ecore_X_Cursor cursor;
236 /* Shapes are defined in Ecore_X_Cursor.h */
237 font = xcb_generate_id(_ecore_xcb_conn);
238 xcb_open_font(_ecore_xcb_conn, font, strlen("cursor"), "cursor");
240 cursor = xcb_generate_id(_ecore_xcb_conn);
241 xcb_create_glyph_cursor (_ecore_xcb_conn,
248 65535, 65535, 65535);
250 xcb_close_font(_ecore_xcb_conn, font);
253 } /* ecore_x_cursor_shape_get */
256 ecore_x_cursor_size_set(int size)
258 #ifdef ECORE_XCB_CURSOR
259 XcursorSetDefaultSize(_ecore_x_disp, size);
260 #else /* ifdef ECORE_XCB_CURSOR */
262 #endif /* ECORE_XCB_CURSOR */
263 } /* ecore_x_cursor_size_set */
266 ecore_x_cursor_size_get(void)
268 #ifdef ECORE_XCB_CURSOR
269 return XcursorGetDefaultSize(_ecore_x_disp);
270 #else /* ifdef ECORE_XCB_CURSOR */
272 #endif /* ECORE_XCB_CURSOR */
273 } /* ecore_x_cursor_size_get */