bling/widget/app_launcher/init.lua

821 lines
29 KiB
Lua
Raw Normal View History

App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
local Gio = require("lgi").Gio
local awful = require("awful")
local gobject = require("gears.object")
local gtable = require("gears.table")
local gtimer = require("gears.timer")
local wibox = require("wibox")
local beautiful = require("beautiful")
2023-02-19 17:01:01 +01:00
local prompt_widget = require(... .. ".prompt")
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
local dpi = beautiful.xresources.apply_dpi
local string = string
local table = table
local math = math
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
local ipairs = ipairs
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
local pairs = pairs
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
local capi = { screen = screen, mouse = mouse }
local path = ...
2023-02-14 01:31:36 +01:00
local helpers = require(tostring(path):match(".*bling") .. ".helpers")
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
local app_launcher = { mt = {} }
2023-02-04 23:53:50 +01:00
local KILL_OLD_INOTIFY_SCRIPT = [[ ps x | grep "inotifywait -e modify /usr/share/applications" | grep -v grep | awk '{print $1}' | xargs kill ]]
local INOTIFY_SCRIPT = [[ bash -c "while (inotifywait -e modify /usr/share/applications -qq) do echo; done" ]]
2023-02-04 23:47:12 +01:00
local AWESOME_SENSIBLE_TERMINAL_PATH = debug.getinfo(1).source:match("@?(.*/)") ..
"awesome-sensible-terminal"
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
local function default_value(value, default)
if value == nil then
return default
else
return value
end
end
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
local function string_levenshtein(str1, str2)
local len1 = string.len(str1)
local len2 = string.len(str2)
local matrix = {}
local cost = 0
-- quick cut-offs to save time
if (len1 == 0) then
return len2
elseif (len2 == 0) then
return len1
elseif (str1 == str2) then
return 0
end
-- initialise the base matrix values
for i = 0, len1, 1 do
matrix[i] = {}
matrix[i][0] = i
end
for j = 0, len2, 1 do
matrix[0][j] = j
end
-- actual Levenshtein algorithm
for i = 1, len1, 1 do
for j = 1, len2, 1 do
if (str1:byte(i) == str2:byte(j)) then
cost = 0
else
cost = 1
end
matrix[i][j] = math.min(matrix[i-1][j] + 1, matrix[i][j-1] + 1, matrix[i-1][j-1] + cost)
end
end
-- return the last value - this is the Levenshtein distance
return matrix[len1][len2]
end
local function case_insensitive_pattern(pattern)
-- find an optional '%' (group 1) followed by any character (group 2)
local p = pattern:gsub("(%%?)(.)", function(percent, letter)
if percent ~= "" or not letter:match("%a") then
-- if the '%' matched, or `letter` is not a letter, return "as is"
return percent .. letter
else
-- else, return a case-insensitive character class of the matched letter
return string.format("[%s%s]", letter:lower(), letter:upper())
end
end)
return p
end
local function has_value(tab, val)
for index, value in pairs(tab) do
if val:find(case_insensitive_pattern(value)) then
return true
end
end
return false
end
2023-02-12 17:14:35 +01:00
local function app_widget(self, app)
local widget = nil
if self.app_template == nil then
2023-02-12 17:14:35 +01:00
widget = wibox.widget
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
{
widget = wibox.container.background,
2023-02-19 16:33:53 +01:00
forced_width = dpi(300),
forced_height = dpi(120),
bg = self.app_normal_color,
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
{
widget = wibox.container.margin,
2023-02-19 16:33:53 +01:00
margins = dpi(10),
{
2023-02-20 02:39:42 +01:00
layout = wibox.layout.fixed.vertical,
spacing = dpi(10),
{
2023-02-20 02:39:42 +01:00
widget = wibox.container.place,
halign = "center",
valign = "center",
{
widget = wibox.widget.imagebox,
id = "icon_role",
forced_width = dpi(70),
forced_height = dpi(70),
image = app.icon
},
},
2023-02-20 02:39:42 +01:00
{
widget = wibox.container.place,
halign = "center",
valign = "center",
{
widget = wibox.widget.textbox,
id = "name_role",
markup = string.format("<span foreground='%s'>%s</span>", self.app_name_normal_color, app.name)
}
}
}
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
}
}
2023-02-12 17:14:35 +01:00
widget:connect_signal("mouse::enter", function()
local widget = capi.mouse.current_wibox
if widget then
widget.cursor = "hand2"
end
end)
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
2023-02-12 17:14:35 +01:00
widget:connect_signal("mouse::leave", function()
local widget = capi.mouse.current_wibox
if widget then
widget.cursor = "left_ptr"
end
end)
else
2023-02-12 17:14:35 +01:00
widget = self.app_template(app)
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
2023-02-12 17:14:35 +01:00
local icon = widget:get_children_by_id("icon_role")[1]
if icon then
icon.image = app.icon
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
end
2023-02-12 17:14:35 +01:00
local name = widget:get_children_by_id("name_role")[1]
if name then
name.text = app.name
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
end
2023-02-12 17:14:35 +01:00
local generic_name = widget:get_children_by_id("generic_name_role")[1]
if generic_name then
generic_name.text = app.generic_name
end
2023-02-12 17:14:35 +01:00
local command = widget:get_children_by_id("command_role")[1]
if command then
command.text = app.executable
end
end
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
2023-02-12 17:14:35 +01:00
widget:connect_signal("button::press", function(app, _, __, button)
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 button == 1 then
if self._private.active_widget == app or not self.select_before_spawn then
2023-02-05 00:28:51 +01:00
app:spawn()
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
else
app:select()
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
end
end
end)
2023-02-07 13:42:17 +01:00
local _self = self
2023-02-12 17:14:35 +01:00
function widget:spawn()
if app.terminal == true then
awful.spawn.with_shell(AWESOME_SENSIBLE_TERMINAL_PATH .. " -e " .. app.executable)
else
awful.spawn(app.executable)
end
2023-02-07 13:42:17 +01:00
if _self.hide_on_launch then
_self:hide()
end
end
2023-02-12 17:14:35 +01:00
function widget:select()
if _self._private.active_widget then
_self._private.active_widget:unselect()
end
_self._private.active_widget = self
self:emit_signal("selected")
self.selected = true
if _self.app_template == nil then
2023-02-20 02:39:42 +01:00
widget.bg = _self.app_selected_color
local name_widget = self:get_children_by_id("name_role")[1]
2023-02-20 02:39:42 +01:00
name_widget.markup = string.format("<span foreground='%s'>%s</span>", _self.app_name_selected_color, name_widget.text)
end
end
2023-02-12 17:14:35 +01:00
function widget:unselect()
self:emit_signal("unselected")
self.selected = false
_self._private.active_widget = nil
if _self.app_template == nil then
2023-02-20 02:39:42 +01:00
widget.bg = _self.app_normal_color
local name_widget = self:get_children_by_id("name_role")[1]
2023-02-20 02:39:42 +01:00
name_widget.markup = string.format("<span foreground='%s'>%s</span>", _self.app_name_normal_color, name_widget.text)
end
end
2023-02-12 17:14:35 +01:00
return widget
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
local function search(self, text)
local old_pos = self._private.grid:get_widget_position(self._private.active_widget)
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
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
-- Reset all the matched entries
self._private.matched_entries = {}
-- Remove all the grid widgets
self._private.grid:reset()
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 text == "" then
self._private.matched_entries = self._private.all_entries
else
for _, entry in pairs(self._private.all_entries) do
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
text = text:gsub( "%W", "" )
-- Check if there's a match by the app name or app command
if string.find(entry.name:lower(), text:lower(), 1, true) ~= nil or
self.search_commands and string.find(entry.commandline, text:lower(), 1, true) ~= nil
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
then
table.insert(self._private.matched_entries, {
name = entry.name,
generic_name = entry.generic_name,
commandline = entry.commandline,
executable = entry.executable,
terminal = entry.terminal,
icon = entry.icon
})
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
end
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
-- Sort by string similarity
table.sort(self._private.matched_entries, function(a, b)
return string_levenshtein(text, a.name) < string_levenshtein(text, b.name)
end)
end
for _, entry in pairs(self._private.matched_entries) do
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
-- Only add the widgets for apps that are part of the first page
if #self._private.grid.children + 1 <= self._private.max_apps_per_page then
2023-02-12 17:14:35 +01:00
self._private.grid:add(app_widget(self, entry))
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
end
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
-- Recalculate the apps per page based on the current matched entries
self._private.apps_per_page = math.min(#self._private.matched_entries, self._private.max_apps_per_page)
-- Recalculate the pages count based on the current apps per page
self._private.pages_count = math.ceil(math.max(1, #self._private.matched_entries) / math.max(1, self._private.apps_per_page))
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
-- Page should be 1 after a search
self._private.current_page = 1
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
-- This is an option to mimic rofi behaviour where after a search
-- it will reselect the app whose index is the same as the app index that was previously selected
-- and if matched_entries.length < current_index it will instead select the app with the greatest index
if self.try_to_keep_index_after_searching then
if self._private.grid:get_widgets_at(old_pos.row, old_pos.col) == nil then
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
local app = self._private.grid.children[#self._private.grid.children]
app:select()
else
local app = self._private.grid:get_widgets_at(old_pos.row, old_pos.col)[1]
app:select()
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
end
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
-- Otherwise select the first app on the list
2023-02-05 15:47:09 +01:00
elseif #self._private.grid.children > 0 then
local app = self._private.grid:get_widgets_at(1, 1)[1]
app:select()
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
end
2023-02-05 14:45:31 +01:00
local function page_forward(self, dir)
local min_app_index_to_include = 0
local max_app_index_to_include = self._private.apps_per_page
if self._private.current_page < self._private.pages_count then
min_app_index_to_include = self._private.apps_per_page * self._private.current_page
self._private.current_page = self._private.current_page + 1
max_app_index_to_include = self._private.apps_per_page * self._private.current_page
elseif self.wrap_page_scrolling and #self._private.matched_entries >= self._private.max_apps_per_page then
self._private.current_page = 1
min_app_index_to_include = 0
max_app_index_to_include = self._private.apps_per_page
elseif self.wrap_app_scrolling then
local app = self._private.grid:get_widgets_at(1, 1)[1]
app:select()
return
else
return
end
local pos = self._private.grid:get_widget_position(self._private.active_widget)
-- Remove the current page apps from the grid
self._private.grid:reset()
for index, entry in pairs(self._private.matched_entries) do
-- Only add widgets that are between this range (part of the current page)
if index > min_app_index_to_include and index <= max_app_index_to_include then
2023-02-12 17:14:35 +01:00
self._private.grid:add(app_widget(self, entry))
end
end
if self._private.current_page > 1 or self.wrap_page_scrolling then
2023-02-05 14:45:31 +01:00
if dir == "down" then
local app = self._private.grid:get_widgets_at(1, 1)[1]
app:select()
else
local app = self._private.grid:get_widgets_at(pos.row, 1)[1]
if app == nil then
local app = self._private.grid.children[#self._private.grid.children]
app:select()
2023-02-05 14:03:02 +01:00
else
app:select()
2023-02-05 14:03:02 +01:00
end
end
end
end
2023-02-05 14:45:31 +01:00
local function page_backward(self, dir)
if self._private.current_page > 1 then
self._private.current_page = self._private.current_page - 1
elseif self.wrap_page_scrolling and #self._private.matched_entries >= self._private.max_apps_per_page then
self._private.current_page = self._private.pages_count
elseif self.wrap_app_scrolling then
2023-02-05 14:58:18 +01:00
local app = self._private.grid.children[#self._private.grid.children]
app:select()
return
else
return
end
local pos = self._private.grid:get_widget_position(self._private.active_widget)
-- Remove the current page apps from the grid
self._private.grid:reset()
local max_app_index_to_include = self._private.apps_per_page * self._private.current_page
local min_app_index_to_include = max_app_index_to_include - self._private.apps_per_page
for index, entry in pairs(self._private.matched_entries) do
-- Only add widgets that are between this range (part of the current page)
if index > min_app_index_to_include and index <= max_app_index_to_include then
2023-02-12 17:14:35 +01:00
self._private.grid:add(app_widget(self, entry))
end
end
local rows, columns = self._private.grid:get_dimension()
if self._private.current_page < self._private.pages_count then
2023-02-05 14:45:31 +01:00
if dir == "up" then
2023-02-05 14:58:18 +01:00
local app = self._private.grid.children[#self._private.grid.children]
app:select()
else
-- Keep the same row from last page
local app = self._private.grid:get_widgets_at(pos.row, columns)[1]
app:select()
end
elseif self.wrap_page_scrolling then
local app = self._private.grid.children[#self._private.grid.children]
app:select()
end
end
2023-02-05 14:45:13 +01:00
local function scroll(self, dir)
if #self._private.grid.children < 1 then
self._private.active_widget = nil
return
end
local pos = self._private.grid:get_widget_position(self._private.active_widget)
local can_scroll = false
local step_size = 0
local if_cant_scroll_func = nil
if dir == "up" then
can_scroll = self._private.grid:index(self._private.active_widget) > 1
step_size = -1
if_cant_scroll_func = function() page_backward(self, "up") end
elseif dir == "down" then
can_scroll = self._private.grid:index(self._private.active_widget) < #self._private.grid.children
step_size = 1
if_cant_scroll_func = function() page_forward(self, "down") end
elseif dir == "left" then
can_scroll = self._private.grid:get_widgets_at(pos.row, pos.col - 1) ~= nil
step_size = -self._private.grid.forced_num_rows
2023-02-05 14:45:13 +01:00
if_cant_scroll_func = function() page_backward(self, "left") end
elseif dir == "right" then
can_scroll = self._private.grid:get_widgets_at(pos.row, pos.col + 1) ~= nil
step_size = self._private.grid.forced_num_cols
2023-02-05 14:45:13 +01:00
if_cant_scroll_func = function() page_forward(self, "right") end
end
if can_scroll then
local app = gtable.cycle_value(self._private.grid.children, self._private.active_widget, step_size)
app:select()
else
if_cant_scroll_func()
end
end
local function reset(self)
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
self._private.grid:reset()
self._private.matched_entries = self._private.all_entries
self._private.apps_per_page = self._private.max_apps_per_page
self._private.pages_count = math.ceil(#self._private.all_entries / self._private.apps_per_page)
self._private.current_page = 1
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
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
for index, entry in pairs(self._private.all_entries) do
-- Only add the apps that are part of the first page
if index <= self._private.apps_per_page then
2023-02-12 17:14:35 +01:00
self._private.grid:add(app_widget(self, entry))
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
else
break
end
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
local app = self._private.grid:get_widgets_at(1, 1)[1]
app:select()
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
end
local function generate_apps(self)
self._private.all_entries = {}
self._private.matched_entries = {}
local app_info = Gio.AppInfo
local apps = app_info.get_all()
if self.sort_alphabetically then
table.sort(apps, function(a, b)
local app_a_score = app_info.get_name(a):lower()
if has_value(self.favorites, app_info.get_id(a)) then
app_a_score = "aaaaaaaaaaa" .. app_a_score
end
local app_b_score = app_info.get_name(b):lower()
if has_value(self.favorites, app_info.get_id(b)) then
app_b_score = "aaaaaaaaaaa" .. app_b_score
end
return app_a_score < app_b_score
end)
elseif self.reverse_sort_alphabetically then
table.sort(apps, function(a, b)
local app_a_score = app_info.get_name(a):lower()
if has_value(self.favorites, app_info.get_id(a)) then
app_a_score = "zzzzzzzzzzz" .. app_a_score
end
local app_b_score = app_info.get_name(b):lower()
if has_value(self.favorites, app_info.get_id(b)) then
app_b_score = "zzzzzzzzzzz" .. app_b_score
end
return app_a_score > app_b_score
end)
else
table.sort(apps, function(a, b)
local app_a_favorite = has_value(self.favorites, app_info.get_id(a))
local app_b_favorite = has_value(self.favorites, app_info.get_id(b))
if app_a_favorite and not app_b_favorite then
return true
elseif app_b_favorite and not app_a_favorite then
return false
elseif app_a_favorite and app_b_favorite then
return app_info.get_name(a):lower() < app_info.get_name(b):lower()
else
return false
end
end)
end
for _, app in ipairs(apps) do
if app.should_show(app) then
local name = app_info.get_name(app)
local commandline = app_info.get_commandline(app)
local executable = app_info.get_executable(app)
2023-02-14 01:26:18 +01:00
local icon = helpers.icon_theme.get_gicon_path(app_info.get_icon(app), self.icon_theme, self.icon_size)
-- Check if this app should be skipped, depanding on the skip_names / skip_commands table
if not has_value(self.skip_names, name) and not has_value(self.skip_commands, commandline) then
-- Check if this app should be skipped becuase it's iconless depanding on skip_empty_icons
if icon ~= "" or self.skip_empty_icons == false then
if icon == "" then
if self.default_app_icon_name ~= nil then
2023-02-14 01:26:18 +01:00
icon = helpers.icon_theme.get_icon_path(self.default_app_icon_name, self.icon_theme, self.icon_size)
elseif self.default_app_icon_path ~= nil then
icon = self.default_app_icon_path
else
2023-02-14 01:26:18 +01:00
icon = helpers.icon_theme.choose_icon(
{"application-all", "application", "application-default-icon", "app"},
self.icon_theme, self.icon_size)
end
end
local desktop_app_info = Gio.DesktopAppInfo.new(app_info.get_id(app))
local terminal = Gio.DesktopAppInfo.get_string(desktop_app_info, "Terminal") == "true" and true or false
local generic_name = Gio.DesktopAppInfo.get_string(desktop_app_info, "GenericName") or nil
table.insert(self._private.all_entries, {
name = name,
generic_name = generic_name,
commandline = commandline,
executable = executable,
terminal = terminal,
icon = icon
})
end
end
end
end
end
2023-02-19 17:01:01 +01:00
local function build_widget(self)
local widget = self.widget_template
2023-02-20 02:39:42 +01:00
if widget == nil then
self._private.prompt = wibox.widget
2023-02-19 17:01:01 +01:00
{
widget = prompt_widget,
2023-02-20 03:33:23 +01:00
always_on = true,
reset_on_stop = self.reset_on_hide,
2023-02-20 02:39:42 +01:00
icon_font = self.prompt_icon_font,
icon_size = self.prompt_icon_size,
icon_color = self.prompt_icon_color,
icon = self.prompt_icon,
label_font = self.prompt_label_font,
label_size = self.prompt_label_size,
label_color = self.prompt_label_color,
label = self.prompt_label,
text_font = self.prompt_text_font,
text_size = self.prompt_text_size,
text_color = self.prompt_text_color,
2023-02-19 17:01:01 +01:00
}
self._private.grid = wibox.widget
{
layout = wibox.layout.grid,
orientation = "horizontal",
homogeneous = true,
2023-02-20 03:54:20 +01:00
spacing = dpi(30),
forced_num_cols = self.apps_per_column,
forced_num_rows = self.apps_per_row,
}
widget = wibox.widget
2023-02-19 17:01:01 +01:00
{
layout = wibox.layout.fixed.vertical,
{
widget = wibox.container.background,
2023-02-20 02:39:42 +01:00
forced_height = dpi(120),
2023-02-19 17:01:01 +01:00
bg = self.prompt_bg_color,
{
widget = wibox.container.margin,
margins = dpi(30),
{
widget = wibox.container.place,
halign = "left",
valign = "center",
self._private.prompt
2023-02-19 17:01:01 +01:00
}
}
},
{
widget = wibox.container.margin,
margins = dpi(30),
self._private.grid
}
}
2023-02-20 02:39:42 +01:00
else
self._private.prompt = widget:get_children_by_id("prompt_role")[1]
self._private.grid = widget:get_children_by_id("grid_role")[1]
end
self._private.widget = awful.popup
{
2023-02-20 03:51:00 +01:00
screen = self.screen,
type = self.type,
visible = false,
ontop = true,
placement = self.placement,
border_width = self.border_width,
border_color = self.border_color,
shape = self.shape,
bg = self.background,
widget = widget
2023-02-19 17:01:01 +01:00
}
self._private.grid:connect_signal("button::press", function(_, lx, ly, button, mods, find_widgets_result)
if button == 4 then
self:scroll_up()
elseif button == 5 then
self:scroll_down()
end
end)
self._private.prompt:connect_signal("text::changed", function(_, text)
2023-02-19 17:01:01 +01:00
if text == self._private.text then
return
end
self._private.text = text
self._private.search_timer:again()
end)
self._private.prompt:connect_signal("key::press", function(_, mod, key, cmd)
2023-02-19 17:01:01 +01:00
if key == "Escape" then
self:hide()
end
if key == "Return" then
if self._private.active_widget ~= nil then
self._private.active_widget:spawn()
end
end
if key == "Up" then
self:scroll_up()
end
if key == "Down" then
self:scroll_down()
end
if key == "Left" then
self:scroll_left()
end
if key == "Right" then
self:scroll_right()
end
end)
self._private.max_apps_per_page = self._private.grid.forced_num_cols * self._private.grid.forced_num_rows
self._private.apps_per_page = self._private.max_apps_per_page
2023-02-19 17:01:01 +01:00
end
-- Sets favorites
function app_launcher:set_favorites(favorites)
self.favorites = favorites
generate_apps(self)
end
--- Scrolls up
function app_launcher:scroll_up()
scroll(self, "up")
end
--- Scrolls down
function app_launcher:scroll_down()
scroll(self, "down")
end
--- Scrolls to the left
function app_launcher:scroll_left()
scroll(self, "left")
end
--- Scrolls to the right
function app_launcher:scroll_right()
scroll(self, "right")
end
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
--- Shows the app launcher
function app_launcher:show()
if self.show_on_focused_screen then
self._private.widget.screen = awful.screen.focused()
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
self._private.widget.visible = true
self._private.prompt:start()
self:emit_signal("visibility", true)
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
--- Hides the app launcher
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
function app_launcher:hide()
self._private.widget.visible = false
self._private.prompt:stop()
self:emit_signal("visibility", false)
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
--- Toggles the app launcher
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
function app_launcher:toggle()
if self._private.widget.visible then
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
self:hide()
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
else
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
self:show()
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
end
end
-- Returns a new app launcher
local function new(args)
args = args or {}
args.favorites = default_value(args.favorites, {})
args.search_commands = default_value(args.search_commands, true)
args.skip_names = default_value(args.skip_names, {})
args.skip_commands = default_value(args.skip_commands, {})
args.skip_empty_icons = default_value(args.skip_empty_icons, false)
args.sort_alphabetically = default_value(args.sort_alphabetically, true)
args.reverse_sort_alphabetically = default_value(args.reverse_sort_alphabetically, false)
args.select_before_spawn = default_value(args.select_before_spawn, true)
args.hide_on_left_clicked_outside = default_value(args.hide_on_left_clicked_outside, true)
args.hide_on_right_clicked_outside = default_value(args.hide_on_right_clicked_outside, true)
args.hide_on_launch = default_value(args.hide_on_launch, true)
args.try_to_keep_index_after_searching = default_value(args.try_to_keep_index_after_searching, false)
args.reset_on_hide = default_value(args.reset_on_hide, true)
args.wrap_page_scrolling = default_value(args.wrap_page_scrolling, true)
args.wrap_app_scrolling = default_value(args.wrap_app_scrolling, true)
args.type = default_value(args.type, "dock")
args.show_on_focused_screen = default_value(args.show_on_focused_screen, true)
args.screen = default_value(args.screen, capi.screen.primary)
args.placement = default_value(args.placement, awful.placement.centered)
args.background = default_value(args.background, "#000000")
args.border_width = default_value(args.border_width, beautiful.border_width or dpi(0))
args.border_color = default_value(args.border_color, beautiful.border_color or "#FFFFFF")
args.shape = default_value(args.shape, nil)
args.default_app_icon_name = default_value(args.default_app_icon_name, nil)
args.default_app_icon_path = default_value(args.default_app_icon_path, nil)
args.icon_theme = default_value(args.icon_theme, nil)
args.icon_size = default_value(args.icon_size, nil)
args.apps_per_row = default_value(args.apps_per_row, 5)
args.apps_per_column = default_value(args.apps_per_column, 3)
2023-02-20 02:39:42 +01:00
args.prompt_bg_color = default_value(args.prompt_bg_color, "#000000")
args.prompt_icon_font = default_value(args.prompt_icon_font, beautiful.font)
args.prompt_icon_size = default_value(args.prompt_icon_size, 12)
args.prompt_icon_color = default_value(args.prompt_icon_color, "#FFFFFF")
args.prompt_icon = default_value(args.prompt_icon, "")
2023-02-20 02:39:42 +01:00
args.prompt_label_font = default_value(args.prompt_label_font, beautiful.font)
args.prompt_label_size = default_value(args.prompt_label_size, 12)
args.prompt_label_color = default_value(args.prompt_label_color, "#FFFFFF")
args.prompt_label = default_value(args.prompt_label, "<b>Search</b>: ")
2023-02-20 02:39:42 +01:00
args.prompt_text_font = default_value(args.prompt_text_font, beautiful.font)
args.prompt_text_size = default_value(args.prompt_text_size, 12)
args.prompt_text_color = default_value(args.prompt_text_color, "#FFFFFF")
args.app_normal_color = default_value(args.app_normal_color, "#000000")
args.app_selected_color = default_value(args.app_selected_color, "#FFFFFF")
args.app_name_normal_color = default_value( args.app_name_normal_color, "#FFFFFF")
args.app_name_selected_color = default_value(args.app_name_selected_color, "#000000")
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
2023-02-05 14:48:13 +01:00
local ret = gobject {}
2023-02-19 16:36:09 +01:00
gtable.crush(ret, app_launcher, true)
gtable.crush(ret, args, true)
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
2023-02-19 16:47:54 +01:00
ret._private = {}
ret._private.text = ""
ret._private.pages_count = 0
ret._private.current_page = 1
2023-02-19 16:36:14 +01:00
ret._private.search_timer = gtimer {
timeout = 0.05,
autostart = true,
single_shot = true,
callback = function()
search(ret, ret._private.text)
end
}
if ret.hide_on_left_clicked_outside then
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
awful.mouse.append_client_mousebinding(
awful.button({ }, 1, function (c)
ret:hide()
end)
)
awful.mouse.append_global_mousebinding(
awful.button({ }, 1, function (c)
ret:hide()
end)
)
end
if ret.hide_on_right_clicked_outside then
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
awful.mouse.append_client_mousebinding(
awful.button({ }, 3, function (c)
ret:hide()
end)
)
awful.mouse.append_global_mousebinding(
awful.button({ }, 3, function (c)
ret:hide()
end)
)
end
2023-02-04 23:53:50 +01:00
awful.spawn.easy_async_with_shell(KILL_OLD_INOTIFY_SCRIPT, function()
2023-02-05 13:57:39 +01:00
awful.spawn.with_line_callback(INOTIFY_SCRIPT, {stdout = function()
generate_apps(ret)
end})
end)
2023-02-19 17:01:01 +01:00
build_widget(ret)
2023-02-05 01:20:23 +01:00
generate_apps(ret)
reset(ret)
App launcher ala rofi widget (#103) * Initial commit * Fix missing dpi variable * Add an option to search by command * Add turn_on and turn_off signals * Add options to skip apps by their names or commands * Add an option to skip apps with no icons * Fix looping over the wrong table * Refactor to make it into a proper bling like widget * Fix selecting the wrong app after a search * Why was this in a seperate check? * Fix various issues with toggle/show/hide * Stop it from complaining * Fix wrong app getting selected after scrolling up/down * Add an option to spawn the app when pressing on it regardless if it was selected or not * lol what? * Don't add widgets that won't be visible after scrolling down * Yap wasn't needed * This is a little clearer * Add an option 'try_to_keep_index_after_search' to mimic rofi behaviour * Only add widgets that are visible after a search * Fix search not adding the correct number of widgets * Add proper customization options * Add proper customizaiton options for the prompt * Simplfy scroll down logic and fix possible bugs * Add animation support * Fix app list being empty on some occasions * Default placement when x and y is nil * Free up ram * Add a default icon option * style change * Not needed and also hurts search peformance by a decent amount * Fix error when trying to spawn an app when no app is currently marked * Not needed * Add a small debounce delay for the search to prevent it from lagging * Formatting * Replace menubar with app_info * Fix the default icon option
2021-11-03 22:38:50 +01:00
return ret
end
function app_launcher.mt:__call(...)
return new(...)
end
return setmetatable(app_launcher, app_launcher.mt)