rum 0.0.1-universal-darwin-10 → 0.0.3-universal-darwin-10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGELOG +9 -0
  2. data/README.md +35 -0
  3. data/Rakefile +22 -19
  4. data/bin/rum-client +4 -4
  5. data/doc/basic.rb +1 -1
  6. data/doc/doc.html +619 -602
  7. data/doc/example.rb +1 -1
  8. data/doc/reference.rb +29 -16
  9. data/doc/resources/build.rb +14 -12
  10. data/doc/resources/doc.haml +8 -3
  11. data/ext/mac/keyboard_hook/EventTap.h +1 -1
  12. data/ext/mac/keyboard_hook/EventTap.m +9 -9
  13. data/ext/mac/keyboard_hook/KeyboardHook.xcodeproj/project.pbxproj +12 -9
  14. data/ext/windows/keyboard_hook/keyboard_hook.c +3 -3
  15. data/ext/windows/system/autohotkey_stuff.c +12 -10
  16. data/ext/windows/system/clipboard_watcher.c +2 -2
  17. data/ext/windows/system/extconf.rb +1 -0
  18. data/ext/windows/system/input_box.c +9 -9
  19. data/ext/windows/system/system.c +51 -46
  20. data/lib/rum/barrel.rb +46 -16
  21. data/lib/rum/barrel/emacs.rb +1 -1
  22. data/lib/rum/barrel/emacs_client.rb +32 -5
  23. data/lib/rum/core.rb +24 -22
  24. data/lib/rum/dsl.rb +15 -16
  25. data/lib/rum/gui.rb +3 -3
  26. data/lib/rum/help.rb +10 -8
  27. data/lib/rum/hotkey_core.rb +35 -25
  28. data/lib/rum/mac.rb +1 -1
  29. data/lib/rum/mac/gui.rb +1 -1
  30. data/lib/rum/mac/gui/growl.rb +3 -3
  31. data/lib/rum/mac/irb/completion.rb +13 -13
  32. data/lib/rum/mac/keyboard_hook.rb +8 -5
  33. data/lib/rum/mac/keyboard_hook/KeyboardHook.framework/KeyboardHook +0 -0
  34. data/lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/KeyboardHook +0 -0
  35. data/lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/Resources/English.lproj/InfoPlist.strings +0 -0
  36. data/lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/Resources/Info.plist +16 -0
  37. data/lib/rum/mac/layouts.rb +4 -4
  38. data/lib/rum/mac/system.rb +2 -2
  39. data/lib/rum/remote.rb +3 -3
  40. data/lib/rum/server.rb +2 -3
  41. data/lib/rum/windows.rb +2 -1
  42. data/lib/rum/windows/app.rb +12 -7
  43. data/lib/rum/windows/apps.rb +3 -8
  44. data/lib/rum/windows/gui.rb +8 -8
  45. data/lib/rum/windows/keyboard.rb +34 -9
  46. data/lib/rum/windows/layouts.rb +6 -6
  47. data/lib/rum/windows/system.rb +71 -28
  48. data/lib/rum/windows/system_foreign_functions.rb +44 -20
  49. data/rum.gemspec +2 -2
  50. metadata +32 -53
  51. data/README +0 -30
@@ -7,7 +7,7 @@ module Rum
7
7
  def default_layout
8
8
  us
9
9
  end
10
-
10
+
11
11
  def core
12
12
  # http://msdn.microsoft.com/en-us/library/dd375731%28VS.85%29.aspx
13
13
  core = Layout.new
@@ -133,12 +133,12 @@ module Rum
133
133
 
134
134
  def basic
135
135
  basic = core
136
-
136
+
137
137
  basic.remap 'lcontrol', 'rcontrol', 'control'
138
138
  basic.remap 'rmenu', 'lmenu'
139
139
  basic.remap 'lshift', 'rshift', 'shift'
140
140
  basic.remap 'rwin', 'lwin'
