Class: XlibObj::Display
- Inherits:
-
Object
- Object
- XlibObj::Display
- Defined in:
- lib/display.rb
Class Method Summary collapse
Instance Method Summary collapse
- #flush ⇒ Object
- #focused_window ⇒ Object
- #handle_events ⇒ Object
-
#initialize(name) ⇒ Display
constructor
A new instance of Display.
- #name ⇒ Object
- #on_error(&callback) ⇒ Object
- #on_io_error(&callback) ⇒ Object
- #screens ⇒ Object
- #selection(*args, &on_receive) ⇒ Object
- #set_selection(*args, &on_request) ⇒ Object
- #socket ⇒ Object
- #to_native ⇒ Object
Constructor Details
#initialize(name) ⇒ Display
Returns a new instance of Display.
22 23 24 25 26 |
# File 'lib/display.rb', line 22 def initialize(name) display_pointer = Xlib.XOpenDisplay(name) raise ArgumentError, "Unknown display #{name}" if display_pointer.null? @struct = Xlib::Display.new(display_pointer) end |
Class Method Details
.names ⇒ Object
14 15 16 17 18 19 |
# File 'lib/display.rb', line 14 def names Dir['/tmp/.X11-unix/*'].map do |file_name| match = file_name.match(/X(\d+)$/) ":#{match[1]}" if match end.compact end |
Instance Method Details
#flush ⇒ Object
89 90 91 92 |
# File 'lib/display.rb', line 89 def flush Xlib.XFlush(to_native) handle_events end |
#focused_window ⇒ Object
44 45 46 |
# File 'lib/display.rb', line 44 def focused_window screens.reduce(nil){ |focused_window, s| focused_window or s.focused_window } end |
#handle_events ⇒ Object
48 49 50 |
# File 'lib/display.rb', line 48 def handle_events handle_event(next_event) while pending_events > 0 end |
#name ⇒ Object
32 33 34 |
# File 'lib/display.rb', line 32 def name @struct[:display_name] end |
#on_error(&callback) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/display.rb', line 62 def on_error(&callback) @error_handler = if callback FFI::Function.new(:pointer, [:pointer, :pointer]) do |display_ptr, error_ptr| next if display_ptr != to_native x_error = Xlib::XErrorEvent.new(error_ptr) callback.call Error.new(self, x_error) end else nil end Xlib.XSetErrorHandler(@error_handler) end |
#on_io_error(&callback) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/display.rb', line 76 def on_io_error(&callback) @io_error_handler = if callback FFI::Function.new(:pointer, [:pointer]) do |display_ptr| next if display_ptr != to_native callback.call end else nil end Xlib.XSetIOErrorHandler(@io_error_handler) end |
#screens ⇒ Object
40 41 42 |
# File 'lib/display.rb', line 40 def screens (0..@struct[:nscreens]-1).map{ |number| screen(number) } end |
#selection(*args, &on_receive) ⇒ Object
52 53 54 55 |
# File 'lib/display.rb', line 52 def selection(*args, &on_receive) internal_window.request_selection(*args, &on_receive) self end |
#set_selection(*args, &on_request) ⇒ Object
57 58 59 60 |
# File 'lib/display.rb', line 57 def set_selection(*args, &on_request) internal_window.set_selection(*args, &on_request) self end |
#socket ⇒ Object
36 37 38 |
# File 'lib/display.rb', line 36 def socket @socket ||= UNIXSocket.for_fd(Xlib.XConnectionNumber(to_native)) end |
#to_native ⇒ Object
28 29 30 |
# File 'lib/display.rb', line 28 def to_native @struct.pointer end |