Advertisement
Guest User

rc.lua

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