diff --git a/lib/awful/widget/only_on_screen.lua b/lib/awful/widget/only_on_screen.lua index 961f88699..6d8aae1d7 100644 --- a/lib/awful/widget/only_on_screen.lua +++ b/lib/awful/widget/only_on_screen.lua @@ -25,10 +25,12 @@ local function should_display_on(self, s) if not self._private.widget then return false end - local success, own_s = pcall(function() - return capi.screen[self._private.screen] - end) - return success and own_s == s + local own_s = self._private.screen + if type(own_s) == "number" and (own_s < 1 or own_s > capi.screen.count()) then + -- Invalid screen number + return false + end + return capi.screen[self._private.screen] == s end -- Layout this layout diff --git a/tests/examples/shims/screen.lua b/tests/examples/shims/screen.lua index 6e5d59dd8..f015dab05 100644 --- a/tests/examples/shims/screen.lua +++ b/tests/examples/shims/screen.lua @@ -2,7 +2,9 @@ local gears_obj = require("gears.object") local screen, meta = awesome._shim_fake_class() -screen.count = 1 +function screen.count() + return 1 +end local function create_screen(args) local s = gears_obj()