rc.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. -- Standard awesome library
  2. local gears = require("gears")
  3. local awful = require("awful")
  4. require("awful.autofocus")
  5. -- Widget and layout library
  6. local wibox = require("wibox")
  7. -- Theme handling library
  8. local beautiful = require("beautiful")
  9. -- Notification library
  10. local naughty = require("naughty")
  11. local menubar = require("menubar")
  12. local hotkeys_popup = require("awful.hotkeys_popup").widget
  13. -- Load Debian menu entries
  14. -- require("debian.menu")
  15. -- {{{ Error handling
  16. -- Check if awesome encountered an error during startup and fell back to
  17. -- another config (This code will only ever execute for the fallback config)
  18. if awesome.startup_errors then
  19. naughty.notify({ preset = naughty.config.presets.critical,
  20. title = "Oops, there were errors during startup!",
  21. text = awesome.startup_errors,timeout=3 })
  22. end
  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. naughty.notify({ preset = naughty.config.presets.critical,
  31. title = "Oops, an error happened!",
  32. text = tostring(err),timeout=3 })
  33. in_error = false
  34. end)
  35. end
  36. -- }}}
  37. theme_base = "/home/cpi/launcher/awesome"
  38. -- Themes define colours, icons, font and wallpapers.
  39. beautiful.init(theme_base .. "/themes/default/theme.lua")
  40. -- This is used later as the default terminal and editor to run.
  41. terminal = "xterm"
  42. editor = os.getenv("EDITOR") or "editor"
  43. editor_cmd = terminal .. " -e " .. editor
  44. -- Default modkey.
  45. -- Usually, Mod4 is the key with a logo between Control and Alt.
  46. -- If you do not like this or do not have such a key,
  47. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  48. -- However, you can use another modifier like Mod1, but it may interact with others.
  49. modkey = "Mod4"
  50. -- Table of layouts to cover with awful.layout.inc, order matters.
  51. awful.layout.layouts = {
  52. awful.layout.suit.floating,
  53. awful.layout.suit.tile,
  54. awful.layout.suit.tile.left,
  55. awful.layout.suit.tile.bottom,
  56. awful.layout.suit.tile.top,
  57. awful.layout.suit.fair,
  58. awful.layout.suit.fair.horizontal,
  59. -- awful.layout.suit.spiral,
  60. -- awful.layout.suit.spiral.dwindle,
  61. --awful.layout.suit.max,
  62. --awful.layout.suit.max.fullscreen,
  63. awful.layout.suit.magnifier,
  64. awful.layout.suit.corner.nw,
  65. -- awful.layout.suit.corner.ne,
  66. -- awful.layout.suit.corner.sw,
  67. -- awful.layout.suit.corner.se,
  68. }
  69. -- }}}
  70. -- {{{ Helper functions
  71. local function client_menu_toggle_fn()
  72. local instance = nil
  73. return function ()
  74. if instance and instance.wibox.visible then
  75. instance:hide()
  76. instance = nil
  77. else
  78. instance = awful.menu.clients({ theme = { width = 250 } })
  79. end
  80. end
  81. end
  82. -- }}}
  83. -- {{{ Menu
  84. -- Create a launcher widget and a main menu
  85. myawesomemenu = {
  86. { "edit config", editor_cmd .. " " .. awesome.conffile },
  87. { "restart", awesome.restart },
  88. { "quit", function() awesome.quit() end}
  89. }
  90. mymenu = {
  91. { "xterm" , "xterm"},
  92. { "xclock", "xclock"}
  93. }
  94. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  95. { "MyStuff", mymenu },
  96. { "open terminal", terminal }
  97. }
  98. })
  99. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  100. menu = mymainmenu })
  101. -- Menubar configuration
  102. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  103. -- }}}
  104. -- Keyboard map indicator and switcher
  105. mykeyboardlayout = awful.widget.keyboardlayout()
  106. -- Create a textclock widget
  107. mytextclock = wibox.widget.textclock()
  108. -- Create a wibox for each screen and add it
  109. local taglist_buttons = awful.util.table.join(
  110. awful.button({ }, 1, function(t) t:view_only() end),
  111. awful.button({ modkey }, 1, function(t)
  112. if client.focus then
  113. client.focus:move_to_tag(t)
  114. end
  115. end),
  116. awful.button({ }, 3, awful.tag.viewtoggle),
  117. awful.button({ modkey }, 3, function(t)
  118. if client.focus then
  119. client.focus:toggle_tag(t)
  120. end
  121. end),
  122. awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end),
  123. awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end)
  124. )
  125. local tasklist_buttons = awful.util.table.join(
  126. awful.button({ }, 1, function (c)
  127. if c == client.focus then
  128. c.minimized = true
  129. else
  130. -- Without this, the following
  131. -- :isvisible() makes no sense
  132. c.minimized = false
  133. if not c:isvisible() and c.first_tag then
  134. c.first_tag:view_only()
  135. end
  136. -- This will also un-minimize
  137. -- the client, if needed
  138. client.focus = c
  139. c:raise()
  140. end
  141. end),
  142. awful.button({ }, 3, client_menu_toggle_fn()),
  143. awful.button({ }, 4, function ()
  144. awful.client.focus.byidx(1)
  145. end),
  146. awful.button({ }, 5, function ()
  147. awful.client.focus.byidx(-1)
  148. end))
  149. -- screen.connect_signal("property::geometry", set_wallpaper)
  150. awful.screen.connect_for_each_screen(function(s)
  151. -- Wallpaper
  152. -- Each screen has its own tag table.
  153. awful.tag({ "1", "2" }, s, awful.layout.layouts[1])
  154. -- Create a promptbox for each screen
  155. s.mypromptbox = awful.widget.prompt()
  156. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  157. -- We need one layoutbox per screen.
  158. s.mylayoutbox = awful.widget.layoutbox(s)
  159. s.mylayoutbox:buttons(awful.util.table.join(
  160. awful.button({ }, 1, function () awful.layout.inc( 1) end),
  161. awful.button({ }, 3, function () awful.layout.inc(-1) end),
  162. awful.button({ }, 4, function () awful.layout.inc( 1) end),
  163. awful.button({ }, 5, function () awful.layout.inc(-1) end)))
  164. -- Create a taglist widget
  165. s.mytaglist = awful.widget.taglist(s, awful.widget.taglist.filter.all, taglist_buttons)
  166. -- Create a tasklist widget
  167. s.mytasklist = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, tasklist_buttons)
  168. -- Create the wibox
  169. s.mywibox = awful.wibar({ position = "top", screen = s,visible=false })
  170. -- Add widgets to the wibox
  171. s.mywibox:setup {
  172. layout = wibox.layout.align.horizontal,
  173. { -- Left widgets
  174. layout = wibox.layout.fixed.horizontal,
  175. mylauncher,
  176. s.mytaglist,
  177. s.mypromptbox,
  178. },
  179. s.mytasklist, -- Middle widget
  180. { -- Right widgets
  181. layout = wibox.layout.fixed.horizontal,
  182. mykeyboardlayout,
  183. wibox.widget.systray(),
  184. mytextclock,
  185. s.mylayoutbox,
  186. },
  187. }
  188. end)
  189. -- }}}
  190. -- {{{ Mouse bindings
  191. root.buttons(awful.util.table.join(
  192. awful.button({ }, 3, function () mymainmenu:toggle() end),
  193. awful.button({ }, 4, awful.tag.viewnext),
  194. awful.button({ }, 5, awful.tag.viewprev)
  195. ))
  196. -- }}}
  197. -- Bind all key numbers to tags.
  198. -- Be careful: we use keycodes to make it works on any keyboard layout.
  199. -- This should map on the top row of your keyboard, usually 1 to 9.
  200. clientbuttons = awful.util.table.join(
  201. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  202. awful.button({ modkey }, 1, awful.mouse.client.move),
  203. awful.button({ modkey }, 3, awful.mouse.client.resize))
  204. function titlebar_add_with_settings(c)
  205. awful.titlebar.add(c, { modkey = modkey, height = 16, font = "Terminus 6"})
  206. end
  207. -- {{{ Rules
  208. -- Rules to apply to new clients (through the "manage" signal).
  209. awful.rules.rules = {
  210. -- All clients will match this rule.
  211. { rule = { },
  212. properties = { border_width = 0,
  213. border_color = beautiful.border_normal,
  214. focus = awful.client.focus.filter,
  215. raise = true,
  216. keys = clientkeys,
  217. buttons = clientbuttons,
  218. screen = awful.screen.preferred,
  219. placement = awful.placement.no_overlap+awful.placement.no_offscreen
  220. }
  221. },
  222. -- Floating clients.
  223. { rule_any = {
  224. instance = {
  225. "DTA", -- Firefox addon DownThemAll.
  226. "copyq", -- Includes session name in class.
  227. },
  228. class = {
  229. "Arandr",
  230. "Gpick",
  231. "Kruler",
  232. "MessageWin", -- kalarm.
  233. "Sxiv",
  234. "Wpa_gui",
  235. "pinentry",
  236. "veromix",
  237. "xtightvncviewer",
  238. "xclock"
  239. },
  240. name = {
  241. "Event Tester", -- xev.
  242. },
  243. role = {
  244. "AlarmWindow", -- Thunderbird's calendar.
  245. "pop-up", -- e.g. Google Chrome's (detached) Developer Tools.
  246. }
  247. }, properties = { ontop=false,floating = true }},
  248. { rule_any = {type = { "normal", "dialog","desktop","dock","splash","menu","toolbar","utility","dnd","combo","popup_menu","dropdown_menu" }
  249. }, properties = { titlebars_enabled = false }
  250. },
  251. -- Set Firefox to always map on the tag named "2" on screen 1.
  252. -- { rule = { class = "Firefox" },
  253. -- properties = { screen = 1, tag = "2" } },
  254. }
  255. -- }}}
  256. -- {{{ Signals
  257. -- Signal function to execute when a new client appears.
  258. client.connect_signal("manage", function (c)
  259. -- Set the windows at the slave,
  260. -- i.e. put it at the end of others instead of setting it master.
  261. -- if not awesome.startup then awful.client.setslave(c) end
  262. if awesome.startup and
  263. not c.size_hints.user_position
  264. and not c.size_hints.program_position then
  265. -- Prevent clients from being unreachable after screen count changes.
  266. awful.placement.no_offscreen(c)
  267. end
  268. c.ontop=false
  269. c.above=false
  270. c.below=true
  271. c.fullscreen=false
  272. if c.class:lower() == "gsnotify-arm" then
  273. -- naughty.notify({text = "launched!",timeout = 2,position = "top_center"})
  274. c.ontop = true
  275. c.above = true
  276. c.focusable=false
  277. c.type = "notification"
  278. c.floating = true
  279. c:raise()
  280. -- awful.titlebar.hide(c)
  281. end
  282. end)
  283. -- Add a titlebar if titlebars_enabled is set to true in the rules.
  284. client.connect_signal("request::titlebars", function(c)
  285. -- buttons for the titlebar
  286. local buttons = awful.util.table.join(
  287. awful.button({ }, 1, function()
  288. client.focus = c
  289. c:raise()
  290. awful.mouse.client.move(c)
  291. end),
  292. awful.button({ }, 3, function()
  293. client.focus = c
  294. c:raise()
  295. awful.mouse.client.resize(c)
  296. end)
  297. )
  298. awful.titlebar(c) : setup {
  299. { -- Left
  300. awful.titlebar.widget.closebutton(c),
  301. -- buttons = buttons,
  302. layout = wibox.layout.fixed.horizontal
  303. },
  304. { -- Middle
  305. { -- Title
  306. align = "left",
  307. widget = awful.titlebar.widget.titlewidget(c)
  308. },
  309. buttons = buttons,
  310. layout = wibox.layout.flex.horizontal
  311. },
  312. { -- Right
  313. align="right",
  314. awful.titlebar.widget.floatingbutton (c),
  315. awful.titlebar.widget.maximizedbutton(c),
  316. -- awful.titlebar.widget.stickybutton (c),
  317. -- awful.titlebar.widget.ontopbutton (c),
  318. -- awful.titlebar.widget.closebutton (c),
  319. layout = wibox.layout.fixed.horizontal()
  320. },
  321. layout = wibox.layout.align.horizontal
  322. }
  323. end)
  324. -- Enable sloppy focus, so that focus follows mouse.
  325. client.connect_signal("focus",
  326. function(c)
  327. c.border_color = beautiful.border_normal
  328. end)
  329. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  330. -- }}}
  331. client.disconnect_signal("request::activate", awful.ewmh.activate)
  332. function awful.ewmh.activate(c)
  333. if c:isvisible() then
  334. if c.class:lower() ~= "gsnotify-arm" then
  335. client.focus = c
  336. end
  337. if c.class:lower() == "retroarch" then
  338. c:lower()
  339. end
  340. end
  341. end
  342. client.connect_signal("request::activate", awful.ewmh.activate)
  343. client.connect_signal("property::fullscreen", function (c)
  344. c.fullscreen = false
  345. c.ontop = false
  346. c.focus=false
  347. c:lower()
  348. end)