mouse 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.markdown CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.1.0 - A bit more granularity
2
+
3
+ * Add `Mouse.secondary_click_down` and alias `Mouse.right_click_down`
4
+ * Add `Mouse.secondary_click_up` and alias `Mouse.right_click_up`
5
+ * Add `Mouse.arbitrary_click_down`
6
+ * Add `Mouse.arbitrary_click_up`
7
+
1
8
  # 1.0.6 - Boogs
2
9
 
3
10
  * Fix `Mouse.scroll` assuming arguments always included units
data/ext/mouse/mouse.c CHANGED
@@ -6,7 +6,6 @@ static VALUE rb_cCGPoint;
6
6
  static ID sel_x;
7
7
  static ID sel_y;
8
8
  static ID sel_to_point;
9
- static ID sel_to_i;
10
9
  static ID sel_new;
11
10
  static ID unit_pixel;
12
11
  static ID unit_line;
@@ -130,12 +129,11 @@ rb_mouse_scroll(int argc, VALUE *argv, VALUE self)
130
129
  if (argc == 0 || argc > 3)
131
130
  rb_raise(rb_eArgError, "scroll requires 1..3 arguments, you gave %d", argc);
132
131
 
133
- VALUE amount = rb_funcall(argv[0], sel_to_i, 0);
134
- int amt = NUM2INT(amount);
132
+ int amt = NUM2INT(argv[0]);
135
133
 
136
134
  if (argc == 1) {
137
135
  mouse_scroll(amt);
138
- return amount;
136
+ return argv[0];
139
137
  }
140
138
 
141
139
  ID units = rb_to_id(argv[1]);
@@ -160,7 +158,7 @@ rb_mouse_scroll(int argc, VALUE *argv, VALUE self)
160
158
  rb_raise(rb_eArgError, "unknown units `%s'", rb_id2name(units));
161
159
  }
162
160
 
163
- return amount;
161
+ return argv[0];
164
162
  }
165
163
 
166
164
  /*
@@ -247,6 +245,65 @@ rb_mouse_click(int argc, VALUE *argv, VALUE self)
247
245
  return CURRENT_POSITION;
248
246
  }
249
247
 
248
+ /*
249
+ * Generate the down click part of a secondary/right click event
250
+ *
251
+ * This might be useful in concert with {Mouse.secondary_click_up} if
252
+ * you want to inject some behaviour between the down and up click
253
+ * events.
254
+ *
255
+ * You can optionally specify a point to click; the mouse cursor will
256
+ * instantly jump to the given point.
257
+ *
258
+ * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
259
+ * @return [CGPoint]
260
+ */
261
+ static
262
+ VALUE
263
+ rb_mouse_secondary_click_down(int argc, VALUE* argv, VALUE self)
264
+ {
265
+ switch (argc)
266
+ {
267
+ case 0:
268
+ mouse_secondary_click_down();
269
+ break;
270
+ case 1:
271
+ default:
272
+ mouse_secondary_click_down2(rb_mouse_unwrap_point(argv[0]));
273
+ }
274
+
275
+ return CURRENT_POSITION;
276
+ }
277
+
278
+ /*
279
+ * Generate the up click part of a secondary/right click event
280
+ *
281
+ * This might be useful in concert with {Mouse.secondary_click_down} if
282
+ * you want to inject some behaviour between the down and up click events.
283
+ *
284
+ * You can optionally specify a point to click; the mouse cursor will
285
+ * instantly jump to the given point.
286
+ *
287
+ * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
288
+ * @return [CGPoint]
289
+ */
290
+ static
291
+ VALUE
292
+ rb_mouse_secondary_click_up(int argc, VALUE* argv, VALUE self)
293
+ {
294
+ switch (argc)
295
+ {
296
+ case 0:
297
+ mouse_secondary_click_up();
298
+ break;
299
+ case 1:
300
+ default:
301
+ mouse_secondary_click_up2(rb_mouse_unwrap_point(argv[0]));
302
+ }
303
+
304
+ return CURRENT_POSITION;
305
+ }
306
+
250
307
  /*
251
308
  * Generate a secondary click (both down and up events)
252
309
  *
@@ -275,6 +332,75 @@ rb_mouse_secondary_click(int argc, VALUE *argv, VALUE self)
275
332
  return CURRENT_POSITION;
276
333
  }
277
334
 
335
+ /*
336
+ * Generate the down click part of an arbitrary click event
337
+ *
338
+ * This might be useful in concert with {Mouse.arbitrary_click_up} if
339
+ * you want to inject some behaviour between the down and up click
340
+ * events.
341
+ *
342
+ * You can optionally specify a point to click; the mouse cursor will
343
+ * instantly jump to the given point.
344
+ *
345
+ * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
346
+ * @return [CGPoint]
347
+ */
348
+ static
349
+ VALUE
350
+ rb_mouse_arbitrary_click_down(int argc, VALUE* argv, VALUE self)
351
+ {
352
+ if (argc == 0)
353
+ rb_raise(rb_eArgError, "arbitrary_click_down requires at least one arg");
354
+
355
+ uint_t button = NUM2INT(argv[0]);
356
+
357
+ switch (argc)
358
+ {
359
+ case 1:
360
+ mouse_arbitrary_click_down(button);
361
+ break;
362
+ case 2:
363
+ default:
364
+ mouse_arbitrary_click_down2(button, rb_mouse_unwrap_point(argv[1]));
365
+ }
366
+
367
+ return CURRENT_POSITION;
368
+ }
369
+
370
+ /*
371
+ * Generate the up click part of an arbitrary click event
372
+ *
373
+ * This might be useful in concert with {Mouse.arbitrary_click_down} if
374
+ * you want to inject some behaviour between the down and up click events.
375
+ *
376
+ * You can optionally specify a point to click; the mouse cursor will
377
+ * instantly jump to the given point.
378
+ *
379
+ * @param point [CGPoint] (_default_: {#current_position}) (__optional__)
380
+ * @return [CGPoint]
381
+ */
382
+ static
383
+ VALUE
384
+ rb_mouse_arbitrary_click_up(int argc, VALUE* argv, VALUE self)
385
+ {
386
+ if (argc == 0)
387
+ rb_raise(rb_eArgError, "arbitrary_click_up requires at least one arg");
388
+
389
+ uint_t button = NUM2INT(argv[0]);
390
+
391
+ switch (argc)
392
+ {
393
+ case 1:
394
+ mouse_arbitrary_click_up(button);
395
+ break;
396
+ case 2:
397
+ default:
398
+ mouse_arbitrary_click_up2(button, rb_mouse_unwrap_point(argv[1]));
399
+ }
400
+
401
+ return CURRENT_POSITION;
402
+ }
403
+
278
404
  /*
279
405
  * Generate a click using an arbitrary mouse button (down and up events)
280
406
  *
@@ -305,7 +431,7 @@ rb_mouse_arbitrary_click(int argc, VALUE *argv, VALUE self)
305
431
  return Qnil;
306
432
  }
307
433
 
308
- uint_t button = NUM2INT(rb_funcall(argv[0], sel_to_i, 0));
434
+ uint_t button = NUM2INT(argv[0]);
309
435
 
310
436
  switch (argc)
311
437
  {
@@ -372,7 +498,7 @@ rb_mouse_multi_click(int argc, VALUE *argv, VALUE self)
372
498
  }
373
499
 
374
500
  // TODO: there has got to be a more idiomatic way to do this coercion
375
- size_t num_clicks = NUM2SIZET(rb_funcall(argv[0], sel_to_i, 0));
501
+ size_t num_clicks = NUM2SIZET(argv[0]);
376
502
 
377
503
  switch (argc)
378
504
  {
@@ -457,7 +583,6 @@ Init_mouse()
457
583
  sel_x = rb_intern("x");
458
584
  sel_y = rb_intern("y");
459
585
  sel_to_point = rb_intern("to_point");
460
- sel_to_i = rb_intern("to_i");
461
586
  sel_new = rb_intern("new");
462
587
 
463
588
  unit_pixel = rb_intern("pixel");
@@ -482,19 +607,25 @@ Init_mouse()
482
607
 
483
608
  rb_extend_object(rb_mMouse, rb_mMouse);
484
609
 
485
- rb_define_method(rb_mMouse, "current_position", rb_mouse_current_position, 0);
486
- rb_define_method(rb_mMouse, "move_to", rb_mouse_move_to, -1);
487
- rb_define_method(rb_mMouse, "drag_to", rb_mouse_drag_to, -1);
488
- rb_define_method(rb_mMouse, "scroll", rb_mouse_scroll, -1);
489
- rb_define_method(rb_mMouse, "click_down", rb_mouse_click_down, -1);
490
- rb_define_method(rb_mMouse, "click_up", rb_mouse_click_up, -1);
491
- rb_define_method(rb_mMouse, "click", rb_mouse_click, -1);
492
- rb_define_method(rb_mMouse, "secondary_click", rb_mouse_secondary_click, -1);
493
- rb_define_method(rb_mMouse, "middle_click", rb_mouse_middle_click, -1);
494
- rb_define_method(rb_mMouse, "arbitrary_click", rb_mouse_arbitrary_click, -1);
495
- rb_define_method(rb_mMouse, "multi_click", rb_mouse_multi_click, -1);
496
- rb_define_method(rb_mMouse, "double_click", rb_mouse_double_click, -1);
497
- rb_define_method(rb_mMouse, "triple_click", rb_mouse_triple_click, -1);
498
-
499
- rb_define_alias(rb_mMouse, "right_click", "secondary_click");
610
+ rb_define_method(rb_mMouse, "current_position", rb_mouse_current_position, 0);
611
+ rb_define_method(rb_mMouse, "move_to", rb_mouse_move_to, -1);
612
+ rb_define_method(rb_mMouse, "drag_to", rb_mouse_drag_to, -1);
613
+ rb_define_method(rb_mMouse, "scroll", rb_mouse_scroll, -1);
614
+ rb_define_method(rb_mMouse, "click_down", rb_mouse_click_down, -1);
615
+ rb_define_method(rb_mMouse, "click_up", rb_mouse_click_up, -1);
616
+ rb_define_method(rb_mMouse, "click", rb_mouse_click, -1);
617
+ rb_define_method(rb_mMouse, "secondary_click_down", rb_mouse_secondary_click_down, -1);
618
+ rb_define_method(rb_mMouse, "secondary_click_up", rb_mouse_secondary_click_up, -1);
619
+ rb_define_method(rb_mMouse, "secondary_click", rb_mouse_secondary_click, -1);
620
+ rb_define_method(rb_mMouse, "middle_click", rb_mouse_middle_click, -1);
621
+ rb_define_method(rb_mMouse, "arbitrary_click_down", rb_mouse_arbitrary_click_down, -1);
622
+ rb_define_method(rb_mMouse, "arbitrary_click_up", rb_mouse_arbitrary_click_up, -1);
623
+ rb_define_method(rb_mMouse, "arbitrary_click", rb_mouse_arbitrary_click, -1);
624
+ rb_define_method(rb_mMouse, "multi_click", rb_mouse_multi_click, -1);
625
+ rb_define_method(rb_mMouse, "double_click", rb_mouse_double_click, -1);
626
+ rb_define_method(rb_mMouse, "triple_click", rb_mouse_triple_click, -1);
627
+
628
+ rb_define_alias(rb_mMouse, "right_click_down", "secondary_click_down");
629
+ rb_define_alias(rb_mMouse, "right_click_up", "secondary_click_up");
630
+ rb_define_alias(rb_mMouse, "right_click", "secondary_click");
500
631
  }
data/ext/mouse/mouser.c CHANGED
@@ -27,10 +27,10 @@ static const double DEFAULT_DURATION = 0.2; // seconds
27
27
  #endif
28
28
 
29
29
  #define POSTRELEASE(x) do { \
30
- CGEventRef event = x; \
31
- POST(event); \
32
- RELEASE(event); \
33
- } while(false);
30
+ CGEventRef event = x; \
31
+ POST(event); \
32
+ RELEASE(event); \
33
+ } while(false);
34
34
 
35
35
 
36
36
  static
@@ -152,7 +152,7 @@ mouse_scroll3(int amount, CGScrollEventUnit units, double duration)
152
152
  {
153
153
  size_t steps = round(FPS * duration);
154
154
  double current = 0.0;
155
- double done = 0;
155
+ double done = 0.0;
156
156
  int32_t scroll = 0;
157
157
 
158
158
  for (size_t step = 0; step < steps; step++) {
@@ -225,57 +225,134 @@ mouse_click()
225
225
 
226
226
 
227
227
  void
228
- mouse_secondary_click3(CGPoint point, uint_t sleep_quanta)
228
+ mouse_secondary_click_down3(CGPoint point, uint_t sleep_quanta)
229
229
  {
230
230
  CGEventRef base_event = NEW_EVENT(
231
231
  kCGEventRightMouseDown,
232
232
  point,
233
233
  kCGMouseButtonRight
234
234
  );
235
- POST(base_event);
235
+ POSTRELEASE(base_event);
236
236
  mouse_sleep(sleep_quanta);
237
+ }
238
+
239
+ void
240
+ mouse_secondary_click_down2(CGPoint point)
241
+ {
242
+ mouse_secondary_click_down3(point, FPS / 10);
243
+ }
237
244
 
238
- CHANGE(base_event, kCGEventRightMouseUp);
245
+ void
246
+ mouse_secondary_click_down()
247
+ {
248
+ mouse_secondary_click_down2(mouse_current_position());
249
+ }
250
+
251
+
252
+ void
253
+ mouse_secondary_click_up2(CGPoint point)
254
+ {
255
+ CGEventRef base_event = NEW_EVENT(
256
+ kCGEventRightMouseUp,
257
+ point,
258
+ kCGMouseButtonRight
259
+ );
239
260
  POSTRELEASE(base_event);
240
261
  }
241
262
 
263
+ void
264
+ mouse_secondary_click_up()
265
+ {
266
+ mouse_secondary_click_up2(mouse_current_position());
267
+ }
268
+
269
+
270
+ void
271
+ mouse_secondary_click3(CGPoint point, uint_t sleep_quanta)
272
+ {
273
+ mouse_secondary_click_down3(point, sleep_quanta);
274
+ mouse_secondary_click_up2(point);
275
+ }
276
+
242
277
  void
243
278
  mouse_secondary_click2(CGPoint point)
244
279
  {
245
- mouse_secondary_click3(point, FPS / 10);
280
+ mouse_secondary_click_down2(point);
281
+ mouse_secondary_click_up2(point);
246
282
  }
247
283
 
248
284
  void
249
285
  mouse_secondary_click()
250
286
  {
251
- mouse_secondary_click2(mouse_current_position());
287
+ mouse_secondary_click_down();
288
+ mouse_secondary_click_up();
252
289
  }
253
290
 
254
291
 
255
292
  void
256
- mouse_arbitrary_click3(CGEventMouseSubtype button, CGPoint point, uint_t sleep_quanta)
293
+ mouse_arbitrary_click_down3(
294
+ CGEventMouseSubtype button,
295
+ CGPoint point,
296
+ uint_t sleep_quanta
297
+ )
257
298
  {
258
299
  CGEventRef base_event = NEW_EVENT(
259
300
  kCGEventOtherMouseDown,
260
301
  point,
261
302
  button
262
303
  );
263
- POST(base_event);
304
+ POSTRELEASE(base_event);
264
305
  mouse_sleep(sleep_quanta);
265
- CHANGE(base_event, kCGEventOtherMouseUp);
306
+ }
307
+
308
+ void
309
+ mouse_arbitrary_click_down2(CGEventMouseSubtype button, CGPoint point)
310
+ {
311
+ mouse_arbitrary_click_down3(button, point, FPS / 10);
312
+ }
313
+
314
+ void
315
+ mouse_arbitrary_click_down(CGEventMouseSubtype button)
316
+ {
317
+ mouse_arbitrary_click_down2(button, mouse_current_position());
318
+ }
319
+
320
+
321
+ void mouse_arbitrary_click_up2(CGEventMouseSubtype button, CGPoint point)
322
+ {
323
+ CGEventRef base_event = NEW_EVENT(
324
+ kCGEventOtherMouseUp,
325
+ point,
326
+ button
327
+ );
266
328
  POSTRELEASE(base_event);
267
329
  }
268
330
 
331
+ void mouse_arbitrary_click_up(CGEventMouseSubtype button)
332
+ {
333
+ mouse_arbitrary_click_up2(button, mouse_current_position());
334
+ }
335
+
336
+
337
+ void
338
+ mouse_arbitrary_click3(CGEventMouseSubtype button, CGPoint point, uint_t sleep_quanta)
339
+ {
340
+ mouse_arbitrary_click_down3(button, point, sleep_quanta);
341
+ mouse_arbitrary_click_up2(button, point);
342
+ }
343
+
269
344
  void
270
345
  mouse_arbitrary_click2(CGEventMouseSubtype button, CGPoint point)
271
346
  {
272
- mouse_arbitrary_click3(button, point, FPS / 10);
347
+ mouse_arbitrary_click_down2(button, point);
348
+ mouse_arbitrary_click_up2(button, point);
273
349
  }
274
350
 
275
351
  void
276
352
  mouse_arbitrary_click(CGEventMouseSubtype button)
277
353
  {
278
- mouse_arbitrary_click2(button, mouse_current_position());
354
+ mouse_arbitrary_click_down(button);
355
+ mouse_arbitrary_click_up(button);
279
356
  }
280
357
 
281
358
 
data/ext/mouse/mouser.h CHANGED
@@ -32,10 +32,24 @@ void mouse_click_up2(CGPoint point);
32
32
  void mouse_click();
33
33
  void mouse_click2(CGPoint point);
34
34
 
35
+ void mouse_secondary_click_down();
36
+ void mouse_secondary_click_down2(CGPoint point);
37
+ void mouse_secondary_click_down3(CGPoint point, uint_t sleep_quanta);
38
+
39
+ void mouse_secondary_click_up();
40
+ void mouse_secondary_click_up2(CGPoint point);
41
+
35
42
  void mouse_secondary_click();
36
43
  void mouse_secondary_click2(CGPoint point);
37
44
  void mouse_secondary_click3(CGPoint point, uint_t sleep_quanta);
38
45
 
46
+ void mouse_arbitrary_click_down(CGEventMouseSubtype button);
47
+ void mouse_arbitrary_click_down2(CGEventMouseSubtype button, CGPoint point);
48
+ void mouse_arbitrary_click_down3(CGEventMouseSubtype button, CGPoint point, uint_t sleep_quanta);
49
+
50
+ void mouse_arbitrary_click_up(CGEventMouseSubtype button);
51
+ void mouse_arbitrary_click_up2(CGEventMouseSubtype button, CGPoint point);
52
+
39
53
  void mouse_arbitrary_click(CGEventMouseSubtype button);
40
54
  void mouse_arbitrary_click2(CGEventMouseSubtype button, CGPoint point);
41
55
  void mouse_arbitrary_click3(CGEventMouseSubtype button, CGPoint point, uint_t sleep_quanta);
data/lib/mouse/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Mouse
2
- VERSION = '1.0.6'
2
+ VERSION = '1.1.0'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mouse
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-26 00:00:00.000000000 Z
12
+ date: 2013-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard