+end) -- }}}
+
+-- {{{ autorandr integration
+local function find_screen_by_name(name)
+ for s in screen do
+ if s.name == name then
+ return s
+ end
+ end
+end
+
+local function get_target_screen_for_tag(tag)
+ local function primary_screen(reason)
+ local s = screen.primary
+ local msg = " → primary screen \"" .. s.name .. "\""
+ if reason then msg = msg .. " (" .. reason .. ")" end
+ print(msg)
+ return s
+ end
+
+ print("Figuring out target screen for tag " .. tag.name .. "…")
+ if tag.targets then
+ if type(tag.targets) == "table" then
+ for _,target in ipairs(tag.targets) do
+ local s = find_screen_by_name(target)
+ if s then
+ print(" → screen " .. s.name)
+ return s
+ end
+ end
+ elseif tag.targets == "primary" then
+ return primary_screen("explicit request")
+ end
+ return primary_screen("no matching target in " .. table.concat(tag.targets, ","))
+ else
+ return primary_screen("no targets specified")
+ end
+end
+
+local function move_tag_to_target_screen(tag)
+ tag.screen = get_target_screen_for_tag(tag)
+end
+
+local function move_tags_to_target_screens()
+ for _,tag in ipairs(root.tags()) do
+ move_tag_to_target_screen(tag)
+ end
+end
+
+tag.connect_signal("request::screen", function(t)
+ -- throw the tag onto any other screen, it'll get reassigned later when
+ -- a new profile has been processed.
+ for s in screen do
+ if s ~= t.screen then
+ t.screen = s
+ t.selected = false
+ break
+ end
+ end
+ naughty.notify({
+ title = "Screen removed",
+ text = "Salvaged tab " .. t.name .. " onto screen " .. t.screen.name,
+ })
+end)
+
+function handle_new_autorandr_profile(newprofile)
+ -- The main idea here is that autorandr invokes this via awesome-client
+ -- after switching to a new profile. Awesome will have already set up all
+ -- the screens long before this function is called. Therefore, we just do
+ -- the necessary modifications to the existing screens, and move tags
+ -- around.
+
+ if not newprofile then
+ error("Missing new profile name")
+ end
+
+ naughty.notify({
+ preset = naughty.config.presets.low,
+ title = "New autorandr profile",
+ text = "Reconfiguring for profile <b>" .. newprofile .. "</b>",
+ })
+
+ for s in screen do
+ s:set_profile(newprofile)
+ end
+ move_tags_to_target_screens()
+end
+
+local function initialise_to_autorandr_profile()
+ local profile
+
+ local function process_line(line)
+ if profile then return end
+ local match = string.match(line, "^([^%s]+) %(detected%)$")
+ if match then
+ profile = match
+ end
+ end
+
+ local function output_done()
+ if not profile then
+ error("autorandr detected no profile")
+ profile = "awesome"
+ end
+ handle_new_autorandr_profile(profile)
+ end
+
+ local function handle_exit(reason, code)
+ if not (reason == "exit" and code == 0) then
+ error("autorandr error: " .. reason .. ": " .. tostring(code))
+ end
+ end
+
+ awful.spawn.with_line_callback('autorandr', {
+ stderr = process_line,
+ output_done = output_done,
+ exit = handle_exit
+ })
+end
+awesome.connect_signal("startup", initialise_to_autorandr_profile)
+-- }}}
+
+-- }}}
+
+-- {{{ Tags
+
+local default_tag = {
+ name = nil,
+ init = true,
+ layout = layouts.default,
+ fallback = true,
+ targets = "primary",
+}
+local default_tags = {}
+for i = 1, 9 do
+ default_tags[i] = {}
+ for k,v in pairs(default_tag) do
+ default_tags[i][k] = v
+ end
+ default_tags[i].name = tostring(i)
+end
+default_tags[1].selected = true
+
+default_tags = gears.table.join(default_tags, {
+ {
+ name = "irc",
+ init = true,
+ exclusive = true,
+ master_width_factor = 0.33,
+ layout = layouts.tiled,
+ selected = true,
+ exec_once = { terminal .. " -name irc -e env MOSH_TITLE_NOPREFIX=true mosh -4 -- irc-host tmux new -As irc irssi" },
+ instance = { "irc" },
+ targets = { "catalyst/eDP1", "mtvic/eDP1", "lehel/DisplayPort-2" },
+ },
+ {
+ name = "[m]",
+ init = true,
+ exclusive = true,
+ master_width_factor = 0.67,
+ layout = layouts.tiled,
+ selected = true,
+ exec_once = { "revolt" },
+ instance = { "Revolt" },
+ targets = { "catalyst/eDP1", "mtvic/eDP1", "lehel/DisplayPort-2" },
+ },
+ {
+ name = "dflt",
+ init = false,
+ fallback = true,
+ layout = layouts.floating,
+ volatile = true,
+ selected = true,
+ },
+ {
+ name = "cal",
+ init = true,
+ exclusive = true,
+ layout = layouts.default,
+ exec_once = { "thunderbird" },
+ class = { "Thunderbird" },
+ targets = { "catalyst/HDMI1", "mtvic/eDP1", "lehel/DisplayPort-1" },
+ },
+ {
+ name = "chr",
+ init = true,
+ exclusive = true,
+ layout = layouts.default,
+ exec_once = { "chromium" },
+ class = { "Chromium" },
+ targets = { "catalyst/HDMI1", "mtvic/eDP1", "lehel/DisplayPort-1" },
+ },
+ {
+ name = "ffx",
+ init = true,
+ exclusive = true,
+ layout = layouts.default,
+ exec_once = { "firefox" },
+ class = { "Firefox" },
+ targets = { "catalyst/HDMI1", "mtvic/eDP1", "lehel/DisplayPort-1" },
+ },
+})
+
+if not tyrannical then
+
+for _,t in ipairs(default_tags) do
+ if t.init then
+ t.screen = t.screen or screen.primary
+ t.layout = t.layout or layouts.default
+ local newt = th.add_tag(t.name, t, false)
+ end