Class: X11::Display
- Inherits:
-
Object
- Object
- X11::Display
- Defined in:
- lib/X11/display.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
- #atom(name) ⇒ Object
- #atom_enum(val) ⇒ Object
- #change_gc ⇒ Object
- #change_property(mode, window, property, type, format, data) ⇒ Object
- #change_save_set ⇒ Object
- #change_window_attributes(wid, values: {}) ⇒ Object
- #clear_area(*args) ⇒ Object
- #client_message(window: default_root, type: :ClientMessage, format: 32, destination: default_root, mask: 0, data: [], propagate: true) ⇒ Object
- #close ⇒ Object
- #configure_window(window, x: nil, y: nil, width: nil, height: nil, border_width: nil, sibling: nil, stack_mode: nil) ⇒ Object
- #copy_area(*args) ⇒ Object
- #create_colormap(alloc, window, visual) ⇒ Object
- #create_gc(window, foreground: nil, background: nil, graphics_exposures: nil) ⇒ Object
- #create_pixmap(depth, drawable, w, h) ⇒ Object
-
#create_window(x, y, w, h, values: {}, depth: 32, parent: nil, border_width: 0, wclass: X11::Form::InputOutput, visual: nil) ⇒ Object
Requests.
- #default_root ⇒ Object
- #destroy_window(window) ⇒ Object
- #display_info ⇒ Object
- #event_handler=(block) ⇒ Object
- #find_visual(screen, depth, qlass = 4) ⇒ Object
- #flush ⇒ Object
- #free_pixmap(pixmap) ⇒ Object
- #get_atom_name(atom) ⇒ Object
- #get_geometry(drawable) ⇒ Object
- #get_keyboard_mapping(min_keycode = display_info.min_keycode, count = display_info.max_keycode - min_keycode) ⇒ Object
- #get_property(window, property, type, offset: 0, length: 4, delete: false) ⇒ Object
-
#get_selection_owner(selection) ⇒ Object
Get the current owner of a selection selection: the selection atom Returns: the window ID of the owner, or None (0) if there is no owner.
- #get_window_attributes(wid) ⇒ Object
- #grab_button(owner_events, grab_window, event_mask, pointer_mode, keyboard_mode, confine_to, cursor, button, modifiers) ⇒ Object
- #grab_key(owner_events, grab_window, modifiers, keycode, pointer_mode, keyboard_mode) ⇒ Object
- #image_text16(*args) ⇒ Object
- #image_text8(*args) ⇒ Object
-
#initialize(target = ENV['DISPLAY']) ⇒ Display
constructor
Open a connection to the specified display (numbered from 0) on the specified host.
- #intern_atom(flag, name) ⇒ Object
- #list_fonts ⇒ Object
- #major_opcode(name) ⇒ Object
- #map_window ⇒ Object
-
#new_id ⇒ Object
The resource-id-mask contains a single contiguous set of bits (at least 18).
- #next_packet ⇒ Object
- #open_enum(val, map) ⇒ Object
- #open_font ⇒ Object
- #peek_packet ⇒ Object
- #poly_fill_rectangle(wid, gc, *rects) ⇒ Object
- #put_image(*args) ⇒ Object
- #query_extension(name) ⇒ Object
- #query_pointer(window) ⇒ Object
- #query_tree ⇒ Object
- #read_error(data) ⇒ Object
- #read_event(type, data, event_class) ⇒ Object
- #read_full_packet(len = 32) ⇒ Object
- #read_packet ⇒ Object
- #read_reply(data) ⇒ Object
- #render_add_glyphs(glyphset, glyphids, glyphinfos, data) ⇒ Object
- #render_composite_glyphs32(op, src, dst, fmt, glyphset, srcx, srcy, *elts) ⇒ Object
- #render_create_glyph_set(format) ⇒ Object
- #render_create_picture(drawable, format, vmask = 0, vlist = []) ⇒ Object
- #render_create_solid_fill(*color) ⇒ Object
- #render_fill_rectangles(op, dst, color, rects) ⇒ Object
- #render_find_standard_format(sym) ⇒ Object
- #render_find_visual_format(visual) ⇒ Object
- #render_free_picture(picture) ⇒ Object
-
#render_opcode ⇒ Object
XRender.
- #render_query_pict_formats ⇒ Object
- #reparent_window(window, parent, x, y, save: true) ⇒ Object
- #run ⇒ Object
- #screens ⇒ Object
- #select_input(w, events) ⇒ Object
- #send_event ⇒ Object
- #set_input_focus(revert_to, focus, time = :now) ⇒ Object
-
#set_selection_owner(selection, owner, time = 0) ⇒ Object
Set the owner of a selection selection: the selection atom owner: the window ID of the new owner, or None (0) to indicate no owner time: the server time when ownership should take effect, or CurrentTime (0).
- #set_value(values, mask, x) ⇒ Object
- #start_io ⇒ Object
- #u16(*args) ⇒ Object
- #u32(*args) ⇒ Object
- #u8(*args) ⇒ Object
- #unmap_window ⇒ Object
- #window(*args) ⇒ Object
- #write_packet(*args) ⇒ Object
- #write_request(ob) ⇒ Object
- #write_sync(ob, reply = nil) ⇒ Object
- #xinerama_is_active ⇒ Object
-
#xinerama_opcode ⇒ Object
Xinerama extension.
- #xinerama_query_screens ⇒ Object
- #xinerama_query_version ⇒ Object
Constructor Details
#initialize(target = ENV['DISPLAY']) ⇒ Display
Open a connection to the specified display (numbered from 0) on the specified host
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 46 |
# File 'lib/X11/display.rb', line 21 def initialize(target = ENV['DISPLAY']) target =~ /^([\w.-]*):(\d+)(?:.(\d+))?$/ host, display_id, _screen_id = $1, $2, $3 family = nil @debug = ENV["PUREX_DEBUG"].to_s.strip == "true" if host.empty? @socket = UNIXSocket.new("/tmp/.X11-unix/X#{display_id}") family = :Local host = nil else @socket = TCPSocket.new(host,6000+display_id) family = :Internet end (host, family, display_id) @requestseq = 1 @rqueue = Queue.new # Read but not returned events @wqueue = Queue.new @extensions = {} # Known extensions @atoms = {} # Interned atoms start_io end |
Instance Attribute Details
#socket ⇒ Object
Returns the value of attribute socket.
18 19 20 |
# File 'lib/X11/display.rb', line 18 def socket @socket end |
Instance Method Details
#atom(name) ⇒ Object
323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/X11/display.rb', line 323 def atom(name) return name if name.is_a?(Integer) # Allow atom(atom_integer_or_symbol) begin return Form::Atoms.const_get(name.to_sym) if Form::Atoms.const_defined?(name.to_sym) rescue # const_defined? will throw if name isn't a valid constant name, but # that's fine end name = name.to_sym intern_atom(false, name) if !@atoms[name] @atoms[name] end |
#atom_enum(val) ⇒ Object
456 457 458 |
# File 'lib/X11/display.rb', line 456 def atom_enum(val) open_enum(val, {cardinal: Form::CardinalAtom, atom: Form::AtomAtom, window: Form::WindowAtom}) || atom(val) end |
#change_gc ⇒ Object
441 |
# File 'lib/X11/display.rb', line 441 def change_gc(...) = write_request(Form::ChangeGC.new(...)) |
#change_property(mode, window, property, type, format, data) ⇒ Object
430 431 432 433 434 435 436 437 |
# File 'lib/X11/display.rb', line 430 def change_property(mode, window, property, type, format, data) property = atom(property.to_sym) if property.is_a?(Symbol) || property.is_a?(String) window_id = window.is_a?(X11::Window) ? window.wid : window mode = open_enum(mode, {replace: 0, prepend: 1, append: 2}) type = atom_enum(type) write_request(Form::ChangeProperty.new(mode, window_id, property, type, format, data)) end |
#change_save_set ⇒ Object
442 |
# File 'lib/X11/display.rb', line 442 def change_save_set(...)= write_request(Form::ChangeSaveSet.new(...)) |
#change_window_attributes(wid, values: {}) ⇒ Object
313 314 315 316 317 318 319 |
# File 'lib/X11/display.rb', line 313 def change_window_attributes(wid, values: {}) values = values.sort_by{_1[0]} mask = values.inject(0) {|acc,v| (acc | v[0]) } values = values.map{_1[1]} write_request(Form::ChangeWindowAttributes.new(wid, mask, values)) end |
#clear_area(*args) ⇒ Object
569 |
# File 'lib/X11/display.rb', line 569 def clear_area(*args) = write_request(X11::Form::ClearArea.new(*args)) |
#client_message(window: default_root, type: :ClientMessage, format: 32, destination: default_root, mask: 0, data: [], propagate: true) ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/X11/display.rb', line 553 def (window: default_root, type: :ClientMessage, format: 32, destination: default_root, mask: 0, data: [], propagate: true) f = {8 => "C20", 16 => "S10", 32 => "L5"}[format] # p f data = (Array(data).map{|item|atom(item)} + [0]*20).pack(f) event = Form::ClientMessage.new( format, 0, window, atom(type), data ) event.code =33 pp event send_event(propagate, destination, mask, event) end |
#close ⇒ Object
206 |
# File 'lib/X11/display.rb', line 206 def close = @rqueue.close |
#configure_window(window, x: nil, y: nil, width: nil, height: nil, border_width: nil, sibling: nil, stack_mode: nil) ⇒ Object
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/X11/display.rb', line 507 def configure_window(window, x: nil, y: nil, width: nil, height: nil, border_width: nil, sibling: nil, stack_mode: nil) values = [] mask = 0 mask |= set_value(values, 0x001, x) mask |= set_value(values, 0x002, y) mask |= set_value(values, 0x004, width) mask |= set_value(values, 0x008, height) mask |= set_value(values, 0x010, border_width) mask |= set_value(values, 0x020, sibling) if stack_mode mask |= 0x040 values << case stack_mode when :above then 0 when :below then 1 when :top_if then 2 when :bottom_if then 3 when :opposite then 4 else raise "Unknown stack_mode #{stack_mode.inspect}" end end write_request(X11::Form::ConfigureWindow.new(window, mask, values)) end |
#copy_area(*args) ⇒ Object
570 |
# File 'lib/X11/display.rb', line 570 def copy_area(*args) = write_request(X11::Form::CopyArea.new(*args)) |
#create_colormap(alloc, window, visual) ⇒ Object
400 401 402 403 404 |
# File 'lib/X11/display.rb', line 400 def create_colormap(alloc, window, visual) mid = new_id write_request(Form::CreateColormap.new(alloc, mid, window, visual)) mid end |
#create_gc(window, foreground: nil, background: nil, graphics_exposures: nil) ⇒ Object
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/X11/display.rb', line 534 def create_gc(window, foreground: nil, background: nil, graphics_exposures: nil ) mask = 0 args = [] # FIXME: # The rest can be found here: # https://tronche.com/gui/x/xlib/GC/manipulating.html#XGCValues mask |= set_value(args, 0x04, foreground) mask |= set_value(args, 0x08, background) mask |= set_value(args, 0x10000, graphics_exposures) gc = new_id write_request(X11::Form::CreateGC.new(gc, window, mask, args)) gc end |
#create_pixmap(depth, drawable, w, h) ⇒ Object
578 579 580 |
# File 'lib/X11/display.rb', line 578 def create_pixmap(depth, drawable, w,h) new_id.tap{|pid| write_request(Form::CreatePixmap.new(depth, pid, drawable, w,h)) } end |
#create_window(x, y, w, h, values: {}, depth: 32, parent: nil, border_width: 0, wclass: X11::Form::InputOutput, visual: nil) ⇒ Object
Requests
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/X11/display.rb', line 285 def create_window(x,y,w,h, values: {}, depth: 32, parent: nil, border_width: 0, wclass: X11::Form::InputOutput, visual: nil ) wid = new_id parent ||= default_root if visual.nil? visual = find_visual(0, depth).visual_id end values[X11::Form::CWColorMap] ||= create_colormap(0, parent, visual) values = values.sort_by{_1[0]} mask = values.inject(0) {|acc,v| (acc | v[0]) } values = values.map{_1[1]} write_request( X11::Form::CreateWindow.new( depth, wid, parent, x,y,w,h,border_width, wclass, visual, mask, values) ) return wid end |
#default_root ⇒ Object
282 |
# File 'lib/X11/display.rb', line 282 def default_root = screens.first.root |
#destroy_window(window) ⇒ Object
358 |
# File 'lib/X11/display.rb', line 358 def destroy_window(window) = write_request(Form::DestroyWindow.new(window)) |
#display_info ⇒ Object
58 59 60 |
# File 'lib/X11/display.rb', line 58 def display_info @internal end |
#event_handler=(block) ⇒ Object
48 49 50 |
# File 'lib/X11/display.rb', line 48 def event_handler= block @event_handler= block end |
#find_visual(screen, depth, qlass = 4) ⇒ Object
277 278 279 280 |
# File 'lib/X11/display.rb', line 277 def find_visual(screen, depth, qlass = 4) self.display_info.screens[screen].depths.find{|d| d.depth == depth }.visuals.find{|v| v.qlass = qlass } end |
#flush ⇒ Object
52 53 54 55 56 |
# File 'lib/X11/display.rb', line 52 def flush while !@wqueue.empty? sleep(0.01) end end |
#free_pixmap(pixmap) ⇒ Object
582 583 584 |
# File 'lib/X11/display.rb', line 582 def free_pixmap(pixmap) write_request(Form::FreePixmap.new(pixmap)) end |
#get_atom_name(atom) ⇒ Object
357 |
# File 'lib/X11/display.rb', line 357 def get_atom_name(atom) = write_sync(Form::GetAtomName.new(atom), Form::AtomName)&.name |
#get_geometry(drawable) ⇒ Object
359 |
# File 'lib/X11/display.rb', line 359 def get_geometry(drawable) = write_sync(Form::GetGeometry.new(drawable), Form::Geometry) |
#get_keyboard_mapping(min_keycode = display_info.min_keycode, count = display_info.max_keycode - min_keycode) ⇒ Object
396 397 398 |
# File 'lib/X11/display.rb', line 396 def get_keyboard_mapping(min_keycode=display_info.min_keycode, count= display_info.max_keycode - min_keycode) write_sync(Form::GetKeyboardMapping.new(min_keycode, count), Form::GetKeyboardMappingReply) end |
#get_property(window, property, type, offset: 0, length: 4, delete: false) ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/X11/display.rb', line 406 def get_property(window, property, type, offset: 0, length: 4, delete: false) property = atom(property) type = atom_enum(type) window_id = window.is_a?(X11::Window) ? window.wid : window result = write_sync(Form::GetProperty.new( delete, window_id, property, type, offset, length ), Form::Property) if result && result.format != 0 case result.format when 16 result.value = result.value.unpack("v*") result.value = result.value.first if result.value.length == 1 when 32 result.value = result.value.unpack("V*") result.value = result.value.first if result.value.length == 1 end elsif result result.value = nil end result end |
#get_selection_owner(selection) ⇒ Object
Get the current owner of a selection selection: the selection atom Returns: the window ID of the owner, or None (0) if there is no owner
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/X11/display.rb', line 380 def get_selection_owner(selection) # Convert selection to atom ID if necessary selection = atom(selection) if selection.is_a?(Symbol) || selection.is_a?(String) # Use the form-based approach for reading req = Form::GetSelectionOwner.new(selection) begin reply = write_sync(req, Form::SelectionOwner) reply ? reply.owner : 0 rescue => e STDERR.puts "Error getting selection owner: #{e.}" if @debug 0 # Return 0 (None) on error end end |
#get_window_attributes(wid) ⇒ Object
309 310 311 |
# File 'lib/X11/display.rb', line 309 def get_window_attributes(wid) write_sync( Form::GetWindowAttributes.new(wid), Form::WindowAttributes ) end |
#grab_button(owner_events, grab_window, event_mask, pointer_mode, keyboard_mode, confine_to, cursor, button, modifiers) ⇒ Object
488 489 490 491 492 493 494 495 496 |
# File 'lib/X11/display.rb', line 488 def (owner_events, grab_window, event_mask, pointer_mode, keyboard_mode, confine_to, cursor, , modifiers) write_request(Form::GrabButton.new( owner_events, grab_window, event_mask, pointer_mode == :async ? 1 : 0, keyboard_mode == :async ? 1 : 0, confine_to.to_i, cursor.to_i, , modifiers) ) end |
#grab_key(owner_events, grab_window, modifiers, keycode, pointer_mode, keyboard_mode) ⇒ Object
477 478 479 480 481 482 483 484 485 486 |
# File 'lib/X11/display.rb', line 477 def grab_key(owner_events, grab_window, modifiers, keycode, pointer_mode, keyboard_mode) write_request(Form::GrabKey.new( owner_events, grab_window, modifiers, keycode, pointer_mode == :async ? 1 : 0, keyboard_mode == :async ? 1 : 0 )) end |
#image_text16(*args) ⇒ Object
572 |
# File 'lib/X11/display.rb', line 572 def image_text16(*args)= write_request(X11::Form::ImageText16.new(*args)) |
#image_text8(*args) ⇒ Object
571 |
# File 'lib/X11/display.rb', line 571 def image_text8(*args) = write_request(X11::Form::ImageText8.new(*args)) |
#intern_atom(flag, name) ⇒ Object
350 351 352 353 354 355 |
# File 'lib/X11/display.rb', line 350 def intern_atom(flag, name) reply = write_sync(Form::InternAtom.new(flag, name.to_s),Form::InternAtomReply) if reply @atoms[name.to_sym] = reply.atom end end |
#list_fonts ⇒ Object
439 |
# File 'lib/X11/display.rb', line 439 def list_fonts(...) = write_sync(Form::ListFonts.new(...), Form::ListFontsReply) |
#major_opcode(name) ⇒ Object
342 343 344 345 346 347 348 |
# File 'lib/X11/display.rb', line 342 def major_opcode(name) if !@extensions[name] query_extension(name) end raise "No such extension '#{name}'" if !@extensions[name] @extensions[name][:major] end |
#map_window ⇒ Object
450 |
# File 'lib/X11/display.rb', line 450 def map_window(...) = write_request(Form::MapWindow.new(...)) |
#new_id ⇒ Object
The resource-id-mask contains a single contiguous set of bits (at least 18). The client allocates resource IDs for types WINDOW, PIXMAP, CURSOR, FONT, GCONTEXT, and COLORMAP by choosing a value with only some subset of these bits set and ORing it with resource-id-base.
74 75 76 77 78 79 |
# File 'lib/X11/display.rb', line 74 def new_id id = (@xid_next ||= 0) @xid_next += 1 (id & @internal.resource_id_mask) | @internal.resource_id_base end |
#next_packet ⇒ Object
204 |
# File 'lib/X11/display.rb', line 204 def next_packet = @rqueue.shift |
#open_enum(val, map) ⇒ Object
465 |
# File 'lib/X11/display.rb', line 465 def open_enum(val, map) = (map[val].nil? ? val : map[val]) |
#open_font ⇒ Object
440 |
# File 'lib/X11/display.rb', line 440 def open_font(...) = write_request(Form::OpenFont.new(...)) |
#peek_packet ⇒ Object
203 |
# File 'lib/X11/display.rb', line 203 def peek_packet = !@rqueue.empty? |
#poly_fill_rectangle(wid, gc, *rects) ⇒ Object
573 574 575 576 |
# File 'lib/X11/display.rb', line 573 def poly_fill_rectangle(wid, gc, *rects) rects = rects.map{|r| r.is_a?(Array) ? Form::Rectangle.new(*r) : r} write_request(X11::Form::PolyFillRectangle.new(wid, gc, rects)) end |
#put_image(*args) ⇒ Object
568 |
# File 'lib/X11/display.rb', line 568 def put_image(*args) = write_request(X11::Form::PutImage.new(*args)) |
#query_extension(name) ⇒ Object
336 337 338 339 340 |
# File 'lib/X11/display.rb', line 336 def query_extension(name) r = write_sync(Form::QueryExtension.new(name), Form::QueryExtensionReply) @extensions[name] = { major: r.major_opcode } r end |
#query_pointer(window) ⇒ Object
731 732 733 |
# File 'lib/X11/display.rb', line 731 def query_pointer(window) write_sync(Form::QueryPointer.new(window), Form::QueryPointerReply) end |
#query_tree ⇒ Object
566 |
# File 'lib/X11/display.rb', line 566 def query_tree(...) = write_sync(X11::Form::QueryTree.new(...), X11::Form::QueryTreeReply) |
#read_error(data) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/X11/display.rb', line 81 def read_error data error = Form::Error.from_packet(StringIO.new(data)) # FIXME: Maybe make this configurable, as it means potentially # keeping along really heavy requests. or alternative purge them # more aggressively also when there are no errors, as otherwise # the growth might be unbounded error.request = @requests[error.sequence_number] @requests.keys.find_all{|s| s <= error.sequence_number}.each do |s| @requests.delete(s) end STDERR.puts "ERROR: #{error.inspect}" error end |
#read_event(type, data, event_class) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/X11/display.rb', line 103 def read_event type, data, event_class io = StringIO.new(data) case type # 0 is error, not handled here # 1 is reply, not handled here when 2 then return Form::KeyPress.from_packet(io) when 3 then return Form::KeyRelease.from_packet(io) when 4 then return Form::ButtonPress.from_packet(io) when 5 then return Form::ButtonRelease.from_packet(io) when 6 then return Form::MotionNotify.from_packet(io) when 7 then return Form::EnterNotify.from_packet(io) when 8 then return Form::LeaveNotify.from_packet(io) when 9 then return Form::FocusIn.from_packet(io) when 10 then return Form::FocusOut.from_packet(io) # FIXME 11: KeymapNotify when 12 then return Form::Expose.from_packet(io) # FIXME 13: GraphicsExposure when 14 then return Form::NoExposure.from_packet(io) # FIXME: 15: VisibilityNotify when 16 then return Form::CreateNotify.from_packet(io) when 17 then return Form::DestroyNotify.from_packet(io) when 18 then return Form::UnmapNotify.from_packet(io) when 19 then return Form::MapNotify.from_packet(io) when 20 then return Form::MapRequest.from_packet(io) when 21 then return Form::ReparentNotify.from_packet(io) when 22 then return Form::ConfigureNotify.from_packet(io) when 23 then return Form::ConfigureRequest.from_packet(io) # FIXME: 24: GravityNotify # FIXME: 25: ResizeRequest # FIXME: 26: CirculateNotify # FIXME: 27: CirculateRequest when 28 then return Form::PropertyNotify.from_packet(io) # FIXME: 29: SelectionClear # FIXME: 30: SelectionRequest # FIXME: 31: SelectionNotify # FIXME: 32: ColormapNotify when 33 then return Form::ClientMessage.from_packet(io) # FIXME: 34: MappingNotify else STDERR.puts "FIXME: Event: #{type}" STDERR.puts "EVENT: #{data.inspect}" data end end |
#read_full_packet(len = 32) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/X11/display.rb', line 148 def read_full_packet(len = 32) data = @socket.read(32) return nil if data.nil? while data.length < 32 IO.select([@socket],nil,nil,0.001) data.concat(@socket.read_nonblock(32 - data.length)) end return data end |
#read_packet ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/X11/display.rb', line 158 def read_packet data = read_full_packet(32) return nil if data.nil? # FIXME: Make it configurable. @requests.keys.find_all{|s| s <= @requestseq - 50}.each do |s| @requests.delete(s) end # FIXME: What is bit 8 for? Synthentic? type = data.unpack("C").first & 0x7f case type when 0 then read_error(data) when 1 then read_reply(data) when 2..34 then read_event(type, data, nil) else raise ProtocolError, "Unsupported reply type: #{type} #{data.inspect}" end end |
#read_reply(data) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/X11/display.rb', line 95 def read_reply data len = data.unpack("@4L")[0] extra = len > 0 ? @socket.read(len*4) : "" #STDERR.puts "REPLY: #{data.inspect}" #STDERR.puts "EXTRA: #{extra.inspect}" data + extra end |
#render_add_glyphs(glyphset, glyphids, glyphinfos, data) ⇒ Object
664 665 666 667 |
# File 'lib/X11/display.rb', line 664 def render_add_glyphs(glyphset, glyphids, glyphinfos, data) write_request(X11::Form::XRenderAddGlyphs.new(render_opcode, glyphset, Array(glyphids), Array(glyphinfos), data)) end |
#render_composite_glyphs32(op, src, dst, fmt, glyphset, srcx, srcy, *elts) ⇒ Object
675 676 677 678 679 680 681 682 683 |
# File 'lib/X11/display.rb', line 675 def render_composite_glyphs32(op, src, dst, fmt, glyphset, srcx,srcy, *elts) write_request(X11::Form::XRenderCompositeGlyphs32.new( render_opcode, op, src, dst, fmt, glyphset, srcx, srcy, elts.map {|e| e.is_a?(Array) ? Form::GlyphElt32.new(*e) : e } )) end |
#render_create_glyph_set(format) ⇒ Object
657 658 659 660 661 662 |
# File 'lib/X11/display.rb', line 657 def render_create_glyph_set(format) glyphset = new_id write_request(X11::Form::XRenderCreateGlyphSet.new( major_opcode("RENDER"),glyphset, format)) glyphset end |
#render_create_picture(drawable, format, vmask = 0, vlist = []) ⇒ Object
600 601 602 603 604 605 |
# File 'lib/X11/display.rb', line 600 def render_create_picture(drawable, format, vmask=0, vlist=[]) pid = new_id write_request(X11::Form::XRenderCreatePicture.new( render_opcode, pid, drawable, format, vmask, vlist)) pid end |
#render_create_solid_fill(*color) ⇒ Object
685 686 687 688 689 690 691 692 693 694 |
# File 'lib/X11/display.rb', line 685 def render_create_solid_fill(*color) if color.length == 1 && color.is_a?(Form::XRenderColor) color = color[0] else color = Form::XRenderColor.new(*color) end fill = new_id write_request(Form::XRenderCreateSolidFill.new(render_opcode,fill,color)) fill end |
#render_fill_rectangles(op, dst, color, rects) ⇒ Object
669 670 671 672 673 |
# File 'lib/X11/display.rb', line 669 def render_fill_rectangles(op, dst, color, rects) color = Form::XRenderColor.new(*color) if color.is_a?(Array) rects = rects.map{|r| r.is_a?(Array) ? Form::Rectangle.new(*r) : r} write_request(Form::XRenderFillRectangles.new(render_opcode, op, dst, color, rects)) end |
#render_find_standard_format(sym) ⇒ Object
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'lib/X11/display.rb', line 623 def render_find_standard_format(sym) # A pox be on the people who made this necessary formats = render_query_pict_formats case sym when :a8 @a8 ||= formats.formats.find do |f| f.type == 1 && f.depth == 8 && f.direct.alpha_mask == 255 end when :rgb24 @rgb24 ||= formats.formats.find do |f| f.type == 1 && f.depth == 24 && f.direct.red == 16 && f.direct.green == 8 && f.direct.blue == 0 end when :argb24 @argb24 ||= formats.formats.find do |f| f.type == 1 && f.depth == 32 && f.direct.alpha == 24 && f.direct.red == 16 && f.direct.green == 8 && f.direct.blue == 0 end else raise "Unsupported format (a4/a1 by omission)" end end |
#render_find_visual_format(visual) ⇒ Object
614 615 616 617 618 619 620 621 |
# File 'lib/X11/display.rb', line 614 def render_find_visual_format(visual) # FIXME. render_query_pict_formats.screens.map do |s| s.depths.map do |d| d.visuals.map {|v| v.visual == visual ? v : nil } end end.flatten.compact.first&.format end |
#render_free_picture(picture) ⇒ Object
696 697 698 |
# File 'lib/X11/display.rb', line 696 def render_free_picture(picture) write_request(Form::XRenderFreePicture.new(render_opcode, picture)) end |
#render_opcode ⇒ Object
XRender
588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/X11/display.rb', line 588 def render_opcode return @render_opcode if @render_opcode @render_opcode = major_opcode("RENDER") if @render_opcode @render_version = write_sync(X11::Form::XRenderQueryVersion.new( @render_opcode,0,11), X11::Form::XRenderQueryVersionReply ) end @render_opcode end |
#render_query_pict_formats ⇒ Object
607 608 609 610 611 612 |
# File 'lib/X11/display.rb', line 607 def render_query_pict_formats @render_formats ||= write_sync( Form::XRenderQueryPictFormats.new(render_opcode), Form::XRenderQueryPictFormatsReply ) end |
#reparent_window(window, parent, x, y, save: true) ⇒ Object
444 445 446 447 448 |
# File 'lib/X11/display.rb', line 444 def reparent_window(window, parent, x, y, save: true) # You so almost always want this that it should've been a single request change_save_set(0, window) if save write_request(Form::ReparentWindow.new(window, parent, x,y)) end |
#run ⇒ Object
269 270 271 272 273 274 275 |
# File 'lib/X11/display.rb', line 269 def run loop do pkt = next_packet return if !pkt yield(pkt) end end |
#screens ⇒ Object
62 63 64 65 66 |
# File 'lib/X11/display.rb', line 62 def screens @internal.screens.map do |s| Screen.new(self, s) end end |
#select_input(w, events) ⇒ Object
321 |
# File 'lib/X11/display.rb', line 321 def select_input(w, events) = change_window_attributes(w, values: {Form::CWEventMask => events}) |
#send_event ⇒ Object
552 |
# File 'lib/X11/display.rb', line 552 def send_event(...) = write_request(Form::SendEvent.new(...)) |
#set_input_focus(revert_to, focus, time = :now) ⇒ Object
467 468 469 470 471 472 473 474 475 |
# File 'lib/X11/display.rb', line 467 def set_input_focus(revert_to, focus, time=:now) # FIXME: This is an experiment. # Upside: Simpler. Downside: Doesn't work server-side. # Probably a bad idea. revert_to = open_enum(revert_to, {none: 0, pointer_root: 1, parent: 2}) focus = open_enum(focus, {none: 0, pointer_root: 1 }) time = open_enum(time, {current_time: 0, now: 0}) write_packet(u8(42,revert_to), u16(3), window(focus), u32(time)) end |
#set_selection_owner(selection, owner, time = 0) ⇒ Object
Set the owner of a selection selection: the selection atom owner: the window ID of the new owner, or None (0) to indicate no owner time: the server time when ownership should take effect, or CurrentTime (0)
365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/X11/display.rb', line 365 def set_selection_owner(selection, owner, time = 0) # Convert selection to atom ID if necessary selection = atom(selection) if selection.is_a?(Symbol) || selection.is_a?(String) owner = owner || 0 # Allow nil for owner to mean None (0) # Create and send the SetSelectionOwner request using the Form req = Form::SetSelectionOwner.new(owner, selection, time) write_request(req) true # Always returns true; check get_selection_owner to verify end |
#set_value(values, mask, x) ⇒ Object
498 499 500 501 502 503 504 505 |
# File 'lib/X11/display.rb', line 498 def set_value(values, mask, x) if x values << x mask else 0 end end |
#start_io ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/X11/display.rb', line 208 def start_io @replies ||= {} @requests ||= {} # Read thread. # FIXME: Drop the select. rt = Thread.new do while pkt = read_packet #STDERR.puts "read: #{pkt.inspect}" if !pkt sleep 0.1 elsif pkt.is_a?(String) # This is a reply. We need the sequence number. # seq = pkt.unpack1("@2S") STDERR.puts " - seq= #{seq}" if @debug STDERR.puts @replies.inspect if @debug if @replies[seq] q = @replies.delete(seq) STDERR.puts " - reply to #{q}" if @debug q << pkt end elsif pkt.is_a?(X11::Form::Error) if @replies[pkt.sequence_number] q = @replies.delete(pkt.sequence_number) q << pkt else @rqueue << pkt end else @rqueue << pkt end end @rqueue.close @replies.values.each(&:close) end # Write thread wt = Thread.new do while msg = @wqueue.shift ob, q, data = *msg @requests[@requestseq] = ob @replies[@requestseq] = q if q @requestseq = (@requestseq + 1) % 65536 @socket.write(data) end end at_exit do flush @rqueue.close @wqueue.close # We kill this because it may be stuck in a read # we'll never care about Thread.kill(rt) # We wait for this to finish because otherwise we may # lose side-effects wt.join end end |
#u16(*args) ⇒ Object
454 |
# File 'lib/X11/display.rb', line 454 def u16(*args) = args.pack("v*") |
#u32(*args) ⇒ Object
455 |
# File 'lib/X11/display.rb', line 455 def u32(*args) = args.pack("V*") |
#u8(*args) ⇒ Object
453 |
# File 'lib/X11/display.rb', line 453 def u8(*args) = args.pack("c*") |
#unmap_window ⇒ Object
451 |
# File 'lib/X11/display.rb', line 451 def unmap_window(...) = write_request(Form::UnmapWindow.new(...)) |
#window(*args) ⇒ Object
460 461 462 463 |
# File 'lib/X11/display.rb', line 460 def window(*args) args.each {|a| raise "Window expected" if a.nil? } u32(*args) end |
#write_packet(*args) ⇒ Object
178 179 180 181 182 |
# File 'lib/X11/display.rb', line 178 def write_packet(*args) pkt = args.join pkt[2..3] = u16(pkt.length/4) @wqueue << [nil,nil,pkt] end |
#write_request(ob) ⇒ Object
184 185 186 187 188 189 |
# File 'lib/X11/display.rb', line 184 def write_request ob data = ob.to_packet(self) if ob.respond_to?(:to_packet) raise "BAD LENGTH for #{ob.inspect} (#{ob.request_length.to_i*4} ! #{data.size} " if ob.request_length && ob.request_length.to_i*4 != data.size STDERR.puts "write_req: #{ob.inspect}" if @debug @wqueue << [ob,nil,data] end |
#write_sync(ob, reply = nil) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/X11/display.rb', line 191 def write_sync(ob, reply=nil) data = ob.to_packet(self) if ob.respond_to?(:to_packet) q = Queue.new @wqueue << [ob,q,data] STDERR.puts "write_sync_req: #{ob.inspect}" if @debug pkt = q.shift STDERR.puts "write_sync_rep: #{pkt.inspect}" if @debug raise(X11::Error.new(pkt)) if pkt.is_a?(X11::Form::Error) return pkt if !pkt.is_a?(String) reply ? reply.from_packet(StringIO.new(pkt)) : pkt end |
#xinerama_is_active ⇒ Object
716 717 718 719 720 721 722 |
# File 'lib/X11/display.rb', line 716 def xinerama_is_active result = write_sync( X11::Form::XineramaIsActive.new(xinerama_opcode), X11::Form::XineramaIsActiveReply ) result.state != 0 end |
#xinerama_opcode ⇒ Object
Xinerama extension
702 703 704 705 706 |
# File 'lib/X11/display.rb', line 702 def xinerama_opcode return @xinerama_opcode if @xinerama_opcode @xinerama_opcode = major_opcode("XINERAMA") @xinerama_opcode end |
#xinerama_query_screens ⇒ Object
724 725 726 727 728 729 |
# File 'lib/X11/display.rb', line 724 def xinerama_query_screens write_sync( X11::Form::XineramaQueryScreens.new(xinerama_opcode), X11::Form::XineramaQueryScreensReply ) end |
#xinerama_query_version ⇒ Object
708 709 710 711 712 713 714 |
# File 'lib/X11/display.rb', line 708 def xinerama_query_version return @xinerama_version if @xinerama_version @xinerama_version = write_sync( X11::Form::XineramaQueryVersion.new(xinerama_opcode), X11::Form::XineramaQueryVersionReply ) end |