Class: Rkremap::WinAttr
- Inherits:
-
Object
- Object
- Rkremap::WinAttr
- Defined in:
- lib/rkremap/winattr.rb
Overview
アプリの name, class, title を取得する
Instance Method Summary collapse
- #app_title(window) ⇒ String
- #app_win(window) ⇒ Array<window, name, class>
-
#focus_win ⇒ Integer
Window.
-
#initialize ⇒ WinAttr
constructor
A new instance of WinAttr.
Constructor Details
Instance Method Details
#app_title(window) ⇒ String
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rkremap/winattr.rb', line 47 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.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 |