grid_rc.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. local gears = require("gears")
  2. local awful = require("awful")
  3. awful.rules = require("awful.rules")
  4. require("awful.autofocus")
  5. local wibox = require("wibox")
  6. local beautiful = require("beautiful")
  7. local naughty = require("naughty")
  8. local menubar = require("menubar")
  9. if awesome.startup_errors then
  10. naughty.notify({ preset = naughty.config.presets.critical,
  11. title = "Oops, there were errors during startup!",
  12. text = awesome.startup_errors })
  13. end
  14. do
  15. local in_error = false
  16. awesome.connect_signal("debug::error", function (err)
  17. -- Make sure we don't go into an endless error loop
  18. if in_error then return end
  19. in_error = true
  20. naughty.notify({ preset = naughty.config.presets.critical,
  21. title = "Oops, an error happened!",
  22. text = err })
  23. in_error = false
  24. end)
  25. end
  26. -- }}}
  27. beautiful.init("/home/cedlemo/Projets/Lua/blingbling/config_example/grid_tests/theme.lua")
  28. terminal = "Germinal"
  29. editor = os.getenv("EDITOR") or "nvim"
  30. editor_cmd = terminal .. " -e " .. editor
  31. modkey = "Mod4"
  32. local layouts =
  33. {
  34. awful.layout.suit.floating,
  35. }
  36. for s = 1, screen.count() do
  37. gears.wallpaper.maximized("/home/cedlemo/Projets/Lua/blingbling/config_example/tiles_grey.png", s, true)
  38. end
  39. tags = {}
  40. for s = 1, screen.count() do
  41. tags[s] = awful.tag({ 1, 2 }, s, layouts[1])
  42. end
  43. myawesomemenu = {
  44. { "edit config", editor_cmd .. " " .. awesome.conffile },
  45. { "restart", awesome.restart },
  46. { "quit", awesome.quit }
  47. }
  48. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  49. { "open terminal", terminal }
  50. }
  51. })
  52. -- Menubar configuration
  53. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  54. -- }}}
  55. -- {{{ Wibox
  56. -- Create a textclock widget
  57. mytextclock = awful.widget.textclock()
  58. -- Create a wibox for each screen and add it
  59. mywibox = {}
  60. mypromptbox = {}
  61. mylayoutbox = {}
  62. mytaglist = {}
  63. mytaglist.buttons = awful.util.table.join(
  64. awful.button({ }, 1, awful.tag.viewonly),
  65. awful.button({ modkey }, 1, awful.client.movetotag),
  66. awful.button({ }, 3, awful.tag.viewtoggle),
  67. awful.button({ modkey }, 3, awful.client.toggletag),
  68. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  69. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  70. )
  71. mytasklist = {}
  72. mytasklist.buttons = awful.util.table.join(
  73. awful.button({ }, 1, function (c)
  74. if c == client.focus then
  75. c.minimized = true
  76. else
  77. -- Without this, the following
  78. -- :isvisible() makes no sense
  79. c.minimized = false
  80. if not c:isvisible() then
  81. awful.tag.viewonly(c:tags()[1])
  82. end
  83. -- This will also un-minimize
  84. -- the client, if needed
  85. client.focus = c
  86. c:raise()
  87. end
  88. end),
  89. awful.button({ }, 3, function ()
  90. if instance then
  91. instance:hide()
  92. instance = nil
  93. else
  94. instance = awful.menu.clients({
  95. theme = { width = 250 }
  96. })
  97. end
  98. end),
  99. awful.button({ }, 4, function ()
  100. awful.client.focus.byidx(1)
  101. if client.focus then client.focus:raise() end
  102. end),
  103. awful.button({ }, 5, function ()
  104. awful.client.focus.byidx(-1)
  105. if client.focus then client.focus:raise() end
  106. end))
  107. for s = 1, screen.count() do
  108. -- Create a promptbox for each screen
  109. mypromptbox[s] = awful.widget.prompt()
  110. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  111. -- We need one layoutbox per screen.
  112. mylayoutbox[s] = awful.widget.layoutbox(s)
  113. mylayoutbox[s]:buttons(awful.util.table.join(
  114. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  115. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  116. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  117. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  118. -- Create a taglist widget
  119. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  120. -- Create a tasklist widget
  121. mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  122. -- Create the wibox
  123. mywibox[s] = awful.wibox({ position = "top", screen = s })
  124. -- Widgets that are aligned to the left
  125. local left_layout = wibox.layout.fixed.horizontal()
  126. left_layout:add(mytaglist[s])
  127. left_layout:add(mypromptbox[s])
  128. -- Widgets that are aligned to the right
  129. local right_layout = wibox.layout.fixed.horizontal()
  130. if s == 1 then right_layout:add(wibox.widget.systray()) end
  131. right_layout:add(mytextclock)
  132. right_layout:add(mylayoutbox[s])
  133. -- Now bring it all together (with the tasklist in the middle)
  134. local layout = wibox.layout.align.horizontal()
  135. layout:set_left(left_layout)
  136. layout:set_middle(mytasklist[s])
  137. layout:set_right(right_layout)
  138. mywibox[s]:set_widget(layout)
  139. end
  140. -- }}}
  141. -- {{{ Mouse bindings
  142. root.buttons(awful.util.table.join(
  143. awful.button({ }, 3, function () mymainmenu:toggle() end),
  144. awful.button({ }, 4, awful.tag.viewnext),
  145. awful.button({ }, 5, awful.tag.viewprev)
  146. ))
  147. -- }}}
  148. -- {{{ Key bindings
  149. globalkeys = awful.util.table.join(
  150. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  151. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  152. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  153. awful.key({ modkey, }, "j",
  154. function ()
  155. awful.client.focus.byidx( 1)
  156. if client.focus then client.focus:raise() end
  157. end),
  158. awful.key({ modkey, }, "k",
  159. function ()
  160. awful.client.focus.byidx(-1)
  161. if client.focus then client.focus:raise() end
  162. end),
  163. awful.key({ modkey, }, "w", function () mymainmenu:show() end),
  164. -- Layout manipulation
  165. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  166. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  167. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  168. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  169. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  170. awful.key({ modkey, }, "Tab",
  171. function ()
  172. awful.client.focus.history.previous()
  173. if client.focus then
  174. client.focus:raise()
  175. end
  176. end),
  177. -- Standard program
  178. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  179. awful.key({ modkey, "Control" }, "r", awesome.restart),
  180. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  181. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  182. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  183. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  184. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  185. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  186. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  187. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  188. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  189. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  190. -- Prompt
  191. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  192. awful.key({ modkey }, "x",
  193. function ()
  194. awful.prompt.run({ prompt = "Run Lua code: " },
  195. mypromptbox[mouse.screen].widget,
  196. awful.util.eval, nil,
  197. awful.util.getdir("cache") .. "/history_eval")
  198. end),
  199. -- Menubar
  200. awful.key({ modkey }, "p", function() menubar.show() end)
  201. )
  202. clientkeys = awful.util.table.join(
  203. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  204. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  205. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  206. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  207. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  208. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  209. awful.key({ modkey, }, "n",
  210. function (c)
  211. -- The client currently has the input focus, so it cannot be
  212. -- minimized, since minimized clients can't have the focus.
  213. c.minimized = true
  214. end),
  215. awful.key({ modkey, }, "m",
  216. function (c)
  217. c.maximized_horizontal = not c.maximized_horizontal
  218. c.maximized_vertical = not c.maximized_vertical
  219. end)
  220. )
  221. -- Bind all key numbers to tags.
  222. -- Be careful: we use keycodes to make it works on any keyboard layout.
  223. -- This should map on the top row of your keyboard, usually 1 to 9.
  224. for i = 1, 9 do
  225. globalkeys = awful.util.table.join(globalkeys,
  226. -- View tag only.
  227. awful.key({ modkey }, "#" .. i + 9,
  228. function ()
  229. local screen = mouse.screen
  230. local tag = awful.tag.gettags(screen)[i]
  231. if tag then
  232. awful.tag.viewonly(tag)
  233. end
  234. end),
  235. -- Toggle tag.
  236. awful.key({ modkey, "Control" }, "#" .. i + 9,
  237. function ()
  238. local screen = mouse.screen
  239. local tag = awful.tag.gettags(screen)[i]
  240. if tag then
  241. awful.tag.viewtoggle(tag)
  242. end
  243. end),
  244. -- Move client to tag.
  245. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  246. function ()
  247. if client.focus then
  248. local tag = awful.tag.gettags(client.focus.screen)[i]
  249. if tag then
  250. awful.client.movetotag(tag)
  251. end
  252. end
  253. end),
  254. -- Toggle tag.
  255. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  256. function ()
  257. if client.focus then
  258. local tag = awful.tag.gettags(client.focus.screen)[i]
  259. if tag then
  260. awful.client.toggletag(tag)
  261. end
  262. end
  263. end))
  264. end
  265. clientbuttons = awful.util.table.join(
  266. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  267. awful.button({ modkey }, 1, awful.mouse.client.move),
  268. awful.button({ modkey }, 3, awful.mouse.client.resize))
  269. -- Set keys
  270. root.keys(globalkeys)
  271. -- }}}
  272. -- {{{ Rules
  273. -- Rules to apply to new clients (through the "manage" signal).
  274. awful.rules.rules = {
  275. -- All clients will match this rule.
  276. { rule = { },
  277. properties = { border_width = beautiful.border_width,
  278. border_color = beautiful.border_normal,
  279. focus = awful.client.focus.filter,
  280. raise = true,
  281. keys = clientkeys,
  282. buttons = clientbuttons } },
  283. { rule = { class = "MPlayer" },
  284. properties = { floating = true } },
  285. { rule = { class = "pinentry" },
  286. properties = { floating = true } },
  287. { rule = { class = "gimp" },
  288. properties = { floating = true } },
  289. -- Set Firefox to always map on tags number 2 of screen 1.
  290. -- { rule = { class = "Firefox" },
  291. -- properties = { tag = tags[1][2] } },
  292. }
  293. -- }}}
  294. -- {{{ Signals
  295. -- Signal function to execute when a new client appears.
  296. client.connect_signal("manage", function (c, startup)
  297. -- Enable sloppy focus
  298. c:connect_signal("mouse::enter", function(c)
  299. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  300. and awful.client.focus.filter(c) then
  301. client.focus = c
  302. end
  303. end)
  304. if not startup then
  305. -- Set the windows at the slave,
  306. -- i.e. put it at the end of others instead of setting it master.
  307. -- awful.client.setslave(c)
  308. -- Put windows in a smart way, only if they does not set an initial position.
  309. if not c.size_hints.user_position and not c.size_hints.program_position then
  310. awful.placement.no_overlap(c)
  311. awful.placement.no_offscreen(c)
  312. end
  313. end
  314. local titlebars_enabled = false
  315. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  316. -- buttons for the titlebar
  317. local buttons = awful.util.table.join(
  318. awful.button({ }, 1, function()
  319. client.focus = c
  320. c:raise()
  321. awful.mouse.client.move(c)
  322. end),
  323. awful.button({ }, 3, function()
  324. client.focus = c
  325. c:raise()
  326. awful.mouse.client.resize(c)
  327. end)
  328. )
  329. -- Widgets that are aligned to the left
  330. local left_layout = wibox.layout.fixed.horizontal()
  331. left_layout:add(awful.titlebar.widget.iconwidget(c))
  332. left_layout:buttons(buttons)
  333. -- Widgets that are aligned to the right
  334. local right_layout = wibox.layout.fixed.horizontal()
  335. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  336. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  337. right_layout:add(awful.titlebar.widget.stickybutton(c))
  338. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  339. right_layout:add(awful.titlebar.widget.closebutton(c))
  340. -- The title goes in the middle
  341. local middle_layout = wibox.layout.flex.horizontal()
  342. local title = awful.titlebar.widget.titlewidget(c)
  343. title:set_align("center")
  344. middle_layout:add(title)
  345. middle_layout:buttons(buttons)
  346. -- Now bring it all together
  347. local layout = wibox.layout.align.horizontal()
  348. layout:set_left(left_layout)
  349. layout:set_right(right_layout)
  350. layout:set_middle(middle_layout)
  351. awful.titlebar(c):set_widget(layout)
  352. end
  353. end)
  354. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  355. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  356. grid_box = wibox({height = 400, width = 400, ontop = true, x = 200, y = 200})
  357. grid_box.visible = true
  358. local blingbling = require("blingbling")
  359. grid = blingbling.grid()
  360. texts = {}
  361. for i=1,5 do
  362. c = tostring(i - 1)
  363. texts[i] = blingbling.text_box({text = tostring(i),
  364. background_color = "#"..c..c..c..c..c..c,
  365. rounded_size = 0,
  366. h_margin = 0,
  367. v_margin = 0})
  368. end
  369. grid:add_child(texts[1], 1, 1, 1, 1)
  370. grid:add_child(texts[2], 2, 1, 1, 1)
  371. grid:add_child(texts[3], 1, 2, 2, 2)
  372. grid:add_child(texts[4], 3, 2, 2, 2)
  373. grid:add_child(texts[5], 3, 1, 2, 1)
  374. grid_box:set_widget(grid)