Class: WindowGeometry::X::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/window_geometry/x.rb

Instance Method Summary collapse

Constructor Details

#initialize(display, window) ⇒ Window

Returns a new instance of Window.



254
255
256
257
# File 'lib/window_geometry/x.rb', line 254

def initialize(display, window)
  @display = display
  @window = window
end

Instance Method Details

#attributesObject



348
349
350
351
352
# File 'lib/window_geometry/x.rb', line 348

def attributes
  attr = X11::XWindowAttributes.malloc(Fiddle::RUBY_FREE)
  X11::XGetWindowAttributes(@display, @window, attr)
  attr
end

#change_property(property, mode, data) ⇒ Object



341
342
343
344
345
346
# File 'lib/window_geometry/x.rb', line 341

def change_property(property, mode, data)
  prop_ = X11::XInternAtom(@display, property.to_s, 0)
  type = 4  # XA_ATOM
  data_ = [X11::XInternAtom(@display, data.to_s, 0)].pack('L!')
  X11::XChangeProperty(@display, @window, prop_, type, 32, mode, data_, 1)
end

#class_hintObject



263
264
265
266
267
# File 'lib/window_geometry/x.rb', line 263

def class_hint
  class_hint = X11::XClassHint.malloc(Fiddle::RUBY_FREE)
  X11::XGetClassHint(@display, @window, class_hint)
  class_hint
end

#clearObject



365
366
367
# File 'lib/window_geometry/x.rb', line 365

def clear
  X11::XClearWindow(@display, @window)
end

#create_gcObject



360
361
362
363
# File 'lib/window_geometry/x.rb', line 360

def create_gc
  gc = X11::XCreateGC(@display, @window, 0, nil)
  GC.new(@display, @window, gc)
end

#create_simple_window(x, y, width, height, border_width, border, background) ⇒ Object



320
321
322
323
# File 'lib/window_geometry/x.rb', line 320

def create_simple_window(x, y, width, height, border_width, border, background)
  win = X11::XCreateSimpleWindow(@display, @window, x, y, width, height, border_width, border, background)
  Window.new(@display, win)
end

#idObject



259
260
261
# File 'lib/window_geometry/x.rb', line 259

def id
  @window
end

#map_windowObject



329
330
331
# File 'lib/window_geometry/x.rb', line 329

def map_window
  X11::XMapWindow(@display, @window)
end

#move_window(x, y) ⇒ Object



325
326
327
# File 'lib/window_geometry/x.rb', line 325

def move_window(x, y)
  X11::XMoveWindow(@display, @window, x, y)
end

#query_treeObject



306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/window_geometry/x.rb', line 306

def query_tree
  root = ' '*8
  parent = ' '*8
  nchildren = X11::Int.malloc(Fiddle::RUBY_FREE)
  children_p = X11::Pointer.malloc(Fiddle::RUBY_FREE)
  ret = X11::XQueryTree(@display, @window, root, parent, children_p, nchildren)
  return if ret == 0

  nchildren.n.times.map do |i|
    win = children_p.ptr[X11::Window.size * i, X11::Window.size].unpack1('L!')
    Window.new(@display, win)
  end
end

#screenObject



354
355
356
357
358
# File 'lib/window_geometry/x.rb', line 354

def screen
  attr = X11::XWindowAttributes.malloc(Fiddle::RUBY_FREE)
  X11::XGetWindowAttributes(@display, @window, attr)
  X11::Screen.new(attr.screen)
end

#select_input(mask) ⇒ Object



302
303
304
# File 'lib/window_geometry/x.rb', line 302

def select_input(mask)
  X11::XSelectInput(@display, @window, mask)
end

#unmap_subwindowsObject



337
338
339
# File 'lib/window_geometry/x.rb', line 337

def unmap_subwindows
  X11::XUnmapSubwindows(@display, @window)
end

#unmap_windowObject



333
334
335
# File 'lib/window_geometry/x.rb', line 333

def unmap_window
  X11::XUnmapWindow(@display, @window)
end

#wm_hintsObject



269
270
271
272
273
274
275
276
277
# File 'lib/window_geometry/x.rb', line 269

def wm_hints
  hints = X11::XGetWMHints(@display, @window)
  return nil if hints.null?
  WMHints.new(hints.flags, hints.input, hints.initial_state,
              hints.icon_pixmap, hints.icon_window, hints.icon_x, hints.icon_y,
              hints.icon_mask, hints.window_group)
ensure
  X11::XFree(hints) unless hints.null?
end

#wm_nameObject



289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/window_geometry/x.rb', line 289

def wm_name
  prop = X11::XTextProperty.malloc(Fiddle::RUBY_FREE)
  text_list = X11::Pointer.malloc(Fiddle::RUBY_FREE)
  X11::XGetWMName(@display, @window, prop)
  X11::Xutf8TextPropertyToTextList(@display, prop, text_list, ' '*8)
  ptr = text_list.ptr
  if ptr.null?
    nil
  else
    ptr.ptr.to_s.force_encoding('utf-8')
  end
end

#wm_normal_hintsObject



279
280
281
282
283
284
285
286
287
# File 'lib/window_geometry/x.rb', line 279

def wm_normal_hints
  hints = X11::XSizeHints.malloc(Fiddle::RUBY_FREE)
  X11::XGetWMNormalHints(@display, @window, hints, ' '*8)
  SizeHints.new(hints.flags, hints.x, hints.y, hints.width, hints.height,
                hints.min_width, hints.min_height, hints.max_width, hints.max_height,
                hints.width_inc, hints.height_inc,
                hints.min_aspect_x, hints.min_aspect_y, hints.max_aspect_x, hints.max_aspect_y,
                hints.base_width, hints.base_height, hints.win_gravity)
end