Class: WMCtrl::Window

Inherits:
DataHash show all
Defined in:
lib/wmctrl/wmctrl.rb

Constant Summary collapse

STATE_FULLSCREEN =
"_NET_WM_STATE_FULLSCREEN"

Instance Method Summary collapse

Methods inherited from DataHash

#initialize, #method_missing

Constructor Details

This class inherits a constructor from WMCtrl::DataHash

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class WMCtrl::DataHash

Instance Method Details

#[](key) ⇒ Object

Parameters:

  • key (Symbol)

    Valid keys are :class, :id, :title, :active, :desktop, :client_machine, :pid, :geometry, :state, :exterior_frame, :frame_extents, and :strut. :wm_class is an alias of :class.



72
73
74
75
76
77
78
# File 'lib/wmctrl/wmctrl.rb', line 72

def [](key)
  if key == :wm_class
    self.wm_class
  else
    super(key)
  end
end

#activateObject



109
110
111
# File 'lib/wmctrl/wmctrl.rb', line 109

def activate
  action(:activate)
end

#active?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/wmctrl/wmctrl.rb', line 84

def active?
  self[:active]
end

#change_state(*args) ⇒ Object



105
106
107
# File 'lib/wmctrl/wmctrl.rb', line 105

def change_state(*args)
  action(:change_state, *args)
end

#closeObject



101
102
103
# File 'lib/wmctrl/wmctrl.rb', line 101

def close
  action(:close)
end

#fullscreen?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/wmctrl/wmctrl.rb', line 90

def fullscreen?
  self[:state].include?(STATE_FULLSCREEN)
end

#place(opts = {}) ⇒ Object

Parameters:

  • opts (Hash) (defaults to: {})

    Options

Options Hash (opts):

  • :x (Integer)

    X coordinate

  • :y (Integer)

    Y coordinate

  • :width (Integer)

    Width of window

  • :height (Integer)

    Height of window

  • :desktop (Integer, :current)

    Desktop number



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/wmctrl/wmctrl.rb', line 119

def place(opts = {})
  if opts[:desktop]
    if opts[:desktop] == :current
      action(:move_to_current)
    elsif (opts[:desktop] != self[:desktop])
      action(:move_to_desktop, opts[:desktop])
    end
  end
  x = self[:exterior_frame][0]
  y = self[:exterior_frame][1]
  width = self[:exterior_frame][2]
  height = self[:exterior_frame][3]
  extent_horizontal = self[:frame_extents][0] + self[:frame_extents][1]
  extent_vertical = self[:frame_extents][2] + self[:frame_extents][3]
  width = opts[:width] if opts[:width] && (opts[:width] != width)
  height = opts[:height] if opts[:height] && (opts[:height] != height)
  x = opts[:x] if opts[:x] && (opts[:x] != x)
  y = opts[:y] if opts[:y] && (opts[:y] != y)
  action(:move_resize, 0, x + self[:frame_extents][0], y + self[:frame_extents][1], width - extent_horizontal, height - extent_vertical)
end

#positionObject



140
141
142
143
# File 'lib/wmctrl/wmctrl.rb', line 140

def position
  a = self[:exterior_frame]
  { :x => a[0], :y => a[1], :width => a[2], :height => a[3] }
end

#sticky?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/wmctrl/wmctrl.rb', line 80

def sticky?
  self[:desktop] == -1
end

#wm_classObject

Because method name "class" is a basic ruby method, we use "wm_class" to get window class.



65
66
67
# File 'lib/wmctrl/wmctrl.rb', line 65

def wm_class
  self[:class]
end