Module: Wmadd::X11

Extended by:
Fiddle::Importer
Defined in:
lib/wmadd/x.rb

Constant Summary collapse

Screen =
struct [
  'XExtData *ext_data',
  'struct _XDisplay *display',
  'Window root',
  'int width',
  'int height',
  'int mwidth',
  'int mheight',
  'int ndepths',
  'Depth *depths',
  'int root_depth',
  'Visual *root_visual',
  'GC default_gc',
  'Colormap cmap',
  'unsigned long white_pixel',
  'unsigned long black_pixel',
  'int max_maps',
  'int min_maps',
  'int backing_store',
  'Bool save_unders',
  'long root_input_mask',
]
Window =
struct ['Window window']
Pointer =
struct ['void *ptr']
XClassHint =
struct ['char *name', 'char *class_name']
XSizeHints =
struct [
  'long flags', 'int x', 'int y', 'int width', 'int height',
  'int min_width', 'int min_height', 'int max_width', 'int max_height',
  'int width_inc', 'int height_inc',
  'int min_aspect_x', 'int min_aspect_y', 'int max_aspect_x', 'int max_aspect_y',
  'int base_width', 'int base_height',
  'int win_gravity',
]
XTextProperty =
struct ['unsigned char *value', 'Atom encoding', 'int format', 'unsigned long nitems']
XCreateWindowEvent =
struct [
  'int type',
  'unsigned long serial',
  'Bool send_event',
  'Display *display',
  'Window parent',
  'Window window',
  'int x',
  'int y',
  'int width',
  'int height',
  'int border_width',
  'Bool override_redirect',
]
XConfigureEvent =
struct [
  'int type',
  'unsigned long serial',
  'Bool send_event',
  'Display *display',
  'Window event',
  'Window window',
  'int x',
  'int y',
  'int width',
  'int height',
  'int border_width',
  'Window above',
  'Bool override_redirect',
]
XExposeEvent =
struct [
  'int type',
  'unsigned long serial',
  'Bool send_event',
  'Display *display',
  'Window window',
  'int x',
  'int y',
  'int width',
  'int height',
  'int count',
]
XPropertyEvent =
struct [
  'int type',
  'unsigned long serial',
  'Bool send_event',
  'Display *display',
  'Window window',
  'Atom atom',
  'Time time',
  'int state',
]
XWMHints =
struct [
  'long flags',
  'Bool input',
  'int initial_state',
  'Pixmap icon_pixmap',
  'Window icon_window',
  'int icon_x',
  'int icon_y',
  'Pixmap icon_mask',
  'XID window_group',
]
XWindowAttributes =
struct [
  'int x',
  'int y',
  'int width',
  'int height',
  'int border_width',
  'int depth',
  'Visual *visual',
  'Window root',
  'int c_class',
  'int bit_gravity',
  'int win_gravity',
  'int backing_store',
  'unsigned long backing_planes',
  'unsigned long backing_pixel',
  'Bool save_under',
  'Colormap colormap',
  'Bool map_installed',
  'int map_state',
  'long all_event_masks',
  'long your_event_mask',
  'long do_not_propagate_mask',
  'Bool override_redirect',
  'Screen *screen',
]
Int =
struct ['int n']
UnsignedLong =
struct ['unsigned long n']
ErrorHandler =
bind("int error_handler(Display*, XErrorEvent*)") { |*| return 0 }

Class Method Summary collapse

Class Method Details

.struct(members) ⇒ Object



19
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
45
46
47
# File 'lib/wmadd/x.rb', line 19

def self.struct(members)
  klass = super

  h = members.map.to_h do |member|
    if member =~ /\A(.*\*\s*)(\w+)\z/
      name = $2
      pointer = true
    elsif member =~ /(\w+)\z/
      name = $1
      pointer = false
    end
    [name.intern, pointer]
  end

  klass.define_singleton_method :attributes do
    h.keys
  end

  klass.define_method :to_h do
    super().transform_values{|v| v.is_a?(Fiddle::Pointer) && v.null? ? nil : v}
  end

  klass.define_method :inspect do
    h = to_h.transform_values{|v| v.is_a?(Fiddle::Pointer) ? "(pointer)" : v}
    "#<#{klass.name}: #{h.inspect}>"
  end

  klass
end