From 2432dda3e3315c3a26a6872a8647075c175e17cd Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 26 Mar 2016 18:25:51 +0100 Subject: [PATCH 1/6] screen: Add "added" signal This signal is emitted when a new screen is added. Signed-off-by: Uli Schlachter --- objects/screen.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/objects/screen.c b/objects/screen.c index 044fb9edb..c7e508b71 100644 --- a/objects/screen.c +++ b/objects/screen.c @@ -145,8 +145,12 @@ screen_add(lua_State *L, int sidx) return; } + sidx = luaA_absindex(L, sidx); + lua_pushvalue(L, sidx); luaA_object_ref(L, sidx); screen_array_append(&globalconf.screens, new_screen); + luaA_object_emit_signal(L, -1, "added", 0); + lua_pop(L, 1); } static bool @@ -755,6 +759,11 @@ screen_class_setup(lua_State *L) * @signal primary_changed */ signal_add(&screen_class.signals, "primary_changed"); + /** + * This signal is emitted when a new screen is added to the current setup. + * @signal added + */ + signal_add(&screen_class.signals, "added"); } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 From 94dede75113b934d7f49cf8b880e61dfdb170e58 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 26 Mar 2016 18:33:45 +0100 Subject: [PATCH 2/6] Add functions for calling something for every screen This adds gears.screen which contains a wrapper around screen.connect_signal("added", func) that also calls the callback function for each screen that already exists. This is added in gears.screen so that it can also be used from e.g. wibox, if needed. Feel free to move this elsewhere if that's a bad idea (I'm not really convinced of it). Signed-off-by: Uli Schlachter --- lib/gears/init.lua | 1 + lib/gears/screen.lua | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 lib/gears/screen.lua diff --git a/lib/gears/init.lua b/lib/gears/init.lua index 4f5e83f6e..3fe46b448 100644 --- a/lib/gears/init.lua +++ b/lib/gears/init.lua @@ -18,6 +18,7 @@ return matrix = require("gears.matrix"); shape = require("gears.shape"); protected_call = require("gears.protected_call"); + screen = require("gears.screen"); } -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/gears/screen.lua b/lib/gears/screen.lua new file mode 100644 index 000000000..fea8fd1ed --- /dev/null +++ b/lib/gears/screen.lua @@ -0,0 +1,29 @@ +--------------------------------------------------------------------------- +-- @author Uli Schlachter +-- @copyright 2016 Uli Schlachter +-- @release @AWESOME_VERSION@ +-- @classmod gears.screen +--------------------------------------------------------------------------- + +local screen = screen + +local module = {} + +--- Call a function for each existing and created-in-the-future screen. +-- @tparam function func The function to call. +function module.connect_for_each_screen(func) + for s in screen do + func(s) + end + screen.connect_signal("added", func) +end + +--- Undo the effect of connect_for_each_screen. +-- @tparam function func The function that should no longer be called. +function module.disconnect_for_each_screen(func) + screen.disconnect_signal("added", func) +end + +return module + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 From 3f4018317738acb75ddace4161caa3591f38c617 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 26 Mar 2016 18:36:04 +0100 Subject: [PATCH 3/6] naughty: Use connect_for_each_screen() Signed-off-by: Uli Schlachter --- lib/naughty/core.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index 18aa9629f..c7b3fb085 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -143,8 +143,8 @@ local suspended = false -- @field id Unique notification id based on a counter -- @table notifications naughty.notifications = { suspended = { } } -for s in capi.screen do - naughty.notifications[get_screen(s)] = { +require("gears.screen").connect_for_each_screen(function(s) + naughty.notifications[s] = { top_left = {}, top_middle = {}, top_right = {}, @@ -152,7 +152,7 @@ for s in capi.screen do bottom_middle = {}, bottom_right = {}, } -end +end) --- Notification state function naughty.is_suspended() From bed09f6c1834648beee95b82c4c0292da4a9b660 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 26 Mar 2016 18:36:38 +0100 Subject: [PATCH 4/6] Default config: Use connect_for_each_screen() Signed-off-by: Uli Schlachter --- awesomerc.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/awesomerc.lua b/awesomerc.lua index eddb9ab67..4319b2c6f 100755 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -91,19 +91,19 @@ end -- {{{ Wallpaper if beautiful.wallpaper then - for s in screen do + gears.screen.connect_for_each_screen(function(s) gears.wallpaper.maximized(beautiful.wallpaper, s, true) - end + end) end -- }}} -- {{{ Tags -- Define a tag table which hold all screen tags. tags = {} -for s in screen do +gears.screen.connect_for_each_screen(function(s) -- Each screen has its own tag table. tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, awful.layout.layouts[1]) -end +end) -- }}} -- {{{ Menu @@ -175,7 +175,7 @@ mytasklist.buttons = awful.util.table.join( awful.client.focus.byidx(-1) end)) -for s in screen do +gears.screen.connect_for_each_screen(function(s) -- Create a promptbox for each screen mypromptbox[s] = awful.widget.prompt() -- Create an imagebox widget which will contains an icon indicating which layout we're using. @@ -213,7 +213,7 @@ for s in screen do mylayoutbox[s], }, } -end +end) -- }}} -- {{{ Mouse bindings From 3233eb6cce076e49a501f5db9e411a9dc2a4a6a9 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 26 Mar 2016 18:37:55 +0100 Subject: [PATCH 5/6] gears.wallpaper: Use connect_for_each_screen() Signed-off-by: Uli Schlachter --- lib/gears/wallpaper.lua | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/gears/wallpaper.lua b/lib/gears/wallpaper.lua index 873324bd2..491d81241 100644 --- a/lib/gears/wallpaper.lua +++ b/lib/gears/wallpaper.lua @@ -13,20 +13,12 @@ local timer = require("gears.timer") local wallpaper = { mt = {} } -- The size of the root window -local root_geom -do - local geom = screen[1].geometry - root_geom = { - x = 0, y = 0, - width = geom.x + geom.width, - height = geom.y + geom.height - } - for s in screen do - local g = screen[s].geometry - root_geom.width = math.max(root_geom.width, g.x + g.width) - root_geom.height = math.max(root_geom.height, g.y + g.height) - end -end +local root_geom = { x = 0, y = 0, width = 0, height = 0 } +require("gears.screen").connect_for_each_screen(function(s) + local g = s.geometry + root_geom.width = math.max(root_geom.width, g.x + g.width) + root_geom.height = math.max(root_geom.height, g.y + g.height) +end) -- A cairo surface that we still want to set as the wallpaper local pending_wallpaper = nil From e6037b47385bb908e56ee8aaf32097b971790c38 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 26 Mar 2016 18:38:44 +0100 Subject: [PATCH 6/6] Only define screens after the config is loaded This gives us the worst of both worlds: We still restart on RandR screen changes and the information about screens isn't available during startup. However, it's a step in the right direction, because all Lua code will now have to handle kind-of-dynamic screen changes. Signed-off-by: Uli Schlachter --- awesome.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/awesome.c b/awesome.c index b16f23950..60aa2dc32 100644 --- a/awesome.c +++ b/awesome.c @@ -643,9 +643,6 @@ main(int argc, char **argv) /* init atom cache */ atoms_init(globalconf.connection); - /* init screens information */ - screen_scan(); - /* do this only for real screen */ ewmh_init(); systray_init(); @@ -702,6 +699,9 @@ main(int argc, char **argv) xdgWipeHandle(&xdg); + /* init screens information */ + screen_scan(); + /* scan existing windows */ scan(tree_c);