Advertisement
constantin-net

displaytest_to_rc_lua

May 6th, 2021
1,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | None | 0 0
  1. local function get_screen_id(s)
  2.     local name = ""
  3.     for i, e in pairs(s.outputs) do
  4.         name = tostring(i)
  5.     end
  6.     return name
  7. end
  8.  
  9. mydisplaymenu = awful.menu({ })
  10.  
  11. function display_menu ()
  12.     local current_display = get_screen_id(awful.screen.focused())
  13.     local terms = {}
  14.     local displays = io.popen("xrandr | grep ' connected' | awk {'print $1'}")
  15.     for l in displays:lines() do
  16.         if l ~= current_display then
  17.             local item = l
  18.             table.insert(terms, { current_display .. " <-> " .. item, {
  19.                                                     { "duplicate with " .. item, function() awful.util.spawn("displayexec.sh " .. current_display .. " duplicate " .. item) end },
  20.                                                     {"switch to " .. item, function() awful.util.spawn("displayexec.sh " .. current_display .. " switch " .. item) end },
  21.                                                     {"extend to " .. item, {
  22.                                                                             {"left", function() awful.util.spawn("displayexec.sh " .. current_display .. " extend " .. item .. " left") end },
  23.                                                                             {"above", function() awful.util.spawn("displayexec.sh " .. current_display .. " extend " .. item .. " above") end },
  24.                                                                             {"right", function() awful.util.spawn("displayexec.sh " .. current_display .. " extend " .. item .. " right") end },
  25.                                                                             {"below", function() awful.util.spawn("displayexec.sh " .. current_display .. " extend " .. item .. " below") end },
  26.             }}}})
  27.         end
  28.     end
  29.     displays:close()
  30.     mydisplaymenu = awful.menu( { items = terms, theme = { width = 200 }} )
  31. end
  32.  
  33. function display_menu_toggle_fn()
  34.     instance = nil
  35.     return function ()
  36.         if instance and instance.wibox.visible then
  37.             instance:hide()
  38.             instance = nil
  39.         else
  40.             display_menu()
  41.             instance = mydisplaymenu
  42.             mydisplaymenu:update()
  43.             mydisplaymenu:show()
  44.         end
  45.     end
  46. end
  47.  
  48. display_widget = wibox.widget { widget = wibox.widget.textbox }
  49. display_widget:set_text(" ▢ ")
  50. display_widget:buttons(gears.table.join(
  51.     awful.button({ }, 1, display_menu_toggle_fn() )
  52.     ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement