Enlightenment CVS committal Author : moom 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: Lib: ---- * [Tree2] More work and some fixes * [Widget] Add etk_widget_padding_set() * Various fixes Engine: ------- * [FB engine] Fb engine now supports mouse pointers, window's titles, borderless window, + a lot of fixes Theme: ------ * The widget theme has been separated from the WM theme (the WM theme is used by the FB engine) =================================================================== RCS file: /cvs/e/e17/libs/etk/src/engines/ecore_fb/Etk_Engine_Ecore_Fb.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- Etk_Engine_Ecore_Fb.h 9 Jan 2007 22:09:42 -0000 1.3 +++ Etk_Engine_Ecore_Fb.h 12 Jan 2007 02:53:56 -0000 1.4 @@ -12,9 +12,11 @@ Etk_Size size; Etk_Size min_size; Etk_Bool visible; + Etk_Bool maximized; + char *title; + Etk_Bool borderless; 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.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- ecore_fb.c 9 Jan 2007 22:09:42 -0000 1.11 +++ ecore_fb.c 12 Jan 2007 02:53:56 -0000 1.12 @@ -9,6 +9,12 @@ #include "Etk_Engine_Ecore_Fb.h" #include "config.h" +/* TODO: Debug */ +#include <Ecore_X.h> +#define USE_X11 0 + +#define WM_THEME_FILE (PACKAGE_DATA_DIR "/wm/default.edj") + typedef Etk_Engine_Ecore_Fb_Window_Data Etk_Engine_Window_Data; /* General engine functions */ @@ -24,19 +30,27 @@ static void _window_show(Etk_Window *window); static void _window_hide(Etk_Window *window); static Evas *_window_evas_get(Etk_Window *window); +static void _window_title_set(Etk_Window *window, const char *title); +static const char *_window_title_get(Etk_Window *window); static void _window_move(Etk_Window *window, int x, int y); static void _window_resize(Etk_Window *window, int w, int h); static void _window_min_size_set(Etk_Window *window, int w, int h); static void _window_evas_position_get(Etk_Window *window, int *x, int *y); static void _window_screen_position_get(Etk_Window *window, int *x, int *y); +static void _window_maximized_set(Etk_Window *window, Etk_Bool maximized); +static Etk_Bool _window_maximized_get(Etk_Window *window); static void _window_size_get(Etk_Window *window, int *w, int *h); 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_decorated_set(Etk_Window *window, Etk_Bool decorated); +static Etk_Bool _window_decorated_get(Etk_Window *window); +static void _window_pointer_set(Etk_Window *window, Etk_Pointer_Type pointer_type); static void _window_realized_cb(Etk_Object *object, void *data); +static void _window_unrealized_cb(Etk_Object *object, void *data); static void _window_titlebar_mouse_down_cb(void *data, Evas_Object *obj, const char *emission, const char *source); static void _window_titlebar_mouse_up_cb(void *data, Evas_Object *obj, const char *emission, const char *source); @@ -45,18 +59,24 @@ static void _mouse_position_get(int *x, int *y); 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); +static int _mouse_move_X_handler_cb(void *data, int ev_type, void *ev); -/* Internal functions */ - +/* Private functions */ Etk_Window *_window_focus_find_other(Etk_Window *current); +static Etk_Cache *_pointer_cache_build(void); + /* Private vars */ static Ecore_Evas *_ecore_evas = NULL; static Evas *_evas = NULL; -static Evas_Object *_background_object = NULL; static int _fb_width = 0; static int _fb_height = 0; +static Evas_Object *_background_object = NULL; +static Evas_Object *_pointer_object = NULL; +static Etk_Cache *_pointer_cache = NULL; +static char *_pointer_group = NULL; + static void (*_event_callback)(Etk_Event_Type event, Etk_Event_Global event_info) = NULL; static int _mouse_x = 0; static int _mouse_y = 0; @@ -64,6 +84,8 @@ static int _window_drag_offset_x = 0; static int _window_drag_offset_y = 0; +static Etk_Window *_focused_window = NULL; + static Etk_Engine engine_info = { @@ -80,8 +102,8 @@ _window_show, _window_hide, _window_evas_get, - NULL, /* window_title_set */ - NULL, /* window_title_get */ + _window_title_set, + _window_title_get, NULL, /* window_wmclass_set */ _window_move, _window_resize, @@ -93,8 +115,8 @@ NULL, /* window_modal_for_window */ NULL, /* window_iconified_set */ NULL, /* window_iconified_get */ - NULL, /* window_maximized_set */ - NULL, /* window_maximized_get */ + _window_maximized_set, + _window_maximized_get, NULL, /* window_fullscreen_set */ NULL, /* window_fullscreen_get */ _window_raise, @@ -105,15 +127,15 @@ NULL, /* window_sticky_get */ _window_focused_set, _window_focused_get, - NULL, /* window_decorated_set */ - NULL, /* window_decorated_get */ + _window_decorated_set, + _window_decorated_get, NULL, /* window_shaped_set */ NULL, /* window_shaped_get */ NULL, /* window_skip_taskbar_hint_set */ NULL, /* window_skip_taskbar_hint_get */ NULL, /* window_skip_pager_hint_set */ NULL, /* window_skip_pager_hint_get */ - NULL, /* window_pointer_set */ + _window_pointer_set, NULL, /* popup_window_constructor */ NULL, /* popup_window_popup */ @@ -156,9 +178,28 @@ /* Initializes the engine */ static Etk_Bool _engine_init() { +#if USE_X11 + if (!ecore_x_init(NULL)) + { + ETK_WARNING("Ecore_X initialization failed!"); + return ETK_FALSE; + } + if (!ecore_evas_init()) + { + ETK_WARNING("Ecore_Evas initialization failed!"); + return ETK_FALSE; + } + + ecore_event_handler_add(ECORE_X_EVENT_MOUSE_MOVE, _mouse_move_X_handler_cb, NULL); + _fb_width = 1024; + _fb_height = 768; + + /* Create the evas where all the windows will be drawn */ + _ecore_evas = ecore_evas_software_x11_new(NULL, 0, 0, 0, _fb_width, _fb_height); +#else if (!ecore_fb_init(NULL)) { - ETK_WARNING("Ecore_Fb initialization failed!"); + ETK_WARNING("Ecore_FB initialization failed!"); return ETK_FALSE; } if (!ecore_evas_init()) @@ -166,11 +207,13 @@ ETK_WARNING("Ecore_Evas initialization failed!"); return ETK_FALSE; } + ecore_event_handler_add(ECORE_FB_EVENT_MOUSE_MOVE, _mouse_move_handler_cb, NULL); ecore_fb_size_get(&_fb_width, &_fb_height); /* Create the evas where all the windows will be drawn */ _ecore_evas = ecore_evas_fb_new(NULL, 0, _fb_width, _fb_height); +#endif if (!_ecore_evas) { ETK_WARNING("Unable to create a FB Ecore_Evas"); @@ -182,14 +225,20 @@ return ETK_FALSE; } - ecore_evas_cursor_set(_ecore_evas, PACKAGE_DATA_DIR "/pointers/default_pointer.png", 1000, 32, 32); ecore_evas_show(_ecore_evas); /* Create the background */ _background_object = edje_object_add(_evas); - etk_theme_edje_object_set(_background_object, etk_theme_widget_get(), "wm_background", NULL); + edje_object_file_set(_background_object, WM_THEME_FILE, "etk/wm_background"); evas_object_resize(_background_object, _fb_width, _fb_height); evas_object_show(_background_object); + + /* Cache the different mouse pointers and use the default one */ + _pointer_cache = _pointer_cache_build(); + _window_pointer_set(NULL, ETK_POINTER_DEFAULT); +#if USE_X11 + ecore_evas_cursor_set(_ecore_evas, "", 1000, 32, 32); +#endif return ETK_TRUE; } @@ -197,14 +246,16 @@ /* Shutdowns the engine */ static void _engine_shutdown() { + etk_cache_destroy(_pointer_cache); + free(_pointer_group); ecore_evas_free(_ecore_evas); - _ecore_evas = NULL; - _evas = NULL; - _background_object = NULL; - _window_dragged = NULL; ecore_evas_shutdown(); +#if USE_X11 + ecore_x_shutdown(); +#else ecore_fb_shutdown(); +#endif } /************************** @@ -218,7 +269,6 @@ { Etk_Engine_Window_Data *engine_data; - /* TODO: free? */ engine_data = malloc(sizeof(Etk_Engine_Window_Data)); engine_data->border_position.x = 0; engine_data->border_position.y = 0; @@ -227,11 +277,15 @@ engine_data->min_size.w = 0; engine_data->min_size.h = 0; engine_data->visible = ETK_FALSE; + engine_data->maximized = ETK_FALSE; + engine_data->title = NULL; + engine_data->borderless = ETK_FALSE; engine_data->border = NULL; window->engine_data = engine_data; ETK_TOPLEVEL(window)->evas = _evas; etk_signal_connect("realize", ETK_OBJECT(window), ETK_CALLBACK(_window_realized_cb), NULL); + etk_signal_connect("unrealize", ETK_OBJECT(window), ETK_CALLBACK(_window_unrealized_cb), NULL); } /* Cleans up the window */ @@ -242,12 +296,18 @@ engine_data = window->engine_data; - // move focus to another window if this was the focused one - if (window == engine_data->focused) + /* Move focus to another window if this was the focused one */ + if (window == _focused_window) { other = _window_focus_find_other(window); - if (other != NULL) _window_focused_set(other, ETK_TRUE); + if (other) + etk_window_focused_set(other, ETK_TRUE); + else + _focused_window = NULL; } + + free(engine_data->title); + free(engine_data); } /* Shows the window */ @@ -272,11 +332,14 @@ 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) + /* Move focus to another window if this was the focused one */ + if (window == _focused_window) { other = _window_focus_find_other(window); - if (other != NULL) _window_focused_set(other, ETK_TRUE); + if (other) + etk_window_focused_set(other, ETK_TRUE); + else + _focused_window = NULL; } } @@ -286,6 +349,33 @@ return _evas; } +/* Sets the title of the window */ +static void _window_title_set(Etk_Window *window, const char *title) +{ + Etk_Engine_Window_Data *engine_data; + + engine_data = window->engine_data; + if (engine_data->title != title) + { + free(engine_data->title); + engine_data->title = strdup(title); + + if (engine_data->border) + edje_object_part_text_set(engine_data->border, "etk.text.title", title ? title : ""); + + etk_object_notify(ETK_OBJECT(window), "title"); + } +} + +/* Returns the title of the window */ +static const char *_window_title_get(Etk_Window *window) +{ + Etk_Engine_Window_Data *engine_data; + + engine_data = window->engine_data; + return engine_data->title; +} + /* Moves the window at the given position */ static void _window_move(Etk_Window *window, int x, int y) { @@ -311,7 +401,7 @@ int border_w, border_h; edje_extern_object_min_size_set(ETK_WIDGET(window)->smart_object, engine_data->size.w, engine_data->size.h); - edje_object_part_swallow(engine_data->border, "content", ETK_WIDGET(window)->smart_object); + edje_object_part_swallow(engine_data->border, "etk.swallow.content", ETK_WIDGET(window)->smart_object); edje_object_size_min_calc(engine_data->border, &border_w, &border_h); evas_object_resize(engine_data->border, border_w, border_h); } @@ -372,6 +462,28 @@ if (h) *h = _fb_height; } +/* Sets whether or not the window is maximized */ +static void _window_maximized_set(Etk_Window *window, Etk_Bool maximized) +{ + Etk_Engine_Window_Data *engine_data; + + engine_data = window->engine_data; + if (engine_data->maximized != maximized) + { + engine_data->maximized = maximized; + etk_object_notify(ETK_OBJECT(window), "maximized"); + } +} + +/* Gets whether or not the window is maximized */ +Etk_Bool _window_maximized_get(Etk_Window *window) +{ + Etk_Engine_Window_Data *engine_data; + + engine_data = window->engine_data; + return engine_data->maximized; +} + /* Raises the window */ static void _window_raise(Etk_Window *window) { @@ -379,31 +491,26 @@ engine_data = window->engine_data; if (engine_data->border) + { evas_object_raise(engine_data->border); + if (_pointer_object) + evas_object_raise(_pointer_object); + } } /* Lowers the window */ 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. -*/ + * 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; @@ -412,17 +519,18 @@ engine_data = window->engine_data; if (focused) { - engine_data->focused = window; + _focused_window = 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. + if (_focused_window != window) + return; other = _window_focus_find_other(window); - if (other != NULL) + if (other) { - engine_data->focused = other; + _focused_window = other; evas_object_focus_set(ETK_WIDGET(other)->smart_object, 1); } } @@ -431,11 +539,108 @@ /* Is this window the current focused window in the system ? */ Etk_Bool _window_focused_get(Etk_Window *window) { + return (_focused_window == window); +} + +/* Sets whether or not the window is decorated (i.e. the window has a border) */ +static void _window_decorated_set(Etk_Window *window, Etk_Bool decorated) +{ Etk_Engine_Window_Data *engine_data; engine_data = window->engine_data; - if (engine_data->focused == window) return ETK_TRUE; - else return ETK_FALSE; + if (engine_data->borderless == !decorated) + return; + + engine_data->borderless = !decorated; + if (engine_data->border) + { + /* Recreate the border */ + _window_unrealized_cb(ETK_OBJECT(window), NULL); + _window_realized_cb(ETK_OBJECT(window), NULL); + } + etk_object_notify(ETK_OBJECT(window), "decorated"); +} + +/* Gets whether or not the window is decorated */ +static Etk_Bool _window_decorated_get(Etk_Window *window) +{ + Etk_Engine_Window_Data *engine_data; + + engine_data = window->engine_data; + return !engine_data->borderless; +} + +/* Sets the mouse pointer to use */ +static void _window_pointer_set(Etk_Window *window, Etk_Pointer_Type pointer_type) +{ + char *group; + + switch (pointer_type) + { + case ETK_POINTER_DND_DROP: + group = "etk/wm_pointer_dnd_drop"; + break; + case ETK_POINTER_MOVE: + group = "etk/wm_pointer_dnd_move"; + break; + case ETK_POINTER_H_DOUBLE_ARROW: + group = "etk/wm_pointer_h_double_arrow"; + break; + case ETK_POINTER_V_DOUBLE_ARROW: + group = "etk/wm_pointer_v_double_arrow"; + break; + case ETK_POINTER_RESIZE: + group = "etk/wm_pointer_resize"; + break; + case ETK_POINTER_RESIZE_TL: + group = "etk/wm_pointer_resize_tl"; + break; + case ETK_POINTER_RESIZE_T: + group = "etk/wm_pointer_resize_t"; + break; + case ETK_POINTER_RESIZE_TR: + group = "etk/wm_pointer_resize_tr"; + break; + case ETK_POINTER_RESIZE_R: + group = "etk/wm_pointer_resize_r"; + break; + case ETK_POINTER_RESIZE_BR: + group = "etk/wm_pointer_resize_br"; + break; + case ETK_POINTER_RESIZE_B: + group = "etk/wm_pointer_resize_b"; + break; + case ETK_POINTER_RESIZE_BL: + group = "etk/wm_pointer_resize_bl"; + break; + case ETK_POINTER_RESIZE_L: + group = "etk/wm_pointer_resize_l"; + break; + case ETK_POINTER_TEXT_EDIT: + group = "etk/wm_pointer_text_edit"; + break; + case ETK_POINTER_DEFAULT: + default: + group = "etk/wm_pointer_default"; + break; + } + + if (_pointer_object) + etk_cache_add(_pointer_cache, _pointer_object, WM_THEME_FILE, _pointer_group); + free(_pointer_group); + _pointer_group = NULL; + + if ((_pointer_object = etk_cache_find(_pointer_cache, WM_THEME_FILE, group))) + _pointer_group = strdup(group); + else if ((_pointer_object = etk_cache_find(_pointer_cache, WM_THEME_FILE, "etk/wm_pointer_default"))) + _pointer_group = strdup("etk/wm_pointer_default"); + + if (_pointer_object) + { + evas_object_move(_pointer_object, _mouse_x, _mouse_y); + evas_object_show(_pointer_object); + evas_object_raise(_pointer_object); + } } /************************** @@ -468,31 +673,6 @@ /************************** * - * 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; -} - -/************************** - * * Handlers and callbacks * **************************/ @@ -509,9 +689,14 @@ engine_data = window->engine_data; engine_data->border = edje_object_add(_evas); - etk_theme_edje_object_set(engine_data->border, etk_widget_theme_file_get(ETK_WIDGET(window)), "wm_border", NULL); + if (engine_data->borderless) + edje_object_file_set(engine_data->border, WM_THEME_FILE, "etk/wm_borderless"); + else + edje_object_file_set(engine_data->border, WM_THEME_FILE, "etk/wm_border"); + edje_object_part_text_set(engine_data->border, "etk.text.title", engine_data->title ? engine_data->title : ""); + edje_extern_object_min_size_set(ETK_WIDGET(window)->smart_object, engine_data->size.w, engine_data->size.h); - edje_object_part_swallow(engine_data->border, "content", ETK_WIDGET(window)->smart_object); + edje_object_part_swallow(engine_data->border, "etk.swallow.content", ETK_WIDGET(window)->smart_object); edje_object_size_min_calc(engine_data->border, &border_w, &border_h); evas_object_move(engine_data->border, engine_data->border_position.x, engine_data->border_position.y); @@ -519,8 +704,30 @@ if (engine_data->visible) evas_object_show(engine_data->border); - edje_object_signal_callback_add(engine_data->border, "mouse,down,1*", "titlebar", _window_titlebar_mouse_down_cb, window); - edje_object_signal_callback_add(engine_data->border, "mouse,up,1*", "titlebar", _window_titlebar_mouse_up_cb, window); + edje_object_signal_callback_add(engine_data->border, "mouse,down,1*", "etk.event.titlebar", + _window_titlebar_mouse_down_cb, window); + edje_object_signal_callback_add(engine_data->border, "mouse,up,1*", "etk.event.titlebar", + _window_titlebar_mouse_up_cb, window); + + if (_pointer_object) + evas_object_raise(_pointer_object); +} + +/* Called when the window is unrealized: it destroys the border */ +static void _window_unrealized_cb(Etk_Object *object, void *data) +{ + Etk_Window *window; + Etk_Engine_Window_Data *engine_data; + + if (!(window = ETK_WINDOW(object))) + return; + engine_data = window->engine_data; + + if (engine_data->border) + { + evas_object_del(engine_data->border); + engine_data->border = NULL; + } } /* Called when the titlebar of the window is pressed */ @@ -553,6 +760,8 @@ _mouse_x = event->x; _mouse_y = event->y; + if (_pointer_object) + evas_object_move(_pointer_object, _mouse_x, _mouse_y); /* Move the window to drag */ if (_window_dragged) @@ -561,4 +770,75 @@ return 1; } +/* Called when the mouse is moved (X11 debug version) */ +static int _mouse_move_X_handler_cb(void *data, int ev_type, void *ev) +{ + Ecore_X_Event_Mouse_Move *event = ev; + + _mouse_x = event->x; + _mouse_y = event->y; + if (_pointer_object) + evas_object_move(_pointer_object, _mouse_x, _mouse_y); + + /* Move the window to drag */ + if (_window_dragged) + etk_window_move(_window_dragged, _mouse_x - _window_drag_offset_x, _mouse_y - _window_drag_offset_y); + + return 1; +} + +/************************** + * + * Private functions + * + **************************/ + +/* Find a window to focus that is different from the current one */ +/* TODO: 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; + + /* We 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; +} +/* Cache the different mouse pointers */ +static Etk_Cache *_pointer_cache_build(void) +{ + Etk_Cache *cache; + Evas_List *groups, *l; + Evas_Object *pointer; + char *group; + int w, h; + + cache = etk_cache_new(50); + groups = edje_file_collection_list(WM_THEME_FILE); + for (l = groups; l; l = l->next) + { + group = l->data; + if (strncmp(group, "etk/wm_pointer_", 15) == 0) + { + pointer = edje_object_add(_evas); + evas_object_pass_events_set(pointer, 1); + + edje_object_file_set(pointer, WM_THEME_FILE, group); + edje_object_size_min_get(pointer, &w, &h); + evas_object_resize(pointer, w, h); + etk_cache_add(cache, pointer, WM_THEME_FILE, group); + } + } + edje_file_collection_list_free(groups); + + return cache; +} ------------------------------------------------------------------------- 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