rc.lua 15 KB

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