Class: RBGL::GUI::X11::Connection
- Inherits:
-
Object
- Object
- RBGL::GUI::X11::Connection
- Defined in:
- lib/rbgl/gui/x11/connection.rb
Instance Attribute Summary collapse
-
#black_pixel ⇒ Object
readonly
Returns the value of attribute black_pixel.
-
#default_screen ⇒ Object
readonly
Returns the value of attribute default_screen.
-
#resource_id_base ⇒ Object
readonly
Returns the value of attribute resource_id_base.
-
#resource_id_mask ⇒ Object
readonly
Returns the value of attribute resource_id_mask.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#root_depth ⇒ Object
readonly
Returns the value of attribute root_depth.
-
#root_visual ⇒ Object
readonly
Returns the value of attribute root_visual.
-
#white_pixel ⇒ Object
readonly
Returns the value of attribute white_pixel.
Instance Method Summary collapse
- #atom(name) ⇒ Object
- #change_property(window, property, type, data, mode: :replace, format: 8) ⇒ Object
- #create_gc(gc_id, drawable, values = {}) ⇒ Object
- #create_window(depth:, wid:, parent:, x:, y:, width:, height:, border_width:, window_class:, visual:, value_mask:, values:) ⇒ Object
- #destroy_window(wid) ⇒ Object
- #enable_wm_delete_window(window) ⇒ Object
- #flush ⇒ Object
- #generate_id ⇒ Object
-
#initialize(display_name) ⇒ Connection
constructor
A new instance of Connection.
- #intern_atom(name, only_if_exists: false) ⇒ Object
- #map_window(wid) ⇒ Object
- #next_event ⇒ Object
- #pending ⇒ Object
- #put_image(format:, drawable:, gc:, width:, height:, dst_x:, dst_y:, depth:, data:) ⇒ Object
- #read_events ⇒ Object
- #wm_delete_window_atom ⇒ Object
- #wm_protocols_atom ⇒ Object
Constructor Details
#initialize(display_name) ⇒ Connection
Returns a new instance of Connection.
17 18 19 20 21 22 23 24 25 |
# File 'lib/rbgl/gui/x11/connection.rb', line 17 def initialize(display_name) host, display_num, _screen_num = parse_display_name(display_name) @socket = connect(host, display_num) @transport = Transport.new(@socket) @resource_id_counter = 0 @pending_events = [] handshake end |
Instance Attribute Details
#black_pixel ⇒ Object (readonly)
Returns the value of attribute black_pixel.
15 16 17 |
# File 'lib/rbgl/gui/x11/connection.rb', line 15 def black_pixel @black_pixel end |
#default_screen ⇒ Object (readonly)
Returns the value of attribute default_screen.
14 15 16 |
# File 'lib/rbgl/gui/x11/connection.rb', line 14 def default_screen @default_screen end |
#resource_id_base ⇒ Object (readonly)
Returns the value of attribute resource_id_base.
14 15 16 |
# File 'lib/rbgl/gui/x11/connection.rb', line 14 def resource_id_base @resource_id_base end |
#resource_id_mask ⇒ Object (readonly)
Returns the value of attribute resource_id_mask.
14 15 16 |
# File 'lib/rbgl/gui/x11/connection.rb', line 14 def resource_id_mask @resource_id_mask end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
15 16 17 |
# File 'lib/rbgl/gui/x11/connection.rb', line 15 def root @root end |
#root_depth ⇒ Object (readonly)
Returns the value of attribute root_depth.
15 16 17 |
# File 'lib/rbgl/gui/x11/connection.rb', line 15 def root_depth @root_depth end |
#root_visual ⇒ Object (readonly)
Returns the value of attribute root_visual.
15 16 17 |
# File 'lib/rbgl/gui/x11/connection.rb', line 15 def root_visual @root_visual end |
#white_pixel ⇒ Object (readonly)
Returns the value of attribute white_pixel.
15 16 17 |
# File 'lib/rbgl/gui/x11/connection.rb', line 15 def white_pixel @white_pixel end |
Instance Method Details
#atom(name) ⇒ Object
40 41 42 |
# File 'lib/rbgl/gui/x11/connection.rb', line 40 def atom(name) atom_cache.fetch(name) end |
#change_property(window, property, type, data, mode: :replace, format: 8) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rbgl/gui/x11/connection.rb', line 107 def change_property(window, property, type, data, mode: :replace, format: 8) property_atom = atom(property) type_atom = atom(type) mode_val, request = request_encoder.change_property_data( window, property_atom, type_atom, data, mode: mode, format: format ) send_request(18, request, mode_val) end |
#create_gc(gc_id, drawable, values = {}) ⇒ Object
87 88 89 90 |
# File 'lib/rbgl/gui/x11/connection.rb', line 87 def create_gc(gc_id, drawable, values = {}) request = request_encoder.create_gc_data(gc_id, drawable, values) send_request(55, request) end |
#create_window(depth:, wid:, parent:, x:, y:, width:, height:, border_width:, window_class:, visual:, value_mask:, values:) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rbgl/gui/x11/connection.rb', line 60 def create_window(depth:, wid:, parent:, x:, y:, width:, height:, border_width:, window_class:, visual:, value_mask:, values:) request = request_encoder.create_window_data( depth: depth, wid: wid, parent: parent, x: x, y: y, width: width, height: height, border_width: border_width, window_class: window_class, visual: visual, value_mask: value_mask, values: values ) send_request(1, request) end |
#destroy_window(wid) ⇒ Object
83 84 85 |
# File 'lib/rbgl/gui/x11/connection.rb', line 83 def destroy_window(wid) send_request(4, [wid].pack("V")) end |
#enable_wm_delete_window(window) ⇒ Object
52 53 54 |
# File 'lib/rbgl/gui/x11/connection.rb', line 52 def enable_wm_delete_window(window) change_property(window, :wm_protocols, :atom, [wm_delete_window_atom], format: 32) end |
#flush ⇒ Object
36 37 38 |
# File 'lib/rbgl/gui/x11/connection.rb', line 36 def flush transport.flush end |
#generate_id ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/rbgl/gui/x11/connection.rb', line 27 def generate_id masked_counter = @resource_id_counter & @resource_id_mask raise GUI::BackendUnavailable, "X11 resource ID space exhausted" if masked_counter != @resource_id_counter id = @resource_id_base | masked_counter @resource_id_counter += 1 id end |
#intern_atom(name, only_if_exists: false) ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rbgl/gui/x11/connection.rb', line 121 def intern_atom(name, only_if_exists: false) request = request_encoder.intern_atom_data(name) send_request(16, request, only_if_exists ? 1 : 0) flush reply = read_reply return 0 unless reply reply[8, 4].unpack1("V") end |
#map_window(wid) ⇒ Object
79 80 81 |
# File 'lib/rbgl/gui/x11/connection.rb', line 79 def map_window(wid) send_request(8, [wid].pack("V")) end |
#next_event ⇒ Object
132 133 134 135 136 137 |
# File 'lib/rbgl/gui/x11/connection.rb', line 132 def next_event return @pending_events.shift unless @pending_events.empty? read_events @pending_events.shift end |
#pending ⇒ Object
56 57 58 |
# File 'lib/rbgl/gui/x11/connection.rb', line 56 def pending transport.pending end |
#put_image(format:, drawable:, gc:, width:, height:, dst_x:, dst_y:, depth:, data:) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rbgl/gui/x11/connection.rb', line 92 def put_image(format:, drawable:, gc:, width:, height:, dst_x:, dst_y:, depth:, data:) format_byte, header, image_data = request_encoder.put_image_data( format: format, drawable: drawable, gc: gc, width: width, height: height, dst_x: dst_x, dst_y: dst_y, depth: depth, data: data ) send_request_with_data(72, format_byte, header, image_data) end |
#read_events ⇒ Object
139 140 141 142 143 144 |
# File 'lib/rbgl/gui/x11/connection.rb', line 139 def read_events while pending > 0 event = read_event @pending_events << event if event end end |
#wm_delete_window_atom ⇒ Object
44 45 46 |
# File 'lib/rbgl/gui/x11/connection.rb', line 44 def wm_delete_window_atom atom(:wm_delete_window) end |
#wm_protocols_atom ⇒ Object
48 49 50 |
# File 'lib/rbgl/gui/x11/connection.rb', line 48 def wm_protocols_atom atom(:wm_protocols) end |