add long-press support

This commit is contained in:
Izaya 2022-08-25 13:34:31 +10:00
parent 9c7d068dd0
commit 526dfd4c4b
2 changed files with 36 additions and 3 deletions

View File

@ -1,6 +1,6 @@
# popupswitcher
Popup tasklist switcher for awesomewm
Popup tasklist switcher for awesomewm. Requires [awesome-longpress](https://git.shadowkat.net/izaya/awesome-longpress)
## Usage
`require` the library:

View File

@ -2,13 +2,15 @@ local awful = require("awful")
local wibox = require("wibox")
local gears = require("gears")
local beautiful = require("beautiful")
local longpress = require("awesome-longpress")
local switcherpopup = {
iconSize = 128,
systraySize = 64,
buttonSize = 96,
spacing = 5,
defaultLayout = awful.layout.suit.max,
iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-switcherpopup/"
iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-switcherpopup/",
batteryPath = "/sys/class/power_supply/pad-battery/"
}
function switcherpopup.nextTagName(s)
print(#s.tags, #s.tags+1)
@ -26,7 +28,7 @@ function switcherpopup.new(s)
local tagindex = wibox.widget({widget = wibox.widget.textbox, align = "center"})
local function updateSwitcherpopup()
tagindex.text = "Tag: "..tostring(awful.screen.focused().selected_tag.name)
local fp, fs = io.open("/sys/class/power_supply/axp20x-battery/capacity","rb"), io.open("/sys/class/power_supply/axp20x-battery/status","rb")
local fp, fs = io.open(switcherpopup.batteryPath .. "/capacity","rb"), io.open(switcherpopup.batteryPath .. "/status","rb")
if fp and fs then
local status = fs:read()
tagindex.text = string.format("Battery: %s%%%s\n%s", fp:read(), status == "Charging" and "+" or "-", tagindex.text)
@ -83,6 +85,21 @@ function switcherpopup.new(s)
end)
))
local prev_tag_button = wibox.container.place(awful.widget.button({image = switcherpopup.iconPath .. "/go-previous.png"}), "center", "center")
longpress.add(prev_tag_button, function()
awful.tag.viewprev(s)
popup.visible = false
end, function()
if s.clients[1] and s.selected_tag then
local nextTag = s.selected_tag.index-1
if nextTag < 1 then nextTag = #s.tags end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
error("move attempted")
end
error("move failed?")
end)
--[[
prev_tag_button:buttons(gears.table.join(
prev_tag_button:buttons(),
awful.button({}, 1, nil, function()
@ -90,7 +107,22 @@ function switcherpopup.new(s)
popup.visible = false
end)
))
]]
local next_tag_button = wibox.container.place(awful.widget.button({image = switcherpopup.iconPath .. "/go-next.png"}), "center", "center")
longpress.add(next_tag_button, function()
awful.tag.viewnext(s)
popup.visible = false
end, function()
if s.clients[1] and s.selected_tag then
local nextTag = s.selected_tag.index+1
if nextTag > #s.tags then nextTag = 1 end
s.clients[1]:move_to_tag(s.tags[nextTag])
popup.visible = false
error("move attempted")
end
error("move failed?")
end)
--[[
next_tag_button:buttons(gears.table.join(
next_tag_button:buttons(),
awful.button({}, 1, nil, function()
@ -98,6 +130,7 @@ function switcherpopup.new(s)
popup.visible = false
end)
))
]]
local tagbuttons = wibox.widget({layout = wibox.layout.fixed.horizontal, spacing = (switcherpopup.iconSize + switcherpopup.spacing) - switcherpopup.buttonSize, prev_tag_button, create_tag_button, destroy_tag_button, next_tag_button, close_button})
systray:set_screen(s)
systray:set_horizontal(true)