From ac15d2ce705cc221cfc375384f47782a857433f2 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Mon, 13 Mar 2023 01:08:23 +0400 Subject: [PATCH] Context-based keys --- desktop.conf | 2 +- libs/asckey.lua | 26 ++++++++++++++++++++++++++ libs/pager.lua | 3 --- widgets/desktop/notifications.lua | 24 +++++++++++++++++++++++- widgets/desktop/wallpapers.lua | 21 +++++++++++++++++++++ 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/desktop.conf b/desktop.conf index fa76735..35d566d 100644 --- a/desktop.conf +++ b/desktop.conf @@ -3,7 +3,7 @@ terminal = "$HOME/.local/bin/st" browser = "prime-run librewolf" modkey = "Mod4" -theme = "reno98" +theme = "unity_mate" shell = "zsh" # Keybindings diff --git a/libs/asckey.lua b/libs/asckey.lua index 1c28337..399cbb0 100644 --- a/libs/asckey.lua +++ b/libs/asckey.lua @@ -11,6 +11,7 @@ local asckey = { keymap = {} } local awful = require("awful") +local gears = require("gears") asckey.set_keymap = function(keymap) for k,v in pairs(keymap) do @@ -50,4 +51,29 @@ asckey.custom_binds = function() return custom_keys 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 diff --git a/libs/pager.lua b/libs/pager.lua index bd8d17c..64611b4 100644 --- a/libs/pager.lua +++ b/libs/pager.lua @@ -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. -- -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see . -local awful = require("awful") -local wibox = require("wibox") - return function(widget,list,max_elements) if not tostring(widget):match("wibox.layout") then error("Cannot attach pager to widget that isn't a layout") diff --git a/widgets/desktop/notifications.lua b/widgets/desktop/notifications.lua index 95eea00..86a762a 100644 --- a/widgets/desktop/notifications.lua +++ b/widgets/desktop/notifications.lua @@ -12,6 +12,8 @@ local beautiful = require("beautiful") local wibox = require("wibox") local awmtk2 = require("awmtk2") local naughty = require("naughty") +local context = require("asckey").context +local gears = require("gears") return function(args) local style = awmtk2.create_style("notifications", @@ -79,6 +81,7 @@ return function(args) end end) end + local page_index = popup.widget:get_children_by_id("page_id")[1] naughty.config.notify_callback = function(update_args) count = count + 1 local w = wibox.widget(t.button(t.article({ @@ -89,7 +92,6 @@ return function(args) forced_height = style.button.height, 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).."/".. tostring(math.ceil(count/(args.max_notifications or 8)))) w:connect_signal("button::press",style.button.onpress) @@ -115,5 +117,25 @@ return function(args) clip_icon.image = beautiful["notifications-area-flagged-symbolic"] return update_args 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 end diff --git a/widgets/desktop/wallpapers.lua b/widgets/desktop/wallpapers.lua index 9753158..966fe46 100644 --- a/widgets/desktop/wallpapers.lua +++ b/widgets/desktop/wallpapers.lua @@ -13,6 +13,7 @@ local gears = require("gears") local wibox = require("wibox") local awmtk2 = require("awmtk2") local thumbnailer = require("thumbnail") +local context = require("asckey").context local function ls(path) 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 local pager_size = ((args.rows and args.columns) and args.rows*args.columns) or 20 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 for _,v in pairs(image_list) do local new_button = wibox.widget(t.button(t.icon({