convert everything to metatables and added rules

This commit is contained in:
Noella
2024-03-04 18:38:56 -07:00
parent 497a6bd76c
commit 1e248a903d
7 changed files with 212 additions and 158 deletions

View File

@@ -1,11 +1,16 @@
local naughty = require("naughty") local naughty = require("naughty")
local _M = {}
function _M.get()
-- Check if awesome encountered an error during startup and fell back to -- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config) -- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then if awesome.startup_errors then
naughty.notify({ preset = naughty.config.presets.critical, naughty.notify({
preset = naughty.config.presets.critical,
title = "Oops, there were errors during startup!", title = "Oops, there were errors during startup!",
text = awesome.startup_errors }) text = awesome.startup_errors,
})
end end
-- Handle runtime errors after startup -- Handle runtime errors after startup
@@ -13,12 +18,23 @@ do
local in_error = false local in_error = false
awesome.connect_signal("debug::error", function(err) awesome.connect_signal("debug::error", function(err)
-- Make sure we don't go into an endless error loop -- Make sure we don't go into an endless error loop
if in_error then return end if in_error then
return
end
in_error = true in_error = true
naughty.notify({ preset = naughty.config.presets.critical, naughty.notify({
preset = naughty.config.presets.critical,
title = "Oops, an error happened!", title = "Oops, an error happened!",
text = tostring(err) }) text = tostring(err),
})
in_error = false in_error = false
end) end)
end end
end
return setmetatable({}, {
__call = function(_, ...)
return _M.get(...)
end,
})

9
main/init.lua Normal file
View File

@@ -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

View File

@@ -1,5 +1,8 @@
local awful = require("awful") local awful = require("awful")
local _M = {}
function _M.get()
local _L = {} local _L = {}
_L = { _L = {
@@ -10,3 +13,10 @@ _L = {
} }
return _L return _L
end
return setmetatable({}, {
__call = function(_, ...)
return _M.get(...)
end,
})

93
main/rules.lua Normal file
View File

@@ -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,
})

View File

@@ -1,5 +1,8 @@
local awful = require("awful") local awful = require("awful")
local _M = {}
function _M.get()
local _T = {} local _T = {}
local tags = { local tags = {
@@ -25,3 +28,10 @@ awful.screen.connect_for_each_screen(function(s)
end) end)
return _T return _T
end
return setmetatable({}, {
__call = function(_, ...)
return _M.get(...)
end,
})

View File

@@ -1,3 +1,6 @@
local _M = {}
function _M.get()
local _V = {} local _V = {}
_V = { _V = {
@@ -9,3 +12,10 @@ _V = {
_V.editor_cmd = _V.terminal .. " -e " .. _V.editor _V.editor_cmd = _V.terminal .. " -e " .. _V.editor
return _V return _V
end
return setmetatable({}, {
__call = function(_, ...)
return _M.get(...)
end,
})

106
rc.lua
View File

@@ -8,53 +8,22 @@ local wibox = require("wibox")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local menubar = require("menubar") local menubar = require("menubar")
local hotkeys_popup = require("awful.hotkeys_popup") local hotkeys_popup = require("awful.hotkeys_popup")
local main = require("main")
require("awful.autofocus") require("awful.autofocus")
require("main.error_handling") require("main.error_handling")
beautiful.init(require("theme")) beautiful.init(require("theme"))
RC = {} RC = {}
RC.vars = require("main.user_vars") RC.vars = main.user_vars()
RC.layouts = require("main.layouts") RC.layouts = main.layouts()
RC.taglist = require("main.taglist") RC.tags = main.taglist()
-- Table of layouts to cover with awful.layout.inc, order matters. -- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = RC.layouts 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 -- Keyboard map indicator and switcher
mykeyboardlayout = awful.widget.keyboardlayout() -- mykeyboardlayout = awful.widget.keyboardlayout()
-- {{{ Wibar -- {{{ Wibar
-- Create a textclock widget -- Create a textclock widget
@@ -194,9 +163,6 @@ globalkeys = gears.table.join(
awful.key({ RC.vars.modkey }, "k", function() awful.key({ RC.vars.modkey }, "k", function()
awful.client.focus.byidx(-1) awful.client.focus.byidx(-1)
end, { description = "focus previous by index", group = "client" }), 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 -- Layout manipulation
awful.key({ RC.vars.modkey, "Shift" }, "j", function() awful.key({ RC.vars.modkey, "Shift" }, "j", function()
@@ -386,67 +352,7 @@ clientbuttons = gears.table.join(
root.keys(globalkeys) root.keys(globalkeys)
-- }}} -- }}}
-- {{{ Rules awful.rules.rules = main.rules(clientkeys, clientbuttons)
-- 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" } },
}
-- }}}
-- {{{ Signals -- {{{ Signals
-- Signal function to execute when a new client appears. -- Signal function to execute when a new client appears.