From a7e4a1214faa21a700adbe7f6db7423a7fe393d5 Mon Sep 17 00:00:00 2001 From: Kievits Rene Date: Tue, 19 Apr 2022 18:35:56 +0200 Subject: [PATCH] reworked Get_icon and some other fixes --- .vscode/settings.json | 4 +- awesome/crylia_bar/dock.lua | 131 +++++++++++++++------------ awesome/crylia_bar/init.lua | 2 +- awesome/mappings/global_keys.lua | 12 +-- awesome/rc.lua | 3 +- awesome/src/modules/powermenu.lua | 7 +- awesome/src/modules/titlebar.lua | 72 --------------- awesome/src/theme/user_variables.lua | 36 ++++---- awesome/src/tools/icon_handler.lua | 99 +++++++++++++------- awesome/src/widgets/audio.lua | 3 +- awesome/src/widgets/power.lua | 1 - 11 files changed, 171 insertions(+), 199 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 589b6c6..39bc7da 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,8 @@ "client", "screen", "mouse", - "double_click_timer" + "double_click_timer", + "vim", + "lspSymbol" ] } diff --git a/awesome/crylia_bar/dock.lua b/awesome/crylia_bar/dock.lua index 9553e46..80a4619 100644 --- a/awesome/crylia_bar/dock.lua +++ b/awesome/crylia_bar/dock.lua @@ -10,60 +10,22 @@ local wibox = require("wibox") return function(screen, programs) - local function create_dock_element(program, name, is_steam, size) + local function create_dock_element(class, program, name, is_steam, size) + if program == nil or class == nil then + return + end is_steam = is_steam or false - if program:match("com.*%a.Client") ~= nil then - program = program:gsub("com.", ""):gsub(".Client", ""):gsub("flatpak", ""):gsub("run", ""):gsub(" ", "") - end - - local function create_indicator() - local col = "#fff" - local indicators = { layout = wibox.layout.flex.horizontal, spacing = dpi(5) } - for i, c in ipairs(client.get()) do - if string.lower(c.class):match(program or name) then - if c == client.focus then - col = color["YellowA200"] - elseif c.urgent then - col = color["RedA200"] - elseif c.maximized then - col = color["GreenA200"] - elseif c.minimized then - col = color["BlueA200"] - elseif c.fullscreen then - col = color["PinkA200"] - else - col = color["Grey600"] - end - local indicator = wibox.widget { - widget = wibox.container.background, - shape = gears.shape.rounded_rect, - forced_height = dpi(3), - spacing_widget = dpi(5), - spacing = dpi(5), - bg = col - } - indicators[i] = indicator - end - end - return indicators - end - local dock_element = wibox.widget { { { { - { - resize = true, - forced_width = size, - forced_height = size, - image = Get_icon(user_vars.icon_theme, program, is_steam), - widget = wibox.widget.imagebox, - id = "icon" - }, - create_indicator(), - layout = wibox.layout.align.vertical, - id = "dock_layout" + resize = true, + forced_width = size, + forced_height = size, + image = Get_icon(user_vars.icon_theme, nil, program, class, is_steam), + widget = wibox.widget.imagebox, + id = "icon" }, margins = dpi(5), widget = wibox.container.margin, @@ -76,7 +38,9 @@ return function(screen, programs) widget = wibox.container.background, id = "background" }, - margins = dpi(5), + top = dpi(5), + left = dpi(5), + right = dpi(5), widget = wibox.container.margin } @@ -140,12 +104,14 @@ return function(screen, programs) local dock_elements = { layout = wibox.layout.fixed.horizontal } for i, p in ipairs(pr) do - dock_elements[i] = create_dock_element(p[1], p[2], p[3], user_vars.dock_icon_size) + dock_elements[i] = create_dock_element(p[1], p[2], p[3], p[4], user_vars.dock_icon_size) end return dock_elements end + local dock_elements = get_dock_elements(programs) + local function get_fake_elements(amount) local fake_elements = { layout = wibox.layout.fixed.horizontal } @@ -160,10 +126,52 @@ return function(screen, programs) return fake_elements end - dock:setup { - get_dock_elements(programs), - layout = wibox.layout.fixed.vertical - } + local function create_incicator_widget(prog) + local container = { layout = wibox.layout.flex.horizontal } + local clients = client.get() + for index, pr in ipairs(prog) do + local indicators = { layout = wibox.layout.flex.horizontal, spacing = dpi(5) } + local col = color["Grey600"] + for i, c in ipairs(clients) do + if string.lower(c.class or c.name):match(string.lower(pr[1]) or string.lower(pr[2])) then + if c == client.focus then + col = color["YellowA200"] + elseif c.urgent then + col = color["RedA200"] + elseif c.maximized then + col = color["GreenA200"] + elseif c.minimized then + col = color["BlueA200"] + elseif c.fullscreen then + col = color["PinkA200"] + else + col = color["Grey600"] + end + indicators[i] = wibox.widget { + widget = wibox.container.background, + shape = gears.shape.rounded_rect, + forced_height = dpi(3), + bg = col, + forced_width = dpi(5), + } + end + end + container[index] = wibox.widget { + indicators, + forced_height = dpi(5), + forced_width = dpi(50), + left = dpi(5), + right = dpi(5), + widget = wibox.container.margin, + } + end + + return wibox.widget { + container, + bottom = dpi(5), + widget = wibox.container.margin, + } + end fakedock:setup { get_fake_elements(#programs), @@ -200,7 +208,8 @@ return function(screen, programs) function() check_for_dock_hide(screen) dock:setup { - get_dock_elements(programs), + dock_elements, + create_incicator_widget(programs), layout = wibox.layout.fixed.vertical } end @@ -211,7 +220,8 @@ return function(screen, programs) function() check_for_dock_hide(screen) dock:setup { - get_dock_elements(programs), + dock_elements, + create_incicator_widget(programs), layout = wibox.layout.fixed.vertical } end @@ -222,7 +232,8 @@ return function(screen, programs) function() check_for_dock_hide(screen) dock:setup { - get_dock_elements(programs), + dock_elements, + create_incicator_widget(programs), layout = wibox.layout.fixed.vertical } end @@ -250,4 +261,10 @@ return function(screen, programs) dock_intelligent_hide:again() end ) + + dock:setup { + get_dock_elements(programs), + create_incicator_widget(programs), + layout = wibox.layout.fixed.vertical + } end diff --git a/awesome/crylia_bar/init.lua b/awesome/crylia_bar/init.lua index a33583e..39a99e5 100644 --- a/awesome/crylia_bar/init.lua +++ b/awesome/crylia_bar/init.lua @@ -54,10 +54,10 @@ awful.screen.connect_for_each_screen( require("crylia_bar.right_bar")(s, {s.battery, s.network, s.bluetooth, s.audio, s.kblayout, s.date, s.clock,s.powerbutton}) end ]] -- Bars + require("crylia_bar.left_bar")(s, { s.layoutlist, s.systray, s.taglist }) require("crylia_bar.center_bar")(s, s.tasklist) require("crylia_bar.right_bar")(s, { s.battery, s.network, s.bluetooth, s.audio, s.kblayout, s.date, s.clock, s.powerbutton }) require("crylia_bar.dock")(s, user_vars.dock_programs) - end ) diff --git a/awesome/mappings/global_keys.lua b/awesome/mappings/global_keys.lua index b397969..cc07b00 100644 --- a/awesome/mappings/global_keys.lua +++ b/awesome/mappings/global_keys.lua @@ -207,7 +207,7 @@ return gears.table.join( {}, "XF86AudioLowerVolume", function(c) - awful.spawn("pactl set-sink-volume @DEFAULT_SINK@ -2%") + awful.spawn.easy_async("pactl set-sink-volume @DEFAULT_SINK@ -2%") awesome.emit_signal("widget::volume") awesome.emit_signal("module::volume_osd:show", true) awesome.emit_signal("module::slider:update") @@ -219,15 +219,7 @@ return gears.table.join( {}, "XF86AudioRaiseVolume", function(c) - awful.spawn.easy_async_with_shell( - [[ pacmd list-sinks | grep "volume: front" | awk '{print $5}' ]], - function(stdout) - stdout = stdout:gsub("%%", "") - local volume = tonumber(stdout) or 0 - if volume <= 98 then - awful.spawn("pactl set-sink-volume @DEFAULT_SINK@ +2%") - end - end) + awful.spawn.easy_async("pactl set-sink-volume @DEFAULT_SINK@ +2%") awesome.emit_signal("widget::volume") awesome.emit_signal("module::volume_osd:show", true) awesome.emit_signal("module::slider:update") diff --git a/awesome/rc.lua b/awesome/rc.lua index c37265c..686fa04 100644 --- a/awesome/rc.lua +++ b/awesome/rc.lua @@ -6,7 +6,6 @@ -- ██║ ██║╚███╔███╔╝███████╗███████║╚██████╔╝██║ ╚═╝ ██║███████╗╚███╔███╔╝██║ ╚═╝ ██║ -- -- ╚═╝ ╚═╝ ╚══╝╚══╝ ╚══════╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝ -- ----------------------------------------------------------------------------------------- - -- Initialising, order is important! require("src.theme.user_variables") require("src.theme.init") @@ -16,4 +15,4 @@ require("src.core.signals") require("mappings.global_buttons") require("mappings.bind_to_tags") require("crylia_bar.init") -require("src.tools.auto_starter")(user_vars.autostart) +--require("src.tools.auto_starter")(user_vars.autostart) diff --git a/awesome/src/modules/powermenu.lua b/awesome/src/modules/powermenu.lua index f22c844..19f686f 100644 --- a/awesome/src/modules/powermenu.lua +++ b/awesome/src/modules/powermenu.lua @@ -304,9 +304,10 @@ return function(s) awesome.connect_signal( "module::powermenu:show", function() - powermenu_container.visible = false - powermenu_container.visible = true - powermenu_keygrabber:start() + if s == mouse.screen then + powermenu_container.visible = true + powermenu_keygrabber:start() + end end ) diff --git a/awesome/src/modules/titlebar.lua b/awesome/src/modules/titlebar.lua index 3b39937..866584f 100644 --- a/awesome/src/modules/titlebar.lua +++ b/awesome/src/modules/titlebar.lua @@ -60,19 +60,6 @@ local create_click_events = function(c) return buttons end -local createresize_click_events = function(c) - local buttons = gears.table.join( - awful.button( - {}, - 1, - function() - c:activate { context = 'titlebar', action = 'mouse_resize' } - end - ) - ) - return buttons -end - local create_titlebar = function(c, bg, size) local titlebar = awful.titlebar(c, { position = "left", @@ -191,55 +178,8 @@ local create_titlebar_dialog = function(c, bg, size) Hover_signal(titlebar.main.margin.spacing.minimizebutton, color["Green200"]) end -local create_titlebar_borderhack = function(c, bg, position) - local borderhack = awful.titlebar(c, { - position = position, - bg = bg, - size = "4" - }) - borderhack:setup { - { - bg = bg, - widget = wibox.container.background - }, - { - buttons = createresize_click_events(c), - layout = wibox.layout.flex.vertical - }, - nil, - layout = wibox.layout.align.vertical - } - - local old_wibox, old_cursor - borderhack:connect_signal( - "mouse::enter", - function() - local w = mouse.current_client - if w then - old_cursor, old_wibox = w.cursor, w - w.cursor = "hand1" - end - end - ) - - borderhack:connect_signal( - "mouse::leave", - function() - if old_wibox then - old_wibox.cursor = old_cursor - old_wibox = nil - end - end - ) - -end - local draw_titlebar = function(c) if c.type == 'normal' and not c.requests_no_titlebar then - create_titlebar_borderhack(c, "#121212AA", "right") - create_titlebar_borderhack(c, "#121212AA", "top") - create_titlebar_borderhack(c, "#121212AA", "bottom") - if c.class == 'Firefox' then create_titlebar(c, '#121212AA', 35) elseif c.name == "Steam" then @@ -253,15 +193,6 @@ local draw_titlebar = function(c) end elseif c.type == 'dialog' then create_titlebar_dialog(c, '#121212AA', 35) - create_titlebar_borderhack(c, "#121212AA", "right") - create_titlebar_borderhack(c, "#121212AA", "top") - create_titlebar_borderhack(c, "#121212AA", "bottom") - elseif c.type == 'modal' then - else - create_titlebar_borderhack(c, "#121212AA", "right") - create_titlebar_borderhack(c, "#121212AA", "top") - create_titlebar_borderhack(c, "#121212AA", "bottom") - create_titlebar_borderhack(c, "#121212AA", "left") end end @@ -313,9 +244,6 @@ client.connect_signal( awful.titlebar.hide(c, 'bottom') else awful.titlebar.show(c, 'left') - awful.titlebar.show(c, 'right') - awful.titlebar.show(c, 'top') - awful.titlebar.show(c, 'bottom') end else awful.titlebar.hide(c, 'left') diff --git a/awesome/src/theme/user_variables.lua b/awesome/src/theme/user_variables.lua index d166642..bde266f 100644 --- a/awesome/src/theme/user_variables.lua +++ b/awesome/src/theme/user_variables.lua @@ -42,7 +42,7 @@ user_vars = { }, -- This is your default Terminal - terminal = "alacritty -o font.size=14", + terminal = "alacritty", -- This is the modkey 'mod4' = Super/Mod/WindowsKey, 'mod3' = alt... modkey = "Mod4", @@ -68,22 +68,24 @@ user_vars = { -- Add your programs exactly like in this example. -- First entry has to be how you would start the program in the terminal (just try it if you dont know yahoo it) -- Second can be what ever the fuck you want it to be (will be the displayed name if you hover over it) - -- For steam games please use this format {"394360", "Name", true} true will tell the func that it's a steam game - -- TODO: Add appimage support - -- Theoretically you can put the appimage path as the first argument and it *should* work + -- For steam games please use this format (look in .local/share/applications for the .desktop file, that will contain the number you need) + -- {"394360", "Name", true} true will tell the func that it's a steam game + -- Use xprop | grep WM_CLASS and use the *SECOND* string + -- { WM_CLASS, program, name, isSteam } dock_programs = { - { "alacritty", "Alacritty" }, - { "firefox", "Firefox" }, - { "discord", "Discord" }, - { "flatpak run com.spotify.Client", "Spotify" }, - { "code", "Visual Studio Code" }, - { "arduino", "Arduino IDE" }, - { "zoom", "Zoom" }, - { "thunderbird", "Thunderbird" }, - { "mattermost-desktop", "Mattermost" }, - { "blender", "Blender" }, - { "steam", "Steams" }, - { "freecad", "Freecad" }, - { "nemo", "Dateien" } + { "Alacritty", "alacritty", "Alacritty" }, + { "firefox", "firefox", "Firefox" }, + { "discord", "discord", "Discord" }, + { "Spotify", "flatpak run com.spotify.Client", "Spotify" }, + { "Code", "code", "Visual Studio Code" }, + { "processing-app-Base", "arduino", "Arduino IDE" }, + { "zoom", "zoom", "Zoom" }, + { "Thunderbird", "thunderbird", "Thunderbird" }, + { "Mattermost", "mattermost-desktop", "Mattermost" }, + { "Blender", "blender", "Blender" }, + { "Steam", "steam", "Steams" }, + { "FreeCAD", "freecad", "Freecad" }, + { "Nemo", "nemo", "Dateien" }, + { "Paradox Launcher", "394360", "Hearts of Iron 4", true } } } diff --git a/awesome/src/tools/icon_handler.lua b/awesome/src/tools/icon_handler.lua index eae08ea..785c297 100644 --- a/awesome/src/tools/icon_handler.lua +++ b/awesome/src/tools/icon_handler.lua @@ -1,62 +1,95 @@ ----------------------------------------------------- -- Helper to get icons from a program/program name -- ----------------------------------------------------- -local naughty = require("naughty") +local icon_cache = {} + -- tries to find a matching file name in /usr/share/icons/THEME/RESOLUTION/apps/ and if not found tried with first letter -- as uppercase, this should get almost all icons to work with the papirus theme atleast -- TODO: try with more icon themes -function Get_icon(theme, c, is_steam) - if theme ~= nil and c ~= nil then +function Get_icon(theme, client, program_string, class_string, is_steam) + + client = client or nil + program_string = program_string or nil + class_string = class_string or nil + is_steam = is_steam or nil + + if theme and (client or program_string or class_string) then local clientName - if type(c) == "string" then - if c:match("com.*%a") ~= nil then - c = c:gsub("com.", ""):gsub(".Client", ""):gsub("flatpak", ""):gsub("run", ""):gsub(" ", "") - end - end if is_steam then - clientName = "steam_icon_" .. tostring(c) .. ".svg" - else - if c.class ~= nil then - clientName = string.lower(c.class) .. ".svg" - elseif c.name ~= nil then - clientName = string.lower(c.name) .. ".svg" - elseif type(c) == "string" then - clientName = c .. ".svg" + clientName = "steam_icon_" .. tostring(client) .. ".svg" + elseif client then + if client.class then + clientName = string.lower(client.class) .. ".svg" + elseif client.name then + clientName = string.lower(client.name) .. ".svg" + elseif type(client) == "string" then + clientName = client .. ".svg" else - return + if client.icon == nil then + return "/usr/share/icons/Papirus-Dark/128x128/apps/application-default-icon.svg" + else + return client.icon + end + end + else + if program_string then + clientName = program_string .. ".svg" + else + clientName = class_string .. ".svg" end end + + for index, icon in ipairs(icon_cache) do + if icon:match(clientName) then + return icon + end + end + local resolutions = { "128x128", "96x96", "64x64", "48x48", "42x42", "32x32", "24x24", "16x16" } for i, res in ipairs(resolutions) do local iconDir = "/usr/share/icons/" .. theme .. "/" .. res .. "/apps/" local ioStream = io.open(iconDir .. clientName, "r") if ioStream ~= nil then + icon_cache[#icon_cache + 1] = iconDir .. clientName return iconDir .. clientName else clientName = clientName:gsub("^%l", string.upper) iconDir = "/usr/share/icons/" .. theme .. "/" .. res .. "/apps/" ioStream = io.open(iconDir .. clientName, "r") if ioStream ~= nil then + icon_cache[#icon_cache + 1] = iconDir .. clientName return iconDir .. clientName - elseif type(c) ~= type("") then - if pcall( - function() - if c:Get_icon(1) then - error("icon error") - else - return c:Get_icon(1) - end - end - ) then - return nil + else + clientName = class_string .. ".svg" + iconDir = "/usr/share/icons/" .. theme .. "/" .. res .. "/apps/" + ioStream = io.open(iconDir .. clientName, "r") + if ioStream ~= nil then + icon_cache[#icon_cache + 1] = iconDir .. clientName + return iconDir .. clientName + else + return "/usr/share/icons/Papirus-Dark/128x128/apps/application-default-icon.svg" end end end end - end - if c.icon == nil then - return "/usr/share/icons/Papirus-Dark/128x128/apps/application-default-icon.svg" - else - return c.icon + if client then + return client:Get_icon(1) + end end end + +--———————————No swiches?——————————— +--⠀⣞⢽⢪⢣⢣⢣⢫⡺⡵⣝⡮⣗⢷⢽⢽⢽⣮⡷⡽⣜⣜⢮⢺⣜⢷⢽⢝⡽⣝ +--⠸⡸⠜⠕⠕⠁⢁⢇⢏⢽⢺⣪⡳⡝⣎⣏⢯⢞⡿⣟⣷⣳⢯⡷⣽⢽⢯⣳⣫⠇ +--⠀⠀⢀⢀⢄⢬⢪⡪⡎⣆⡈⠚⠜⠕⠇⠗⠝⢕⢯⢫⣞⣯⣿⣻⡽⣏⢗⣗⠏⠀ +--⠀⠪⡪⡪⣪⢪⢺⢸⢢⢓⢆⢤⢀⠀⠀⠀⠀⠈⢊⢞⡾⣿⡯⣏⢮⠷⠁⠀⠀ +--⠀⠀⠀⠈⠊⠆⡃⠕⢕⢇⢇⢇⢇⢇⢏⢎⢎⢆⢄⠀⢑⣽⣿⢝⠲⠉⠀⠀⠀⠀ +--⠀⠀⠀⠀⠀⡿⠂⠠⠀⡇⢇⠕⢈⣀⠀⠁⠡⠣⡣⡫⣂⣿⠯⢪⠰⠂⠀⠀⠀⠀ +--⠀⠀⠀⠀⡦⡙⡂⢀⢤⢣⠣⡈⣾⡃⠠⠄⠀⡄⢱⣌⣶⢏⢊⠂⠀⠀⠀⠀⠀⠀ +--⠀⠀⠀⠀⢝⡲⣜⡮⡏⢎⢌⢂⠙⠢⠐⢀⢘⢵⣽⣿⡿⠁⠁⠀⠀⠀⠀⠀⠀⠀ +--⠀⠀⠀⠀⠨⣺⡺⡕⡕⡱⡑⡆⡕⡅⡕⡜⡼⢽⡻⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +--⠀⠀⠀⠀⣼⣳⣫⣾⣵⣗⡵⡱⡡⢣⢑⢕⢜⢕⡝⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +--⠀⠀⠀⣴⣿⣾⣿⣿⣿⡿⡽⡑⢌⠪⡢⡣⣣⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +--⠀⠀⠀⡟⡾⣿⢿⢿⢵⣽⣾⣼⣘⢸⢸⣞⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +--⠀⠀⠀⠀⠁⠇⠡⠩⡫⢿⣝⡻⡮⣒⢽⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +--————————————————————————————— diff --git a/awesome/src/widgets/audio.lua b/awesome/src/widgets/audio.lua index a1952c0..36e3c81 100644 --- a/awesome/src/widgets/audio.lua +++ b/awesome/src/widgets/audio.lua @@ -60,8 +60,7 @@ return function() awful.spawn.easy_async_with_shell( [[ SINK="$(pacmd stat | awk -F": " '/^Default sink name: /{print $2}')" - -echo $(pacmd list-sinks | awk '/^\s+name: /{indefault = $2 == "<'$SINK'>"} /^\s+volume: / && indefault {print $5; exit}') + echo $(pacmd list-sinks | awk '/^\s+name: /{indefault = $2 == "<'$SINK'>"} /^\s+volume: / && indefault {print $5; exit}') ]], function(stdout) local icon = icondir .. "volume" diff --git a/awesome/src/widgets/power.lua b/awesome/src/widgets/power.lua index 958e271..c4b380d 100644 --- a/awesome/src/widgets/power.lua +++ b/awesome/src/widgets/power.lua @@ -7,7 +7,6 @@ local awful = require("awful") local color = require("src.theme.colors") local dpi = require("beautiful").xresources.apply_dpi local gears = require("gears") -local naughty = require("naughty") local wibox = require("wibox") require("src.core.signals")