diff --git a/main/error_handling.lua b/main/error_handling.lua index ae441ed..843684e 100644 --- a/main/error_handling.lua +++ b/main/error_handling.lua @@ -1,24 +1,40 @@ local naughty = require("naughty") --- Check if awesome encountered an error during startup and fell back to --- another config (This code will only ever execute for the fallback config) -if awesome.startup_errors then - naughty.notify({ preset = naughty.config.presets.critical, - title = "Oops, there were errors during startup!", - text = awesome.startup_errors }) +local _M = {} + +function _M.get() + -- Check if awesome encountered an error during startup and fell back to + -- another config (This code will only ever execute for the fallback config) + if awesome.startup_errors then + naughty.notify({ + preset = naughty.config.presets.critical, + title = "Oops, there were errors during startup!", + text = awesome.startup_errors, + }) + end + + -- Handle runtime errors after startup + do + local in_error = false + awesome.connect_signal("debug::error", function(err) + -- Make sure we don't go into an endless error loop + if in_error then + return + end + in_error = true + + naughty.notify({ + preset = naughty.config.presets.critical, + title = "Oops, an error happened!", + text = tostring(err), + }) + in_error = false + end) + end end --- Handle runtime errors after startup -do - local in_error = false - awesome.connect_signal("debug::error", function (err) - -- Make sure we don't go into an endless error loop - if in_error then return end - in_error = true - - naughty.notify({ preset = naughty.config.presets.critical, - title = "Oops, an error happened!", - text = tostring(err) }) - in_error = false - end) -end +return setmetatable({}, { + __call = function(_, ...) + return _M.get(...) + end, +}) diff --git a/main/init.lua b/main/init.lua new file mode 100644 index 0000000..d9b3a45 --- /dev/null +++ b/main/init.lua @@ -0,0 +1,9 @@ +local _M = { + error_handling = require("main.error_handling"), + rules = require("main.rules"), + layouts = require("main.layouts"), + taglist = require("main.taglist"), + user_vars = require("main.user_vars"), +} + +return _M diff --git a/main/layouts.lua b/main/layouts.lua index 086438c..81830c1 100644 --- a/main/layouts.lua +++ b/main/layouts.lua @@ -1,12 +1,22 @@ local awful = require("awful") -local _L = {} +local _M = {} -_L = { - awful.layout.suit.tile, - awful.layout.suit.fair, - awful.layout.suit.max, - awful.layout.suit.floating, -} +function _M.get() + local _L = {} -return _L + _L = { + awful.layout.suit.tile, + awful.layout.suit.fair, + awful.layout.suit.max, + awful.layout.suit.floating, + } + + return _L +end + +return setmetatable({}, { + __call = function(_, ...) + return _M.get(...) + end, +}) diff --git a/main/rules.lua b/main/rules.lua new file mode 100644 index 0000000..a4a7b3b --- /dev/null +++ b/main/rules.lua @@ -0,0 +1,93 @@ +local awful = require("awful") +local beautiful = require("beautiful") + +local _M = {} + +function _M.get(clientkeys, clientbuttons) + local _R = { + { + rule = {}, + properties = { + border_width = beautiful.border_width, + border_color = beautiful.border_normal, + focus = awful.client.focus.filter, + raise = true, + titlebars_enabled = false, + keys = clientkeys, + buttons = clientbuttons, + screen = awful.screen.preferred, + placement = awful.placement.no_overlap + awful.placement.no_offscreen, + }, + }, + + -- Floating clients. + { + rule_any = { + instance = { + "DTA", + "copyq", + "pinentry", + }, + class = { + "Arandr", + "Blueman-manager", + "Gpick", + "Kruler", + "MessageWin", + "Sxiv", + "Tor Browser", + "Wpa_gui", + "veromix", + "xtightvncviewer", + }, + name = { + "Event Tester", + }, + role = { + "AlarmWindow", + "ConfigManager", + "pop-up", + }, + }, + properties = { + floating = true, + }, + }, + + -- Add titlebars to normal clients and dialogs + { + rule_any = { + type = { "normal", "dialog" }, + }, + properties = { + titlebars_enabled = true, + }, + }, + + { + rule = { class = "Firefox" }, + properties = { + screen = 1, + tag = RC.tags[2], + titlebars_enabled = false, + }, + }, + + { + rule = { class = "Discord" }, + properties = { + screen = 1, + tag = RC.tags[6], + titlebars_enabled = false, + }, + }, + } + + return _R +end + +return setmetatable({}, { + __call = function(_, ...) + return _M.get(...) + end, +}) diff --git a/main/taglist.lua b/main/taglist.lua index 46459ea..7e105a5 100644 --- a/main/taglist.lua +++ b/main/taglist.lua @@ -1,27 +1,37 @@ local awful = require("awful") -local _T = {} +local _M = {} -local tags = { - "󰎤 Terminal", - "󰎧 Web", - "󰎪 Code", - "󰎭 Junk", - "󰎱 Music", - "󰎳 Chat", -} +function _M.get() + local _T = {} -local layouts = { - RC.layouts[0], - RC.layouts[1], - RC.layouts[2], - RC.layouts[3], - RC.layouts[3], - RC.layouts[3], -} + local tags = { + "󰎤 Terminal", + "󰎧 Web", + "󰎪 Code", + "󰎭 Junk", + "󰎱 Music", + "󰎳 Chat", + } -awful.screen.connect_for_each_screen(function(s) - _T[s] = awful.tag(tags, s, layouts) -end) + local layouts = { + RC.layouts[0], + RC.layouts[1], + RC.layouts[2], + RC.layouts[3], + RC.layouts[3], + RC.layouts[3], + } -return _T + awful.screen.connect_for_each_screen(function(s) + _T[s] = awful.tag(tags, s, layouts) + end) + + return _T +end + +return setmetatable({}, { + __call = function(_, ...) + return _M.get(...) + end, +}) diff --git a/main/user_vars.lua b/main/user_vars.lua index f1aa497..47e01a0 100644 --- a/main/user_vars.lua +++ b/main/user_vars.lua @@ -1,11 +1,21 @@ -local _V = {} +local _M = {} -_V = { - terminal = "alacritty", - editor = os.getenv("EDITOR") or "nvim", - modkey = "Mod4", - wallpaper = os.getenv("HOME") .. "/.config/awesome/theme/background.jpg", -} -_V.editor_cmd = _V.terminal .. " -e " .. _V.editor +function _M.get() + local _V = {} -return _V + _V = { + terminal = "alacritty", + editor = os.getenv("EDITOR") or "nvim", + modkey = "Mod4", + wallpaper = os.getenv("HOME") .. "/.config/awesome/theme/background.jpg", + } + _V.editor_cmd = _V.terminal .. " -e " .. _V.editor + + return _V +end + +return setmetatable({}, { + __call = function(_, ...) + return _M.get(...) + end, +}) diff --git a/rc.lua b/rc.lua index 82d45ee..63343d4 100644 --- a/rc.lua +++ b/rc.lua @@ -8,53 +8,22 @@ local wibox = require("wibox") local beautiful = require("beautiful") local menubar = require("menubar") local hotkeys_popup = require("awful.hotkeys_popup") +local main = require("main") require("awful.autofocus") require("main.error_handling") beautiful.init(require("theme")) RC = {} -RC.vars = require("main.user_vars") -RC.layouts = require("main.layouts") -RC.taglist = require("main.taglist") +RC.vars = main.user_vars() +RC.layouts = main.layouts() +RC.tags = main.taglist() -- Table of layouts to cover with awful.layout.inc, order matters. awful.layout.layouts = RC.layouts --- {{{ Menu --- Create a launcher widget and a main menu -myawesomemenu = { - { - "hotkeys", - function() - hotkeys_popup.show_help(nil, awful.screen.focused()) - end, - }, - { "manual", RC.vars.terminal .. " -e man awesome" }, - { "edit config", RC.vars.editor_cmd .. " " .. awesome.conffile }, - { "restart", awesome.restart }, - { - "quit", - function() - awesome.quit() - end, - }, -} - -mymainmenu = awful.menu({ - items = { - { "awesome", myawesomemenu, beautiful.awesome_icon }, - { "open terminal", RC.vars.terminal }, - }, -}) - -mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, menu = mymainmenu }) - --- Menubar configuration -menubar.utils.terminal = RC.vars.terminal -- Set the terminal for applications that require it --- }}} -- Keyboard map indicator and switcher -mykeyboardlayout = awful.widget.keyboardlayout() +-- mykeyboardlayout = awful.widget.keyboardlayout() -- {{{ Wibar -- Create a textclock widget @@ -194,9 +163,6 @@ globalkeys = gears.table.join( awful.key({ RC.vars.modkey }, "k", function() awful.client.focus.byidx(-1) end, { description = "focus previous by index", group = "client" }), - awful.key({ RC.vars.modkey }, "w", function() - mymainmenu:show() - end, { description = "show main menu", group = "awesome" }), -- Layout manipulation awful.key({ RC.vars.modkey, "Shift" }, "j", function() @@ -386,67 +352,7 @@ clientbuttons = gears.table.join( root.keys(globalkeys) -- }}} --- {{{ Rules --- Rules to apply to new clients (through the "manage" signal). -awful.rules.rules = { - -- All clients will match this rule. - { - rule = {}, - properties = { - border_width = beautiful.border_width, - border_color = beautiful.border_normal, - focus = awful.client.focus.filter, - raise = true, - keys = clientkeys, - buttons = clientbuttons, - screen = awful.screen.preferred, - placement = awful.placement.no_overlap + awful.placement.no_offscreen, - }, - }, - - -- Floating clients. - { - rule_any = { - instance = { - "DTA", -- Firefox addon DownThemAll. - "copyq", -- Includes session name in class. - "pinentry", - }, - class = { - "Arandr", - "Blueman-manager", - "Gpick", - "Kruler", - "MessageWin", -- kalarm. - "Sxiv", - "Tor Browser", -- Needs a fixed window size to avoid fingerprinting by screen size. - "Wpa_gui", - "veromix", - "xtightvncviewer", - }, - - -- Note that the name property shown in xprop might be set slightly after creation of the client - -- and the name shown there might not match defined rules here. - name = { - "Event Tester", -- xev. - }, - role = { - "AlarmWindow", -- Thunderbird's calendar. - "ConfigManager", -- Thunderbird's about:config. - "pop-up", -- e.g. Google Chrome's (detached) Developer Tools. - }, - }, - properties = { floating = true }, - }, - - -- Add titlebars to normal clients and dialogs - { rule_any = { type = { "normal", "dialog" } }, properties = { titlebars_enabled = true } }, - - -- Set Firefox to always map on the tag named "2" on screen 1. - -- { rule = { class = "Firefox" }, - -- properties = { screen = 1, tag = "2" } }, -} --- }}} +awful.rules.rules = main.rules(clientkeys, clientbuttons) -- {{{ Signals -- Signal function to execute when a new client appears.