Class: Wmctile::Router

Inherits:
Class
  • Object
show all
Defined in:
lib/wmctile/router.rb

Instance Method Summary collapse

Methods inherited from Class

#cmd, #notify

Constructor Details

#initializeRouter

init ##########################



5
6
7
8
# File 'lib/wmctile/router.rb', line 5

def initialize
	@settings = Wmctile::Settings.new
	@all_workspaces = false
end

Instance Method Details

#dispatch(args = []) ⇒ Object

main dispatch method ##########



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wmctile/router.rb', line 12

def dispatch args = []
	if args.length
		main_arg = args[0]
		if ['--all-workspaces', '-a'].include? main_arg 
			@all_workspaces = true
			drop = 2
			main_arg = args[1]
		else
			@all_workspaces = false
			drop = 1
		end
		if main_arg and !['dispatch', 'initialize', 'wm', 'wt', 'memory'].include? main_arg and self.respond_to? main_arg
			self.send main_arg, *args.drop(drop)
		else
			self.help
		end
	else
		self.help
	end
end

#help(args = nil) ⇒ Object

actual command-line methods ###



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/wmctile/router.rb', line 48

def help args = nil
	puts <<-eos
wmctile version 0.1.2

usage:
  wmctile [--option1, --option2, ...] <command> ['argument1', 'argument2', ...]

examples:
  wmctile snap 'left' 'terminator'
  wmctile summon --all-workspaces ':ACTIVE:'

options:
  --all-workspaces, -a
     Use all workspaces when searching for windows. 

commands:
  summon 'window_string'
     Summons a window matching 'window_str'.

  summon_or_run 'window_string' 'command_to_run'
     Summons a window matching 'window_string'. If no window is found, the 'command_to_run' is run.

  switch_to 'window_string'
     Switches to a window matching 'window_string'.

  switch_to_or_run 'window_string' 'command_to_run'
     Switches to a window matching 'window_string'. If no window is found, the 'command_to_run' is run.

  maximize 'window_string'
     Maximizes a window matching 'window_string'.

  unmaximize 'window_string'
     Unmaximizes a window matching 'window_string'.

  shade 'window_string'
     Shades a window matching 'window_string'.

  unshade 'window_string'
     Unshades a window matching 'window_string'.

  unshade_last_shaded
     Unshades the last shaded window on active workspace.

  snap 'where' 'window_string' ['portion']
     Snaps a window matching 'window_string' to occupy the 'where' 'portion' of the screen.
        'where' can be one of 'left', 'right', 'top', 'bottom'
        'portion' is a float number with the default of 0.5

  resize 'where' ['portion']
     Resizes the last performed action (snap/tile etc.) on active workspace.
        'where' can be one of 'left', 'right', 'top', 'bottom'
            The action depends on the previously performed action. When you resize 'left' a previous snap 'left', you're shrinking the  window. When you resize 'left' a previous snap 'right', you're increasing the size of the window.
        'portion' is a float number with the default of 0.01 by which to edit the previous portion of the screen

  resize_snap 'where' ['portion']
     Resizes the last performed snap on active workspace. Arguments are the same as in resize command.

additional information:
  To use the active window, pass ':ACTIVE:' as the 'window_string' argument.
	eos
end

#maximize(window_str) ⇒ Object



137
138
139
140
141
142
# File 'lib/wmctile/router.rb', line 137

def maximize window_str
	window = self.wm.get_window window_str
	if window
		window.maximize
	end
end

#memoryObject



42
43
44
# File 'lib/wmctile/router.rb', line 42

def memory
	@memory || @memory = Wmctile::Memory.new
end

#resize(where = 'left', portion = 0.01) ⇒ Object



180
181
182
# File 'lib/wmctile/router.rb', line 180

def resize where = 'left', portion = 0.01
	self.wt.resize where, portion
end

#resize_snap(where = 'left', portion = 0.01) ⇒ Object



183
184
185
# File 'lib/wmctile/router.rb', line 183

def resize_snap where = 'left', portion = 0.01
	self.wt.resize_snap where, portion
end

#shade(window_str) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/wmctile/router.rb', line 149

def shade window_str
	window = self.wm.get_window window_str
	if window
		window.shade
		self.memory.set self.wm.workspace, 'shade', {
			'window_id' => window.id
		}
	end
end

#snap(where = 'left', window_str = nil, portion = 0.5) ⇒ Object



177
178
179
# File 'lib/wmctile/router.rb', line 177

def snap where = 'left', window_str = nil, portion = 0.5
	self.wt.snap where, window_str, portion
end

#summon(window_str) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/wmctile/router.rb', line 109

def summon window_str
	window = self.wm.find_in_windows window_str, @all_workspaces
	if window
		window.summon
		return true
	else
		return false
	end
end

#summon_or_run(window_str, cmd_to_run) ⇒ Object



118
119
120
121
122
# File 'lib/wmctile/router.rb', line 118

def summon_or_run window_str, cmd_to_run
	unless self.summon window_str
		self.cmd "#{ cmd_to_run } > /dev/null &"
	end
end

#switch_to(window_str) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/wmctile/router.rb', line 123

def switch_to window_str
	window = self.wm.find_in_windows window_str, @all_workspaces
	if window
		window.switch_to
		return true
	else
		return false
	end
end

#switch_to_or_run(window_str, cmd_to_run) ⇒ Object



132
133
134
135
136
# File 'lib/wmctile/router.rb', line 132

def switch_to_or_run window_str, cmd_to_run
	unless self.switch_to window_str
		self.cmd "#{ cmd_to_run } > /dev/null &"
	end
end

#unmaximize(window_str) ⇒ Object



143
144
145
146
147
148
# File 'lib/wmctile/router.rb', line 143

def unmaximize window_str
	window = self.wm.get_window window_str
	if window
		window.unmaximize
	end
end

#unshade(window_str) ⇒ Object



158
159
160
161
162
163
164
165
166
# File 'lib/wmctile/router.rb', line 158

def unshade window_str
	window = self.wm.get_window window_str
	if window
		window.unshade
		self.memory.set self.wm.workspace, 'unshade', {
			'window_id' => window.id
		}
	end
end

#unshade_last_shadedObject



167
168
169
170
171
172
173
174
175
176
# File 'lib/wmctile/router.rb', line 167

def unshade_last_shaded
	win_id = self.memory.get self.wm.workspace, 'shade', 'window_id'
	window = Wmctile::Window.new win_id, @settings
	if window
		window.unshade
		self.memory.set self.wm.workspace, 'unshade', {
			'window_id' => window.id
		}
	end
end

#wmObject

object getter methods #########



35
36
37
# File 'lib/wmctile/router.rb', line 35

def wm
	@wm || @wm = Wmctile::WindowManager.new(@settings)
end

#wtObject



38
39
40
41
# File 'lib/wmctile/router.rb', line 38

def wt
	# @wm might be nil
	@wt || @wt = Wmctile::WindowTiler.new(@settings, self.memory, @wm)
end