141
-
141
+
142
142
  basic.alias 'control', 'ctrl'
143
143
  basic.alias 'control', 'c'
144
144
  basic.rename 'lmenu', 'alt'
@@ -152,8 +152,8 @@ module Rum
152
152
  basic.rename 'prior', 'pageup'
153
153
  basic.rename 'next', 'pagedown'
154
154
  basic.rename 'snapshot', 'print'
155
-
156
-
155
+
156
+
157
157
  %w{shift control alt win}.each { |key| basic.core_modifier key }
158
158
 
159
159
  basic.action_modifier 'alt'
@@ -205,7 +205,7 @@ END
205
205
  german.rename 'oem_6', '´'
206
206
  german.rename 'oem_7', 'ä'
207
207
  german.rename 'oem_102', '<'
208
-
208
+
209
209
  shift_translations = <<END.scan(/(\S) (\S)/)
210
210
  ° ^ $ 4 ( 8 ` ´ ; ,
211
211
  ! 1 % 5 ) 9 * + : .
@@ -3,9 +3,13 @@ require_relative 'system_foreign_functions'
3
3
  module Rum
4
4
  module System
5
5
  extend self
6
-
6
+
7
7
  def send_key_event key, down
8
- extended, id = key.id.divmod 2**9
8
+ send_key_event_for_id key.id, down
9
+ end
10
+
11
+ def send_key_event_for_id id, down
12
+ extended, id = id.divmod 2**9
9
13
  extended = (extended == 1)
10
14
  keybd_event id, down, 0, extended
11
15
  end
@@ -15,6 +19,10 @@ module Rum
15
19
  send_key_event key, false
16
20
  end
17
21
 
22
+ def send_unicode_char char
23
+ send_unicode_char_internal(char.encode(Encoding::UTF_16LE))
24
+ end
25
+
18
26
  def active_window_handles
19
27
  Enumerator.new(self, :enum_windows)
20
28
  end
@@ -28,7 +36,7 @@ module Rum
28
36
  def active_window
29
37
  Window.new get_foreground_window
30
38
  end
31
-
39
+
32
40
  def terminal_window
33
41
  Window.new get_console_window
34
42
  end
@@ -51,7 +59,7 @@ module Rum
51
59
  # returns a copy
52
60
  def c_string obj
53
61
  str = obj.to_s + "\0"
54
- str.encode(Encoding::UTF_16LE)
62
+ str.encode(Encoding::UTF_16LE)
55
63
  end
56
64
 
57
65
  def message_box message, title=''
@@ -81,11 +89,15 @@ module Rum
81
89
  Clipboard.preserve { Clipboard.get_selection }
82
90
  end
83
91
 
84
- class Window
92
+ def kill_task exe_name
93
+ system("taskkill /F /IM #{exe_name}.exe")
94
+ end
95
+
96
+ class Window
85
97
  include System
86
-
98
+
87
99
  attr_reader :handle
88
-
100
+
89
101
  def initialize(handle)
90
102
  @handle = handle
91
103
  end
@@ -94,7 +106,7 @@ module Rum
94
106
  return false unless other.respond_to? :handle
95
107
  @handle == other.handle
96
108
  end
97
-
109
+
98
110
  def active?
99
111
  self.handle == get_foreground_window
100
112
  end
@@ -118,7 +130,7 @@ module Rum
118
130
  def maximize
119
131
  post_message @handle, WM_SYSCOMMAND, SC_MAXIMIZE, 0
120
132
  end
121
-
133
+
122
134
  def minimize
123
135
  post_message @handle, WM_SYSCOMMAND, SC_MINIMIZE, 0
124
136
  end
@@ -127,6 +139,15 @@ module Rum
127
139
  post_message @handle, WM_SYSCOMMAND, SC_RESTORE, 0
128
140
  end
129
141
 
142
+ # Don't underestimate the Force
143
+ def force_show
144
+ 100.times do
145
+ show
146
+ sleep 0.02
147
+ return true if active_window == self
148
+ end
149
+ end
150
+
130
151
  def file_dialog?
131
152
  class_name == '#32770'
132
153
  end
@@ -150,7 +171,7 @@ module Rum
150
171
  restore if zoomed?
151
172
  move_window(@handle, x, y, width, height, 1)
152
173
  end
153
-
174
+
154
175
  def title(max_length = 1024)
155
176
  buffer = "\0" * (max_length * 2)
156
177
  length = get_window_text_w(@handle, buffer, buffer.length)
@@ -158,13 +179,13 @@ module Rum
158
179
  result.force_encoding(Encoding::UTF_16LE)
159
180
  result.encode(Encoding::UTF_8, invalid: :replace)
160
181
  end
161
-
182
+
162
183
  def class_name(max_length = 2048)
163
184
  buffer = "\0" * max_length
164
185
  length = get_class_name(@handle, buffer, buffer.length)
165
186
  length == 0 ? '' : buffer[0..length - 1]
166
187
  end
167
-
188
+
168
189
  def text(max_length = 2048)
169
190
  buffer = '\0' * max_length
170
191
  length = send_with_buffer @handle, WM_GETTEXT, buffer.length, buffer
@@ -182,19 +203,44 @@ module Rum
182
203
  else
183
204
  0
184
205
  end
185
-
206
+
186
207
  raise "Control '#{id}' not found" if result == 0
187
208
  Window.new result
188
209
  end
189
210
 
211
+ def child_window class_name
212
+ if class_name.is_a? Regexp
213
+ child_windows.find { |child| child.class_name =~ class_name }
214
+ else
215
+ child_windows.find { |child| child.class_name == class_name }
216
+ end
217
+ end
218
+
219
+ def child_windows
220
+ Enumerator.new do |yielder|
221
+ enum_child_windows { |handle| yielder.yield Window.new(handle) }
222
+ end
223
+ end
224
+
190
225
  def kill_task
191
- system("taskkill /F /IM #{exe_name}.exe")
226
+ System.kill_task exe_name
192
227
  end
193
-
228
+
194
229
  def report
195
230
  "Title: #{title}\nClass: #{class_name}"
196
231
  end
197
232
 
233
+ def exe_path
234
+ exe_path_internal.
235
+ force_encoding(Encoding::UTF_16LE).
236
+ encode(Encoding::UTF_8).
237
+ gsub('\\', '/')
238
+ end
239
+
240
+ def exe_name
241
+ File.basename(exe_path, '.exe')
242
+ end
243
+
198
244
  def self.[] arg, class_name=nil
199
245
  if arg.is_a? Hash
200
246
  WindowMatcher.new(arg[:title], arg[:class_name])
@@ -207,7 +253,7 @@ module Rum
207
253
  class WindowMatcher
208
254
  include System
209
255
  attr_reader :specs
210
-
256
+
211
257
  def initialize title=nil, class_name=nil
212
258
  @specs = { title: title, class_name: class_name }
213
259
  raise 'No specifications given.' unless @specs.values.any?
@@ -221,7 +267,7 @@ module Rum
221
267
  def comparison_method obj
222
268
  if obj.is_a? Regexp then :=~ else :== end
223
269
  end
224
-
270
+
225
271
  def matches? window
226
272
  @specs.all? do |spec, value|
227
273
  not value or value.send(comparison_method(value), window.send(spec))
@@ -249,14 +295,18 @@ module Rum
249
295
  end
250
296
  end
251
297
  end
252
-
298
+
253
299
  module Clipboard
254
300
  extend self
255
-
301
+
256
302
  def get
257
303
  Win32::Clipboard.get
258
304
  end
259
-
305
+
306
+ def get_html
307
+ Win32::Clipboard.get_html
308
+ end
309
+
260
310
  def set str
261
311
  Win32::Clipboard.set str
262
312
  end
@@ -268,12 +318,6 @@ module Rum
268
318
  set old_content
269
319
  end
270
320
 
271
- # def copy
272
- # watcher = install_watcher
273
- # Keyboard.type '(ctrl c)'
274
- # evaluate_watcher(watcher, 400) # Timeout: 400 msec
275
- # end
276
-
277
321
  def wait_for_change
278
322
  watcher = install_watcher
279
323
  begin
@@ -291,7 +335,7 @@ module Rum
291
335
  def paste
292
336
  Keyboard.type '(ctrl v)'
293
337
  end
294
-
338
+
295
339
  def get_selection
296
340
  Clipboard.get if Clipboard.copy
297
341
  end
@@ -307,4 +351,3 @@ module Rum
307
351
  end
308
352
  end
309
353
  end
310
-
@@ -41,14 +41,14 @@ module Rum
41
41
  def_api 'SendMessage', 'LLLP', 'L', :send_with_buffer
42
42
  def_api 'SendMessage', 'LLLL', 'L'
43
43
  def_api 'PostMessage', 'LLLL', 'L'
44
- def_api 'GetDlgItem', 'LL', 'L'
44
+ def_api 'GetDlgItem', 'LL', 'L'
45
45
  def_api 'GetWindowRect', 'LP', 'I'
46
- def_api 'SetCursorPos', 'LL', 'I'
46
+ def_api 'SetCursorPos', 'LL', 'I'
47
47
  def_api 'mouse_event', 'LLLLL', 'V'
48
48
  def_api 'IsWindow', 'L', 'L'
49
49
  def_api 'IsWindowVisible', 'L', 'L'
50
50
  def_api 'SetForegroundWindow', 'L', 'L'
51
-
51
+
52
52
  def_api 'GetWindowLong', 'LI', 'L'
53
53
  def_api 'GetForegroundWindow', 'V', 'L'
54
54
  def_api 'GetClassName', 'LPI', 'I'
@@ -60,15 +60,17 @@ module Rum
60
60
  def_api 'IsZoomed', 'L', 'L'
61
61
  def_api 'SetWindowPos', 'LLIIIII', 'I'
62
62
  def_api 'MoveWindow', 'LIIIIB', 'L'
63
-
63
+
64
64
  ShellExecute = Win32::API.new('ShellExecute', 'LPPPPI', 'L', 'shell32')
65
65
  def start command, parameters=0
66
+ command.encode!(Encoding::WINDOWS_1252)
67
+ parameters.encode!(Encoding::WINDOWS_1252) if parameters != 0
66
68
  ShellExecute.call(0, 'open', command, parameters, 0, 1)
67
69
  end
68
-
69
- WM_COMMAND = 0x0111
70
+
71
+ WM_COMMAND = 0x0111
70
72
  WM_SYSCOMMAND = 0x0112
71
-
73
+
72
74
  SC_CLOSE = 0xF060
73
75
  SC_RESTORE = 0xF120;
74
76
  SC_MAXIMIZE = 0xF030;
@@ -105,19 +107,17 @@ end
105
107
  module Win32
106
108
  class Clipboard
107
109
  def self.get
108
- begin
109
- self.open
110
- return '' unless IsClipboardFormatAvailable(UNICODETEXT)
111
- handle = GetClipboardData(UNICODETEXT)
112
- clip_data = 0.chr * GlobalSize(handle)
113
- memcpy(clip_data, handle, clip_data.size)
114
- clip_data.force_encoding(Encoding::UTF_16LE)
115
- clip_data.encode!(Encoding::UTF_8, invalid: :replace, replace: '', \
116
- universal_newline: true)
117
- clip_data[ /^[^\0]*/ ]
118
- ensure
119
- self.close
120
- end
110
+ self.open
111
+ return '' unless IsClipboardFormatAvailable(UNICODETEXT)
112
+ handle = GetClipboardData(UNICODETEXT)
113
+ clip_data = 0.chr * GlobalSize(handle)
114
+ memcpy(clip_data, handle, clip_data.size)
115
+ clip_data.force_encoding(Encoding::UTF_16LE)
116
+ clip_data.encode!(Encoding::UTF_8, invalid: :replace, replace: '', \
117
+ universal_newline: true)
118
+ clip_data[ /^[^\0]*/ ]
119
+ ensure
120
+ self.close
121
121
  end
122
122
 
123
123
  def self.set str
@@ -125,5 +125,29 @@ module Win32
125
125
  data.force_encoding Encoding::BINARY
126
126
  set_data(data, UNICODETEXT)
127
127
  end
128
+
129
+ def self.html_format
130
+ @html_format ||= register_format('HTML Format')
131
+ end
132
+
133
+ def self.get_html
134
+ html = html_format
135
+ self.open
136
+ if IsClipboardFormatAvailable(html)
137
+ handle = GetClipboardData(html)
138
+ clip_data = 0.chr * GlobalSize(handle)
139
+ memcpy(clip_data, handle, clip_data.size)
140
+ clip_data.force_encoding(Encoding::UTF_8)
141
+ clip_data = clip_data[ /^[^\0]*/ ]
142
+ end
143
+ ensure
144
+ self.close
145
+ end
146
+
147
+ def self.set_html str
148
+ data = str + "\0"
149
+ data.force_encoding Encoding::BINARY
150
+ set_data(data, html_format)
151
+ end
128
152
  end
129
153
  end
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rum'
5
- spec.version = '0.0.1'
5
+ spec.version = '0.0.3'
6
6
  spec.author = 'nonsequitur'
7
7
  spec.license = 'MIT'
8
8
  spec.homepage = 'http://nonsequitur.github.com/rum'
@@ -10,5 +10,5 @@ Gem::Specification.new do |spec|
10
10
  spec.required_ruby_version = '>= 1.9.1'
11
11
 
12
12
  spec.executables << 'rum-client'
13
- spec.extra_rdoc_files = ['README']
13
+ spec.extra_rdoc_files = ['README.md']
14
14
  end
metadata CHANGED
@@ -1,35 +1,28 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rum
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
11
6
  platform: universal-darwin-10
12
- authors:
7
+ authors:
13
8
  - nonsequitur
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-06-04 00:00:00 +04:00
19
- default_executable:
12
+ date: 2012-11-24 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
14
  description:
23
15
  email:
24
- executables:
16
+ executables:
25
17
  - rum-client
26
18
  extensions: []
27
-
28
- extra_rdoc_files:
29
- - README
30
- files:
31
- - bin/rum-client
19
+ extra_rdoc_files:
20
+ - README.md
21
+ files:
32
22
  - CHANGELOG
23
+ - README.md
24
+ - Rakefile
25
+ - bin/rum-client
33
26
  - doc/basic.rb
34
27
  - doc/doc.html
35
28
  - doc/example.rb
@@ -53,8 +46,8 @@ files:
53
46
  - ext/mac/keyboard_hook/EventTap.h
54
47
  - ext/mac/keyboard_hook/EventTap.m
55
48
  - ext/mac/keyboard_hook/Info.plist
56
- - ext/mac/keyboard_hook/KeyboardHook.xcodeproj/project.pbxproj
57
49
  - ext/mac/keyboard_hook/KeyboardHook.xcodeproj/TemplateIcon.icns
50
+ - ext/mac/keyboard_hook/KeyboardHook.xcodeproj/project.pbxproj
58
51
  - ext/mac/keyboard_hook/KeyboardHook_Prefix.pch
59
52
  - ext/mac/keyboard_hook/version.plist
60
53
  - ext/windows/keyboard_hook/extconf.rb
@@ -67,17 +60,20 @@ files:
67
60
  - ext/windows/system/input_box.c
68
61
  - ext/windows/system/input_box.h
69
62
  - ext/windows/system/system.c
63
+ - lib/rum.rb
70
64
  - lib/rum/apps.rb
65
+ - lib/rum/barrel.rb
71
66
  - lib/rum/barrel/emacs.rb
72
67
  - lib/rum/barrel/emacs_client.rb
73
- - lib/rum/barrel.rb
74
68
  - lib/rum/core.rb
75
69
  - lib/rum/dsl.rb
76
70
  - lib/rum/gui.rb
77
71
  - lib/rum/help.rb
78
72
  - lib/rum/hotkey_core.rb
73
+ - lib/rum/mac.rb
79
74
  - lib/rum/mac/app.rb
80
75
  - lib/rum/mac/apps.rb
76
+ - lib/rum/mac/gui.rb
81
77
  - lib/rum/mac/gui/CocoaDialog.app/Contents/Info.plist
82
78
  - lib/rum/mac/gui/CocoaDialog.app/Contents/MacOS/CocoaDialog
83
79
  - lib/rum/mac/gui/CocoaDialog.app/Contents/Resources/Info.plist
@@ -101,18 +97,17 @@ files:
101
97
  - lib/rum/mac/gui/Growl.framework/Versions/A/Headers/GrowlDefines.h
102
98
  - lib/rum/mac/gui/Growl.framework/Versions/A/Resources/Info.plist
103
99
  - lib/rum/mac/gui/growl.rb
104
- - lib/rum/mac/gui.rb
105
100
  - lib/rum/mac/irb/completion.rb
101
+ - lib/rum/mac/keyboard_hook.rb
106
102
  - lib/rum/mac/keyboard_hook/KeyboardHook.framework/KeyboardHook
107
103
  - lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/KeyboardHook
108
104
  - lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/Resources/English.lproj/InfoPlist.strings
109
105
  - lib/rum/mac/keyboard_hook/KeyboardHook.framework/Versions/A/Resources/Info.plist
110
- - lib/rum/mac/keyboard_hook.rb
111
106
  - lib/rum/mac/layouts.rb
112
107
  - lib/rum/mac/system.rb
113
- - lib/rum/mac.rb
114
108
  - lib/rum/remote.rb
115
109
  - lib/rum/server.rb
110
+ - lib/rum/windows.rb
116
111
  - lib/rum/windows/app.rb
117
112
  - lib/rum/windows/apps.rb
118
113
  - lib/rum/windows/gui.rb
@@ -121,46 +116,30 @@ files:
121
116
  - lib/rum/windows/layouts.rb
122
117
  - lib/rum/windows/system.rb
123
118
  - lib/rum/windows/system_foreign_functions.rb
124
- - lib/rum/windows.rb
125
- - lib/rum.rb
126
- - Rakefile
127
- - README
128
119
  - rum.gemspec
129
- has_rdoc: true
130
120
  homepage: http://nonsequitur.github.com/rum
131
- licenses:
121
+ licenses:
132
122
  - MIT
133
123
  post_install_message:
134
124
  rdoc_options: []
135
-
136
- require_paths:
125
+ require_paths:
137
126
  - lib
138
- required_ruby_version: !ruby/object:Gem::Requirement
127
+ required_ruby_version: !ruby/object:Gem::Requirement
139
128
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- hash: 49
144
- segments:
145
- - 1
146
- - 9
147
- - 1
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
148
132
  version: 1.9.1
149
- required_rubygems_version: !ruby/object:Gem::Requirement
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
134
  none: false
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- hash: 3
155
- segments:
156
- - 0
157
- version: "0"
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
158
139
  requirements: []
159
-
160
140
  rubyforge_project:
161
- rubygems_version: 1.3.7
141
+ rubygems_version: 1.8.24
162
142
  signing_key:
163
143
  specification_version: 3
164
144
  summary: A cross-platform Hotkey and Macro utility, running on Windows and Mac OS.
165
145
  test_files: []
166
-