Class: Rkremap::WinAttrX11
- Inherits:
-
Object
- Object
- Rkremap::WinAttrX11
- Defined in:
- lib/rkremap/winattr_x11.rb
Overview
アプリの name, class, title を取得する
Instance Method Summary collapse
- #app_title(window) ⇒ String
- #app_win(window) ⇒ Array<window, name, class>
- #class_name(window) ⇒ String
-
#focus_win ⇒ Integer
Window.
-
#initialize ⇒ WinAttrX11
constructor
A new instance of WinAttrX11.
Constructor Details
#initialize ⇒ WinAttrX11
Returns a new instance of WinAttrX11.
6 7 8 9 10 |
# File 'lib/rkremap/winattr_x11.rb', line 6 def initialize @app_win = {} @display = X11.XOpenDisplay(nil) or raise "Cannot open display: #{ENV['DISPLAY']}" @buf = ' '*8 end |
Instance Method Details
#app_title(window) ⇒ String
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rkremap/winattr_x11.rb', line 52 def app_title(window) win = app_win(window)[0] return '' if win == 0 prop = X11::XTextProperty.malloc(Fiddle::RUBY_FREE) text_list = X11::Pointer.malloc(Fiddle::RUBY_FREE) X11.XGetWMName(@display, win, prop) X11.Xutf8TextPropertyToTextList(@display, prop, text_list, @buf) ptr = text_list.ptr return '' if ptr.null? title = ptr.ptr.to_s.force_encoding('utf-8') X11.XFreeStringList(text_list.ptr) title end |
#app_win(window) ⇒ Array<window, name, class>
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rkremap/winattr_x11.rb', line 20 def app_win(window) return @app_win[window] if @app_win[window] class_hint = X11::XClassHint.malloc(Fiddle::RUBY_FREE) parent = X11::Window.malloc(Fiddle::RUBY_FREE) children = X11::Pointer.malloc(Fiddle::RUBY_FREE) win = window while win > 0 class_hint.name = nil class_hint.class_name = nil X11.XGetClassHint(@display, win, class_hint) X11.XQueryTree(@display, win, @buf, parent, children, @buf) X11.XFree(children.ptr) break unless class_hint.name.null? && class_hint.class_name.null? win = parent.window end unless class_hint.name.null? win_name = class_hint.name.to_s X11.XFree(class_hint.name) end unless class_hint.class_name.null? win_class = class_hint.class_name.to_s X11.XFree(class_hint.class_name) end @app_win[window] = [win, win_name, win_class] end |
#class_name(window) ⇒ String
47 48 49 |
# File 'lib/rkremap/winattr_x11.rb', line 47 def class_name(window) app_win(window)[2] end |
#focus_win ⇒ Integer
Returns Window.
13 14 15 16 17 |
# File 'lib/rkremap/winattr_x11.rb', line 13 def focus_win win = X11::Window.malloc(Fiddle::RUBY_FREE) X11.XGetInputFocus(@display, win, @buf) win.window end |