movewin 1.4 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,6 +37,11 @@
37
37
  #include <fnmatch.h>
38
38
  #include "winutils.h"
39
39
 
40
+ /* These hardcoded applications are allowed to windows with no name */
41
+ static int emptyWindowNameAllowed(char *appName) {
42
+ return 0 == strcmp(appName, "Messages");
43
+ }
44
+
40
45
  /* Undocumented accessibility API to get window ID:
41
46
  * http://stackoverflow.com/a/10134254
42
47
  * https://github.com/jmgao/metamove/blob/master/src/window.mm
@@ -49,7 +54,7 @@ int EnumerateWindows(
49
54
  void(*callback)(CFDictionaryRef window, void *callback_data),
50
55
  void *callback_data
51
56
  ) {
52
- int patternLen, subPatternLen, count, i, layer, titleSize;
57
+ int patternLen, subPatternLen, count, i, layer;
53
58
  char *subPattern, *starL, *starR, *appName, *windowName, *title;
54
59
  CFArrayRef windowList;
55
60
  CFDictionaryRef window;
@@ -84,10 +89,9 @@ int EnumerateWindows(
84
89
  appName = CFDictionaryCopyCString(window, kCGWindowOwnerName);
85
90
  if(!appName || !*appName) goto skip;
86
91
  windowName = CFDictionaryCopyCString(window, kCGWindowName);
87
- if(!windowName || !*windowName) goto skip;
88
- titleSize = strlen(appName) + strlen(" - ") + strlen(windowName) + 1;
89
- title = (char *)malloc(titleSize);
90
- snprintf(title, titleSize, "%s - %s", appName, windowName);
92
+ if(!windowName || (!*windowName && !emptyWindowNameAllowed(appName)))
93
+ goto skip;
94
+ title = windowTitle(appName, windowName);
91
95
 
92
96
  /* If no pattern, or pattern matches, run callback */
93
97
  if(!pattern || fnmatch(subPattern, title, 0) == 0) {
@@ -145,6 +149,27 @@ char *CFDictionaryCopyCString(CFDictionaryRef dict, const void *key) {
145
149
  return isSuccess ? value : NULL;
146
150
  }
147
151
 
152
+ /* Return newly allocated window title like "appName - windowName" */
153
+ char *windowTitle(char *appName, char *windowName) {
154
+ size_t titleSize;
155
+ char *title;
156
+
157
+ if(!appName || !*appName) {
158
+ title = (char *)malloc(1);
159
+ *title = '\0';
160
+ } else if(!windowName || !*windowName) {
161
+ titleSize = strlen(appName) + 1;
162
+ title = (char *)malloc(titleSize);
163
+ strncpy(title, appName, titleSize);
164
+ } else {
165
+ titleSize = strlen(appName) + strlen(" - ") + strlen(windowName) + 1;
166
+ title = (char *)malloc(titleSize);
167
+ snprintf(title, titleSize, "%s - %s", appName, windowName);
168
+ }
169
+
170
+ return title;
171
+ }
172
+
148
173
  /* Given window dictionary from CGWindowList, return position */
149
174
  CGPoint CGWindowGetPosition(CFDictionaryRef window) {
150
175
  CFDictionaryRef bounds = CFDictionaryGetValue(window, kCGWindowBounds);
@@ -223,7 +248,7 @@ AXUIElementRef AXWindowFromCGWindow(CFDictionaryRef window) {
223
248
  appWindow, kAXTitleAttribute, (CFTypeRef *)&actualWindowTitle
224
249
  );
225
250
  if( !actualWindowTitle ||
226
- CFStringCompare(targetWindowName, actualWindowTitle, 0) != 0)
251
+ CFStringCompare(targetWindowName, actualWindowTitle, 0) != 0 )
227
252
  {
228
253
  continue;
229
254
  }
@@ -56,6 +56,9 @@ int CFDictionaryGetInt(CFDictionaryRef dict, const void *key);
56
56
  /* Copy a string value from a CFDictionary into a newly allocated string */
57
57
  char *CFDictionaryCopyCString(CFDictionaryRef dict, const void *key);
58
58
 
59
+ /* Return newly allocated window title like "appName - windowName" */
60
+ char *windowTitle(char *appName, char *windowName);
61
+
59
62
  /* Given window dictionary from CGWindowList, return position, size */
60
63
  CGPoint CGWindowGetPosition(CFDictionaryRef window);
61
64
  CGSize CGWindowGetSize(CFDictionaryRef window);
data/lib/movewin.rb CHANGED
@@ -36,7 +36,7 @@
36
36
  require 'movewin/movewin_ext'
37
37
 
38
38
  module MoveWin
39
- VERSION = '1.4'
39
+ VERSION = '1.5'
40
40
 
41
41
  # Individual accessors for display size components
42
42
  def self.display_width; MoveWin.display_size[0]; end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: movewin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 4
9
- version: "1.4"
8
+ - 5
9
+ version: "1.5"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Ho
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2014-10-30 00:00:00 Z
17
+ date: 2014-10-31 00:00:00 Z
18
18
  dependencies: []
19
19
 
20
20
  description: List and move OS X windows from Ruby via the OS X accessibility APIs.
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  requirements: []
61
61
 
62
62
  rubyforge_project:
63
- rubygems_version: 1.8.7
63
+ rubygems_version: 1.8.10
64
64
  signing_key:
65
65
  specification_version: 3
66
66
  summary: List and move OS X windows from Ruby