Advertisement
Guest User

Untitled

a guest
Aug 24th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.64 KB | None | 0 0
  1. -- Modules
  2. local gears = require("gears")
  3. local naughty = require("naughty")
  4. local wibox = require("wibox")
  5. local beautiful = require("beautiful")
  6. local lain = require("lain")
  7. local vicious = require("vicious")
  8. local menubar = require("menubar")
  9. local volume = require("volume")
  10. local awful = require("awful")
  11. awful.rules = require("awful.rules")
  12. awful.autofocus = require("awful.autofocus")
  13.  
  14. -- Variables
  15. home_path = os.getenv('HOME') .. '/'
  16. terminal = "x-terminal-emulator"
  17. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  18. editor = "geany"
  19. modkey = "Mod4"
  20. modkey_alt = "Mod1"
  21.  
  22. -- Appearance
  23. beautiful.init(awful.util.getdir("config") .. "/themes/default/theme.lua")
  24. if beautiful.wallpaper then
  25. for s = 1, screen.count() do
  26. gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  27. end
  28. end
  29.  
  30. -- Returns true if all pairs in table1 are present in table2 (for use by "Run of raise")
  31. function match (table1, table2)
  32. for k, v in pairs(table1) do
  33. if table2[k] ~= v and not table2[k]:find(v) then
  34. return false
  35. end
  36. end
  37. return true
  38. end
  39.  
  40. -- "Run or raise" function
  41. function run_or_raise(cmd, properties)
  42. local clients = client.get()
  43. local focused = awful.client.next(0)
  44. local findex = 0
  45. local matched_clients = {}
  46. local n = 0
  47. for i, c in pairs(clients) do
  48. -- make an array of matched clients
  49. if match(properties, c) then
  50. n = n + 1
  51. matched_clients[n] = c
  52. if c == focused then
  53. findex = n
  54. end
  55. end
  56. end
  57. if n > 0 then
  58. local c = matched_clients[1]
  59. -- if the focused window matched switch focus to next in list
  60. if 0 < findex and findex < n then
  61. c = matched_clients[findex+1]
  62. end
  63. local ctags = c:tags()
  64. if #ctags == 0 then
  65. -- ctags is empty, show client on current tag
  66. local curtag = awful.tag.selected()
  67. awful.client.movetotag(curtag, c)
  68. else
  69. -- Otherwise, pop to first tag client is visible on
  70. awful.tag.viewonly(ctags[1])
  71. end
  72. -- And then focus the client
  73. client.focus = c
  74. c:raise()
  75. return
  76. end
  77. awful.util.spawn(cmd)
  78. end
  79.  
  80. -- "Run once" function
  81. function run_once(prg,arg_string,pname,screen) -- Run PRG once with command-line ARGuments, expecting PNAME as process name on SCREEN
  82. if not prg then
  83. do return nil end
  84. end
  85.  
  86. if not pname then
  87. pname = prg
  88. end
  89.  
  90. if not arg_string then
  91. awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
  92. else
  93. awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
  94. end
  95. end
  96.  
  97. -- Handle runtime errors after startup
  98. do
  99. local in_error = false
  100. awesome.connect_signal("debug::error", function (err)
  101. -- Make sure we don't go into an endless error loop
  102. if in_error then return end
  103. in_error = true
  104.  
  105. naughty.notify({ preset = naughty.config.presets.critical,
  106. title = "Oops, an error happened!",
  107. text = err })
  108. in_error = false
  109. end)
  110. end
  111.  
  112. -- Autostart
  113. awful.util.spawn_with_shell('setxkbmap -layout "us,ru" setxkbmap -option "grp:caps_toggle,grp_led:scroll,compose:ralt"')
  114. run_once("kbdd")
  115. run_once("xsettingsd")
  116. run_once("mpd")
  117. run_once("nm-applet")
  118. run_once("clipit")
  119. run_once("transmission-gtk","-m")
  120. run_once("/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1")
  121.  
  122. -- Key bindings
  123. -- Global
  124. globalkeys = awful.util.table.join(
  125. -- Manipulating layouts
  126. awful.key({ modkey, }, "Left", awful.tag.viewprev),
  127. awful.key({ modkey, }, "Right", awful.tag.viewnext),
  128. awful.key({ modkey, }, "j",
  129. function ()
  130. awful.client.focus.byidx(1)
  131. if client.focus then client.focus:raise() end
  132. end),
  133. awful.key({ modkey, }, "k",
  134. function ()
  135. awful.client.focus.byidx(-1)
  136. if client.focus then client.focus:raise() end
  137. end),
  138. awful.key({ modkey_alt, }, "Tab",
  139. function ()
  140. awful.client.focus.byidx(1)
  141. if client.focus then client.focus:raise() end
  142. end),
  143. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx(1) end),
  144. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx(-1) end),
  145. awful.key({ modkey_alt, "Shift" }, "Tab", function () awful.client.swap.byidx(1) end),
  146. awful.key({ modkey, }, "`", function () awful.client.urgent.jumpto() end),
  147. awful.key({ modkey, }, "Tab",
  148. function ()
  149. awful.client.focus.history.previous()
  150. if client.focus then
  151. client.focus:raise()
  152. end
  153. end),
  154.  
  155. -- Standard program
  156. awful.key({ modkey, "Shift" }, "r", awesome.restart),
  157. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  158. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  159. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  160. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  161. awful.key({ modkey, }, "space", function () awful.layout.inc( 1) end),
  162. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(-1) end),
  163. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  164.  
  165. -- Launchers
  166. awful.key({ modkey, }, "p", function() menubar.show() end),
  167. awful.key({ modkey, }, "w", function () run_or_raise("x-www-browser", { class = "Iceweasel" }) end),
  168. awful.key({ modkey, }, "e", function () run_or_raise("icedove", { class = "Icedove" }) end),
  169. awful.key({ modkey, }, "o", function () awful.util.spawn("dm-tool lock") end),
  170. awful.key({ modkey, }, "Return", function () awful.util.spawn("x-terminal-emulator") end),
  171. awful.key({ modkey, }, "F1", function () awful.util.spawn("x-terminal-emulator") end),
  172. awful.key({ modkey, }, "f", function () awful.util.spawn("thunar") end),
  173. awful.key({ modkey, }, "q", function () awful.util.spawn("tkscreen") end),
  174. awful.key({ modkey, }, "a", function () run_or_raise("x-terminal-emulator -T ncmpcpp -e ncmpcpp", { name = "ncmpcpp" }) end),
  175. awful.key({ modkey, }, "F2", function () run_or_raise("x-terminal-emulator -T htop -e sudo htop", { name = "htop" }) end),
  176.  
  177. -- Multimedia
  178. awful.key({}, "XF86Calculator", function () awful.util.spawn ("qalculate") end),
  179. awful.key({}, "XF86AudioPlay", function () awful.util.spawn("mpc toggle") end),
  180. awful.key({}, "XF86AudioNext", function () awful.util.spawn("mpc next") end),
  181. awful.key({}, "XF86AudioPrev", function () awful.util.spawn("mpc prev") end),
  182. awful.key({}, "XF86AudioStop", function () awful.util.spawn("mpc stop") end),
  183. awful.key({}, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer set Master 4%+ on") end),
  184. awful.key({}, "XF86AudioLowerVolume", function () awful.util.spawn("amixer set Master 4%- on") end),
  185. awful.key({}, "XF86AudioMute", function () awful.util.spawn("amixer set Master toggle") end)
  186. )
  187.  
  188. clientkeys = awful.util.table.join(
  189. awful.key({ modkey_alt, }, "F1", function (c) c.fullscreen = not c.fullscreen end),
  190. awful.key({ modkey_alt, }, "F2",
  191. function (c)
  192. c:raise()
  193. c.maximized_horizontal = not c.maximized_horizontal
  194. c.maximized_vertical = not c.maximized_vertical
  195. end),
  196. awful.key({ modkey_alt, }, "F3", awful.client.floating.toggle),
  197. awful.key({ modkey_alt, }, "F4", function (c) c:kill() end),
  198. awful.key({ modkey_alt, }, "F5", function (c) c:swap(awful.client.getmaster()) end),
  199. awful.key({ modkey_alt, }, "F6", function (c) c.ontop = not c.ontop end)
  200. )
  201.  
  202. -- Mouse bindings
  203. root.buttons(awful.util.table.join(
  204. awful.button({ }, 3, function () mymainmenu:toggle() end),
  205. awful.button({ }, 4, awful.tag.viewnext),
  206. awful.button({ }, 5, awful.tag.viewprev)
  207. ))
  208. clientbuttons = awful.util.table.join(
  209. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  210. awful.button({ modkey }, 1, awful.mouse.client.move),
  211. awful.button({ modkey }, 3, awful.mouse.client.resize))
  212.  
  213. -- Table of layouts
  214. awful.layout.layouts = {
  215. awful.layout.suit.floating,
  216. lain.layout.centerfair, -- будет использоваться для тегов, где обычно то, чему не нужен фуллскрин
  217. awful.layout.suit.fair, -- будет использоваться для всех остальных тегов
  218. awful.layout.suit.tile, -- будет использоваться для тегов, где нужен фуллскрин и есть одно главное окно
  219. -- awful.layout.suit.tile.left
  220. -- awful.layout.suit.tile.bottom,
  221. -- awful.layout.suit.tile.top,
  222. -- awful.layout.suit.fair,
  223. -- awful.layout.suit.fair.horizontal,
  224. -- awful.layout.suit.spiral
  225. -- awful.layout.suit.spiral.dwindle,
  226. -- awful.layout.suit.max,
  227. -- awful.layout.suit.max.fullscreen,
  228. -- awful.layout.suit.magnifier
  229. }
  230.  
  231. -- Tags
  232. tags = {
  233. names = { "www", "music", "mail", 4, 5, 6, 7, 8, 9 },
  234. layout = { awful.layout.layouts[4], awful.layout.layouts[4], awful.layout.layouts[4], awful.layout.layouts[2], awful.layout.layouts[2],
  235. awful.layout.layouts[2], awful.layout.layouts[3], awful.layout.layouts[3], awful.layout.layouts[3]
  236. }}
  237. for s = 1, screen.count() do
  238. tags[s] = awful.tag(tags.names, s, tags.layout)
  239. end
  240.  
  241. -- Rules
  242. awful.rules.rules = {
  243. { rule = { },
  244. properties = { border_width = beautiful.border_width,
  245. border_color = beautiful.border_normal,
  246. focus = awful.client.focus.filter,
  247. keys = clientkeys,
  248. size_hints_honor = false,
  249. buttons = clientbuttons } },
  250. { rule = { instance = "pidgin" },
  251. properties = { floating = true }
  252. },
  253. { rule = { instance = "Pidgin" },
  254. properties = { floating = true }
  255. },
  256. { rule = { class = "qemu-system-x86_64" },
  257. properties = { floating = true }
  258. },
  259. { rule = { name = "File Operation Progress" },
  260. properties = { floating = true }
  261. },
  262. { rule = { instance = "qalculate" },
  263. properties = { floating = true }
  264. }
  265. }
  266.  
  267. -- Launcher widget and main menu
  268. myawesomemenu = {
  269. { "edit config", editor .. " " .. awesome.conffile },
  270. { "restart", awesome.restart },
  271. }
  272.  
  273. mysessionmenu = {
  274. { "lock session", "dm-tool lock" },
  275. { "quit session", awesome.quit },
  276. { "switch user", "dm-tool switch-to-greeter" },
  277. { "suspend", "systemctl suspend" },
  278. { "reboot", "systemctl reboot" },
  279. { "shutdown", "systemctl poweroff" }
  280.  
  281. }
  282.  
  283. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, { "session", mysessionmenu } }
  284. })
  285.  
  286. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  287. menu = mymainmenu })
  288.  
  289. -- Wibox
  290.  
  291. -- Create a textclock widget
  292. mytextclock = awful.widget.textclock()
  293.  
  294. -- Create a wibox for each screen and add it
  295. mywibox = {}
  296. mypromptbox = {}
  297. mylayoutbox = {}
  298. mytaglist = {}
  299. mytaglist.buttons = awful.util.table.join(
  300. awful.button({ }, 1, awful.tag.viewonly), -- Go to tag
  301. awful.button({ modkey }, 1, awful.client.movetotag), -- Move focused window to tag
  302. awful.button({ }, 3, awful.tag.viewtoggle), -- Append tag's windows to current tag
  303. awful.button({ modkey }, 3, awful.client.toggletag), -- Display focused window on tag
  304. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end), -- Scroll through tags
  305. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end) -- Scroll through tags
  306. )
  307. mytasklist = {}
  308. mytasklist.buttons = awful.util.table.join(
  309. awful.button({ }, 1, function (c)
  310. if c == client.focus then -- If in focus, then minimize
  311. c.minimized = true
  312. else
  313. c.minimized = false -- Else, go to window's tag, unminize and give focus
  314. if not c:isvisible() then
  315. awful.tag.viewonly(c:tags()[1])
  316. end
  317. client.focus = c
  318. c:raise()
  319. end
  320. end),
  321. awful.button({ }, 3, function ()
  322. if instance then
  323. instance:hide()
  324. instance = nil
  325. else
  326. instance = awful.menu.clients({
  327. theme = { width = 250 }
  328. })
  329. end
  330. end),
  331. awful.button({ }, 4, function () -- Scroll focus through windows
  332. awful.client.focus.byidx(1)
  333. if client.focus then client.focus:raise() end
  334. end),
  335. awful.button({ }, 5, function () -- Scroll focus through windows
  336. awful.client.focus.byidx(-1)
  337. if client.focus then client.focus:raise() end
  338. end))
  339.  
  340. for s = 1, screen.count() do
  341. -- Create a promptbox for each screen
  342. mypromptbox[s] = awful.widget.prompt()
  343. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  344. -- We need one layoutbox per screen.
  345. mylayoutbox[s] = awful.widget.layoutbox(s)
  346. mylayoutbox[s]:buttons(awful.util.table.join(
  347. awful.button({ }, 1, function () awful.layout.inc( 1) end), -- Scroll through layouts
  348. awful.button({ }, 3, function () awful.layout.inc(-1) end),
  349. awful.button({ }, 4, function () awful.layout.inc( 1) end),
  350. awful.button({ }, 5, function () awful.layout.inc(-1) end)))
  351. -- Create a taglist widget
  352. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  353.  
  354. -- Create a tasklist widget
  355. mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  356.  
  357. -- Create the wibox
  358. mywibox[s] = awful.wibox({ position = "top", screen = s })
  359.  
  360. -- Widgets that are aligned to the left
  361. local left_layout = wibox.layout.fixed.horizontal()
  362. left_layout:add(mylauncher)
  363. left_layout:add(mytaglist[s])
  364. left_layout:add(mypromptbox[s])
  365.  
  366. -- Widgets that are aligned to the right
  367. local right_layout = wibox.layout.fixed.horizontal()
  368. if s == 1 then right_layout:add(wibox.widget.systray()) end
  369. right_layout:add(volume_widget)
  370. right_layout:add(mytextclock)
  371. right_layout:add(mylayoutbox[s])
  372. -- Now bring it all together (with the tasklist in the middle)
  373. local layout = wibox.layout.align.horizontal()
  374. layout:set_left(left_layout)
  375. layout:set_middle(mytasklist[s])
  376. layout:set_right(right_layout)
  377.  
  378. mywibox[s]:set_widget(layout)
  379. end
  380.  
  381. -- Key bindings for tags manipulating
  382. for i = 1, 9 do
  383. globalkeys = awful.util.table.join(globalkeys,
  384. awful.key({ modkey }, "#" .. i + 9,
  385. function ()
  386. local screen = mouse.screen
  387. local tag = awful.tag.gettags(screen)[i]
  388. if tag then
  389. awful.tag.viewonly(tag)
  390. end
  391. end),
  392. awful.key({ modkey, "Control" }, "#" .. i + 9, -- ИЗМЕНИТЬ
  393. function ()
  394. local screen = mouse.screen
  395. local tag = awful.tag.gettags(screen)[i]
  396. if tag then
  397. awful.tag.viewtoggle(tag)
  398. end
  399. end),
  400. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  401. function ()
  402. if client.focus then
  403. local tag = awful.tag.gettags(client.focus.screen)[i]
  404. if tag then
  405. awful.client.movetotag(tag)
  406. end
  407. end
  408. end),
  409. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, -- ИЗМЕНИТЬ
  410. function ()
  411. if client.focus then
  412. local tag = awful.tag.gettags(client.focus.screen)[i]
  413. if tag then
  414. awful.client.toggletag(tag)
  415. end
  416. end
  417. end))
  418. end
  419.  
  420. -- Set keys
  421. root.keys(globalkeys)
  422.  
  423. -- Signals
  424. -- Signal function to execute when a new client appears.
  425. client.connect_signal("manage", function (c)
  426. if not awesome.startup then
  427. -- Set the windows at the slave,
  428. -- i.e. put it at the end of others instead of setting it master.
  429. awful.client.setslave(c)
  430.  
  431. -- Put windows in a smart way, only if they does not set an initial position.
  432. if not c.size_hints.user_position and not c.size_hints.program_position then
  433. awful.placement.no_overlap(c)
  434. awful.placement.no_offscreen(c)
  435. end
  436. elseif not c.size_hints.user_position and not c.size_hints.program_position then
  437. -- Prevent clients from being unreachable after screen count change
  438. awful.placement.no_offscreen(c)
  439. end
  440.  
  441. local titlebars_enabled = false
  442. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  443. -- buttons for the titlebar
  444. local buttons = awful.util.table.join(
  445. awful.button({ }, 1, function()
  446. client.focus = c
  447. c:raise()
  448. awful.mouse.client.move(c)
  449. end),
  450. awful.button({ }, 3, function()
  451. client.focus = c
  452. c:raise()
  453. awful.mouse.client.resize(c)
  454. end)
  455. )
  456.  
  457. -- Widgets that are aligned to the left
  458. local left_layout = wibox.layout.fixed.horizontal()
  459. left_layout:add(awful.titlebar.widget.iconwidget(c))
  460. left_layout:buttons(buttons)
  461.  
  462. -- Widgets that are aligned to the right
  463. local right_layout = wibox.layout.fixed.horizontal()
  464. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  465. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  466. right_layout:add(awful.titlebar.widget.stickybutton(c))
  467. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  468. right_layout:add(awful.titlebar.widget.closebutton(c))
  469.  
  470. -- The title goes in the middle
  471. local middle_layout = wibox.layout.flex.horizontal()
  472. local title = awful.titlebar.widget.titlewidget(c)
  473. title:set_align("center")
  474. middle_layout:add(title)
  475. middle_layout:buttons(buttons)
  476.  
  477. -- Now bring it all together
  478. local layout = wibox.layout.align.horizontal()
  479. layout:set_left(left_layout)
  480. layout:set_right(right_layout)
  481. layout:set_middle(middle_layout)
  482.  
  483. awful.titlebar(c):set_widget(layout)
  484. end
  485. end)
  486.  
  487. -- Enable sloppy focus
  488. client.connect_signal("mouse::enter", function(c)
  489. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  490. and awful.client.focus.filter(c) then
  491. client.focus = c
  492. end
  493. end)
  494.  
  495. client.connect_signal("focus", function(c) -- Jump to focused client
  496. c.border_color = beautiful.border_focus
  497. awful.client.jumpto(c)
  498. end)
  499. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement