rc.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. -- Standard awesome library
  2. local gears = require("gears")
  3. local awful = require("awful")
  4. require("awful.autofocus")
  5. require("awful.spawn")
  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. local hotkeys_popup = require("awful.hotkeys_popup").widget
  14. -- Enable hotkeys help widget for VIM and other apps
  15. -- when client with a matching name is opened:
  16. require("awful.hotkeys_popup.keys")
  17. -- {{{ Error handling
  18. -- Check if awesome encountered an error during startup and fell back to
  19. -- another config (This code will only ever execute for the fallback config)
  20. if awesome.startup_errors then
  21. naughty.notify({ preset = naughty.config.presets.critical,
  22. title = "Oops, there were errors during startup!",
  23. text = awesome.startup_errors })
  24. end
  25. -- Handle runtime errors after startup
  26. do
  27. local in_error = false
  28. awesome.connect_signal("debug::error", function (err)
  29. -- Make sure we don't go into an endless error loop
  30. if in_error then return end
  31. in_error = true
  32. naughty.notify({ preset = naughty.config.presets.critical,
  33. title = "Oops, an error happened!",
  34. text = tostring(err) })
  35. in_error = false
  36. end)
  37. end
  38. -- }}}
  39. beautiful.init("/home/alex/.config/awesome/theme/theme.lua")
  40. terminal = "kitty"
  41. editor = os.getenv("EDITOR") or "nano"
  42. editor_cmd = terminal .. " -e " .. editor
  43. modkey = "Mod4"
  44. altkey = "Mod1"
  45. awful.layout.layouts = {
  46. -- awful.layout.suit.floating,
  47. awful.layout.suit.tile,
  48. -- awful.layout.suit.tile.left,
  49. -- awful.layout.suit.tile.bottom,
  50. -- awful.layout.suit.tile.top,
  51. -- awful.layout.suit.fair,
  52. -- awful.layout.suit.fair.horizontal,
  53. -- awful.layout.suit.spiral,
  54. -- awful.layout.suit.spiral.dwindle,
  55. -- awful.layout.suit.max,
  56. -- awful.layout.suit.max.fullscreen,
  57. -- awful.layout.suit.magnifier,
  58. -- awful.layout.suit.corner.nw,
  59. -- awful.layout.suit.corner.ne,
  60. -- awful.layout.suit.corner.sw,
  61. -- awful.layout.suit.corner.se,
  62. }
  63. local function set_wallpaper(s)
  64. if beautiful.wallpaper then
  65. local wallpaper = beautiful.wallpaper
  66. -- if wallpaper is a function, call it with the screen
  67. if type(wallpaper) == "function" then
  68. wallpaper = wallpaper(s)
  69. end
  70. gears.wallpaper.maximized(wallpaper, s, true)
  71. end
  72. end
  73. -- reset wallpaper when screen geometry changes
  74. screen.connect_signal("property::geometry", set_wallpaper)
  75. awful.screen.connect_for_each_screen(function(s)
  76. set_wallpaper(s)
  77. -- each screen has its own set of desktops
  78. awful.tag({
  79. "1",
  80. "2",
  81. "3",
  82. "4",
  83. "5",
  84. "6",
  85. "7",
  86. "8",
  87. "9",
  88. }, s, awful.layout.layouts[1])
  89. end)
  90. function do_border_radius(c)
  91. if beautiful.border_radius and not c.fullscreen then
  92. -- rounded corners
  93. c.shape = function (cr, w, h)
  94. gears.shape.rounded_rect(cr, w, h, beautiful.border_radius)
  95. end
  96. else
  97. c.shape = nil
  98. end
  99. end
  100. -- keybindings
  101. globalkeys = gears.table.join(
  102. --[[
  103. awful.key({ altkey }, "Tab", function ()
  104. awful.client.focus.history.previous()
  105. if client.focus then
  106. client.focus:raise()
  107. end
  108. end),
  109. --]]
  110. awful.key({ modkey, "Shift" }, "Return", function () awful.spawn(terminal) end),
  111. awful.key({ altkey }, " ", function () awful.spawn("rofi -show run") end),
  112. awful.key({}, "Print", function () awful.spawn("screenshot-area") end),
  113. awful.key({ "Shift" }, "Print", function () awful.spawn("color-picker") end),
  114. awful.key({ modkey, "Control" }, "r", awesome.restart),
  115. awful.key({ modkey, "Control" }, "q", awesome.quit)
  116. )
  117. -- window-specific keybindings
  118. clientkeys = gears.table.join(
  119. awful.key({ modkey }, " ", function (c)
  120. c.fullscreen = not c.fullscreen
  121. do_border_radius(c)
  122. c:raise()
  123. end),
  124. awful.key({ modkey, "Shift" }, "q", function (c) c:kill() end)
  125. )
  126. -- multiple desktops
  127. for i = 1, 9 do
  128. globalkeys = gears.table.join(globalkeys,
  129. -- view desktop -- mod+#
  130. awful.key({ modkey }, "#" .. i + 9, function ()
  131. local screen = awful.screen.focused()
  132. local tag = screen.tags[i]
  133. if tag then
  134. tag:view_only()
  135. end
  136. end),
  137. -- move window to desktop -- mod+shift+#
  138. awful.key({ modkey, "Shift" }, "#" .. i + 9, function ()
  139. if client.focus then
  140. local tag = client.focus.screen.tags[i]
  141. if tag then
  142. client.focus:move_to_tag(tag)
  143. end
  144. end
  145. end)
  146. )
  147. end
  148. clientbuttons = gears.table.join(
  149. awful.button({}, 1, function (c) client.focus = c; c:raise() end),
  150. awful.button({ altkey }, 1, awful.mouse.client.move),
  151. awful.button({ altkey }, 3, awful.mouse.client.resize))
  152. -- window rules
  153. awful.rules.rules = {
  154. -- default properties
  155. { rule = {
  156. -- all
  157. }, properties = {
  158. border_width = beautiful.border_width,
  159. border_color = beautiful.border_normal,
  160. focus = awful.client.focus.filter,
  161. raise = true,
  162. keys = clientkeys,
  163. buttons = clientbuttons,
  164. screen = 1,
  165. titlebars_enabled = true,
  166. floating = false,
  167. placement = awful.placement.no_overlap+awful.placement.no_offscreen
  168. }},
  169. -- centred dialogs
  170. { rule_any = {
  171. type = {
  172. "dialog",
  173. },
  174. name = {
  175. "Save As",
  176. },
  177. role = {
  178. "GtkFileChooserDialog",
  179. },
  180. class = {
  181. "Rofi",
  182. },
  183. }, properties = {
  184. floating = true,
  185. ontop = true,
  186. sticky = true,
  187. --titlebars_enabled = true,
  188. }, callback = function (c)
  189. awful.placement.centered(c, { honor_workarea=true })
  190. end },
  191. -------------------------- application-specific ----------------------------
  192. { rule_any = {
  193. class = { "Firefox Developer Edition", "Sublime_text" },
  194. }, properties = { tag = "1", titlebars_enabled = false } },
  195. { rule_any = {
  196. class = { "discord" },
  197. }, properties = { tag = "2", titlebars_enabled = false } },
  198. { rule_any = {
  199. class = { "Inkscape", "allegro" }, -- see github/aseprite#1942
  200. }, properties = { tag = "3" } },
  201. { rule_any = {
  202. class = { "Steam" },
  203. }, properties = { tag = "6" } },
  204. }
  205. client.connect_signal("manage", function (c)
  206. if awesome.startup and
  207. not c.size_hints.user_position
  208. and not c.size_hints.program_position then
  209. -- prevent clients from being unreachable when a screen is disconnected
  210. awful.placement.no_offscreen(c)
  211. end
  212. do_border_radius(c)
  213. end)
  214. -- titlebars
  215. client.connect_signal("request::titlebars", function(c)
  216. local drag2move = gears.table.join(
  217. awful.button({ }, 1, function()
  218. client.focus = c
  219. c:raise()
  220. awful.mouse.client.move(c)
  221. end),
  222. awful.button({ }, 3, function()
  223. client.focus = c
  224. c:raise()
  225. awful.mouse.client.resize(c)
  226. end)
  227. )
  228. local horiz = wibox.layout.flex.horizontal
  229. awful.titlebar(c, { size = 36 }) : setup {
  230. { buttons = drag2move, layout = horiz }, -- left
  231. {
  232. {
  233. -- title
  234. align = "center",
  235. widget = awful.titlebar.widget.titlewidget(c),
  236. },
  237. buttons = drag2move,
  238. layout = horiz,
  239. },
  240. { buttons = drag2move, layout = horiz }, -- right
  241. layout = horiz,
  242. }
  243. end)
  244. --[[
  245. -- focus follows mouse
  246. client.connect_signal("mouse::enter", function(c)
  247. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  248. and awful.client.focus.filter(c) then
  249. client.focus = c
  250. end
  251. end)
  252. --]]
  253. -- bind keys
  254. root.keys(globalkeys)
  255. --root.buttons(globalbuttons)