Class: RBGL::GUI::Wayland::Backend
- Inherits:
-
Backend
- Object
- Backend
- RBGL::GUI::Wayland::Backend
show all
- Defined in:
- lib/rbgl/gui/wayland/backend.rb
Constant Summary
collapse
- BUFFER_WAIT_TIMEOUT =
0.25
- BUFFER_POLL_INTERVAL =
0.016
Instance Attribute Summary
Attributes inherited from Backend
#height, #title, #width
Instance Method Summary
collapse
Methods inherited from Backend
#metal_available?, #native_handle, #poll_events_raw, #set_pixels
Constructor Details
#initialize(width, height, title = "RBGL", env: ENV, roundtrip_timeout: Connection::DEFAULT_ROUNDTRIP_TIMEOUT) ⇒ Backend
Returns a new instance of Backend.
12
13
14
15
16
17
|
# File 'lib/rbgl/gui/wayland/backend.rb', line 12
def initialize(width, height, title = "RBGL", env: ENV, roundtrip_timeout: Connection::DEFAULT_ROUNDTRIP_TIMEOUT)
super(width, height, title)
@connection = Connection.new(env: env, roundtrip_timeout: roundtrip_timeout)
@windows = {}
setup_window(width, height, title)
end
|
Instance Method Details
#close ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/rbgl/gui/wayland/backend.rb', line 96
def close
return unless @handle
window = @windows[@handle]
return unless window
window[:should_close] = true
window[:toplevel].destroy
window[:xdg_surface].destroy
window[:surface].destroy
window.fetch(:buffers, [window[:shm_buffer]].compact).each(&:destroy)
@windows.delete(@handle)
@handle = nil
end
|
#poll_events ⇒ Object
69
70
71
|
# File 'lib/rbgl/gui/wayland/backend.rb', line 69
def poll_events
@connection.dispatch_pending.filter_map { |event| convert_event(event) }
end
|
#present(framebuffer) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/rbgl/gui/wayland/backend.rb', line 48
def present(framebuffer)
return false unless @handle
window = @windows[@handle]
return false unless window
buffer_object = wait_for_available_buffer(window)
return false unless buffer_object
buffer = convert_to_wayland_format(framebuffer)
buffer_object.write(buffer)
window[:surface].damage(0, 0, framebuffer.width, framebuffer.height)
window[:surface].attach(buffer_object, 0, 0)
buffer_object.mark_in_use
window[:shm_buffer] = buffer_object
window[:surface].commit
@connection.flush
true
end
|
#resize(width, height) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/rbgl/gui/wayland/backend.rb', line 73
def resize(width, height)
super
return unless @handle
window = @windows[@handle]
return unless window
return if window[:width] == width && window[:height] == height
old_buffers = window.fetch(:buffers, [window[:shm_buffer]].compact)
new_buffers = create_shm_buffers(width, height)
window[:buffers] = new_buffers
window[:shm_buffer] = new_buffers.first
window[:width] = width
window[:height] = height
old_buffers.each(&:destroy)
end
|
#should_close? ⇒ Boolean
90
91
92
93
94
|
# File 'lib/rbgl/gui/wayland/backend.rb', line 90
def should_close?
return false unless @handle
@windows[@handle]&.[](:should_close) || false
end
|