1 #include "ecore_x_private.h"
5 ecore_x_cursor_color_supported_get(void)
7 return _ecore_x_xcursor;
11 ecore_x_cursor_new(Ecore_X_Window win, int *pixels, int w, int h, int hot_x, int hot_y)
19 xci = XcursorImageCreate(w, h);
27 for (i = 0; i < (w * h); i++)
31 // a = (pixels[i] >> 24) & 0xff;
32 // r = (((pixels[i] >> 16) & 0xff) * a) / 0xff;
33 // g = (((pixels[i] >> 8 ) & 0xff) * a) / 0xff;
34 // b = (((pixels[i] ) & 0xff) * a) / 0xff;
35 xci->pixels[i] = pixels[i];
36 // (a << 24) | (r << 16) | (g << 8) | (b);
38 c = XcursorImageLoadCursor(_ecore_x_disp, xci);
39 XcursorImageDestroy(xci);
53 int fr, fg, fb, br, bg, bb;
55 int darkest = 255 * 3;
57 const int dither[2][2] =
63 pmap = XCreatePixmap(_ecore_x_disp, win, w, h, 1);
64 mask = XCreatePixmap(_ecore_x_disp, win, w, h, 1);
65 xim = XCreateImage(_ecore_x_disp,
66 DefaultVisual(_ecore_x_disp, 0),
67 1, ZPixmap, 0, NULL, w, h, 32, 0);
68 xim->data = malloc(xim->bytes_per_line * xim->height);
70 fr = 0x00; fg = 0x00; fb = 0x00;
71 br = 0xff; bg = 0xff; bb = 0xff;
72 pix = (unsigned int*)pixels;
73 for (y = 0; y < h; y++)
75 for (x = 0; x < w; x++)
79 a = (pix[0] >> 24) & 0xff;
80 r = (pix[0] >> 16) & 0xff;
81 g = (pix[0] >> 8 ) & 0xff;
85 if ((r + g + b) > brightest)
87 brightest = r + g + b;
92 if ((r + g + b) < darkest)
104 pix = (unsigned int*)pixels;
105 for (y = 0; y < h; y++)
107 for (x = 0; x < w; x++)
113 r = (pix[0] >> 16) & 0xff;
114 g = (pix[0] >> 8 ) & 0xff;
115 b = (pix[0] ) & 0xff;
117 ((r - fr) * (r - fr)) +
118 ((g - fg) * (g - fg)) +
119 ((b - fb) * (b - fb));
121 ((r - br) * (r - br)) +
122 ((g - bg) * (g - bg)) +
123 ((b - bb) * (b - bb));
126 v = (((d2 * 255) / (d1 + d2)) * 5) / 256;
127 if (v > dither[x & 0x1][y & 0x1]) v = 1;
134 XPutPixel(xim, x, y, v);
138 gc = XCreateGC(_ecore_x_disp, pmap, 0, &gcv);
139 XPutImage(_ecore_x_disp, pmap, gc, xim, 0, 0, 0, 0, w, h);
140 XFreeGC(_ecore_x_disp, gc);
142 pix = (unsigned int*)pixels;
143 for (y = 0; y < h; y++)
145 for (x = 0; x < w; x++)
149 v = (((pix[0] >> 24) & 0xff) * 5) / 256;
150 if (v > dither[x & 0x1][y & 0x1]) v = 1;
152 XPutPixel(xim, x, y, v);
156 gc = XCreateGC(_ecore_x_disp, mask, 0, &gcv);
157 XPutImage(_ecore_x_disp, mask, gc, xim, 0, 0, 0, 0, w, h);
158 XFreeGC(_ecore_x_disp, gc);
165 c1.red = fr << 8 | fr;
166 c1.green = fg << 8 | fg;
167 c1.blue = fb << 8 | fb;
168 c1.flags = DoRed | DoGreen | DoBlue;
171 c2.red = br << 8 | br;
172 c2.green = bg << 8 | bg;
173 c2.blue = bb << 8 | bb;
174 c2.flags = DoRed | DoGreen | DoBlue;
176 c = XCreatePixmapCursor(_ecore_x_disp,
180 XFreePixmap(_ecore_x_disp, pmap);
181 XFreePixmap(_ecore_x_disp, mask);
188 ecore_x_cursor_free(Ecore_X_Cursor c)
190 XFreeCursor(_ecore_x_disp, c);
194 * Returns the cursor for the given shape.
195 * Note that the return value must not be freed with
196 * ecore_x_cursor_free()!
199 ecore_x_cursor_shape_get(int shape)
201 /* Shapes are defined in Ecore_X_Cursor.h */
202 return XCreateFontCursor(_ecore_x_disp, shape);
206 ecore_x_cursor_size_set(int size)
209 XcursorSetDefaultSize(_ecore_x_disp, size);
216 ecore_x_cursor_size_get(void)
219 return XcursorGetDefaultSize(_ecore_x_disp);