Hi guys,
I'm currently working on an IM client plugin for Canola in GSoC. This is my
first proposed patch for enlightenment.
The problem begun when I tried to embed a elm widget inside canola. Every
time I created a widget, with a Edje smart object as parent, I got
segfaults. So I started investigating why it happaned inside the binding.
Nothing was wrong with it. Then I looked inside the code for elementary.
There I found it. All widgets suppose their top father is an evas smart
object containing a Elm_Win structure as the data field. Thats not true in
my case. So the patch changes the function elm_win_xwindow_get() inside
elm_win.c in a way that it get the xwindow reference from the evas of the
object, avoiding the corruption of data done by calling
_elm_win_xwindow_get(). See code for more details. That fixed the first
problem.
But I kept getting segfaults when I used an entry widget, after I gave it
the focus. Problem was _on_focus_hook() (elm_entry.c) calling
elm_win_keyboard_mode_set(). This would also currupt a non-Elm_Win structure
pointed by data. So I proposed the creation of a magic field inside Elm_Win
to be tested before doing any operations that needs the smart object to be
attached to Elm_Win.
The patch is working with tests and everything is working for me! I don't
know if this is the best solution, but at least it is one.
Waiting on comments!
Thanks.
--
Thiago 'bolaum' Borges Abdnur
----------------------------------
"Trust no one..."
- Deep Throat (The X-Files)
Index: src/lib/elm_priv.h
===================================================================
--- src/lib/elm_priv.h (revision 41310)
+++ src/lib/elm_priv.h (working copy)
@@ -56,6 +56,13 @@
#define ELM_NEW(t) calloc(1, sizeof(t))
+#define ELM_MAGIC_WIN_DATA 0x90327190
+
+#define ELM_MAGIC unsigned int __magic
+
+#define ELM_MAGIC_SET(d, m) (d)->__magic = (m)
+#define ELM_MAGIC_CHECK(d, m) ((d) && ((d)->__magic == (m)))
+
void _elm_win_shutdown(void);
void _elm_win_rescale(void);
Index: src/lib/elm_win.c
===================================================================
--- src/lib/elm_win.c (revision 41310)
+++ src/lib/elm_win.c (working copy)
@@ -5,6 +5,7 @@
struct _Elm_Win
{
+ ELM_MAGIC;
Ecore_Evas *ee;
Evas *evas;
Evas_Object *parent;
@@ -38,7 +39,7 @@
_elm_win_resize(Ecore_Evas *ee)
{
Elm_Win *win = elm_widget_data_get(ecore_evas_object_associate_get(ee));
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
if (win->deferred_resize_job) ecore_job_del(win->deferred_resize_job);
win->deferred_resize_job = ecore_job_add(_elm_win_resize_job, win);
}
@@ -46,8 +47,8 @@
static void
_elm_win_focus_in(Ecore_Evas *ee)
{
- Elm_Win *win = elm_widget_data_get(ecore_evas_object_associate_get(ee));
- if (!win) return;
+ Elm_Win *win = elm_widget_data_get(ecore_evas_object_associate_get(ee));
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
evas_object_smart_callback_call(win->win_obj, "focus-in", NULL);
}
@@ -55,7 +56,7 @@
_elm_win_focus_out(Ecore_Evas *ee)
{
Elm_Win *win = elm_widget_data_get(ecore_evas_object_associate_get(ee));
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
evas_object_smart_callback_call(win->win_obj, "focus-out", NULL);
}
@@ -102,7 +103,7 @@
_elm_win_delete_request(Ecore_Evas *ee)
{
Elm_Win *win = elm_widget_data_get(ecore_evas_object_associate_get(ee));
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
int autodel = win->autodel;
win->autodel_clear = &autodel;
evas_object_smart_callback_call(win->win_obj, "delete-request", NULL);
@@ -292,6 +293,8 @@
const char *fontpath;
win = ELM_NEW(Elm_Win);
+ ELM_MAGIC_SET(win, ELM_MAGIC_WIN_DATA);
+
switch (_elm_config->engine)
{
case ELM_SOFTWARE_X11:
@@ -395,7 +398,7 @@
{
Elm_Win *win = elm_widget_data_get(obj);
Evas_Coord w, h;
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
win->subobjs = eina_list_append(win->subobjs, subobj);
elm_widget_sub_object_add(obj, subobj);
evas_object_event_callback_add(subobj, EVAS_CALLBACK_DEL, _elm_win_subobj_callback_del, obj);
@@ -410,7 +413,7 @@
elm_win_resize_object_del(Evas_Object *obj, Evas_Object *subobj)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
evas_object_event_callback_del(subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _elm_win_subobj_callback_changed_size_hints);
evas_object_event_callback_del(subobj, EVAS_CALLBACK_DEL, _elm_win_subobj_callback_del);
win->subobjs = eina_list_remove(win->subobjs, subobj);
@@ -422,7 +425,7 @@
elm_win_title_set(Evas_Object *obj, const char *title)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_title_set(win->ee, title);
}
@@ -430,7 +433,7 @@
elm_win_autodel_set(Evas_Object *obj, Eina_Bool autodel)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
win->autodel = autodel;
}
@@ -438,7 +441,7 @@
elm_win_activate(Evas_Object *obj)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_activate(win->ee);
}
@@ -446,7 +449,7 @@
elm_win_lower(Evas_Object *obj)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_lower(win->ee);
}
@@ -454,7 +457,7 @@
elm_win_raise(Evas_Object *obj)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_raise(win->ee);
}
@@ -462,7 +465,7 @@
elm_win_borderless_set(Evas_Object *obj, Eina_Bool borderless)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_borderless_set(win->ee, borderless);
_elm_win_xwin_update(win);
}
@@ -471,7 +474,7 @@
elm_win_shaped_set(Evas_Object *obj, Eina_Bool shaped)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_shaped_set(win->ee, shaped);
_elm_win_xwin_update(win);
}
@@ -480,7 +483,7 @@
elm_win_alpha_set(Evas_Object *obj, Eina_Bool alpha)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
if (win->xwin)
{
if (alpha)
@@ -502,7 +505,7 @@
elm_win_override_set(Evas_Object *obj, Eina_Bool override)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_override_set(win->ee, override);
_elm_win_xwin_update(win);
}
@@ -511,7 +514,7 @@
elm_win_fullscreen_set(Evas_Object *obj, Eina_Bool fullscreen)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
switch (_elm_config->engine)
{
case ELM_SOFTWARE_16_WINCE:
@@ -529,7 +532,7 @@
elm_win_maximized_set(Evas_Object *obj, Eina_Bool maximized)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_maximized_set(win->ee, maximized);
_elm_win_xwin_update(win);
}
@@ -538,7 +541,7 @@
elm_win_iconified_set(Evas_Object *obj, Eina_Bool iconified)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_iconified_set(win->ee, iconified);
_elm_win_xwin_update(win);
}
@@ -547,7 +550,7 @@
elm_win_layer_set(Evas_Object *obj, int layer)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_layer_set(win->ee, layer);
_elm_win_xwin_update(win);
}
@@ -556,7 +559,7 @@
elm_win_rotation_set(Evas_Object *obj, int rotation)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
if (win->rot == rotation) return;
win->rot = rotation;
ecore_evas_rotation_set(win->ee, rotation);
@@ -570,7 +573,7 @@
elm_win_sticky_set(Evas_Object *obj, Eina_Bool sticky)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
ecore_evas_sticky_set(win->ee, sticky);
_elm_win_xwin_update(win);
}
@@ -579,7 +582,7 @@
elm_win_keyboard_mode_set(Evas_Object *obj, Elm_Win_Keyboard_Mode mode)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
if (mode == win->kbdmode) return;
_elm_win_xwindow_get(win);
win->kbdmode = mode;
@@ -594,7 +597,7 @@
elm_win_keyboard_win_set(Evas_Object *obj, Eina_Bool is_keyboard)
{
Elm_Win *win = elm_widget_data_get(obj);
- if (!win) return;
+ if (!ELM_MAGIC_CHECK(win, ELM_MAGIC_WIN_DATA)) return;
_elm_win_xwindow_get(win);
#ifdef HAVE_ELEMENTARY_X
if (win->xwin)
@@ -734,8 +737,11 @@
EAPI Ecore_X_Window
elm_win_xwindow_get(const Evas_Object *obj)
{
- Elm_Win *win = (Elm_Win *)elm_widget_data_get(obj);
- if (!win) return 0;
- _elm_win_xwindow_get(win);
- return win->xwin;
+ Ecore_X_Window xwin = 0;
+ Ecore_Evas *ee = NULL;
+
+ ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
+ if (ee) xwin = (Ecore_X_Window)ecore_evas_window_get(ee);
+
+ return xwin;
}
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel