movewin 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/movewin/movewin_ext.c +36 -9
- data/ext/movewin/winutils.c +2 -0
- data/lib/movewin.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 186d90a92e2cba238cb35a3dd4c0ca998ae39c32
|
4
|
+
data.tar.gz: dbbebd61d13940f5e749697f81c0b121b9a57e5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07394cd3f53cb282b2a606a46fc9802c5e773422f69a15b722cdf41aeea9e780ebb9d427e4ec95a1b22cf5feeb6cd582f6419a6ff39a8cf53ffbbc8868747ecd
|
7
|
+
data.tar.gz: 0cd496ec1c9c9d462db9c483d7908f04fc5a4313fe55cfa6dbd7cfe705e660345c40e2de79261c8cf81963d98551439af189828ddcf905f379279ef468742175
|
data/ext/movewin/movewin_ext.c
CHANGED
@@ -67,6 +67,10 @@ void StoreWindows(CFDictionaryRef cgWindow, void *rb_ary_ptr);
|
|
67
67
|
/* Callback for Data_Wrap_Struct(), frees internal refs with CFRelease() */
|
68
68
|
void MW_Window_destroy(void *ref);
|
69
69
|
|
70
|
+
/* Check if VALUE is number or has to_i() method; get number as integer */
|
71
|
+
static bool canGetNumber(VALUE v);
|
72
|
+
static int getNumber(VALUE v);
|
73
|
+
|
70
74
|
/* Copy contents of a CFStringRef into a Ruby string */
|
71
75
|
static VALUE convertStringRef(CFStringRef str);
|
72
76
|
|
@@ -188,11 +192,11 @@ VALUE MW_Window_set_position(VALUE self, VALUE args) {
|
|
188
192
|
args = rb_ary_entry(args, 0);
|
189
193
|
}
|
190
194
|
if( RARRAY_LEN(args) == 2 &&
|
191
|
-
|
192
|
-
|
195
|
+
canGetNumber(rb_ary_entry(args, 0)) &&
|
196
|
+
canGetNumber(rb_ary_entry(args, 1)) )
|
193
197
|
{
|
194
|
-
position.x =
|
195
|
-
position.y =
|
198
|
+
position.x = getNumber(rb_ary_entry(args, 0));
|
199
|
+
position.y = getNumber(rb_ary_entry(args, 1));
|
196
200
|
} else {
|
197
201
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
198
202
|
}
|
@@ -211,11 +215,11 @@ VALUE MW_Window_set_size(VALUE self, VALUE args) {
|
|
211
215
|
args = rb_ary_entry(args, 0);
|
212
216
|
}
|
213
217
|
if( RARRAY_LEN(args) == 2 &&
|
214
|
-
|
215
|
-
|
218
|
+
canGetNumber(rb_ary_entry(args, 0)) &&
|
219
|
+
canGetNumber(rb_ary_entry(args, 1)) )
|
216
220
|
{
|
217
|
-
size.width =
|
218
|
-
size.height =
|
221
|
+
size.width = getNumber(rb_ary_entry(args, 0));
|
222
|
+
size.height = getNumber(rb_ary_entry(args, 1));
|
219
223
|
} else {
|
220
224
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
221
225
|
}
|
@@ -253,7 +257,8 @@ void StoreWindows(CFDictionaryRef cgWindow, void *rb_ary_ptr) {
|
|
253
257
|
axWindow = AXWindowFromCGWindow(cgWindow, i);
|
254
258
|
if(!axWindow) break;
|
255
259
|
mwWindow = (MW_Window *)malloc(sizeof(MW_Window));
|
256
|
-
mwWindow->cgWindow =
|
260
|
+
mwWindow->cgWindow =
|
261
|
+
CFDictionaryCreateCopy(kCFAllocatorDefault, cgWindow);
|
257
262
|
mwWindow->axWindow = axWindow;
|
258
263
|
wrappedMwWindow = Data_Wrap_Struct(
|
259
264
|
MW_WindowClass, NULL, MW_Window_destroy, (void *)mwWindow
|
@@ -272,6 +277,28 @@ void MW_Window_destroy(void *ref) {
|
|
272
277
|
free(mwWindow);
|
273
278
|
}
|
274
279
|
|
280
|
+
/* Return true if a VALUE is a number, or has a to_i() method */
|
281
|
+
static bool canGetNumber(VALUE v) {
|
282
|
+
ID rb_respond_to = rb_intern("respond_to?");
|
283
|
+
ID rb_to_i = rb_intern("to_i");
|
284
|
+
|
285
|
+
return TYPE(v) == T_FIXNUM ||
|
286
|
+
rb_funcall(v, rb_respond_to, 1, ID2SYM(rb_to_i)) == Qtrue;
|
287
|
+
}
|
288
|
+
|
289
|
+
/* Return an integer for a VALUE, calling to_i() first if needed */
|
290
|
+
static int getNumber(VALUE v) {
|
291
|
+
ID rb_to_i = rb_intern("to_i");
|
292
|
+
|
293
|
+
if(TYPE(v) == T_FIXNUM) {
|
294
|
+
return NUM2INT(v);
|
295
|
+
} else if(canGetNumber(v)) {
|
296
|
+
return NUM2INT(rb_funcall(v, rb_to_i, 0));
|
297
|
+
} else {
|
298
|
+
return 0;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
275
302
|
/* Given a CFStringRef, copy its contents into a Ruby string */
|
276
303
|
static VALUE convertStringRef(CFStringRef str) {
|
277
304
|
CFRange range;
|
data/ext/movewin/winutils.c
CHANGED
@@ -94,6 +94,7 @@ int EnumerateWindows(
|
|
94
94
|
if(windowName) free(windowName);
|
95
95
|
if(appName) free(appName);
|
96
96
|
}
|
97
|
+
CFRelease(windowList);
|
97
98
|
if(subPattern != pattern) free(subPattern);
|
98
99
|
|
99
100
|
return count;
|
@@ -219,6 +220,7 @@ AXUIElementRef AXWindowFromCGWindow(CFDictionaryRef window, int minIdx) {
|
|
219
220
|
matchIdx++;
|
220
221
|
}
|
221
222
|
}
|
223
|
+
CFRelease(app);
|
222
224
|
|
223
225
|
return foundAppWindow;
|
224
226
|
}
|
data/lib/movewin.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: movewin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "1.
|
4
|
+
version: "1.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Ho
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2014-09-
|
12
|
+
date: 2014-09-08 00:00:00 Z
|
13
13
|
dependencies: []
|
14
14
|
|
15
15
|
description: List and move OS X windows from Ruby via the OS X accessibility APIs.
|