Hello! Carsten Haitzler (The Rasterman) wrote: >that depends on the quality of the code/patches and how well it's done :) we >can't pre-approve things that haven't been done yet :) you also will be in a >race-condition of who gets to doing it "right" first :) > > I try to make an aproveable patch :) Please If it is not aproveable, then describe me the errors, what I did. Thank You! I try to make a key binding for windows (stick, hide, close, maximize, iconify, shade...), and this settings save with e_config.c (~/.e/e/config/e.cfg). Bye Godzzo
Index: apps/e/src/bin/e_border.c =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_border.c,v retrieving revision 1.147 diff -u -r1.147 e_border.c --- apps/e/src/bin/e_border.c 22 Apr 2005 20:17:25 -0000 1.147 +++ apps/e/src/bin/e_border.c 23 Apr 2005 09:03:48 -0000 @@ -56,6 +56,7 @@ static int _e_border_cb_mouse_move(void *data, int type, void *event); static int _e_border_cb_mouse_wheel(void *data, int type, void *event); static int _e_border_cb_grab_replay(void *data, int type, void *event); +static int _e_border_cb_key_down (void *data, int type, void *event); static void _e_border_eval(E_Border *bd); static void _e_border_resize_limit(E_Border *bd, int *w, int *h); @@ -205,6 +206,7 @@ Ecore_X_Window_Attributes *att; Evas_List *list; E_Config_Binding *eb; + E_Config_Key_Binding *ekb; Ecore_X_Window mwin; unsigned int managed, desk[2]; int deskx, desky; @@ -237,6 +239,15 @@ eb->modifiers, 0); } + /* Key Bindings */ + for (list = e_config->key_bindings; list; list = list->next) + { + ekb = list->data; + printf("GODZZO KEY BINDING %s, %d \n", ekb->key, ekb->modifiers); + ecore_x_key_grab(bd->win, + ekb->key, + ekb->modifiers); + } bd->bg_ecore_evas = ecore_evas_software_x11_new(NULL, bd->win, 0, 0, bd->w, bd->h); ecore_evas_software_x11_direct_resize_set(bd->bg_ecore_evas, 1); e_canvas_add(bd->bg_ecore_evas); @@ -268,6 +279,7 @@ bd->handlers = evas_list_append(bd->handlers, ecore_event_handler_add(ECORE_X_EVENT_MOUSE_BUTTON_UP, _e_border_cb_mouse_up, bd)); bd->handlers = evas_list_append(bd->handlers, ecore_event_handler_add(ECORE_X_EVENT_MOUSE_MOVE, _e_border_cb_mouse_move, bd)); bd->handlers = evas_list_append(bd->handlers, ecore_event_handler_add(ECORE_X_EVENT_MOUSE_WHEEL, _e_border_cb_mouse_wheel, bd)); + bd->handlers = evas_list_append(bd->handlers, ecore_event_handler_add(ECORE_X_EVENT_KEY_DOWN, _e_border_cb_key_down, bd)); bd->client.win = win; @@ -1149,6 +1161,7 @@ { Evas_List *list; E_Config_Binding *eb; + E_Config_Key_Binding *ekb; if (resize == bd) _e_border_resize_end(bd); @@ -1197,6 +1210,14 @@ eb->modifiers, 0); } + /* Key Bindings */ + for (list = e_config->key_bindings; list; list = list->next) + { + ekb = list->data; + ecore_x_key_ungrab(bd->win, + ekb->key, + ekb->modifiers); + } ecore_x_window_del(bd->win); bd->container->clients = evas_list_remove(bd->container->clients, bd); @@ -1941,6 +1962,65 @@ } static int +_e_border_cb_key_down(void *data, int type, void *event) +{ + Ecore_X_Event_Key_Down *ev; + E_Border *bd; + int intNewPos; + E_Desk *desk; + E_Config_Key_Binding *ekb; + Evas_List *list; + + + ev = event; + bd = data; + + if (ev->event_win != bd->win) + return 1; + + for (list = e_config->key_bindings; list; list = list->next) + { + ekb = list->data; + + if (!strcmp(ev->keyname, ekb->key) && ev->modifiers == ekb->modifiers) + { + switch (ekb->action) + { + case E_KEY_BINDING_ACTION_WINDOW_STICK: + if (bd->sticky) e_border_unstick(bd); + else e_border_stick(bd); + break; + case E_KEY_BINDING_ACTION_WINDOW_SHADE: + if (bd->shaded) e_border_unshade(bd, E_DIRECTION_UP); + else e_border_shade(bd, E_DIRECTION_UP); + break; + case E_KEY_BINDING_ACTION_WINDOW_ICONIFY: + if (bd->maximized) e_border_uniconify(bd); + else e_border_iconify(bd); + break; + case E_KEY_BINDING_ACTION_WINDOW_MENU: + _e_border_menu_show(bd, bd->x, bd->y); + break; + case E_KEY_BINDING_ACTION_WINDOW_ICON_EDIT: + _e_border_menu_cb_icon_edit(bd, NULL, NULL); + break; + case E_KEY_BINDING_ACTION_WINDOW_MAXIMIZE: + if (bd->maximized) e_border_unmaximize(bd); + else e_border_maximize(bd); + break; + case E_KEY_BINDING_ACTION_WINDOW_CLOSE: + _e_border_menu_cb_close(bd, NULL, NULL); + break; + } + + } + } + + + return 1; +} + +static int _e_border_cb_mouse_in(void *data, int type, void *event) { Ecore_X_Event_Mouse_In *ev; Index: apps/e/src/bin/e_config.c =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_config.c,v retrieving revision 1.29 diff -u -r1.29 e_config.c --- apps/e/src/bin/e_config.c 19 Apr 2005 06:04:33 -0000 1.29 +++ apps/e/src/bin/e_config.c 23 Apr 2005 09:03:48 -0000 @@ -25,6 +25,7 @@ static E_Config_DD *_e_config_edd = NULL; static E_Config_DD *_e_config_module_edd = NULL; static E_Config_DD *_e_config_binding_edd = NULL; +static E_Config_DD *_e_config_key_binding_edd = NULL; static E_Config_DD *_e_config_font_fallback_edd = NULL; static E_Config_DD *_e_config_font_default_edd = NULL; @@ -50,6 +51,15 @@ E_CONFIG_VAL(D, T, modifiers, INT); E_CONFIG_VAL(D, T, action, INT); + _e_config_key_binding_edd = E_CONFIG_DD_NEW("E_Config_Key_Binding", E_Config_Key_Binding); +#undef T +#undef D +#define T E_Config_Key_Binding +#define D _e_config_key_binding_edd + E_CONFIG_VAL(D, T, key, STR); + E_CONFIG_VAL(D, T, modifiers, INT); + E_CONFIG_VAL(D, T, action, INT); + _e_config_font_default_edd = E_CONFIG_DD_NEW("E_Font_Default", E_Font_Default); #undef T @@ -87,6 +97,7 @@ E_CONFIG_VAL(D, T, zone_desks_y_count, INT); E_CONFIG_LIST(D, T, modules, _e_config_module_edd); E_CONFIG_LIST(D, T, bindings, _e_config_binding_edd); + E_CONFIG_LIST(D, T, key_bindings, _e_config_key_binding_edd); E_CONFIG_LIST(D, T, font_fallbacks, _e_config_font_fallback_edd); E_CONFIG_LIST(D, T, font_defaults, _e_config_font_default_edd); @@ -169,6 +180,51 @@ e_config->bindings = evas_list_append(e_config->bindings, eb); } { + E_Config_Key_Binding *ekb; + + ekb = E_NEW(E_Config_Key_Binding, 1); + ekb->key = "F10"; + ekb->modifiers = ECORE_X_MODIFIER_ALT; + ekb->action = E_KEY_BINDING_ACTION_WINDOW_STICK; + e_config->key_bindings = evas_list_append(e_config->key_bindings, ekb); + + ekb = E_NEW(E_Config_Key_Binding, 1); + ekb->key = "F9"; + ekb->modifiers = ECORE_X_MODIFIER_ALT; + ekb->action = E_KEY_BINDING_ACTION_WINDOW_SHADE; + e_config->key_bindings = evas_list_append(e_config->key_bindings, ekb); + + ekb = E_NEW(E_Config_Key_Binding, 1); + ekb->key = "F8"; + ekb->modifiers = ECORE_X_MODIFIER_ALT; + ekb->action = E_KEY_BINDING_ACTION_WINDOW_ICONIFY; + e_config->key_bindings = evas_list_append(e_config->key_bindings, ekb); + + ekb = E_NEW(E_Config_Key_Binding, 1); + ekb->key = "F7"; + ekb->modifiers = ECORE_X_MODIFIER_ALT; + ekb->action = E_KEY_BINDING_ACTION_WINDOW_MENU; + e_config->key_bindings = evas_list_append(e_config->key_bindings, ekb); + + ekb = E_NEW(E_Config_Key_Binding, 1); + ekb->key = "F6"; + ekb->modifiers = ECORE_X_MODIFIER_ALT; + ekb->action = E_KEY_BINDING_ACTION_WINDOW_ICON_EDIT; + e_config->key_bindings = evas_list_append(e_config->key_bindings, ekb); + + ekb = E_NEW(E_Config_Key_Binding, 1); + ekb->key = "F5"; + ekb->modifiers = ECORE_X_MODIFIER_ALT; + ekb->action = E_KEY_BINDING_ACTION_WINDOW_MAXIMIZE; + e_config->key_bindings = evas_list_append(e_config->key_bindings, ekb); + + ekb = E_NEW(E_Config_Key_Binding, 1); + ekb->key = "F4"; + ekb->modifiers = ECORE_X_MODIFIER_ALT; + ekb->action = E_KEY_BINDING_ACTION_WINDOW_CLOSE; + e_config->key_bindings = evas_list_append(e_config->key_bindings, ekb); + } + { E_Font_Fallback* eff; eff = E_NEW(E_Font_Fallback, 1); @@ -229,6 +285,14 @@ e_config->bindings = evas_list_remove_list(e_config->bindings, e_config->bindings); E_FREE(eb); } + while (e_config->key_bindings) + { + E_Config_Key_Binding *ekb; + + ekb = e_config->key_bindings->data; + e_config->key_bindings = evas_list_remove_list(e_config->key_bindings, e_config->key_bindings); + E_FREE(ekb); + } while (e_config->font_fallbacks) { E_Font_Fallback *eff; Index: apps/e/src/bin/e_config.h =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/e/src/bin/e_config.h,v retrieving revision 1.12 diff -u -r1.12 e_config.h --- apps/e/src/bin/e_config.h 2 Apr 2005 16:40:30 -0000 1.12 +++ apps/e/src/bin/e_config.h 23 Apr 2005 09:03:49 -0000 @@ -34,6 +34,7 @@ typedef struct _E_Config E_Config; typedef struct _E_Config_Module E_Config_Module; typedef struct _E_Config_Binding E_Config_Binding; +typedef struct _E_Config_Key_Binding E_Config_Key_Binding; typedef Eet_Data_Descriptor E_Config_DD; typedef enum _E_Binding_Action @@ -43,6 +44,17 @@ E_BINDING_ACTION_MENU } E_Binding_Action; +typedef enum _E_Key_Binding_Action +{ + E_KEY_BINDING_ACTION_WINDOW_STICK, + E_KEY_BINDING_ACTION_WINDOW_SHADE, + E_KEY_BINDING_ACTION_WINDOW_ICONIFY, + E_KEY_BINDING_ACTION_WINDOW_MENU, + E_KEY_BINDING_ACTION_WINDOW_ICON_EDIT, + E_KEY_BINDING_ACTION_WINDOW_MAXIMIZE, + E_KEY_BINDING_ACTION_WINDOW_CLOSE +} E_Key_Binding_Action; + #else #ifndef E_CONFIG_H #define E_CONFIG_H @@ -64,6 +76,7 @@ int use_virtual_roots; Evas_List *modules; Evas_List *bindings; + Evas_List *key_bindings; Evas_List *font_fallbacks; Evas_List *font_defaults; }; @@ -83,6 +96,14 @@ }; +struct _E_Config_Key_Binding +{ + char *key; + int modifiers; + E_Key_Binding_Action action; + +}; + EAPI int e_config_init(void); EAPI int e_config_shutdown(void); Index: libs/ecore/src/lib/ecore_x/Ecore_X.h =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/Ecore_X.h,v retrieving revision 1.108 diff -u -r1.108 Ecore_X.h --- libs/ecore/src/lib/ecore_x/Ecore_X.h 22 Apr 2005 08:46:04 -0000 1.108 +++ libs/ecore/src/lib/ecore_x/Ecore_X.h 23 Apr 2005 09:04:02 -0000 @@ -1233,6 +1233,8 @@ EAPI int ecore_x_pointer_warp(Ecore_X_Window win, int x, int y); EAPI int ecore_x_keyboard_grab(Ecore_X_Window win); EAPI void ecore_x_keyboard_ungrab(void); +EAPI int ecore_x_key_grab(Ecore_X_Window win, const char *key, unsigned int modifiers); +EAPI int ecore_x_key_ungrab(Ecore_X_Window win, const char *key, unsigned int modifiers); EAPI void ecore_x_grab(void); EAPI void ecore_x_ungrab(void); EAPI void ecore_x_passive_grab_replay_func_set(int (*func) (void *data, int event_type, void *event), void *data); Index: libs/ecore/src/lib/ecore_x/ecore_x.c =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_x/ecore_x.c,v retrieving revision 1.71 diff -u -r1.71 ecore_x.c --- libs/ecore/src/lib/ecore_x/ecore_x.c 22 Apr 2005 08:46:05 -0000 1.71 +++ libs/ecore/src/lib/ecore_x/ecore_x.c 23 Apr 2005 09:04:05 -0000 @@ -1295,6 +1295,27 @@ XUngrabKeyboard(_ecore_x_disp, CurrentTime); } +int +ecore_x_key_grab(Ecore_X_Window win, const char *key, unsigned int modifiers) +{ + int keycode; + + keycode = XKeysymToKeycode(_ecore_x_disp, XStringToKeysym(key)); + + return XGrabKey(_ecore_x_disp, keycode, modifiers, win, + False, GrabModeAsync, GrabModeAsync); +} + +int +ecore_x_key_ungrab(Ecore_X_Window win, const char *key, unsigned int modifiers) +{ + int keycode; + + keycode = XKeysymToKeycode(_ecore_x_disp, XStringToKeysym(key)); + + return XUngrabKey(_ecore_x_disp, keycode, modifiers, win); +} + void ecore_x_grab(void) {
patch2.tbz2
Description: Binary data