From f0b32f45746c026d402651013b7e98315d6956a1 Mon Sep 17 00:00:00 2001 From: delta Date: Sat, 4 Mar 2023 22:04:55 +0100 Subject: restructure awesome config, add fresnel --- .config/awesome/misc/autostart/init.lua | 4 + .config/awesome/misc/autostart/programs.sh | 22 ++ .config/awesome/misc/cfg.lua | 6 + .config/awesome/misc/helpers.lua | 121 +++++++++++ .config/awesome/misc/init.lua | 5 + .config/awesome/misc/keys.lua | 318 +++++++++++++++++++++++++++++ .config/awesome/misc/rules.lua | 103 ++++++++++ .config/awesome/misc/setup.lua | 65 ++++++ .config/awesome/misc/signals.lua | 89 ++++++++ .config/awesome/misc/vars.lua | 81 ++++++++ 10 files changed, 814 insertions(+) create mode 100644 .config/awesome/misc/autostart/init.lua create mode 100644 .config/awesome/misc/autostart/programs.sh create mode 100644 .config/awesome/misc/cfg.lua create mode 100644 .config/awesome/misc/helpers.lua create mode 100644 .config/awesome/misc/init.lua create mode 100644 .config/awesome/misc/keys.lua create mode 100644 .config/awesome/misc/rules.lua create mode 100644 .config/awesome/misc/setup.lua create mode 100644 .config/awesome/misc/signals.lua create mode 100644 .config/awesome/misc/vars.lua (limited to '.config/awesome/misc') diff --git a/.config/awesome/misc/autostart/init.lua b/.config/awesome/misc/autostart/init.lua new file mode 100644 index 0000000..e0d4efb --- /dev/null +++ b/.config/awesome/misc/autostart/init.lua @@ -0,0 +1,4 @@ +local awful = require "awful" +local gfs = require "gears.filesystem" + +awful.spawn.once("bash " .. gfs.get_configuration_dir() .. "/misc/autostart/programs.sh") diff --git a/.config/awesome/misc/autostart/programs.sh b/.config/awesome/misc/autostart/programs.sh new file mode 100644 index 0000000..dbafe44 --- /dev/null +++ b/.config/awesome/misc/autostart/programs.sh @@ -0,0 +1,22 @@ +function exe () { + local cmd=$@ + if ! pgrep -x $(echo $cmd | cut -d " " -f1); then + $cmd & + fi +} + +function exe_lax () { + local cmd=$@ + if ! pgrep $(echo $cmd | cut -d " " -f1); then + $cmd & + fi +} + +exe "picom -b" +exe sxhkd +exe clipcatd +exe_lax wezterm +exe_lax "wezterm start --class code_term" +exe firefox +exe spotify +exe discord diff --git a/.config/awesome/misc/cfg.lua b/.config/awesome/misc/cfg.lua new file mode 100644 index 0000000..0d9bcba --- /dev/null +++ b/.config/awesome/misc/cfg.lua @@ -0,0 +1,6 @@ +local c = { + titlebars_enabled = false, + terminal = "wezterm" +} + +return c diff --git a/.config/awesome/misc/helpers.lua b/.config/awesome/misc/helpers.lua new file mode 100644 index 0000000..132a4df --- /dev/null +++ b/.config/awesome/misc/helpers.lua @@ -0,0 +1,121 @@ +local awful = require "awful" +local gears = require "gears" +local xresources = require "beautiful.xresources" +local n = require "naughty".notification +local dpi = xresources.apply_dpi +local vars = require "misc.vars" +local wibox = require "wibox" + +local h = {} + +-- utils + +function h.debug(message) + n { message = tostring(message) } +end + +function h.map(t, f) + local nt = {} + for k,v in pairs(t) do + nt[k] = f(v) + end + return nt +end + +function h.filter(t, f, dict) + local nt = {} + for k,v in pairs(t) do + if not f(v) then goto continue end + if dict then + nt[k] = v + else + table.insert(nt, v) + end + ::continue:: + end + return nt +end + +-- This is taken from http://lua-users.org/wiki/SortedIteration +-- This version is stripped of comments and empty lines + some stuff is renamed + +local function __gen_oindex( t ) + local oindex = {} + for key in pairs(t) do + table.insert(oindex, key) + end + table.sort(oindex) + return oindex +end + +local function onext(t, state) + local key = nil + if state == nil then + t.__oindex = __gen_oindex(t) + key = t.__oindex[1] + else + for i = 1,#t.__oindex do + if t.__oindex[i] == state then + key = t.__oindex[i+1] + end + end + end + if key then + return key, t[key] + end + t.__oindex = nil +end + +function h.opairs(t) + return onext, t, nil +end + +-- markup + +function h.markup_fg(color, text) + return "" .. text .. "" +end + +function h.markup_bg(color, text) + return "" .. text .. "" +end + +-- ui + +function h.font(factor) + return vars.text_font .. " " .. vars.font_size * (factor or 1) +end + +function h.symbol_font(factor) + return vars.symbol_font .. " " .. vars.font_size * (factor or 1) +end + +function h.styled(target) + return gears.table.crush({ + bg = vars.colors.bg, + border_color = vars.colors.bright.black, + border_width = vars.border_width, + shape = vars.shape + }, target) +end + +function h.popup(args) + args.widget = { + widget = wibox.container.margin, + margins = vars.big_padding, + args.widget + } + + return awful.popup(h.styled(args)) +end + +function h.tooltip(objects, callback) + awful.tooltip(h.styled { + objects = objects, + timer_function = callback, + margin_leftright = vars.padding, + margin_topbottom = vars.padding + }) +end + +return h diff --git a/.config/awesome/misc/init.lua b/.config/awesome/misc/init.lua new file mode 100644 index 0000000..ce17c05 --- /dev/null +++ b/.config/awesome/misc/init.lua @@ -0,0 +1,5 @@ +require "misc.setup" +require "misc.signals" +require "misc.keys" +require "misc.rules" +require "misc.autostart" diff --git a/.config/awesome/misc/keys.lua b/.config/awesome/misc/keys.lua new file mode 100644 index 0000000..6d83ec4 --- /dev/null +++ b/.config/awesome/misc/keys.lua @@ -0,0 +1,318 @@ +local awful = require "awful" +local gears = require "gears" +local naughty = require "naughty" +local cfg = require "misc.cfg" +local insightful = require "ui.insightful" +local archaic = require "ui.archaic" +local fresnel = require "ui.fresnel" +local vars = require "misc.vars" +local btn = awful.button.names + +local recording = { false, "" } + +client.connect_signal("request::default_mousebindings", function() + awful.mouse.append_client_mousebindings { + insightful:bind { + mods = {}, + triggers = btn.LEFT, + press = function (c) + c:activate { + context = "mouse_click" + } + end, + group = "client", + desc = "raise client" + }, + insightful:bind { + mods = vars.mods.M, + triggers = btn.LEFT, + press = function (c) + c:activate { + context = "mouse_click", + action = "mouse_move" + } + end, + group = "client", + desc = "move client" + }, + insightful:bind { + mods = vars.mods.M, + triggers = btn.RIGHT, + press = function (c) + c:activate { + context = "mouse_click", + action = "mouse_resize" + } + end, + group = "client", + desc = "resize client" + } + } +end) + +local globalkeys = gears.table.join( + insightful:bind { + mods = vars.mods.MC, + triggers = "r", + press = awesome.restart, + group = "awesome", + desc = "restart awesome" + }, + insightful:bind { + mods = vars.mods.MC, + triggers = "s", + press = function() + insightful:toggle() + end, + group = "awesome", + desc = "toggle insightful" + }, + insightful:bind { + mods = vars.mods.MC, + triggers = "a", + press = function() + archaic:toggle() + end, + group = "awesome", + desc = "toggle notification center" + }, + insightful:bind { + mods = vars.mods.M, + triggers = " ", + press = function() + fresnel:show() + end, + group = "awesome", + desc = "toggle fresnel" + }, + + insightful:bind { + mods = {}, + triggers = "XF86AudioMute", + press = function() + awful.spawn("wpctl set-mute @DEFAULT_SINK@ toggle") + end, + group = "audio", + desc = "mute" + }, + insightful:bind { + mods = {}, + triggers = { + { "XF86AudioRaiseVolume", true }, + { "XF86AudioLowerVolume", false } + }, + press = function(up) + if up then + awful.spawn("wpctl set-volume @DEFAULT_SINK@ 5%+") + else + awful.spawn("wpctl set-volume @DEFAULT_SINK@ 5%-") + end + end, + group = "audio", + desc = "increase/decrease volume" + }, + insightful:bind { + mods = {}, + triggers = { + { "XF86AudioNext", true }, + { "XF86AudioPrev", false } + }, + press = function(next) + if next then + archaic.playerctl:next() + else + archaic.playerctl:previous() + end + end, + group = "audio", + desc = "previous/next song" + }, + insightful:bind { + mods = {}, + triggers = "XF86AudioPlay", + press = function() + archaic.playerctl:play_pause() + end, + group = "audio", + desc = "(un)pause song" + }, + + insightful:bind { + mods = {}, + triggers = { + { "XF86MonBrightnessUp", true }, + { "XF86MonBrightnessDown", false } + }, + press = function(up) + if up then + awful.spawn("brightnessctl set +51") + else + awful.spawn("brightnessctl set 51-") + end + end, + group = "brightness", + desc = "increase/decrease brightness" + }, + + insightful:bind { + mods = vars.mods.M, + triggers = "Return", + press = function() + awful.spawn(cfg.terminal) + end, + group = "launcher", + desc = "launch terminal" + }, + + insightful:bind { + mods = vars.mods.MC, + triggers = "q", + press = function() + local c = client.focus + if c then + c:kill() + end + end, + group = "client", + desc = "close" + }, + insightful:bind { + mods = vars.mods.M, + triggers = "m", + press = function() + local c = client.focus + if c then + c.maximized = not c.maximized + end + end, + group = "client", + desc = "(un)maximize" + }, + insightful:bind { + mods = vars.mods.M, + triggers = "n", + press = function() + local c = client.focus + if c then + gears.timer.delayed_call(function() + c.minimized = true + end) + end + end, + group = "client", + desc = "minimize" + }, + insightful:bind { + mods = vars.mods.M, + triggers = "f", + press = function() + local c = client.focus + if c then + c.fullscreen = not c.fullscreen + end + end, + group = "client", + desc = "toggle fullscreen" + }, + + insightful:bind { + mods = {}, + triggers = "Print", + press = function() + local date = os.date("%Y%m%d_%H%M%S") + local path = os.getenv("HOME") .. "/Pictures/" .. date .. ".png" + + awful.spawn.with_shell("maim --hidecursor " .. path .. " && xclip -selection clipboard -t image/png " .. path) + naughty.notification { + app_name = "Maim", + title = "Screenshot taken", + message = "Saved at " .. path + } + end, + group = "screenshot", + desc = "take fullscreen screenshot" + }, + insightful:bind { + mods = vars.mods.S, + triggers = "Print", + press = function() + local date = os.date("%Y%m%d_%H%M%S") + local path = os.getenv("HOME") .. "/Pictures/" .. date .. ".png" + + awful.spawn.with_shell("maim --hidecursor -s " .. path .. " && xclip -selection clipboard -t image/png " .. path .. [[ && notify-send -a "Maim" "Screenshot taken" "Saved at ]] .. path .. [["]]) + -- naughty.notification { + -- app_name = "Maim",r + -- title = "Screenshot taken", + -- message = "Saved at " .. path + -- } + end, + group = "screenshot", + desc = "take region screenshot" + }, + + insightful:bind { + mods = vars.mods.M, + triggers = "Print", + press = function() + if recording[1] then + awful.spawn("giph --stop") + naughty.notification { + app_name = "Giph", + title = "Recording stopped", + message = "Saved at " .. recording[2] + } + recording[1] = false + recording[2] = "" + else + recording[1] = true + recording[2] = os.getenv("HOME") .. "/Videos/" .. os.date("%Y%m%d_%H%M%S") .. ".mp4" + awful.spawn("giph --format mp4 --framerate 30 " .. recording[2]) + naughty.notification { + app_name = "Giph", + title = "Recording started" + } + end + end, + group = "video", + desc = "toggle recording" + }, + + insightful:bind { + mods = vars.mods.M, + triggers = "k", + press = function() + awful.spawn("xkblayout-state set +1") + end, + group = "keyboard", + desc = "next keyboard layout" + }, + insightful:bind { + mods = vars.mods.MS, + triggers = "k", + press = function() + awful.spawn("xkblayout-state set -1") + end, + group = "keyboard", + desc = "previous keyboard layout" + }, + + insightful:bind { + mods = vars.mods.M, + triggers = "Up", + press = awful.tag.viewprev, + group = "tag", + desc = "switch to previous" + }, + insightful:bind { + mods = vars.mods.M, + triggers = "Down", + press = awful.tag.viewnext, + group = "tag", + desc = "switch to next" + } +) + +-- gears.debug.dump(insightful:bind.hottriggerss) + +root.keys(globalkeys) + diff --git a/.config/awesome/misc/rules.lua b/.config/awesome/misc/rules.lua new file mode 100644 index 0000000..803d49a --- /dev/null +++ b/.config/awesome/misc/rules.lua @@ -0,0 +1,103 @@ +local ruled = require "ruled" +local beautiful = require "beautiful" +local awful = require "awful" +local vars = require "misc.vars" + +ruled.client.connect_signal("request::rules", function() + ruled.client.append_rule({ + id = "global", + rule = {}, + properties = { + border_width = beautiful.border_width, + border_color = beautiful.border_normal, + focus = awful.client.focus.filter, + raise = true, + screen = awful.screen.preferred, + placement = awful.placement.centered+awful.placement.no_offscreen, + floating = false, + -- shape = vars.shape, + honor_padding = true + -- tag = "1" + } + }) + + ruled.client.append_rule({ + id = "titlebars", + rule_any = { + type = { + "normal", + "dialog" + } + }, + properties = { + titlebars_enabled = true + } + }) + + ruled.client.append_rule({ + id = "pip", + rule = { + name = "Picture-in-Picture" + }, + properties = { + ontop = true + } + }) + + ruled.client.append_rule({ + id = "browser_tag", + rule_any = { + class = { "firefox" } + }, + properties = { + screen = 1, + tag = screen[1].tags[2] + } + }) + + ruled.client.append_rule({ + id = "chat_tag", + rule_any = { + class = { "discord" } + }, + properties = { + screen = 1, + tag = screen[1].tags[3] + } + }) + + + ruled.client.append_rule({ + id = "music_tag", + rule_any = { + class = { "Spotify" } + }, + properties = { + screen = 1, + tag = screen[1].tags[4], + titlebars_enabled = false + } + }) + + ruled.client.append_rule({ + id = "code_tag", + rule_any = { + class = { "lite-xl", "code_term" } + }, + properties = { + screen = 1, + tag = screen[1].tags[5] + } + }) + + ruled.client.append_rule({ + id = "steam", + rule_any = { + class = { "Steam" } + }, + properties = { + screen = 1, + tag = screen[1].tags[6] + } + }) +end) diff --git a/.config/awesome/misc/setup.lua b/.config/awesome/misc/setup.lua new file mode 100644 index 0000000..aeee19a --- /dev/null +++ b/.config/awesome/misc/setup.lua @@ -0,0 +1,65 @@ +local naughty = require "naughty" +local beautiful = require "beautiful" +-- local notif_overlay = require "ui.notifs" +local wicked = require "ui.wicked" +local awful = require "awful" +local rubato = require "lib.rubato" +local vars = require "misc.vars" + +-- naughty.connect_signal("request::display", function(n) +-- notif_overlay:notify(n) +-- end) + +naughty.connect_signal("request::display", function(n) + naughty.layout.box { + notification = n, + placement = function(d) + return awful.placement.right(d, { + margins = beautiful.useless_gap * 2 + }) + end + } + + -- wicked:.notify(n) +end) + +naughty.connect_signal("request::display_error", function(message, startup) + naughty.notification { + urgency = "critical", + title = "Oops, an error happened"..(startup and " during startup!" or "!"), + message = message + } +end) + +-- Taken from https://www.reddit.com/r/awesomewm/comments/syjolb/comment/hy0xy35/ + +awesome.connect_signal('exit', function(reason_restart) + if not reason_restart then return end + + local file = io.open('/tmp/awesomewm-last-selected-tags', 'w+') + + for s in screen do + file:write(s.selected_tag.index, '\n') + end + + file:close() +end) + +awesome.connect_signal('startup', function() + local file = io.open('/tmp/awesomewm-last-selected-tags', 'r') + if not file then return end + + local selected_tags = {} + + for line in file:lines() do + table.insert(selected_tags, tonumber(line)) + end + + for s in screen do + local i = selected_tags[s.index] + local t = s.tags[i] + t:view_only() + end + + file:close() +end) diff --git a/.config/awesome/misc/signals.lua b/.config/awesome/misc/signals.lua new file mode 100644 index 0000000..a65ca43 --- /dev/null +++ b/.config/awesome/misc/signals.lua @@ -0,0 +1,89 @@ +local vars = require "misc.vars" +local awful = require "awful" +local rectangle = require "gears.shape".rectangle +local bling = require "lib.bling" + +client.connect_signal("property::name", function(c) + local out = io.popen("readlink /proc/" .. c.pid .. "/exe") + local name = c.name + if out ~= nil then + name = out:read("*a"):sub(0, -2):match("[^\\/]+$") or name + end + c.name = string.lower(name) +end) + +client.connect_signal("request::manage", function (c) + c.shape = vars.shape + if c.maximized then + c.maximized = false + c.maximized = true + end +end) + +local function handle_corners(c) + if c.maximized then + c.shape = rectangle + c.border_width = 0 + else + c.shape = vars.shape + c.border_width = vars.border_width + end +end + +client.connect_signal("property::maximized", handle_corners) +client.connect_signal("property::fullscreen", handle_corners) + +screen.connect_signal("request::desktop_decoration", function(s) + awful.tag.add( + "1", + { + screen = s, + layout = awful.layout.suit.floating, + selected = true + } + ) + + awful.tag.add( + "2", + { + screen = s, + layout = awful.layout.suit.floating, + + } + ) + + awful.tag.add( + "3", + { + screen = s, + layout = awful.layout.suit.tile.left, + master_width_factor = 0.7 + } + ) + + awful.tag.add( + "4", + { + screen = s, + layout = awful.layout.suit.tile.top, + master_width_factor = 0.2 + } + ) + + awful.tag.add( + "5", + { + screen = s, + layout = awful.layout.suit.tile.right, + master_width_factor = 0.7 + } + ) + + awful.tag.add( + "6", + { + screen = s, + layout = awful.layout.suit.floating, + } + ) +end) diff --git a/.config/awesome/misc/vars.lua b/.config/awesome/misc/vars.lua new file mode 100644 index 0000000..7a5f9c8 --- /dev/null +++ b/.config/awesome/misc/vars.lua @@ -0,0 +1,81 @@ +local gears = require "gears" +local xresources = require "beautiful.xresources" +local x_col = xresources.get_current_theme() +local dpi = xresources.apply_dpi +local wibox = require "wibox" + +local v = {} + +v.notif_timeout = 3 + +v.anim_duration = 0.15 +v.anim_intro = v.anim_duration / 2 + +function v.shape(cr,w,h) + gears.shape.rounded_rect(cr,w,h,dpi(4)) +end + +v.border_width = dpi(1.5) + +v.padding = dpi(4) +v.big_padding = dpi(8) + +v.text_font = "Fira Code Nerd Font Mono Medium" +v.symbol_font = "Symbols Nerd Font:style=1000-em" +v.font_size = 8 +v.font = v.text_font .. " " .. v.font_size + +local char_width, char_height = wibox.widget { + widget = wibox.widget.textbox, + text = "a" +}:get_preferred_size_at_dpi(screen[1].dpi) + +v.char_height = char_height +v.char_width = char_width + +v.bar_size = dpi(16) + +v.button_size = dpi(12) + +v.colors = { + fg = x_col.foreground, + bg = x_col.background, + + black = x_col.color0, + red = x_col.color1, + green = x_col.color2, + yellow = x_col.color3, + blue = x_col.color4, + pink = x_col.color5, + cyan = x_col.color6, + white = x_col.color7, + + bright = { + black = x_col.color8, + red = x_col.color9, + green = x_col.color10, + yellow = x_col.color11, + blue = x_col.color12, + pink = x_col.color13, + cyan = x_col.color14, + white = x_col.color15, + }, + + dim = { + fg = "#8893a5", + bg = "#20262e" + } +} + +-- taken from https://github.com/bew/dotfiles/blob/ab9bb1935783f7a31ef777b1d7e26d53f35df864/gui/wezterm/cfg_utils.lua +v.mods = setmetatable({ _SHORT_MAP = { C = "Control", S = "Shift", A = "Mod1", M = "Mod4" } }, { + __index = function(self, key) + local resolved_mods = {} + for i = 1, #key do + resolved_mods[i] = self._SHORT_MAP[key:sub(i, i)] + end + return resolved_mods + end +}) + +return v -- cgit v1.2.3