constantin-net

rc.v082c.desktop

Jun 9th, 2023 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 90.96 KB | None | 0 0
  1. -- v082 desktop changes
  2. -- Standard awesome library
  3. local gears         = require("gears")
  4. local awful         = require("awful")
  5. require("awful.autofocus")
  6. -- Widget and layout library
  7. local wibox         = require("wibox")
  8. -- Theme handling library
  9. local beautiful     = require("beautiful")
  10. -- Notification library
  11. local naughty       = require("naughty")
  12. local vicious       = require("vicious")
  13. local menubar       = require("menubar")
  14. local hotkeys_popup = require("awful.hotkeys_popup").widget
  15. -- Freedesktop menu
  16. local freedesktop   = require("freedesktop")
  17. -- Enable VIM help for hotkeys widget when client with matching name is opened:
  18. require("awful.hotkeys_popup.keys.vim")
  19. os.setlocale("ru_RU.UTF-8")
  20.  
  21. -- {{{ Error handling
  22. --[[if awesome.startup_errors then
  23.     naughty.notify({ preset = naughty.config.presets.critical, position = "bottom_left", timeout = 1,
  24.                                   title = "Oops, there were errors during startup!",
  25.                                   text = awesome.startup_errors })
  26. end
  27. -- Handle runtime errors after startup
  28. do
  29.     local in_error = false
  30.     awesome.connect_signal("debug::error", function (err)
  31.         -- Make sure we don't go into an endless error loop
  32.         if in_error then return end
  33.         in_error = true
  34.         naughty.notify({ preset = naughty.config.presets.critical, position = "bottom_left",
  35.                                       title = "Oops, an error happened!",
  36.                                       text = tostring(err) })
  37.         in_error = false
  38.     end)
  39. end
  40. --]]
  41. -- }}}
  42.  
  43. -- {{{ Variable definitions
  44. -- Themes define colours, icons, font and wallpapers.
  45. config_dir = awful.util.getdir("config")
  46. user      = string.match( awful.util.getdir("config"), '^/home/(%a+)')
  47. theme     = "gtk3"
  48.  
  49. beautiful.init( config_dir .. "themes/" .. theme .. "/theme.lua")
  50. local icons_size = beautiful.menu_height-2
  51. if beautiful.icon_theme == nil then beautiful.icon_theme = "Adwaita" end
  52. if beautiful.radius < 3 then beautiful.radius = 3 end
  53. if beautiful.radius > 9 then beautiful.radius = 9 end
  54.  
  55. awesome.set_preferred_icon_size(beautiful.menu_height)
  56.  
  57. -- This is used later as the default terminal and editor to run.
  58. browser         = "firefox"
  59. --browser         = "chromium"
  60. filemanager      = "spacefm"
  61. gui_editor      = "geany"
  62. terminal        = os.getenv("TERMINAL") or "lxterminal"
  63. xterminal       = "xterm"
  64. mocp_terminal   = "sakura"
  65. vkboard         = "onboard"
  66. smag            = "xzoom"
  67. torrent_client  = "qbittorrent"
  68. --torrent_client  = "transmission-gtk"
  69. smixer_gui      = "pavucontrol"
  70. geditor         = "gimp"
  71. calc            = "galculator"
  72. comixreader     = "mcomix"
  73. mindmaps        = "vym"
  74.  
  75. rofi             = "/usr/local/sbin/rofi-1.6.1"
  76. rofi_cmd_drun    = rofi .. " -modi drun -show drun -config ~/.config/rofi/config-apps.rasi -theme ~/.config/rofi/theme-apps.rasi"
  77. rofi_cmd_run     = rofi .. " -modi run -show run -config ~/.config/rofi/config.rasi -theme ~/.config/rofi/theme.rasi"
  78. rofi_cmd_combi   = rofi .. " -show combi -combi-modi 'window,drun' -modi combi -config ~/.config/rofi/config.rasi -theme ~/.config/rofi/theme.rasi"
  79. rofi_cmd_window  = rofi .. " -show window -modi window -config ~/.config/rofi/config.rasi -theme ~/.config/rofi/theme.rasi"
  80. rofi_file_browser = rofi .. " -modi drun,file-browser -show file-browser -config ~/.config/rofi/config-files.rasi -theme ~/.config/rofi/theme-files.rasi"
  81.  
  82. -- scrot
  83. scrot_dir_command = "'mv $f /home/" .. user .. "/Pictures/PrintScreen/'"
  84. scr_full          = "scrot -m -z -e " .. scrot_dir_command
  85. scr_area          = "sleep 0.2; scrot -f -s -e " .. scrot_dir_command
  86. scr_area_delay    = "sleep 0.2; scrot -d 5 -s -e " .. scrot_dir_command
  87. scr_active_window = "scrot -z -u -e " .. scrot_dir_command --]]
  88. --[[ Gnome-screenshot
  89. scr_full          = "gnome-screenshot"
  90. scr_area          = "sleep 0.2; gnome-screenshot -a"
  91. scr_area_delay    = "sleep 0.2; gnome-screenshot -d 5"
  92. scr_active_window = "gnome-screenshot -w"--]]
  93.  
  94. -- ~/.config/pulse/default.pa
  95. -- set-card-profile <card_name> output:<output_profile>+input:<input_profile>
  96. pa_sink_default       = " alsa_output.pci-0000_00_1b.0.analog-stereo" --acer n/b, asus B75M-A
  97. --pa_sink_default       = " alsa_output.pci-0000_00_14.2.analog-stereo" --ALC883 ASUS m2a-vm 5.1
  98. pa_sink               = " "
  99.  
  100. function dir_exists(dir)
  101.       return os.rename(dir,dir)
  102. end
  103.  
  104. local icons_path = "/usr/share/icons/" .. beautiful.icon_theme .. "/"
  105. if dir_exists(icons_path) == nil then icons_path = "/home/" .. user .. "/.icons/".. beautiful.icon_theme .. "/" end
  106. local theme_icons_size = "24x24"
  107.  
  108. -- Icons
  109. beautiful.media_play     = icons_path .. theme_icons_size .. "/actions/media-playback-start.png"
  110. beautiful.home           = icons_path .. theme_icons_size .. "/actions/go-home.png"
  111. beautiful.media_next     = icons_path .. theme_icons_size .. "/actions/media-skip-forward.png"
  112. beautiful.media_prev     = icons_path .. theme_icons_size .. "/actions/media-skip-backward.png"
  113. beautiful.media_pause    = icons_path .. theme_icons_size .. "/actions/media-playback-pause.png"
  114. beautiful.media_playlist = icons_path .. theme_icons_size .. "/actions/format-justify-fill.png"
  115. beautiful.media_shuffle    = icons_path .. theme_icons_size .. "/status/media-playlist-shuffle.png"
  116. beautiful.media_repeat   = icons_path .. theme_icons_size .. "/status/media-playlist-repeat.png"
  117. beautiful.close_key      = icons_path .. theme_icons_size .. "/actions/window-close.png"
  118.  
  119. -- Tags
  120. media_tag = "media"
  121. files_tag  = "files"
  122. inet_tag  = "web"
  123. misc_tag  = "misc"
  124.  
  125. modkey         = "Mod4"
  126. -- Table of layouts to cover with awful.layout.inc, order matters.
  127. awful.layout.layouts = {
  128.     awful.layout.suit.max,
  129.     --awful.layout.suit.tile,
  130.     --awful.layout.suit.floating,
  131.     --awful.layout.suit.fair,
  132.     --awful.layout.suit.spiral,
  133.     --awful.layout.suit.spiral.dwindle,
  134.     --awful.layout.suit.tile.left,
  135.     awful.layout.suit.tile.bottom,
  136.     --awful.layout.suit.tile.top,
  137.     --awful.layout.suit.fair.horizontal,
  138.     --awful.layout.suit.max.fullscreen,
  139.     --awful.layout.suit.magnifier,
  140.     --awful.layout.suit.corner.nw,
  141.     --awful.layout.suit.corner.ne,
  142.     --awful.layout.suit.corner.sw,
  143.     --awful.layout.suit.corner.se,
  144. }
  145. -- }}}
  146.  
  147. -- {{{ Helper functions
  148.  
  149. function run_once(prg)
  150.     if not prg then
  151.         do return nil end
  152.     end
  153.     awful.spawn.with_shell("ps ux | grep -v grep | grep -q '" .. prg .. "' || (" .. prg .. ")")
  154. end
  155.  
  156. function spawn_client_once(command,target_tag)
  157.     run_once(command)
  158.     local screen = awful.screen.focused() local tag = screen.tags[target_tag] if tag then tag:view_only() end
  159. end
  160.  
  161. function client_menu_toggle_fn()
  162.     local instance = nil
  163.     return function ()
  164.         if instance and instance.wibox.visible then
  165.             instance:hide()
  166.             instance = nil
  167.         else
  168.             instance = awful.menu.clients({ theme = { width = beautiful.menu_width*2 } })
  169.         end
  170.     end
  171. end
  172.  
  173. screen_index_mark = function(n)
  174.     if n.index == 1 then return "" else return n.index end
  175. end
  176.  
  177. -- Net menu v2.1
  178. -- fsudo
  179. beautiful.net_wl        = config_dir .. "/net_icons/network-wl.png"
  180. beautiful.net_wl_off     = config_dir .. "/net_icons/network-cellular-offline.svg"
  181. beautiful.net_wl_none   = config_dir .. "/net_icons/network-cellular-signal-none.svg"
  182. beautiful.net_wl_low    = config_dir .. "/net_icons/network-cellular-signal-low.svg"
  183. beautiful.net_wl_ok     = config_dir .. "/net_icons/network-cellular-signal-ok.svg"
  184. beautiful.net_wl_good   = config_dir .. "/net_icons/network-cellular-signal-good.svg"
  185. beautiful.net_wl_full   = config_dir .. "/net_icons/network-cellular-signal-excellent.svg"
  186. beautiful.net_en_off     = config_dir .. "/net_icons/network-offline.svg"
  187. beautiful.net_en_on     = config_dir .. "/net_icons/network-wired.svg"
  188.  
  189.  
  190. wifi_menu_exec = function ( iface, ap )
  191.     awful.spawn.with_shell(xterminal .. " -geometry 30x10 -e 'wpa_connect2 " .. iface .. " " .. ap .. "'")
  192. end
  193. mywifimenu = awful.menu({ })
  194. function wifi_menu ( iface )
  195.     local terms = {}
  196.     awful.spawn.with_shell("fsudo -c | sudo -S ifconfig " .. iface .. " up")
  197.     local aps = io.popen("fsudo -c | sudo -S iwlist ".. iface .. " scan 2>/dev/null | awk -F':' '/ESSID/{print $2}' | nl -w2 -n rz -s '=' ")
  198.     for l in aps:lines() do
  199.         local item = { l, function() wifi_menu_exec(iface,l) end }
  200.         table.insert(terms, item)
  201.     end
  202.     aps:close()
  203.     table.insert(terms, {"update", function() mywifimenu:hide() wifi_menu ( iface ) mywifimenu:update() mywifimenu:show() end })
  204.     mywifimenu = awful.menu( {items = terms} )
  205. end
  206. net_menu_widget = wibox.widget.textbox(" ⇋") -- ⇵⇄ text widget
  207. --[[ icon widget
  208. net_menu_widget = wibox.widget {
  209.     forced_height = 24,
  210.     forced_width = 24,
  211.     widget = wibox.widget.imagebox
  212. }
  213. net_menu_widget:set_resize(false)
  214. net_menu_widget:set_image(beautiful.net_en_off)
  215.  
  216. net_menu_widget_timer = gears.timer { timeout = 5, autostart = true, call_now = true }
  217. net_menu_widget_timer:connect_signal("timeout", function()
  218.     awful.spawn.easy_async({"bash", "-c", "ip -4 -br a"},
  219.         function(out)
  220.             local icon_chooser = ""
  221.             --#https://stackoverflow.com/questions/68473020/lua-count-occurrences-of-a-character-into-a-string
  222.             for l in string.gmatch( out, "(.-)\n" ) do
  223.                 local net_name = string.match(l, "^(%S+).*")
  224.                 local net_id = string.sub(net_name, 1, 2)
  225.                 if net_id ~= "lo" then
  226.                     if net_id == "wl" then
  227.                         local fd = io.popen("iwconfig " .. net_name)
  228.                         local wireless = fd:read("*all")
  229.                         fd:close()
  230.                         local unassociated = string.find(wireless, "Access Point: Not-Associated", 1, true)
  231.                         if not unassociated then
  232.                             local percent = tonumber(string.match(wireless, "Link Quality=(%d?%d?%d)"))
  233.                             if percent == 0 or nil then icon_chooser = beautiful.net_wl_off
  234.                             elseif percent > 0 and percent < 28 then icon_chooser = beautiful.net_wl_low
  235.                             elseif percent >= 28  and percent < 60 then icon_chooser = beautiful.net_wl_ok
  236.                             elseif percent >= 60 and percent < 95 then icon_chooser = beautiful.net_wl_good
  237.                             elseif percent >=95 then icon_chooser = beautiful.net_wl_full
  238.                             end
  239.                             --break
  240.                         end
  241.                     else
  242.                         icon_chooser = beautiful.net_en_on
  243.                         --break
  244.                     end
  245.                 end
  246.             end
  247.             if icon_chooser == "" then
  248.                 net_menu_widget:set_image(beautiful.net_en_off)
  249.             else
  250.                 net_menu_widget:set_image(icon_chooser)
  251.             end
  252.         end)
  253.     end
  254. )--]]
  255.  
  256. net_menu_exec = function ( iface ) -- v2
  257.     local cmd = xterminal .. " -geometry 30x10 -e "
  258.     local onoff = ""
  259.     local info = ""
  260.     local onoff_cmd = ""
  261.     local setup_title = ""
  262.     local setup_title2 = ""
  263.     local setup_cmd = ""
  264.     local setup_cmd2 = ""
  265.     local icon = beautiful.net_en_on
  266.     local fd = io.popen("ip -4 l show " .. iface .. " && ip -4 a show " .. iface .. " && iwconfig " .. iface)
  267.     local state = fd:read("*all")
  268.     fd:close()
  269.     local up_state = string.find(state, "inet ", 1, true)
  270.     if up_state then
  271.         onoff = "disconnect"
  272.         onoff_cmd = cmd .. "\"fsudo -c | sudo -S -p ' ' netmenu_off " .. iface .. "\""
  273.         local ip_local = string.match(state, "inet (%d*.%d*.%d*.%d*/%d*)")
  274.         if ip_local == nil then info = "   " else info = ip_local end
  275.     else
  276.         onoff = "connect"
  277.         onoff_cmd = cmd .. "fsudo -c | sudo -S -p ' ' ifup " .. iface
  278.         info = "   "
  279.         if string.find(state, "NO-CARRIER", 1, true) then info = "   " end
  280.     end
  281.     if string.sub(iface, 1, 2) == "wl" then
  282.         icon = beautiful.net_wl
  283.         if not up_state then
  284.             onoff = "last network"
  285.             onoff_cmd = cmd .. " wpa_connect2 ".. iface .. " last &"
  286.         end
  287.         setup_title = "search Wi-Fi"
  288.         setup_cmd = function() wifi_menu( iface ) mywifimenu:update() mywifimenu:show() end
  289.         setup_title2 = "connect to hidden..."
  290.         setup_cmd2 = cmd .. " wpa_connect2 ".. iface .. " hidden &"
  291.     else
  292.         setup_title = "Auto"
  293.         setup_cmd = function() awful.spawn (cmd .. "\"fsudo -c | sudo -S -p ' ' dhclient " .. iface .. "\"") end
  294.         setup_title2 = "Edit config"
  295.         setup_cmd2 = cmd .. "sudo netmenu_new_conf " .. iface
  296.     end
  297.     return {
  298.         { iface, _, icon },
  299.         { "   "..onoff, function() awful.spawn(onoff_cmd) end },
  300.         { "   setup", { { setup_title, setup_cmd }, --function() () end
  301.                           { "config",{ { "Static", function() awful.spawn(cmd .. "sudo netmenu_setup_iface " .. iface .. " s" ) end },
  302.                                       { "Auto", function() awful.spawn(cmd .. "\"fsudo -c | sudo -S -p ' ' netmenu_setup_iface " .. iface .. " d\"") end },
  303.                                       { "Manual", function() awful.spawn(cmd .. "\"fsudo -c | sudo -S -p ' ' netmenu_setup_iface " .. iface .. " m\"" ) end } } },
  304.                           { setup_title2, function() awful.spawn(setup_cmd2) end },
  305.                            } },
  306.         { "   "..info, _ }
  307.     }
  308. end
  309. myifacemenu = awful.menu({ })
  310. function net_menu ()
  311.     local terms = {}
  312.     local nets = io.popen("ls /sys/class/net | tr ' ' '\n'")
  313.     for l in nets:lines() do
  314.         if l ~= "lo" then
  315.             local item = net_menu_exec(l)
  316.             for i=1,#item do
  317.                 terms[#terms+1] = item[i]
  318.             end
  319.             --table.insert(terms, item)
  320.             --naughty.notify({ text = tostring(#item) })
  321.         end
  322.     end
  323.     nets:close()
  324.     myifacemenu = awful.menu( { items = terms, theme = {height = 24, width = 180, border_width = 1 } })
  325. end
  326.  
  327. --net_menu()
  328. function net_menu_toggle_fn()
  329.     instance = nil
  330.     return function ()
  331.         if instance and instance.wibox.visible then
  332.             instance:hide()
  333.             instance = nil
  334.         else
  335.             net_menu()
  336.             instance = myifacemenu
  337.             myifacemenu:update()
  338.             myifacemenu:show()
  339.         end
  340.     end
  341. end
  342. net_menu_widget:buttons(gears.table.join(
  343.     awful.button({ }, 1, net_menu_toggle_fn() )
  344. ))
  345.  
  346. -- Display switch menu
  347. local function get_screen_id(s)
  348.     local name = ""
  349.     for i, e in pairs(s.outputs) do
  350.         name = tostring(i)
  351.     end
  352.     return name
  353. end
  354. mydisplaymenu = awful.menu({ })
  355. local displayexec = config_dir .. "/displayexec.sh "
  356. function display_menu ()
  357.     local current_display = get_screen_id(awful.screen.focused())
  358.     local terms = {}
  359.     local displays = io.popen("xrandr | grep ' connected' | awk {'print $1'}")
  360.     for l in displays:lines() do
  361.         if l ~= current_display then
  362.             local item = l
  363.             table.insert(terms, { current_display .. " <-> " .. item, {
  364.                                                     { "duplicate with " .. item, function() awful.spawn(displayexec  .. current_display .. " duplicate " .. item) end },
  365.                                                     { "switch to " .. item, function() awful.spawn(displayexec .. current_display .. " switch " .. item) end },
  366.                                                     { "extend to " .. item, {
  367.                                                                             {"left", function() awful.spawn(displayexec  .. current_display .. " extend " .. item .. " left") end },
  368.                                                                             {"above", function() awful.spawn(displayexec  .. current_display .. " extend " .. item .. " above") end },
  369.                                                                             {"right", function() awful.spawn(displayexec .. current_display .. " extend " .. item .. " right") end },
  370.                                                                             {"below", function() awful.spawn(displayexec .. current_display .. " extend " .. item .. " below") end },
  371.             }}}})
  372.         end
  373.     end
  374.     displays:close()
  375.     mydisplaymenu = awful.menu( { items = terms } )
  376. end
  377. function display_menu_toggle_fn()
  378.     instance = nil
  379.     return function ()
  380.         if instance and instance.wibox.visible then
  381.             instance:hide()
  382.             instance = nil
  383.         else
  384.             display_menu()
  385.             instance = mydisplaymenu
  386.             mydisplaymenu:update()
  387.             mydisplaymenu:show()
  388.         end
  389.     end
  390. end
  391. --display_widget = wibox.widget { widget = wibox.widget.textbox }
  392. --display_widget:set_text(" ▢ ")
  393. --display_widget:buttons(gears.table.join(
  394. --    awful.button({ }, 1, nil, display_menu_toggle_fn() )
  395. --))
  396.  
  397. -- }}}
  398.  
  399. -- {{{ Menu
  400. -- Create a launcher widget and a main menu
  401. myawesomemenu = {
  402.     { "hotkeys",    function() return false, hotkeys_popup.show_help end },
  403.     { "manual",     terminal .. " -e man awesome" },
  404.     { "edit config", gui_editor .. " " .. awesome.conffile },
  405.     { "restart",    awesome.restart }
  406. }
  407. myaccessmenu = {
  408.     { "keyboard",   vkboard },
  409.     { "magnifier",   smag },
  410.     { "screenshot", scr_full }
  411. }
  412. myappsmenu = {
  413.     { "mocp",            mocp_terminal .. " -e /usr/bin/mocp" },
  414.     { "geany",           gui_editor },
  415.     { "terminal",        terminal },
  416.     { "xterm",           xterminal },
  417.     { "calculator",      calc },
  418.     { "mComix",          comixreader },
  419.     { "torrent client",  torrent_client },
  420.     { "gimp",            geditor },
  421.     { "mind map",        mindmaps },
  422.     { "accessibility",   myaccessmenu },
  423.     { "run command",     rofi_cmd_run },
  424.     { "all apps",        rofi_cmd_drun },
  425.     --{ "run command cmb", rofi_cmd_combi },
  426.     --{ "run command wnd", rofi_cmd_window },
  427. }
  428. myexitmenu = {
  429.     { "display",   'xset dpms force off' },
  430.     { "log out",   function() awesome.quit() end },
  431.     { "suspend",   "systemctl suspend" },
  432.     { "hibernate", "systemctl hibernate" },
  433.     { "reboot",    "systemctl reboot -i" },
  434.     { "shutdown",  "systemctl poweroff" }
  435. }
  436. myexitmenu_now = awful.menu ( myexitmenu )
  437. mysetupmenu = {
  438.     { "✿ theme",   config_dir .. "/theme_switch.sh" },
  439.     { "⇋ network", net_menu_toggle_fn()},
  440.     { "▢ display", display_menu_toggle_fn()},
  441.     { "♫ sound",   smixer_gui },
  442.     { "⎙ printer", browser .. " http://localhost:631" },
  443.     { "awesomewm", myawesomemenu, beautiful.awesome_icon }
  444. }
  445. mymainmenu = awful.menu ({
  446. --mymainmenu = freedesktop.menu.build ({
  447.     --before = {
  448.         { "files",    filemanager },
  449.         { "browser", browser },
  450.         -- other triads can be put here
  451.     --},
  452.     --after = {
  453.         { "apps",  myappsmenu },
  454.         { "setup", mysetupmenu },
  455.         { "exit",  "rofi-shutdown-menu.sh" },
  456.         -- other triads can be put here
  457.     --}
  458. })
  459. --mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  460. --                                    menu = mymainmenu,
  461. --                                     --command = rofi_cmd_combi,
  462. --})
  463. --mylauncher:set_forced_width(beautiful.menu_height)
  464. --mylauncher:set_forced_height(beautiful.menu_height)
  465. mylauncher = wibox.widget {
  466.     forced_height = beautiful.menu_height,
  467.     forced_width  = beautiful.menu_height,
  468.     widget        = wibox.widget.imagebox
  469. }
  470. mylauncher:set_resize(true)
  471. mylauncher:set_image(beautiful.awesome_icon)
  472. mylauncher:buttons(gears.table.join(
  473.     awful.button({ }, 1, nil, function () mymainmenu:toggle() end),
  474.     awful.button({ }, 3, nil, function () mouse.screen.tray_popup_vert.visible = not mouse.screen.tray_popup_vert.visible end)
  475. ))
  476. mylauncher:connect_signal("mouse::enter", function() mylauncher:set_image(beautiful.awesome_icon_hover) end)
  477. mylauncher:connect_signal("mouse::leave", function() mylauncher:set_image(beautiful.awesome_icon) end)
  478.  
  479. mykeyboardlayout = awful.widget.keyboardlayout()
  480.  
  481. -- Menubar configuration
  482. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  483. -- }}}
  484.  
  485. -- {{{ Wibar
  486.  
  487. separator = wibox.widget.textbox('<span color="' .. beautiful.border_focus .. '">⋅</span>') -- ⋮∙
  488. separator:set_forced_width(beautiful.menu_height)
  489. separator:set_forced_height(beautiful.menu_height)
  490.  
  491. volumebar = wibox.widget {
  492.     widget           = wibox.widget.progressbar,
  493.     margins          = 5,
  494.     shape            = gears.shape.rounded_bar,
  495.     color            = beautiful.border_focus,
  496.     background_color = "#000000",
  497.     max_value        = 100,
  498. }
  499. sound_widget = wibox.widget {
  500.     widget        = wibox.widget.textbox,
  501.     align         = 'center',
  502.     valign        = 'center',
  503.     forced_height = beautiful.menu_height,
  504.     forced_width  = beautiful.menu_height
  505. }
  506. sound_widget:set_markup("<span color='" .. beautiful.border_focus .. "'>♫</span>\n")
  507.  
  508. function get_volume_level(vol_string, vol_format)
  509.     local volume_level = string.match(vol_string, vol_format)
  510.     if volume_level == nil then volume_level=0x0000 end
  511.     volume_level = tonumber(string.format("%04x", volume_level),"16")
  512.     return volume_level
  513. end
  514.  
  515. -- Volume widget (pa) v2
  516. volumecfg = {}
  517. volumecfg = wibox.widget.textbox( )
  518. volumecfg.pa_init = false
  519. volumecfg.get_sink = function ()
  520.     if not volumecfg.pa_init then
  521.         local fd = io.popen("pacmd dump | grep -e set-sink-volume")
  522.         local status = fd:read("*all")
  523.         pa_sink = string.match(status, "^.*( [^%s]+) ")
  524.         if pa_sink == nil then pa_sink = pa_sink_default end
  525.         fd:close()
  526.         volumecfg.pa_init = true
  527.     else
  528.         awful.spawn.easy_async({"bash", "-c","pacmd dump | grep -e set-sink-volume"},
  529.             function(out)
  530.             pa_sink = string.match(out, "^.*( [^%s]+) ")
  531.         end)
  532.     end
  533. end
  534.  
  535. volumecfg.mixercommand = function (pa_command)
  536.     awful.spawn.easy_async({"bash", "-c", pa_command .. " && pacmd dump | grep -e set-sink-volume -e set-sink-mute"},
  537.     function(out)
  538.         volume_f = get_volume_level(out, "(0x%x%x%x%x?%x)")
  539.         local volume_p = math.ceil(volume_f/655)
  540.         local volume = tostring(volume_p)
  541.         local unmuted = string.find(out, " no", 1, true)
  542.         volumebar:set_value(volume_p)
  543.         if unmuted then volume = "♫" .. volume volumebar:set_color(beautiful.border_focus)
  544.         else volume = "♩....." volumebar:set_color(beautiful.fg_minimize)
  545.         end
  546.         volumecfg:set_text(volume)
  547.     end)
  548. end
  549. volumecfg.update = function ()
  550.     volumecfg.get_sink()
  551.     volumecfg.mixercommand("pactl set-sink-volume " .. pa_sink .. " +0")
  552. end
  553. volumecfg.update()
  554. volumecfg.up = function ()
  555.     volumecfg.get_sink()
  556.     local add_volume = " +1310"
  557.     if (volume_f+1310)> 65500 then add_volume = " 65500" end
  558.     volumecfg.mixercommand("pactl set-sink-volume " .. pa_sink .. add_volume)
  559.     mouse.screen.popup_volume.visible = true mouse.screen.popup_volume_timer:again()
  560. end
  561. volumecfg.down = function ()
  562.     volumecfg.get_sink()
  563.     volumecfg.mixercommand("pactl set-sink-volume " .. pa_sink .. " -1310") mouse.screen.popup_volume.visible = true mouse.screen.popup_volume_timer:again()
  564. end
  565. volumecfg.toggle = function ()
  566.     volumecfg.get_sink()
  567.     volumecfg.mixercommand("pactl set-sink-mute " .. pa_sink .. " toggle") mouse.screen.popup_volume.visible = true mouse.screen.popup_volume_timer:again()
  568. end
  569. volumebar:buttons(gears.table.join(
  570.     --awful.button({ }, 1, function () volumecfg.toggle() end),
  571.     awful.button({ }, 4, function () volumecfg.up() end),
  572.     awful.button({ }, 5, function () volumecfg.down() end)
  573. ))
  574. -- clickable volume bar
  575. volumebar:connect_signal("button::press", function(_,xpl,_,b,_,fwr)
  576.     local volume = math.ceil(65500 * xpl/fwr.height)
  577.     if b == 1 then volumecfg.get_sink() volumecfg.mixercommand("pactl set-sink-volume " .. pa_sink .. " " .. volume ) end
  578. end)
  579. volumebar:connect_signal("button::release", function(_,xpl,_,b,_,fwr)
  580.     local volume = math.ceil(65500 * xpl/fwr.height)
  581.     if b == 1 then volumecfg.get_sink() volumecfg.mixercommand("pactl set-sink-volume " .. pa_sink .. " " .. volume ) end
  582. end)
  583.  
  584. volumecfg:buttons(gears.table.join(
  585.     awful.button({ }, 4, function () volumecfg.up() end),
  586.     awful.button({ }, 5, function () volumecfg.down() end),
  587.     awful.button({ }, 3, function () awful.spawn(smixer_gui) end),
  588.     awful.button({ }, 2, function () volumecfg.update() end),
  589.     awful.button({ }, 1, function () volumecfg.toggle() end)
  590. ))
  591.  
  592. -- Create a textclock widget and calendar
  593. mytextclock = wibox.widget.textclock(" %H:%M ")
  594.  
  595. local calendar = wibox.widget {
  596.     date          = os.date('*t'),
  597.     font          = "Helvetica Neue " .. beautiful.base_size,
  598.     --forced_width  = 250,
  599.     long_weekdays = true,
  600.     widget        = wibox.widget.calendar.month,
  601. }
  602.  
  603. mytextdate = wibox.widget {
  604.     widget       = wibox.widget.textclock("%d"),
  605.     font         = "Helvetica Neue " .. beautiful.base_size,
  606.     align        = 'center',
  607.     valign       = 'center',
  608.     forced_width = 250,
  609. }
  610.  
  611. mytexthours = wibox.widget {
  612.     widget = wibox.widget.textclock("%H"),
  613.     font   = "Helvetica Neue " .. beautiful.menu_height + 6,
  614.     align  = 'right',
  615.     valign = 'bottom',
  616. }
  617.  
  618. mytextminutes = wibox.widget {
  619.     widget = wibox.widget.textclock("%M"),
  620.     font   = "Helvetica Neue " .. beautiful.base_size + 6,
  621.     align  = 'left',
  622.     valign = 'top',
  623. }
  624.  
  625. popup_date_dt = awful.popup {
  626.     ontop     = false,
  627.     visible   = true,
  628.     bg        = string.sub(beautiful.bg_normal, 1, 7) .. "00",
  629.     fg        = beautiful.fg_normal,
  630.     placement = function (self) awful.placement.top_right(self, { margins = { top = 10, right = beautiful.menu_height + 40 } }) end,
  631.     widget    = {
  632.         {
  633.             { widget = mytexthours },
  634.             { widget = mytextminutes },
  635.             layout = wibox.layout.fixed.horizontal,
  636.         },
  637.         top    = 1,
  638.         bottom = 1,
  639.         widget = wibox.container.margin,
  640.     },
  641. }
  642.  
  643. popup_date = awful.popup {
  644.     ontop     = true,
  645.     visible   = false,
  646.     placement = function (self) awful.placement.top_right (self, { margins = { top = beautiful.menu_height + 40, right = 10 } }) end,
  647.     bg        = string.sub(beautiful.bg_normal, 1, 7),
  648.     fg        = beautiful.fg_normal,
  649.     shape     = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, beautiful.radius-1) end,
  650.     widget    = {
  651.         {
  652.             --{
  653.             --    { widget = mytexthours },
  654.             --    { widget = mytextminutes },
  655.             --    layout = wibox.layout.flex.horizontal,
  656.             --},
  657.             {
  658.                 { widget = mytextdate },
  659.                 { widget = calendar },
  660.                 layout = wibox.layout.fixed.vertical,
  661.                 expand = 'none',
  662.             },
  663.             layout = wibox.layout.fixed.vertical,
  664.         },
  665.         margins = beautiful.menu_height,
  666.         widget  = wibox.container.margin,
  667.     }
  668. }
  669.  
  670. popup_date:buttons(gears.table.join(
  671.                 awful.button({}, 3, nil, function()
  672.                     local a = calendar:get_date()
  673.                     a.month = a.month + 1
  674.                     calendar:set_date(nil)
  675.                     calendar:set_date(a)
  676.                 end),
  677.                 awful.button({}, 2, nil, function()
  678.                     calendar:set_date(nil) -- the new date is not set without removing the old one
  679.                     calendar:set_date(os.date('*t'))
  680.                 end),
  681.                 awful.button({}, 1, nil, function()
  682.                     local a = calendar:get_date()
  683.                     a.month = a.month - 1
  684.                     calendar:set_date(nil)
  685.                     calendar:set_date(a)
  686.                 end)
  687.             ))
  688.  
  689. popup_date_dt:connect_signal("button::press",
  690.     function(_, _, _, button)
  691.         if button == 1 then
  692.             if popup_date.visible then
  693.             -- to faster render the calendar refresh it and just hide
  694.                 calendar:set_date(nil) -- the new date is not set without removing the old one
  695.                 calendar:set_date(os.date('*t'))
  696.                 --popup_date:set_widget(nil) -- just in case
  697.                 --popup_date:set_widget(calendar)
  698.                 popup_date.visible = not popup_date.visible
  699.             else
  700.                 popup_date.visible = true
  701.             end
  702.        
  703.         end
  704.     end
  705. )
  706.  
  707. -- MOC widget
  708. mocwidget = {}
  709. mocwidget.w_title = wibox.widget {
  710.     widget        = wibox.widget.textbox,
  711.     forced_height = beautiful.menu_height,
  712.     forced_width  = beautiful.menu_width
  713. }
  714. mocwidget.w_artist = wibox.widget {
  715.     widget        = wibox.widget.textbox,
  716.     forced_height = beautiful.menu_height,
  717.     forced_width  = beautiful.menu_width
  718. }
  719. mocwidget.w_album = wibox.widget {
  720.     widget        = wibox.widget.textbox,
  721.     forced_height = beautiful.menu_height,
  722.     forced_width  = beautiful.menu_width
  723. }
  724.  
  725. mocline = wibox.widget {
  726.     widget           = wibox.widget.progressbar,
  727.     forced_height    = beautiful.base_size - 3,
  728.     forced_width     = beautiful.menu_width,
  729.     background_color = beautiful.notification_bg,
  730.     shape            = gears.shape.rounded_bar,
  731.     color            = beautiful.border_focus,
  732.     max_value        = 1,
  733. }
  734.  
  735. function hook_moc()
  736.     awful.spawn.easy_async({"bash", "-c", "mocp -i"},
  737.         function(out)
  738.             moc_info = out
  739.         end
  740.     )
  741.     if moc_info == nil then moc_info = "State: STOP" end
  742.     moc_state = string.gsub(string.match(moc_info, "State: %a*"),"State: ","")
  743.     if moc_state == "STOP" or nil then
  744.         moc_string = " ..."
  745.         mocline.visible = false
  746.         mocp_pause_button:set_image(beautiful.media_play)
  747.     elseif moc_state == "PLAY" or moc_state == "PAUSE" then
  748.         if moc_state == "PAUSE" then
  749.             mocline.visible = false
  750.             mocp_pause_button:set_image(beautiful.media_play)
  751.             return
  752.         end
  753.         moc_artist  = string.gsub(string.match(moc_info, "Artist: %C*"), "Artist: ","")
  754.         moc_title   = string.gsub(string.match(moc_info, "SongTitle: %C*"), "SongTitle: ","")
  755.         moc_album   = string.gsub(string.match(moc_info, "Album: %C*"), "Album: ","")
  756.         moc_path = string.gsub(string.match(moc_info, "File: %C*"), "File: ", "")
  757.         moc_file   = string.gsub(moc_path, "^.*/","")
  758.         moc_artist  = string.gsub(moc_artist, "&amp;", "&")
  759.         if string.len(moc_title) >=75 then moc_title = " title" else if string.len(moc_artist) >= 85 then moc_artist = "VA " end end
  760.         moc_title   = string.gsub(moc_title, "&amp;", "&")
  761.         moc_album   = string.gsub(moc_album, "&amp;", "&")
  762.         moc_file   = string.gsub(moc_file, "&amp;", "&")
  763.         moc_cs = string.gsub(string.match(moc_info, "CurrentSec: %d+"),"CurrentSec: ","")
  764.         ts = string.match(moc_info, "TotalSec: %d+")
  765.         if ts ~= nil then moc_ts = string.gsub(ts,"TotalSec: ","") else moc_ts = 0 end
  766.         if moc_artist == "" or nil then moc_artist = "unknown artist" end
  767.         if moc_title == "" or nil then moc_title = moc_file end
  768.         if moc_album == "" or nil then moc_album = "unknown album" end
  769.         moc_play_lineval = moc_cs/moc_ts
  770.         moc_play_percentage = math.floor(moc_play_lineval*100)
  771.         if moc_state == "PLAY" then mocline.visible = true mocp_pause_button:set_image(beautiful.media_pause) end
  772.         mocline:set_value(moc_play_lineval)
  773.     end
  774.     mocwidget.w_title:set_text(moc_title or " ")
  775.     mocwidget.w_artist:set_text("@ " .. moc_artist or " ")
  776.     mocwidget.w_album:set_text("⦾ " .. moc_album or " ")
  777. end
  778. mocwidget.t = gears.timer { timeout = 1 }
  779. mocwidget.t:connect_signal("timeout", function() hook_moc() end)
  780. -- clickable progressbar
  781. mocline:connect_signal("button::press", function(_,xpl,_,b,_,fwr)
  782.     local percent = math.floor(100 * xpl/fwr.width)
  783.     local cmd = "mocp -j " .. percent .. "%"
  784.     if b == 1 then awful.spawn.with_shell(cmd) end
  785. end)
  786. -- mocp functions
  787. function mocp_pause()
  788.     local fd = io.popen("mocp -i")
  789.     local moc_info = fd:read("*all")
  790.     fd:close()
  791.     local moc_state = string.gsub(string.match(moc_info, "State: %a*"),"State: ","")
  792.     if moc_state == "PLAY" then
  793.         awful.spawn.with_shell("mocp -P")
  794.     elseif moc_state == "PAUSE" then
  795.         awful.spawn.with_shell("mocp -U")
  796.     end
  797.     return false
  798. end
  799. function mocp_func(f)
  800. -- -Ppause -fnext -rprev -pplaylist -cclear -k{ +|-N}seek -t{ shuffle|repeat}toggle
  801.     awful.spawn.with_shell( "mocp -" .. f )
  802.     return false
  803. end
  804. function mocp_enqueue()
  805.     awful.spawn.with_shell("xte 'key a'")
  806.     return false
  807. end
  808. mocline:buttons(gears.table.join(
  809.     awful.button({ }, 5, function () mocp_func("k -10") end),
  810.     awful.button({ }, 4, function () mocp_func("k +10")  end)
  811.     ))
  812. mocp_play_button = wibox.widget {
  813.     widget = wibox.widget.textbox,
  814.     --visible = false
  815. }
  816. mocp_play_button:set_markup("<span color='" .. beautiful.border_focus .. "'> ▷</span>")
  817. --mocp_play_button:set_text(" ▷ ")
  818. mocp_play_button:buttons(gears.table.join(
  819.     awful.button({ }, 3, nil,function () spawn_client_once(mocp_terminal .. " -e /usr/bin/mocp",3) end)
  820.     ))
  821.  
  822. mocp_album_cover = wibox.widget {
  823.     forced_height = beautiful.menu_height * 4,
  824.     forced_width = beautiful.menu_height * 4,
  825.     resize = true,
  826.     widget = wibox.widget.imagebox,
  827. }
  828. mocp_album_cover:set_image("/home/" .. user .. "/.moc/default_album.png")
  829. mocp_album_cover:buttons(gears.table.join(
  830.     awful.button({ }, 1, function () awful.spawn.with_shell("xte 'key Return'") end),
  831.     awful.button({ }, 2, function () awful.spawn.with_shell("xte 'key Tab'") end),
  832.     awful.button({ }, 3, function () awful.spawn.with_shell("xte 'key BackSpace'") end),
  833.     awful.button({ }, 4, function () awful.spawn.with_shell("xte 'key Up'") end),
  834.     awful.button({ }, 5, function () awful.spawn.with_shell("xte 'key Down'") end)
  835.     ))
  836.  
  837. mocp_pause_button = wibox.widget {
  838.     forced_height = icons_size,
  839.     forced_width = icons_size,
  840.     widget = wibox.widget.imagebox
  841. }
  842. mocp_pause_button:set_resize(true)
  843. mocp_pause_button:set_image(beautiful.media_play)
  844. mocp_pause_button:buttons(gears.table.join(
  845.     awful.button({ }, 1, nil, function() mocp_pause() end),
  846.     awful.button({ }, 3, nil, function() local c = client.focus if c.class == "Sakura" then awful.spawn.with_shell("xte 'keydown Shift_L' 'key g' 'keyup Shift_L'") end end)
  847.     ))
  848. mocp_pause_button.tip = awful.tooltip { delay_show = 2 }
  849. mocp_pause_button.tip:add_to_object(mocp_pause_button)
  850. mocp_pause_button.tip.text = "1 - play\n3 - go dir"
  851.  
  852. mocp_next_button = wibox.widget {
  853.     forced_height = icons_size,
  854.     forced_width = icons_size,
  855.     widget = wibox.widget.imagebox
  856. }
  857. mocp_next_button:set_resize(true)
  858. mocp_next_button:set_image(beautiful.media_next)
  859. mocp_next_button:buttons(gears.table.join(
  860.     awful.button({ }, 1, nil, function() mocp_func("f") end)
  861.     ))
  862. mocp_prev_button = wibox.widget {
  863.     forced_height = icons_size,
  864.     forced_width = icons_size,
  865.     widget = wibox.widget.imagebox
  866. }
  867. mocp_prev_button:set_resize(true)
  868. mocp_prev_button:set_image(beautiful.media_prev)
  869. mocp_prev_button:buttons(gears.table.join(
  870.     awful.button({ }, 1, nil, function() mocp_func("r") end)
  871.     ))
  872. mocp_playlist_button = wibox.widget {
  873.     forced_height = icons_size,
  874.     forced_width = icons_size,
  875.     widget = wibox.widget.imagebox
  876. }
  877. mocp_playlist_button:set_resize(true)
  878. mocp_playlist_button:set_image(beautiful.media_playlist)
  879. mocp_playlist_button:buttons(gears.table.join(
  880.     awful.button({ }, 1, nil, function() mocp_func("p") end),
  881.     awful.button({ }, 2, nil, function() mocp_func("c") end),
  882.     awful.button({ }, 3, nil, function() local c = client.focus if c.class == "Sakura" then mocp_enqueue() end end)
  883.     ))
  884. mocp_playlist_button.tip = awful.tooltip { delay_show = 2 }
  885. mocp_playlist_button.tip:add_to_object(mocp_playlist_button)
  886. mocp_playlist_button.tip.text = "1 - play\n2 - clear\n3 - add"
  887.  
  888. mocp_shuffle_button = wibox.widget {
  889.     forced_height = icons_size,
  890.     forced_width = icons_size,
  891.     widget = wibox.widget.imagebox
  892. }
  893. mocp_shuffle_button:set_resize(true)
  894. mocp_shuffle_button:set_image(beautiful.media_shuffle)
  895. mocp_shuffle_button:buttons(gears.table.join(
  896.     awful.button({ }, 1, nil, function() mocp_func("t shuffle") end)
  897.     ))
  898. mocp_repeat_button = wibox.widget {
  899.     forced_height = icons_size,
  900.     forced_width = icons_size,
  901.     widget = wibox.widget.imagebox
  902. }
  903. mocp_repeat_button:set_resize(true)
  904. mocp_repeat_button:set_image(beautiful.media_repeat)
  905. mocp_repeat_button:buttons(gears.table.join(
  906.     awful.button({ }, 1, nil, function() mocp_func("t repeat") end)
  907.     ))
  908.  
  909. -- Scrot
  910. scr_button = wibox.widget {
  911.     widget = wibox.widget.textbox,
  912.     --visible = false
  913. }
  914. scr_button:set_text(" ⬚")
  915. scr_button:buttons(gears.table.join(
  916.     awful.button({ }, 1, function () awful.spawn.with_shell(scr_area)  end),
  917.     awful.button({ }, 2, function () awful.spawn.with_shell(scr_full)  end),
  918.     awful.button({ }, 3, function () awful.spawn.with_shell(scr_area_delay)  end)
  919.     ))
  920.  
  921. mocp_play_button:connect_signal("button::press",
  922.     function(_, _, _, button)
  923.         if button == 1 then
  924.             if mouse.screen.popup_mocp.visible then
  925.                 mouse.screen.popup_mocp.visible = not mouse.screen.popup_mocp.visible
  926.                 mocwidget.t:stop()
  927.             else
  928.                 mouse.screen.popup_mocp.visible = true
  929.                 mocwidget.t:start()
  930.                 mocp_album_cover:set_image(gears.surface.load_uncached("/home/" .. user .. "/.moc/current_album.png"))
  931.             end
  932.         end
  933.     end
  934. )
  935.  
  936. -- unused
  937. --[[ Battery indicator (example)(v082r)
  938. mybatterybar = wibox.widget {
  939.     {
  940.         min_value        = 0,
  941.         max_value        = 100,
  942.         color            = beautiful.border_focus,
  943.         background_color = beautiful.bg_normal,
  944.         border_width     = 1,
  945.         border_color     = beautiful.border_focus,
  946.         forced_width     = beautiful.menu_height,
  947.         forced_height           = beautiful.menu_height - 4,
  948.         shape = function(cr) -- custom scalable shape
  949.             local h = beautiful.menu_height
  950.             cr:move_to(0,       h/2           )
  951.             cr:line_to(0,       h - 6 * h/23  )
  952.             cr:line_to(h - h/8, h - 6 * h/23  )
  953.             cr:line_to(h - h/8, h/2 - 3 * h/23)
  954.             cr:line_to(h - 1,   h/2 - 3* h/23 )
  955.             cr:line_to(h - 1,   h/2 + h/23    )  
  956.             cr:line_to(h - h/8, h/2 + h/23    )
  957.             cr:line_to(h - h/8, 4 * h/23      )
  958.             cr:line_to(0,       4 * h/23      )
  959.             cr:close_path()
  960.         end,
  961.         id               = "mypb",
  962.         widget           = wibox.widget.progressbar,
  963.         value            = 0,
  964.     },
  965.     {
  966.         id               = "mytb",
  967.         text             = "0",
  968.         --valign = "top",
  969.         widget           = wibox.widget.textbox,
  970.         font             = beautiful.font_name .. " " .. math.ceil(beautiful.menu_height/2.45),
  971.     },
  972.     layout      = wibox.layout.stack,
  973.     set_battery = function(self, val)
  974.         if beautiful.menu_height < 25 then self.mytb.text = " "
  975.         else self.mytb.text  = " " .. val end
  976.         self.mypb.value = val
  977.     end
  978. }
  979. local battery_tooltip = " "
  980. gears.timer {
  981.     timeout   = 5,
  982.     call_now  = true,
  983.     autostart = true,
  984.     callback  = function()
  985.         awful.spawn.easy_async({"bash", "-c", "acpi"},
  986.             function(out)
  987.                 local percent = tonumber(string.match(out, "(%d?%d?%d)%%"))
  988.                 battery_state = string.match(out, ": (%a+),")
  989.                 battery_time = tostring(string.match(out, "(%d%d:%d%d):"))
  990.                 if battery_state == nil then battery_state = "n/a" end
  991.                 if percent == 100 then battery_time = " full" end
  992.                 if percent == nil then percent = 0 end
  993.                 if percent < 11 and battery_state == "Discharging" then awful.spawn("systemctl suspend") end
  994.                 mybatterybar.battery = percent
  995.                 battery_tooltip = "<span size='xx-large'>" .. percent .. "%</span>\n\n" .. battery_state .. ": " .. battery_time .. "\n"
  996.             end
  997.         )
  998.     end
  999. }
  1000. local mybattery_t = awful.tooltip { delay_show = 1.5 }
  1001. mybattery_t:add_to_object(mybatterybar)
  1002. mybatterybar:connect_signal('mouse::enter', function()
  1003.     mybattery_t.markup = battery_tooltip
  1004. end)--]]
  1005.  
  1006. -- Kanji show widget
  1007. --[[kanji = {}
  1008. kanji.w = wibox.widget {
  1009.     widget = wibox.widget.textbox,
  1010.     text = " 漢字 "
  1011. }
  1012. kanji.t = awful.tooltip { }
  1013. kanji.t:add_to_object(kanji.w)
  1014. kanji.timer = gears.timer {
  1015.     timeout   = 120,
  1016.     call_now  = true,
  1017.     autostart = true,
  1018.     callback  = function()
  1019.         awful.spawn.easy_async({"bash", "-c", "cat ".. config_dir .. "/jlpt5_4_list.txt | head -n`shuf -i 1-320 -n 1` | tail -n1"},
  1020.             function(out)
  1021.                 local kanji_current = string.match(out, "^(.*);.*;")
  1022.                 local on_kun = string.match(out, ";(.*);")
  1023.                 local rus = string.match(out, "^.*;(.*)$")
  1024.                 kanji.w:set_text(kanji_current)
  1025.                 kanji.t.text = on_kun .. "\n" .. rus
  1026.             end
  1027.         )
  1028.     end
  1029. }--]]
  1030.  
  1031. -- Create a wibox for each screen and add it
  1032. local taglist_buttons = gears.table.join(
  1033.                     awful.button({ }, 1, function(t) t:view_only() end),
  1034.                     awful.button({ modkey }, 1, function(t)
  1035.                                               if client.focus then
  1036.                                                   client.focus:move_to_tag(t)
  1037.                                               end
  1038.                                           end),
  1039.                    --[[ awful.button({ }, 2, function(t)
  1040.                                               if client.focus then
  1041.                                                   local c = client.focus
  1042.                                                   if c.fullscreen then
  1043.                                                       c.fullscreen = not c.fullscreen
  1044.                                                   else c.fullscreen = true
  1045.                                                   end
  1046.                                                  
  1047.                                               end
  1048.                                           end),--]]
  1049.                     --awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end),
  1050.                     --awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end),
  1051.                     awful.button({ }, 3, awful.tag.viewtoggle),
  1052.                     awful.button({ modkey }, 3, function(t)
  1053.                                               if client.focus then
  1054.                                                   client.focus:toggle_tag(t)
  1055.                                               end
  1056.                                           end)
  1057. )
  1058. local tasklist_buttons = gears.table.join(
  1059.                      awful.button({ }, 1, function (c)
  1060.                                               if c == client.focus then
  1061.                                                   c.minimized = true
  1062.                                               else
  1063.                                                   -- Without this, the following
  1064.                                                   -- :isvisible() makes no sense
  1065.                                                   c.minimized = false
  1066.                                                   if not c:isvisible() and c.first_tag then
  1067.                                                       c.first_tag:view_only()
  1068.                                                   end
  1069.                                                   -- This will also un-minimize
  1070.                                                   -- the client, if needed
  1071.                                                   client.focus = c
  1072.                                                   c:raise()
  1073.                                               end
  1074.                                           end),
  1075.                      awful.button({ }, 2, function (c)
  1076.                                               if c:isvisible() then
  1077.                                                   c.first_tag:view_only()
  1078.                                               end
  1079.                                               client.focus = c
  1080.                                               c:kill()
  1081.                                           end),
  1082.                      --awful.button({ }, 4, function () awful.client.focus.byidx(1) end),
  1083.                      --awful.button({ }, 5, function () awful.client.focus.byidx(-1) end)),
  1084.                      awful.button({ }, 3, client_menu_toggle_fn() )
  1085. )
  1086.  
  1087. -- Wallpaper
  1088. local function set_wallpaper(s)
  1089.     if beautiful.wallpaper then
  1090.         local wallpaper = beautiful.wallpaper
  1091.         -- If wallpaper is a function, call it with the screen
  1092.         if type(wallpaper) == "function" then
  1093.             wallpaper = wallpaper(s)
  1094.         else
  1095. -- set (pattern)    Set the current wallpaper.
  1096. -- centered (surf, s, background, scale)    Set a centered wallpaper.
  1097. -- tiled (surf, s, offset)  Set a tiled wallpaper.
  1098. -- maximized (surf, s, ignore_aspect, offset)   Set a maximized wallpaper.
  1099. -- fit (surf, s, background)    Set a fitting wallpaper.
  1100.             gears.wallpaper.maximized(wallpaper, s, false)
  1101.         end
  1102.     end
  1103. end
  1104. -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
  1105. screen.connect_signal("property::geometry", set_wallpaper)
  1106.  
  1107. empty_widget = wibox.widget {
  1108.     widget = wibox.widget.textbox,
  1109. }
  1110. empty_widget:set_text(" ")
  1111. --empty_widget:set_forced_width(5)
  1112. --empty_widget:set_forced_height(beautiful.menu_height)
  1113.  
  1114.  
  1115. awful.screen.connect_for_each_screen(function(s)
  1116.     -- Wallpaper
  1117.     set_wallpaper(s)
  1118.     -- Tags
  1119.     if s.index == 1 then
  1120.         awful.tag.add(inet_tag, {
  1121.             --icon                = "/path/to/icon1.png",
  1122.             --gap_single_client   = true,
  1123.             --master_fill_policy   = "master_width_factor",
  1124.             layout              = awful.layout.suit.tile,
  1125.             master_width_factor = 0.71,
  1126.             master_count        = 1,
  1127.             --gap                 = 5,
  1128.             screen              = 1,
  1129.             selected            = true,
  1130.             index               = 1,
  1131.         })
  1132.         awful.tag.add(misc_tag, {
  1133.             layout = awful.layout.suit.fair,
  1134.             screen = 1,
  1135.             index  = 2,
  1136.         })
  1137.         awful.tag.add(media_tag, {
  1138.             layout = awful.layout.suit.max,
  1139.             screen = 1,
  1140.             index  = 3,
  1141.         })
  1142.         awful.tag.add(files_tag, {
  1143.             layout = awful.layout.suit.spiral.dwindle,
  1144.             screen = 1,
  1145.             index  = 4,
  1146.         })
  1147.     else
  1148.         awful.tag.add("Screen " .. screen_index_mark(s), {
  1149.             layout   = awful.layout.suit.spiral.dwindle,
  1150.             screen   = s,
  1151.             index    = 1,
  1152.             --gap      = 0,
  1153.             selected = true,
  1154.         })
  1155.     end
  1156.     -- Create a promptbox for each screen
  1157.     s.mypromptbox = awful.widget.prompt()
  1158.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  1159.     -- We need one layoutbox per screen.
  1160.     --s.mylayoutbox = awful.widget.layoutbox()
  1161.     s.mylayoutbox = wibox.widget {
  1162.         {
  1163.             awful.widget.layoutbox(s),
  1164.             top    = math.ceil(beautiful.base_size/2.5),
  1165.             left   = math.ceil(beautiful.base_size/2.5),
  1166.             right  = math.ceil(beautiful.base_size/3.5),
  1167.             widget = wibox.container.margin,
  1168.         },
  1169.         bg     = beautiful.bg_normal,
  1170.         widget = wibox.container.background,
  1171.     }
  1172.     s.mylayoutbox:buttons(gears.table.join(
  1173.             --awful.button({ }, 4, function () awful.layout.inc( 1) end),
  1174.             --awful.button({ }, 5, function () awful.layout.inc(-1) end),
  1175.             awful.button({ }, 1, function () awful.layout.inc( 1) end),
  1176.             awful.button({ }, 3, function () awful.layout.inc(-1) end)
  1177.     ))
  1178.     s.mylayoutbox:set_forced_width(beautiful.menu_height - 4)
  1179.     s.mylayoutbox:set_forced_height(beautiful.menu_height)
  1180.     -- Volume popup
  1181.     s.popup_volume = awful.popup {
  1182.         ontop     = true,
  1183.         visible   = false,
  1184.         screen    = s,
  1185.         shape     = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, beautiful.radius-1) end,
  1186.         placement = function(self,s) awful.placement.top_right( self, { margins = { top = beautiful.menu_height, right = beautiful.menu_height } }) end,
  1187.         widget    = {
  1188.             {
  1189.                 {
  1190.                     { widget = volumebar },
  1191.                     forced_height = beautiful.menu_height*5,
  1192.                     forced_width  = beautiful.menu_height,
  1193.                     direction     = 'east',
  1194.                     layout        = wibox.container.rotate,
  1195.                 },
  1196.                 { widget = sound_widget },
  1197.                 layout = wibox.layout.fixed.vertical,
  1198.             },
  1199.             widget  = wibox.container.margin,
  1200.         },
  1201.     }
  1202.     s.popup_volume_timer = gears.timer { timeout = 2.1 }
  1203.     s.popup_volume_timer:connect_signal("timeout", function() s.popup_volume.visible = false s.popup_volume_timer:stop() end)
  1204.     s.popup_volume:connect_signal("mouse::enter", function(w) s.popup_volume.visible = true s.popup_volume_timer:again() end)
  1205.     s.popup_volume:connect_signal("mouse::move", function(w) s.popup_volume.visible = true s.popup_volume_timer:again() end)
  1206.     -- Mocp popup
  1207.     s.popup_mocp = awful.popup {
  1208.         ontop        = true,
  1209.         visible      = false,
  1210.         screen       = s,
  1211.         shape        = function(cr, width, height) gears.shape.partially_rounded_rect(cr, width, height, true, true, false, true, beautiful.radius-1 ) end,
  1212.         placement    = function(self) awful.placement.right( self, { margins = { right = beautiful.menu_height + 40 } }) end,
  1213.         border_width = 1,
  1214.         border_color = beautiful.border_focus,
  1215.         widget       = {
  1216.             {
  1217.                 {
  1218.                     {
  1219.                         {
  1220.                             {
  1221.                                 { widget = mocp_album_cover, },
  1222.                                 bg         = beautiful.bg_normal,
  1223.                                 shape_clip = true,
  1224.                                 shape      = function(cr, width, height) gears.shape.partially_rounded_rect(cr, width, height, true, true, false, true, (beautiful.radius-1)*2) end,
  1225.                                 widget     = wibox.container.background,
  1226.                             },
  1227.                             margins = 5,
  1228.                             widget  = wibox.container.margin,
  1229.                         },
  1230.                         {
  1231.                             {
  1232.                                 { widget = mocp_playlist_button },
  1233.                                 { widget = mocp_shuffle_button },
  1234.                                 { widget = mocp_repeat_button },
  1235.                                 layout = wibox.layout.align.horizontal,
  1236.                                 expand = 'none',
  1237.                             },
  1238.                             { widget = mocwidget.w_artist },
  1239.                             { widget = mocwidget.w_album },
  1240.                             { widget = mocwidget.w_title },
  1241.                             layout = wibox.layout.fixed.vertical,
  1242.                         },
  1243.                         layout = wibox.layout.fixed.horizontal,
  1244.                     },
  1245.                     layout = wibox.layout.fixed.horizontal,
  1246.                 },
  1247.                 { widget = mocline },
  1248.                 {
  1249.                     { widget = mocp_prev_button },
  1250.                     { widget = mocp_pause_button },
  1251.                     { widget = mocp_next_button },
  1252.                     layout = wibox.layout.align.horizontal,
  1253.                     expand = 'none',
  1254.                 },
  1255.                 layout = wibox.layout.fixed.vertical,
  1256.             },
  1257.             margins = 10,
  1258.             widget  = wibox.container.margin,
  1259.         },
  1260.     }
  1261.     -- Create a taglist widget
  1262.     s.mytaglist = awful.widget.taglist { --(s, awful.widget.taglist.filter.all, taglist_buttons)
  1263.         screen  = s,
  1264.         filter  = awful.widget.taglist.filter.all,
  1265.         buttons = taglist_buttons,
  1266.         forced_height = beautiful.menu_height,
  1267.         --style = { shape = function(cr, width, height) gears.shape.rounded_rect (cr, width, height, beautiful.radius) end, },
  1268.         widget_template = {
  1269.             {
  1270.                 {
  1271.                     layout = wibox.layout.fixed.vertical,
  1272.                     {
  1273.                         {
  1274.                             left   = 1,
  1275.                             right  = 1,
  1276.                             top    = math.ceil(beautiful.menu_height/3), -- slider height
  1277.                             widget = wibox.container.margin
  1278.                         },
  1279.                         id           = 'slider',
  1280.                         bg           = '#ffffff',
  1281.                         forced_width = math.ceil(beautiful.menu_height/2),
  1282.                         shape        = function(cr, width, height) gears.shape.rounded_bar (cr, math.ceil(beautiful.menu_height/4), math.ceil(beautiful.menu_height/4)) end,
  1283.                         widget       = wibox.container.background,
  1284.                     },
  1285.                     --{
  1286.                         --{
  1287.                             --id     = 'text_role',
  1288.                             --widget = wibox.widget.textbox,
  1289.                         --},
  1290.                         --left   = 1,
  1291.                         --top    = -1,
  1292.                         --right  = 1,
  1293.                         --widget = wibox.container.margin,
  1294.                     --}
  1295.                 },
  1296.                 top   = math.ceil(beautiful.menu_height/3),
  1297.                 left  = math.ceil(beautiful.menu_height/3),
  1298.                 right = 0,
  1299.                 widget = wibox.container.margin,
  1300.              },
  1301.              id              = 'background_role',
  1302.              widget          = wibox.container.background,
  1303.             create_callback = function(self, c3, index, objects)
  1304.                 local focused = false
  1305.                 for _, x in pairs(awful.screen.focused().selected_tags) do
  1306.                     if x.index == index then
  1307.                         focused = true
  1308.                         break
  1309.                     end
  1310.                 end
  1311.                 if awful.tag.getproperty(c3, "urgent") then
  1312.                     self:get_children_by_id("slider")[1].bg = beautiful.bg_urgent
  1313.                 else
  1314.                     self:get_children_by_id("slider")[1].bg = beautiful.border_focus
  1315.                 end
  1316.                 if focused then
  1317.                     self:get_children_by_id("slider")[1].shape = function(cr, width, height) gears.shape.rounded_bar (cr, math.ceil(beautiful.menu_height/2), math.ceil(beautiful.menu_height/4)) end
  1318.                 else
  1319.                     self:get_children_by_id("slider")[1].shape = function(cr, width, height) gears.shape.rounded_bar (cr, math.ceil(beautiful.menu_height/4), math.ceil(beautiful.menu_height/4)) end
  1320.                 end
  1321.             end,
  1322.             update_callback = function(self, c3, index, objects)
  1323.                 local focused = false
  1324.                 for _, x in pairs(awful.screen.focused().selected_tags) do
  1325.                     if x.index == index then
  1326.                         focused = true
  1327.                         break
  1328.                     end
  1329.                 end
  1330.                 if awful.tag.getproperty(c3, "urgent") then
  1331.                     self:get_children_by_id("slider")[1].bg = beautiful.bg_urgent
  1332.                 else
  1333.                     self:get_children_by_id("slider")[1].bg = beautiful.border_focus
  1334.                 end
  1335.                 if focused then
  1336.                     self:get_children_by_id("slider")[1].shape = function(cr, width, height) gears.shape.rounded_bar (cr, math.ceil(beautiful.menu_height/2), math.ceil(beautiful.menu_height/4)) end
  1337.                 else
  1338.                     self:get_children_by_id("slider")[1].shape = function(cr, width, height) gears.shape.rounded_bar (cr, math.ceil(beautiful.menu_height/4), math.ceil(beautiful.menu_height/4)) end
  1339.                 end
  1340.             end
  1341.             },
  1342.         layout   = {
  1343.             spacing = 2,
  1344.             layout  = wibox.layout.fixed.horizontal,
  1345.         },
  1346.     }
  1347.     -- Create a tasklist widget
  1348.     s.mytasklist = awful.widget.tasklist {
  1349.         screen  = s,
  1350.         filter   = awful.widget.tasklist.filter.alltags,
  1351.         buttons = tasklist_buttons,
  1352.         style   = {
  1353.             shape = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, beautiful.radius-1) end,
  1354.         },
  1355.         layout  = {
  1356.             spacing         = 10,
  1357.             forced_num_rows = 1,
  1358.             layout          = wibox.layout.grid.horizontal,
  1359.         },
  1360.         widget_template = {
  1361.             {
  1362.                 {
  1363.                     id     = 'clienticon',
  1364.                     widget = awful.widget.clienticon,
  1365.                 },
  1366.                 margins = 1,
  1367.                 widget  = wibox.container.margin,
  1368.             },
  1369.             id              = 'background_role',
  1370.             forced_width    = beautiful.menu_height,
  1371.             forced_height   = beautiful.menu_height,
  1372.             widget          = wibox.container.background,
  1373.             create_callback = function(self, c, index, objects) --luacheck: no unused
  1374.                 self:get_children_by_id('clienticon')[1].client = c
  1375.                 -- tooltip v1
  1376.                 -- todo: destroy, reload, signals
  1377.                 --local c_tip = awful.tooltip { delay_show = 1.5 }
  1378.                 --c_tip:add_to_object(self)
  1379.                 --c_tip.text = c.name
  1380.             end,
  1381.         },
  1382.     }
  1383.  
  1384.     s.task_popup_bar = awful.popup {
  1385.         ontop         = false,
  1386.         visible       = true,
  1387.         screen        = s,
  1388.         border_width  = 0,
  1389.         border_color  = beautiful.border_focus,
  1390.         forced_height = beautiful.menu_height,
  1391.         shape         = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, beautiful.radius-1) end,
  1392.         placement     = function (self,s) awful.placement.top_left( self, { margins = { top = 10, left = 10 } }) end,
  1393.         widget        = {
  1394.             {
  1395.                 mylauncher,
  1396.                 --mybatterybar,
  1397.                 s.mytaglist,
  1398.                 s.mytasklist,
  1399.                 spacing   = 10,
  1400.                 layout    = wibox.layout.fixed.horizontal,
  1401.                 fill_space = false,
  1402.             },
  1403.             margins = 10,
  1404.             widget  = wibox.container.margin,
  1405.         }
  1406.     }
  1407.     s.task_popup_bar:buttons(gears.table.join(
  1408.             awful.button({ }, 1, function () s.task_popup_bar:draw() end)
  1409.     ))
  1410.     -- Task popup (example)
  1411.     s.task_popup = awful.popup {
  1412.         screen       = s,
  1413.         border_color = beautiful.border_normal,
  1414.         border_width = 2,
  1415.         ontop        = true,
  1416.         placement    = awful.placement.centered,
  1417.         shape        = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, 10) end,
  1418.         visible      = false,
  1419.         widget       = awful.widget.tasklist {
  1420.             screen  = s,
  1421.             filter   = awful.widget.tasklist.filter.allscreen,
  1422.             buttons = tasklist_buttons,
  1423.             style   = {
  1424.                 shape = function(cr, width, height) gears.shape.rounded_rect(cr, width, height, 6) end,
  1425.             },
  1426.             layout = {
  1427.                 spacing         = 5,
  1428.                 forced_num_rows = 1,
  1429.                 layout          = wibox.layout.grid.horizontal
  1430.             },
  1431.             widget_template = {
  1432.                 {
  1433.                     {
  1434.                         id     = 'clienticon',
  1435.                         widget = awful.widget.clienticon,
  1436.                     },
  1437.                     margins = 4,
  1438.                     widget  = wibox.container.margin,
  1439.                 },
  1440.                 id              = 'background_role',
  1441.                 forced_width    = beautiful.menu_height*2,
  1442.                 forced_height   = beautiful.menu_height*2,
  1443.                 widget          = wibox.container.background,
  1444.                 create_callback = function(self, c, index, objects) --luacheck: no unused
  1445.                     self:get_children_by_id('clienticon')[1].client = c
  1446.                 end,
  1447.             },
  1448.         },
  1449.     }
  1450.     s.task_popup_timer = gears.timer { timeout = 2 }
  1451.     s.task_popup_timer:connect_signal("timeout", function() s.task_popup.visible = false s.task_popup_timer:stop() end)
  1452.     s.task_popup:connect_signal("mouse::enter", function(w)
  1453.         w.visible = true s.task_popup_timer:again()
  1454.     end)
  1455.     s.task_popup:connect_signal("mouse::move", function(w)
  1456.         w.visible = true s.task_popup_timer:again()
  1457.     end)
  1458.  
  1459.     s.mysystray = wibox.widget.systray()
  1460.     s.mysystray:set_base_size(beautiful.menu_height)
  1461.     s.mysystray:set_horizontal(false)
  1462.     s.mysystray:set_screen(s)
  1463.     s.mysystray:set_reverse(true)
  1464.    
  1465.     s.tray_popup_vert = awful.popup {
  1466.         ontop     = true,
  1467.         visible   = false,
  1468.         shape     = function(cr, width, height) gears.shape.rounded_rect (cr, width, height, beautiful.radius-1) end,
  1469.         screen    = s,
  1470.         placement = function (self,s) awful.placement.top_left( self, { margins = { top = beautiful.menu_height + 40, left = 10 } }) end,
  1471.         widget    = {
  1472.             {
  1473.                 s.mysystray,
  1474.                 layout = wibox.layout.fixed.vertical,
  1475.                 forced_width = beautiful.menu_height,
  1476.             },
  1477.             margins = 10,
  1478.             widget  = wibox.container.margin,
  1479.         },
  1480.     }
  1481.     s.tray_popup_vert:buttons(gears.table.join(
  1482.         awful.button({ }, 2, function () s.tray_popup_vert.visible = not s.tray_popup_vert.visible end)
  1483.     ))
  1484.     -- Side bar
  1485.     s.sidebar_min = awful.popup {
  1486.         ontop     = true,
  1487.         screen    = s,
  1488.         visible   = true,
  1489.         shape     = function(cr, width, height) gears.shape.partially_rounded_rect (cr, width, height, true, false, false, true, beautiful.radius-1) end,
  1490.         placement = function (self,s) awful.placement.right( self ) end,
  1491.         widget    = {
  1492.             { widget = empty_widget },
  1493.             layout = wibox.layout.align.vertical,
  1494.             forced_height = beautiful.menu_height*8,
  1495.             forced_width = 2,
  1496.             expand = 'outside',
  1497.         },
  1498.     }
  1499.     s.sidebar_min:buttons(gears.table.join(
  1500.         awful.button({ }, 4, function () volumecfg.up() end),
  1501.         awful.button({ }, 5, function () volumecfg.down() end)
  1502.     ))
  1503.     s.sidebar = awful.popup {
  1504.         ontop     = true,
  1505.         visible   = false,
  1506.         shape     = function(cr, width, height) gears.shape.partially_rounded_rect (cr, width, height, true, false, false, true, beautiful.radius-1) end,
  1507.         screen    = s,
  1508.         placement = function (self,s) awful.placement.right( self ) end,
  1509.         widget    = {
  1510.             {
  1511.                 {
  1512.                     {
  1513.                         mytextclock,
  1514.                         layout = wibox.layout.fixed.vertical,
  1515.                     },
  1516.                     volumecfg,
  1517.                     {
  1518.                         mykeyboardlayout,
  1519.                         mocp_play_button,
  1520.                         net_menu_widget,
  1521.                         scr_button,
  1522.                         s.mylayoutbox,
  1523.                         layout = wibox.layout.grid.vertical,
  1524.                         forced_num_rows = 3,
  1525.                         forced_num_cols = 2,
  1526.                         homogeneous     = true,
  1527.                         expand          = false,
  1528.                     },
  1529.                     forced_height = beautiful.menu_height*8,
  1530.                     layout = wibox.layout.align.vertical,
  1531.                     expand = 'inside',
  1532.                 },
  1533.                 layout = wibox.layout.fixed.vertical
  1534.             },
  1535.             margins = 10,
  1536.             widget  = wibox.container.margin,
  1537.         },
  1538.     }
  1539.     s.sidebar:buttons(gears.table.join(
  1540.         awful.button({ }, 4, function () volumecfg.up() end),
  1541.         awful.button({ }, 5, function () volumecfg.down() end)
  1542.     ))
  1543.     s.sidebar_timer = gears.timer { timeout = 3 }
  1544.     s.sidebar_timer:connect_signal("timeout", function(t) s.sidebar.visible = false s.sidebar_min.visible = true t:stop() end)
  1545.     s.sidebar_min:connect_signal("mouse::enter", function(w) s.sidebar.visible = true w.visible = false end)
  1546.     s.sidebar:connect_signal("mouse::leave", function(w) s.sidebar_timer:again() end)    
  1547. end)
  1548. -- }}}
  1549.  
  1550. -- {{{ Mouse bindings
  1551. root.buttons(gears.table.join(
  1552.     --awful.button({ }, 4, awful.tag.viewnext),
  1553.     --awful.button({ }, 5, awful.tag.viewprev),
  1554.     --awful.button({ }, 3, client_menu_toggle_fn() ),
  1555.     awful.button({ }, 1, function () mymainmenu:hide() myifacemenu:hide() end)
  1556. ))
  1557. -- }}}
  1558. -- Test window switcher
  1559. local tiled_c = false
  1560. local tiled = function()
  1561.     if tiled_c == false then awful.client.focus.byidx(-1) awful.layout.inc(1) tiled_c = true
  1562.     else awful.layout.inc(1) tiled_c = false
  1563.     end
  1564. end
  1565. -- Show task popup
  1566. local function task_popup_play_tab()
  1567.     for s in screen do
  1568.     s.task_popup.visible = true s.task_popup_timer:again()
  1569.     end
  1570.     local all_clients = awful.client.iterate(function (x) return true end)
  1571.     for c in awful.client.iterate(function (x) return true end) do
  1572.         if client.focus ~= c then
  1573.             awful.tag.viewmore(c:tags(), c.screen)
  1574.             client.focus = c
  1575.             client.focus:raise()
  1576.             c:emit_signal("request::activate", "ewmh", {raise = true})
  1577.             return
  1578.         end
  1579.     end
  1580. end
  1581. local function task_popup_play()
  1582.      mouse.screen.task_popup.visible = true mouse.screen.task_popup_timer:again()
  1583. end
  1584.  
  1585. -- {{{ Key bindings
  1586. globalkeys = gears.table.join(
  1587.     awful.key({ modkey            }, "e", function () awful.spawn(rofi_file_browser) end,
  1588.               {description = "rofi file browser", group = "rofi"}),
  1589.     awful.key({ modkey            }, "a", function () awful.spawn(rofi_cmd_drun) end,
  1590.               {description = "rofi drun", group = "rofi"}),
  1591.     awful.key({ modkey,           }, "s",      hotkeys_popup.show_help,
  1592.               {description="show help", group="awesome"}),
  1593.     awful.key({ modkey,           }, "Right", function() awful.tag.viewidx(1) task_popup_play() end,
  1594.               {description = "view previous", group = "tag"}),
  1595.     awful.key({ modkey,           }, "Left", function() awful.tag.viewidx(-1) task_popup_play() end,
  1596.               {description = "view next", group = "tag"}),
  1597.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore,
  1598.               {description = "go back", group = "tag"}),
  1599.     awful.key({ modkey,           }, "Up",
  1600.         function ()
  1601.             awful.client.focus.byidx( 1) task_popup_play()
  1602.         end,
  1603.               {description = "focus next by index", group = "client"}
  1604.     ),
  1605.     awful.key({ modkey,           }, "Down",
  1606.         function ()
  1607.             awful.client.focus.byidx(-1) task_popup_play()
  1608.         end,
  1609.               {description = "focus previous by index", group = "client"}
  1610.     ),
  1611.     awful.key({ modkey,           }, "w", function () mymainmenu:show() end,
  1612.     --awful.key({ modkey,           }, "w", function () awful.spawn(rofi_cmd_window) end,
  1613.               {description = "show main menu", group = "awesome"}),
  1614.     -- Layout manipulation
  1615.     awful.key({ modkey, "Shift"   }, "Right", function () awful.client.swap.byidx(  1)    end,
  1616.               {description = "swap with next client by index", group = "client"}),
  1617.     awful.key({ modkey, "Shift"   }, "Left", function () awful.client.swap.byidx( -1)    end,
  1618.               {description = "swap with previous client by index", group = "client"}),
  1619.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
  1620.               {description = "focus the next screen", group = "screen"}),
  1621.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end,
  1622.               {description = "focus the previous screen", group = "screen"}),
  1623.     awful.key({ modkey,           }, "u", function() awful.client.urgent.jumpto() end,
  1624.               {description = "jump to urgent client", group = "client"}),
  1625.     awful.key({ modkey, "Shift"   }, "Tab", client_menu_toggle_fn(),
  1626.               {description = "open client menu", group = "client"}),
  1627.     awful.key({ modkey,           }, "Tab", function () task_popup_play_tab() end,
  1628.               {description = "switch windows via popup", group = "client"}),
  1629.     --[[awful.key({ modkey,           }, "Tab",
  1630.         function ()
  1631.             task_popup.visible = true task_popup_timer:again()
  1632.             local all_clients = awful.client.iterate(function (x) return true end)
  1633.             for c in awful.client.iterate(function (x) return true end) do
  1634.                 if client.focus ~= c then
  1635.                     awful.tag.viewmore(c:tags(), c.screen)
  1636.                     client.focus = c
  1637.                     client.focus:raise()
  1638.                     c:emit_signal("request::activate", "ewmh", {raise = true})
  1639.                     return
  1640.                 end
  1641.             end
  1642.         end,
  1643.         {description = "switch clients", group = "client"}),--]]
  1644.     -- Standard program
  1645.     awful.key({ modkey,           }, "Return", function () awful.spawn(terminal) end,
  1646.               {description = "open a terminal", group = "launcher"}),
  1647.     awful.key({ modkey,           }, "z", function () awful.spawn("rofi-translate-run-enru") end,
  1648.               {description = "open a rofi translate", group = "launcher"}),
  1649.     awful.key({ modkey, "Shift"   }, "z", function () awful.spawn("rofi-translate-run-ruen") end,
  1650.               {description = "open a rofi translate", group = "launcher"}),
  1651.     awful.key({ modkey, "Control" }, "r", awesome.restart,
  1652.               {description = "reload awesome", group = "awesome"}),
  1653.     awful.key({ modkey, "Shift"   }, "q", awesome.quit,
  1654.               {description = "quit awesome", group = "awesome"}),
  1655.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)                 end,
  1656.               {description = "increase master width factor", group = "layout"}),
  1657.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)                 end,
  1658.               {description = "decrease master width factor", group = "layout"}),
  1659.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1, nil, true)        end,
  1660.               {description = "increase the number of master clients", group = "layout"}),
  1661.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1, nil, true)        end,
  1662.               {description = "decrease the number of master clients", group = "layout"}),
  1663.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1, nil, true)           end,
  1664.               {description = "increase the number of columns", group = "layout"}),
  1665.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1, nil, true)           end,
  1666.               {description = "decrease the number of columns", group = "layout"}),
  1667.     awful.key({ modkey,           }, "space", function () awful.layout.inc(-1) end,
  1668.               {description = "select previous", group = "layout"}),
  1669.     awful.key({ modkey            }, "b", function () awful.spawn(browser)          end,
  1670.               {description = "launch Browser", group = "launcher"}),
  1671.     awful.key({ modkey, "Control" }, "d", display_menu_toggle_fn(),
  1672.               {description = "show display_switch menu", group = "menu"}),
  1673.     awful.key({                   }, "Print", function () awful.spawn.with_shell(scr_full)   end,
  1674.               {description = "capture a screenshot", group = "screenshot"}),
  1675.     awful.key({ modkey,           }, "Print", function () awful.spawn.with_shell(scr_area) end,
  1676.               {description = "capture a screenshot of a selection", group = "screenshot"}),
  1677.     awful.key({ modkey, "Shift"   }, "Print", function () awful.spawn.with_shell(scr_active_window)   end,
  1678.               {description = "capture a screenshot of an active window", group = "screenshot"}),
  1679.     awful.key({ modkey, "Shift"   }, "n", net_menu_toggle_fn(),
  1680.               {description = "net menu", group = "menu"}),
  1681.     awful.key({ modkey, "Control" }, "n",
  1682.               function ()
  1683.                   local c = awful.client.restore()
  1684.                   -- Focus restored client
  1685.                   if c then
  1686.                       client.focus = c
  1687.                       c:raise()
  1688.                   end
  1689.               end,
  1690.               {description = "restore minimized", group = "client"}),
  1691.     -- Prompt
  1692.     awful.key({ modkey            }, "r", function () awful.spawn(rofi_cmd_run)
  1693.             --awful.screen.focused().mypromptbox:run()
  1694.         end,
  1695.               {description = "run prompt", group = "launcher"}),
  1696.     --[[awful.key({ modkey, "Shift"   }, "r",
  1697.               function ()
  1698.                   awful.prompt.run {
  1699.                     prompt       = "Run Lua code: ",
  1700.                     textbox      = awful.screen.focused().mypromptbox.widget,
  1701.                     exe_callback = awful.util.eval,
  1702.                     history_path = awful.util.get_cache_dir() .. "/history_eval"
  1703.                   }
  1704.               end,
  1705.               {description = "lua execute prompt", group = "awesome"}),--]]
  1706.     -- Menubar
  1707.     awful.key({ modkey            }, "p", function() menubar.show() end,
  1708.               {description = "show the menubar", group = "launcher"}),
  1709.     -- XF86
  1710.     --awful.key({ }, "XF86WakeUp", function () volumecfg.down() end),
  1711.     --awful.key({ }, "XF86Display", function() end ),
  1712.     awful.key({ }, "XF86Sleep", function () awful.spawn("rofi-shutdown-menu.sh") end,
  1713.               {description = "show poweroff screen", group = "mediakeys"}),
  1714.     awful.key({ }, "XF86PowerOff", function () awful.spawn("rofi-shutdown-menu.sh") end,
  1715.               {description = "show poweroff screen", group = "mediakeys"}),
  1716.     awful.key({ }, "XF86AudioMute", function () volumecfg.toggle() end,
  1717.               {description = "toggle mute", group = "mediakeys"}),
  1718.     awful.key({ }, "XF86AudioRaiseVolume", function () volumecfg.up() end,
  1719.               {description = "volume up", group = "mediakeys"}),
  1720.     awful.key({ }, "XF86AudioLowerVolume", function () volumecfg.down() end,
  1721.               {description = "volume down", group = "mediakeys"}),
  1722.     awful.key({ }, "XF86Calculator", function() awful.spawn(calc) end,
  1723.               {description = "run calculator", group = "mediakeys"}),
  1724.     awful.key({ }, "XF86AudioMedia", function() spawn_client_once(mocp_terminal .. " -e /usr/bin/mocp",3) end,
  1725.               {description = "run player", group = "mediakeys"})
  1726. )
  1727.  
  1728. clientkeys = gears.table.join(
  1729.     awful.key({ modkey,           }, "f",
  1730.         function (c)
  1731.             c.fullscreen = not c.fullscreen
  1732.             c:raise()
  1733.         end,
  1734.         {description = "toggle fullscreen", group = "client"}),
  1735.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end,
  1736.               {description = "close", group = "client"}),
  1737.     awful.key({ modkey, "Control" }, "space",  function (c) c.floating = not c.floating        end,
  1738.               {description = "toggle floating", group = "client"}),
  1739.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end,
  1740.               {description = "move to master", group = "client"}),
  1741.     awful.key({ modkey,           }, "o",      function (c) c:move_to_screen()               end,
  1742.               {description = "move to screen", group = "client"}),
  1743.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end,
  1744.               {description = "toggle tray popup", group = "popup"}),
  1745.     awful.key({ modkey, "Control" }, "t",      function () mouse.screen.tray_popup_vert.visible = not mouse.screen.tray_popup_vert.visible end,
  1746.               {description = "toggle keep on top", group = "client"}),
  1747.     awful.key({ modkey, "Shift"   }, "t",
  1748.         function (c)
  1749.             t = awful.tag.add(c.class or "N/A", {screen=c.screen, volatile=true})
  1750.             if not t then return end
  1751.             local tags = c:tags()
  1752.             table.insert(tags, t)
  1753.             c:tags(tags)
  1754.             c:move_to_tag(t)
  1755.             awful.tag.viewonly(t)
  1756.         end,
  1757.               {description = "move client to new tag", group = "client"}),
  1758.     awful.key({ modkey,           }, "n",
  1759.         function (c)
  1760.             -- The client currently has the input focus, so it cannot be
  1761.             -- minimized, since minimized clients can't have the focus.
  1762.             c.minimized = true
  1763.         end ,
  1764.         {description = "minimize", group = "client"}),
  1765.     awful.key({ modkey,           }, "m",
  1766.         function (c)
  1767.             c.maximized = not c.maximized
  1768.             c:raise()
  1769.         end ,
  1770.         {description = "ex((un)maximize) raise sakura terminal with mocp client", group = "client"}),
  1771.     awful.key({ modkey, "Control" }, "m",
  1772.         function (c)
  1773.             c.maximized_vertical = not c.maximized_vertical
  1774.             c:raise()
  1775.         end ,
  1776.         {description = "(un)maximize vertically", group = "client"}),
  1777.     awful.key({ modkey, "Shift"   }, "m",
  1778.         function (c)
  1779.             c.maximized_horizontal = not c.maximized_horizontal
  1780.             c:raise()
  1781.         end ,
  1782.         {description = "(un)maximize horizontally", group = "client"})
  1783. )
  1784.  
  1785. -- Bind all key numbers to tags.
  1786. -- Be careful: we use keycodes to make it work on any keyboard layout.
  1787. -- This should map on the top row of your keyboard, usually 1 to 9.
  1788. for i = 1, 9 do
  1789.     globalkeys = gears.table.join(globalkeys,
  1790.         -- View tag only.
  1791.         awful.key({ modkey }, "#" .. i + 9,
  1792.                   function ()
  1793.                         local screen = awful.screen.focused()
  1794.                         local tag = screen.tags[i]
  1795.                         if tag then
  1796.                            tag:view_only()
  1797.                         end
  1798.                   end,
  1799.                   {description = "view tag #"..i, group = "tag"}),
  1800.         -- Toggle tag display.
  1801.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  1802.                   function ()
  1803.                       local screen = awful.screen.focused()
  1804.                       local tag = screen.tags[i]
  1805.                       if tag then
  1806.                          awful.tag.viewtoggle(tag)
  1807.                       end
  1808.                   end,
  1809.                   {description = "toggle tag #" .. i, group = "tag"}),
  1810.         -- Move client to tag.
  1811.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  1812.                   function ()
  1813.                       if client.focus then
  1814.                           local tag = client.focus.screen.tags[i]
  1815.                           if tag then
  1816.                               client.focus:move_to_tag(tag)
  1817.                           end
  1818.                      end
  1819.                   end,
  1820.                   {description = "move focused client to tag #"..i, group = "tag"}),
  1821.         -- Toggle tag on focused client.
  1822.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  1823.                   function ()
  1824.                       if client.focus then
  1825.                           local tag = client.focus.screen.tags[i]
  1826.                           if tag then
  1827.                               client.focus:toggle_tag(tag)
  1828.                           end
  1829.                       end
  1830.                   end,
  1831.                   {description = "toggle focused client on tag #" .. i, group = "tag"})
  1832.     )
  1833. end
  1834.  
  1835. clientbuttons = gears.table.join(
  1836.     awful.button({ }, 1, function (c) if c.name ~= "Onboard" then -- unfocusable screen keyboard
  1837.                                           client.focus = c
  1838.                                       end
  1839.                                       c:raise()
  1840.                                       mymainmenu:hide()
  1841.                                       myexitmenu_now:hide()
  1842.                                       for s in screen do s.popup_mocp.visible = false end
  1843.                                       if mocwidget.t.started then mocwidget.t:stop() end
  1844.     end),
  1845.     awful.button({ modkey }, 1, awful.mouse.client.move),
  1846.     awful.button({ modkey }, 3, awful.mouse.client.resize)
  1847. )
  1848.  
  1849.  
  1850. -- Set keys
  1851. root.keys(globalkeys)
  1852. -- }}}
  1853.  
  1854. -- {{{ Rules
  1855. -- Rules to apply to new clients (through the "manage" signal).
  1856. awful.rules.rules = {
  1857.     -- All clients will match this rule.
  1858.     { rule = { },
  1859.       properties = { border_width = beautiful.border_width,
  1860.                      --border_color = beautiful.border_normal,
  1861.                      titlebars_enabled = true,
  1862.                      focus = awful.client.focus.filter,
  1863.                      raise = true,
  1864.                      keys = clientkeys,
  1865.                      buttons = clientbuttons,
  1866.                      size_hints_honor = false, -- Remove gaps between terminals
  1867.                      screen = 1,--awful.screen.preferred,
  1868.                      maximized = false,
  1869.                      callback = awful.client.setslave,
  1870.                      placement = awful.placement.no_overlap+awful.placement.no_offscreen
  1871.       }
  1872.     },
  1873.     -- Add titlebars to normal clients and dialogs
  1874.     { rule_any = {type = { "normal", "dialog" } },
  1875.       properties = { titlebars_enabled = true }
  1876.     },
  1877.     -- Floating clients
  1878.     { rule_any = {
  1879.         class = {
  1880.             "Pavucontrol",
  1881.             "Xarchiver",
  1882.             "Calcoo",
  1883.             "Galculator",
  1884.             "Wine",
  1885.             "Qemu-system-x86_64",
  1886.             "Gtk-theme-switch2",
  1887.             "Gtk-chtheme",
  1888.             "discord",
  1889.             "Discord",
  1890.             "libreoffice",
  1891.             "Geany",
  1892.             "Gnome-screenshot",
  1893.             "Xsane"
  1894.         },
  1895.         name = {
  1896.             "Event Tester",  -- xev.
  1897.         },
  1898.                 role = {
  1899.             "pop-up",       -- e.g. Google Chrome's (detached) Developer Tools.
  1900.         }
  1901.       }, properties = { floating = true, titlebars_enabled = true, placement = awful.placement.centered, maximized = false } },
  1902.     { rule = { class = "Sakura" },
  1903.        properties = { tag = media_tag, switchtotag = true } },
  1904.     { rule_any = { class = { "qpdfview", "Viewnior", "MComix", "Gimp" } },
  1905.        properties = { titlebars_enabled = true } },
  1906.     { rule_any = { class = { "qBittorrent", "Transmission-gtk" } },
  1907.        properties = { tag = inet_tag, switchtotag = true, titlebars_enabled = true } },
  1908.     { rule = { role = "browser" },
  1909.        properties = { tag = inet_tag, switchtotag = true, floating = false } },
  1910.     { rule = { role = "GtkFileChooserDialog" },
  1911.        properties = { floating = true, placement = awful.placement.centered, titlebars_enabled = true } },
  1912.     { rule = { role = "file_manager" },
  1913.        properties = { tag = files_tag, switchtotag = true, switchtotag = true } },
  1914.     { rule = { name = "Поиск файлов" },
  1915.        properties = { titlebars_enabled = true } },
  1916.     { rule_any = { class = { "X-terminal-emulator", "Lxterminal" } },
  1917.        properties = { tag = misc_tag, switchtotag = true } },
  1918.     { rule_any = { role = { "PictureInPicture", "text_dialog", "task_dialog", "rename_dialog" } },
  1919.        properties = { titlebars_enabled = true, ontop = true, floating = true, maximized = false, sticky = true, placement = awful.placement.centered
  1920.                       } },
  1921.     { rule = { class = "XTerm" },
  1922.        --callback = function(c)
  1923.        --    local w_area = screen[ awful.screen.focused().index ].workarea
  1924.        --    c:geometry( { y = math.ceil(w_area.height/2) } )
  1925.        --    end,
  1926.        --properties = { titlebars_enabled = true, focus = true, ontop = true, floating = true, maximized_horizontal = true, maximized_vertical = false, sticky = true
  1927.        properties = { placement = awful.placement.bottom_right, focus = true, ontop = false, floating = true, maximized_horizontal = false, maximized_vertical = false, sticky = true,
  1928.                       } },
  1929.     { rule_any = { class = { "mpv", "vlc" } },
  1930.        callback = function(c)
  1931.            awful.spawn.with_shell("mocp -P")
  1932.        end,
  1933.        properties = { titlebars_enabled = true } },
  1934.     { rule = { class = "Onboard" },
  1935.        properties = { titlebars_enabled = false, floating = true, focusable = false, focus = false, ontop = true, --hidden = true,
  1936.        } },
  1937.     { rule = { icon_name = "xzoom" },
  1938.        properties = { titlebars_enabled = true, floating = true, focusable = false, focus = false, ontop = true, sticky = true, placement = awful.placement.centered
  1939.        } },
  1940. }
  1941. -- }}}
  1942.  
  1943. -- {{{ Signals
  1944.  
  1945. -- Signal function to execute when a new client appears.
  1946. client.connect_signal("manage", function (c)
  1947.     c.border_color = beautiful.bg_normal
  1948.     -- Set the windows at the slave,
  1949.     -- i.e. put it at the end of others instead of setting it master.
  1950.     -- if not awesome.startup then awful.client.setslave(c) end
  1951.     --awful.client.setslave(c)
  1952.     if awesome.startup and
  1953.       not c.size_hints.user_position
  1954.       and not c.size_hints.program_position then
  1955.         -- Prevent clients from being unreachable after screen count changes.
  1956.         awful.placement.no_offscreen(c)
  1957.     end
  1958. end)
  1959.  
  1960. awful.titlebar.enable_tooltip = false
  1961. -- https://r.nf/r/awesomewm/comments/oahc1a/quick_guide_how_to_create_a_double_border_effect/
  1962. -- Add a titlebar if titlebars_enabled is set to true in the rules.
  1963.  
  1964. client.connect_signal("request::titlebars", function(c)
  1965.     local titlebar_right = {
  1966.                      awful.titlebar.widget.stickybutton   (c),
  1967.                      awful.titlebar.widget.ontopbutton    (c),
  1968.                      awful.titlebar.widget.floatingbutton (c),
  1969.                      layout = wibox.layout.fixed.horizontal(),
  1970.     }
  1971.     local titlebar_left = {
  1972.                      --mykeyboardlayout,
  1973.                      awful.titlebar.widget.maximizedbutton(c),
  1974.                      awful.titlebar.widget.minimizebutton (c),
  1975.                      layout = wibox.layout.fixed.horizontal(),
  1976.     }
  1977.     -- buttons for the titlebar
  1978.     local buttons = gears.table.join(
  1979.         awful.button({ }, 1, function()
  1980.             c:emit_signal("request::activate", "titlebar", {raise = true})
  1981.             awful.mouse.client.move(c)
  1982.         end),
  1983.         awful.button({ }, 3, function()
  1984.             c:emit_signal("request::activate", "titlebar", {raise = true})
  1985.             awful.mouse.client.resize(c)
  1986.         end)
  1987.     )
  1988.     local top_titlebar = awful.titlebar(c, {
  1989.         size            = 4,
  1990.         enable_tooltip  = false,
  1991.         position        = 'top',
  1992.     }) : setup {
  1993.         {
  1994.             {
  1995.                 bg     = c.border_color,
  1996.                 widget = wibox.container.background,
  1997.             },
  1998.             top    = 2,
  1999.             left   = 2,
  2000.             right  = 2,
  2001.             widget = wibox.container.margin
  2002.         },
  2003.  
  2004.         bg     = c.border_color,
  2005.         widget = wibox.container.background,
  2006.     }
  2007.  
  2008.     local bottom_titlebar = awful.titlebar(c, {
  2009.         size            = beautiful.menu_height+15,
  2010.         enable_tooltip  = false,
  2011.         position        = 'bottom',
  2012.     })
  2013.     bottom_titlebar:setup {
  2014.         { -- Right
  2015.              {
  2016.                  {
  2017.                      {
  2018.                          awful.titlebar.widget.closebutton   (c),
  2019.                          top = 4, bottom = 4,
  2020.                          widget  = wibox.container.margin,
  2021.                      },
  2022.                      layout  = wibox.layout.fixed.horizontal,
  2023.                  },
  2024.                  titlebar_left,
  2025.                  layout  = wibox.layout.fixed.horizontal,
  2026.                  spacing = 5,
  2027.              },
  2028.              margins = 10,
  2029.              widget  = wibox.container.margin,
  2030.         },
  2031.         { -- Middle
  2032.            { -- Title
  2033.                align  = "center",
  2034.                font = beautiful.font_name .. " " ..  tostring(math.ceil(0.85*beautiful.base_size)),
  2035.                widget = awful.titlebar.widget.titlewidget(c)
  2036.            },
  2037.            buttons = buttons,
  2038.            expand = "inside",
  2039.            layout  = wibox.layout.flex.horizontal
  2040.         },
  2041.         { -- Right
  2042.              {
  2043.                  titlebar_right,
  2044.                  {
  2045.                      awful.titlebar.widget.iconwidget(c),
  2046.                      buttons = buttons,
  2047.                      layout  = wibox.layout.fixed.horizontal,
  2048.                  },
  2049.                  layout  = wibox.layout.fixed.horizontal,
  2050.                  spacing = 5,
  2051.              },
  2052.              margins = 10,
  2053.              widget  = wibox.container.margin,
  2054.         },
  2055.         layout = wibox.layout.align.horizontal,
  2056.     }
  2057.  
  2058.     local left_titlebar = awful.titlebar(c, {
  2059.         size            = 4,
  2060.         enable_tooltip  = false,
  2061.         position        = 'left',
  2062.     })
  2063.     left_titlebar:setup {
  2064.         {
  2065.             {
  2066.                 bg     = c.border_color,
  2067.                 widget = wibox.container.background
  2068.             },
  2069.             left   = 2,
  2070.             widget = wibox.container.margin
  2071.         },
  2072.         bg     =  c.border_color,
  2073.         widget = wibox.container.background,
  2074.     }
  2075.  
  2076.     local right_titlebar = awful.titlebar(c, {
  2077.         size            = 4,
  2078.         enable_tooltip  = false,
  2079.         position        = 'right',
  2080.     })
  2081.     right_titlebar:setup {
  2082.         {
  2083.             {
  2084.                 bg     = c.border_color,
  2085.                 widget = wibox.container.background
  2086.             },
  2087.             right  = 2,
  2088.             widget = wibox.container.margin
  2089.         },
  2090.         bg     = c.border_color,
  2091.         widget = wibox.container.background
  2092.     }
  2093.  
  2094. end)
  2095.  
  2096. -- OnSongChange.sh signal
  2097. awesome.connect_signal("music::changed",
  2098.     function()
  2099.         mocp_album_cover:set_image(gears.surface.load_uncached("/home/" .. user .. "/.moc/current_album.png"))
  2100.     end
  2101. )
  2102.  
  2103. client.connect_signal("property::size", function(c)
  2104.     if c.fullscreen then
  2105.         c.shape = gears.shape.rectangle
  2106.     else c.shape = function(cr,w,h) gears.shape.rounded_rect(cr,w,h,beautiful.radius-1) end
  2107.     end
  2108. end
  2109. )
  2110. -- unused
  2111.  
  2112. --[[ Enable sloppy focus, so that focus follows mouse.
  2113. client.connect_signal("mouse::enter", function(c)
  2114.     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  2115.         and awful.client.focus.filter(c) then
  2116.         client.focus = c
  2117.     end
  2118. end)--]]
  2119.  
  2120. --client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  2121. --client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  2122.  
  2123. --[[ hint: focus client under mouse
  2124. tag.connect_signal("property::selected",
  2125.     function (t)
  2126.         local selected = tostring(t.selected) == "true"
  2127.         if selected then
  2128.             local mouseX = mouse.coords().x
  2129.             local mouseY = mouse.coords().y
  2130.             for k,v in pairs(t.screen.all_clients) do
  2131.                 if v.first_tag.index==t.index and mouseX>=v.x and mouseX<=(v.x+v.width) and mouseY>=v.y and mouseY<=(v.y+v.height) then
  2132.                     client.focus = v
  2133.                     v:raise()
  2134.                 end
  2135.             end
  2136.         end
  2137.     end
  2138. )
  2139. client.connect_signal("property::fullscreen", function(c)
  2140.     c.shape = gears.shape.rectangle
  2141. end
  2142. )
  2143. client.connect_signal("property::floating", function (c)
  2144.     if c.floating then
  2145.         awful.titlebar.show(c)
  2146.     else
  2147.         awful.titlebar.hide(c)
  2148.     end
  2149. end)
  2150. --]]
  2151. -- }}}
  2152.  
  2153. -- Autorun
  2154. run_once("/usr/bin/mocp --server")
  2155. run_once(config_dir.."/theme_terminals.sh '" .. string.sub(beautiful.bg_normal,1,7) .. "' '" .. string.sub(beautiful.fg_normal,1,7) .. "'")
  2156. run_once("lxpolkit &")
  2157. --run_once("irexec -d")
  2158.  
Add Comment
Please, Sign In to add comment