awesome/lib/naughty/init.lua

93 lines
2.8 KiB
Lua
Raw Normal View History

---------------------------------------------------------------------------
-- @author Uli Schlachter <psychon@znc.in>
-- @copyright 2014 Uli Schlachter
-- @module naughty
---------------------------------------------------------------------------
local naughty = require("naughty.core")
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
local gdebug = require("gears.debug")
local capi = {awesome = awesome, screen = screen}
if dbus then
naughty.dbus = require("naughty.dbus")
end
naughty.action = require("naughty.action")
naughty.list = require("naughty.list")
naughty.layout = require("naughty.layout")
naughty.widget = require("naughty.widget")
naughty.container = require("naughty.container")
naughty.action = require("naughty.action")
naughty.notification = require("naughty.notification")
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
-- Attempt to handle early errors when using the manual screen mode.
--
-- Creating a notification popup before the screens are added won't work. To
-- work around this, the code below initializes some screens. One potential
-- problem is that it could emit enough signal to cause even more errors and
-- lose the original error.
--
-- For example, the following error can be displayed using this fallback:
--
-- screen.connect_signal("scanned", function() foobar() end)
--
local function screen_fallback()
if capi.screen.count() == 0 then
gdebug.print_warning("An error occurred before a screen was added")
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
-- Private API to scan for screens now.
if #screen._viewports() == 0 then
screen._scan_quiet()
end
local viewports = screen._viewports()
if #viewports > 0 then
for _, viewport in ipairs(viewports) do
local geo = viewport.geometry
local s = capi.screen.fake_add(geo.x, geo.y, geo.width, geo.height)
s.outputs = viewport.outputs
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
end
else
capi.screen.fake_add(0, 0, 640, 480)
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
end
end
end
-- Handle runtime errors during startup
if capi.awesome.startup_errors then
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
-- Wait until `rc.lua` is executed before creating the notifications.
-- Otherwise nothing is handling them (yet).
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
client.connect_signal("scanning", function()
-- A lot of things have to go wrong for this to happen, but it can.
screen_fallback()
naughty.emit_signal(
"request::display_error", capi.awesome.startup_errors, true
)
end)
end
-- Handle runtime errors after startup
do
local in_error = false
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
capi.awesome.connect_signal("debug::error", function (err)
-- Make sure we don't go into an endless error loop
if in_error then return end
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
in_error = true
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
screen_fallback()
naughty.emit_signal("request::display_error", tostring(err), false)
in_error = false
end)
init: Add a command line option to start AwesomeWM without screens. This commit add an optional `--screen off` command to initialize Lua without first adding the screens. This is inconvinient for most users since it restrict the APIs that are usable out of the box. However, this allows AwesomeWM to work independently from the hardware. This means that when a screen is unplugged, it is the Lua code that will remove the screen instead of CAPI pulling the carpet from under. It also allows to ignore some screen areas before the screen is ever created. Combined, it makes it possible to work with screens even when they are physically disconnected. Finally, it will allow for an awful.rules like API to control how screens are created. All in all, some people need this for their setup and some people might want to do it anyway for fine grained and/or dynamaic multi-screen setups. This commit also adds 4 new signals to `capi` to be able to execute code at specific points during the initialization. The commit improves naughty error notifications to work even if problems occurs before the screens are added. Note that AwesomeWM will exit if no screens are created. While it would be easy to just call `refresh_screen();` after unsetting the magic variable, doing so would have corner cases. Better be harsher and prevent the user from shooting themselves in the foot from not reading the f****** manual. Code introduced in future commits will take care of automatically calling fake_screen in the event nothing is created. Fixes #1382
2018-08-06 22:43:01 +02:00
end
return naughty
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80