Class: ActiveWindowX::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/active_window_x/display.rb,
lib/active_window_x.rb

Overview

binding for Display on X11

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ Display

Returns a new instance of Display.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_window_x/display.rb', line 15

def initialize arg=nil
  @raw =
    if arg.nil? or arg.kind_of? String
      Xlib::x_open_display arg
    elsif arg.kind_of? Xlib::Display
      arg
    else
      raise ArgumentError, 'expect nil, String or Xlib::Display'
    end
  @closed = false
  @root_window = nil
  @cache = {}
end

Instance Attribute Details

#closedObject (readonly) Also known as: closed?

a boolean which be true if this display was closed



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

def closed
  @closed
end

#rawObject (readonly)

raw class of Display



9
10
11
# File 'lib/active_window_x/display.rb', line 9

def raw
  @raw
end

Instance Method Details

#active_windowObject



48
49
50
# File 'lib/active_window_x/display.rb', line 48

def active_window
  root_window.active_window
end

#atom_name(id) ⇒ Object



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

def atom_name id
  if @cache.has_key? id
    @cache[id]
  else
    @cache[id] = Xlib::x_get_atom_name @raw, id
  end
end

#closeObject



29
30
31
32
# File 'lib/active_window_x/display.rb', line 29

def close
  Xlib::x_close_display @raw
  @closed = true
end

#connectionObject

return IO to select and poll a XEvent with timeout



39
40
41
# File 'lib/active_window_x/display.rb', line 39

def connection
  @conn ||= IO.new(Xlib::connection_number @raw)
end

#intern_atom(name) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/active_window_x/display.rb', line 52

def intern_atom name
  if @cache.has_key? name
    @cache[name]
  else
    @cache[name] = Xlib::x_intern_atom @raw, name, false
  end
end

#next_eventObject



68
69
70
71
72
73
74
75
76
# File 'lib/active_window_x/display.rb', line 68

def next_event
  xevent = Xlib::x_next_event @raw

  case xevent.type
  when Xlib::PropertyNotify; PropertyEvent.new self, xevent
  when Xlib::ClientMessage; ClientMessageEvent.new self, xevent
  else Event.new self, xevent
  end
end

#pendingObject

return the number of events that have been received from the X server



44
45
46
# File 'lib/active_window_x/display.rb', line 44

def pending
  Xlib::x_pending @raw
end

#root_windowObject



34
35
36
# File 'lib/active_window_x/display.rb', line 34

def root_window
  @root_window ||= RootWindow.new(self, Xlib::default_root_window(@raw))
end