Merge pull request #780 from psychon/screen-add-signal

Add screen add signal
This commit is contained in:
Daniel Hahler 2016-04-03 18:35:08 +02:00
commit 3ad0a9d8d2
7 changed files with 57 additions and 26 deletions

View File

@ -643,9 +643,6 @@ main(int argc, char **argv)
/* init atom cache */ /* init atom cache */
atoms_init(globalconf.connection); atoms_init(globalconf.connection);
/* init screens information */
screen_scan();
/* do this only for real screen */ /* do this only for real screen */
ewmh_init(); ewmh_init();
systray_init(); systray_init();
@ -702,6 +699,9 @@ main(int argc, char **argv)
xdgWipeHandle(&xdg); xdgWipeHandle(&xdg);
/* init screens information */
screen_scan();
/* scan existing windows */ /* scan existing windows */
scan(tree_c); scan(tree_c);

View File

@ -91,19 +91,19 @@ end
-- {{{ Wallpaper -- {{{ Wallpaper
if beautiful.wallpaper then if beautiful.wallpaper then
for s in screen do gears.screen.connect_for_each_screen(function(s)
gears.wallpaper.maximized(beautiful.wallpaper, s, true) gears.wallpaper.maximized(beautiful.wallpaper, s, true)
end end)
end end
-- }}} -- }}}
-- {{{ Tags -- {{{ Tags
-- Define a tag table which hold all screen tags. -- Define a tag table which hold all screen tags.
tags = {} tags = {}
for s in screen do gears.screen.connect_for_each_screen(function(s)
-- Each screen has its own tag table. -- 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]) tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, awful.layout.layouts[1])
end end)
-- }}} -- }}}
-- {{{ Menu -- {{{ Menu
@ -175,7 +175,7 @@ mytasklist.buttons = awful.util.table.join(
awful.client.focus.byidx(-1) awful.client.focus.byidx(-1)
end)) end))
for s in screen do gears.screen.connect_for_each_screen(function(s)
-- Create a promptbox for each screen -- Create a promptbox for each screen
mypromptbox[s] = awful.widget.prompt() mypromptbox[s] = awful.widget.prompt()
-- Create an imagebox widget which will contains an icon indicating which layout we're using. -- 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], mylayoutbox[s],
}, },
} }
end end)
-- }}} -- }}}
-- {{{ Mouse bindings -- {{{ Mouse bindings

View File

@ -18,6 +18,7 @@ return
matrix = require("gears.matrix"); matrix = require("gears.matrix");
shape = require("gears.shape"); shape = require("gears.shape");
protected_call = require("gears.protected_call"); protected_call = require("gears.protected_call");
screen = require("gears.screen");
} }
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

29
lib/gears/screen.lua Normal file
View File

@ -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

View File

@ -13,20 +13,12 @@ local timer = require("gears.timer")
local wallpaper = { mt = {} } local wallpaper = { mt = {} }
-- The size of the root window -- The size of the root window
local root_geom local root_geom = { x = 0, y = 0, width = 0, height = 0 }
do require("gears.screen").connect_for_each_screen(function(s)
local geom = screen[1].geometry local g = s.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.width = math.max(root_geom.width, g.x + g.width)
root_geom.height = math.max(root_geom.height, g.y + g.height) root_geom.height = math.max(root_geom.height, g.y + g.height)
end end)
end
-- A cairo surface that we still want to set as the wallpaper -- A cairo surface that we still want to set as the wallpaper
local pending_wallpaper = nil local pending_wallpaper = nil

View File

@ -143,8 +143,8 @@ local suspended = false
-- @field id Unique notification id based on a counter -- @field id Unique notification id based on a counter
-- @table notifications -- @table notifications
naughty.notifications = { suspended = { } } naughty.notifications = { suspended = { } }
for s in capi.screen do require("gears.screen").connect_for_each_screen(function(s)
naughty.notifications[get_screen(s)] = { naughty.notifications[s] = {
top_left = {}, top_left = {},
top_middle = {}, top_middle = {},
top_right = {}, top_right = {},
@ -152,7 +152,7 @@ for s in capi.screen do
bottom_middle = {}, bottom_middle = {},
bottom_right = {}, bottom_right = {},
} }
end end)
--- Notification state --- Notification state
function naughty.is_suspended() function naughty.is_suspended()

View File

@ -145,8 +145,12 @@ screen_add(lua_State *L, int sidx)
return; return;
} }
sidx = luaA_absindex(L, sidx);
lua_pushvalue(L, sidx);
luaA_object_ref(L, sidx); luaA_object_ref(L, sidx);
screen_array_append(&globalconf.screens, new_screen); screen_array_append(&globalconf.screens, new_screen);
luaA_object_emit_signal(L, -1, "added", 0);
lua_pop(L, 1);
} }
static bool static bool
@ -755,6 +759,11 @@ screen_class_setup(lua_State *L)
* @signal primary_changed * @signal primary_changed
*/ */
signal_add(&screen_class.signals, "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 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80