Guest User

Untitled

a guest
Oct 2nd, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.24 KB | None | 0 0
  1. -- Standard awesome library
  2. local gears = require("gears")
  3. local awful = require("awful")
  4. awful.rules = require("awful.rules")
  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 menubar = require("menubar")
  13. -- Battery
  14. local battery = require("battery")
  15. -- NetworkManager library
  16. require("network.pech")
  17.  
  18. -- Battery
  19. batterywidget = wibox.widget.textbox()
  20. batterywidget_timer = timer({timeout = 1})
  21. batterywidget_timer:connect_signal("timeout", function()
  22.   batterywidget:set_text(batteryInfo("BAT0"))
  23. end)
  24. batterywidget_timer:start()
  25. batterywidget:set_text(batteryInfo("BAT0"))
  26.  
  27.  
  28.     -- create a network menu widget
  29.     function mynetworkmenu()
  30.         networkmenu = awful.menu({  items = netmgr.generate_network_menu()    })
  31.         return networkmenu
  32.     end
  33.     mynetworklauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  34.                         menu = mynetworkmenu()})
  35.  
  36.         nettimer = timer({ timeout = 360 })
  37.     nettimer:connect_signal("timeout", function()
  38.         mynetworklauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  39.                                             menu = mynetworkmenu()})
  40.         end)
  41.     nettimer:start()
  42. -- {{{ Error handling
  43. -- Check if awesome encountered an error during startup and fell back to
  44. -- another config (This code will only ever execute for the fallback config)
  45. if awesome.startup_errors then
  46.     naughty.notify({ preset = naughty.config.presets.critical,
  47.                      title = "Oops, there were errors during startup!",
  48.                      text = awesome.startup_errors })
  49. end
  50.  
  51. -- Handle runtime errors after startup
  52. do
  53.     local in_error = false
  54.     awesome.connect_signal("debug::error", function (err)
  55.         -- Make sure we don't go into an endless error loop
  56.         if in_error then return end
  57.         in_error = true
  58.  
  59.         naughty.notify({ preset = naughty.config.presets.critical,
  60.                          title = "Oops, an error happened!",
  61.                          text = err })
  62.         in_error = false
  63.     end)
  64. end
  65. -- }}}
  66.  
  67. -- {{{ Variable definitions
  68. -- Themes define colours, icons, font and wallpapers.
  69. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  70.  
  71. -- This is used later as the default terminal and editor to run.
  72. terminal = "urxvt"
  73. editor = os.getenv("EDITOR") or "nano"
  74. editor_cmd = terminal .. " -e " .. editor
  75.  
  76. -- Default modkey.
  77. -- Usually, Mod4 is the key with a logo between Control and Alt.
  78. -- If you do not like this or do not have such a key,
  79. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  80. -- However, you can use another modifier like Mod1, but it may interact with others.
  81. modkey = "Mod4"
  82.  
  83. -- Table of layouts to cover with awful.layout.inc, order matters.
  84. local layouts =
  85. {
  86.     awful.layout.suit.floating,
  87.     awful.layout.suit.tile,
  88.     awful.layout.suit.tile.left,
  89.     awful.layout.suit.tile.bottom,
  90.     awful.layout.suit.tile.top,
  91.     awful.layout.suit.fair,
  92.     awful.layout.suit.fair.horizontal,
  93.     awful.layout.suit.spiral,
  94.     awful.layout.suit.spiral.dwindle,
  95.     awful.layout.suit.max,
  96.     awful.layout.suit.max.fullscreen,
  97.     awful.layout.suit.magnifier
  98. }
  99. -- }}}
  100.  
  101. -- {{{ Wallpaper
  102. if beautiful.wallpaper then
  103.     for s = 1, screen.count() do
  104.         gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  105.     end
  106. end
  107. -- }}}
  108.  
  109. -- {{{ Tags
  110. -- Define a tag table which hold all screen tags.
  111. tags = {}
  112. for s = 1, screen.count() do
  113.     -- Each screen has its own tag table.
  114.     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  115. end
  116. -- }}}
  117.  
  118. -- {{{ Menu
  119. -- Create a laucher widget and a main menu
  120. myawesomemenu = {
  121.    { "manual", terminal .. " -e man awesome" },
  122.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  123.    { "restart", awesome.restart },
  124.    { "quit", awesome.quit }
  125. }
  126.  
  127. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  128.                                     { "open terminal", terminal }
  129.                                   }
  130.                         })
  131.  
  132. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  133.                                      menu = mymainmenu })
  134.  
  135. -- Menubar configuration
  136. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  137. -- }}}
  138.  
  139. -- {{{ Wibox
  140. -- Create a textclock widget
  141. mytextclock = awful.widget.textclock()
  142.  
  143. -- Create a wibox for each screen and add it
  144. mywibox = {}
  145. mypromptbox = {}
  146. mylayoutbox = {}
  147. mytaglist = {}
  148. mytaglist.buttons = awful.util.table.join(
  149.                     awful.button({ }, 1, awful.tag.viewonly),
  150.                     awful.button({ modkey }, 1, awful.client.movetotag),
  151.                     awful.button({ }, 3, awful.tag.viewtoggle),
  152.                     awful.button({ modkey }, 3, awful.client.toggletag),
  153.                     awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  154.                     awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  155.                     )
  156. mytasklist = {}
  157. mytasklist.buttons = awful.util.table.join(
  158.                      awful.button({ }, 1, function (c)
  159.                                               if c == client.focus then
  160.                                                   c.minimized = true
  161.                                               else
  162.                                                   -- Without this, the following
  163.                                                   -- :isvisible() makes no sense
  164.                                                   c.minimized = false
  165.                                                   if not c:isvisible() then
  166.                                                       awful.tag.viewonly(c:tags()[1])
  167.                                                   end
  168.                                                   -- This will also un-minimize
  169.                                                   -- the client, if needed
  170.                                                   client.focus = c
  171.                                                   c:raise()
  172.                                               end
  173.                                           end),
  174.                      awful.button({ }, 3, function ()
  175.                                               if instance then
  176.                                                   instance:hide()
  177.                                                   instance = nil
  178.                                               else
  179.                                                   instance = awful.menu.clients({
  180.                                                       theme = { width = 250 }
  181.                                                   })
  182.                                               end
  183.                                           end),
  184.                      awful.button({ }, 4, function ()
  185.                                               awful.client.focus.byidx(1)
  186.                                               if client.focus then client.focus:raise() end
  187.                                           end),
  188.                      awful.button({ }, 5, function ()
  189.                                               awful.client.focus.byidx(-1)
  190.                                               if client.focus then client.focus:raise() end
  191.                                           end))
  192.  
  193. for s = 1, screen.count() do
  194.     -- Create a promptbox for each screen
  195.     mypromptbox[s] = awful.widget.prompt()
  196.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  197.     -- We need one layoutbox per screen.
  198.     mylayoutbox[s] = awful.widget.layoutbox(s)
  199.     mylayoutbox[s]:buttons(awful.util.table.join(
  200.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  201.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  202.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  203.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  204.     -- Create a taglist widget
  205.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  206.  
  207.     -- Create a tasklist widget
  208.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  209.  
  210.     -- Create the wibox
  211.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  212.  
  213.     -- Widgets that are aligned to the left
  214.     local left_layout = wibox.layout.fixed.horizontal()
  215.     left_layout:add(mylauncher)
  216.     left_layout:add(mytaglist[s])
  217.     left_layout:add(mypromptbox[s])
  218.  
  219.     -- Widgets that are aligned to the right
  220.     local right_layout = wibox.layout.fixed.horizontal()
  221.     if s == 1 then right_layout:add(wibox.widget.systray()) end
  222.     right_layout:add(mynetworklauncher)
  223.     right_layout:add(batterywidget)
  224.     right_layout:add(mytextclock)
  225.     right_layout:add(mylayoutbox[s])
  226.  
  227.     -- Now bring it all together (with the tasklist in the middle)
  228.     local layout = wibox.layout.align.horizontal()
  229.     layout:set_left(left_layout)
  230.     layout:set_middle(mytasklist[s])
  231.     layout:set_right(right_layout)
  232.  
  233.     mywibox[s]:set_widget(layout)
  234. end
  235. -- }}}
  236.  
  237. -- {{{ Mouse bindings
  238. root.buttons(awful.util.table.join(
  239.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  240.     awful.button({ }, 4, awful.tag.viewnext),
  241.     awful.button({ }, 5, awful.tag.viewprev)
  242. ))
  243. -- }}}
  244.  
  245. -- {{{ Key bindings
  246. globalkeys = awful.util.table.join(
  247.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  248.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  249.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  250.  
  251.     awful.key({ modkey,           }, "j",
  252.         function ()
  253.             awful.client.focus.byidx( 1)
  254.             if client.focus then client.focus:raise() end
  255.         end),
  256.     awful.key({ modkey,           }, "k",
  257.         function ()
  258.             awful.client.focus.byidx(-1)
  259.             if client.focus then client.focus:raise() end
  260.         end),
  261.     awful.key({ modkey,           }, "w", function () mymainmenu:show() end),
  262.  
  263.     -- Layout manipulation
  264.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  265.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  266.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  267.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  268.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  269.     awful.key({ modkey,           }, "Tab",
  270.         function ()
  271.             awful.client.focus.history.previous()
  272.             if client.focus then
  273.                 client.focus:raise()
  274.             end
  275.         end),
  276.  
  277.     -- Standard program
  278.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  279.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  280.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  281.  
  282.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  283.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  284.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  285.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  286.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  287.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  288.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  289.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  290.  
  291.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  292.  
  293.     -- Prompt
  294.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  295.  
  296.     awful.key({ modkey }, "x",
  297.               function ()
  298.                   awful.prompt.run({ prompt = "Run Lua code: " },
  299.                   mypromptbox[mouse.screen].widget,
  300.                   awful.util.eval, nil,
  301.                   awful.util.getdir("cache") .. "/history_eval")
  302.               end),
  303.     -- Menubar
  304.     awful.key({ modkey }, "p", function() menubar.show() end)
  305. )
  306.  
  307. clientkeys = awful.util.table.join(
  308.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  309.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  310.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  311.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  312.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  313.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  314.     awful.key({ modkey,           }, "n",
  315.         function (c)
  316.             -- The client currently has the input focus, so it cannot be
  317.             -- minimized, since minimized clients can't have the focus.
  318.             c.minimized = true
  319.         end),
  320.     awful.key({ modkey,           }, "m",
  321.         function (c)
  322.             c.maximized_horizontal = not c.maximized_horizontal
  323.             c.maximized_vertical   = not c.maximized_vertical
  324.         end)
  325. )
  326.  
  327. -- Bind all key numbers to tags.
  328. -- Be careful: we use keycodes to make it works on any keyboard layout.
  329. -- This should map on the top row of your keyboard, usually 1 to 9.
  330. for i = 1, 9 do
  331.     globalkeys = awful.util.table.join(globalkeys,
  332.         -- View tag only.
  333.         awful.key({ modkey }, "#" .. i + 9,
  334.                   function ()
  335.                         local screen = mouse.screen
  336.                         local tag = awful.tag.gettags(screen)[i]
  337.                         if tag then
  338.                            awful.tag.viewonly(tag)
  339.                         end
  340.                   end),
  341.         -- Toggle tag.
  342.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  343.                   function ()
  344.                       local screen = mouse.screen
  345.                       local tag = awful.tag.gettags(screen)[i]
  346.                       if tag then
  347.                          awful.tag.viewtoggle(tag)
  348.                       end
  349.                   end),
  350.         -- Move client to tag.
  351.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  352.                   function ()
  353.                       if client.focus then
  354.                           local tag = awful.tag.gettags(client.focus.screen)[i]
  355.                           if tag then
  356.                               awful.client.movetotag(tag)
  357.                           end
  358.                      end
  359.                   end),
  360.         -- Toggle tag.
  361.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  362.                   function ()
  363.                       if client.focus then
  364.                           local tag = awful.tag.gettags(client.focus.screen)[i]
  365.                           if tag then
  366.                               awful.client.toggletag(tag)
  367.                           end
  368.                       end
  369.                   end))
  370. end
  371.  
  372. clientbuttons = awful.util.table.join(
  373.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  374.     awful.button({ modkey }, 1, awful.mouse.client.move),
  375.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  376.  
  377. -- Set keys
  378. root.keys(globalkeys)
  379. -- }}}
  380.  
  381. -- {{{ Rules
  382. -- Rules to apply to new clients (through the "manage" signal).
  383. awful.rules.rules = {
  384.     -- All clients will match this rule.
  385.     { rule = { },
  386.       properties = { border_width = beautiful.border_width,
  387.                      border_color = beautiful.border_normal,
  388.                      focus = awful.client.focus.filter,
  389.                      raise = true,
  390.                      keys = clientkeys,
  391.                      buttons = clientbuttons } },
  392.     { rule = { class = "MPlayer" },
  393.       properties = { floating = true } },
  394.     { rule = { class = "pinentry" },
  395.       properties = { floating = true } },
  396.     { rule = { class = "gimp" },
  397.       properties = { floating = true } },
  398.     -- Set Firefox to always map on tags number 2 of screen 1.
  399.     -- { rule = { class = "Firefox" },
  400.     --   properties = { tag = tags[1][2] } },
  401. }
  402. -- }}}
  403.  
  404. -- {{{ Signals
  405. -- Signal function to execute when a new client appears.
  406. client.connect_signal("manage", function (c, startup)
  407.     -- Enable sloppy focus
  408.     c:connect_signal("mouse::enter", function(c)
  409.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  410.             and awful.client.focus.filter(c) then
  411.             client.focus = c
  412.         end
  413.     end)
  414.  
  415.     if not startup then
  416.         -- Set the windows at the slave,
  417.         -- i.e. put it at the end of others instead of setting it master.
  418.         -- awful.client.setslave(c)
  419.  
  420.         -- Put windows in a smart way, only if they does not set an initial position.
  421.         if not c.size_hints.user_position and not c.size_hints.program_position then
  422.             awful.placement.no_overlap(c)
  423.             awful.placement.no_offscreen(c)
  424.         end
  425.     end
  426.  
  427.     local titlebars_enabled = false
  428.     if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  429.         -- buttons for the titlebar
  430.         local buttons = awful.util.table.join(
  431.                 awful.button({ }, 1, function()
  432.                     client.focus = c
  433.                     c:raise()
  434.                     awful.mouse.client.move(c)
  435.                 end),
  436.                 awful.button({ }, 3, function()
  437.                     client.focus = c
  438.                     c:raise()
  439.                     awful.mouse.client.resize(c)
  440.                 end)
  441.                 )
  442.  
  443.         -- Widgets that are aligned to the left
  444.         local left_layout = wibox.layout.fixed.horizontal()
  445.         left_layout:add(awful.titlebar.widget.iconwidget(c))
  446.         left_layout:buttons(buttons)
  447.  
  448.         -- Widgets that are aligned to the right
  449.         local right_layout = wibox.layout.fixed.horizontal()
  450.         right_layout:add(awful.titlebar.widget.floatingbutton(c))
  451.         right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  452.         right_layout:add(awful.titlebar.widget.stickybutton(c))
  453.         right_layout:add(awful.titlebar.widget.ontopbutton(c))
  454.         right_layout:add(awful.titlebar.widget.closebutton(c))
  455.  
  456.         -- The title goes in the middle
  457.         local middle_layout = wibox.layout.flex.horizontal()
  458.         local title = awful.titlebar.widget.titlewidget(c)
  459.         title:set_align("center")
  460.         middle_layout:add(title)
  461.         middle_layout:buttons(buttons)
  462.  
  463.         -- Now bring it all together
  464.         local layout = wibox.layout.align.horizontal()
  465.         layout:set_left(left_layout)
  466.         layout:set_right(right_layout)
  467.         layout:set_middle(middle_layout)
  468.  
  469.         awful.titlebar(c):set_widget(layout)
  470.     end
  471. end)
  472.  
  473. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  474. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  475. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment