mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-14 20:24:22 +02:00
xrandr: use naughty instead of menus
This commit is contained in:
parent
06150559db
commit
aa851d1f11
1 changed files with 55 additions and 10 deletions
|
@ -42,7 +42,7 @@ local function arrange(out)
|
||||||
return choices
|
return choices
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Display xrandr menu
|
-- Build available choices
|
||||||
local function menu()
|
local function menu()
|
||||||
local menu = {}
|
local menu = {}
|
||||||
local out = outputs()
|
local out = outputs()
|
||||||
|
@ -66,24 +66,69 @@ local function menu()
|
||||||
|
|
||||||
local label = ""
|
local label = ""
|
||||||
if #choice == 1 then
|
if #choice == 1 then
|
||||||
label = 'Only ' .. choice[1]
|
label = 'Only <span weight="bold">' .. choice[1] .. '</span>'
|
||||||
else
|
else
|
||||||
for i, o in pairs(choice) do
|
for i, o in pairs(choice) do
|
||||||
if i > 1 then label = label .. ", " end
|
if i > 1 then label = label .. " + " end
|
||||||
label = label .. o
|
label = label .. '<span weight="bold">' .. o .. '</span>'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
menu[#menu + 1] = { " " .. label,
|
menu[#menu + 1] = { label,
|
||||||
function() awful.util.spawn(cmd, false) end,
|
cmd,
|
||||||
"/usr/share/icons/gnome/32x32/devices/display.png" }
|
"/usr/share/icons/gnome/32x32/devices/display.png" }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Show the menu
|
return menu
|
||||||
awful.menu({ items = menu,
|
end
|
||||||
width = 300 }):show({ keygrabber = true })
|
|
||||||
|
-- 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)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Select one and display the appropriate notification
|
||||||
|
local next = state.iterator()
|
||||||
|
local label, action, icon
|
||||||
|
if not next then
|
||||||
|
label, icon = "Keep the current configuration", "/usr/share/icons/gnome/32x32/devices/display.png"
|
||||||
|
state.iterator = nil
|
||||||
|
else
|
||||||
|
label, action, icon = unpack(next)
|
||||||
|
end
|
||||||
|
state.cid = naughty.notify({ text = label,
|
||||||
|
icon = icon,
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
state.timer:start()
|
||||||
end
|
end
|
||||||
|
|
||||||
config.keys.global = awful.util.table.join(
|
config.keys.global = awful.util.table.join(
|
||||||
config.keys.global,
|
config.keys.global,
|
||||||
awful.key({}, "XF86Display", menu))
|
awful.key({}, "XF86Display", xrandr))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue