2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include "ecore_xcb_private.h"
7 #include <xcb/xcb_image.h>
10 extern int _ecore_xcb_xcursor;
14 ecore_x_cursor_color_supported_get(void)
16 return _ecore_xcb_xcursor;
20 ecore_x_cursor_new(Ecore_X_Window window,
27 Ecore_X_Cursor cursor = 0;
29 #ifdef ECORE_XCB_CURSOR
35 xci = XcursorImageCreate(w, h);
43 for (i = 0; i < (w * h); i++)
47 // a = (pixels[i] >> 24) & 0xff;
48 // r = (((pixels[i] >> 16) & 0xff) * a) / 0xff;
49 // g = (((pixels[i] >> 8 ) & 0xff) * a) / 0xff;
50 // b = (((pixels[i] ) & 0xff) * a) / 0xff;
51 xci->pixels[i] = pixels[i];
52 // (a << 24) | (r << 16) | (g << 8) | (b);
54 c = XcursorImageLoadCursor(_ecore_x_disp, xci);
55 XcursorImageDestroy(xci);
60 #endif /* ECORE_XCB_CURSOR */
62 const uint32_t dither[2][2] =
67 Ecore_X_Drawable draw;
68 Ecore_X_Pixmap pixmap;
79 uint32_t brightest = 0;
80 uint32_t darkest = 255 * 3;
85 pixmap = xcb_generate_id(_ecore_xcb_conn);
86 xcb_create_pixmap(_ecore_xcb_conn,
89 mask = xcb_generate_id(_ecore_xcb_conn);
90 xcb_create_pixmap(_ecore_xcb_conn,
94 image = xcb_image_create_native(_ecore_xcb_conn, w, h,
95 XCB_IMAGE_FORMAT_Z_PIXMAP,
97 image->data = malloc(image->size);
99 fr = 0x00; fg = 0x00; fb = 0x00;
100 br = 0xff; bg = 0xff; bb = 0xff;
101 pix = (uint32_t *)pixels;
102 for (y = 0; y < h; y++)
104 for (x = 0; x < w; x++)
108 a = (pix[0] >> 24) & 0xff;
109 r = (pix[0] >> 16) & 0xff;
110 g = (pix[0] >> 8 ) & 0xff;
111 b = (pix[0] ) & 0xff;
114 if ((uint32_t)(r + g + b) > brightest)
116 brightest = r + g + b;
121 if ((uint32_t)(r + g + b) < darkest)
133 pix = (uint32_t *)pixels;
134 for (y = 0; y < h; y++)
136 for (x = 0; x < w; x++)
142 r = (pix[0] >> 16) & 0xff;
143 g = (pix[0] >> 8 ) & 0xff;
144 b = (pix[0] ) & 0xff;
146 ((r - fr) * (r - fr)) +
147 ((g - fg) * (g - fg)) +
148 ((b - fb) * (b - fb));
150 ((r - br) * (r - br)) +
151 ((g - bg) * (g - bg)) +
152 ((b - bb) * (b - bb));
155 v = (((d2 * 255) / (d1 + d2)) * 5) / 256;
156 if (v > dither[x & 0x1][y & 0x1]) v = 1;
163 xcb_image_put_pixel(image, x, y, v);
168 gc = xcb_generate_id(_ecore_xcb_conn);
169 xcb_create_gc(_ecore_xcb_conn, gc, draw, 0, NULL);
170 xcb_image_put(_ecore_xcb_conn, draw, gc, image, 0, 0, 0);
171 xcb_free_gc(_ecore_xcb_conn, gc);
173 pix = (uint32_t *)pixels;
174 for (y = 0; y < h; y++)
176 for (x = 0; x < w; x++)
180 v = (((pix[0] >> 24) & 0xff) * 5) / 256;
181 if (v > dither[x & 0x1][y & 0x1]) v = 1;
183 xcb_image_put_pixel(image, x, y, v);
188 gc = xcb_generate_id(_ecore_xcb_conn);
189 xcb_create_gc (_ecore_xcb_conn, gc, draw, 0, NULL);
190 xcb_image_put(_ecore_xcb_conn, draw, gc, image, 0, 0, 0);
191 xcb_free_gc(_ecore_xcb_conn, gc);
195 xcb_image_destroy(image);
197 cursor = xcb_generate_id(_ecore_xcb_conn);
198 xcb_create_cursor (_ecore_xcb_conn, cursor,
208 xcb_free_pixmap(_ecore_xcb_conn, pixmap);
209 xcb_free_pixmap(_ecore_xcb_conn, mask);
217 ecore_x_cursor_free(Ecore_X_Cursor cursor)
219 xcb_free_cursor(_ecore_xcb_conn, cursor);
223 * Returns the cursor for the given shape.
224 * Note that the return value must not be freed with
225 * ecore_x_cursor_free()!
228 ecore_x_cursor_shape_get(int shape)
230 Ecore_X_Cursor cursor;
233 /* Shapes are defined in Ecore_X_Cursor.h */
234 font = xcb_generate_id(_ecore_xcb_conn);
235 xcb_open_font(_ecore_xcb_conn, font, strlen("cursor"), "cursor");
237 cursor = xcb_generate_id(_ecore_xcb_conn);
238 xcb_create_glyph_cursor (_ecore_xcb_conn,
245 65535, 65535, 65535);
247 xcb_close_font(_ecore_xcb_conn, font);
253 ecore_x_cursor_size_set(int size)
255 #ifdef ECORE_XCB_CURSOR
256 XcursorSetDefaultSize(_ecore_x_disp, size);
259 #endif /* ECORE_XCB_CURSOR */
263 ecore_x_cursor_size_get(void)
265 #ifdef ECORE_XCB_CURSOR
266 return XcursorGetDefaultSize(_ecore_x_disp);
269 #endif /* ECORE_XCB_CURSOR */