diff --git a/.editorconfig b/.editorconfig index c1e2c64..5967019 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,8 +5,11 @@ root = true [*] indent_style = space -indent_size = 4 +indent_size = 3 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[*.json] +indent_size = 2 diff --git a/.gitignore b/.gitignore index a2e6bd4..5df5866 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -doc/ +/doc diff --git a/.luacheckrc b/.luacheckrc index 2761cd2..1c95742 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,34 +1,33 @@ --- Only allow symbols available in all Lua versions std = "min" -files[".luacheckrc"].ignore = { "111", "112", "131" } -files["config.ld"].ignore = { "111", "113" } +cache = true + +include_files = { + ".luacheckrc", + "*.rockspec", + "src/", + "config.ld", +} --- Global objects defined by the C code read_globals = { - "awesome", - "button", - "dbus", - "drawable", - "drawin", - "key", - "keygrabber", - "mousegrabber", - "selection", - "tag", - "window", - "table.unpack", - "math.atan2", + "awesome", + "button", + "dbus", + "drawable", + "drawin", + "key", + "keygrabber", + "mousegrabber", + "selection", + "tag", + "window", + "table.unpack", + "math.atan2", } globals = { - "screen", - "mouse", - "root", - "client", + "screen", + "mouse", + "root", + "client", } - --- Enable cache (uses .luacheckcache relative to this rc file). -cache = true - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..8440490 --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +indent_type = "Spaces" +indent_width = 3 +call_parentheses = "None" + +[sort_requires] +enabled = true diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c6cd6f0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "Lua.runtime.path": [ + "/usr/share/awesome/lib/?.lua", + "/usr/share/awesome/lib/?/init.lua" + ], + "[lua]": { + "editor.defaultFormatter": "JohnnyMorganz.stylua" + }, + "stylua.targetReleaseVersion": "latest", + "files.associations": { + ".luacheckrc": "lua", + "*.rockspec": "lua", + "config.ld": "lua" + } +} diff --git a/awesome-slot-dev-1.rockspec b/awesome-slot-dev-1.rockspec new file mode 100644 index 0000000..828ece1 --- /dev/null +++ b/awesome-slot-dev-1.rockspec @@ -0,0 +1,25 @@ +package = "awesome-slot" +version = "dev-1" +source = { + url = "git+https://github.com/Aire-One/awesome-slot.git", +} +description = { + summary = "A declarative API to connect signals for the AwesomeWM.", + detailed = "A declarative API to connect signals for the AwesomeWM.", + homepage = "https://github.com/Aire-One/awesome-slot", + license = "*** please specify a license ***", +} +build = { + type = "builtin", + modules = { + ["awesome-slot.init"] = "src/awesome-slot/init.lua", + ["awesome-slot.slots.client"] = "src/awesome-slot/slots/client.lua", + ["awesome-slot.slots.init"] = "src/awesome-slot/slots/init.lua", + ["awesome-slot.slots.ruled"] = "src/awesome-slot/slots/ruled.lua", + ["awesome-slot.slots.screen"] = "src/awesome-slot/slots/screen.lua", + ["awesome-slot.slots.tag"] = "src/awesome-slot/slots/tag.lua", + }, + copy_directories = { + "doc", + }, +} diff --git a/config.ld b/config.ld index 3fd0526..902d368 100644 --- a/config.ld +++ b/config.ld @@ -14,10 +14,10 @@ sort_modules = true not_luadoc = true file = { - "init.lua", - exclude = { - "slots", - }, + "src/awesome-slot", + exclude = { + "src/awesome-slot/slots", + }, } -- Define some new ldoc tags from the AwesomeWM doc diff --git a/slots/client.lua b/slots/client.lua deleted file mode 100644 index b93beaf..0000000 --- a/slots/client.lua +++ /dev/null @@ -1,21 +0,0 @@ -local client_slots = {} - -function client_slots.append_mousebindings(params) - local amouse = require "awful.mouse" - - for _, bindings in pairs(params.mousebindings) do - amouse.append_client_mousebindings(bindings) - end -end - -function client_slots.append_keybindings(params) - local akeyboard = require "awful.keyboard" - - for _, bindings in pairs(params.keybindings) do - akeyboard.append_client_keybindings(bindings) - end -end - -return client_slots - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/slots/ruled.lua b/slots/ruled.lua deleted file mode 100644 index 583f970..0000000 --- a/slots/ruled.lua +++ /dev/null @@ -1,21 +0,0 @@ -local ruled_slots = {} - -function ruled_slots.append_client_rules(params) - local rclient = require "ruled.client" - - for _, rule in pairs(params.rules) do - rclient.append_rule(rule) - end -end - -function ruled_slots.append_notification_rules(params) - local rnotification = require "ruled.notification" - - for _, rule in pairs(params.rules) do - rnotification.append_rule(rule) - end -end - -return ruled_slots - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/slots/screen.lua b/slots/screen.lua deleted file mode 100644 index 3c9c811..0000000 --- a/slots/screen.lua +++ /dev/null @@ -1,25 +0,0 @@ -local screen_slots = {} - -function screen_slots.wallpaper(screen, params) - local beautiful = require "beautiful" - local gwallpaper = require "gears.wallpaper" - - params = params or { - wallpaper = beautiful.wallpaper, - } - - local wallpaper = params.wallpaper - - if wallpaper then - -- If wallpaper is a function, call it with the screen - if type(wallpaper) == "function" then - wallpaper = wallpaper(screen) - end - - gwallpaper.maximized(wallpaper, screen, true) - end -end - -return screen_slots - --- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/init.lua b/src/awesome-slot/init.lua similarity index 56% rename from init.lua rename to src/awesome-slot/init.lua index f6ba980..793493d 100644 --- a/init.lua +++ b/src/awesome-slot/init.lua @@ -46,43 +46,43 @@ local gtable = require "gears.table" local capi = { - client = _G.client, - screen = _G.screen, - tag = _G.tag, + client = _G.client, + screen = _G.screen, + tag = _G.tag, } local awesome_slot = { - mt = {}, + mt = {}, - --- Slots defined by this module. - -- @table awesome_slot.slots - slots = require "awesome-slot.slots", + --- Slots defined by this module. + -- @table awesome_slot.slots + slots = require "awesome-slot.slots", - --- Special objects that require a static connection instead of object level connection. - -- @table awesome_slot.static_connect - static_connect = { - client = capi.client, - screen = capi.screen, - tag = capi.tag, - ruled_client = require "ruled.client", - ruled_notification = require "ruled.notification", - }, + --- Special objects that require a static connection instead of object level connection. + -- @table awesome_slot.static_connect + static_connect = { + client = capi.client, + screen = capi.screen, + tag = capi.tag, + ruled_client = require "ruled.client", + ruled_notification = require "ruled.notification", + }, - _private = { - registered_slots = {}, - }, + _private = { + registered_slots = {}, + }, } local function generate_id(base_id) - local id = base_id - local n = 0 + local id = base_id + local n = 0 - while awesome_slot.slots[id] ~= nil do - n = n + 1 - id = base_id .. "_#" .. n - end + while awesome_slot.slots[id] ~= nil do + n = n + 1 + id = base_id .. "_#" .. n + end - return id + return id end --- Find a previously registered slot. @@ -93,11 +93,11 @@ end -- @treturn Slot The slot. -- @staticfct awesome_slot.get_slot function awesome_slot.get_slot(slot) - assert(slot) - local id = type(slot) == "string" and slot or slot.id - assert(id, "Slot not found!") + assert(slot) + local id = type(slot) == "string" and slot or slot.id + assert(id, "Slot not found!") - return awesome_slot._private.registered_slots[id] + return awesome_slot._private.registered_slots[id] end --- Create a new Slot instance. @@ -114,30 +114,30 @@ end -- @treturn Slot The created Slot instance. -- @constructorfct awesome_slot function awesome_slot.create(params) - local slot = {} + local slot = {} - slot.id = generate_id(params.id or "UNNAMED_SLOT") - slot.target = params.target - slot.signal = params.signal - slot.connected = false + slot.id = generate_id(params.id or "UNNAMED_SLOT") + slot.target = params.target + slot.signal = params.signal + slot.connected = false - if params.slot_params then - slot.params = params.slot_params - slot.callback = function() - params.slot(slot.params) - end - else - slot.callback = params.slot - end + if params.slot_params then + slot.params = params.slot_params + slot.callback = function() + params.slot(slot.params) + end + else + slot.callback = params.slot + end - -- Insert the new slot into the slots list - awesome_slot._private.registered_slots[slot.id] = slot + -- Insert the new slot into the slots list + awesome_slot._private.registered_slots[slot.id] = slot - if params.connect then - awesome_slot.connect(slot) - end + if params.connect then + awesome_slot.connect(slot) + end - return slot + return slot end --- Remove a registered slot and disconnect it. @@ -145,13 +145,13 @@ end -- @tparam Slot slot The slot to remove. -- @staticfct awesome_slot.remove function awesome_slot.remove(slot) - local s = awesome_slot.get_slot(slot) + local s = awesome_slot.get_slot(slot) - if s.connected then - awesome_slot.disconnect_slot(s) - end + if s.connected then + awesome_slot.disconnect_slot(s) + end - awesome_slot._private.registered_slots[s.id] = nil + awesome_slot._private.registered_slots[s.id] = nil end --- Connect a slot to its signal. @@ -160,20 +160,20 @@ end -- @treturn Slot The slot. -- @staticfct awesome_slot.connect function awesome_slot.connect(slot) - local s = awesome_slot.get_slot(slot) + local s = awesome_slot.get_slot(slot) - -- Some modules expose a static connect_signals function - -- at the module level, while other tables/objects inheriting from - -- gears.object implement the signal connection API at the instance level. - if gtable.hasitem(awesome_slot.static_connect, s.target) then - s.target.connect_signal(s.signal, s.callback) - else - s.target:connect_signal(s.signal, s.callback) - end + -- Some modules expose a static connect_signals function + -- at the module level, while other tables/objects inheriting from + -- gears.object implement the signal connection API at the instance level. + if gtable.hasitem(awesome_slot.static_connect, s.target) then + s.target.connect_signal(s.signal, s.callback) + else + s.target:connect_signal(s.signal, s.callback) + end - s.connected = true + s.connected = true - return s + return s end --- Disconnect a slot from its signal. @@ -182,22 +182,22 @@ end -- @treturn Slot The slot. -- @staticfct awesome_slot.disconnect function awesome_slot.disconnect(slot) - local s = awesome_slot.get_slot(slot) + local s = awesome_slot.get_slot(slot) - -- Please check the `:connect_slot` method to understand why we do this. - if gtable.hasitem(awesome_slot.static_connect, s.target) then - s.target.disconnect_slot(s.signal, s.callback) - else - s.target:disconnect_slot(s.signal, s.callback) - end + -- Please check the `:connect_slot` method to understand why we do this. + if gtable.hasitem(awesome_slot.static_connect, s.target) then + s.target.disconnect_slot(s.signal, s.callback) + else + s.target:disconnect_slot(s.signal, s.callback) + end - s.connected = false + s.connected = false - return s + return s end function awesome_slot.mt:__call(...) -- luacheck: ignore unused argument self - return awesome_slot.create(...) + return awesome_slot.create(...) end return setmetatable(awesome_slot, awesome_slot.mt) diff --git a/src/awesome-slot/slots/client.lua b/src/awesome-slot/slots/client.lua new file mode 100644 index 0000000..3b0ef04 --- /dev/null +++ b/src/awesome-slot/slots/client.lua @@ -0,0 +1,21 @@ +local client_slots = {} + +function client_slots.append_mousebindings(params) + local amouse = require "awful.mouse" + + for _, bindings in pairs(params.mousebindings) do + amouse.append_client_mousebindings(bindings) + end +end + +function client_slots.append_keybindings(params) + local akeyboard = require "awful.keyboard" + + for _, bindings in pairs(params.keybindings) do + akeyboard.append_client_keybindings(bindings) + end +end + +return client_slots + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/slots/init.lua b/src/awesome-slot/slots/init.lua similarity index 100% rename from slots/init.lua rename to src/awesome-slot/slots/init.lua diff --git a/src/awesome-slot/slots/ruled.lua b/src/awesome-slot/slots/ruled.lua new file mode 100644 index 0000000..36f8dc5 --- /dev/null +++ b/src/awesome-slot/slots/ruled.lua @@ -0,0 +1,21 @@ +local ruled_slots = {} + +function ruled_slots.append_client_rules(params) + local rclient = require "ruled.client" + + for _, rule in pairs(params.rules) do + rclient.append_rule(rule) + end +end + +function ruled_slots.append_notification_rules(params) + local rnotification = require "ruled.notification" + + for _, rule in pairs(params.rules) do + rnotification.append_rule(rule) + end +end + +return ruled_slots + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/src/awesome-slot/slots/screen.lua b/src/awesome-slot/slots/screen.lua new file mode 100644 index 0000000..32c659a --- /dev/null +++ b/src/awesome-slot/slots/screen.lua @@ -0,0 +1,25 @@ +local screen_slots = {} + +function screen_slots.wallpaper(screen, params) + local beautiful = require "beautiful" + local gwallpaper = require "gears.wallpaper" + + params = params or { + wallpaper = beautiful.wallpaper, + } + + local wallpaper = params.wallpaper + + if wallpaper then + -- If wallpaper is a function, call it with the screen + if type(wallpaper) == "function" then + wallpaper = wallpaper(screen) + end + + gwallpaper.maximized(wallpaper, screen, true) + end +end + +return screen_slots + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/slots/tag.lua b/src/awesome-slot/slots/tag.lua similarity index 64% rename from slots/tag.lua rename to src/awesome-slot/slots/tag.lua index a5058c8..79600fc 100644 --- a/slots/tag.lua +++ b/src/awesome-slot/slots/tag.lua @@ -1,9 +1,9 @@ local tag_slots = {} function tag_slots.default_layouts(params) - local alayout = require "awful.layout" + local alayout = require "awful.layout" - alayout.append_default_layouts(params.layouts) + alayout.append_default_layouts(params.layouts) end return tag_slots diff --git a/stylua.toml b/stylua.toml deleted file mode 100644 index 976e686..0000000 --- a/stylua.toml +++ /dev/null @@ -1,6 +0,0 @@ -column_width = 80 -line_endings = "Unix" -indent_type = "Spaces" -indent_width = 4 -quote_style = "AutoPreferDouble" -no_call_parentheses = true