vincentbernat.i3wm-configur.../rc/xrandr.lua

67 lines
1.7 KiB
Lua
Raw Normal View History

-- Menu with autorandr choices
local icons = loadrc("icons", "vbe/icons")
2012-07-15 16:51:30 +02:00
-- Build available choices
local function menu()
return {
{ "Autodetect", "autorandr --change" },
{ "Clone", "autorandr --load common" },
{ "Horizontal", "autorandr --load horizontal" },
{ "Vertical", "autorandr --load vertical" },
{ "Keep current configuration", nil },
}
2012-07-15 16:51:30 +02:00
end
-- Display xrandr notifications from choices
local state = { iterator = nil,
timer = nil,
cid = nil }
local function xrandr()
-- Stop any previous timer
if state.timer then
state.timer:stop()
state.timer = nil
end
-- Build the list of choices
if not state.iterator then
state.iterator = awful.util.table.cycle(
menu(),
function() return true end)
2012-07-15 16:51:30 +02:00
end
-- Select one and display the appropriate notification
local next = state.iterator()
local label, action
2012-07-15 16:51:30 +02:00
if not next then
state.iterator = nil
return xrandr()
2012-07-15 16:51:30 +02:00
else
label, action = unpack(next)
2012-07-15 16:51:30 +02:00
end
state.cid = naughty.notify({ text = label,
icon = icons.lookup({ name = "display", type = "devices" }),
2012-07-15 16:51:30 +02:00
timeout = 4,
screen = mouse.screen, -- Important, not all screens may be visible
font = "Free Sans 18",
replaces_id = state.cid }).id
-- Setup the timer
state.timer = timer { timeout = 4 }
state.timer:add_signal("timeout",
function()
state.timer:stop()
state.timer = nil
state.iterator = nil
if action then
awful.util.spawn(action, false)
2012-07-15 16:51:30 +02:00
end
end)
state.timer:start()
end
config.keys.global = awful.util.table.join(
config.keys.global,
2012-07-15 16:51:30 +02:00
awful.key({}, "XF86Display", xrandr))