~sircmpwn/gdwlroots

ref: 07803cabba84175954dd129338ef18c5dba5b9e5 gdwlroots/threeston/prefabs/surface/Surface_Node2D.gd -rw-r--r-- 1.3 KiB
07803cabDrew DeVault Move threeston into VR 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
extends Node2D

export var xdg_surface: WlrXdgSurface = null setget _xdg_surface_set
var toplevel: WlrXdgToplevel

signal map(surface)
signal unmap(surface)

func _xdg_surface_set(val):
	if xdg_surface != null:
		xdg_surface.disconnect("destroy", self, "_on_xdg_surface_destroy")
		xdg_surface.disconnect("map", self, "_on_xdg_surface_map")
		xdg_surface.disconnect("unmap", self, "_on_xdg_surface_unmap")
	xdg_surface = val
	xdg_surface.connect("destroy", self, "_on_xdg_surface_destroy")
	xdg_surface.connect("map", self, "_on_xdg_surface_map")
	xdg_surface.connect("unmap", self, "_on_xdg_surface_unmap")

func _on_xdg_surface_destroy(xdg_surface):
	pass # TODO
	
func _on_xdg_surface_map(xdg_surface):
	set_process(true)
	emit_signal("map", self)
	
func _on_xdg_surface_unmap(xdg_surface):
	set_process(false)
	emit_signal("unmap", self)

func _process(delta):
	update()

func _draw_surface(surface, sx, sy):
	var texture = surface.get_texture()
	if texture == null:
		return
	var state = xdg_surface.get_wlr_surface().get_current_state()
	draw_rect(Rect2(0, 0, get_viewport().size.x, get_viewport().size.y), Color.red)
	draw_texture(texture, Vector2(0, 0))
	surface.send_frame_done()

func _draw():
	if xdg_surface != null:
		var fn = funcref(self, "_draw_surface")
		xdg_surface.for_each_surface(fn)