Guest User

Untitled

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