rc.lua 15 KB

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