Here's my attempt to clean up the cursor api in Ecore X.
First, ecore_x_cursor_set() has been renamed to
ecore_x_window_cursor_set().
ecore_x_cursor_shape_set() was just a wrapper around XCreateFontCursor
and ecore_x_cursor_set() - I removed it completely.
What I didn't like is the fact that the the cursor thats set isn't
returned to the caller in any way, so you cannot cache it and Ecore X
has to call XCreateFontCursor over and over again :)
So, I added ecore_x_cursor_shape_get(int shape), which calls
XCreateFontCursor().
I avoided the "new" suffix in the function name to make clear the caller
must not call ecore_x_cursor_free() on it.
Comments welcome ;)
--
Regards,
Tilman
Index: Ecore_X.h
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/Ecore_X.h,v
retrieving revision 1.51
diff -u -r1.51 Ecore_X.h
--- Ecore_X.h 23 Aug 2004 10:44:22 -0000 1.51
+++ Ecore_X.h 23 Aug 2004 20:16:27 -0000
@@ -738,6 +738,8 @@
Ecore_X_Window ecore_x_window_new(Ecore_X_Window parent, int x, int y, int w, int
h);
Ecore_X_Window ecore_x_window_override_new(Ecore_X_Window parent, int x, int y, int
w, int h);
Ecore_X_Window ecore_x_window_input_new(Ecore_X_Window parent, int x, int y, int w,
int h);
+void ecore_x_window_cursor_set(Ecore_X_Window win,
+ Ecore_X_Cursor c);
void ecore_x_window_del(Ecore_X_Window win);
void ecore_x_window_delete_request_send(Ecore_X_Window win);
void ecore_x_window_show(Ecore_X_Window win);
@@ -877,10 +879,8 @@
ecore_x_cursor_new(Ecore_X_Window win, int *pixels, int w, int h, int hot_x, int
hot_y);
void
ecore_x_cursor_free(Ecore_X_Cursor c);
- void
- ecore_x_cursor_set(Ecore_X_Window win, Ecore_X_Cursor c);
- void
- ecore_x_cursor_shape_set(Ecore_X_Window win, int shape);
+ Ecore_X_Cursor
+ ecore_x_cursor_shape_get(int shape);
int
ecore_x_pointer_grab(Ecore_X_Window win);
Index: ecore_x.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x.c,v
retrieving revision 1.36
diff -u -r1.36 ecore_x.c
--- ecore_x.c 22 Aug 2004 21:44:52 -0000 1.36
+++ ecore_x.c 23 Aug 2004 20:16:28 -0000
@@ -1184,22 +1184,16 @@
XFreeCursor(_ecore_x_disp, c);
}
-void
-ecore_x_cursor_set(Ecore_X_Window win, Ecore_X_Cursor c)
-{
- if (c == 0)
- XUndefineCursor(_ecore_x_disp, win);
- else
- XDefineCursor(_ecore_x_disp, win, c);
-}
-
-void
-ecore_x_cursor_shape_set(Ecore_X_Window win, int shape)
+/*
+ * Returns the cursor for the given shape.
+ * Note that the return value must not be freed with
+ * ecore_x_cursor_free()!
+ */
+Ecore_X_Cursor
+ecore_x_cursor_shape_get(int shape)
{
/* Shapes are defined in Ecore_X_Cursor.h */
- Cursor c = XCreateFontCursor(_ecore_x_disp, shape);
- if (c)
- ecore_x_cursor_set(win, c);
+ return XCreateFontCursor(_ecore_x_disp, shape);
}
int
Index: ecore_x_window.c
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x_window.c,v
retrieving revision 1.23
diff -u -r1.23 ecore_x_window.c
--- ecore_x_window.c 23 Aug 2004 10:47:20 -0000 1.23
+++ ecore_x_window.c 23 Aug 2004 20:16:29 -0000
@@ -536,6 +536,15 @@
}
}
+void
+ecore_x_window_cursor_set(Ecore_X_Window win, Ecore_X_Cursor c)
+{
+ if (c == 0)
+ XUndefineCursor(_ecore_x_disp, win);
+ else
+ XDefineCursor(_ecore_x_disp, win, c);
+}
+
/**
* Finds out whether the given window is currently visible.
* @param win The given window.