Advertisement
Guest User

Untitled

a guest
Oct 25th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.41 KB | None | 0 0
  1. -- Standard awesome library
  2. require("awful")
  3. require("awful.autofocus")
  4. require("awful.rules")
  5. -- Theme handling library
  6. require("beautiful")
  7. -- Notification library
  8. require("naughty")
  9.  
  10. -- Load Debian menu entries
  11. require("debian.menu")
  12.  
  13. -- {{{ Error handling
  14. -- Check if awesome encountered an error during startup and fell back to
  15. -- another config (This code will only ever execute for the fallback config)
  16. if awesome.startup_errors then
  17.     naughty.notify({ preset = naughty.config.presets.critical,
  18.                      title = "Oops, there were errors during startup!",
  19.                      text = awesome.startup_errors })
  20. end
  21.  
  22. -- Handle runtime errors after startup
  23. do
  24.     local in_error = false
  25.     awesome.add_signal("debug::error", function (err)
  26.         -- Make sure we don't go into an endless error loop
  27.         if in_error then return end
  28.         in_error = true
  29.  
  30.         naughty.notify({ preset = naughty.config.presets.critical,
  31.                          title = "Oops, an error happened!",
  32.                          text = err })
  33.         in_error = false
  34.     end)
  35. end
  36. -- }}}
  37.  
  38. -- {{{ Variable definitions
  39. -- Themes define colours, icons, and wallpapers
  40. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  41.  
  42. -- This is used later as the default terminal and editor to run.
  43. terminal = "terminator"
  44. editor = os.getenv("EDITOR") or "editor"
  45. editor_cmd = terminal .. " -e " .. editor
  46.  
  47. -- Default modkey.
  48. -- Usually, Mod4 is the key with a logo between Control and Alt.
  49. -- If you do not like this or do not have such a key,
  50. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  51. -- However, you can use another modifier like Mod1, but it may interact with others.
  52. modkey = "Mod4"
  53.  
  54. -- Table of layouts to cover with awful.layout.inc, order matters.
  55. layouts =
  56. {
  57.     awful.layout.suit.floating,
  58.     awful.layout.suit.tile,
  59.     awful.layout.suit.tile.left,
  60.     awful.layout.suit.tile.bottom,
  61.     awful.layout.suit.tile.top,
  62.     awful.layout.suit.fair,
  63.     awful.layout.suit.fair.horizontal,
  64.     awful.layout.suit.spiral,
  65.     awful.layout.suit.spiral.dwindle,
  66.     awful.layout.suit.max,
  67.     awful.layout.suit.max.fullscreen,
  68.     awful.layout.suit.magnifier
  69. }
  70. -- }}}
  71.  
  72. -- {{{ Tags
  73. -- Define a tag table which hold all screen tags.
  74. tags = {}
  75. for s = 1, screen.count() do
  76.     -- Each screen has its own tag table.
  77.     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  78. end
  79. -- }}}
  80.  
  81. -- {{{ Menu
  82. -- Create a laucher widget and a main menu
  83. myawesomemenu = {
  84.    { "manual", terminal .. " -e man awesome" },
  85.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  86.    { "restart", awesome.restart },
  87.    { "quit", awesome.quit }
  88. }
  89.  
  90. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  91.                                     { "Debian", debian.menu.Debian_menu.Debian },
  92.                                     { "open terminal", terminal }
  93.                                   }
  94.                         })
  95.  
  96. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  97.                                      menu = mymainmenu })
  98. -- }}}
  99.  
  100. -- {{{ Wibox
  101. -- Create a textclock widget
  102. mytextclock = awful.widget.textclock({ align = "right" })
  103.  
  104. -- Create a systray
  105. mysystray = widget({ type = "systray" })
  106.  
  107. -- Create a wibox for each screen and add it
  108. mywibox = {}
  109. mypromptbox = {}
  110. mylayoutbox = {}
  111. mytaglist = {}
  112. mytaglist.buttons = awful.util.table.join(
  113.                     awful.button({ }, 1, awful.tag.viewonly),
  114.                     awful.button({ modkey }, 1, awful.client.movetotag),
  115.                     awful.button({ }, 3, awful.tag.viewtoggle),
  116.                     awful.button({ modkey }, 3, awful.client.toggletag),
  117.                     awful.button({ }, 4, awful.tag.viewnext),
  118.                     awful.button({ }, 5, awful.tag.viewprev)
  119.                     )
  120. mytasklist = {}
  121. mytasklist.buttons = awful.util.table.join(
  122.                      awful.button({ }, 1, function (c)
  123.                                               if c == client.focus then
  124.                                                   c.minimized = true
  125.                                               else
  126.                                                   if not c:isvisible() then
  127.                                                       awful.tag.viewonly(c:tags()[1])
  128.                                                   end
  129.                                                   -- This will also un-minimize
  130.                                                   -- the client, if needed
  131.                                                   client.focus = c
  132.                                                   c:raise()
  133.                                               end
  134.                                           end),
  135.                      awful.button({ }, 3, function ()
  136.                                               if instance then
  137.                                                   instance:hide()
  138.                                                   instance = nil
  139.                                               else
  140.                                                   instance = awful.menu.clients({ width=250 })
  141.                                               end
  142.                                           end),
  143.                      awful.button({ }, 4, function ()
  144.                                               awful.client.focus.byidx(1)
  145.                                               if client.focus then client.focus:raise() end
  146.                                           end),
  147.                      awful.button({ }, 5, function ()
  148.                                               awful.client.focus.byidx(-1)
  149.                                               if client.focus then client.focus:raise() end
  150.                                           end))
  151.  
  152. for s = 1, screen.count() do
  153.     -- Create a promptbox for each screen
  154.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  155.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  156.     -- We need one layoutbox per screen.
  157.     mylayoutbox[s] = awful.widget.layoutbox(s)
  158.     mylayoutbox[s]:buttons(awful.util.table.join(
  159.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  160.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  161.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  162.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  163.     -- Create a taglist widget
  164.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  165.  
  166.     -- Create a tasklist widget
  167.     mytasklist[s] = awful.widget.tasklist(function(c)
  168.                                               return awful.widget.tasklist.label.currenttags(c, s)
  169.                                           end, mytasklist.buttons)
  170.  
  171.     -- Create the wibox
  172.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  173.     -- Add widgets to the wibox - order matters
  174.     mywibox[s].widgets = {
  175.         {
  176.             mylauncher,
  177.             mytaglist[s],
  178.             mypromptbox[s],
  179.             layout = awful.widget.layout.horizontal.leftright
  180.         },
  181.         mylayoutbox[s],
  182.         mytextclock,
  183.         s == 1 and mysystray or nil,
  184.         mytasklist[s],
  185.         layout = awful.widget.layout.horizontal.rightleft
  186.     }
  187. end
  188. -- }}}
  189.  
  190. -- {{{ Mouse bindings
  191. root.buttons(awful.util.table.join(
  192.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  193.     awful.button({ }, 4, awful.tag.viewnext),
  194.     awful.button({ }, 5, awful.tag.viewprev)
  195. ))
  196. -- }}}
  197.  
  198. -- {{{ Key bindings
  199. globalkeys = awful.util.table.join(
  200.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  201.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  202.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  203.  
  204.     awful.key({ modkey,           }, "j",
  205.         function ()
  206.             awful.client.focus.byidx( 1)
  207.             if client.focus then client.focus:raise() end
  208.         end),
  209.     awful.key({ modkey,           }, "k",
  210.         function ()
  211.             awful.client.focus.byidx(-1)
  212.             if client.focus then client.focus:raise() end
  213.         end),
  214.     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
  215.  
  216.     -- Layout manipulation
  217.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  218.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  219.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  220.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  221.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  222.     awful.key({ modkey,           }, "Tab",
  223.         function ()
  224.             awful.client.focus.history.previous()
  225.             if client.focus then
  226.                 client.focus:raise()
  227.             end
  228.         end),
  229.  
  230.     -- Standard program
  231.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  232.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  233.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  234.  
  235.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  236.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  237.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  238.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  239.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  240.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  241.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  242.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  243.  
  244.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  245.  
  246.     -- Prompt
  247.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  248.  
  249.     awful.key({ modkey }, "x",
  250.               function ()
  251.                   awful.prompt.run({ prompt = "Run Lua code: " },
  252.                   mypromptbox[mouse.screen].widget,
  253.                   awful.util.eval, nil,
  254.                   awful.util.getdir("cache") .. "/history_eval")
  255.               end)
  256. )
  257.  
  258. clientkeys = awful.util.table.join(
  259.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  260.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  261.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  262.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  263.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  264.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  265.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  266.     awful.key({ modkey,           }, "n",
  267.         function (c)
  268.             -- The client currently has the input focus, so it cannot be
  269.             -- minimized, since minimized clients can't have the focus.
  270.             c.minimized = true
  271.         end),
  272.     awful.key({ modkey,           }, "m",
  273.         function (c)
  274.             c.maximized_horizontal = not c.maximized_horizontal
  275.             c.maximized_vertical   = not c.maximized_vertical
  276.         end)
  277. )
  278.  
  279. -- Compute the maximum number of digit we need, limited to 9
  280. keynumber = 0
  281. for s = 1, screen.count() do
  282.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  283. end
  284.  
  285. -- Bind all key numbers to tags.
  286. -- Be careful: we use keycodes to make it works on any keyboard layout.
  287. -- This should map on the top row of your keyboard, usually 1 to 9.
  288. for i = 1, keynumber do
  289.     globalkeys = awful.util.table.join(globalkeys,
  290.         awful.key({ modkey }, "#" .. i + 9,
  291.                   function ()
  292.                         local screen = mouse.screen
  293.                         if tags[screen][i] then
  294.                             awful.tag.viewonly(tags[screen][i])
  295.                         end
  296.                   end),
  297.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  298.                   function ()
  299.                       local screen = mouse.screen
  300.                       if tags[screen][i] then
  301.                           awful.tag.viewtoggle(tags[screen][i])
  302.                       end
  303.                   end),
  304.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  305.                   function ()
  306.                       if client.focus and tags[client.focus.screen][i] then
  307.                           awful.client.movetotag(tags[client.focus.screen][i])
  308.                       end
  309.                   end),
  310.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  311.                   function ()
  312.                       if client.focus and tags[client.focus.screen][i] then
  313.                           awful.client.toggletag(tags[client.focus.screen][i])
  314.                       end
  315.                   end))
  316. end
  317.  
  318. clientbuttons = awful.util.table.join(
  319.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  320.     awful.button({ modkey }, 1, awful.mouse.client.move),
  321.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  322.  
  323. -- Set keys
  324. root.keys(globalkeys)
  325. -- }}}
  326.  
  327. -- {{{ Rules
  328. awful.rules.rules = {
  329.     -- All clients will match this rule.
  330.     { rule = { },
  331.       properties = { border_width = beautiful.border_width,
  332.                      border_color = beautiful.border_normal,
  333.                      focus = true,
  334.                      keys = clientkeys,
  335.                      buttons = clientbuttons } },
  336.     { rule = { class = "MPlayer" },
  337.       properties = { floating = true } },
  338.     { rule = { class = "pinentry" },
  339.       properties = { floating = true } },
  340.     { rule = { class = "gimp" },
  341.       properties = { floating = true } },
  342.     -- Set Firefox to always map on tags number 2 of screen 1.
  343.     -- { rule = { class = "Firefox" },
  344.     --   properties = { tag = tags[1][2] } },
  345. }
  346. -- }}}
  347.  
  348. -- {{{ Signals
  349. -- Signal function to execute when a new client appears.
  350. client.add_signal("manage", function (c, startup)
  351.     -- Add a titlebar
  352.     -- awful.titlebar.add(c, { modkey = modkey })
  353.  
  354.     -- Enable sloppy focus
  355.     c:add_signal("mouse::enter", function(c)
  356.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  357.             and awful.client.focus.filter(c) then
  358.             client.focus = c
  359.         end
  360.     end)
  361.  
  362.     if not startup then
  363.         -- Set the windows at the slave,
  364.         -- i.e. put it at the end of others instead of setting it master.
  365.         -- awful.client.setslave(c)
  366.  
  367.         -- Put windows in a smart way, only if they does not set an initial position.
  368.         if not c.size_hints.user_position and not c.size_hints.program_position then
  369.             awful.placement.no_overlap(c)
  370.             awful.placement.no_offscreen(c)
  371.         end
  372.     end
  373. end)
  374.  
  375. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  376. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  377. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement