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); 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 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 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 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() 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