Enlightenment CVS committal Author : nerochiaro Project : e17 Module : libs/etk
Dir : e17/libs/etk/src/engines/ecore_fb Modified Files: Etk_Engine_Ecore_Fb.h ecore_fb.c Log Message: Adds window focus handling to FB engine. =================================================================== RCS file: /cvs/e/e17/libs/etk/src/engines/ecore_fb/Etk_Engine_Ecore_Fb.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- Etk_Engine_Ecore_Fb.h 5 Sep 2006 00:14:57 -0000 1.2 +++ Etk_Engine_Ecore_Fb.h 9 Jan 2007 22:09:42 -0000 1.3 @@ -14,6 +14,7 @@ Etk_Bool visible; Evas_Object *border; + Etk_Window *focused; } Etk_Engine_Ecore_Fb_Window_Data; #endif =================================================================== RCS file: /cvs/e/e17/libs/etk/src/engines/ecore_fb/ecore_fb.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- ecore_fb.c 8 Oct 2006 10:04:53 -0000 1.10 +++ ecore_fb.c 9 Jan 2007 22:09:42 -0000 1.11 @@ -20,6 +20,7 @@ /* Etk_Window functions */ static void _window_constructor(Etk_Window *window); +static void _window_destructor(Etk_Window *window); static void _window_show(Etk_Window *window); static void _window_hide(Etk_Window *window); static Evas *_window_evas_get(Etk_Window *window); @@ -32,6 +33,8 @@ static void _window_screen_geometry_get(Etk_Window *window, int *x, int *y, int *w, int *h); static void _window_raise(Etk_Window *window); static void _window_lower(Etk_Window *window); +static void _window_focused_set(Etk_Window *window, Etk_Bool focused); +static Etk_Bool _window_focused_get(Etk_Window *window); static void _window_realized_cb(Etk_Object *object, void *data); static void _window_titlebar_mouse_down_cb(void *data, Evas_Object *obj, const char *emission, const char *source); @@ -43,6 +46,10 @@ static void _mouse_screen_geometry_get(int *x, int *y, int *w, int *h); static int _mouse_move_handler_cb(void *data, int ev_type, void *ev); +/* Internal functions */ + +Etk_Window *_window_focus_find_other(Etk_Window *current); + /* Private vars */ static Ecore_Evas *_ecore_evas = NULL; static Evas *_evas = NULL; @@ -69,7 +76,7 @@ _engine_shutdown, _window_constructor, - NULL, /* window_destructor */ + _window_destructor, _window_show, _window_hide, _window_evas_get, @@ -96,8 +103,8 @@ NULL, /* window_stacking_get */ NULL, /* window_sticky_set */ NULL, /* window_sticky_get */ - NULL, /* window_focused_set */ - NULL, /* window_focused_get */ + _window_focused_set, + _window_focused_get, NULL, /* window_decorated_set */ NULL, /* window_decorated_get */ NULL, /* window_shaped_set */ @@ -227,6 +234,22 @@ etk_signal_connect("realize", ETK_OBJECT(window), ETK_CALLBACK(_window_realized_cb), NULL); } +/* Cleans up the window */ +static void _window_destructor(Etk_Window *window) +{ + Etk_Engine_Window_Data *engine_data; + Etk_Window *other; + + engine_data = window->engine_data; + + // move focus to another window if this was the focused one + if (window == engine_data->focused) + { + other = _window_focus_find_other(window); + if (other != NULL) _window_focused_set(other, ETK_TRUE); + } +} + /* Shows the window */ static void _window_show(Etk_Window *window) { @@ -242,11 +265,19 @@ static void _window_hide(Etk_Window *window) { Etk_Engine_Window_Data *engine_data; - + Etk_Window *other; + engine_data = window->engine_data; engine_data->visible = ETK_FALSE; if (engine_data->border) evas_object_hide(engine_data->border); + + // move focus to another window if this was the focused one + if (window == engine_data->focused) + { + other = _window_focus_find_other(window); + if (other != NULL) _window_focused_set(other, ETK_TRUE); + } } /* Gets the evas where the window is drawn */ @@ -355,10 +386,56 @@ static void _window_lower(Etk_Window *window) { Etk_Engine_Window_Data *engine_data; - + Etk_Window *other; + engine_data = window->engine_data; if (engine_data->border) evas_object_lower(engine_data->border); + + // move focus to another window if this was the focused one + if (window == engine_data->focused) + { + other = _window_focus_find_other(window); + if (other != NULL) _window_focused_set(other, ETK_TRUE); + } +} + +/* Sets the window as the current focused window in the system, or unfocus it. + When unfocusing, the next window available in the windows list will be focused. + If no other window is available, focus will remain on current window. +*/ +void _window_focused_set(Etk_Window *window, Etk_Bool focused) +{ + Etk_Engine_Window_Data *engine_data; + Etk_Window *other; + + engine_data = window->engine_data; + if (focused) + { + engine_data->focused = window; + evas_object_focus_set(ETK_WIDGET(window)->smart_object, 1); + } + else + { + if (engine_data->focused != window) return; // you can't unfocus a window that's not the focused one. + + other = _window_focus_find_other(window); + if (other != NULL) + { + engine_data->focused = other; + evas_object_focus_set(ETK_WIDGET(other)->smart_object, 1); + } + } +} + +/* Is this window the current focused window in the system ? */ +Etk_Bool _window_focused_get(Etk_Window *window) +{ + Etk_Engine_Window_Data *engine_data; + + engine_data = window->engine_data; + if (engine_data->focused == window) return ETK_TRUE; + else return ETK_FALSE; } /************************** @@ -387,6 +464,31 @@ if (y) *y = 0; if (w) *w = _fb_width; if (h) *h = _fb_height; +} + +/************************** + * + * Internal functions + * + **************************/ + +/* Find a window to focus that is different from the current one. + Maybe replace this with a focus stack or something similar, later. +*/ +Etk_Window *_window_focus_find_other(Etk_Window *current) +{ + Evas_List *toplevels; + Etk_Window *other; + + // for now just return the first other window we find. + for (toplevels = etk_toplevel_widgets_get(); toplevels; toplevels = toplevels->next) + { + if (!ETK_IS_WINDOW(toplevels->data)) continue; + + other = ETK_WINDOW(toplevels->data); + if (other != current) return other; + } + return NULL; } /************************** ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs