Class: XlibObj::Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/screen.rb,
lib/screen/crtc.rb,
lib/screen/crtc/output.rb

Defined Under Namespace

Classes: Crtc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(display, screen_pointer) ⇒ Screen

Returns a new instance of Screen.



17
18
19
20
# File 'lib/screen.rb', line 17

def initialize(display, screen_pointer)
  @display = display
  @struct = Xlib::Screen.new(screen_pointer)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



33
34
35
# File 'lib/screen.rb', line 33

def method_missing(name)
  attribute(name)
end

Instance Attribute Details

#displayObject (readonly)

Returns the value of attribute display.



22
23
24
# File 'lib/screen.rb', line 22

def display
  @display
end

Class Method Details

.finalize(resources) ⇒ Object



12
13
14
# File 'lib/screen.rb', line 12

def finalize(resources)
  proc{ Xlib.XRRFreeScreenResources(resources.pointer) }
end

Instance Method Details

#attribute(name) ⇒ Object



28
29
30
31
# File 'lib/screen.rb', line 28

def attribute(name)
  return unless @struct.layout.members.include? name.to_sym
  @struct[name]
end

#crtcsObject



60
61
62
63
64
65
66
# File 'lib/screen.rb', line 60

def crtcs
  (0..resources[:ncrtc]-1).map do |crtc_number|
    crtc_id(resources[:crtcs], crtc_number)
  end.map do |crtc_id|
    Crtc.new(self, crtc_id)
  end
end

#focused_windowObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/screen.rb', line 45

def focused_window
  window_ptr = FFI::MemoryPointer.new :Window
  trash_ptr  = FFI::MemoryPointer.new :int
  Xlib.XGetInputFocus(@display.to_native, window_ptr, trash_ptr)
  window = window_ptr.read_int

  if window == Xlib::PointerRoot
    root_window
  elsif window == Xlib::None
    nil
  else
    Window.new(@display, window)
  end
end

#inspectObject



68
69
70
# File 'lib/screen.rb', line 68

def inspect
  "#<#{self.class.name}:0x#{'%014x' % __id__} @number=#{number}>"
end

#numberObject



37
38
39
# File 'lib/screen.rb', line 37

def number
  Xlib.XScreenNumberOfScreen(to_native)
end

#root_windowObject



41
42
43
# File 'lib/screen.rb', line 41

def root_window
  @root_window ||= Window.new(@display, Xlib.XRootWindowOfScreen(to_native))
end

#to_nativeObject



24
25
26
# File 'lib/screen.rb', line 24

def to_native
  @struct.pointer
end