Added stickers prototype

This commit is contained in:
Yessiest 2021-11-14 15:04:39 +04:00
parent 333859dbc4
commit 00aaec4c6b
2 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,68 @@
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local function start_moving(widget)
local mouse_coords = mouse.coords()
local offset_x = widget.x - mouse_coords.x
local offset_y = widget.y - mouse_coords.y
if not mousegrabber.isrunning() then
mousegrabber.run(function(coords)
widget.x = coords.x + offset_x
widget.y = coords.y + offset_y
return coords.buttons[3]
end,"plus")
end
end
return function(args)
local args = args or {}
local container_settings = {
screen = s,
bg = "#00000000",
visible = true,
type = "desktop",
height = args.height or 64,
width = args.width or 64,
x = args.x or 40,
y = args.y or 40
}
local widget = wibox.widget {
{
image = args.image,
resize = true,
widget = wibox.widget.imagebox,
id = "imagebox"
},
widget = wibox.widget.background,
layout = wibox.layout.fixed.vertical
}
container = wibox(container_settings)
widget:get_children_by_id("imagebox")[1]:connect_signal("button::press",
function(self,x,y,button)
if button == 1 then
awful.spawn(args.command)
elseif button == 3 then
start_moving(container)
elseif button == 4 then
container.height = container.height / 0.9
container.width = container.width / 0.9
elseif button == 5 then
container.height = container.height * 0.9
container.width = container.width * 0.9
end
end)
widget:get_children_by_id("imagebox")[1]:connect_signal("button::release",
function()
if mousegrabber.isrunning() then
mousegrabber.stop()
end
args.x = container.x
args.y = container.y
args.width = container.width
args.height = container.height
end)
container:set_widget(widget)
return container
end

54
widgets/stickers/init.lua Normal file
View File

@ -0,0 +1,54 @@
local dkjson = require("dkjson")
local handler = io.open(global.widget_config_dir.."stickers.json","r")
local stickers = {}
local objects = {}
if handler then
stickers = dkjson.decode(handler:read("*a") or "[]") or {}
end
local image = require("widgets.stickers.image")
return function(s)
objects.image = objects.image or {}
for id, args in pairs(stickers.image or {}) do
s["sticker_image"..tostring(args.id)] = image(args)
objects[args.type][args.id] = s["sticker_image"..tostring(args.id)]
end
awesome.connect_signal("stickers::add",function(x,y,h,w,cmd,t,arg)
if t == "image" then
stickers.image = stickers.image or {}
objects.image = objects.image or {}
local args = {
x = x,
y = y,
height = h,
width = w,
command = cmd,
image = arg,
type = "image",
id = #stickers.image+1
}
table.insert(stickers.image,args)
s["sticker_image"..tostring(#stickers.image)] = image(args)
objects.image[#stickers.image] = s["sticker_image"..tostring(#stickers.image)]
end
end)
awesome.connect_signal("stickers::remove",function(type,id)
if stickes[type] and stickers[type][id] then
stickers[type][id] = nil
objects[type][id] = nil
end
s["sticker_"..tostring(type)..tostring(id)] = nil
end)
awesome.connect_signal("stickers::save",function()
for type, obj_list in pairs(objects) do
for id, obj in pairs(obj_list) do
stickers[type][id].x = obj.x
stickers[type][id].y = obj.y
stickers[type][id].width = obj.width
stickers[type][id].height = obj.height
end
end
local handler = io.open(global.widget_config_dir.."stickers.json","w")
handler:write(dkjson.encode(stickers) or "")
handler:close()
end)
end