Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/lua/pinnacle-api-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ build = {
["pinnacle.snowcap.snowcap.input.keys"] = "pinnacle/snowcap/snowcap/input/keys.lua",
["pinnacle.snowcap.snowcap.widget"] = "pinnacle/snowcap/snowcap/widget.lua",
["pinnacle.snowcap.snowcap.widget.operation"] = "pinnacle/snowcap/snowcap/widget/operation.lua",
["pinnacle.snowcap.snowcap.widget.base"] = "pinnacle/snowcap/snowcap/widget/base.lua",
["pinnacle.snowcap.snowcap.widget.signal"] = "pinnacle/snowcap/snowcap/widget/signal.lua",
["pinnacle.snowcap.snowcap.layer"] = "pinnacle/snowcap/snowcap/layer.lua",
["pinnacle.snowcap.snowcap.decoration"] = "pinnacle/snowcap/snowcap/decoration.lua",
["pinnacle.snowcap.snowcap.popup"] = "pinnacle/snowcap/snowcap/popup.lua",
["pinnacle.snowcap.snowcap.signal"] = "pinnacle/snowcap/snowcap/signal.lua",
["pinnacle.snowcap.snowcap.util"] = "pinnacle/snowcap/snowcap/util.lua",
["pinnacle.snowcap.snowcap.log"] = "pinnacle/snowcap/snowcap/log.lua",
},
Expand Down
53 changes: 43 additions & 10 deletions api/lua/pinnacle/snowcap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ local snowcap = {
---The height of the prompt.
---@field height integer
local QuitPrompt = {}
setmetatable(QuitPrompt, { __index = require("snowcap.widget.base").Base })

---An overlay that shows various input binds.
---@class pinnacle.snowcap.integration.BindOverlay : snowcap.widget.Program
Expand All @@ -65,6 +66,7 @@ local QuitPrompt = {}
---The height of the overlay.
---@field height integer
local BindOverlay = {}
setmetatable(BindOverlay, { __index = require("snowcap.widget.base").Base })

---A border that shows window focus, with an optional titlebar.
---@class pinnacle.snowcap.integration.FocusBorder : snowcap.widget.Program
Expand All @@ -85,6 +87,7 @@ local BindOverlay = {}
---The height of the titlebar
---@field titlebar_height integer
local FocusBorder = {}
setmetatable(FocusBorder, { __index = require("snowcap.widget.base").Base })

function QuitPrompt:view()
local Widget = require("snowcap.widget")
Expand Down Expand Up @@ -644,7 +647,9 @@ function FocusBorder:view()
if self.include_titlebar then
local titlebar = Widget.container({
style = {
background = Widget.background.Color(self.focused and self.focused_color or self.unfocused_color),
background = Widget.background.Color(
self.focused and self.focused_color or self.unfocused_color
),
},
padding = {
top = self.thickness,
Expand Down Expand Up @@ -927,6 +932,9 @@ end
function integration.quit_prompt()
local Widget = require("snowcap.widget")

local base = require("snowcap.widget.base").Base.new()
setmetatable(base, { __index = QuitPrompt })

---@type pinnacle.snowcap.integration.QuitPrompt
local prompt = {
border_radius = 12.0,
Expand All @@ -940,9 +948,13 @@ function integration.quit_prompt()
height = 120,
}

setmetatable(prompt, { __index = QuitPrompt })
for k, v in pairs(prompt) do
base[k] = v
end

return prompt
---@cast base pinnacle.snowcap.integration.QuitPrompt

return base
end

---Creates the default bind overlay.
Expand All @@ -953,8 +965,11 @@ end
function integration.bind_overlay()
local Widget = require("snowcap.widget")

local base = require("snowcap.widget.base").Base.new()
setmetatable(base, { __index = BindOverlay })

---@type pinnacle.snowcap.integration.BindOverlay
local prompt = {
local overlay = {
border_radius = 12.0,
border_thickness = 6.0,
background_color = Widget.color.from_rgba(0.15, 0.15, 0.225, 0.8),
Expand All @@ -966,9 +981,13 @@ function integration.bind_overlay()
height = 500,
}

setmetatable(prompt, { __index = BindOverlay })
for k, v in pairs(overlay) do
base[k] = v
end

---@cast base pinnacle.snowcap.integration.BindOverlay

return prompt
return base
end

---Creates the default focus border without a titlebar.
Expand All @@ -979,6 +998,9 @@ end
function integration.focus_border(window)
local Widget = require("snowcap.widget")

local base = require("snowcap.widget.base").Base.new()
setmetatable(base, { __index = FocusBorder })

---@type pinnacle.snowcap.integration.FocusBorder
local border = {
window = window,
Expand All @@ -991,9 +1013,13 @@ function integration.focus_border(window)
titlebar_height = 0,
}

setmetatable(border, { __index = FocusBorder })
for k, v in pairs(border) do
base[k] = v
end

---@cast base pinnacle.snowcap.integration.FocusBorder

return border
return base
end

---Creates the default focus border with a titlebar.
Expand All @@ -1004,6 +1030,9 @@ end
function integration.focus_border_with_titlebar(window)
local Widget = require("snowcap.widget")

local base = require("snowcap.widget.base").Base.new()
setmetatable(base, { __index = FocusBorder })

---@type pinnacle.snowcap.integration.FocusBorder
local border = {
window = window,
Expand All @@ -1016,9 +1045,13 @@ function integration.focus_border_with_titlebar(window)
titlebar_height = 16,
}

setmetatable(border, { __index = FocusBorder })
for k, v in pairs(border) do
base[k] = v
end

---@cast base pinnacle.snowcap.integration.FocusBorder

return border
return base
end

return snowcap
3 changes: 3 additions & 0 deletions snowcap/api/lua/snowcap-api-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ build = {
["snowcap.input.keys"] = "snowcap/input/keys.lua",
["snowcap.widget"] = "snowcap/widget.lua",
["snowcap.widget.operation"] = "snowcap/widget/operation.lua",
["snowcap.widget.base"] = "snowcap/widget/base.lua",
["snowcap.widget.signal"] = "snowcap/widget/signal.lua",
["snowcap.layer"] = "snowcap/layer.lua",
["snowcap.decoration"] = "snowcap/decoration.lua",
["snowcap.popup"] = "snowcap/popup.lua",
["snowcap.signal"] = "snowcap/signal.lua",
["snowcap.util"] = "snowcap/util.lua",
["snowcap.log"] = "snowcap/log.lua",
},
Expand Down
39 changes: 26 additions & 13 deletions snowcap/api/lua/snowcap/decoration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local log = require("snowcap.log")
local client = require("snowcap.grpc.client").client

local widget = require("snowcap.widget")
local widget_signal = require("snowcap.widget.signal")

---@class snowcap.decoration
local decoration = {}
Expand All @@ -18,7 +19,7 @@ local decoration_handle = {}
local DecorationHandle = {}

---@param id integer
---@param update fun(msg: any)
---@param update fun(msg: any?)
---@return snowcap.decoration.DecorationHandle
function decoration_handle.new(id, update)
---@type snowcap.decoration.DecorationHandle
Expand Down Expand Up @@ -79,6 +80,29 @@ function decoration.new_widget(args)

local decoration_id = response.decoration_id or 0

---@type fun(msg: any?)
local update_on_msg = function(msg)
if msg ~= nil then
args.program:update(msg)
end

---@diagnostic disable-next-line: redefined-local
local _, err = client:snowcap_decoration_v1_DecorationService_RequestView({
decoration_id = decoration_id,
})

if err then
log.error(err)
end
end

args.program:connect(widget_signal.redraw_needed, update_on_msg)
args.program:connect(widget_signal.send_message, update_on_msg)

local handle = decoration_handle.new(decoration_id, update_on_msg)

args.program:created(widget.SurfaceHandle.from_decoration_handle(handle))

local err = client:snowcap_widget_v1_WidgetService_GetWidgetEvents({
decoration_id = decoration_id,
}, function(response)
Expand Down Expand Up @@ -107,18 +131,7 @@ function decoration.new_widget(args)
})
end)

return decoration_handle.new(decoration_id, function(msg)
args.program:update(msg)

---@diagnostic disable-next-line: redefined-local
local _, err = client:snowcap_decoration_v1_DecorationService_RequestView({
decoration_id = decoration_id,
})

if err then
log.error(err)
end
end)
return handle
end

---Convert a DecorationHandle into a Popup's ParentHandle
Expand Down
41 changes: 27 additions & 14 deletions snowcap/api/lua/snowcap/layer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local log = require("snowcap.log")
local client = require("snowcap.grpc.client").client

local widget = require("snowcap.widget")
local widget_signal = require("snowcap.widget.signal")

---@class snowcap.layer
local layer = {}
Expand All @@ -24,7 +25,7 @@ function LayerHandle:as_parent()
end

---@param id integer
---@param update fun(msg: any)
---@param update fun(msg: any?)
---@return snowcap.layer.LayerHandle
function layer_handle.new(id, update)
---@type snowcap.layer.LayerHandle
Expand Down Expand Up @@ -122,7 +123,30 @@ function layer.new_widget(args)
return nil
end

local layer_id = response.layer_id
local layer_id = response.layer_id or 0

---@type fun(msg: any?)
local update_on_msg = function(msg)
if msg ~= nil then
args.program:update(msg)
end

---@diagnostic disable-next-line: redefined-local
local _, err = client:snowcap_layer_v1_LayerService_RequestView({
layer_id = layer_id,
})

if err then
log.error(err)
end
end

args.program:connect(widget_signal.redraw_needed, update_on_msg)
args.program:connect(widget_signal.send_message, update_on_msg)
Comment thread
Ottatop marked this conversation as resolved.

local handle = layer_handle.new(layer_id, update_on_msg)

args.program:created(widget.SurfaceHandle.from_layer_handle(handle))

local err = client:snowcap_widget_v1_WidgetService_GetWidgetEvents({
layer_id = layer_id,
Expand Down Expand Up @@ -152,18 +176,7 @@ function layer.new_widget(args)
})
end)

return layer_handle.new(layer_id, function(msg)
args.program:update(msg)

---@diagnostic disable-next-line: redefined-local
local _, err = client:snowcap_layer_v1_LayerService_RequestView({
layer_id = layer_id,
})

if err then
log.error(err)
end
end)
return handle
end

---Do something when a key event is received.
Expand Down
37 changes: 25 additions & 12 deletions snowcap/api/lua/snowcap/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local log = require("snowcap.log")
local client = require("snowcap.grpc.client").client

local widget = require("snowcap.widget")
local widget_signal = require("snowcap.widget.signal")

---Support for popup surface widgets using `xdg-shell::xdg_popup`
---@class snowcap.popup
Expand Down Expand Up @@ -257,6 +258,29 @@ function popup.new_widget(args)

local popup_id = response.popup_id --[[@as integer]]

---@type fun(msg: any?)
local update_on_msg = function(msg)
if msg ~= nil then
args.program:update(msg)
end

---@diagnostic disable-next-line: redefined-local
local _, err = client:snowcap_popup_v1_PopupService_RequestView({
popup_id = popup_id,
})

if err then
log.error(err)
end
end

args.program:connect(widget_signal.redraw_needed, update_on_msg)
args.program:connect(widget_signal.send_message, update_on_msg)

local handle = popup_handle.new(popup_id, update_on_msg)

args.program:created(widget.SurfaceHandle.from_popup_handle(handle))

err = client:snowcap_widget_v1_WidgetService_GetWidgetEvents({
popup_id = popup_id,
}, function(response) ---@diagnostic disable-line:redefined-local
Expand Down Expand Up @@ -291,18 +315,7 @@ function popup.new_widget(args)
end
end)

return popup_handle.new(popup_id, function(msg)
args.program:update(msg)

---@diagnostic disable-next-line: redefined-local
local _, err = client:snowcap_popup_v1_PopupService_RequestView({
popup_id = popup_id,
})

if err then
log.error(err)
end
end)
return handle
end

---Do something when a key event is received.
Expand Down
Loading
Loading