From 55190646c4912a091be54dabd40ae49bff746bb5 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 3 Jan 2016 03:29:21 -0500 Subject: [PATCH] client: Add swapped, raised and lowered signals This allow layout "arrange" to be called less often and react on the cause of the change itself rather than it's consequences (usually, the "focus" signal). Previously, the layout were re-arranged everytime the focus changed. Now, with "raised" and "lowered", it require less "arrange". "swapped" allow smarted layouts. Currently, swapped cause a full re-arrange. It re-read the "index" list from scratch and create a "new" layout. With "swapped", incremental layout changes are possible. Fixes https://github.com/awesomeWM/awesome/issues/616 --- lib/awful/layout/init.lua | 3 ++- objects/client.c | 40 +++++++++++++++++++++++++++++++++++++++ objects/client.h | 6 ++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index af3c9409..0a988a28 100755 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -205,7 +205,8 @@ for s = 1, capi.screen.count() do end) end -capi.client.connect_signal("focus", function(c) layout.arrange(c.screen) end) +capi.client.connect_signal("raised", function(c) layout.arrange(c.screen) end) +capi.client.connect_signal("lowered", function(c) layout.arrange(c.screen) end) capi.client.connect_signal("list", function() for screen = 1, capi.screen.count() do layout.arrange(screen) diff --git a/objects/client.c b/objects/client.c index 5ce84f3f..db63309c 100644 --- a/objects/client.c +++ b/objects/client.c @@ -1602,6 +1602,17 @@ luaA_client_swap(lua_State *L) *ref_swap = c; luaA_class_emit_signal(L, &client_class, "list", 0); + + luaA_object_push(L, swap); + lua_pushboolean(L, true); + luaA_object_emit_signal(L, -4, "swapped", 2); + lua_pop(L, 2); + + luaA_object_push(L, swap); + luaA_object_push(L, c); + lua_pushboolean(L, false); + luaA_object_emit_signal(L, -3, "swapped", 2); + lua_pop(L, 3); } return 0; @@ -1688,7 +1699,13 @@ static int luaA_client_raise(lua_State *L) { client_t *c = luaA_checkudata(L, 1, &client_class); + + /* Avoid sending the signal if nothing was done */ + if (c->transient_for == NULL && globalconf.stack.tab[globalconf.stack.len-1] == c) + return 0; + client_raise(c); + return 0; } @@ -1701,12 +1718,21 @@ luaA_client_lower(lua_State *L) { client_t *c = luaA_checkudata(L, 1, &client_class); + /* Avoid sending the signal if nothing was done */ + if (globalconf.stack.len && globalconf.stack.tab[0] == c) + return 0; + stack_client_push(c); /* Traverse all transient layers. */ for(client_t *tc = c->transient_for; tc; tc = tc->transient_for) stack_client_push(tc); + /* Notify the listeners */ + luaA_object_push(L, c); + luaA_object_emit_signal(L, -1, "lowered", 0); + lua_pop(L, 1); + return 0; } @@ -2736,6 +2762,12 @@ client_class_setup(lua_State *L) * @signal .list */ signal_add(&client_class.signals, "list"); + /** When 2 clients are swapped + * @args client The other client + * @args is_source If self is the source or the destination of the swap + * @signal .swapped + */ + signal_add(&client_class.signals, "swapped"); /** * @signal .manage */ @@ -2979,6 +3011,14 @@ client_class_setup(lua_State *L) * @tag t The tag object. */ signal_add(&client_class.signals, "untagged"); + /** + * @signal .raised + */ + signal_add(&client_class.signals, "raised"); + /** + * @signal .lowered + */ + signal_add(&client_class.signals, "lowered"); } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/objects/client.h b/objects/client.h index b30c6cf2..86a28c9c 100644 --- a/objects/client.h +++ b/objects/client.h @@ -208,6 +208,12 @@ client_raise(client_t *c) /* Push c on top of the stack. */ stack_client_append(c); + + /* Notify the listeners */ + lua_State *L = globalconf_get_lua_State(); + luaA_object_push(L, c); + luaA_object_emit_signal(L, -1, "raised", 0); + lua_pop(L, 1); } /** Check if a client has fixed size.