rc.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. local wallpaperpc = beautiful.wallpaperpc
  160. -- If wallpaper is a function, call it with the screen
  161. if type(wallpaper) == "function" then
  162. wallpaper = wallpaper(s)
  163. end
  164. -- wallpaper only in PC
  165. if s.geometry.width > 320 then
  166. gears.wallpaper.centered(wallpaperpc, s, 1)
  167. end
  168. end
  169. end
  170. local function get_screen(s)
  171. return s and screen[s]
  172. end
  173. function awful.widget.tasklist.filter.currenttags_without_gs(c, screen)
  174. screen = get_screen(screen)
  175. -- Only print client on the same screen as this widget
  176. if get_screen(c.screen) ~= screen then return false end
  177. -- Include sticky client too
  178. if c.sticky then return true end
  179. local tags = screen.tags
  180. for _, t in ipairs(tags) do
  181. if t.selected then
  182. local ctags = c:tags()
  183. for _, v in ipairs(ctags) do
  184. if v == t then
  185. if c.class:lower() == "run.py" or c.class:lower() == "gsnotify-arm" or c.class:lower() == "main" then
  186. return false
  187. else
  188. return true
  189. end
  190. end
  191. end
  192. end
  193. end
  194. return false
  195. end
  196. screen.connect_signal("property::geometry", set_wallpaper)
  197. awful.screen.connect_for_each_screen(function(s)
  198. -- Wallpaper
  199. set_wallpaper(s)
  200. -- Each screen has its own tag table.
  201. awful.tag({ "GameShell" }, s, awful.layout.layouts[1])
  202. -- Create a promptbox for each screen
  203. s.mypromptbox = awful.widget.prompt()
  204. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  205. -- We need one layoutbox per screen.
  206. s.mylayoutbox = awful.widget.layoutbox(s)
  207. s.mylayoutbox:buttons(awful.util.table.join(
  208. awful.button({ }, 1, function () awful.layout.inc( 1) end),
  209. awful.button({ }, 3, function () awful.layout.inc(-1) end),
  210. awful.button({ }, 4, function () awful.layout.inc( 1) end),
  211. awful.button({ }, 5, function () awful.layout.inc(-1) end)))
  212. -- Create a taglist widget
  213. s.mytaglist = awful.widget.taglist(s, awful.widget.taglist.filter.all, taglist_buttons)
  214. -- Create a tasklist widget
  215. s.mytasklist = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags_without_gs, tasklist_buttons)
  216. -- Create the wibox
  217. if s.geometry.width > 320 then
  218. s.mywibox = awful.wibar({ position = "bottom", screen = s,visible=true })
  219. else
  220. s.mywibox = awful.wibar({ position = "bottom", screen = s,visible=false })
  221. end
  222. -- Add widgets to the wibox
  223. s.mywibox:setup {
  224. layout = wibox.layout.align.horizontal,
  225. { -- Left widgets
  226. layout = wibox.layout.fixed.horizontal,
  227. mylauncher,
  228. s.mytaglist,
  229. s.mypromptbox,
  230. },
  231. s.mytasklist, -- Middle widget
  232. { -- Right widgets
  233. layout = wibox.layout.fixed.horizontal,
  234. mykeyboardlayout,
  235. wibox.widget.systray(),
  236. mytextclock,
  237. s.mylayoutbox,
  238. },
  239. }
  240. end)
  241. -- }}}
  242. -- {{{ Mouse bindings
  243. root.buttons(awful.util.table.join(
  244. awful.button({ }, 3, function () mymainmenu:toggle() end),
  245. awful.button({ }, 4, awful.tag.viewnext),
  246. awful.button({ }, 5, awful.tag.viewprev)
  247. ))
  248. -- }}}
  249. -- Bind all key numbers to tags.
  250. -- Be careful: we use keycodes to make it works on any keyboard layout.
  251. -- This should map on the top row of your keyboard, usually 1 to 9.
  252. clientbuttons = awful.util.table.join(
  253. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  254. awful.button({ modkey }, 1, awful.mouse.client.move),
  255. awful.button({ modkey }, 3, awful.mouse.client.resize))
  256. function titlebar_add_with_settings(c)
  257. awful.titlebar.add(c, { modkey = modkey, height = 16, font = "Terminus 6"})
  258. end
  259. -- {{{ Rules
  260. -- Rules to apply to new clients (through the "manage" signal).
  261. awful.rules.rules = {
  262. -- All clients will match this rule.
  263. { rule = { },
  264. properties = {
  265. size_hints_honor = false,
  266. border_width = 0,
  267. border_color = beautiful.border_normal,
  268. focus = awful.client.focus.filter,
  269. raise = true,
  270. keys = clientkeys,
  271. buttons = clientbuttons,
  272. screen = awful.screen.preferred,
  273. placement = awful.placement.no_overlap+awful.placement.no_offscreen
  274. --placement = awful.placement.no_overlap+awful.placement.centered+awful.placement.no_offscreen
  275. }
  276. },
  277. { rule_any = {type = { "normal", "dialog"}
  278. }, properties = { titlebars_enabled = true }
  279. },
  280. -- Floating clients.
  281. { rule_any = {
  282. instance = {
  283. "DTA", -- Firefox addon DownThemAll.
  284. "copyq", -- Includes session name in class.
  285. },
  286. class = {
  287. "Arandr",
  288. "Gpick",
  289. "Kruler",
  290. "MessageWin", -- kalarm.
  291. "Sxiv",
  292. "Wpa_gui",
  293. "pinentry",
  294. "veromix",
  295. "xtightvncviewer",
  296. "xclock"
  297. },
  298. name = {
  299. "Event Tester", -- xev.
  300. },
  301. role = {
  302. "AlarmWindow", -- Thunderbird's calendar.
  303. "pop-up", -- e.g. Google Chrome's (detached) Developer Tools.
  304. }
  305. }, properties = { ontop=false,floating = true,titlebars_enabled=false }},
  306. }
  307. -- }}}
  308. local gs_class = {"run.py","gsnotify","gsnotify-arm","retroarch","GSPLauncher","main"}
  309. -- {{{ Signals
  310. -- Signal function to execute when a new client appears.
  311. client.connect_signal("manage", function (c)
  312. -- Set the windows at the slave,
  313. -- i.e. put it at the end of others instead of setting it master.
  314. -- if not awesome.startup then awful.client.setslave(c) end
  315. if awesome.startup and
  316. not c.size_hints.user_position
  317. and not c.size_hints.program_position then
  318. -- Prevent clients from being unreachable after screen count changes.
  319. awful.placement.no_offscreen(c)
  320. end
  321. c.ontop=false
  322. c.above=false
  323. c.below=true
  324. c.fullscreen=false
  325. if tableHasKey(c,"class") and c.class:lower() == "gsnotify-arm" then
  326. -- naughty.notify({text = "launched!",timeout = 2,position = "top_center"})
  327. c.ontop = true
  328. c.above = true
  329. c.focusable=false
  330. c.type = "notification"
  331. c.floating = true
  332. c:raise()
  333. end
  334. for s in capi.screen do
  335. if s.geometry.width > 320 then
  336. for _,v in pairs(gs_class) do
  337. if tableHasKey(c,"class") and c.class:lower() == v then
  338. awful.titlebar.hide(c)
  339. if v ~= "gsnotify-arm" then
  340. awful.placement.centered(c)
  341. end
  342. break
  343. end
  344. end
  345. -- centered bg with offset of tasklist_bar's height
  346. -- c.y= c.y + s.mywibox.height
  347. else
  348. -- hide all titlebars in GS
  349. awful.titlebar.hide(c)
  350. end
  351. end
  352. end)
  353. -- Add a titlebar if titlebars_enabled is set to true in the rules.
  354. client.connect_signal("request::titlebars", function(c)
  355. -- buttons for the titlebar
  356. local buttons = awful.util.table.join(
  357. awful.button({ }, 1, function()
  358. client.focus = c
  359. c:raise()
  360. awful.mouse.client.move(c)
  361. end),
  362. awful.button({ }, 3, function()
  363. client.focus = c
  364. c:raise()
  365. awful.mouse.client.resize(c)
  366. end)
  367. )
  368. awful.titlebar(c) : setup {
  369. { -- Left
  370. awful.titlebar.widget.closebutton(c),
  371. -- buttons = buttons,
  372. layout = wibox.layout.fixed.horizontal
  373. },
  374. { -- Middle
  375. { -- Title
  376. align = "left",
  377. widget = awful.titlebar.widget.titlewidget(c)
  378. },
  379. buttons = buttons,
  380. layout = wibox.layout.flex.horizontal
  381. },
  382. { -- Right
  383. align="right",
  384. awful.titlebar.widget.floatingbutton (c),
  385. awful.titlebar.widget.maximizedbutton(c),
  386. -- awful.titlebar.widget.stickybutton (c),
  387. -- awful.titlebar.widget.ontopbutton (c),
  388. -- awful.titlebar.widget.closebutton (c),
  389. layout = wibox.layout.fixed.horizontal()
  390. },
  391. layout = wibox.layout.align.horizontal
  392. }
  393. end)
  394. -- Enable sloppy focus, so that focus follows mouse.
  395. client.connect_signal("focus",
  396. function(c)
  397. c.border_color = beautiful.border_normal
  398. end)
  399. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  400. -- }}}
  401. client.disconnect_signal("request::activate", awful.ewmh.activate)
  402. function awful.ewmh.activate(c)
  403. if tableHasKey(c,"class") == false then
  404. return
  405. end
  406. if c:isvisible() then
  407. if c.class:lower() ~= "gsnotify-arm" then
  408. client.focus = c
  409. end
  410. if c.class:lower() == "retroarch" then
  411. c:lower()
  412. end
  413. end
  414. end
  415. client.connect_signal("request::activate", awful.ewmh.activate)
  416. client.connect_signal("property::fullscreen", function (c)
  417. c.fullscreen = false
  418. c.ontop = false
  419. c.focus=false
  420. c:lower()
  421. end)