rcsample.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. -- {{{ 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. -- Handle runtime errors after startup
  22. do
  23. local in_error = false
  24. awesome.connect_signal("debug::error", function (err)
  25. -- Make sure we don't go into an endless error loop
  26. if in_error then return end
  27. in_error = true
  28. naughty.notify({ preset = naughty.config.presets.critical,
  29. title = "Oops, an error happened!",
  30. text = err })
  31. in_error = false
  32. end)
  33. end
  34. -- }}}
  35. -- {{{ Variable definitions
  36. -- Themes define colours, icons, and wallpapers
  37. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  38. -- This is used later as the default terminal and editor to run.
  39. terminal = "xterm"
  40. editor = os.getenv("EDITOR") or "nano"
  41. editor_cmd = terminal .. " -e " .. editor
  42. -- Default modkey.
  43. -- Usually, Mod4 is the key with a logo between Control and Alt.
  44. -- If you do not like this or do not have such a key,
  45. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  46. -- However, you can use another modifier like Mod1, but it may interact with others.
  47. modkey = "Mod4"
  48. -- Table of layouts to cover with awful.layout.inc, order matters.
  49. local layouts =
  50. {
  51. awful.layout.suit.floating,
  52. awful.layout.suit.tile,
  53. awful.layout.suit.tile.left,
  54. awful.layout.suit.tile.bottom,
  55. awful.layout.suit.tile.top,
  56. awful.layout.suit.fair,
  57. awful.layout.suit.fair.horizontal,
  58. awful.layout.suit.spiral,
  59. awful.layout.suit.spiral.dwindle,
  60. awful.layout.suit.max,
  61. awful.layout.suit.max.fullscreen,
  62. awful.layout.suit.magnifier
  63. }
  64. -- }}}
  65. -- {{{ Wallpaper
  66. if beautiful.wallpaper then
  67. for s = 1, screen.count() do
  68. gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  69. end
  70. end
  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. -- {{{ Menu
  81. -- Create a laucher widget and a main menu
  82. myawesomemenu = {
  83. { "manual", terminal .. " -e man awesome" },
  84. { "edit config", editor_cmd .. " " .. awesome.conffile },
  85. { "restart", awesome.restart },
  86. { "quit", awesome.quit }
  87. }
  88. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  89. { "open terminal", terminal }
  90. }
  91. })
  92. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  93. menu = mymainmenu })
  94. -- Menubar configuration
  95. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  96. -- }}}
  97. -- {{{ Wibox
  98. -- Create a textclock widget
  99. mytextclock = awful.widget.textclock()
  100. -- BEGIN OF AWESOMPD WIDGET DECLARATION
  101. local awesompd = require('awesompd/awesompd')
  102. musicwidget = awesompd:create() -- Create awesompd widget
  103. musicwidget.font = "Liberation Mono" -- Set widget font
  104. -- musicwidget.font_color = "#FFFFFF" --Set widget font color
  105. -- musicwidget.background = "#000000" --Set widget background color
  106. musicwidget.scrolling = true -- If true, the text in the widget will be scrolled
  107. musicwidget.output_size = 30 -- Set the size of widget in symbols
  108. musicwidget.update_interval = 10 -- Set the update interval in seconds
  109. -- Set the folder where icons are located (change username to your login name)
  110. musicwidget.path_to_icons = "/home/unlogic/.config/awesome/icons"
  111. -- Set the path to the icon to be displayed on the widget itself
  112. -- musicwidget.widget_icon = "/path/to/icon"
  113. -- Set the default music format for Jamendo streams. You can change
  114. -- this option on the fly in awesompd itself.
  115. -- possible formats: awesompd.FORMAT_MP3, awesompd.FORMAT_OGG
  116. musicwidget.jamendo_format = awesompd.FORMAT_MP3
  117. -- Specify the browser you use so awesompd can open links from
  118. -- Jamendo in it.
  119. musicwidget.browser = "firefox"
  120. -- If true, song notifications for Jamendo tracks and local tracks
  121. -- will also contain album cover image.
  122. musicwidget.show_album_cover = true
  123. -- Specify how big in pixels should an album cover be. Maximum value
  124. -- is 100.
  125. musicwidget.album_cover_size = 50
  126. -- This option is necessary if you want the album covers to be shown
  127. -- for your local tracks.
  128. musicwidget.mpd_config = "/home/unlogic/.mpdconf"
  129. -- Specify decorators on the left and the right side of the
  130. -- widget. Or just leave empty strings if you decorate the widget
  131. -- from outside.
  132. musicwidget.ldecorator = " "
  133. musicwidget.rdecorator = " "
  134. -- Set all the servers to work with (here can be any servers you use)
  135. musicwidget.servers = {
  136. { server = "localhost",
  137. port = 6600 },
  138. { server = "192.168.0.72",
  139. port = 6600 }
  140. }
  141. -- Set the buttons of the widget. Keyboard keys are working in the
  142. -- entire Awesome environment. Also look at the line 352.
  143. musicwidget:register_buttons(
  144. { { "", awesompd.MOUSE_LEFT, musicwidget:command_playpause() },
  145. { "Control", awesompd.MOUSE_SCROLL_UP, musicwidget:command_prev_track() },
  146. { "Control", awesompd.MOUSE_SCROLL_DOWN, musicwidget:command_next_track() },
  147. { "", awesompd.MOUSE_SCROLL_UP, musicwidget:command_volume_up() },
  148. { "", awesompd.MOUSE_SCROLL_DOWN, musicwidget:command_volume_down() },
  149. { "", awesompd.MOUSE_RIGHT, musicwidget:command_show_menu() },
  150. { "", "XF86AudioLowerVolume", musicwidget:command_volume_down() },
  151. { "", "XF86AudioRaiseVolume", musicwidget:command_volume_up() },
  152. { modkey, "Pause", musicwidget:command_playpause() } })
  153. musicwidget:run() -- After all configuration is done, run the widget
  154. -- END OF AWESOMPD WIDGET DECLARATION
  155. -- Don't forget to add the widget to the wibox. It is done on the line 244.
  156. -- Create a wibox for each screen and add it
  157. mywibox = {}
  158. mypromptbox = {}
  159. mylayoutbox = {}
  160. mytaglist = {}
  161. mytaglist.buttons = awful.util.table.join(
  162. awful.button({ }, 1, awful.tag.viewonly),
  163. awful.button({ modkey }, 1, awful.client.movetotag),
  164. awful.button({ }, 3, awful.tag.viewtoggle),
  165. awful.button({ modkey }, 3, awful.client.toggletag),
  166. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  167. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  168. )
  169. mytasklist = {}
  170. mytasklist.buttons = awful.util.table.join(
  171. awful.button({ }, 1, function (c)
  172. if c == client.focus then
  173. c.minimized = true
  174. else
  175. -- Without this, the following
  176. -- :isvisible() makes no sense
  177. c.minimized = false
  178. if not c:isvisible() then
  179. awful.tag.viewonly(c:tags()[1])
  180. end
  181. -- This will also un-minimize
  182. -- the client, if needed
  183. client.focus = c
  184. c:raise()
  185. end
  186. end),
  187. awful.button({ }, 3, function ()
  188. if instance then
  189. instance:hide()
  190. instance = nil
  191. else
  192. instance = awful.menu.clients({ width=250 })
  193. end
  194. end),
  195. awful.button({ }, 4, function ()
  196. awful.client.focus.byidx(1)
  197. if client.focus then client.focus:raise() end
  198. end),
  199. awful.button({ }, 5, function ()
  200. awful.client.focus.byidx(-1)
  201. if client.focus then client.focus:raise() end
  202. end))
  203. for s = 1, screen.count() do
  204. -- Create a promptbox for each screen
  205. mypromptbox[s] = awful.widget.prompt()
  206. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  207. -- We need one layoutbox per screen.
  208. mylayoutbox[s] = awful.widget.layoutbox(s)
  209. mylayoutbox[s]:buttons(awful.util.table.join(
  210. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  211. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  212. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  213. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  214. -- Create a taglist widget
  215. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  216. -- Create a tasklist widget
  217. mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  218. -- Create the wibox
  219. mywibox[s] = awful.wibox({ position = "top", screen = s })
  220. -- Widgets that are aligned to the left
  221. local left_layout = wibox.layout.fixed.horizontal()
  222. left_layout:add(mylauncher)
  223. left_layout:add(mytaglist[s])
  224. left_layout:add(mypromptbox[s])
  225. -- Widgets that are aligned to the right
  226. local right_layout = wibox.layout.fixed.horizontal()
  227. if s == 1 then right_layout:add(wibox.widget.systray()) end
  228. right_layout:add(musicwidget.widget) -- Widget is added here.
  229. right_layout:add(mytextclock)
  230. right_layout:add(mylayoutbox[s])
  231. -- Now bring it all together (with the tasklist in the middle)
  232. local layout = wibox.layout.align.horizontal()
  233. layout:set_left(left_layout)
  234. layout:set_middle(mytasklist[s])
  235. layout:set_right(right_layout)
  236. mywibox[s]:set_widget(layout)
  237. end
  238. -- }}}
  239. -- {{{ Mouse bindings
  240. root.buttons(awful.util.table.join(
  241. awful.button({ }, 3, function () mymainmenu:toggle() end),
  242. awful.button({ }, 4, awful.tag.viewnext),
  243. awful.button({ }, 5, awful.tag.viewprev)
  244. ))
  245. -- }}}
  246. -- {{{ Key bindings
  247. globalkeys = awful.util.table.join(
  248. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  249. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  250. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  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. -- Layout manipulation
  263. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  264. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  265. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  266. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  267. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  268. awful.key({ modkey, }, "Tab",
  269. function ()
  270. awful.client.focus.history.previous()
  271. if client.focus then
  272. client.focus:raise()
  273. end
  274. end),
  275. -- Standard program
  276. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  277. awful.key({ modkey, "Control" }, "r", awesome.restart),
  278. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  279. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  280. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  281. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  282. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  283. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  284. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  285. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  286. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  287. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  288. -- Prompt
  289. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  290. awful.key({ modkey }, "x",
  291. function ()
  292. awful.prompt.run({ prompt = "Run Lua code: " },
  293. mypromptbox[mouse.screen].widget,
  294. awful.util.eval, nil,
  295. awful.util.getdir("cache") .. "/history_eval")
  296. end),
  297. -- Menubar
  298. awful.key({ modkey }, "p", function() menubar.show() end)
  299. )
  300. clientkeys = awful.util.table.join(
  301. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  302. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  303. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  304. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  305. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  306. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  307. awful.key({ modkey, }, "n",
  308. function (c)
  309. -- The client currently has the input focus, so it cannot be
  310. -- minimized, since minimized clients can't have the focus.
  311. c.minimized = true
  312. end),
  313. awful.key({ modkey, }, "m",
  314. function (c)
  315. c.maximized_horizontal = not c.maximized_horizontal
  316. c.maximized_vertical = not c.maximized_vertical
  317. end)
  318. )
  319. -- Bind all key numbers to tags.
  320. -- Be careful: we use keycodes to make it works on any keyboard layout.
  321. -- This should map on the top row of your keyboard, usually 1 to 9.
  322. for i = 1, 9 do
  323. globalkeys = awful.util.table.join(globalkeys,
  324. awful.key({ modkey }, "#" .. i + 9,
  325. function ()
  326. local screen = mouse.screen
  327. local tag = awful.tag.gettags(screen)[i]
  328. if tag then
  329. awful.tag.viewonly(tag)
  330. end
  331. end),
  332. awful.key({ modkey, "Control" }, "#" .. i + 9,
  333. function ()
  334. local screen = mouse.screen
  335. local tag = awful.tag.gettags(screen)[i]
  336. if tag then
  337. awful.tag.viewtoggle(tag)
  338. end
  339. end),
  340. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  341. function ()
  342. local tag = awful.tag.gettags(client.focus.screen)[i]
  343. if client.focus and tag then
  344. awful.client.movetotag(tag)
  345. end
  346. end),
  347. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  348. function ()
  349. local tag = awful.tag.gettags(client.focus.screen)[i]
  350. if client.focus and tag then
  351. awful.client.toggletag(tag)
  352. end
  353. end))
  354. end
  355. clientbuttons = awful.util.table.join(
  356. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  357. awful.button({ modkey }, 1, awful.mouse.client.move),
  358. awful.button({ modkey }, 3, awful.mouse.client.resize))
  359. -- Set keys
  360. -- Add this line before root.keys(globalkeys).
  361. musicwidget:append_global_keys()
  362. root.keys(globalkeys)
  363. -- }}}
  364. -- {{{ Rules
  365. awful.rules.rules = {
  366. -- All clients will match this rule.
  367. { rule = { },
  368. properties = { border_width = beautiful.border_width,
  369. border_color = beautiful.border_normal,
  370. focus = awful.client.focus.filter,
  371. keys = clientkeys,
  372. buttons = clientbuttons } },
  373. { rule = { class = "MPlayer" },
  374. properties = { floating = true } },
  375. { rule = { class = "pinentry" },
  376. properties = { floating = true } },
  377. { rule = { class = "gimp" },
  378. properties = { floating = true } },
  379. -- Set Firefox to always map on tags number 2 of screen 1.
  380. -- { rule = { class = "Firefox" },
  381. -- properties = { tag = tags[1][2] } },
  382. }
  383. -- }}}
  384. -- {{{ Signals
  385. -- Signal function to execute when a new client appears.
  386. client.connect_signal("manage", function (c, startup)
  387. -- Enable sloppy focus
  388. c:connect_signal("mouse::enter", function(c)
  389. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  390. and awful.client.focus.filter(c) then
  391. client.focus = c
  392. end
  393. end)
  394. if not startup then
  395. -- Set the windows at the slave,
  396. -- i.e. put it at the end of others instead of setting it master.
  397. -- awful.client.setslave(c)
  398. -- Put windows in a smart way, only if they does not set an initial position.
  399. if not c.size_hints.user_position and not c.size_hints.program_position then
  400. awful.placement.no_overlap(c)
  401. awful.placement.no_offscreen(c)
  402. end
  403. end
  404. local titlebars_enabled = false
  405. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  406. -- buttons for the titlebar
  407. local buttons = awful.util.table.join(
  408. awful.button({ }, 1, function()
  409. client.focus = c
  410. c:raise()
  411. awful.mouse.client.move(c)
  412. end),
  413. awful.button({ }, 3, function()
  414. client.focus = c
  415. c:raise()
  416. awful.mouse.client.resize(c)
  417. end)
  418. )
  419. -- Widgets that are aligned to the left
  420. local left_layout = wibox.layout.fixed.horizontal()
  421. left_layout:add(awful.titlebar.widget.iconwidget(c))
  422. left_layout:buttons(buttons)
  423. -- Widgets that are aligned to the right
  424. local right_layout = wibox.layout.fixed.horizontal()
  425. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  426. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  427. right_layout:add(awful.titlebar.widget.stickybutton(c))
  428. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  429. right_layout:add(awful.titlebar.widget.closebutton(c))
  430. -- The title goes in the middle
  431. local middle_layout = wibox.layout.flex.horizontal()
  432. local title = awful.titlebar.widget.titlewidget(c)
  433. title:set_align("center")
  434. middle_layout:add(title)
  435. middle_layout:buttons(buttons)
  436. -- Now bring it all together
  437. local layout = wibox.layout.align.horizontal()
  438. layout:set_left(left_layout)
  439. layout:set_right(right_layout)
  440. layout:set_middle(middle_layout)
  441. awful.titlebar(c):set_widget(layout)
  442. end
  443. end)
  444. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  445. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  446. -- }}}