3 #endif /* ifdef HAVE_CONFIG_H */
7 #include "ecore_x_private.h"
10 ecore_x_cursor_color_supported_get(void)
12 return _ecore_x_xcursor;
16 ecore_x_cursor_new(Ecore_X_Window win,
23 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
25 LOGFN(__FILE__, __LINE__, __FUNCTION__);
32 xci = XcursorImageCreate(w, h);
33 if (_ecore_xlib_sync) ecore_x_sync();
41 for (i = 0; i < (w * h); i++)
45 // a = (pixels[i] >> 24) & 0xff;
46 // r = (((pixels[i] >> 16) & 0xff) * a) / 0xff;
47 // g = (((pixels[i] >> 8 ) & 0xff) * a) / 0xff;
48 // b = (((pixels[i] ) & 0xff) * a) / 0xff;
49 xci->pixels[i] = pixels[i];
50 // (a << 24) | (r << 16) | (g << 8) | (b);
52 c = XcursorImageLoadCursor(_ecore_x_disp, xci);
53 if (_ecore_xlib_sync) ecore_x_sync();
54 XcursorImageDestroy(xci);
59 #endif /* ifdef ECORE_XCURSOR */
68 int fr, fg, fb, br, bg, bb;
70 int darkest = 255 * 3;
72 const int dither[2][2] =
78 pmap = XCreatePixmap(_ecore_x_disp, win, w, h, 1);
79 if (_ecore_xlib_sync) ecore_x_sync();
80 mask = XCreatePixmap(_ecore_x_disp, win, w, h, 1);
81 if (_ecore_xlib_sync) ecore_x_sync();
82 xim = XCreateImage(_ecore_x_disp,
83 DefaultVisual(_ecore_x_disp, 0),
84 1, ZPixmap, 0, NULL, w, h, 32, 0);
85 if (_ecore_xlib_sync) ecore_x_sync();
86 xim->data = malloc(xim->bytes_per_line * xim->height);
88 fr = 0x00; fg = 0x00; fb = 0x00;
89 br = 0xff; bg = 0xff; bb = 0xff;
90 pix = (unsigned int *)pixels;
91 for (y = 0; y < h; y++)
93 for (x = 0; x < w; x++)
97 a = (pix[0] >> 24) & 0xff;
98 r = (pix[0] >> 16) & 0xff;
99 g = (pix[0] >> 8) & 0xff;
103 if ((r + g + b) > brightest)
105 brightest = r + g + b;
111 if ((r + g + b) < darkest)
124 pix = (unsigned int *)pixels;
125 for (y = 0; y < h; y++)
127 for (x = 0; x < w; x++)
133 r = (pix[0] >> 16) & 0xff;
134 g = (pix[0] >> 8) & 0xff;
137 ((r - fr) * (r - fr)) +
138 ((g - fg) * (g - fg)) +
139 ((b - fb) * (b - fb));
141 ((r - br) * (r - br)) +
142 ((g - bg) * (g - bg)) +
143 ((b - bb) * (b - bb));
146 v = (((d2 * 255) / (d1 + d2)) * 5) / 256;
147 if (v > dither[x & 0x1][y & 0x1])
155 XPutPixel(xim, x, y, v);
156 if (_ecore_xlib_sync) ecore_x_sync();
160 gc = XCreateGC(_ecore_x_disp, pmap, 0, &gcv);
161 if (_ecore_xlib_sync) ecore_x_sync();
162 XPutImage(_ecore_x_disp, pmap, gc, xim, 0, 0, 0, 0, w, h);
163 if (_ecore_xlib_sync) ecore_x_sync();
164 XFreeGC(_ecore_x_disp, gc);
166 pix = (unsigned int *)pixels;
167 for (y = 0; y < h; y++)
169 for (x = 0; x < w; x++)
173 v = (((pix[0] >> 24) & 0xff) * 5) / 256;
174 if (v > dither[x & 0x1][y & 0x1])
179 XPutPixel(xim, x, y, v);
183 gc = XCreateGC(_ecore_x_disp, mask, 0, &gcv);
184 if (_ecore_xlib_sync) ecore_x_sync();
185 XPutImage(_ecore_x_disp, mask, gc, xim, 0, 0, 0, 0, w, h);
186 if (_ecore_xlib_sync) ecore_x_sync();
187 XFreeGC(_ecore_x_disp, gc);
194 c1.red = fr << 8 | fr;
195 c1.green = fg << 8 | fg;
196 c1.blue = fb << 8 | fb;
197 c1.flags = DoRed | DoGreen | DoBlue;
200 c2.red = br << 8 | br;
201 c2.green = bg << 8 | bg;
202 c2.blue = bb << 8 | bb;
203 c2.flags = DoRed | DoGreen | DoBlue;
205 c = XCreatePixmapCursor(_ecore_x_disp,
209 if (_ecore_xlib_sync) ecore_x_sync();
210 XFreePixmap(_ecore_x_disp, pmap);
211 XFreePixmap(_ecore_x_disp, mask);
219 ecore_x_cursor_free(Ecore_X_Cursor c)
221 LOGFN(__FILE__, __LINE__, __FUNCTION__);
222 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
223 XFreeCursor(_ecore_x_disp, c);
224 if (_ecore_xlib_sync) ecore_x_sync();
228 * Returns the cursor for the given shape.
229 * Note that the return value must not be freed with
230 * ecore_x_cursor_free()!
233 ecore_x_cursor_shape_get(int shape)
236 LOGFN(__FILE__, __LINE__, __FUNCTION__);
237 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
238 /* Shapes are defined in Ecore_X_Cursor.h */
239 cur = XCreateFontCursor(_ecore_x_disp, shape);
240 if (_ecore_xlib_sync) ecore_x_sync();
245 ecore_x_cursor_size_set(int size)
248 LOGFN(__FILE__, __LINE__, __FUNCTION__);
249 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
250 XcursorSetDefaultSize(_ecore_x_disp, size);
251 if (_ecore_xlib_sync) ecore_x_sync();
252 #else /* ifdef ECORE_XCURSOR */
254 #endif /* ifdef ECORE_XCURSOR */
258 ecore_x_cursor_size_get(void)
261 LOGFN(__FILE__, __LINE__, __FUNCTION__);
262 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
263 return XcursorGetDefaultSize(_ecore_x_disp);
264 #else /* ifdef ECORE_XCURSOR */
266 #endif /* ifdef ECORE_XCURSOR */