Context-based keys

This commit is contained in:
Yessiest 2023-03-13 01:08:23 +04:00
parent 2f5b09c953
commit ac15d2ce70
5 changed files with 71 additions and 5 deletions

View File

@ -3,7 +3,7 @@
terminal = "$HOME/.local/bin/st" terminal = "$HOME/.local/bin/st"
browser = "prime-run librewolf" browser = "prime-run librewolf"
modkey = "Mod4" modkey = "Mod4"
theme = "reno98" theme = "unity_mate"
shell = "zsh" shell = "zsh"
# Keybindings # Keybindings

View File

@ -11,6 +11,7 @@ local asckey = {
keymap = {} keymap = {}
} }
local awful = require("awful") local awful = require("awful")
local gears = require("gears")
asckey.set_keymap = function(keymap) asckey.set_keymap = function(keymap)
for k,v in pairs(keymap) do for k,v in pairs(keymap) do
@ -50,4 +51,29 @@ asckey.custom_binds = function()
return custom_keys return custom_keys
end end
asckey.context = function(keys)
local context = {keys = keys, key_lookup = {},active = false}
for _,v in pairs(keys) do
context.key_lookup[v] = true
end
function context:activate()
context.active = true
root.keys(gears.table.join(
root.keys(),
self.keys
))
end
function context:deactivate()
context.active = false
local root_keys = root.keys()
for i = #root_keys,1,-1 do
if self.key_lookup[root_keys[i]] then
table.remove(root_keys,i)
end
end
root.keys(root_keys)
end
return context
end
return asckey return asckey

View File

@ -5,9 +5,6 @@
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-- --
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
local awful = require("awful")
local wibox = require("wibox")
return function(widget,list,max_elements) return function(widget,list,max_elements)
if not tostring(widget):match("wibox.layout") then if not tostring(widget):match("wibox.layout") then
error("Cannot attach pager to widget that isn't a layout") error("Cannot attach pager to widget that isn't a layout")

View File

@ -12,6 +12,8 @@ local beautiful = require("beautiful")
local wibox = require("wibox") local wibox = require("wibox")
local awmtk2 = require("awmtk2") local awmtk2 = require("awmtk2")
local naughty = require("naughty") local naughty = require("naughty")
local context = require("asckey").context
local gears = require("gears")
return function(args) return function(args)
local style = awmtk2.create_style("notifications", local style = awmtk2.create_style("notifications",
@ -79,6 +81,7 @@ return function(args)
end end
end) end)
end end
local page_index = popup.widget:get_children_by_id("page_id")[1]
naughty.config.notify_callback = function(update_args) naughty.config.notify_callback = function(update_args)
count = count + 1 count = count + 1
local w = wibox.widget(t.button(t.article({ local w = wibox.widget(t.button(t.article({
@ -89,7 +92,6 @@ return function(args)
forced_height = style.button.height, forced_height = style.button.height,
forced_width = style.button.width forced_width = style.button.width
})) }))
local page_index = popup.widget:get_children_by_id("page_id")[1]
page_index:set_markup("Page "..tostring(pager.index+1).."/".. page_index:set_markup("Page "..tostring(pager.index+1).."/"..
tostring(math.ceil(count/(args.max_notifications or 8)))) tostring(math.ceil(count/(args.max_notifications or 8))))
w:connect_signal("button::press",style.button.onpress) w:connect_signal("button::press",style.button.onpress)
@ -115,5 +117,25 @@ return function(args)
clip_icon.image = beautiful["notifications-area-flagged-symbolic"] clip_icon.image = beautiful["notifications-area-flagged-symbolic"]
return update_args return update_args
end end
local pager_context = context(gears.table.join(
awful.key({},"Next",function()
pager:next()
page_index:set_markup("Page "..tostring(pager.index+1).."/"..
tostring(math.ceil(count/(args.max_notifications or 8))))
end),
awful.key({},"Prior",function()
pager:prev()
page_index:set_markup("Page "..tostring(pager.index+1).."/"..
tostring(math.ceil(count/(args.max_notifications or 8))))
end)
))
popup:connect_signal("property::visible",function()
if (not pager_context.active) and (popup.visible) then
pager_context:activate()
end
if (pager_context.active) and (not popup.visible) then
pager_context:deactivate()
end
end)
return clip_widget return clip_widget
end end

View File

@ -13,6 +13,7 @@ local gears = require("gears")
local wibox = require("wibox") local wibox = require("wibox")
local awmtk2 = require("awmtk2") local awmtk2 = require("awmtk2")
local thumbnailer = require("thumbnail") local thumbnailer = require("thumbnail")
local context = require("asckey").context
local function ls(path) local function ls(path)
local ls_data = io.popen("find "..path.." -maxdepth 1 -type f \\( -name \\*.jpg -o -name \\*.png \\) -exec realpath {} \\;") local ls_data = io.popen("find "..path.." -maxdepth 1 -type f \\( -name \\*.jpg -o -name \\*.png \\) -exec realpath {} \\;")
@ -85,6 +86,26 @@ return function(args)
-- set up a pager for having multiple pages of wallpapers -- set up a pager for having multiple pages of wallpapers
local pager_size = ((args.rows and args.columns) and args.rows*args.columns) or 20 local pager_size = ((args.rows and args.columns) and args.rows*args.columns) or 20
local pager = pager(layout,{},pager_size) local pager = pager(layout,{},pager_size)
local pager_context = context(gears.table.join(
awful.key({},"Next",function()
pager:next()
page_index:set_markup("Page "..tostring(pager.index+1).."/"..
tostring(math.ceil(#image_list/pager_size)))
end),
awful.key({},"Prior",function()
pager:prev()
page_index:set_markup("Page "..tostring(pager.index+1).."/"..
tostring(math.ceil(#image_list/pager_size)))
end)
))
popup:connect_signal("property::visible",function()
if (not pager_context.active) and (popup.visible) then
pager_context:activate()
end
if (pager_context.active) and (not popup.visible) then
pager_context:deactivate()
end
end)
-- add wallpaper buttons -- add wallpaper buttons
for _,v in pairs(image_list) do for _,v in pairs(image_list) do
local new_button = wibox.widget(t.button(t.icon({ local new_button = wibox.widget(t.button(t.icon({