diff --git a/.definitions/client.d.lua b/.definitions/client.d.lua new file mode 100644 index 0000000..df73817 --- /dev/null +++ b/.definitions/client.d.lua @@ -0,0 +1,26 @@ +---@meta + +---@class client: gearsobject +client = {} + +---Commands the character to say "Hello {name}" +---@param name string +function client.hello(name) end + +--- Get the number of instances. +--- @return integer # The number of client objects alive. +function client.instances() end +--- Set a __index metamethod for all client instances. +--- @param cb function The meta-method +function client.set_index_miss_handler(cb) end +--- Set a __newindex metamethod for all client instances. +--- @param cb function The meta-method +function client.set_newindex_miss_handler(cb) end + +--- Get all clients into a table. +--- +--- @param screen? integer|screen A screen number to filter clients on. +--- @param stacked? boolean Return clients in stacking order? (ordered from +--- top to bottom). +--- @return table # A table with clients. +function client.get(screen, stacked) end diff --git a/.definitions/object.d.lua b/.definitions/object.d.lua new file mode 100644 index 0000000..a47d133 --- /dev/null +++ b/.definitions/object.d.lua @@ -0,0 +1,14 @@ +---@meta + +---@class gearsobject +gearsobject = {} +--- +--- Connect to a signal +--- @param signal string +--- @param handler function +function gearsobject.connect_signal(signal, handler) end + +--- Disconnect from a signal +--- @param signal string +--- @param handler function +function gearsobject.disconnect_signal(signal, handler) end diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..c607b17 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "workspace.library": [ + "/usr/local/share/somewm/lua/", + ".definitions/" + ], + "runtime.version": "Lua 5.1" +} diff --git a/actions.lua b/actions.lua index dd785aa..2c5350a 100644 --- a/actions.lua +++ b/actions.lua @@ -5,9 +5,9 @@ local actions = {} function actions.toggle_naughty() if naughty.is_suspended() then naughty.resume() - naughty.notify({ text = "Notifications enabled", timeout = 2 }) + naughty.notification({ text = "Notifications enabled", timeout = 2 }) else - naughty.notify({ text = "Notifications disabled", timeout = 2 }) + naughty.notification({ text = "Notifications disabled", timeout = 2 }) naughty.suspend() end end diff --git a/inspect_client.lua b/inspect_client.lua new file mode 100644 index 0000000..e7635bb --- /dev/null +++ b/inspect_client.lua @@ -0,0 +1,36 @@ +string.lpad = function(str, len, char) + if char == nil then char = ' ' end + return str .. string.rep(char, len - #str) +end + +local properties = { + "window", + "name", "type", "class", "instance", "role", + "pid", "machine", + "icon_name", "icon", "icon_sizes", + "screen", + "hidden", "minimized", "size_hints_honor", "size_hints", + "border_width", "border_color", + "urgent", + "content", + "opacity", + "ontop", "above", "below", + "fullscreen", "maximized", "maximized_horizontal", + "maximized_vertical", + "transient_for", "modal", "group_window", "leader_window", + "valid", "first_tag", "marked", "is_fixed", "floating", + "sticky", "focusable", "skip_taskbar", "dockable", "shape", + "shape_bounding", "shape_clip", "shape_input", + "shape_client_bounding", "shape_client_clip", "startup_id", + "x", "y", "width", "height", +} + +return function(c) + str = "client info:\n------------\n" + if (c ~= nil) then for _,prop in ipairs(properties) do + if (c[prop] ~= nil) then + str = str .. prop:lpad(20) .. "\t" .. tostring(c[prop]) .. "\n" + end + end end + return str +end diff --git a/localconf.lua.template b/localconf.lua.template index 3b23383..52c07e5 100644 --- a/localconf.lua.template +++ b/localconf.lua.template @@ -40,7 +40,7 @@ conf.cmd = { } -- Mod-r binding for running programs -conf.cmd.run = function() awful.util.spawn("dmenu_run -l 10 -y 350") end +conf.cmd.run = function() awful.spawn("dmenu_run -l 10 -y 350") end local menubar = require("menubar") conf.cmd.drun = menubar.show diff --git a/mpd.lua b/mpd.lua index e1ff36c..2b23d54 100644 --- a/mpd.lua +++ b/mpd.lua @@ -13,11 +13,11 @@ defaults.host = "127.0.0.1" defaults.port = "6600" for key, value in pairs(defaults) do - settings[key] = value + settings[key] = value end for key, value in pairs(conf.mpd) do - settings[key] = value + settings[key] = value end -- {{{ local helpers @@ -26,14 +26,22 @@ local function mpc(command) end local function dmenu(opts) - log.spawn("dmpc -h " .. settings.host .. " -p " .. settings.port .. " " .. - (settings.replace_on_search and "-r" or "-R") .. " " .. opts) + log.spawn( + "dmpc -h " + .. settings.host + .. " -p " + .. settings.port + .. " " + .. (settings.replace_on_search and "-r" or "-R") + .. " " + .. opts + ) end local function notify(stext) if not (naughty == nil) then - naughty.notify({ - text= stext + naughty.notification({ + text = stext, }) end end @@ -45,28 +53,27 @@ M.set_server = function(host, port) notify("Using mpd server " .. settings.host .. ":" .. settings.port) end - -- {{{ mpd.ctrl submodule M.ctrl = {} -M.ctrl.toggle = function () +M.ctrl.toggle = function() mpc("toggle") end -M.ctrl.play = function () +M.ctrl.play = function() mpc("play") end -M.ctrl.pause = function () +M.ctrl.pause = function() mpc("pause") end -M.ctrl.next = function () +M.ctrl.next = function() mpc("next") end -M.ctrl.prev = function () +M.ctrl.prev = function() mpc("prev") end @@ -88,7 +95,6 @@ M.prompt.album = function() dmenu("-A -b") end - M.prompt.title = function() dmenu("-A -b -t") end @@ -103,14 +109,11 @@ end M.prompt.toggle_replace_on_search = function() settings.replace_on_search = not settings.replace_on_search - notify("MPD prompts now " ..( - settings.replace_on_search and "replace" or "add to" - ).. " the playlist") + notify("MPD prompts now " .. (settings.replace_on_search and "replace" or "add to") .. " the playlist") end -- }}} - return M -- vim: set fenc=utf-8 tw=80 foldmethod=marker : diff --git a/mybindings.lua b/mybindings.lua index 3072911..50e8cac 100644 --- a/mybindings.lua +++ b/mybindings.lua @@ -1,5 +1,6 @@ -- key bindings local awful = require("awful") +local gears = require("gears") local conf = require("localconf") local actions = require("actions") @@ -23,7 +24,7 @@ lockhl:setup(wibars, "#F2C740", require("beautiful").bg_normal, { Caps = false } local function mpdserver(host) return function() mpd.set_server(host, "6600") - awful.util.spawn("mpd-host set " .. host .. " 6600") + awful.spawn("mpd-host set " .. host .. " 6600") end end @@ -124,7 +125,7 @@ local notifymap = { { "m", binder.spawn("newmails -p"), "Show unread mails" }, } -local myglobalkeys = awful.util.table.join( +local myglobalkeys = gears.table.join( awful.key({}, "Pause", binder.spawn("rofi -show window")), awful.key({ modkey }, "w", binder.spawn("rofi -show window")), awful.key({}, "Print", binder.spawn("flameshot gui")), diff --git a/rc.lua b/rc.lua index b1ec08b..a06595a 100644 --- a/rc.lua +++ b/rc.lua @@ -1,10 +1,11 @@ -- If LuaRocks is installed, make sure that packages installed through it are -- found (e.g. lgi). If LuaRocks is not installed, do nothing. -pcall(require, "luarocks.loader") +--pcall(require, "luarocks.loader") -- libraries {{{ local awful = require("awful") local beautiful = require("beautiful") local gears = require("gears") +beautiful.init(gears.filesystem.get_dir("config") .. "/theme.lua") ---@diagnostic disable-next-line: unused-local --- for debugging local inspect = require("inspect") @@ -13,10 +14,10 @@ require("awful.autofocus") require("util.errors") -- }}} -beautiful.init(awful.util.getdir("config") .. "/theme.lua") - require("tapestry") +awful.input.xkb_layout = "us_de" + -- {{{ Logging local log = require("talkative") log.add_logger(log.loggers.stdio, log.level.DEBUG) @@ -76,12 +77,12 @@ binder.modal.set_opacity(0.8) binder.add_default_bindings() binder.add_reloadable(tags.create_bindings) -local mybindings = awful.util.getdir("config") .. "/mybindings.lua" +local mybindings = gears.filesystem.get_dir("config") .. "/mybindings.lua" binder.add_reloadable(function() return dofile(mybindings) end) -binder.add_bindings(awful.util.table.join( +binder.add_bindings(gears.table.join( awful.key({}, "XF86AudioRaiseVolume", function() speakerwheel:up() end), @@ -109,7 +110,7 @@ binder.apply() require("rules") require("signals") -local autorun_file = awful.util.getdir("config") .. "/autorun" +local autorun_file = gears.filesystem.get_dir("config") .. "/autorun" if gears.filesystem.file_readable(autorun_file) then awful.spawn(autorun_file) end diff --git a/rules.lua b/rules.lua index 0137cc3..e4b2f83 100644 --- a/rules.lua +++ b/rules.lua @@ -1,8 +1,8 @@ -local awful = require("awful") -awful.rules = require("awful.rules") -local localconf = require("localconf") - local beautiful = require("beautiful") +local awful = require("awful") +local localconf = require("localconf") +local ruled = require("ruled") + local naughty = require("naughty") local binder = require("separable.binder") local log = require("talkative") @@ -11,7 +11,7 @@ local log = require("talkative") local function popup_urgent(client, message) client:connect_signal("property::urgent", function(c) if c.urgent and not c.focus then - naughty.notify({ text = message }) + naughty.notification({ text = message }) end end) end @@ -19,12 +19,12 @@ end local function keyboard_layer(num) return function(client) client:connect_signal("focus", function(c) - awful.util.spawn("kontroll-launch set-layer --index " .. num) - naughty.notify({ text = "kontroll: switching to layer " .. num }) + awful.spawn("kontroll-launch set-layer --index " .. num) + naughty.notification({ text = "kontroll: switching to layer " .. num }) end) client:connect_signal("unfocus", function(c) - awful.util.spawn("kontroll-launch set-layer --index 0") - naughty.notify({ text = "kontroll: switching to base layer" }) + awful.spawn("kontroll-launch set-layer --index 0") + naughty.notification({ text = "kontroll: switching to base layer" }) end) end end @@ -41,7 +41,7 @@ function startswith(str, start) return str:sub(1, #start) == start end -awful.rules.rules = { +ruled.client.append_rules({ -- All clients will match this rule. { rule = {}, @@ -158,4 +158,4 @@ awful.rules.rules = { rule = { class = "zenity" }, properties = { ontop = true, floating = true, placement = awful.placement.centered }, }, -} +}) diff --git a/separable/binder.lua b/separable/binder.lua index 1cf5fa0..dbaf5a1 100644 --- a/separable/binder.lua +++ b/separable/binder.lua @@ -1,5 +1,6 @@ -- key bindings local awful = require("awful") +local gears = require("gears") local naughty = require("naughty") local conf = require("localconf") local modkey = conf.modkey or "Mod4" @@ -101,12 +102,13 @@ local function screen_in_wrapdir(dir, _screen) for s = 1, screen.count() do geomtbl[s] = screen[s].geometry end - local target = awful.util.get_rectangle_in_direction(dir, geomtbl, screen[sel].geometry) + local target = gears.geometry.rectangle.get_in_direction(dir, geomtbl, screen[sel].geometry) if not target then local new_target = sel while new_target do target = new_target - new_target = awful.util.get_rectangle_in_direction(opposite_dirs[dir], geomtbl, screen[target].geometry) + new_target = + gears.geometry.rectangle.get_in_direction(opposite_dirs[dir], geomtbl, screen[target].geometry) end end @@ -114,22 +116,15 @@ local function screen_in_wrapdir(dir, _screen) end end -local function screen_focus_wrapdir(dir) - return function() - local target = screen_in_wrapdir(dir) - awful.screen.focus(target) - end -end - local function screen_move_client_wrapdir(dir) return function(c) local target = screen_in_wrapdir(dir) - awful.client.movetoscreen(c, target) + c:move_to_screen(target) end end function binder.add_bindings(keys) - globalkeys = awful.util.table.join(globalkeys, keys) + globalkeys = gears.table.join(globalkeys, keys) return binder end @@ -144,11 +139,11 @@ function binder.clear() end function binder.apply() - naughty.notify({ text = "Reloading key bindings" }) - local allkeys = awful.util.table.clone(globalkeys) + naughty.notification({ text = "Reloading key bindings" }) + local allkeys = gears.table.clone(globalkeys) for _, v in pairs(globalkeyfuncs) do local loadedkeys = v() - allkeys = awful.util.table.join(allkeys, loadedkeys) + allkeys = gears.table.join(allkeys, loadedkeys) end root.keys(allkeys) end @@ -165,7 +160,7 @@ local function client_opacity_set(c, default, max, step) end end -local clientkeys = awful.util.table.join( +local clientkeys = gears.table.join( awful.key({ modkey, "Shift" }, "f", function(c) c.fullscreen = not c.fullscreen end), @@ -176,7 +171,9 @@ local clientkeys = awful.util.table.join( awful.key({ modkey, "Control" }, "Return", function(c) c:swap(awful.client.getmaster()) end), - awful.key({ modkey }, "o", awful.client.movetoscreen), + awful.key({ modkey }, "o", function(c) + c:move_to_screen() + end), awful.key({ modkey, "Shift" }, "h", screen_move_client_wrapdir("left")), awful.key({ modkey, "Shift" }, "l", screen_move_client_wrapdir("right")), awful.key({ modkey, "Control" }, "o", function(c) @@ -193,7 +190,7 @@ local clientkeys = awful.util.table.join( end), awful.key({}, "XF86Calculater", awful.client.movetoscreen), awful.key({ modkey }, "i", function(c) - require("naughty").notify({ + naughty.notification({ text = string.format( "name: '%s'\nclass: '%s'\ninstance: '%s'\ntype: '%s'\npid: %d", c["name"], @@ -206,9 +203,9 @@ local clientkeys = awful.util.table.join( end) ) -root.buttons(awful.util.table.join(awful.button({}, 4, awful.tag.viewnext), awful.button({}, 5, awful.tag.viewprev))) +root.buttons(gears.table.join(awful.button({}, 4, awful.tag.viewnext), awful.button({}, 5, awful.tag.viewprev))) -local clientbuttons = awful.util.table.join( +local clientbuttons = gears.table.join( awful.button({}, 1, function(c) if c.name ~= "Onboard" then client.focus = c @@ -230,14 +227,14 @@ function binder.client.keys() end function binder.client.add_buttons(buttons) - clientbuttons = awful.util.table.join(clientbuttons, buttons) + clientbuttons = gears.table.join(clientbuttons, buttons) end function binder.client.add_bindings(keys) - clientkeys = awful.util.table.join(clientkeys, keys) + clientkeys = gears.table.join(clientkeys, keys) end -local default_bindings = awful.util.table.join( +local default_bindings = gears.table.join( awful.key({ modkey, "Control" }, "r", awesome.restart), awful.key({ modkey, "Shift" }, "q", awesome.quit), awful.key({ modkey }, "Return", spawnf(conf.cmd.terminal)), diff --git a/signals.lua b/signals.lua index 7fe67fb..002e6fc 100644 --- a/signals.lua +++ b/signals.lua @@ -1,43 +1,49 @@ local awful = require("awful") local beautiful = require("beautiful") +local ruled = require("ruled") +client.connect_signal("request::manage", function(c) + -- Set the windows at the slave, + -- i.e. put it at the end of others instead of setting it master. + -- if not awesome.startup then awful.client.setslave(c) end -client.connect_signal("manage", function (c) - -- Set the windows at the slave, - -- i.e. put it at the end of others instead of setting it master. - -- if not awesome.startup then awful.client.setslave(c) end - - if awesome.startup and - not c.size_hints.user_position - and not c.size_hints.program_position then - -- Prevent clients from being unreachable after screen count changes. - awful.placement.no_offscreen(c) - end + if awesome.startup and not c.size_hints.user_position and not c.size_hints.program_position then + -- Prevent clients from being unreachable after screen count changes. + awful.placement.no_offscreen(c) + end end) local fixed_clients = { - -- action search and similar windows in IDEA - { rule = { name = "", class = "jetbrains-idea", type = "dialog" } }, - -- password inputs - { rule = { class = "Pinentry-gtk-2" } }, - { rule = { class = "pinentry-qt" } }, - -- nextcloud closes on focus loss - { rule = { class = "Nextcloud" } }, + -- action search and similar windows in IDEA + { rule = { name = "", class = "jetbrains-idea", type = "dialog" } }, + -- password inputs + { rule = { class = "Pinentry-gtk-2" } }, + { rule = { class = "pinentry-qt" } }, + -- nextcloud closes on focus loss + { rule = { class = "Nextcloud" } }, } local function may_lose_focus(c) - if c == nil then return true end - return not awful.rules.matches_list(c, fixed_clients) + if c == nil then + return true + end + return not ruled.client.matches_list(c, fixed_clients) end -- Enable sloppy focus, so that focus follows mouse. client.connect_signal("mouse::enter", function(c) - if may_lose_focus(client.focus) - and awful.layout.get(c.screen) ~= awful.layout.suit.magnifier - and awful.client.focus.filter(c) then - client.focus = c - end + if + may_lose_focus(client.focus) + and awful.layout.get(c.screen) ~= awful.layout.suit.magnifier + and awful.client.focus.filter(c) + then + client.focus = c + end end) -client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end) -client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end) +client.connect_signal("focus", function(c) + c.border_color = beautiful.border_focus +end) +client.connect_signal("unfocus", function(c) + c.border_color = beautiful.border_normal +end) diff --git a/tags.lua b/tags.lua index 9050465..0df42cc 100644 --- a/tags.lua +++ b/tags.lua @@ -1,11 +1,12 @@ -- tags local awful = require("awful") +local gears = require("gears") local conf = require("localconf") local modkey = conf.modkey or "Mod4" -local tags={} +local tags = {} -awful.layout.layouts = { +awful.layout.append_default_layouts({ awful.layout.suit.fair, awful.layout.suit.fair.horizontal, awful.layout.suit.tile, @@ -13,16 +14,10 @@ awful.layout.layouts = { awful.layout.suit.max, awful.layout.suit.max.fullscreen, awful.layout.suit.floating, - -- awful.layout.suit.magnifier, - -- awful.layout.suit.corner.nw, - -- awful.layout.suit.corner.ne, - -- awful.layout.suit.corner.sw, - -- awful.layout.suit.corner.se, -} - +}) local function getfunc_viewonly(i) - return function () + return function() local screen = awful.screen.focused() local tag = screen.tags[i] if tag then @@ -32,7 +27,7 @@ local function getfunc_viewonly(i) end local function getfunc_viewtoggle(i) - return function () + return function() local screen = awful.screen.focused() local tag = screen.tags[i] if tag then @@ -42,7 +37,7 @@ local function getfunc_viewtoggle(i) end local function getfunc_moveto(i) - return function () + return function() if client.focus then local tag = client.focus.screen.tags[i] if tag then @@ -53,7 +48,7 @@ local function getfunc_moveto(i) end local function getfunc_clienttoggle(i) - return function () + return function() if client.focus then local tag = client.focus.screen.tags[i] if tag then @@ -64,20 +59,20 @@ local function getfunc_clienttoggle(i) end local tagdef = { - {"1"}, - {"2", { layout = awful.layout.suit.max }}, - {"3"}, - {"4", { layout = awful.layout.suit.max }}, - {"5"}, - {"6"}, - {"7"}, - {"8"}, - {"9"}, - {"0"}, - {"F1", { layout = awful.layout.suit.max }}, - {"F2"}, - {"F3"}, - {"F4", { layout = awful.layout.suit.max }}, + { "1" }, + { "2", { layout = awful.layout.suit.max } }, + { "3" }, + { "4", { layout = awful.layout.suit.max } }, + { "5" }, + { "6" }, + { "7" }, + { "8" }, + { "9" }, + { "0" }, + { "F1", { layout = awful.layout.suit.max } }, + { "F2" }, + { "F3" }, + { "F4", { layout = awful.layout.suit.max } }, } local function defaultlayout(s) @@ -90,11 +85,8 @@ end function tags.setup() awful.screen.connect_for_each_screen(function(s) - for _,t in ipairs(tagdef) do - awful.tag.add(t[1], awful.util.table.join( - {screen = s}, - t[2] or { layout = defaultlayout(s) } - )) + for _, t in ipairs(tagdef) do + awful.tag.add(t[1], gears.table.join({ screen = s }, t[2] or { layout = defaultlayout(s) })) end s.tags[1]:view_only() end) @@ -113,22 +105,24 @@ function tags.create_bindings() else --if i > 10 then k = "F" .. i - 10 -- F keys end - tagkeys = awful.util.table.join(tagkeys, - awful.key( { modkey }, k, getfunc_viewonly(i)), - awful.key( { modkey, "Control" }, k, getfunc_viewtoggle(i)), - awful.key( { modkey, "Shift" }, k, getfunc_moveto(i)), - awful.key( { modkey, "Control", "Shift" }, k, getfunc_clienttoggle(i)) + tagkeys = gears.table.join( + tagkeys, + awful.key({ modkey }, k, getfunc_viewonly(i)), + awful.key({ modkey, "Control" }, k, getfunc_viewtoggle(i)), + awful.key({ modkey, "Shift" }, k, getfunc_moveto(i)), + awful.key({ modkey, "Control", "Shift" }, k, getfunc_clienttoggle(i)) ) end -- keys for all tags - tagkeys = awful.util.table.join(tagkeys, - awful.key({ modkey }, "u", awful.client.urgent.jumpto), - awful.key({ modkey }, "Left", awful.tag.viewprev ), - awful.key({ modkey }, "Right", awful.tag.viewnext ), - awful.key({ modkey }, "Escape", awful.tag.history.restore) + tagkeys = gears.table.join( + tagkeys, + awful.key({ modkey }, "u", awful.client.urgent.jumpto), + awful.key({ modkey }, "Left", awful.tag.viewprev), + awful.key({ modkey }, "Right", awful.tag.viewnext), + awful.key({ modkey }, "Escape", awful.tag.history.restore) ) - return tagkeys; + return tagkeys end return tags diff --git a/talkative b/talkative index 95b709f..ca93752 160000 --- a/talkative +++ b/talkative @@ -1 +1 @@ -Subproject commit 95b709fa483363c894c22e5bf0e3060915e49411 +Subproject commit ca93752bef7cd662f9a102d3aa05c7b1c6adb4b5 diff --git a/tapestry b/tapestry index 5bb7a7d..fdf23d8 160000 --- a/tapestry +++ b/tapestry @@ -1 +1 @@ -Subproject commit 5bb7a7d0510ea1adecf1a175444cdbcca13b7e71 +Subproject commit fdf23d8580ea94cad21a2221b41931c4289bb74f diff --git a/util/errors.lua b/util/errors.lua index 2fc8a1d..856efd9 100644 --- a/util/errors.lua +++ b/util/errors.lua @@ -5,23 +5,29 @@ 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 }) + naughty.notification({ + 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 + 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 = err }) - in_error = false - end) + naughty.notification({ + preset = naughty.config.presets.critical, + title = "Oops, an error happened!", + text = err, + }) + in_error = false + end) end -- }}} diff --git a/widgets.lua b/widgets.lua index 4675b82..de60402 100644 --- a/widgets.lua +++ b/widgets.lua @@ -10,23 +10,23 @@ local gears = require("gears") local wlist = {} local mytaglist = {} -mytaglist.buttons = awful.util.table.join( -awful.button({ }, 1, awful.tag.viewonly), -awful.button({ modkey }, 1, awful.client.movetotag), -awful.button({ }, 3, awful.tag.viewtoggle), -awful.button({ modkey }, 3, awful.client.toggletag), -awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end), -awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end) +mytaglist.buttons = gears.table.join( + awful.button({}, 1, awful.tag.viewonly), + awful.button({ modkey }, 1, awful.client.movetotag), + awful.button({}, 3, awful.tag.viewtoggle), + awful.button({ modkey }, 3, awful.client.toggletag), + awful.button({}, 4, function(t) + awful.tag.viewnext(t.screen) + end), + awful.button({}, 5, function(t) + awful.tag.viewprev(t.screen) + end) ) - local function percentage_overlay(p, color, prefix, suffix) - return ( - '%s%d%%%s' - ):format(color, prefix or "", p, suffix or "") + return ('%s%d%%%s'):format(color, prefix or "", p, suffix or "") end - local function add_bar(s, position, direction, first, second) local newbar = awful.wibar({ position = position, @@ -35,29 +35,33 @@ local function add_bar(s, position, direction, first, second) width = math.floor(s.dpi / 5), }) - newbar:setup { + newbar:setup({ { first, nil, second, - layout = wibox.layout.align.horizontal + layout = wibox.layout.align.horizontal, }, direction = direction, - widget = wibox.container.rotate - } + widget = wibox.container.rotate, + }) return newbar end function widgets.setup(s) return { - left = function(bottom, top) s.leftwibar = add_bar(s, "left", "east", bottom, top) end, - right = function(top, bottom) s.rightwibar = add_bar(s, "right", "west", top, bottom) end + left = function(bottom, top) + s.leftwibar = add_bar(s, "left", "east", bottom, top) + end, + right = function(top, bottom) + s.rightwibar = add_bar(s, "right", "west", top, bottom) + end, } end function widgets.mail(mailboxes, notify_pos, title) local widget = wibox.widget.textbox() - local bg = wibox.widget { widget, widget = wibox.container.background } + local bg = wibox.widget({ widget, widget = wibox.container.background }) local callback = function(widget, args) if args[1] > 0 then @@ -71,7 +75,7 @@ function widgets.mail(mailboxes, notify_pos, title) else bg.visible = false end - return "⬓⬓ Unread "..args[2].." / New "..args[1].. " " + return "⬓⬓ Unread " .. args[2] .. " / New " .. args[1] .. " " end vicious.register(widget, vicious.widgets.mdir, callback, 60, mailboxes) table.insert(wlist, widget) @@ -81,23 +85,29 @@ end function widgets.layout(s) local mylayoutbox = awful.widget.layoutbox(s) - mylayoutbox:buttons(awful.util.table.join( - awful.button({ }, 1, function () awful.layout.inc( 1) end), - awful.button({ }, 3, function () awful.layout.inc(-1) end), - awful.button({ }, 4, function () awful.layout.inc( 1) end), - awful.button({ }, 5, function () awful.layout.inc(-1) end) + mylayoutbox:buttons(gears.table.join( + awful.button({}, 1, function() + awful.layout.inc(1) + end), + awful.button({}, 3, function() + awful.layout.inc(-1) + end), + awful.button({}, 4, function() + awful.layout.inc(1) + end), + awful.button({}, 5, function() + awful.layout.inc(-1) + end) )) return mylayoutbox end function widgets.screennum(s) - return wibox.widget.textbox("Screen " .. s.index) + return wibox.widget.textbox("Screen " .. s.index) end function widgets.taglist(s) - return awful.widget.taglist( - s, awful.widget.taglist.filter.noempty, mytaglist.buttons - ) + return awful.widget.taglist(s, awful.widget.taglist.filter.noempty, mytaglist.buttons) end function widgets.systray(s) @@ -109,18 +119,19 @@ function widgets.systray(s) end local function graph_label(graph, label, rotation, fontsize) - return wibox.widget { + return wibox.widget({ { { text = label, font = beautiful.fontface and (beautiful.fontface .. " " .. (fontsize or 7)) or beautiful.font, - widget = wibox.widget.textbox + widget = wibox.widget.textbox, }, - direction = rotation or 'east', widget = wibox.container.rotate + direction = rotation or "east", + widget = wibox.container.rotate, }, graph, - layout = wibox.layout.fixed.horizontal - } + layout = wibox.layout.fixed.horizontal, + }) end function widgets.cpu(s) @@ -133,16 +144,16 @@ function widgets.ram(s) end function widgets.graph(s, label, viciouswidget, viciousformat, interval) - local graph = wibox.widget { + local graph = wibox.widget({ width = 60, background_color = beautiful.bg_focus, color = "linear:0,0:0,20:0,#FF0000:0.3,#FFFF00:0.6," .. beautiful.fg_normal, widget = wibox.widget.graph, - } - local overlay = wibox.widget { - align = 'center', - widget = wibox.widget.textbox - } + }) + local overlay = wibox.widget({ + align = "center", + widget = wibox.widget.textbox, + }) local callback = function(widget, args) overlay.markup = percentage_overlay(args[1], beautiful.bg_normal) return args[1] @@ -153,39 +164,34 @@ function widgets.graph(s, label, viciouswidget, viciousformat, interval) return { layout = awful.widget.only_on_screen, screen = s and s.index or "primary", - graph_label( - { - graph, - overlay, - layout = wibox.layout.stack - }, - label, - nil, - 7 - ) + graph_label({ + graph, + overlay, + layout = wibox.layout.stack, + }, label, nil, 7), } end local function bar_with_overlay(fg, bg, width, height) - local progress = wibox.widget { + local progress = wibox.widget({ max_value = 1, color = fg, background_color = bg, forced_width = width, forced_height = height, - widget = wibox.widget.progressbar, - } + widget = wibox.widget.progressbar, + }) - progress.overlay = wibox.widget { + progress.overlay = wibox.widget({ font = beautiful.fontface and (beautiful.fontface .. " " .. 7) or beautiful.font, - align = 'center', - widget = wibox.widget.textbox - } + align = "center", + widget = wibox.widget.textbox, + }) return { progress, progress.overlay, - layout = wibox.layout.stack + layout = wibox.layout.stack, } end @@ -193,12 +199,9 @@ end function widgets.battery(s) local bat1 = bar_with_overlay(beautiful.fg_focus, beautiful.bg_focus, 100, math.floor(s.dpi / 10)) - local combined_bats = graph_label( - bat1, - "BAT" - ) + local combined_bats = graph_label(bat1, "BAT") - local callback = function (widget, args) + local callback = function(widget, args) if args[2] == 0 then combined_bats:set_visible(false) return "" @@ -209,9 +212,7 @@ function widgets.battery(s) else widget.background_color = beautiful.bg_focus end - widget.overlay.markup = percentage_overlay( - args[2], beautiful.bg_normal, args[1] .. " " - ) + widget.overlay.markup = percentage_overlay(args[2], beautiful.bg_normal, args[1] .. " ") return args[2] end end @@ -223,26 +224,33 @@ function widgets.battery(s) end local tasklist_buttons = gears.table.join( - awful.button({ }, 1, function(c) - if c == client.focus then - c.minimized = true - else - c:emit_signal("request::activate", "tasklist", {raise = true}) - end - end), - awful.button({ }, 3, function() awful.menu.client_list({ theme = { width = 250 } }) end), - awful.button({ }, 4, function() awful.client.focus.byidx(1) end), - awful.button({ }, 5, function() awful.client.focus.byidx(-1) end)) + awful.button({}, 1, function(c) + if c == client.focus then + c.minimized = true + else + c:emit_signal("request::activate", "tasklist", { raise = true }) + end + end), + awful.button({}, 3, function() + awful.menu.client_list({ theme = { width = 250 } }) + end), + awful.button({}, 4, function() + awful.client.focus.byidx(1) + end), + awful.button({}, 5, function() + awful.client.focus.byidx(-1) + end) +) -- display a taskbar -- `when` is a function taking the current screen, that is called on the given signal, and should return true if the -- taskbar should be shown. -- If signal and when are not given, the taskbar will be visible on tags with "max" layout function widgets.dynamic_taskbar(s, signal, when) - s.mytasklist = awful.widget.tasklist { - screen = s, - filter = awful.widget.tasklist.filter.currenttags, - style = { + s.mytasklist = awful.widget.tasklist({ + screen = s, + filter = awful.widget.tasklist.filter.currenttags, + style = { shape_border_width = 2, bg_focus = beautiful.bg_focus, shape_border_color = beautiful.border_focus, @@ -253,32 +261,32 @@ function widgets.dynamic_taskbar(s, signal, when) { { { - { id = 'icon_role', - widget = wibox.widget.imagebox, }, + { id = "icon_role", widget = wibox.widget.imagebox }, margins = 2, - widget = wibox.container.margin, + widget = wibox.container.margin, }, - { id = 'text_role', - widget = wibox.widget.textbox, }, + { id = "text_role", widget = wibox.widget.textbox }, layout = wibox.layout.fixed.horizontal, }, - left = 20, + left = 20, right = 15, - widget = wibox.container.margin + widget = wibox.container.margin, }, - id = 'background_role', + id = "background_role", widget = wibox.container.background, }, - } + }) s.taskbar = awful.wibar({ position = "top", screen = s, opacity = 0.8, height = math.floor(s.dpi / 4), - widget = s.mytasklist + widget = s.mytasklist, }) - local condition = when or function(s) return awful.layout.get(s).name == "max" end + local condition = when or function(s) + return awful.layout.get(s).name == "max" + end s:connect_signal(signal or "tag::history::update", function() s.taskbar.visible = condition(s) end) @@ -290,4 +298,8 @@ function widgets.update(name) vicious.force(wlist) end -return setmetatable(widgets, { __call = function(_, ...) return widgets.setup(...) end }) +return setmetatable(widgets, { + __call = function(_, ...) + return widgets.setup(...) + end, +})