mouse 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e81909b0a768cd68bb57c1fb51e957cc94d4a5dc
4
- data.tar.gz: 20450a678f6e938de48df53e9d165832df06f5c3
3
+ metadata.gz: 2ddfe16e59a8a567e6ebd72a64bde83a5975b70a
4
+ data.tar.gz: 5903fd9b63b5071d4076d71a67ab30fd32bee76f
5
5
  SHA512:
6
- metadata.gz: 6df452f27bff39f031bfcf620c19a1bcc7d07ead593d2bf0978865d6c0c7da079c80677f3851236457acae952ffe3c3284d49aae003dcb557a0c3042c46d8046
7
- data.tar.gz: 04b9727b98e30a3594a664a675a8c87f3d4ccd951c3c376e71226e89c4dcbb02fdf4a87d12cd1a156aba758e81aa87c97863d61830d0ea7622202c81c515321d
6
+ metadata.gz: d0cc22ad9e05aa6a5b4aed1619b505be16204a9a961cae862b7fcf6e0ef42ef42506d9791a59e8729faf5db0043e470403566114aab54f043b79cf9f96e21830
7
+ data.tar.gz: ad82dcd3fff38d40cf33803a1db0adbd037a4b96b44dbbadf4355ee915c436372d05d55734e2d992d32cdaa14f451ee746dbbc91ec437da2b3bb8a723079c272
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ Kp����6�X��⼐�J�j ������!TD��Qh��{���v��?� e���a��!���ξ��e�f�2�)q�5_���!k�u���†r�߲����7���l�f��������g �5�.��:�����ufu��}s|(C\}?����uw�
2
+ �~ʸ:�>�𖹍�%�:�%�x+DY�{���l��̈́Vmv�K߳�}�{�\��ܖ+$z;B�w�L����W�'�N3c����'z�~�!�$-�
data.tar.gz.sig ADDED
Binary file
data/History.markdown CHANGED
@@ -1,3 +1,11 @@
1
+ # 4.0.0 - Scaling Yosemite
2
+
3
+ * Finish removing MacRuby support
4
+ * Cleanup coding style and doocumentation, and also enable stricter warnings
5
+ * Begin signing the gem
6
+ * Begin distributing pre-compiled versions of the gem
7
+ * Yosemite compatability
8
+
1
9
  # 3.0.0 - The death of MacRuby
2
10
 
3
11
  * Remove MacRuby support (sort of)
data/README.markdown CHANGED
@@ -15,6 +15,8 @@ testing; this is the purpose of the
15
15
 
16
16
  [![Code Climate](https://codeclimate.com/github/AXElements/mouse.png)](https://codeclimate.com/github/AXElements/mouse)
17
17
  [![Dependency Status](https://gemnasium.com/AXElements/mouse.png)](https://gemnasium.com/AXElements/mouse)
18
+ [![Gem Version](https://badge.fury.io/rb/mouse.svg)](http://badge.fury.io/rb/mouse)
19
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/AXElements/mouse/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
18
20
 
19
21
 
20
22
  ## Examples
@@ -91,9 +93,20 @@ change in the future if there are enough complaints.
91
93
  - [ ] Import test app and specialize so we can have better tests
92
94
 
93
95
 
96
+ ## Security
97
+
98
+ mouse is cryptographically signed. To be sure the gem you install
99
+ hasn’t been tampered with you will want to add my public key (if you
100
+ haven’t already) as a trusted certificate for Rubygems:
101
+
102
+ ```sh
103
+ gem cert --add <(curl -Ls https://raw.github.com/AXElements/mouse/master/certs/markrada26@gmail.com.pem)
104
+ gem install mouse -P HighSecurity
105
+ ```
106
+
94
107
  ## Copyright
95
108
 
96
- Copyright (c) 2012-2013, Mark Rada
109
+ Copyright (c) 2012-2015, Mark Rada
97
110
  All rights reserved.
98
111
 
99
112
  Redistribution and use in source and binary forms, with or without
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
- task :default => :test
1
+ task default: :test
2
2
 
3
3
  require 'rake/clean'
4
- CLEAN.include '*.plist', '*.gch'
4
+ CLOBBER.include '*.plist', '*.gch'
5
5
 
6
6
  desc 'Run the Clang static analyzer'
7
7
  task :analyze do
8
- sh "clang --analyze ext/mouse/mouser.c"
8
+ sh 'clang --analyze ext/mouse/mouser.c'
9
9
  end
10
10
 
11
11
  desc 'Startup an IRb console with Mouse loaded'
12
- task :console => [:compile] do
12
+ task console: :compile do
13
13
  sh 'irb -Ilib -rmouse'
14
14
  end
15
15
 
@@ -18,24 +18,23 @@ Rake::TestTask.new do |t|
18
18
  t.libs << '.'
19
19
  t.pattern = 'test/*_test.rb'
20
20
  end
21
- task :test => :compile
22
-
21
+ task test: :compile
23
22
 
24
23
  # Gem stuff
25
24
 
26
25
  require 'rubygems/package_task'
27
26
  mouse_spec = Gem::Specification.load('mouse.gemspec')
28
27
 
29
- Gem::PackageTask.new(mouse_spec) { }
30
-
31
- desc 'Build and install gem (not including deps)'
32
- task :install => :gem do
33
- require 'rubygems/installer'
34
- Gem::Installer.new("pkg/#{mouse_spec.file_name}").install
35
- end
28
+ Gem::PackageTask.new(mouse_spec) {}
36
29
 
37
30
  require 'rake/extensiontask'
38
31
  Rake::ExtensionTask.new('mouse', mouse_spec) do |t|
39
32
  t.lib_dir = 'lib/mouse'
33
+ t.ext_dir = 'ext/mouse'
40
34
  end
41
35
 
36
+ desc 'Build and install gem (not including deps)'
37
+ task install: :gem do
38
+ require 'rubygems/installer'
39
+ Gem::Installer.new("pkg/#{mouse_spec.file_name}").install
40
+ end
data/ext/mouse/extconf.rb CHANGED
@@ -1,24 +1,19 @@
1
1
  require 'mkmf'
2
2
 
3
- $CFLAGS << ' -std=c99 -Wall -Werror -pedantic'
4
- $LIBS << ' -framework Foundation -framework ApplicationServices'
5
- $LIBS << ' -framework CoreGraphics' unless `sw_vers -productVersion`.to_f == 10.7
3
+ $CFLAGS << ' -std=c99 -Weverything'
4
+ $CFLAGS << ' -Wno-disabled-macro-expansion -Wno-gnu -Wno-documentation'
5
+ # @todo REALLY NEED TO CLEAR ALL THESE WARNINGS
6
+ $CFLAGS << ' -Wno-conversion'
6
7
 
7
- if RUBY_ENGINE == 'macruby'
8
- $LIBS << ' -framework Cocoa'
9
- $CFLAGS << ' -ObjC -fobjc-gc'
10
- else
11
- unless RbConfig::CONFIG["CC"].match /clang/
12
- clang = `which clang`.chomp
13
- if clang.empty?
14
- $stdout.puts "Clang not installed. Cannot build C extension"
15
- raise "Clang not installed. Cannot build C extension"
16
- else
17
- RbConfig::MAKEFILE_CONFIG["CC"] = clang
18
- RbConfig::MAKEFILE_CONFIG["CXX"] = clang
19
- end
20
- end
21
- $CFLAGS << ' -DNOT_MACRUBY'
8
+ $LIBS << ' -framework Foundation'
9
+ $LIBS << ' -framework ApplicationServices'
10
+ $LIBS << ' -framework CoreGraphics'
11
+
12
+ unless RbConfig::CONFIG['CC'].match(/clang/)
13
+ clang = `which clang`.chomp
14
+ fail 'Clang not installed. Cannot build C extension' if clang.empty?
15
+ RbConfig::MAKEFILE_CONFIG['CC'] = clang
16
+ RbConfig::MAKEFILE_CONFIG['CXX'] = clang
22
17
  end
23
18
 
24
19
  create_makefile 'mouse/mouse'
data/ext/mouse/mouse.c CHANGED
@@ -1,6 +1,11 @@
1
1
  #include "mouser.h"
2
2
  #include "ruby.h"
3
3
 
4
+ #ifndef UNUSED
5
+ #define UNUSED __attribute__ ((unused))
6
+ #endif
7
+
8
+
4
9
  static VALUE rb_mMouse, rb_cCGPoint;
5
10
 
6
11
  static ID sel_x, sel_y, sel_to_point, sel_new;
@@ -15,32 +20,19 @@ static VALUE sym_pixel, sym_line,
15
20
 
16
21
  static
17
22
  VALUE
18
- rb_mouse_wrap_point(CGPoint point)
23
+ rb_mouse_wrap_point(const CGPoint point)
19
24
  {
20
- #if NOT_MACRUBY
21
- return rb_struct_new(rb_cCGPoint, DBL2NUM(point.x), DBL2NUM(point.y));
22
- #else
23
- return rb_funcall(rb_cCGPoint, sel_new, 2, DBL2NUM(point.x), DBL2NUM(point.y));
24
- #endif
25
+ return rb_struct_new(rb_cCGPoint, DBL2NUM(point.x), DBL2NUM(point.y));
25
26
  }
26
27
 
27
28
  static
28
29
  CGPoint
29
- rb_mouse_unwrap_point(VALUE point)
30
+ rb_mouse_unwrap_point(const VALUE maybe_point)
30
31
  {
31
- point = rb_funcall(point, sel_to_point, 0);
32
-
33
- #if NOT_MACRUBY
34
- double x = NUM2DBL(rb_struct_getmember(point, sel_x));
35
- double y = NUM2DBL(rb_struct_getmember(point, sel_y));
36
- return CGPointMake(x, y);
37
-
38
- #else
39
- CGPoint* ptr;
40
- Data_Get_Struct(point, CGPoint, ptr);
41
- return *ptr;
42
-
43
- #endif
32
+ const VALUE point = rb_funcall(maybe_point, sel_to_point, 0);
33
+ const double x = NUM2DBL(rb_struct_getmember(point, sel_x));
34
+ const double y = NUM2DBL(rb_struct_getmember(point, sel_y));
35
+ return CGPointMake(x, y);
44
36
  }
45
37
 
46
38
  /*
@@ -50,36 +42,42 @@ rb_mouse_unwrap_point(VALUE point)
50
42
  */
51
43
  static
52
44
  VALUE
53
- rb_mouse_current_position(VALUE self)
45
+ rb_mouse_current_position(UNUSED const VALUE self)
54
46
  {
55
- return CURRENT_POSITION;
47
+ return CURRENT_POSITION;
56
48
  }
57
49
 
58
50
  /*
59
51
  * Move the mouse cursor to the given co-ordinates
60
52
  *
61
- * @param point [CGPoint,Array(Number,Number),#to_point]
62
- * @param duration [Number] animation time, in seconds (__optional__)
63
- * @return [CGPoint]
53
+ * The default duration is 0.2 seconds.
54
+ *
55
+ * @overload move_to(point)
56
+ * @param point [CGPoint,Array(Number,Number),#to_point]
57
+ * @return [CGPoint]
58
+ * @overload move_to(point, duration)
59
+ * @param point [CGPoint,Array(Number,Number),#to_point]
60
+ * @param duration [Number] animation time, in seconds
61
+ * @return [CGPoint]
64
62
  */
65
63
  static
66
64
  VALUE
67
- rb_mouse_move_to(int argc, VALUE *argv, VALUE self)
65
+ rb_mouse_move_to(const int argc,
66
+ VALUE* const argv,
67
+ UNUSED const VALUE self)
68
68
  {
69
- switch (argc)
70
- {
69
+ switch (argc) {
71
70
  case 0:
72
- rb_raise(rb_eArgError, "move_to requires at least a one arg");
73
- break;
71
+ rb_raise(rb_eArgError, "move_to requires at least a one arg");
74
72
  case 1:
75
- mouse_move_to(rb_mouse_unwrap_point(argv[0]));
76
- break;
73
+ mouse_move_to(rb_mouse_unwrap_point(argv[0]));
74
+ break;
77
75
  case 2:
78
76
  default:
79
- mouse_move_to2(rb_mouse_unwrap_point(argv[0]), NUM2DBL(argv[1]));
77
+ mouse_move_to2(rb_mouse_unwrap_point(argv[0]), NUM2DBL(argv[1]));
80
78
  }
81
79
 
82
- return CURRENT_POSITION;
80
+ return CURRENT_POSITION;
83
81
  }
84
82
 
85
83
  /*
@@ -90,71 +88,83 @@ rb_mouse_move_to(int argc, VALUE *argv, VALUE self)
90
88
  */
91
89
  static
92
90
  VALUE
93
- rb_mouse_drag_to(int argc, VALUE *argv, VALUE self)
91
+ rb_mouse_drag_to(const int argc,
92
+ VALUE* const argv,
93
+ UNUSED const VALUE self)
94
94
  {
95
- switch (argc)
96
- {
95
+ switch (argc) {
97
96
  case 0:
98
- rb_raise(rb_eArgError, "drag_to requires at least a one arg");
99
- break;
97
+ rb_raise(rb_eArgError, "drag_to requires at least a one arg");
100
98
  case 1:
101
- mouse_drag_to(rb_mouse_unwrap_point(argv[0]));
102
- break;
99
+ mouse_drag_to(rb_mouse_unwrap_point(argv[0]));
100
+ break;
103
101
  case 2:
104
102
  default:
105
- mouse_drag_to2(rb_mouse_unwrap_point(argv[0]), NUM2DBL(argv[1]));
103
+ mouse_drag_to2(rb_mouse_unwrap_point(argv[0]), NUM2DBL(argv[1]));
106
104
  }
107
105
 
108
- return CURRENT_POSITION;
106
+ return CURRENT_POSITION;
109
107
  }
110
108
 
111
109
  /*
112
110
  * @note Scrolling by `:pixel` may not actually be by real pixels, but instead
113
- * correspond to Cocoa co-ords (I don't have a retina display, so I haven't
114
- * checked it out yet).
111
+ * correspond to Cocoa co-ords (I don't have a retina display, so I
112
+ * haven't checked it out yet).
115
113
  *
116
114
  * Generate `amount` scroll events at the current cursor position
117
115
  *
118
- * Returns number of lines scrolled. A positive `amount` will scroll up
119
- * and a negative `amount` will scroll down.
120
- *
121
- * An animation duration can also be specified.
122
- *
123
- * @param amount [Number]
124
- * @param units [Symbol] `:pixel` or `:line` (_default_: `:line` ) (__optional__)
125
- * @param duration [Float] (_default_: `0.2`) (__optional__)
126
- * @return [Number]
116
+ * Returns number of lines/pixels scrolled, default `units` are by `line`.
117
+ * A positive `amount` will scroll up and a negative `amount` will scroll down.
118
+ *
119
+ * An animation duration can also be specified, which defaults to 0.2 seconds.
120
+ *
121
+ * @overload scroll(amount)
122
+ * @param amount [Number]
123
+ * @return [Number]
124
+ * @overload scroll(amount, units)
125
+ * @param amount [Number]
126
+ * @param units [Symbol] `:pixel` or `:line`
127
+ * @return [Number]
128
+ * @overload scroll(amount, units, duration)
129
+ * @param amount [Number]
130
+ * @param units [Symbol] `:pixel` or `:line`
131
+ * @param duration [Number] animation time, in seconds
132
+ * @return [Number]
127
133
  */
128
134
  static
129
135
  VALUE
130
- rb_mouse_scroll(int argc, VALUE *argv, VALUE self)
136
+ rb_mouse_scroll(const int argc, VALUE* const argv, UNUSED const VALUE self)
131
137
  {
132
- if (argc == 0 || argc > 3)
133
- rb_raise(rb_eArgError, "scroll requires 1..3 arguments, you gave %d", argc);
134
-
135
- int amt = NUM2INT(argv[0]);
136
-
137
- if (argc == 1) {
138
- mouse_scroll(amt);
139
-
140
- } else {
141
- VALUE input_units = argv[1];
142
- CGScrollEventUnit units;
143
-
144
- if (input_units == sym_pixel)
145
- units = kCGScrollEventUnitPixel;
146
- else if (input_units == sym_line)
147
- units = kCGScrollEventUnitLine;
148
- else
149
- rb_raise(rb_eArgError, "unknown units `%s'", rb_id2name(input_units));
150
-
151
- if (argc == 2)
152
- mouse_scroll2(amt, units);
153
- else
154
- mouse_scroll3(amt, units, NUM2DBL(argv[2]));
155
- }
138
+ if (argc == 0 || argc > 3)
139
+ rb_raise(rb_eArgError,
140
+ "scroll requires 1..3 arguments, you gave %d",
141
+ argc);
142
+
143
+ const int amt = NUM2INT(argv[0]);
144
+
145
+ if (argc == 1) {
146
+ mouse_scroll(amt);
147
+
148
+ } else {
149
+ const VALUE input_units = argv[1];
150
+ CGScrollEventUnit units;
151
+
152
+ if (input_units == sym_pixel)
153
+ units = kCGScrollEventUnitPixel;
154
+ else if (input_units == sym_line)
155
+ units = kCGScrollEventUnitLine;
156
+ else
157
+ rb_raise(rb_eArgError,
158
+ "unknown units `%s'",
159
+ rb_id2name(input_units));
160
+
161
+ if (argc == 2)
162
+ mouse_scroll2(amt, units);
163
+ else
164
+ mouse_scroll3(amt, units, NUM2DBL(argv[2]));
165
+ }
156
166
 
157
- return argv[0];
167
+ return argv[0];
158
168
  }
159
169
 
160
170
  /*
@@ -164,46 +174,60 @@ rb_mouse_scroll(int argc, VALUE *argv, VALUE self)
164
174
  *
165
175
  * Generate `amount` of horizontal scroll events at the current cursor position
166
176
  *
167
- * Returns number of lines scrolled. A positive `amount` will scroll left
168
- * and a negative `amount` will scroll right.
169
- *
170
- * An animation duration can also be specified.
171
- *
172
- * @param amount [Number]
173
- * @param units [Symbol] `:pixel` or `:line` (_default_: `:line` ) (__optional__)
174
- * @param duration [Float] (_default_: `0.2`) (__optional__)
175
- * @return [Number]
177
+ * Returns number of lines/pixels scrolled, default `units` are by `line`.
178
+ * A positive `amount` will scroll up and a negative `amount` will scroll down.
179
+ *
180
+ * An animation duration can also be specified, which defaults to 0.2 seconds.
181
+ *
182
+ * @overload horizontal_scroll(amount)
183
+ * @param amount [Number]
184
+ * @return [Number]
185
+ * @overload horizontal_scroll(amount, units)
186
+ * @param amount [Number]
187
+ * @param units [Symbol] `:pixel` or `:line`
188
+ * @return [Number]
189
+ * @overload horizontal_scroll(amount, units, duration)
190
+ * @param amount [Number]
191
+ * @param units [Symbol] `:pixel` or `:line`
192
+ * @param duration [Number] animation time, in seconds
193
+ * @return [Number]
176
194
  */
177
195
  static
178
196
  VALUE
179
- rb_mouse_horizontal_scroll(int argc, VALUE *argv, VALUE self)
197
+ rb_mouse_horizontal_scroll(const int argc,
198
+ VALUE* const argv,
199
+ UNUSED const VALUE self)
180
200
  {
181
- if (argc == 0 || argc > 3)
182
- rb_raise(rb_eArgError, "scroll requires 1..3 arguments, you gave %d", argc);
183
-
184
- int amt = NUM2INT(argv[0]);
185
-
186
- if (argc == 1) {
187
- mouse_horizontal_scroll(amt);
188
-
189
- } else {
190
- VALUE input_units = argv[1];
191
- CGScrollEventUnit units;
192
-
193
- if (input_units == sym_pixel)
194
- units = kCGScrollEventUnitPixel;
195
- else if (input_units == sym_line)
196
- units = kCGScrollEventUnitLine;
197
- else
198
- rb_raise(rb_eArgError, "unknown units `%s'", rb_id2name(input_units));
199
-
200
- if (argc == 2)
201
- mouse_horizontal_scroll2(amt, units);
202
- else
203
- mouse_horizontal_scroll3(amt, units, NUM2DBL(argv[2]));
204
- }
201
+ if (argc == 0 || argc > 3)
202
+ rb_raise(rb_eArgError,
203
+ "scroll requires 1..3 arguments, you gave %d",
204
+ argc);
205
+
206
+ const int amt = NUM2INT(argv[0]);
207
+
208
+ if (argc == 1) {
209
+ mouse_horizontal_scroll(amt);
210
+
211
+ } else {
212
+ const VALUE input_units = argv[1];
213
+ CGScrollEventUnit units;
214
+
215
+ if (input_units == sym_pixel)
216
+ units = kCGScrollEventUnitPixel;
217
+ else if (input_units == sym_line)
218
+ units = kCGScrollEventUnitLine;
219
+ else
220
+ rb_raise(rb_eArgError,
221
+ "unknown units `%s'",
222
+ rb_id2name(input_units));
223
+
224
+ if (argc == 2)
225
+ mouse_horizontal_scroll2(amt, units);
226
+ else
227
+ mouse_horizontal_scroll3(amt, units, NUM2DBL(argv[2]));
228
+ }
205
229
 
206
- return argv[0];
230
+ return argv[0];
207
231
  }
208
232
 
209
233
  /*
@@ -213,26 +237,31 @@ rb_mouse_horizontal_scroll(int argc, VALUE *argv, VALUE self)
213
237
  * to inject some behaviour between the down and up click events.
214
238
  *
215
239
  * You can optionally specify a point to click; the mouse cursor will
216
- * instantly jump to the given point.
217
- *
218
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
219
- * @return [CGPoint]
240
+ * instantly jump to the given point; otherwise the click event happens
241
+ * at the current cursor position.
242
+ *
243
+ * @overload click_down()
244
+ * @return [CGPoint]
245
+ * @overload click_down(point)
246
+ * @param point [CGPoint]
247
+ * @return [CGPoint]
220
248
  */
221
249
  static
222
250
  VALUE
223
- rb_mouse_click_down(int argc, VALUE *argv, VALUE self)
251
+ rb_mouse_click_down(const int argc,
252
+ VALUE* const argv,
253
+ UNUSED const VALUE self)
224
254
  {
225
- switch (argc)
226
- {
255
+ switch (argc) {
227
256
  case 0:
228
- mouse_click_down();
229
- break;
257
+ mouse_click_down();
258
+ break;
230
259
  case 1:
231
260
  default:
232
- mouse_click_down2(rb_mouse_unwrap_point(argv[0]));
261
+ mouse_click_down2(rb_mouse_unwrap_point(argv[0]));
233
262
  }
234
263
 
235
- return CURRENT_POSITION;
264
+ return CURRENT_POSITION;
236
265
  }
237
266
 
238
267
  /*
@@ -242,52 +271,58 @@ rb_mouse_click_down(int argc, VALUE *argv, VALUE self)
242
271
  * to inject some behaviour between the down and up click events.
243
272
  *
244
273
  * You can optionally specify a point to click; the mouse cursor will
245
- * instantly jump to the given point.
246
- *
247
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
248
- * @return [CGPoint]
274
+ * instantly jump to the given point; otherwise the click event happens
275
+ * at the current cursor position.
276
+ *
277
+ * @overload click_up()
278
+ * @return [CGPoint]
279
+ * @overload click_up(point)
280
+ * @param point [CGPoint]
281
+ * @return [CGPoint]
249
282
  */
250
283
  static
251
284
  VALUE
252
- rb_mouse_click_up(int argc, VALUE *argv, VALUE self)
285
+ rb_mouse_click_up(const int argc, VALUE* const argv, UNUSED const VALUE self)
253
286
  {
254
- switch (argc)
255
- {
287
+ switch (argc) {
256
288
  case 0:
257
- mouse_click_up();
258
- break;
289
+ mouse_click_up();
290
+ break;
259
291
  case 1:
260
292
  default:
261
- mouse_click_up(rb_mouse_unwrap_point(argv[0]));
293
+ mouse_click_up2(rb_mouse_unwrap_point(argv[0]));
262
294
  }
263
295
 
264
- return CURRENT_POSITION;
296
+ return CURRENT_POSITION;
265
297
  }
266
298
 
267
299
  /*
268
300
  * Generate a regular click event (both up and down events)
269
301
  *
270
302
  * You can optionally specify a point to click; the mouse cursor will
271
- * instantly jump to the given point.
272
- *
273
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
274
- * @return [CGPoint]
303
+ * instantly jump to the given point; otherwise the click event happens
304
+ * at the current cursor position.
305
+ *
306
+ * @overload click()
307
+ * @return [CGPoint]
308
+ * @overload click()
309
+ * @param point [CGPoint]
310
+ * @return [CGPoint]
275
311
  */
276
312
  static
277
313
  VALUE
278
- rb_mouse_click(int argc, VALUE *argv, VALUE self)
314
+ rb_mouse_click(const int argc, VALUE* const argv, UNUSED const VALUE self)
279
315
  {
280
- switch (argc)
281
- {
316
+ switch (argc) {
282
317
  case 0:
283
- mouse_click();
284
- break;
318
+ mouse_click();
319
+ break;
285
320
  case 1:
286
321
  default:
287
- mouse_click2(rb_mouse_unwrap_point(argv[0]));
322
+ mouse_click2(rb_mouse_unwrap_point(argv[0]));
288
323
  }
289
324
 
290
- return CURRENT_POSITION;
325
+ return CURRENT_POSITION;
291
326
  }
292
327
 
293
328
  /*
@@ -298,26 +333,31 @@ rb_mouse_click(int argc, VALUE *argv, VALUE self)
298
333
  * events.
299
334
  *
300
335
  * You can optionally specify a point to click; the mouse cursor will
301
- * instantly jump to the given point.
302
- *
303
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
304
- * @return [CGPoint]
336
+ * instantly jump to the given point; otherwise the click event happens
337
+ * at the current cursor position.
338
+ *
339
+ * @overload secondary_click_down()
340
+ * @return [CGPoint]
341
+ * @overload secondary_click_down(point)
342
+ * @param point [CGPoint]
343
+ * @return [CGPoint]
305
344
  */
306
345
  static
307
346
  VALUE
308
- rb_mouse_secondary_click_down(int argc, VALUE* argv, VALUE self)
347
+ rb_mouse_secondary_click_down(const int argc,
348
+ VALUE* const argv,
349
+ UNUSED const VALUE self)
309
350
  {
310
- switch (argc)
311
- {
351
+ switch (argc) {
312
352
  case 0:
313
- mouse_secondary_click_down();
314
- break;
353
+ mouse_secondary_click_down();
354
+ break;
315
355
  case 1:
316
356
  default:
317
- mouse_secondary_click_down2(rb_mouse_unwrap_point(argv[0]));
357
+ mouse_secondary_click_down2(rb_mouse_unwrap_point(argv[0]));
318
358
  }
319
359
 
320
- return CURRENT_POSITION;
360
+ return CURRENT_POSITION;
321
361
  }
322
362
 
323
363
  /*
@@ -327,26 +367,31 @@ rb_mouse_secondary_click_down(int argc, VALUE* argv, VALUE self)
327
367
  * you want to inject some behaviour between the down and up click events.
328
368
  *
329
369
  * You can optionally specify a point to click; the mouse cursor will
330
- * instantly jump to the given point.
331
- *
332
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
333
- * @return [CGPoint]
370
+ * instantly jump to the given point; otherwise the click event happens
371
+ * at the current cursor position.
372
+ *
373
+ * @overload secondary_click_up()
374
+ * @return [CGPoint]
375
+ * @overload secondary_click_up(point)
376
+ * @param point [CGPoint]
377
+ * @return [CGPoint]
334
378
  */
335
379
  static
336
380
  VALUE
337
- rb_mouse_secondary_click_up(int argc, VALUE* argv, VALUE self)
381
+ rb_mouse_secondary_click_up(const int argc,
382
+ VALUE* const argv,
383
+ UNUSED const VALUE self)
338
384
  {
339
- switch (argc)
340
- {
385
+ switch (argc) {
341
386
  case 0:
342
- mouse_secondary_click_up();
343
- break;
387
+ mouse_secondary_click_up();
388
+ break;
344
389
  case 1:
345
390
  default:
346
- mouse_secondary_click_up2(rb_mouse_unwrap_point(argv[0]));
391
+ mouse_secondary_click_up2(rb_mouse_unwrap_point(argv[0]));
347
392
  }
348
393
 
349
- return CURRENT_POSITION;
394
+ return CURRENT_POSITION;
350
395
  }
351
396
 
352
397
  /*
@@ -355,26 +400,31 @@ rb_mouse_secondary_click_up(int argc, VALUE* argv, VALUE self)
355
400
  * Secondary click is often referred to as "right click".
356
401
  *
357
402
  * You can optionally specify a point to click; the mouse cursor will
358
- * instantly jump to the given point.
359
- *
360
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
361
- * @return [CGPoint]
403
+ * instantly jump to the given point; otherwise the click event happens
404
+ * at the current cursor position.
405
+ *
406
+ * @overload secondary_click()
407
+ * @return [CGPoint]
408
+ * @overload secondary_click(point)
409
+ * @param point [CGPoint]
410
+ * @return [CGPoint]
362
411
  */
363
412
  static
364
413
  VALUE
365
- rb_mouse_secondary_click(int argc, VALUE *argv, VALUE self)
414
+ rb_mouse_secondary_click(const int argc,
415
+ VALUE* const argv,
416
+ UNUSED const VALUE self)
366
417
  {
367
- switch (argc)
368
- {
418
+ switch (argc) {
369
419
  case 0:
370
- mouse_secondary_click();
371
- break;
420
+ mouse_secondary_click();
421
+ break;
372
422
  case 1:
373
423
  default:
374
- mouse_secondary_click2(rb_mouse_unwrap_point(argv[0]));
424
+ mouse_secondary_click2(rb_mouse_unwrap_point(argv[0]));
375
425
  }
376
426
 
377
- return CURRENT_POSITION;
427
+ return CURRENT_POSITION;
378
428
  }
379
429
 
380
430
  /*
@@ -385,31 +435,37 @@ rb_mouse_secondary_click(int argc, VALUE *argv, VALUE self)
385
435
  * events.
386
436
  *
387
437
  * You can optionally specify a point to click; the mouse cursor will
388
- * instantly jump to the given point.
389
- *
390
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
391
- * @return [CGPoint]
438
+ * instantly jump to the given point; otherwise the click event happens
439
+ * at the current cursor position.
440
+ *
441
+ * @overload arbitrary_click_down()
442
+ * @return [CGPoint]
443
+ * @overload arbitrary_click_down(point)
444
+ * @param point [CGPoint]
445
+ * @return [CGPoint]
392
446
  */
393
447
  static
394
448
  VALUE
395
- rb_mouse_arbitrary_click_down(int argc, VALUE* argv, VALUE self)
449
+ rb_mouse_arbitrary_click_down(const int argc,
450
+ VALUE* const argv,
451
+ UNUSED const VALUE self)
396
452
  {
397
- if (argc == 0)
398
- rb_raise(rb_eArgError, "arbitrary_click_down requires at least one arg");
453
+ if (argc == 0)
454
+ rb_raise(rb_eArgError,
455
+ "arbitrary_click_down requires at least one arg");
399
456
 
400
- uint_t button = NUM2INT(argv[0]);
457
+ const uint_t button = NUM2UINT(argv[0]);
401
458
 
402
- switch (argc)
403
- {
459
+ switch (argc) {
404
460
  case 1:
405
- mouse_arbitrary_click_down(button);
406
- break;
461
+ mouse_arbitrary_click_down(button);
462
+ break;
407
463
  case 2:
408
464
  default:
409
- mouse_arbitrary_click_down2(button, rb_mouse_unwrap_point(argv[1]));
465
+ mouse_arbitrary_click_down2(button, rb_mouse_unwrap_point(argv[1]));
410
466
  }
411
467
 
412
- return CURRENT_POSITION;
468
+ return CURRENT_POSITION;
413
469
  }
414
470
 
415
471
  /*
@@ -419,31 +475,37 @@ rb_mouse_arbitrary_click_down(int argc, VALUE* argv, VALUE self)
419
475
  * you want to inject some behaviour between the down and up click events.
420
476
  *
421
477
  * You can optionally specify a point to click; the mouse cursor will
422
- * instantly jump to the given point.
423
- *
424
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
425
- * @return [CGPoint]
478
+ * instantly jump to the given point; otherwise the click event happens
479
+ * at the current cursor position.
480
+ *
481
+ * @overload arbitrary_click_up()
482
+ * @return [CGPoint]
483
+ * @overload arbitrary_click_up(point)
484
+ * @param point [CGPoint]
485
+ * @return [CGPoint]
426
486
  */
427
487
  static
428
488
  VALUE
429
- rb_mouse_arbitrary_click_up(int argc, VALUE* argv, VALUE self)
489
+ rb_mouse_arbitrary_click_up(const int argc,
490
+ VALUE* const argv,
491
+ UNUSED const VALUE self)
430
492
  {
431
- if (argc == 0)
432
- rb_raise(rb_eArgError, "arbitrary_click_up requires at least one arg");
493
+ if (argc == 0)
494
+ rb_raise(rb_eArgError,
495
+ "arbitrary_click_up requires at least one arg");
433
496
 
434
- uint_t button = NUM2INT(argv[0]);
497
+ const uint_t button = NUM2UINT(argv[0]);
435
498
 
436
- switch (argc)
437
- {
499
+ switch (argc) {
438
500
  case 1:
439
- mouse_arbitrary_click_up(button);
440
- break;
501
+ mouse_arbitrary_click_up(button);
502
+ break;
441
503
  case 2:
442
504
  default:
443
- mouse_arbitrary_click_up2(button, rb_mouse_unwrap_point(argv[1]));
505
+ mouse_arbitrary_click_up2(button, rb_mouse_unwrap_point(argv[1]));
444
506
  }
445
507
 
446
- return CURRENT_POSITION;
508
+ return CURRENT_POSITION;
447
509
  }
448
510
 
449
511
  /*
@@ -461,34 +523,40 @@ rb_mouse_arbitrary_click_up(int argc, VALUE* argv, VALUE self)
461
523
  * documentation for the most up to date list.
462
524
  *
463
525
  * You can optionally specify a point to click; the mouse cursor will
464
- * instantly jump to the given point.
465
- *
466
- * @param button [Number,#to_i]
467
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
468
- * @return [CGPoint]
526
+ * instantly jump to the given point; otherwise the click event happens
527
+ * at the current cursor position.
528
+ *
529
+ * @overload arbitrary_click(button)
530
+ * @param button [Number,#to_i]
531
+ * @return [CGPoint]
532
+ * @overload arbitrary_click(button, point)
533
+ * @param button [Number,#to_i]
534
+ * @param point [CGPoint]
535
+ * @return [CGPoint]
469
536
  */
470
537
  static
471
538
  VALUE
472
- rb_mouse_arbitrary_click(int argc, VALUE *argv, VALUE self)
539
+ rb_mouse_arbitrary_click(const int argc,
540
+ VALUE* const argv,
541
+ UNUSED const VALUE self)
473
542
  {
474
- if (argc == 0) {
475
- rb_raise(rb_eArgError, "arbitrary_click requires at least one arg");
476
- return Qnil;
477
- }
543
+ if (argc == 0) {
544
+ rb_raise(rb_eArgError, "arbitrary_click requires at least one arg");
545
+ return Qnil;
546
+ }
478
547
 
479
- uint_t button = NUM2INT(argv[0]);
548
+ const uint_t button = NUM2UINT(argv[0]);
480
549
 
481
- switch (argc)
482
- {
550
+ switch (argc) {
483
551
  case 1:
484
- mouse_arbitrary_click(button);
485
- break;
552
+ mouse_arbitrary_click(button);
553
+ break;
486
554
  case 2:
487
555
  default:
488
- mouse_arbitrary_click2(button, rb_mouse_unwrap_point(argv[1]));
556
+ mouse_arbitrary_click2(button, rb_mouse_unwrap_point(argv[1]));
489
557
  }
490
558
 
491
- return CURRENT_POSITION;
559
+ return CURRENT_POSITION;
492
560
  }
493
561
 
494
562
  /*
@@ -497,26 +565,31 @@ rb_mouse_arbitrary_click(int argc, VALUE *argv, VALUE self)
497
565
  * It doesn't matter if you don't have a middle mouse button.
498
566
  *
499
567
  * You can optionally specify a point to click; the mouse cursor will
500
- * instantly jump to the given point.
501
- *
502
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
503
- * @return [CGPoint]
568
+ * instantly jump to the given point; otherwise the click event happens
569
+ * at the current cursor position.
570
+ *
571
+ * @overload middle_click()
572
+ * @return [CGPoint]
573
+ * @overload middle_click(point)
574
+ * @param point [CGPoint]
575
+ * @return [CGPoint]
504
576
  */
505
577
  static
506
578
  VALUE
507
- rb_mouse_middle_click(int argc, VALUE *argv, VALUE self)
579
+ rb_mouse_middle_click(const int argc,
580
+ VALUE* const argv,
581
+ UNUSED const VALUE self)
508
582
  {
509
- switch (argc)
510
- {
583
+ switch (argc) {
511
584
  case 0:
512
- mouse_middle_click();
513
- break;
585
+ mouse_middle_click();
586
+ break;
514
587
  case 1:
515
588
  default:
516
- mouse_middle_click(rb_mouse_unwrap_point(argv[0]));
589
+ mouse_middle_click2(rb_mouse_unwrap_point(argv[0]));
517
590
  }
518
591
 
519
- return CURRENT_POSITION;
592
+ return CURRENT_POSITION;
520
593
  }
521
594
 
522
595
  /*
@@ -526,36 +599,42 @@ rb_mouse_middle_click(int argc, VALUE *argv, VALUE self)
526
599
  * a single event with the given number of clicks.
527
600
  *
528
601
  * You can optionally specify a point to click; the mouse cursor will
529
- * instantly jump to the given point.
530
- *
531
- * @param num_clicks [Number,#to_i]
532
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
533
- * @return [CGPoint]
602
+ * instantly jump to the given point; otherwise the click event happens
603
+ * at the current cursor position.
604
+ *
605
+ * @overload multi_click(num_clicks)
606
+ * @param num_clicks [Number,#to_i]
607
+ * @return [CGPoint]
608
+ * @overload multi_click(num_clicks, point)
609
+ * @param num_clicks [Number,#to_i]
610
+ * @param point [CGPoint]
611
+ * @return [CGPoint]
534
612
  */
535
613
  static
536
614
  VALUE
537
- rb_mouse_multi_click(int argc, VALUE *argv, VALUE self)
615
+ rb_mouse_multi_click(const int argc,
616
+ VALUE* const argv,
617
+ UNUSED const VALUE self)
538
618
  {
539
619
 
540
- if (argc == 0) {
541
- rb_raise(rb_eArgError, "multi_click requires at least one arg");
542
- return Qnil;
543
- }
620
+ if (argc == 0) {
621
+ rb_raise(rb_eArgError, "multi_click requires at least one arg");
622
+ return Qnil;
623
+ }
544
624
 
545
- // TODO: there has got to be a more idiomatic way to do this coercion
546
- size_t num_clicks = NUM2SIZET(argv[0]);
625
+ // TODO: there has got to be a more idiomatic way to do this coercion
626
+ const size_t num_clicks = NUM2SIZET(argv[0]);
547
627
 
548
- switch (argc)
549
- {
628
+ switch (argc) {
550
629
  case 1:
551
- mouse_multi_click(num_clicks);
552
- break;
630
+ mouse_multi_click(num_clicks);
631
+ break;
553
632
  case 2:
554
633
  default:
555
- mouse_multi_click2(num_clicks, rb_mouse_unwrap_point(argv[1]));
634
+ mouse_multi_click2(num_clicks, rb_mouse_unwrap_point(argv[1]));
556
635
  }
557
636
 
558
- return CURRENT_POSITION;
637
+ return CURRENT_POSITION;
559
638
  }
560
639
 
561
640
  /*
@@ -566,26 +645,31 @@ rb_mouse_multi_click(int argc, VALUE *argv, VALUE self)
566
645
  * how a human would have to generate a double click event.
567
646
  *
568
647
  * You can optionally specify a point to click; the mouse cursor will
569
- * instantly jump to the given point.
570
- *
571
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
572
- * @return [CGPoint]
648
+ * instantly jump to the given point; otherwise the click event happens
649
+ * at the current cursor position.
650
+ *
651
+ * @overload double_click()
652
+ * @return [CGPoint]
653
+ * @overload double_click(point)
654
+ * @param point [CGPoint]
655
+ * @return [CGPoint]
573
656
  */
574
657
  static
575
658
  VALUE
576
- rb_mouse_double_click(int argc, VALUE *argv, VALUE self)
659
+ rb_mouse_double_click(const int argc,
660
+ VALUE* const argv,
661
+ UNUSED const VALUE self)
577
662
  {
578
- switch (argc)
579
- {
663
+ switch (argc) {
580
664
  case 0:
581
- mouse_double_click();
582
- break;
665
+ mouse_double_click();
666
+ break;
583
667
  case 1:
584
668
  default:
585
- mouse_double_click2(rb_mouse_unwrap_point(argv[0]));
669
+ mouse_double_click2(rb_mouse_unwrap_point(argv[0]));
586
670
  }
587
671
 
588
- return CURRENT_POSITION;
672
+ return CURRENT_POSITION;
589
673
  }
590
674
 
591
675
  /*
@@ -597,26 +681,31 @@ rb_mouse_double_click(int argc, VALUE *argv, VALUE self)
597
681
  * triple click event.
598
682
  *
599
683
  * You can optionally specify a point to click; the mouse cursor will
600
- * instantly jump to the given point.
601
- *
602
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
603
- * @return [CGPoint]
684
+ * instantly jump to the given point; otherwise the click event happens
685
+ * at the current cursor position.
686
+ *
687
+ * @overload triple_click()
688
+ * @return [CGPoint]
689
+ * @overload triple_click(point)
690
+ * @param point [CGPoint]
691
+ * @return [CGPoint]
604
692
  */
605
693
  static
606
694
  VALUE
607
- rb_mouse_triple_click(int argc, VALUE *argv, VALUE self)
695
+ rb_mouse_triple_click(const int argc,
696
+ VALUE* const argv,
697
+ UNUSED const VALUE self)
608
698
  {
609
- switch (argc)
610
- {
699
+ switch (argc) {
611
700
  case 0:
612
- mouse_triple_click();
613
- break;
701
+ mouse_triple_click();
702
+ break;
614
703
  case 1:
615
704
  default:
616
- mouse_triple_click2(rb_mouse_unwrap_point(argv[0]));
705
+ mouse_triple_click2(rb_mouse_unwrap_point(argv[0]));
617
706
  }
618
707
 
619
- return CURRENT_POSITION;
708
+ return CURRENT_POSITION;
620
709
  }
621
710
 
622
711
 
@@ -625,27 +714,32 @@ rb_mouse_triple_click(int argc, VALUE *argv, VALUE self)
625
714
  /*
626
715
  * Perform a smart magnify (double tap on trackpad)
627
716
  *
628
- * You can optionally specify the point on the screen where to perform
629
- * the smart magnification.
630
- *
631
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
632
- * @return [CGPoint]
717
+ * You can optionally specify a point to click; the mouse cursor will
718
+ * instantly jump to the given point; otherwise the click event happens
719
+ * at the current cursor position.
720
+ *
721
+ * @overload smart_magnify()
722
+ * @return [CGPoint]
723
+ * @overload smart_magnify(point)
724
+ * @param point [CGPoint]
725
+ * @return [CGPoint]
633
726
  */
634
727
  static
635
728
  VALUE
636
- rb_mouse_smart_magnify(int argc, VALUE* argv, VALUE self)
729
+ rb_mouse_smart_magnify(const int argc,
730
+ VALUE* const argv,
731
+ UNUSED const VALUE self)
637
732
  {
638
- switch (argc)
639
- {
733
+ switch (argc) {
640
734
  case 0:
641
- mouse_smart_magnify();
642
- break;
735
+ mouse_smart_magnify();
736
+ break;
643
737
  case 1:
644
738
  default:
645
- mouse_smart_magnify2(rb_mouse_unwrap_point(argv[0]));
739
+ mouse_smart_magnify2(rb_mouse_unwrap_point(argv[0]));
646
740
  }
647
741
 
648
- return CURRENT_POSITION;
742
+ return CURRENT_POSITION;
649
743
  }
650
744
 
651
745
  /*
@@ -653,52 +747,55 @@ rb_mouse_smart_magnify(int argc, VALUE* argv, VALUE self)
653
747
  *
654
748
  * You can optionally specify a point on screen for the mouse
655
749
  * pointer to be moved to before the gesture begins. The movement will
656
- * be instantaneous.
657
- *
658
- * You can also optionally specify the duration of the swipe event.
659
- *
660
- * @param direction [Symbol]
661
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
662
- * @param duration [Float] (_default_: `0.2`) (__optional__)
663
- * @return [CGPoint]
750
+ * be instantaneous; otherwise the click event happens
751
+ * at the current cursor position.
752
+ *
753
+ * You can also optionally specify the duration of the swipe event;
754
+ * the default `duration` is 0.2 seconds.
755
+ *
756
+ * @overload swipe(direction)
757
+ * @param direction [Symbol]
758
+ * @return [CGPoint]
759
+ * @overload swipe(direction, point)
760
+ * @param direction [Symbol]
761
+ * @param point [CGPoint]
762
+ * @return [CGPoint]
763
+ * @overload swipe(direction, point, duration)
764
+ * @param direction [Symbol]
765
+ * @param point [CGPoint]
766
+ * @param duration [Float]
767
+ * @return [CGPoint]
664
768
  */
665
769
  static
666
770
  VALUE
667
- rb_mouse_swipe(int argc, VALUE* argv, VALUE self)
771
+ rb_mouse_swipe(const int argc, VALUE* const argv, UNUSED const VALUE self)
668
772
  {
669
- if (!argc)
670
- rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");
671
-
672
- CGSwipeDirection direction;
673
- VALUE direction_input = argv[0];
674
- if (direction_input == sym_up)
675
- direction = kCGSwipeDirectionUp;
676
- else if (direction_input == sym_down)
677
- direction = kCGSwipeDirectionDown;
678
- else if (direction_input == sym_left)
679
- direction = kCGSwipeDirectionLeft;
680
- else if (direction_input == sym_right)
681
- direction = kCGSwipeDirectionRight;
682
- else
683
- rb_raise(
684
- rb_eArgError,
685
- "invalid swipe direction `%s'",
686
- rb_id2name(SYM2ID(direction_input))
687
- );
688
-
689
- if (argc == 1) {
690
- mouse_swipe(direction);
691
- return CURRENT_POSITION;
692
- }
773
+ if (!argc)
774
+ rb_raise(rb_eArgError, "wrong number of arguments (0 for 1+)");
775
+
776
+ const VALUE direction_input = argv[0];
777
+ CGSwipeDirection direction;
778
+ if (direction_input == sym_up)
779
+ direction = kCGSwipeDirectionUp;
780
+ else if (direction_input == sym_down)
781
+ direction = kCGSwipeDirectionDown;
782
+ else if (direction_input == sym_left)
783
+ direction = kCGSwipeDirectionLeft;
784
+ else if (direction_input == sym_right)
785
+ direction = kCGSwipeDirectionRight;
786
+ else
787
+ rb_raise(rb_eArgError,
788
+ "invalid swipe direction `%s'",
789
+ rb_id2name(SYM2ID(direction_input)));
693
790
 
694
- CGPoint point = rb_mouse_unwrap_point(argv[1]);
791
+ if (argc == 1) {
792
+ mouse_swipe(direction);
793
+ return CURRENT_POSITION;
794
+ }
695
795
 
696
- if (argc == 2)
796
+ const CGPoint point = rb_mouse_unwrap_point(argv[1]);
697
797
  mouse_swipe2(direction, point);
698
- else
699
- mouse_swipe3(direction, point, NUM2DBL(argv[1]));
700
-
701
- return CURRENT_POSITION;
798
+ return CURRENT_POSITION;
702
799
  }
703
800
 
704
801
  /*
@@ -714,61 +811,72 @@ rb_mouse_swipe(int argc, VALUE* argv, VALUE self)
714
811
  *
715
812
  * Magnification is a relative magnification setting. A zoom value of
716
813
  * `1.0` means `1.0` more than the current zoom level. `2.0` would be
717
- * `2.0` levels higher than the current zoom.
814
+ * `2.0` levels higher than the current zoom. Default is `1.0`.
718
815
  *
719
816
  * You can also optionally specify a point on screen for the mouse
720
817
  * pointer to be moved to before the gesture begins. The movement will
721
- * be instantaneous.
722
- *
723
- * An animation duration can also be specified.
724
- *
725
- * @param direction [Symbol]
726
- * @param magnification [Float] (_default_: `1.0`) (__optional__)
727
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
728
- * @param duration [Float] (_default_: `0.2`) (__optional__)
729
- * @return [CGPoint]
818
+ * be instantaneous. Default `point` is {#current_position}.
819
+ *
820
+ * An animation duration can also be specified. The default is 0.2 seconds.
821
+ *
822
+ * @overload pinch(direction)
823
+ * @param direction [Symbol]
824
+ * @return [CGPoint]
825
+ * @overload pinch(direction, magnification)
826
+ * @param direction [Symbol]
827
+ * @param magnification [Float]
828
+ * @return [CGPoint]
829
+ * @overload pinch(direction, magnification, point)
830
+ * @param direction [Symbol]
831
+ * @param magnification [Float]
832
+ * @param point [CGPoint]
833
+ * @return [CGPoint]
834
+ * @overload pinch(direction, magnification, point, duration)
835
+ * @param direction [Symbol]
836
+ * @param magnification [Float]
837
+ * @param point [CGPoint]
838
+ * @param duration [Float]
839
+ * @return [CGPoint]
730
840
  */
731
841
  static
732
842
  VALUE
733
- rb_mouse_pinch(int argc, VALUE* argv, VALUE self)
843
+ rb_mouse_pinch(const int argc, VALUE* const argv, UNUSED const VALUE self)
734
844
  {
735
- if (!argc)
736
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1+)", argc);
737
-
738
- VALUE input_direction = argv[0];
739
- CGPinchDirection direction = kCGPinchNone;
740
-
741
- if (input_direction == sym_expand || input_direction == sym_zoom)
742
- direction = kCGPinchExpand;
743
- else if (input_direction == sym_contract || input_direction == sym_unzoom)
744
- direction = kCGPinchContract;
745
- else
746
- rb_raise(
747
- rb_eArgError,
748
- "invalid pinch direction `%s'",
749
- rb_id2name(SYM2ID(input_direction))
750
- );
751
-
752
- if (argc == 1) {
753
- mouse_pinch(direction);
754
- return CURRENT_POSITION;
755
- }
845
+ if (!argc)
846
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1+)", argc);
756
847
 
757
- double magnification = NUM2DBL(argv[1]);
758
- if (argc == 2) {
759
- mouse_pinch2(direction, magnification);
760
- return CURRENT_POSITION;
761
- }
848
+ const VALUE input_direction = argv[0];
849
+ CGPinchDirection direction = kCGPinchNone;
762
850
 
763
- CGPoint point = rb_mouse_unwrap_point(argv[2]);
764
- if (argc == 3) {
765
- mouse_pinch3(direction, magnification, point);
766
- return CURRENT_POSITION;
767
- }
851
+ if (input_direction == sym_expand || input_direction == sym_zoom)
852
+ direction = kCGPinchExpand;
853
+ else if (input_direction == sym_contract || input_direction == sym_unzoom)
854
+ direction = kCGPinchContract;
855
+ else
856
+ rb_raise(rb_eArgError,
857
+ "invalid pinch direction `%s'",
858
+ rb_id2name(SYM2ID(input_direction)));
859
+
860
+ if (argc == 1) {
861
+ mouse_pinch(direction);
862
+ return CURRENT_POSITION;
863
+ }
768
864
 
769
- double duration = NUM2DBL(argv[3]);
770
- mouse_pinch4(direction, magnification, point, duration);
771
- return CURRENT_POSITION;
865
+ const double magnification = NUM2DBL(argv[1]);
866
+ if (argc == 2) {
867
+ mouse_pinch2(direction, magnification);
868
+ return CURRENT_POSITION;
869
+ }
870
+
871
+ const CGPoint point = rb_mouse_unwrap_point(argv[2]);
872
+ if (argc == 3) {
873
+ mouse_pinch3(direction, magnification, point);
874
+ return CURRENT_POSITION;
875
+ }
876
+
877
+ const double duration = NUM2DBL(argv[3]);
878
+ mouse_pinch4(direction, magnification, point, duration);
879
+ return CURRENT_POSITION;
772
880
  }
773
881
 
774
882
  /*
@@ -786,142 +894,150 @@ rb_mouse_pinch(int argc, VALUE* argv, VALUE self)
786
894
  *
787
895
  * You can also optionally specify a point on screen for the mouse
788
896
  * pointer to be moved to before the gesture begins. The movement will
789
- * be instantaneous.
790
- *
791
- * An animation duration can also be specified.
792
- *
793
- * @param direction [Symbol]
794
- * @param angle [Float]
795
- * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
796
- * @param duration [Float] (_default_: `0.2`) (__optional__)
797
- * @return [CGPoint]
897
+ * be instantaneous. Default `point` is {#current_position}.
898
+ *
899
+ * An animation duration can also be specified. The default is 0.2 seconds.
900
+ *
901
+ * @overload rotate(direction, angle)
902
+ * @param direction [Symbol]
903
+ * @param angle [Float]
904
+ * @return [CGPoint]
905
+ * @overload rotate(direction, angle, point)
906
+ * @param direction [Symbol]
907
+ * @param angle [Float]
908
+ * @param point [CGPoint]
909
+ * @return [CGPoint]
910
+ * @overload rotate(direction, angle, point, duration)
911
+ * @param direction [Symbol]
912
+ * @param angle [Float]
913
+ * @param point [CGPoint]
914
+ * @param duration [Float]
915
+ * @return [CGPoint]
798
916
  */
799
917
  static
800
918
  VALUE
801
- rb_mouse_rotate(int argc, VALUE* argv, VALUE self)
919
+ rb_mouse_rotate(const int argc, VALUE* const argv, UNUSED const VALUE self)
802
920
  {
803
- if (argc < 2)
804
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);
805
-
806
- CGRotateDirection direction = kCGRotateNone;
807
- VALUE input_dir = argv[0];
808
- if (
809
- input_dir == sym_cw ||
810
- input_dir == sym_clockwise ||
811
- input_dir == sym_clock_wise
812
- )
813
- direction = kCGRotateClockwise;
814
- else if (
815
- input_dir == sym_ccw ||
816
- input_dir == sym_counter_clockwise ||
817
- input_dir == sym_counter_clock_wise
818
- )
819
- direction = kCGRotateCounterClockwise;
820
- else
821
- rb_raise(
822
- rb_eArgError,
823
- "invalid rotation direction `%s'",
824
- rb_id2name(SYM2ID(input_dir))
825
- );
826
-
827
- double angle = NUM2DBL(argv[1]);
828
-
829
- if (argc == 2) {
830
- mouse_rotate(direction, angle);
831
- return CURRENT_POSITION;
832
- }
921
+ if (argc < 2)
922
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc);
833
923
 
834
- CGPoint point = rb_mouse_unwrap_point(argv[2]);
835
- if (argc == 3) {
836
- mouse_rotate2(direction, angle, point);
837
- return CURRENT_POSITION;
838
- }
839
924
 
840
- mouse_rotate3(direction, angle, point, NUM2DBL(argv[3]));
841
- return CURRENT_POSITION;
925
+ const VALUE input_dir = argv[0];
926
+ CGRotateDirection direction;
927
+
928
+ if (input_dir == sym_cw ||
929
+ input_dir == sym_clockwise ||
930
+ input_dir == sym_clock_wise)
931
+ direction = kCGRotateClockwise;
932
+
933
+ else if (input_dir == sym_ccw ||
934
+ input_dir == sym_counter_clockwise ||
935
+ input_dir == sym_counter_clock_wise)
936
+ direction = kCGRotateCounterClockwise;
937
+ else
938
+ rb_raise(rb_eArgError,
939
+ "invalid rotation direction `%s'",
940
+ rb_id2name(SYM2ID(input_dir)));
941
+
942
+ const double angle = NUM2DBL(argv[1]);
943
+
944
+ if (argc == 2) {
945
+ mouse_rotate(direction, angle);
946
+ return CURRENT_POSITION;
947
+ }
948
+
949
+ const CGPoint point = rb_mouse_unwrap_point(argv[2]);
950
+ if (argc == 3) {
951
+ mouse_rotate2(direction, angle, point);
952
+ return CURRENT_POSITION;
953
+ }
954
+
955
+ mouse_rotate3(direction, angle, point, NUM2DBL(argv[3]));
956
+ return CURRENT_POSITION;
842
957
  }
843
958
 
844
959
  /* @!endgroup */
845
960
 
846
961
 
962
+ void Init_mouse(void);
963
+
847
964
  void
848
965
  Init_mouse()
849
966
  {
850
- // on either supported Ruby, this should be defined by now
851
- rb_cCGPoint = rb_const_get(rb_cObject, rb_intern("CGPoint"));
852
-
853
- sel_x = rb_intern("x");
854
- sel_y = rb_intern("y");
855
- sel_to_point = rb_intern("to_point");
856
- sel_new = rb_intern("new");
857
-
858
- sym_pixel = ID2SYM(rb_intern("pixel"));
859
- sym_line = ID2SYM(rb_intern("line"));
860
-
861
- sym_up = ID2SYM(rb_intern("up"));
862
- sym_down = ID2SYM(rb_intern("down"));
863
- sym_left = ID2SYM(rb_intern("left"));
864
- sym_right = ID2SYM(rb_intern("right"));
865
-
866
- sym_zoom = ID2SYM(rb_intern("zoom"));
867
- sym_unzoom = ID2SYM(rb_intern("unzoom"));
868
- sym_expand = ID2SYM(rb_intern("expand"));
869
- sym_contract = ID2SYM(rb_intern("contract"));
870
-
871
- sym_cw = ID2SYM(rb_intern("cw"));
872
- sym_clockwise = ID2SYM(rb_intern("clockwise"));
873
- sym_clock_wise = ID2SYM(rb_intern("clock_wise"));
874
- sym_ccw = ID2SYM(rb_intern("ccw"));
875
- sym_counter_clockwise = ID2SYM(rb_intern("counter_clockwise"));
876
- sym_counter_clock_wise = ID2SYM(rb_intern("counter_clock_wise"));
877
-
878
-
879
- /*
880
- * Document-module: Mouse
881
- *
882
- * A module with methods that "tap" into the system input methods.
883
- * This is done by wrapping wrapping around the CoreGraphics event
884
- * taps API provided by OS X.
885
- *
886
- * The module provides a simple Ruby interface to performing mouse
887
- * interactions such as moving and clicking.
888
- *
889
- * This module can be used in a stand alone fashion or you can mix
890
- * it into another class.
891
- *
892
- * [Reference](http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html)
893
- */
894
- rb_mMouse = rb_define_module("Mouse");
895
-
896
- rb_extend_object(rb_mMouse, rb_mMouse);
897
-
898
- rb_define_method(rb_mMouse, "current_position", rb_mouse_current_position, 0);
899
- rb_define_method(rb_mMouse, "move_to", rb_mouse_move_to, -1);
900
- rb_define_method(rb_mMouse, "drag_to", rb_mouse_drag_to, -1);
901
- rb_define_method(rb_mMouse, "scroll", rb_mouse_scroll, -1);
902
- rb_define_method(rb_mMouse, "horizontal_scroll", rb_mouse_horizontal_scroll, -1);
903
- rb_define_method(rb_mMouse, "click_down", rb_mouse_click_down, -1);
904
- rb_define_method(rb_mMouse, "click_up", rb_mouse_click_up, -1);
905
- rb_define_method(rb_mMouse, "click", rb_mouse_click, -1);
906
- rb_define_method(rb_mMouse, "secondary_click_down", rb_mouse_secondary_click_down, -1);
907
- rb_define_method(rb_mMouse, "secondary_click_up", rb_mouse_secondary_click_up, -1);
908
- rb_define_method(rb_mMouse, "secondary_click", rb_mouse_secondary_click, -1);
909
- rb_define_method(rb_mMouse, "middle_click", rb_mouse_middle_click, -1);
910
- rb_define_method(rb_mMouse, "arbitrary_click_down", rb_mouse_arbitrary_click_down, -1);
911
- rb_define_method(rb_mMouse, "arbitrary_click_up", rb_mouse_arbitrary_click_up, -1);
912
- rb_define_method(rb_mMouse, "arbitrary_click", rb_mouse_arbitrary_click, -1);
913
- rb_define_method(rb_mMouse, "multi_click", rb_mouse_multi_click, -1);
914
- rb_define_method(rb_mMouse, "double_click", rb_mouse_double_click, -1);
915
- rb_define_method(rb_mMouse, "triple_click", rb_mouse_triple_click, -1);
916
-
917
- rb_define_method(rb_mMouse, "smart_magnify", rb_mouse_smart_magnify, -1);
918
- rb_define_method(rb_mMouse, "swipe", rb_mouse_swipe, -1);
919
- rb_define_method(rb_mMouse, "pinch", rb_mouse_pinch, -1);
920
- rb_define_method(rb_mMouse, "rotate", rb_mouse_rotate, -1);
921
-
922
- rb_define_alias(rb_mMouse, "hscroll", "horizontal_scroll");
923
- rb_define_alias(rb_mMouse, "right_click_down", "secondary_click_down");
924
- rb_define_alias(rb_mMouse, "right_click_up", "secondary_click_up");
925
- rb_define_alias(rb_mMouse, "right_click", "secondary_click");
926
- rb_define_alias(rb_mMouse, "two_finger_double_tap", "smart_magnify");
967
+ // on either supported Ruby, this should be defined by now
968
+ rb_cCGPoint = rb_const_get(rb_cObject, rb_intern("CGPoint"));
969
+
970
+ sel_x = rb_intern("x");
971
+ sel_y = rb_intern("y");
972
+ sel_to_point = rb_intern("to_point");
973
+ sel_new = rb_intern("new");
974
+
975
+ sym_pixel = ID2SYM(rb_intern("pixel"));
976
+ sym_line = ID2SYM(rb_intern("line"));
977
+
978
+ sym_up = ID2SYM(rb_intern("up"));
979
+ sym_down = ID2SYM(rb_intern("down"));
980
+ sym_left = ID2SYM(rb_intern("left"));
981
+ sym_right = ID2SYM(rb_intern("right"));
982
+
983
+ sym_zoom = ID2SYM(rb_intern("zoom"));
984
+ sym_unzoom = ID2SYM(rb_intern("unzoom"));
985
+ sym_expand = ID2SYM(rb_intern("expand"));
986
+ sym_contract = ID2SYM(rb_intern("contract"));
987
+
988
+ sym_cw = ID2SYM(rb_intern("cw"));
989
+ sym_clockwise = ID2SYM(rb_intern("clockwise"));
990
+ sym_clock_wise = ID2SYM(rb_intern("clock_wise"));
991
+ sym_ccw = ID2SYM(rb_intern("ccw"));
992
+ sym_counter_clockwise = ID2SYM(rb_intern("counter_clockwise"));
993
+ sym_counter_clock_wise = ID2SYM(rb_intern("counter_clock_wise"));
994
+
995
+ /*
996
+ * Document-module: Mouse
997
+ *
998
+ * A module with methods that "tap" into the system input methods.
999
+ * This is done by wrapping wrapping around the CoreGraphics event
1000
+ * taps API provided by OS X.
1001
+ *
1002
+ * The module provides a simple Ruby interface to performing mouse
1003
+ * interactions such as moving and clicking.
1004
+ *
1005
+ * This module can be used in a stand alone fashion or you can mix
1006
+ * it into another class.
1007
+ *
1008
+ * [Reference](http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html)
1009
+ */
1010
+ rb_mMouse = rb_define_module("Mouse");
1011
+
1012
+ rb_extend_object(rb_mMouse, rb_mMouse);
1013
+
1014
+ rb_define_method(rb_mMouse, "current_position", rb_mouse_current_position, 0);
1015
+ rb_define_method(rb_mMouse, "move_to", rb_mouse_move_to, -1);
1016
+ rb_define_method(rb_mMouse, "drag_to", rb_mouse_drag_to, -1);
1017
+ rb_define_method(rb_mMouse, "scroll", rb_mouse_scroll, -1);
1018
+ rb_define_method(rb_mMouse, "horizontal_scroll", rb_mouse_horizontal_scroll, -1);
1019
+ rb_define_method(rb_mMouse, "click_down", rb_mouse_click_down, -1);
1020
+ rb_define_method(rb_mMouse, "click_up", rb_mouse_click_up, -1);
1021
+ rb_define_method(rb_mMouse, "click", rb_mouse_click, -1);
1022
+ rb_define_method(rb_mMouse, "secondary_click_down", rb_mouse_secondary_click_down, -1);
1023
+ rb_define_method(rb_mMouse, "secondary_click_up", rb_mouse_secondary_click_up, -1);
1024
+ rb_define_method(rb_mMouse, "secondary_click", rb_mouse_secondary_click, -1);
1025
+ rb_define_method(rb_mMouse, "middle_click", rb_mouse_middle_click, -1);
1026
+ rb_define_method(rb_mMouse, "arbitrary_click_down", rb_mouse_arbitrary_click_down, -1);
1027
+ rb_define_method(rb_mMouse, "arbitrary_click_up", rb_mouse_arbitrary_click_up, -1);
1028
+ rb_define_method(rb_mMouse, "arbitrary_click", rb_mouse_arbitrary_click, -1);
1029
+ rb_define_method(rb_mMouse, "multi_click", rb_mouse_multi_click, -1);
1030
+ rb_define_method(rb_mMouse, "double_click", rb_mouse_double_click, -1);
1031
+ rb_define_method(rb_mMouse, "triple_click", rb_mouse_triple_click, -1);
1032
+
1033
+ rb_define_method(rb_mMouse, "smart_magnify", rb_mouse_smart_magnify, -1);
1034
+ rb_define_method(rb_mMouse, "swipe", rb_mouse_swipe, -1);
1035
+ rb_define_method(rb_mMouse, "pinch", rb_mouse_pinch, -1);
1036
+ rb_define_method(rb_mMouse, "rotate", rb_mouse_rotate, -1);
1037
+
1038
+ rb_define_alias(rb_mMouse, "hscroll", "horizontal_scroll");
1039
+ rb_define_alias(rb_mMouse, "right_click_down", "secondary_click_down");
1040
+ rb_define_alias(rb_mMouse, "right_click_up", "secondary_click_up");
1041
+ rb_define_alias(rb_mMouse, "right_click", "secondary_click");
1042
+ rb_define_alias(rb_mMouse, "two_finger_double_tap", "smart_magnify");
927
1043
  }