2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
11 #include "ecore_x_private.h"
15 ecore_x_cursor_color_supported_get(void)
17 return _ecore_x_xcursor;
21 ecore_x_cursor_new(Ecore_X_Window win, int *pixels, int w, int h, int hot_x, int hot_y)
24 LOGFN(__FILE__, __LINE__, __FUNCTION__);
30 xci = XcursorImageCreate(w, h);
38 for (i = 0; i < (w * h); i++)
42 // a = (pixels[i] >> 24) & 0xff;
43 // r = (((pixels[i] >> 16) & 0xff) * a) / 0xff;
44 // g = (((pixels[i] >> 8 ) & 0xff) * a) / 0xff;
45 // b = (((pixels[i] ) & 0xff) * a) / 0xff;
46 xci->pixels[i] = pixels[i];
47 // (a << 24) | (r << 16) | (g << 8) | (b);
49 c = XcursorImageLoadCursor(_ecore_x_disp, xci);
50 XcursorImageDestroy(xci);
64 int fr, fg, fb, br, bg, bb;
66 int darkest = 255 * 3;
68 const int dither[2][2] =
74 pmap = XCreatePixmap(_ecore_x_disp, win, w, h, 1);
75 mask = XCreatePixmap(_ecore_x_disp, win, w, h, 1);
76 xim = XCreateImage(_ecore_x_disp,
77 DefaultVisual(_ecore_x_disp, 0),
78 1, ZPixmap, 0, NULL, w, h, 32, 0);
79 xim->data = malloc(xim->bytes_per_line * xim->height);
81 fr = 0x00; fg = 0x00; fb = 0x00;
82 br = 0xff; bg = 0xff; bb = 0xff;
83 pix = (unsigned int*)pixels;
84 for (y = 0; y < h; y++)
86 for (x = 0; x < w; x++)
90 a = (pix[0] >> 24) & 0xff;
91 r = (pix[0] >> 16) & 0xff;
92 g = (pix[0] >> 8 ) & 0xff;
96 if ((r + g + b) > brightest)
98 brightest = r + g + b;
103 if ((r + g + b) < darkest)
115 pix = (unsigned int*)pixels;
116 for (y = 0; y < h; y++)
118 for (x = 0; x < w; x++)
124 r = (pix[0] >> 16) & 0xff;
125 g = (pix[0] >> 8 ) & 0xff;
126 b = (pix[0] ) & 0xff;
128 ((r - fr) * (r - fr)) +
129 ((g - fg) * (g - fg)) +
130 ((b - fb) * (b - fb));
132 ((r - br) * (r - br)) +
133 ((g - bg) * (g - bg)) +
134 ((b - bb) * (b - bb));
137 v = (((d2 * 255) / (d1 + d2)) * 5) / 256;
138 if (v > dither[x & 0x1][y & 0x1]) v = 1;
145 XPutPixel(xim, x, y, v);
149 gc = XCreateGC(_ecore_x_disp, pmap, 0, &gcv);
150 XPutImage(_ecore_x_disp, pmap, gc, xim, 0, 0, 0, 0, w, h);
151 XFreeGC(_ecore_x_disp, gc);
153 pix = (unsigned int*)pixels;
154 for (y = 0; y < h; y++)
156 for (x = 0; x < w; x++)
160 v = (((pix[0] >> 24) & 0xff) * 5) / 256;
161 if (v > dither[x & 0x1][y & 0x1]) v = 1;
163 XPutPixel(xim, x, y, v);
167 gc = XCreateGC(_ecore_x_disp, mask, 0, &gcv);
168 XPutImage(_ecore_x_disp, mask, gc, xim, 0, 0, 0, 0, w, h);
169 XFreeGC(_ecore_x_disp, gc);
176 c1.red = fr << 8 | fr;
177 c1.green = fg << 8 | fg;
178 c1.blue = fb << 8 | fb;
179 c1.flags = DoRed | DoGreen | DoBlue;
182 c2.red = br << 8 | br;
183 c2.green = bg << 8 | bg;
184 c2.blue = bb << 8 | bb;
185 c2.flags = DoRed | DoGreen | DoBlue;
187 c = XCreatePixmapCursor(_ecore_x_disp,
191 XFreePixmap(_ecore_x_disp, pmap);
192 XFreePixmap(_ecore_x_disp, mask);
199 ecore_x_cursor_free(Ecore_X_Cursor c)
201 LOGFN(__FILE__, __LINE__, __FUNCTION__);
202 XFreeCursor(_ecore_x_disp, c);
206 * Returns the cursor for the given shape.
207 * Note that the return value must not be freed with
208 * ecore_x_cursor_free()!
211 ecore_x_cursor_shape_get(int shape)
213 LOGFN(__FILE__, __LINE__, __FUNCTION__);
214 /* Shapes are defined in Ecore_X_Cursor.h */
215 return XCreateFontCursor(_ecore_x_disp, shape);
219 ecore_x_cursor_size_set(int size)
222 LOGFN(__FILE__, __LINE__, __FUNCTION__);
223 XcursorSetDefaultSize(_ecore_x_disp, size);
230 ecore_x_cursor_size_get(void)
233 LOGFN(__FILE__, __LINE__, __FUNCTION__);
234 return XcursorGetDefaultSize(_ecore_x_disp);