Skip to content

Instantly share code, notes, and snippets.

@skinnyjames
Created May 28, 2026 10:18
Show Gist options
  • Select an option

  • Save skinnyjames/e82ce6d0dbd5e9354a4b4b72a2a51db0 to your computer and use it in GitHub Desktop.

Select an option

Save skinnyjames/e82ce6d0dbd5e9354a4b4b72a2a51db0 to your computer and use it in GitHub Desktop.
testcam.rb
class ACamera < Hokusai::Block
template <<~EOF
[template]
empty { @click="add_filter" }
EOF
uses(empty: Hokusai::Blocks::Empty)
attr_accessor :lw, :lh, :texture, :camera
def initialize(**args)
@lw = nil
@lh = nil
@texture = nil
@camera = nil
@filter = false
super
end
def add_filter(event)
@filter = !@filter
end
def render(canvas)
if @camera.nil?
self.camera = ::V4L2::Camera.init("/dev/video0", canvas.width.to_i, canvas.height.to_i, ::V4L2::DESKTOP)
camera.open
# Use actual negotiated dimensions, not requested ones
self.lw = camera.width
self.lh = camera.height
self.texture = Hokusai::Texture.init(lw, lh)
self.texture.clear
end
if frame = self.camera.frame
self.texture.update(frame)
end
draw_with do |commands|
if @filter
commands.blend_mode_begin("multiply")
commands.rect(canvas.x, canvas.y, canvas.width, canvas.height) do |command|
command.color = Hokusai::Color.new(222,22,22)
end
end
commands.texture(@texture, canvas.x, canvas.y) do |command|
command.flip = false
end
commands.blend_mode_end if @filter
end
yield canvas
end
end
class Foo < Hokusai::Block
template do
child(ACamera) do
end
child(Hokusai::Blocks::Vblock) do
prop :background do
Hokusai::Color.new(22, 85, 130)
end
static :cursor, "'pointer'"
child(Hokusai::Blocks::Empty) do
on :click do |event|
args = [
"Yo boy sean :)",
0,
"dialog-information",
"Clicked!",
"#{event.pos.x}, #{event.pos.y}",
[],
{"image-path" => ["s", "/home/skinnyjames/smile.png"]},
0
]
notify.call("Notify", args)
end
end
end
end
attr_reader :notify
def initialize(**args)
@notify = SDBus.user.service("org.freedesktop.Notifications")
.object("/org/freedesktop/Notifications")
.interface("org.freedesktop.Notifications")
@notify.meta
super
end
end
class App < Hokusai::Block
template do
child(Foo) do
end
end
end
Hokusai::Backend.run(App) do |config|
config.title = "SDBus Test"
config.height = 800
config.width = 500
config.fps = 60
config.after_load do
Hokusai.fonts.register "default", Hokusai::Backend::Font.default
Hokusai.fonts.activate "default"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment