Class: ActiveWindowX::Window
- Defined in:
- lib/active_window_x/window.rb,
lib/active_window_x.rb
Overview
binding for Window on X11
Direct Known Subclasses
Constant Summary collapse
- READ_BUFF_LENGTH =
a buffer for #x_get_window_property
1024
Instance Attribute Summary
Attributes inherited from Xid
Instance Method Summary collapse
-
#app_class ⇒ Object
window class (Terminal, Google-chrome, etc.) TODO write the difference of app_name and app_class.
- #app_class_prop ⇒ Object
-
#app_name ⇒ Object
window name (terminal, google-chrome, etc.).
-
#children ⇒ Object
a return value of XQueryTree which is an Array of Window.
- #command ⇒ Object
-
#parent ⇒ Object
a return value of XQueryTree which is nil, if this window is RootWindow, or a Window.
- #pid ⇒ Object
-
#prop(atom) ⇒ Object
window property getter with easy way for XGetWindowProperty which return nil, if the specified property name does not exist, a String or a Array of Number.
-
#prop_atom_ids ⇒ Object
Array of the property atom ID(Numeric) list for this window.
-
#prop_atoms ⇒ Object
Array of the property atom list for this window.
-
#prop_raw(atom) ⇒ Object
window property getter with easy way for XGetWindowProperty which return [propety_value, format, number_of_items].
-
#root ⇒ Object
a return value of XQueryTree which is the root window for a display contains this window.
- #select_input(mask) ⇒ Object
- #set_wm_protocols(msgs) ⇒ Object
-
#title ⇒ Object
window title (current web page title in browser, current command or dir in terminal app, etc.).
- #x_query_tree ⇒ Object
Methods inherited from Xid
Constructor Details
This class inherits a constructor from ActiveWindowX::Xid
Instance Method Details
#app_class ⇒ Object
window class (Terminal, Google-chrome, etc.) TODO write the difference of app_name and app_class
47 48 49 50 |
# File 'lib/active_window_x/window.rb', line 47 def app_class val = app_class_prop val and val[1] end |
#app_class_prop ⇒ Object
52 53 54 55 |
# File 'lib/active_window_x/window.rb', line 52 def app_class_prop val = prop('WM_CLASS') val and val.split("\0") end |
#app_name ⇒ Object
window name (terminal, google-chrome, etc.)
40 41 42 43 |
# File 'lib/active_window_x/window.rb', line 40 def app_name val = app_class_prop val and val[0] end |
#children ⇒ Object
a return value of XQueryTree which is an Array of Window
29 30 31 |
# File 'lib/active_window_x/window.rb', line 29 def children x_query_tree[2].map{|w| Window.new(@display, w)} end |
#command ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/active_window_x/window.rb', line 62 def command id = pid return nil if id.nil? path = "/proc/#{id}/cmdline" return nil unless File.readable_real? path File.read path end |
#parent ⇒ Object
a return value of XQueryTree which is nil, if this window is RootWindow, or a Window.
23 24 25 |
# File 'lib/active_window_x/window.rb', line 23 def parent (r = x_query_tree[1]) and Window.new(@display, r) end |
#pid ⇒ Object
57 58 59 60 |
# File 'lib/active_window_x/window.rb', line 57 def pid val = prop('_NET_WM_PID') val and val.first end |
#prop(atom) ⇒ Object
window property getter with easy way for XGetWindowProperty which return nil, if the specified property name does not exist, a String or a Array of Number
75 76 77 78 79 80 81 82 83 |
# File 'lib/active_window_x/window.rb', line 75 def prop atom val, format, nitems = prop_raw atom case format when 32; val.unpack("l!#{nitems}") when 16; val.unpack("s#{nitems}") when 8; val[0, nitems] when 0; nil end end |
#prop_atom_ids ⇒ Object
Array of the property atom ID(Numeric) list for this window
99 100 101 102 |
# File 'lib/active_window_x/window.rb', line 99 def prop_atom_ids r = Xlib::x_list_properties @display.raw, @id r.nil? ? [] : r end |
#prop_atoms ⇒ Object
Array of the property atom list for this window
105 106 107 |
# File 'lib/active_window_x/window.rb', line 105 def prop_atoms prop_atom_ids.map{|i| Atom.new @display, i} end |
#prop_raw(atom) ⇒ Object
window property getter with easy way for XGetWindowProperty which return [propety_value, format, number_of_items]
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/active_window_x/window.rb', line 87 def prop_raw atom if atom.kind_of?(Numeric) or atom.kind_of?(String) atom = Atom.new @display, atom elsif not atom.kind_of? Atom raise ArgumentError, "expect Numeric, String or #{Atom.name}" end actual_type, actual_format, nitems, bytes_after, val = Xlib::x_get_window_property @display.raw, @id, atom.id, 0, READ_BUFF_LENGTH, false, Xlib::AnyPropertyType return [val, actual_format, nitems] end |
#root ⇒ Object
a return value of XQueryTree which is the root window for a display contains this window
17 18 19 |
# File 'lib/active_window_x/window.rb', line 17 def root (r = x_query_tree[0]) and Window.new(@display, r) end |
#select_input(mask) ⇒ Object
109 110 111 |
# File 'lib/active_window_x/window.rb', line 109 def select_input mask Xlib::x_select_input @display.raw, @id, mask end |
#set_wm_protocols(msgs) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/active_window_x/window.rb', line 113 def set_wm_protocols msgs atoms = if msgs.kind_of? Atom then [msgs.id] elsif msgs.kind_of? Array then msgs.map {|m| m.id } else raise ArgumentError, 'expect Atom or Array of Atom' end Xlib::x_set_wm_protocols @display.raw, @id, atoms end |
#title ⇒ Object
window title (current web page title in browser, current command or dir in terminal app, etc.)
34 35 36 37 |
# File 'lib/active_window_x/window.rb', line 34 def title title = prop('_NET_WM_NAME') title or prop('WM_NAME') end |
#x_query_tree ⇒ Object
11 12 13 |
# File 'lib/active_window_x/window.rb', line 11 def x_query_tree Xlib::x_query_tree @display.raw, @id end |