Class: RBGL::GUI::Wayland::Connection
- Inherits:
-
Object
- Object
- RBGL::GUI::Wayland::Connection
- Defined in:
- lib/rbgl/gui/wayland/connection.rb
Constant Summary collapse
- DEFAULT_ROUNDTRIP_TIMEOUT =
1.0- ROUNDTRIP_POLL_INTERVAL =
0.01
Instance Attribute Summary collapse
-
#compositor ⇒ Object
readonly
Returns the value of attribute compositor.
-
#globals ⇒ Object
readonly
Returns the value of attribute globals.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#shm ⇒ Object
readonly
Returns the value of attribute shm.
-
#xdg_wm_base ⇒ Object
readonly
Returns the value of attribute xdg_wm_base.
Instance Method Summary collapse
- #allocate_id ⇒ Object
- #dispatch_pending ⇒ Object
- #flush ⇒ Object
-
#initialize(env: ENV, socket_path: nil, roundtrip_timeout: DEFAULT_ROUNDTRIP_TIMEOUT) ⇒ Connection
constructor
A new instance of Connection.
- #object_for(object_id) ⇒ Object
- #pump_events(timeout: nil) ⇒ Object
- #queue_event(event) ⇒ Object
- #register_object(object) ⇒ Object
- #roundtrip ⇒ Object
- #send_request(object_id, opcode, *args) ⇒ Object
- #send_request_with_fd(object_id, opcode, *args, fd) ⇒ Object
- #store_global(interface, name:, version:) ⇒ Object
Constructor Details
#initialize(env: ENV, socket_path: nil, roundtrip_timeout: DEFAULT_ROUNDTRIP_TIMEOUT) ⇒ Connection
Returns a new instance of Connection.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 18 def initialize(env: ENV, socket_path: nil, roundtrip_timeout: DEFAULT_ROUNDTRIP_TIMEOUT) @env = env @roundtrip_timeout = roundtrip_timeout @socket = UNIXSocket.new(resolve_socket_path(socket_path)) @objects = {} @next_id = 2 @globals = {} @pending_events = [] @display = Display.new(self) register_object(@display) @registry = @display.get_registry flush roundtrip bind_globals end |
Instance Attribute Details
#compositor ⇒ Object (readonly)
Returns the value of attribute compositor.
16 17 18 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 16 def compositor @compositor end |
#globals ⇒ Object (readonly)
Returns the value of attribute globals.
16 17 18 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 16 def globals @globals end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
16 17 18 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 16 def registry @registry end |
#shm ⇒ Object (readonly)
Returns the value of attribute shm.
16 17 18 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 16 def shm @shm end |
#xdg_wm_base ⇒ Object (readonly)
Returns the value of attribute xdg_wm_base.
16 17 18 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 16 def xdg_wm_base @xdg_wm_base end |
Instance Method Details
#allocate_id ⇒ Object
37 38 39 40 41 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 37 def allocate_id id = @next_id @next_id += 1 id end |
#dispatch_pending ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 77 def dispatch_pending pump_events(timeout: 0) events = @pending_events @pending_events = [] events end |
#flush ⇒ Object
73 74 75 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 73 def flush @socket.flush end |
#object_for(object_id) ⇒ Object
48 49 50 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 48 def object_for(object_id) @objects[object_id] end |
#pump_events(timeout: nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 85 def pump_events(timeout: nil) ready = IO.select([@socket], nil, nil, timeout) return 0 unless ready loop do header = @socket.read(8) break unless header && header.bytesize == 8 object_id, size_and_opcode = header.unpack("VV") size = size_and_opcode >> 16 opcode = size_and_opcode & 0xFFFF payload = size > 8 ? @socket.read(size - 8) : "" handle_event(object_id, opcode, payload) break unless IO.select([@socket], nil, nil, 0) end @pending_events.length end |
#queue_event(event) ⇒ Object
56 57 58 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 56 def queue_event(event) @pending_events << event end |
#register_object(object) ⇒ Object
43 44 45 46 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 43 def register_object(object) @objects[object.id] = object object end |
#roundtrip ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 105 def roundtrip callback = @display.sync @objects[callback.id] = callback flush deadline = monotonic_time + @roundtrip_timeout until callback.done? raise BackendUnavailable, "Wayland roundtrip timed out" if monotonic_time >= deadline pump_events(timeout: roundtrip_poll_interval(deadline)) end end |
#send_request(object_id, opcode, *args) ⇒ Object
60 61 62 63 64 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 60 def send_request(object_id, opcode, *args) payload = pack_args(args) header = [object_id, (payload.bytesize + 8) << 16 | opcode].pack("VV") @socket.write(header + payload) end |
#send_request_with_fd(object_id, opcode, *args, fd) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 66 def send_request_with_fd(object_id, opcode, *args, fd) payload = pack_args(args) header = [object_id, (payload.bytesize + 8) << 16 | opcode].pack("VV") @socket.sendmsg(header + payload, 0, nil, Socket::AncillaryData.unix_rights(fd)) end |
#store_global(interface, name:, version:) ⇒ Object
52 53 54 |
# File 'lib/rbgl/gui/wayland/connection.rb', line 52 def store_global(interface, name:, version:) @globals[interface] = { name: name, version: version } end |