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
4 changes: 4 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type Keyboard struct {
p *C.struct_wlr_keyboard
}

func (k Keyboard) Valid() bool {
return k.p != nil
}

func (k Keyboard) Base() InputDevice {
return InputDevice{p: &k.p.base}
}
Expand Down
15 changes: 12 additions & 3 deletions renderpass.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ package wlr

/*
#include <wlr/render/pass.h>

// cgo lets Go pass a pointer to Go memory into C only if that memory
// holds no unpinned Go pointers. options is Go memory, so pointing
// options->alpha at a Go variable makes the cgo pointer check panic.
// Taking alpha by value and pointing at the C parameter avoids that.
// The pointer only has to outlive the call: every renderer reads alpha
// during wlr_render_pass_add_texture and doesn't keep options.
static inline void _wlr_render_pass_add_texture(struct wlr_render_pass *pass, struct wlr_render_texture_options *options, float alpha) {
options->alpha = &alpha;
wlr_render_pass_add_texture(pass, options);
}
Comment thread
DeedleFake marked this conversation as resolved.
Resolved
*/
import "C"

Expand Down Expand Up @@ -37,7 +48,6 @@ func (r RenderPass) Submit() bool {
}

func (r RenderPass) AddTexture(texture Texture, srcBox image.Rectangle, dstBox image.Rectangle, alpha float32, transform OutputTransform, filterMode FilterMode, blendMode BlendMode) {
var alphaC C.float = C.float(alpha)
var options C.struct_wlr_render_texture_options
options.texture = texture.p
if srcBox != (image.Rectangle{}) {
Expand All @@ -46,11 +56,10 @@ func (r RenderPass) AddTexture(texture Texture, srcBox image.Rectangle, dstBox i
if dst := boxToC(dstBox); dst != nil {
options.dst_box = *dst
}
options.alpha = &alphaC
options.transform = C.enum_wl_output_transform(transform)
options.filter_mode = C.enum_wlr_scale_filter_mode(filterMode)
options.blend_mode = C.enum_wlr_render_blend_mode(blendMode)
C.wlr_render_pass_add_texture(r.p, &options)
C._wlr_render_pass_add_texture(r.p, &options, C.float(alpha))
}

func (r RenderPass) AddRect(box image.Rectangle, c color.Color, blendMode BlendMode) {
Expand Down
6 changes: 6 additions & 0 deletions surface.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func (s Surface) OnUnmap(cb func(Surface)) Listener {
})
}

func (s Surface) OnCommit(cb func(Surface)) Listener {
return newListener(&s.p.events.commit, func(lis Listener, data unsafe.Pointer) {
cb(s)
})
}

func (s Surface) OnDestroy(cb func(Surface)) Listener {
return newListener(&s.p.events.destroy, func(lis Listener, data unsafe.Pointer) {
cb(s)
Expand Down
22 changes: 22 additions & 0 deletions xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ func (s XDGSurface) HasSurface(sub Surface) bool {
return C._wlr_xdg_surface_has_surface(s.p, sub.p) != 0
}

// Initialized returns true once the client has made its initial
// commit. Configure events, including those sent by setting toplevel
// state, can't be sent before that.
func (s XDGSurface) Initialized() bool {
return bool(s.p.initialized)
}

// InitialCommit returns true if the commit currently being handled is
// the surface's initial commit.
func (s XDGSurface) InitialCommit() bool {
return bool(s.p.initial_commit)
}

func (s XDGSurface) Role() XDGSurfaceRole {
return XDGSurfaceRole(s.p.role)
}
Expand Down Expand Up @@ -215,6 +228,15 @@ type XDGToplevel struct {
p *C.struct_wlr_xdg_toplevel
}

// OnDestroy is called when the toplevel role object is destroyed. This
// happens before the base XDGSurface's destroy event, and listeners on
// the toplevel must be removed by then.
func (t XDGToplevel) OnDestroy(cb func(XDGToplevel)) Listener {
return newListener(&t.p.events.destroy, func(lis Listener, data unsafe.Pointer) {
cb(t)
})
}

func (t XDGToplevel) OnRequestMove(cb func(t XDGToplevel, client SeatClient, serial uint32)) Listener {
return newListener(&t.p.events.request_move, func(lis Listener, data unsafe.Pointer) {
event := (*C.struct_wlr_xdg_toplevel_move_event)(data)
Expand Down
18 changes: 18 additions & 0 deletions xwayland.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ func (s XwaylandSurface) OnDestroy(cb func(XwaylandSurface)) Listener {
})
}

// OnAssociate is called when the X11 window is paired with a
// wlr_surface. Surface returns an invalid Surface until then, so
// listeners on the Surface, such as OnMap, should be added here.
func (s XwaylandSurface) OnAssociate(cb func(XwaylandSurface)) Listener {
return newListener(&s.p.events.associate, func(lis Listener, data unsafe.Pointer) {
cb(s)
})
}

// OnDissociate is called when the X11 window is about to lose its
// wlr_surface. Listeners added to the Surface in OnAssociate should be
// removed here.
func (s XwaylandSurface) OnDissociate(cb func(XwaylandSurface)) Listener {
return newListener(&s.p.events.dissociate, func(lis Listener, data unsafe.Pointer) {
cb(s)
})
}

func (s XwaylandSurface) OnRequestMove(cb func(surface XwaylandSurface)) Listener {
return newListener(&s.p.events.request_move, func(lis Listener, data unsafe.Pointer) {
cb(s)
Expand Down
Loading