Advertisement
Guest User

Untitled

a guest
Oct 14th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.32 KB | None | 0 0
  1. -- Standard awesome library
  2. local gears = require("gears")
  3. local awful = require("awful")
  4. awful.rules = require("awful.rules")
  5. require("awful.autofocus")
  6. -- Widget and layout library
  7. local wibox = require("wibox")
  8. -- Theme handling library
  9. local beautiful = require("beautiful")
  10. -- Notification library
  11. local naughty = require("naughty")
  12. local menubar = require("menubar")
  13.  
  14. -- {{{ Error handling
  15. -- Check if awesome encountered an error during startup and fell back to
  16. -- another config (This code will only ever execute for the fallback config)
  17. if awesome.startup_errors then
  18. naughty.notify({ preset = naughty.config.presets.critical,
  19. title = "Oops, there were errors during startup!",
  20. text = awesome.startup_errors })
  21. end
  22.  
  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.  
  31. naughty.notify({ preset = naughty.config.presets.critical,
  32. title = "Oops, an error happened!",
  33. text = err })
  34. in_error = false
  35. end)
  36. end
  37. -- }}}
  38.  
  39. -- {{{ Variable definitions
  40. -- Themes define colours, icons, and wallpapers
  41. --beautiful.init("/usr/share/awesome/themes/blackarch/theme.lua")
  42. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  43.  
  44. -- This is used later as the default terminal and editor to run.
  45. terminal = "urxvt"
  46. editor = os.getenv("EDITOR") or "nano"
  47. editor_cmd = terminal .. " -e " .. editor
  48.  
  49. -- Default modkey.
  50. -- Usually, Mod4 is the key with a logo between Control and Alt.
  51. -- If you do not like this or do not have such a key,
  52. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  53. -- However, you can use another modifier like Mod1, but it may interact with others.
  54. modkey = "Mod4"
  55.  
  56. -- Table of layouts to cover with awful.layout.inc, order matters.
  57. local layouts =
  58. {
  59. awful.layout.suit.floating,
  60. awful.layout.suit.tile,
  61. awful.layout.suit.tile.left,
  62. awful.layout.suit.tile.bottom,
  63. awful.layout.suit.tile.top,
  64. awful.layout.suit.fair,
  65. awful.layout.suit.fair.horizontal,
  66. awful.layout.suit.spiral,
  67. awful.layout.suit.spiral.dwindle,
  68. awful.layout.suit.max,
  69. awful.layout.suit.max.fullscreen,
  70. awful.layout.suit.magnifier
  71. }
  72. -- }}}
  73.  
  74. -- {{{ Wallpaper
  75. if beautiful.wallpaper then
  76. for s = 1, screen.count() do
  77. gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  78. end
  79. end
  80. -- }}}
  81.  
  82. -- {{{ Tags
  83. -- Define a tag table which hold all screen tags.
  84. tags = {}
  85. for s = 1, screen.count() do
  86. -- Each screen has its own tag table.
  87. tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  88. end
  89. -- }}}
  90.  
  91. -- {{{ Menu
  92. -- Create a laucher widget and a main menu
  93. myawesomemenu = {
  94. { "manual", terminal .. " -e man awesome" },
  95. { "edit config", editor_cmd .. " " .. awesome.conffile },
  96. { "restart", awesome.restart },
  97. { "quit", awesome.quit }
  98. }
  99.  
  100. termmenu = {
  101. { "wezterm", "wezterm" },
  102. { "kitty", "kitty" },
  103. }
  104.  
  105. browsermenu = {
  106. { "firefox", "firefox" },
  107. { "chromium", "chromium --no-sandbox" }
  108. }
  109.  
  110. networkmenu = {
  111. { "wifi-radar", "wifi-radar" },
  112. { "wifi-radar-polkit", "wifi-radar-polkit" }
  113. }
  114.  
  115. mymainmenu = awful.menu({
  116. items = {
  117. { "awesome", myawesomemenu },
  118. { "terminals", termmenu },
  119. { "browsers", browsermenu },
  120. { "network", networkmenu },
  121. }
  122. })
  123.  
  124. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  125. menu = mymainmenu })
  126.  
  127. -- Menubar configuration
  128. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  129. -- }}}
  130.  
  131. -- {{{ Wibox
  132. -- Create a textclock widget
  133. mytextclock = awful.widget.textclock()
  134.  
  135. -- Create a wibox for each screen and add it
  136. mywibox = {}
  137. mypromptbox = {}
  138. mylayoutbox = {}
  139. mytaglist = {}
  140. mytaglist.buttons = awful.util.table.join(
  141. awful.button({ }, 1, awful.tag.viewonly),
  142. awful.button({ modkey }, 1, awful.client.movetotag),
  143. awful.button({ }, 3, awful.tag.viewtoggle),
  144. awful.button({ modkey }, 3, awful.client.toggletag),
  145. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  146. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  147. )
  148. mytasklist = {}
  149. mytasklist.buttons = awful.util.table.join(
  150. awful.button({ }, 1, function (c)
  151. if c == client.focus then
  152. c.minimized = true
  153. else
  154. -- Without this, the following
  155. -- :isvisible() makes no sense
  156. c.minimized = false
  157. if not c:isvisible() then
  158. awful.tag.viewonly(c:tags()[1])
  159. end
  160. -- This will also un-minimize
  161. -- the client, if needed
  162. client.focus = c
  163. c:raise()
  164. end
  165. end),
  166. awful.button({ }, 3, function ()
  167. if instance then
  168. instance:hide()
  169. instance = nil
  170. else
  171. instance = awful.menu.clients({ width=250 })
  172. end
  173. end),
  174. awful.button({ }, 4, function ()
  175. awful.client.focus.byidx(1)
  176. if client.focus then client.focus:raise() end
  177. end),
  178. awful.button({ }, 5, function ()
  179. awful.client.focus.byidx(-1)
  180. if client.focus then client.focus:raise() end
  181. end))
  182.  
  183. for s = 1, screen.count() do
  184. -- Create a promptbox for each screen
  185. mypromptbox[s] = awful.widget.prompt()
  186. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  187. -- We need one layoutbox per screen.
  188. mylayoutbox[s] = awful.widget.layoutbox(s)
  189. mylayoutbox[s]:buttons(awful.util.table.join(
  190. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  191. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  192. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  193. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  194. -- Create a taglist widget
  195. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  196.  
  197. -- Create a tasklist widget
  198. mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  199.  
  200. -- Create the wibox
  201. mywibox[s] = awful.wibox({ position = "top", screen = s })
  202.  
  203. -- Widgets that are aligned to the left
  204. local left_layout = wibox.layout.fixed.horizontal()
  205. left_layout:add(mylauncher)
  206. left_layout:add(mytaglist[s])
  207. left_layout:add(mypromptbox[s])
  208.  
  209. -- Widgets that are aligned to the right
  210. local right_layout = wibox.layout.fixed.horizontal()
  211. if s == 1 then right_layout:add(wibox.widget.systray()) end
  212. right_layout:add(mytextclock)
  213. right_layout:add(mylayoutbox[s])
  214.  
  215. -- Now bring it all together (with the tasklist in the middle)
  216. local layout = wibox.layout.align.horizontal()
  217. layout:set_left(left_layout)
  218. layout:set_middle(mytasklist[s])
  219. layout:set_right(right_layout)
  220.  
  221. mywibox[s]:set_widget(layout)
  222. end
  223. -- }}}
  224.  
  225. -- {{{ Mouse bindings
  226. root.buttons(awful.util.table.join(
  227. awful.button({ }, 3, function () mymainmenu:toggle() end),
  228. awful.button({ }, 4, awful.tag.viewnext),
  229. awful.button({ }, 5, awful.tag.viewprev)
  230. ))
  231. -- }}}
  232.  
  233. -- {{{ Key bindings
  234. globalkeys = awful.util.table.join(
  235. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  236. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  237. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  238.  
  239. awful.key({ modkey, }, "j",
  240. function ()
  241. awful.client.focus.byidx( 1)
  242. if client.focus then client.focus:raise() end
  243. end),
  244. awful.key({ modkey, }, "k",
  245. function ()
  246. awful.client.focus.byidx(-1)
  247. if client.focus then client.focus:raise() end
  248. end),
  249. awful.key({ modkey, }, "w", function () mymainmenu:show() end),
  250.  
  251. -- Layout manipulation
  252. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  253. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  254. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  255. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  256. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  257. awful.key({ modkey, }, "Tab",
  258. function ()
  259. awful.client.focus.history.previous()
  260. if client.focus then
  261. client.focus:raise()
  262. end
  263. end),
  264.  
  265. -- Standard program
  266. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  267. awful.key({ modkey, "Control" }, "r", awesome.restart),
  268. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  269.  
  270. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  271. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  272. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  273. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  274. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  275. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  276. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  277. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  278.  
  279. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  280.  
  281. -- Prompt
  282. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen.index]:run() end),
  283.  
  284. awful.key({ modkey }, "x",
  285. function ()
  286. awful.prompt.run({ prompt = "Run Lua code: " },
  287. mypromptbox[mouse.screen].widget,
  288. awful.util.eval, nil,
  289. awful.util.getdir("cache") .. "/history_eval")
  290. end),
  291. -- Menubar
  292. awful.key({ modkey }, "p", function() menubar.show() end)
  293. )
  294.  
  295. clientkeys = awful.util.table.join(
  296. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  297. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  298. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  299. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  300. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  301. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  302. awful.key({ modkey, }, "n",
  303. function (c)
  304. -- The client currently has the input focus, so it cannot be
  305. -- minimized, since minimized clients can't have the focus.
  306. c.minimized = true
  307. end),
  308. awful.key({ modkey, }, "m",
  309. function (c)
  310. c.maximized_horizontal = not c.maximized_horizontal
  311. c.maximized_vertical = not c.maximized_vertical
  312. end)
  313. )
  314.  
  315. -- Bind all key numbers to tags.
  316. -- Be careful: we use keycodes to make it works on any keyboard layout.
  317. -- This should map on the top row of your keyboard, usually 1 to 9.
  318. for i = 1, 9 do
  319. globalkeys = awful.util.table.join(globalkeys,
  320. awful.key({ modkey }, "#" .. i + 9,
  321. function ()
  322. local screen = mouse.screen
  323. local tag = awful.tag.gettags(screen)[i]
  324. if tag then
  325. awful.tag.viewonly(tag)
  326. end
  327. end),
  328. awful.key({ modkey, "Control" }, "#" .. i + 9,
  329. function ()
  330. local screen = mouse.screen
  331. local tag = awful.tag.gettags(screen)[i]
  332. if tag then
  333. awful.tag.viewtoggle(tag)
  334. end
  335. end),
  336. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  337. function ()
  338. if client.focus then
  339. local tag = awful.tag.gettags(client.focus.screen)[i]
  340. if tag then
  341. awful.client.movetotag(tag)
  342. end
  343. end
  344. end),
  345. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  346. function ()
  347. if client.focus then
  348. local tag = awful.tag.gettags(client.focus.screen)[i]
  349. if tag then
  350. awful.client.toggletag(tag)
  351. end
  352. end
  353. end))
  354. end
  355.  
  356. clientbuttons = awful.util.table.join(
  357. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  358. awful.button({ modkey }, 1, awful.mouse.client.move),
  359. awful.button({ modkey }, 3, awful.mouse.client.resize))
  360.  
  361. -- Set keys
  362. root.keys(globalkeys)
  363. -- }}}
  364.  
  365. -- {{{ Rules
  366. awful.rules.rules = {
  367. -- All clients will match this rule.
  368. { rule = { },
  369. properties = { border_width = beautiful.border_width,
  370. border_color = beautiful.border_normal,
  371. focus = awful.client.focus.filter,
  372. keys = clientkeys,
  373. buttons = clientbuttons } },
  374. { rule = { class = "MPlayer" },
  375. properties = { floating = true } },
  376. { rule = { class = "pinentry" },
  377. properties = { floating = true } },
  378. { rule = { class = "gimp" },
  379. properties = { floating = true } },
  380. { rule = { class = "kitty" },
  381. properties = { floating = true, titlebars_enabled = true, } },
  382. -- Set Firefox to always map on tags number 2 of screen 1.
  383. -- { rule = { class = "Firefox" },
  384. -- properties = { tag = tags[1][2] } },
  385. }
  386. -- }}}
  387.  
  388. -- {{{ Signals
  389. -- Signal function to execute when a new client appears.
  390. client.connect_signal("manage", function (c, startup)
  391. -- Enable sloppy focus
  392. c:connect_signal("mouse::enter", function(c)
  393. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  394. and awful.client.focus.filter(c) then
  395. client.focus = c
  396. end
  397. end)
  398.  
  399. if not startup then
  400. -- Set the windows at the slave,
  401. -- i.e. put it at the end of others instead of setting it master.
  402. -- awful.client.setslave(c)
  403.  
  404. -- Put windows in a smart way, only if they does not set an initial position.
  405. if not c.size_hints.user_position and not c.size_hints.program_position then
  406. awful.placement.no_overlap(c)
  407. awful.placement.no_offscreen(c)
  408. end
  409. end
  410.  
  411. local titlebars_enabled = false
  412. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  413. -- buttons for the titlebar
  414. local buttons = awful.util.table.join(
  415. awful.button({ }, 1, function()
  416. client.focus = c
  417. c:raise()
  418. awful.mouse.client.move(c)
  419. end),
  420. awful.button({ }, 3, function()
  421. client.focus = c
  422. c:raise()
  423. awful.mouse.client.resize(c)
  424. end)
  425. )
  426.  
  427. -- Widgets that are aligned to the left
  428. local left_layout = wibox.layout.fixed.horizontal()
  429. left_layout:add(awful.titlebar.widget.iconwidget(c))
  430. left_layout:buttons(buttons)
  431.  
  432. -- Widgets that are aligned to the right
  433. local right_layout = wibox.layout.fixed.horizontal()
  434. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  435. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  436. right_layout:add(awful.titlebar.widget.stickybutton(c))
  437. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  438. right_layout:add(awful.titlebar.widget.closebutton(c))
  439.  
  440. -- The title goes in the middle
  441. local middle_layout = wibox.layout.flex.horizontal()
  442. local title = awful.titlebar.widget.titlewidget(c)
  443. title:set_align("center")
  444. middle_layout:add(title)
  445. middle_layout:buttons(buttons)
  446.  
  447. -- Now bring it all together
  448. local layout = wibox.layout.align.horizontal()
  449. layout:set_left(left_layout)
  450. layout:set_right(right_layout)
  451. layout:set_middle(middle_layout)
  452.  
  453. awful.titlebar(c):set_widget(layout)
  454. end
  455. end)
  456.  
  457. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  458. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  459. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement