bling/helpers/icon_theme.lua

82 lines
2.0 KiB
Lua
Raw Normal View History

-------------------------------------------
-- @author https://github.com/Kasper24
-- @copyright 2021-2022 Kasper24
-------------------------------------------
local lgi = require("lgi")
local Gio = lgi.Gio
2023-02-14 01:26:18 +01:00
local DesktopAppInfo = Gio.DesktopAppInfo
2023-02-14 04:07:59 +01:00
local AppInfo = Gio.DesktopAppInfo
local Gtk = lgi.require("Gtk", "3.0")
2023-02-14 04:07:59 +01:00
local string = string
local ipairs = ipairs
2023-02-14 01:26:18 +01:00
local ICON_SIZE = 48
local GTK_THEME = Gtk.IconTheme.get_default()
2023-02-14 01:26:18 +01:00
local _icon_theme = {}
2023-02-14 01:26:18 +01:00
function _icon_theme.choose_icon(icons_names, icon_theme, icon_size)
if icon_theme then
GTK_THEME = Gtk.IconTheme.new()
Gtk.IconTheme.set_custom_theme(GTK_THEME, icon_theme);
end
if icon_size then
ICON_SIZE = icon_size
end
2023-02-14 01:26:18 +01:00
local icon_info = GTK_THEME:choose_icon(icons_names, ICON_SIZE, 0);
More app launcher improvements (#132) * Make sure there is always a default icon * Use get_example_icon_path to get the default icon * Refactor scrolling to add support for left and right scrolling * fixup! Make sure there is always a default icon * Fix calculation happening at the wrong time * Fix default icons again * Where did that come from? * Fix calculation happening at the wrong time for scroll_up as well * Fix error on scroll right when scrolling to page where amount of rows is smaller than the selected row * Sort search results by string similarity * Don't sort by similarity when the search string is empty * Add hover effects * try_to_keep_index_after_searching should be false by default * This should only trigger for lmb * Add an option to hide the app launcher when clicked with lmb/rmb outside of it * Use gtk-launch so terminal apps spawn correctly * Use get_executable instead of get_commandline * Add an option to set the hover colors * Further improvements for the spawn function * Fix scrolling/searching errors when there app list is empty * This should never be nil anyway * whitespace * Refactor show, hide and toggle method + remove support for manually setting x an y (use placement) * Add arguements for custom icon_theme (defaults to the selected system gtk theme) and icon_size (defaults to 48) * Pass the app table instead of individual keys to create_app_widget * Add an arguement to pass the default terminal for terminal apps as gtk-launch only uses xterm * Reformating * Rename 'mark_app' and 'unmark_app' to 'select_app' and 'unselect_app' * Call :hide() from app.spawn() to avoid calling hide() twice on some cases * Fix escape not closing the launcher after b7e44ec4 * Reduce code duplication and only reset the launcher when the animation is over (if not nil) * Set active_widget to nil when the grid is empty to prevent from spawning the wrong app * Override the default exe_callback * Override the default behaviour for 'Return' via hooks instead because overriding only exe_callback still doesn't stop it from pausing the prompt keygrabber * Set active_widget to nil on unselect * Unselect previous app on search to avoid from spawning it when the grid is empty * Use double quotes for everything
2021-11-05 04:38:54 +01:00
if icon_info then
local icon_path = icon_info:get_filename()
More app launcher improvements (#132) * Make sure there is always a default icon * Use get_example_icon_path to get the default icon * Refactor scrolling to add support for left and right scrolling * fixup! Make sure there is always a default icon * Fix calculation happening at the wrong time * Fix default icons again * Where did that come from? * Fix calculation happening at the wrong time for scroll_up as well * Fix error on scroll right when scrolling to page where amount of rows is smaller than the selected row * Sort search results by string similarity * Don't sort by similarity when the search string is empty * Add hover effects * try_to_keep_index_after_searching should be false by default * This should only trigger for lmb * Add an option to hide the app launcher when clicked with lmb/rmb outside of it * Use gtk-launch so terminal apps spawn correctly * Use get_executable instead of get_commandline * Add an option to set the hover colors * Further improvements for the spawn function * Fix scrolling/searching errors when there app list is empty * This should never be nil anyway * whitespace * Refactor show, hide and toggle method + remove support for manually setting x an y (use placement) * Add arguements for custom icon_theme (defaults to the selected system gtk theme) and icon_size (defaults to 48) * Pass the app table instead of individual keys to create_app_widget * Add an arguement to pass the default terminal for terminal apps as gtk-launch only uses xterm * Reformating * Rename 'mark_app' and 'unmark_app' to 'select_app' and 'unselect_app' * Call :hide() from app.spawn() to avoid calling hide() twice on some cases * Fix escape not closing the launcher after b7e44ec4 * Reduce code duplication and only reset the launcher when the animation is over (if not nil) * Set active_widget to nil when the grid is empty to prevent from spawning the wrong app * Override the default exe_callback * Override the default behaviour for 'Return' via hooks instead because overriding only exe_callback still doesn't stop it from pausing the prompt keygrabber * Set active_widget to nil on unselect * Unselect previous app on search to avoid from spawning it when the grid is empty * Use double quotes for everything
2021-11-05 04:38:54 +01:00
if icon_path then
return icon_path
end
end
return ""
end
2023-02-14 01:26:18 +01:00
function _icon_theme.get_gicon_path(gicon, icon_theme, icon_size)
if gicon == nil then
return ""
end
2023-02-14 01:26:18 +01:00
if icon_theme then
GTK_THEME = Gtk.IconTheme.new()
Gtk.IconTheme.set_custom_theme(GTK_THEME, icon_theme);
end
if icon_size then
ICON_SIZE = icon_size
end
local icon_info = GTK_THEME:lookup_by_gicon(gicon, ICON_SIZE, 0);
if icon_info then
local icon_path = icon_info:get_filename()
if icon_path then
return icon_path
end
end
return ""
end
2023-02-14 01:26:18 +01:00
function _icon_theme.get_icon_path(icon_name, icon_theme, icon_size)
if icon_theme then
GTK_THEME = Gtk.IconTheme.new()
Gtk.IconTheme.set_custom_theme(GTK_THEME, icon_theme);
end
if icon_size then
ICON_SIZE = icon_size
end
local icon_info = GTK_THEME:lookup_icon(icon_name, ICON_SIZE, 0)
if icon_info then
local icon_path = icon_info:get_filename()
if icon_path then
return icon_path
end
end
return ""
end
2023-02-14 01:26:18 +01:00
return _icon_theme