From 94dede75113b934d7f49cf8b880e61dfdb170e58 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 26 Mar 2016 18:33:45 +0100 Subject: [PATCH] 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