Added sorting methods to the dismal menu

This commit is contained in:
Yessiest 2023-01-19 19:23:50 +04:00
parent 37c403fd78
commit c052387d77
3 changed files with 135 additions and 42 deletions

View File

@ -140,3 +140,8 @@ awesome.connect_signal("xdg::dir_finished",function(dir)
awesome.emit_signal("xdg::all_finished") awesome.emit_signal("xdg::all_finished")
end end
end) end)
-- Before exiting, save all xdg cache
awesome.connect_signal("exit",function()
io.open(gears.filesystem.get_xdg_cache_home()..".reno_xdg_cache.json","w"):write(json.encode(xdg)):close()
end)

View File

@ -17,9 +17,14 @@
"path": "$HOME/Pictures/Wallpapers" "path": "$HOME/Pictures/Wallpapers"
} }
}, },
{ "widget": "widgets.desktop.battery" }, {
{ "widget": "widgets.base.systray" }, "widget": "widgets.base.subpanel",
{ "widget": "widgets.base.clock" } "layout": {"list":[
{ "widget": "widgets.desktop.battery" },
{ "widget": "widgets.base.systray" },
{ "widget": "widgets.base.clock" }
]}
}
] ]
} }
} }

View File

@ -13,19 +13,59 @@ local gears = require("gears")
local awful = require("awful") local awful = require("awful")
local ask = require("asckey") local ask = require("asckey")
local xdg_search = function(name,rlimit) local xdg_search = function(name,rlimit,sorting_method)
local results = {} local ranked_results = {}
local count = 0 if sorting_method == "usage" then
for _,v in pairs(xdg.apps) do local filter = {}
if v.name:lower():find(name,nil,true) then local keys = {}
count = count + 1 for k,v in pairs(xdg.apps) do
table.insert(results,v) if not v.count then
v.count = 0
end
if v.name:lower():find(name,nil,true) then
if not filter[v.count] then
table.insert(keys, v.count)
filter[v.count] = {}
end
table.insert(filter[v.count],{k,v})
end
end end
if rlimit <= count then table.sort(keys,function(a,b) return a > b end)
break local count = 0
local exit = false
gears.debug.dump(keys)
gears.debug.dump(filter)
for k = 1,rlimit do
local i = keys[k]
if not filter[i] then
break
end
for _,v in pairs(filter[i]) do
table.insert(ranked_results, v)
count = count + 1
if count >= rlimit then
exit = true
break
end
end
if exit == true then
break
end
end
gears.debug.dump(ranked_results)
elseif sorting_method == "recent" then
local most_recent = 0
for k,v in pairs(xdg.apps) do
if v.name:lower():find(name,nil,true) and v.atime and v.atime >= most_recent then
most_recent = v.atime
table.insert(ranked_results,1,{k,v})
end
if #ranked_results > rlimit then
table.remove(ranked_results,rlimit+1)
end
end end
end end
return results return ranked_results
end end
return function(args) return function(args)
@ -38,7 +78,7 @@ return function(args)
layout = wibox.layout.fixed.horizontal, layout = wibox.layout.fixed.horizontal,
spacing = style.container.spacing spacing = style.container.spacing
})) }))
local button_cache = gears.cache(function(name,exec,description,icon) local button_cache = gears.cache(function(name,exec,description,icon,key)
-- beacause apparently cache doesn't allow nil values -- beacause apparently cache doesn't allow nil values
if icon == "" then icon = nil end if icon == "" then icon = nil end
-- contents of our button -- contents of our button
@ -59,6 +99,13 @@ return function(args)
widget:connect_signal("button::press",style.button.onpress) widget:connect_signal("button::press",style.button.onpress)
widget:connect_signal("button::release",style.button.onrelease) widget:connect_signal("button::release",style.button.onrelease)
widget:connect_signal("mouses::leave",style.button.onrelease) widget:connect_signal("mouses::leave",style.button.onrelease)
local bump = function()
if not xdg.apps[key].count then
xdg.apps[key].count = 0
end
xdg.apps[key].count = xdg.apps[key].count + 1
xdg.apps[key].atime = os.time()
end
widget:buttons( widget:buttons(
gears.table.join( gears.table.join(
awful.button({},1,function() awful.button({},1,function()
@ -66,17 +113,21 @@ return function(args)
dismal.visible = false dismal.visible = false
-- i know it's deprecated, you literally give me no option -- i know it's deprecated, you literally give me no option
awful.keygrabber.stop() awful.keygrabber.stop()
bump()
end), end),
awful.button({"Control"},1,function() awful.button({"Control"},1,function()
awful.spawn({global.terminal,"-e",exec}) awful.spawn({global.terminal,"-e",exec})
dismal.visible = false dismal.visible = false
awful.keygrabber.stop() awful.keygrabber.stop()
bump()
end), end),
awful.button({},3,function() awful.button({},3,function()
awful.spawn(exec) awful.spawn(exec)
bump()
end), end),
awful.button({"Control"},3,function() awful.button({"Control"},3,function()
awful.spawn({global.terminal,"-e",exec}) awful.spawn({global.terminal,"-e",exec})
bump()
end) end)
) )
) )
@ -101,6 +152,23 @@ return function(args)
bgimage = style.container.bgimage_highlight, bgimage = style.container.bgimage_highlight,
forced_width = style.button.width or 180 forced_width = style.button.width or 180
}), }),
t.container({
t.button(
t.textbox({
markup = "Most used"
}),{
id = "usage"
}),
t.button(
t.textbox({
markup = "Recent"
}),{
id = "recent"
}),
id = "buttonbox",
spacing = style.container.spacing,
layout = wibox.layout.flex.horizontal
}),
t.textbox({ t.textbox({
markup = "<b>Enter</b> - run\n<b>Ctrl+Enter</b> - run in terminal" markup = "<b>Enter</b> - run\n<b>Ctrl+Enter</b> - run in terminal"
}), }),
@ -109,14 +177,43 @@ return function(args)
}) })
local results_list = launchpad:get_children_by_id("resultbox")[1] local results_list = launchpad:get_children_by_id("resultbox")[1]
local input_field = launchpad:get_children_by_id("inputbox")[1] local input_field = launchpad:get_children_by_id("inputbox")[1]
local usage_sort = launchpad:get_children_by_id("usage")[1]
local recent_sort = launchpad:get_children_by_id("recent")[1]
local sorting_method = "usage"
usage_sort:set_bg(style.bg_focus)
if style.button.onpress then
style.button.onpress(usage_sort)
end
usage_sort:connect_signal("button::press",function()
recent_sort:set_bg(style.bg_normal)
if style.button.onrelease then
style.button.onrelease(recent_sort)
end
usage_sort:set_bg(style.bg_focus)
if style.button.onpress then
style.button.onpress(usage_sort)
end
sorting_method = "usage"
end)
recent_sort:connect_signal("button::press",function()
usage_sort:set_bg(style.bg_normal)
if style.button.onrelease then
style.button.onrelease(usage_sort)
end
recent_sort:set_bg(style.bg_focus)
if style.button.onpress then
style.button.onpress(recent_sort)
end
sorting_method = "recent"
end)
root.keys(gears.table.join( root.keys(gears.table.join(
root.keys(), root.keys(),
ask.k(":dismal.run", function() ask.k(":dismal.run", function()
results_list:reset() results_list:reset()
launchpad.visible = true dismal.visible = true
launchpad.x = args.x or 0 dismal.x = args.x or 0
launchpad.y = args.y or 0 dismal.y = args.y or 0
if launchpad.visible then if dismal.visible then
awful.prompt.run { awful.prompt.run {
prompt = "<b>Run: </b>", prompt = "<b>Run: </b>",
textbox = input_field, textbox = input_field,
@ -132,18 +229,18 @@ return function(args)
end}, end},
}, },
done_callback = function() done_callback = function()
dismal:emit_signal("sorted_refresh") dismal.visible = false
launchpad.visible = false
end, end,
changed_callback = function(command) changed_callback = function(command)
local results = xdg_search(command,args.result_limit or 5) local results = xdg_search(command,args.result_limit or 5,sorting_method)
results_list:reset() results_list:reset()
for _,v in pairs(results) do for _,v in pairs(results) do
results_list:insert(1,button_cache:get( results_list:add(button_cache:get(
v.name, v[2].name,
v.exec, v[2].exec,
v.description or "", v[2].description or "",
v.icon or "" v[2].icon or "",
v[1]
)) ))
end end
end, end,
@ -157,21 +254,7 @@ return function(args)
end,{description = "open run menu", group = "widgets"}) end,{description = "open run menu", group = "widgets"})
)) ))
end end
local sorted local dismal_root = dismal.widget:get_children_by_id("dismal_root")[1]
do -- sorting tab dismal_root:add(launchpad)
sorted = wibox.widget({
t.container({
id = "sortingbox",
layout = wibox.layout.fixed.vertical,
spacing = style.container.spacing
},{
bg = style.container.bg_highlight,
bgimage = style.container.bgimage_highlight,
forced_width = style.button.width or 180
}),
spacing = style.container.spacing,
layout = wibox.layout.fixed.vertical
})
end
return dismal return dismal
end end