X11Client is C extension that manages X11 windows/events
Ruby C
Latest commit 25820f9 Nov 19, 2011 @ayanko v0.0.4
Permalink
Failed to load latest commit information.
ext/x11_client_ext Fixed ISO C90 warnings. Support ruby18 and ruby19. Nov 19, 2011
lib
samples Added samples directory Nov 19, 2011
spec Added X11Client#window_children Nov 9, 2011
.gitignore Initial commit Nov 9, 2011
Gemfile preliminary keyboard support Nov 16, 2011
README.md Updated README Nov 19, 2011
Rakefile
x11_client.gemspec v0.0.4 Nov 19, 2011

README.md

X11Client

X11Client is C extension that manages X11 windows/events.

It can be handy if you want to controll some programs running in Xvfb.

Dependencies

  • Xlib
  • Xtst
  • Xext

Installation

gem install x11_client

API

  • X11Client.new(display) - create new client for given display
  • X11Client#open_display - explicit open display
  • X11Client#close_display - explicit close display
  • X11Client#sync - sync display
  • X11Client#start(&block) - block execution and yield event attributes for each new event.
  • X11Client#stop - stop blocking loop
  • X11Client#root_window_id - returns root window id in decimal.
  • X11Client#root_window - returns root window attributes hash.
  • X11Client#get_window(window_id) - returns window attributes hash or nil for given window_id.
  • X11Client#get_window(window_id) - returns window name for given window_id.
  • X11Client#mousemove(x,y) - move mouse pointer to (x,y) coordinates.
  • X11Client#mousedown(button) - down mouse buton
  • X11Client#mouseup(buton) - up mouse button
  • X11Client#mouseclick(button) - mousedown and mouseup
  • X11Client#keydown(key) - press a key
  • X11Client#keyup(key) - release a key
  • X11Client#key(key) - press and release a key

Mouse buttons

  • 1 - left
  • 2 - right
  • 3 - middle
  • 4 - wheel up
  • 5 - wheel down

Key names

  • XK_Return
  • XK_Escape
  • XK_Left
  • XK_Up
  • XK_Page_Up
  • XK_F1
  • XK_Shift_L
  • XK_Control_R
  • XK_Meta_L
  • XK_Alt_R
  • XK_Super_L
  • XK_Hyper_R
  • XK_space
  • XK_A
  • XK_z
  • ...

See X11 keysym list

Keysym list is generated from /usr/include/X11 sources with rake update_keysym

X11 Window attributes

  • id - window id
  • root_id - root window id
  • x - X coordinate
  • y - Y coordinate
  • width - window width
  • height - window height
  • border_width - window border width
  • state - window state
    • shown
    • hidden
    • unmapped

X11 Event attributes

Supported events:

  • CreateWindowEvent
  • DestroyWindowEvent
  • MapEvent
  • UnmapEvent
  • VisibilityEvent

CreateWindowEvent attributes:

  • type
  • window_id
  • parent_id
  • x
  • y
  • width
  • height
  • border_width

DestroyWindowEvent attributes:

  • type
  • window_id

MapEvent attributes:

  • type
  • window_id

UnmapEvent attributes:

  • type
  • window_id

VisibilityEvent attributes:

  • type
  • window_id
  • state:
    • unobscured
    • partially_obscured
    • fully_unobscured

Example

client = X11Client.new(":0")

client.start do |event|

  case event['type']
  when 'CreateWindowEvent'
    window = client.get_window(event["window_id"])
    next unless window

    case window['class']
    when /skype/i
      case window['name']
      when /End User License Agreement/i
        # Accept Skype Aggreement
        client.mousemove(window['x'] + 500, window['y'] + 340)
        client.sync
        sleep(1)
        client.mouseclick(1)
        client.stop
      end
    end

  end

end

Testing

$ sudo pacman -S xorg-xwininfo
$ bundle install
$ bundle exec rspec spec

References