♻️ refactor(awesome): Small fixes

This commit is contained in:
punkfairie 2024-02-24 11:14:40 -08:00
parent aa883fbe22
commit 59016fb63b
9 changed files with 113 additions and 45 deletions

View file

@ -7,7 +7,7 @@ M.keys = {
M.apps = {
terminal = "wezterm",
launcher = "rofi -no-lazy-grab -show drun -theme ~/.config/rofi/launcher.rasi",
launcher = "rofi -show drun -theme ~/.config/rofi/launcher.rasi",
browser = "firefox",
file_manager = "thunar",
editor = os.getenv("EDITOR") or "nvim",

View file

@ -7,10 +7,14 @@ local capi = { mouse = mouse }
local _ui = {}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.colorize_text(text, color)
return "<span foreground='" .. color .. "'>" .. text .. "</span>"
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.add_hover_cursor(w, hover_cursor)
local original_cursor = "left_ptr"
@ -29,6 +33,8 @@ function _ui.add_hover_cursor(w, hover_cursor)
end)
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.vertical_pad(height)
return wibox.widget({
forced_height = height,
@ -36,6 +42,8 @@ function _ui.vertical_pad(height)
})
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.horizontal_pad(width)
return wibox.widget({
forced_width = width,
@ -43,6 +51,8 @@ function _ui.horizontal_pad(width)
})
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.rrect(radius)
return function(cr, width, height)
gshape.rounded_rect(cr, width, height, radius)
@ -55,18 +65,24 @@ function _ui.pie(width, height, start_angle, end_angle, radius)
end
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.prgram(height, base)
return function(cr, width)
gshape.parallelogram(cr, width, height, base)
end
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.prrect(radius, tl, tr, br, bl)
return function(cr, width, height)
gshape.partially_rounded_rect(cr, width, height, tl, tr, br, bl, radius)
end
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.custom_shape(cr, width, height)
cr:move_to(0, height / 25)
cr:line_to(height / 25, 0)
@ -77,6 +93,8 @@ function _ui.custom_shape(cr, width, height)
cr:close_path()
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
local function _get_widget_geometry(_hierarchy, widget)
local width, height = _hierarchy:get_size()
if _hierarchy:get_widget() == widget then
@ -97,6 +115,8 @@ function _ui.get_widget_geometry(_wibox, widget)
return _get_widget_geometry(_wibox._drawable._widget_hierarchy, widget)
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.screen_mask(s, bg)
local mask = wibox({
visible = false,
@ -109,6 +129,8 @@ function _ui.screen_mask(s, bg)
return mask
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _ui.grouping_widget(w1, w2, dpi1)
local container = wibox.widget({
w1,
@ -125,4 +147,6 @@ function _ui.grouping_widget(w1, w2, dpi1)
return container
end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
return _ui

View file

@ -63,18 +63,10 @@ local instance = nil
local ANIMATION_FRAME_DELAY = 5
local function micro_to_milli(micro)
return micro / 1000
end
local function second_to_micro(sec)
return sec * 1000000
end
local function second_to_milli(sec)
return sec * 1000
end
function animation:start(args)
args = args or {}
@ -122,8 +114,8 @@ function animation:stop()
self:emit_signal("stopped")
end
function animation:abort(reset)
animation:stop(reset)
function animation:abort()
animation:stop()
self:emit_signal("aborted")
end
@ -183,6 +175,7 @@ local function new()
ret._private.instant = false
GLib.timeout_add(GLib.PRIORITY_DEFAULT, ANIMATION_FRAME_DELAY, function()
---@diagnostic disable-next-line: redefined-local
for index, animation in ipairs(ret._private.animations) do
if animation.state == true then
-- compute delta time

View file

@ -1,22 +1,24 @@
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful").get()
local dpi = require("beautiful.xresources").apply_dpi
local beautiful = require("beautiful")
local helpers = require("helpers")
local dpi = beautiful.xresources.apply_dpi
local theme = beautiful.get()
--- Minimalist Exit Screen
--- ~~~~~~~~~~~~~~~~~~~~~~
--- Icons
local icon_font = beautiful.font_name .. "bold 45"
local icon_font = theme.font_name .. "bold 45"
local poweroff_text_icon = ""
local reboot_text_icon = ""
local suspend_text_icon = ""
local exit_text_icon = "󰗼"
local lock_text_icon = ""
local button_bg = beautiful.xcolorbase
local button_bg = theme.xcolorbase
local button_size = dpi(120)
--- Commands
@ -50,7 +52,7 @@ local create_button = function(symbol, hover_color, _, command)
align = "center",
valign = "center",
font = icon_font,
markup = helpers.ui.colorize_text(symbol, beautiful.xcolorS0),
markup = helpers.ui.colorize_text(symbol, theme.xcolorS0),
widget = wibox.widget.textbox(),
})
@ -64,8 +66,8 @@ local create_button = function(symbol, hover_color, _, command)
forced_height = button_size,
forced_width = button_size,
border_width = dpi(8),
border_color = beautiful.xcolorS0,
shape = helpers.ui.rrect(beautiful.border_width * 2),
border_color = theme.xcolorS0,
shape = helpers.ui.rrect(theme.border_width * 2),
bg = button_bg,
widget = wibox.container.background,
})
@ -79,8 +81,8 @@ local create_button = function(symbol, hover_color, _, command)
button.border_color = hover_color
end)
button:connect_signal("mouse::leave", function()
icon.markup = helpers.ui.colorize_text(icon.text, beautiful.xcolorS0)
button.border_color = beautiful.xcolorS0
icon.markup = helpers.ui.colorize_text(icon.text, theme.xcolorS0)
button.border_color = theme.xcolorS0
end)
helpers.ui.add_hover_cursor(button, "hand1")
@ -89,11 +91,11 @@ local create_button = function(symbol, hover_color, _, command)
end
--- Create the buttons
local poweroff = create_button(poweroff_text_icon, beautiful.xcolor10, "Poweroff", poweroff_command)
local reboot = create_button(reboot_text_icon, beautiful.xcolor6, "Reboot", reboot_command)
local suspend = create_button(suspend_text_icon, beautiful.xcolor8, "Suspend", suspend_command)
local exit = create_button(exit_text_icon, beautiful.xcolor2, "Exit", exit_command)
local lock = create_button(lock_text_icon, beautiful.xcolor12, "Lock", lock_command)
local poweroff = create_button(poweroff_text_icon, theme.xcolor10, "Poweroff", poweroff_command)
local reboot = create_button(reboot_text_icon, theme.xcolor6, "Reboot", reboot_command)
local suspend = create_button(suspend_text_icon, theme.xcolor8, "Suspend", suspend_command)
local exit = create_button(exit_text_icon, theme.xcolor2, "Exit", exit_command)
local lock = create_button(lock_text_icon, theme.xcolor12, "Lock", lock_command)
local create_exit_screen = function(s)
s.exit_screen = wibox({
@ -101,8 +103,8 @@ local create_exit_screen = function(s)
type = "splash",
visible = false,
ontop = true,
bg = beautiful.transparent,
fg = beautiful.fg_normal,
bg = theme.transparent,
fg = theme.fg_normal,
height = s.geometry.height,
width = s.geometry.width,
x = s.geometry.x,

View file

@ -11,7 +11,9 @@ local keys = config.keys
-- General awesome keybindings
awful.keyboard.append_global_keybindings({
awful.key({ keys.mod, "Control" }, "r", awesome.restart, { description = "reload awesome", group = "awesome" }),
awful.key({ keys.mod, "Shift" }, "q", awesome.quit, { description = "quit awesome", group = "awesome" }),
awful.key({ keys.mod, "Control", "Shift" }, "x", function()
awful.prompt.run({
prompt = "Run Lua code: ",
@ -20,12 +22,15 @@ awful.keyboard.append_global_keybindings({
history_path = awful.util.get_cache_dir() .. "/history_eval",
})
end, { description = "lua execute prompt", group = "awesome" }),
awful.key({ keys.mod }, "Return", function()
awful.spawn(apps.terminal)
end, { description = "open a terminal", group = "launcher" }),
awful.key({ keys.mod, "Shift" }, "c", function()
menu.mainmenu:show()
end, { description = "show main menu", group = "awesome" }),
awful.key({ keys.mod }, "p", function()
menubar.show()
end, { description = "show the menubar", group = "launcher" }),
@ -34,8 +39,11 @@ awful.keyboard.append_global_keybindings({
-- Tag bindings
awful.keyboard.append_global_keybindings({
awful.key({ keys.mod, "Control" }, "s", hotkeys_popup.show_help, { description = "show help", group = "awesome" }),
awful.key({ keys.mod }, "Left", awful.tag.viewprev, { description = "view previous", group = "tag" }),
awful.key({ keys.mod }, "Right", awful.tag.viewnext, { description = "view next", group = "tag" }),
awful.key({ keys.mod }, "Tab", awful.tag.history.restore, { description = "go back", group = "tag" }),
})
@ -53,6 +61,7 @@ awful.keyboard.append_global_keybindings({
end
end,
}),
awful.key({
modifiers = { keys.mod, "Control" },
keygroup = "numrow",
@ -66,6 +75,7 @@ awful.keyboard.append_global_keybindings({
end
end,
}),
awful.key({
modifiers = { keys.mod, "Shift" },
keygroup = "numrow",
@ -80,6 +90,7 @@ awful.keyboard.append_global_keybindings({
end
end,
}),
awful.key({
modifiers = { keys.mod, "Control", "Shift" },
keygroup = "numrow",
@ -94,6 +105,7 @@ awful.keyboard.append_global_keybindings({
end
end,
}),
awful.key({
modifiers = { keys.mod },
keygroup = "numpad",
@ -113,21 +125,26 @@ awful.keyboard.append_global_keybindings({
awful.key({ keys.mod }, "c", function()
awful.client.focus.byidx(1)
end, { description = "focus next by index", group = "client" }),
awful.key({ keys.mod }, "x", function()
awful.client.focus.byidx(-1)
end, { description = "focus previous by index", group = "client" }),
awful.key({ keys.mod }, "Escape", function()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end, { description = "go back", group = "client" }),
awful.key({ keys.mod, "Control" }, "j", function()
awful.screen.focus_relative(1)
end, { description = "focus the next screen", group = "screen" }),
awful.key({ keys.mod, "Control" }, "k", function()
awful.screen.focus_relative(-1)
end, { description = "focus the previous screen", group = "screen" }),
awful.key({ keys.mod, "Control" }, "n", function()
local c = awful.client.restore()
-- Focus restored client
@ -142,36 +159,46 @@ awful.keyboard.append_global_keybindings({
awful.key({ keys.mod, "Shift" }, "j", function()
awful.client.swap.byidx(1)
end, { description = "swap with next client by index", group = "client" }),
awful.key({ keys.mod, "Shift" }, "k", function()
awful.client.swap.byidx(-1)
end, { description = "swap with previous client by index", group = "client" }),
awful.key(
{ keys.mod },
"u",
awful.client.urgent.jumpto,
{ description = "jump to urgent client", group = "client" }
),
awful.key({ keys.mod }, "l", function()
awful.tag.incmwfact(0.05)
end, { description = "increase master width factor", group = "layout" }),
awful.key({ keys.mod }, "h", function()
awful.tag.incmwfact(-0.05)
end, { description = "decrease master width factor", group = "layout" }),
awful.key({ keys.mod, "Shift" }, "h", function()
awful.tag.incnmaster(1, nil, true)
end, { description = "increase the number of master clients", group = "layout" }),
awful.key({ keys.mod, "Shift" }, "l", function()
awful.tag.incnmaster(-1, nil, true)
end, { description = "decrease the number of master clients", group = "layout" }),
awful.key({ keys.mod, "Control" }, "h", function()
awful.tag.incncol(1, nil, true)
end, { description = "increase the number of columns", group = "layout" }),
awful.key({ keys.mod, "Control" }, "l", function()
awful.tag.incncol(-1, nil, true)
end, { description = "decrease the number of columns", group = "layout" }),
awful.key({ keys.mod }, "-", function()
machi.default_editor.start_interactive()
end, { description = "edit the current layout if it is a machi layout", group = "layout" }),
awful.key({ keys.mod }, ".", function()
machi.switcher.start(client.focus)
end, { description = "switch between windows for a machi layout", group = "layout" }),
@ -184,37 +211,46 @@ client.connect_signal("request::default_keybindings", function()
c.fullscreen = not c.fullscreen
c:raise()
end, { description = "toggle fullscreen", group = "client" }),
awful.key({ keys.mod }, "w", function(c)
c:kill()
end, { description = "close", group = "client" }),
awful.key(
{ keys.mod, "Control" },
"space",
awful.client.floating.toggle,
{ description = "toggle floating", group = "client" }
),
awful.key({ keys.mod, "Control" }, "Return", function(c)
c:swap(awful.client.getmaster())
end, { description = "move to master", group = "client" }),
awful.key({ keys.mod }, "o", function(c)
c:move_to_screen()
end, { description = "move to screen", group = "client" }),
awful.key({ keys.mod }, "t", function(c)
c.ontop = not c.ontop
end, { description = "toggle keep on top", group = "client" }),
awful.key({ keys.mod }, "n", function(c)
-- The client currently has the input focus, so it cannot be
-- minimized, since minimized clients can't have the focus.
c.minimized = true
end, { description = "minimize", group = "client" }),
awful.key({ keys.mod }, "m", function(c)
c.maximized = not c.maximized
c:raise()
end, { description = "(un)maximize", group = "client" }),
awful.key({ keys.mod, "Control" }, "m", function(c)
c.maximized_vertical = not c.maximized_vertical
c:raise()
end, { description = "(un)maximize vertically", group = "client" }),
awful.key({ keys.mod, "Shift" }, "m", function(c)
c.maximized_horizontal = not c.maximized_horizontal
c:raise()
@ -227,7 +263,9 @@ awful.mouse.append_global_mousebindings({
awful.button({}, 3, function()
menu.mainmenu:toggle()
end),
awful.button({}, 4, awful.tag.viewprev),
awful.button({}, 5, awful.tag.viewnext),
})
@ -236,9 +274,11 @@ client.connect_signal("request::default_mousebindings", function()
awful.button({}, 1, function(c)
c:activate({ context = "mouse_click" })
end),
awful.button({ keys.mod }, 1, function(c)
c:activate({ context = "mouse_click", action = "mouse_move" })
end),
awful.button({ keys.mod }, 3, function(c)
c:activate({ context = "mouse_click", action = "mouse_resize" })
end),

View file

@ -1,33 +1,41 @@
local awful = require("awful")
local volume = require("ui.popups.volume")
local filesystem = require("gears.filesystem")
local config = require("config")
local keys = config.keys
local config_dir = filesystem.get_configuration_dir()
local utils_dir = config_dir .. "utilities/"
local keys = require("config").keys
local screenshot_area = utils_dir .. "screensht area"
local screenshot_full = utils_dir .. "screensht full"
awful.keyboard.append_global_keybindings({
awful.key({ keys.mod }, "r", function()
awful.spawn("rofi -show drun -theme ~/.config/rofi/launcher.rasi")
awful.spawn(config.apps.launcher)
end, { description = "show rofi", group = "launcher" }),
awful.key({ keys.mod }, "Print", function()
awful.spawn.easy_async_with_shell(screenshot_area, function() end)
end, { description = "take a area screenshot", group = "Utils" }),
awful.key({}, "Print", function()
awful.spawn.easy_async_with_shell(screenshot_full, function() end)
end, { description = "take a full screenshot", group = "Utils" }),
awful.key({ keys.mod }, "q", function()
awesome.emit_signal("module::exit_screen:show")
end, { description = "show Exit Screen", group = "Utils" }),
awful.key({ keys.mod }, "s", function()
awesome.emit_signal("scratchpad::toggle")
end, { description = "show Scratchpad", group = "Utils" }),
awful.key({ keys.mod }, "b", function()
awful.spawn.easy_async_with_shell("headsetcontrol -l 0", function() end)
end, { description = "headsetcontrol", group = "Utils" }),
awful.key({ keys.mod }, "t", function()
awful.titlebar.toggle(client.focus)
end, { description = "toggle titlebar for active client", group = "Utils" }), -- Toggle titlebar
@ -40,11 +48,13 @@ awful.keyboard.append_global_keybindings({
awesome.emit_signal("widget::update_vol")
awesome.emit_signal("module::volume_osd:show", true)
end),
awful.key({}, "XF86AudioLowerVolume", function()
volume.decrease()
awesome.emit_signal("widget::update_vol")
awesome.emit_signal("module::volume_osd:show", true)
end),
awful.key({}, "XF86AudioMute", function()
volume.mute()
awesome.emit_signal("widget::update_vol")

View file

@ -1,8 +1,8 @@
-- require("main.error_handling")
require("main.layout")
require("main.menu")
require("main.wallpaper")
require("main.bindings")
require("main.custom_bindings")
require("main.rules")
require("main.tags")
require(... .. ".layout")
require(... .. ".menu")
require(... .. ".wallpaper")
require(... .. ".bindings")
require(... .. ".custom_bindings")
require(... .. ".rules")
require(... .. ".tags")

View file

@ -1,6 +1,5 @@
---@diagnostic disable: undefined-global
local awful = require("awful")
local beautiful = require("beautiful").get()
local theme = require("beautiful").get()
local gears = require("gears")
local wibox = require("wibox")
local helpers = require("helpers")
@ -16,7 +15,7 @@ rofi.timer = gears.timer({
timeout = 0.1,
single_shot = true,
callback = function()
awful.spawn("rofi -show drun -theme ~/.config/rofi/launcher.rasi")
awful.spawn(apps.launcher)
end,
})
@ -77,10 +76,10 @@ menu.mainmenu = awful.menu({
-- apply rounded corners to menus when picom isn't available, thanks to u/signalsourcesexy
-- also applies antialiasing! - By me.
menu.mainmenu.wibox.shape = helpers.ui.rrect(10)
menu.mainmenu.wibox.bg = beautiful.bg_normal .. "00"
menu.mainmenu.wibox.bg = theme.bg_normal .. "00"
menu.mainmenu.wibox:set_widget(wibox.widget({
menu.mainmenu.wibox.widget,
bg = beautiful.bg_normal,
bg = theme.bg_normal,
shape = helpers.ui.rrect(0),
widget = wibox.container.background,
}))
@ -94,11 +93,11 @@ function awful.menu.new(...)
local ret = awful.menu.original_new(...)
ret.wibox.shape = helpers.ui.rrect(10)
ret.wibox.bg = beautiful.bg_normal .. "00"
ret.wibox.bg = theme.bg_normal .. "00"
ret.wibox:set_widget(wibox.widget({
ret.wibox.widget,
widget = wibox.container.background,
bg = beautiful.xcolorbase,
bg = theme.xcolorbase,
shape = helpers.ui.rrect(0),
}))

View file

@ -45,7 +45,7 @@ ruled.client.connect_signal("request::rules", function()
ruled.client.append_rule({
rule = { instance = "bf1.exe" },
properties = { shape = helpers.ui.rrect(0), fullscreen = true, tag = "", switchtotag = true },
properties = { shape = helpers.ui.rrect(0), fullscreen = true, tag = "󰍹", switchtotag = true },
})
ruled.client.append_rule({
rule = { instance = "wine" },