From 48c4ea17f2d71486e0462eb0ec5547fe752b832c Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Wed, 4 Sep 2019 19:17:12 +0100 Subject: [PATCH] e - fix up resize/move by kbd to work again this used to work years ago ... it seems tihave broken. this fixes it all up to work again so you can bind a move/resize of a window tothe kbd and then use arrow keys etc. like you used to.... @fix --- src/bin/e_actions.c | 41 +++++++++----- src/bin/e_client.c | 122 ++++++++++++++++++---------------------- src/bin/e_comp_object.c | 16 ++++-- src/bin/e_utils.c | 34 +++++++++++ src/bin/e_utils.h | 10 ++++ 5 files changed, 138 insertions(+), 85 deletions(-) diff --git a/src/bin/e_actions.c b/src/bin/e_actions.c index bdf823172..f0b954007 100644 --- a/src/bin/e_actions.c +++ b/src/bin/e_actions.c @@ -103,7 +103,8 @@ ACT_FN_GO(window_move, EINA_UNUSED) ACT_FN_GO_MOUSE(window_move, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return EINA_FALSE; if (obj->type != E_CLIENT_TYPE) return EINA_FALSE; e_client_act_move_begin((E_Client *)(void *)obj, ev); @@ -112,7 +113,8 @@ ACT_FN_GO_MOUSE(window_move, EINA_UNUSED) ACT_FN_GO_SIGNAL(window_move, ) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return; if (obj->type != E_CLIENT_TYPE) return; if (!((E_Client *)(void *)obj)->lock_user_location) @@ -129,7 +131,8 @@ ACT_FN_GO_SIGNAL(window_move, ) ACT_FN_END(window_move, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return; if (obj->type != E_CLIENT_TYPE) return; e_client_act_move_end((E_Client *)(void *)obj, NULL); @@ -137,7 +140,8 @@ ACT_FN_END(window_move, EINA_UNUSED) ACT_FN_END_MOUSE(window_move, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return EINA_FALSE; if (obj->type != E_CLIENT_TYPE) return EINA_FALSE; e_client_act_move_end((E_Client *)(void *)obj, ev); @@ -146,7 +150,8 @@ ACT_FN_END_MOUSE(window_move, EINA_UNUSED) ACT_FN_GO_KEY(window_move, EINA_UNUSED, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return; if (!((E_Client *)(void *)obj)->lock_user_location) e_client_act_move_keyboard((E_Client *)(void *)obj); @@ -164,7 +169,8 @@ ACT_FN_GO(window_resize, EINA_UNUSED) ACT_FN_GO_MOUSE(window_resize, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return EINA_FALSE; if (obj->type != E_CLIENT_TYPE) return EINA_FALSE; if (!((E_Client *)(void *)obj)->lock_user_size) @@ -174,7 +180,8 @@ ACT_FN_GO_MOUSE(window_resize, EINA_UNUSED) ACT_FN_GO_SIGNAL(window_resize, ) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return; if (obj->type != E_CLIENT_TYPE) return; if (!((E_Client *)(void *)obj)->lock_user_size) @@ -194,7 +201,8 @@ ACT_FN_GO_SIGNAL(window_resize, ) ACT_FN_END(window_resize, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return; if (obj->type != E_CLIENT_TYPE) return; e_client_act_resize_end((E_Client *)(void *)obj, NULL); @@ -202,7 +210,8 @@ ACT_FN_END(window_resize, EINA_UNUSED) ACT_FN_END_MOUSE(window_resize, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return EINA_FALSE; if (obj->type != E_CLIENT_TYPE) return EINA_FALSE; e_client_act_resize_end((E_Client *)(void *)obj, ev); @@ -211,7 +220,8 @@ ACT_FN_END_MOUSE(window_resize, EINA_UNUSED) ACT_FN_GO_KEY(window_resize, EINA_UNUSED, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return; if (obj->type != E_CLIENT_TYPE) { @@ -233,7 +243,8 @@ ACT_FN_GO(window_menu, EINA_UNUSED) ACT_FN_GO_MOUSE(window_menu, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return EINA_FALSE; if (obj->type != E_CLIENT_TYPE) { @@ -246,7 +257,8 @@ ACT_FN_GO_MOUSE(window_menu, EINA_UNUSED) ACT_FN_GO_KEY(window_menu, EINA_UNUSED, EINA_UNUSED) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return; if (obj->type != E_CLIENT_TYPE) { @@ -833,7 +845,8 @@ ACT_FN_GO(window_pinned_toggle, EINA_UNUSED) /***************************************************************************/ ACT_FN_GO(window_move_by, ) { - if (!obj) obj = E_OBJECT(e_client_focused_get()); + if ((!obj) || (obj->type != E_CLIENT_TYPE)) + obj = E_OBJECT(e_client_focused_get()); if (!obj) return; if (obj->type != E_CLIENT_TYPE) { @@ -912,9 +925,9 @@ ACT_FN_GO(window_quick_tile_to_quadrant, ) { E_Client *ec; int x, y, zx, zy, zw, zh; + if ((!obj) || (obj->type != E_CLIENT_TYPE)) obj = E_OBJECT(e_client_focused_get()); - if (!obj) return; ec = (E_Client *)(void *)obj; diff --git a/src/bin/e_client.c b/src/bin/e_client.c index 9c592493b..e6b2ff795 100644 --- a/src/bin/e_client.c +++ b/src/bin/e_client.c @@ -820,15 +820,12 @@ _e_client_action_restore_orig(E_Client *ec) static int _e_client_key_down_modifier_apply(int modifier, int value) { - if (modifier & ECORE_EVENT_MODIFIER_CTRL) - return value * 2; + if (modifier & ECORE_EVENT_MODIFIER_CTRL) return value * 5; else if (modifier & ECORE_EVENT_MODIFIER_ALT) { - value /= 2; - if (value) - return value; - else - return 1; + value /= 5; + if (value) return value; + else return 1; } return value; @@ -897,16 +894,17 @@ _e_client_action_move_timeout(void *data EINA_UNUSED) static void _e_client_action_move_timeout_add(void) { + double timeout = e_config->border_keyboard.timeout; E_FREE_FUNC(action_timer, ecore_timer_del); - if (EINA_DBL_NONZERO(e_config->border_keyboard.timeout)) - action_timer = ecore_timer_loop_add(e_config->border_keyboard.timeout, _e_client_action_move_timeout, NULL); + if (!EINA_DBL_NONZERO(timeout)) timeout = 5.0; + action_timer = ecore_timer_loop_add(timeout, _e_client_action_move_timeout, NULL); } static Eina_Bool _e_client_move_key_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) { Ecore_Event_Key *ev = event; - int x, y; + int x, y, dx, dy; if (!comp_grabbed) return ECORE_CALLBACK_RENEW; if (!action_client) @@ -918,27 +916,28 @@ _e_client_move_key_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *even x = action_client->x; y = action_client->y; - if ((strcmp(ev->key, "Up") == 0) || (strcmp(ev->key, "k") == 0)) - y -= _e_client_key_down_modifier_apply(ev->modifiers, MAX(e_config->border_keyboard.move.dy, 1)); - else if ((strcmp(ev->key, "Down") == 0) || (strcmp(ev->key, "j") == 0)) - y += _e_client_key_down_modifier_apply(ev->modifiers, MAX(e_config->border_keyboard.move.dy, 1)); - else if ((strcmp(ev->key, "Left") == 0) || (strcmp(ev->key, "h") == 0)) - x -= _e_client_key_down_modifier_apply(ev->modifiers, MAX(e_config->border_keyboard.move.dx, 1)); - else if ((strcmp(ev->key, "Right") == 0) || (strcmp(ev->key, "l") == 0)) - x += _e_client_key_down_modifier_apply(ev->modifiers, MAX(e_config->border_keyboard.move.dx, 1)); - else if (strcmp(ev->key, "Return") == 0) - goto stop; - else if (strcmp(ev->key, "Escape") == 0) + dx = e_config->border_keyboard.move.dx; + dx = _e_client_key_down_modifier_apply(ev->modifiers, dx); + dy = e_config->border_keyboard.move.dy; + dy = _e_client_key_down_modifier_apply(ev->modifiers, dy); + + switch (e_util_key_geometry_action_get(ev->key, &x, &y, dx, dy)) { + case E_UTIL_ACTION_DONE: + goto stop; + break; + case E_UTIL_ACTION_ABORT: _e_client_action_restore_orig(action_client); goto stop; + break; + case E_UTIL_ACTION_DO: + evas_object_move(action_client->frame, x, y); + _e_client_action_move_timeout_add(); + break; + case E_UTIL_ACTION_NONE: + default: + break; } - else if ((strncmp(ev->key, "Control", sizeof("Control") - 1) != 0) && - (strncmp(ev->key, "Alt", sizeof("Alt") - 1) != 0)) - goto stop; - - evas_object_move(action_client->frame, x, y); - _e_client_action_move_timeout_add(); return ECORE_CALLBACK_PASS_ON; @@ -1118,9 +1117,10 @@ _e_client_action_resize_timeout(void *data EINA_UNUSED) static void _e_client_action_resize_timeout_add(void) { + double timeout = e_config->border_keyboard.timeout; E_FREE_FUNC(action_timer, ecore_timer_del); - if (EINA_DBL_NONZERO(e_config->border_keyboard.timeout)) - action_timer = ecore_timer_loop_add(e_config->border_keyboard.timeout, _e_client_action_resize_timeout, NULL); + if (!EINA_DBL_NONZERO(timeout)) timeout = 5.0; + action_timer = ecore_timer_loop_add(timeout, _e_client_action_resize_timeout, NULL); } static Eina_Bool @@ -1140,48 +1140,41 @@ _e_client_resize_key_down(void *data EINA_UNUSED, int type EINA_UNUSED, void *ev h = action_client->h; dx = e_config->border_keyboard.resize.dx; - if (dx < action_client->icccm.step_w) - dx = action_client->icccm.step_w; + if (dx < action_client->icccm.step_w) dx = action_client->icccm.step_w; dx = _e_client_key_down_modifier_apply(ev->modifiers, dx); - if (dx < action_client->icccm.step_w) - dx = action_client->icccm.step_w; + if (dx < action_client->icccm.step_w) dx = action_client->icccm.step_w; dy = e_config->border_keyboard.resize.dy; - if (dy < action_client->icccm.step_h) - dy = action_client->icccm.step_h; + if (dy < action_client->icccm.step_h) dy = action_client->icccm.step_h; dy = _e_client_key_down_modifier_apply(ev->modifiers, dy); - if (dy < action_client->icccm.step_h) - dy = action_client->icccm.step_h; + if (dy < action_client->icccm.step_h) dy = action_client->icccm.step_h; - if ((strcmp(ev->key, "Up") == 0) || (strcmp(ev->key, "k") == 0)) - h -= dy; - else if ((strcmp(ev->key, "Down") == 0) || (strcmp(ev->key, "j") == 0)) - h += dy; - else if ((strcmp(ev->key, "Left") == 0) || (strcmp(ev->key, "h") == 0)) - w -= dx; - else if ((strcmp(ev->key, "Right") == 0) || (strcmp(ev->key, "l") == 0)) - w += dx; - else if (strcmp(ev->key, "Return") == 0) - goto stop; - else if (strcmp(ev->key, "Escape") == 0) + switch (e_util_key_geometry_action_get(ev->key, &w, &h, dx, dy)) { + case E_UTIL_ACTION_DONE: + goto stop; + break; + case E_UTIL_ACTION_ABORT: _e_client_action_restore_orig(action_client); goto stop; - } - else if ((strncmp(ev->key, "Control", sizeof("Control") - 1) != 0) && - (strncmp(ev->key, "Alt", sizeof("Alt") - 1) != 0)) - goto stop; - if (e_config->screen_limits == E_CLIENT_OFFSCREEN_LIMIT_ALLOW_NONE) - { - if (action_client->zone) + break; + case E_UTIL_ACTION_DO: + if (e_config->screen_limits == E_CLIENT_OFFSCREEN_LIMIT_ALLOW_NONE) { - w = MIN(w, action_client->zone->w); - h = MIN(h, action_client->zone->h); + if (action_client->zone) + { + w = MIN(w, action_client->zone->w); + h = MIN(h, action_client->zone->h); + } } + e_client_resize_limit(action_client, &w, &h); + evas_object_resize(action_client->frame, w, h); + _e_client_action_resize_timeout_add(); + break; + case E_UTIL_ACTION_NONE: + default: + break; } - e_client_resize_limit(action_client, &w, &h); - evas_object_resize(action_client->frame, w, h); - _e_client_action_resize_timeout_add(); return ECORE_CALLBACK_PASS_ON; @@ -2427,7 +2420,6 @@ e_client_idler_before(void) if ((!eina_hash_population(clients_hash[0])) && (!eina_hash_population(clients_hash[1]))) return; - EINA_LIST_FOREACH(e_comp->clients, l, ec) { Eina_Stringshare *title; @@ -4870,17 +4862,15 @@ e_client_act_move_keyboard(E_Client *ec) if (!_e_client_move_begin(ec)) return; - _e_client_action_init(ec); - _e_client_action_move_timeout_add(); if (!_e_client_hook_call(E_CLIENT_HOOK_MOVE_UPDATE, ec)) return; - evas_object_freeze_events_set(ec->frame, 1); if (!action_handler_key) action_handler_key = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _e_client_move_key_down, NULL); if (!action_handler_mouse) action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_move_mouse_down, NULL); + _e_client_action_move_timeout_add(); } E_API void @@ -4896,16 +4886,14 @@ e_client_act_resize_keyboard(E_Client *ec) ec->keyboard_resizing = 0; return; } - _e_client_action_init(ec); - _e_client_action_resize_timeout_add(); - evas_object_freeze_events_set(ec->frame, 1); if (!action_handler_key) action_handler_key = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, _e_client_resize_key_down, NULL); if (!action_handler_mouse) action_handler_mouse = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _e_client_resize_mouse_down, NULL); + _e_client_action_resize_timeout_add(); } E_API void diff --git a/src/bin/e_comp_object.c b/src/bin/e_comp_object.c index 4b3d4db00..2c9423c18 100644 --- a/src/bin/e_comp_object.c +++ b/src/bin/e_comp_object.c @@ -292,10 +292,18 @@ _e_comp_object_layers_add(E_Comp_Object *cw, E_Comp_Object *above, E_Comp_Object if (!cw->ec) return; */ if (above) - e_comp->layers[above->layer].clients = eina_inlist_append_relative(e_comp->layers[above->layer].clients, EINA_INLIST_GET(cw->ec), EINA_INLIST_GET(above->ec)); + { + cw->layer = above->layer; + e_comp->layers[above->layer].clients = eina_inlist_append_relative(e_comp->layers[above->layer].clients, EINA_INLIST_GET(cw->ec), EINA_INLIST_GET(above->ec)); + e_comp->layers[above->layer].clients_count++; + } else if (below) - e_comp->layers[below->layer].clients = eina_inlist_prepend_relative(e_comp->layers[below->layer].clients, EINA_INLIST_GET(cw->ec), EINA_INLIST_GET(below->ec)); - if ((!above) && (!below)) + { + cw->layer = below->layer; + e_comp->layers[below->layer].clients = eina_inlist_prepend_relative(e_comp->layers[below->layer].clients, EINA_INLIST_GET(cw->ec), EINA_INLIST_GET(below->ec)); + e_comp->layers[below->layer].clients_count++; + } + else { if (prepend) e_comp->layers[cw->layer].clients = eina_inlist_prepend(e_comp->layers[cw->layer].clients, EINA_INLIST_GET(cw->ec)); @@ -303,8 +311,8 @@ _e_comp_object_layers_add(E_Comp_Object *cw, E_Comp_Object *above, E_Comp_Object e_comp->layers[cw->layer].clients = eina_inlist_prepend_relative(e_comp->layers[cw->layer].clients, EINA_INLIST_GET(cw->ec), EINA_INLIST_GET(layer_cw->ec)); else //this is either the layer object or a tough actin tinactin^W^W^Wfast stacking client e_comp->layers[cw->layer].clients = eina_inlist_append(e_comp->layers[cw->layer].clients, EINA_INLIST_GET(cw->ec)); + e_comp->layers[cw->layer].clients_count++; } - e_comp->layers[cw->layer].clients_count++; #ifndef E_RELEASE_BUILD if (layer_cw) { diff --git a/src/bin/e_utils.c b/src/bin/e_utils.c index 44584c228..8117e22f3 100644 --- a/src/bin/e_utils.c +++ b/src/bin/e_utils.c @@ -1506,3 +1506,37 @@ e_util_exe_safe_run(const char *cmd, void *data) #endif return ecore_exe_pipe_run(cmd, flags, data); } + +static Eina_Bool +str_matches_one(const char *instr, const char **strset) +{ + int i; + + if ((!instr) || (!strset)) return EINA_FALSE; + for (i = 0; strset[i]; i++) + { + if (!strcmp(strset[i], instr)) return EINA_TRUE; + } + return EINA_FALSE; +} + +E_API E_Util_Action +e_util_key_geometry_action_get(const char *key, int *x, int *y, int dx, int dy) +{ + const char *k_up[] = { "Up", "KP_Up", "k", "K", "w", "W", NULL }; + const char *k_down[] = { "Down", "KP_Down", "j", "J", "s", "S", NULL }; + const char *k_left[] = { "Left", "KP_Left", "h", "H", "a", "A", NULL }; + const char *k_right[] = { "Right", "KP_Right", "l", "L", "d", "D", NULL }; + const char *k_done[] = { "Return", "KP_Enter", "space", NULL }; + const char *k_abort[] = { "Escape", "BackSpace", "Delete", "x", "X", NULL }; + + if (str_matches_one(key, k_up)) *y -= dy; + else if (str_matches_one(key, k_down)) *y += dy; + else if (str_matches_one(key, k_left)) *x -= dx; + else if (str_matches_one(key, k_right)) *x += dx; + else if (str_matches_one(key, k_done)) return E_UTIL_ACTION_DONE; + else if (str_matches_one(key, k_abort)) return E_UTIL_ACTION_ABORT; + else return E_UTIL_ACTION_NONE; + + return E_UTIL_ACTION_DO; +} diff --git a/src/bin/e_utils.h b/src/bin/e_utils.h index cb3cf089f..2a51a5959 100644 --- a/src/bin/e_utils.h +++ b/src/bin/e_utils.h @@ -70,6 +70,16 @@ E_API Ecore_Exe *e_util_open(const char *exe, void *data); E_API Ecore_Exe *e_util_exe_safe_run(const char *cmd, void *data); +typedef enum +{ + E_UTIL_ACTION_NONE, + E_UTIL_ACTION_DONE, + E_UTIL_ACTION_ABORT, + E_UTIL_ACTION_DO +} E_Util_Action; + +E_API E_Util_Action e_util_key_geometry_action_get(const char *key, int *x, int *y, int dx, int dy); + static inline Eina_Bool isedje(const Evas_Object *obj) {