Skip to content

Commit

Permalink
Fixed an issue with the new Activity Monitor (maybe other apps as well)
Browse files Browse the repository at this point in the history
  • Loading branch information
untoldwind committed Nov 21, 2013
1 parent 2ab24a2 commit e4561ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Binary file modified Layout.alfredworkflow
Binary file not shown.
2 changes: 1 addition & 1 deletion src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fi</string>
<key>argument</key>
<integer>3</integer>
<key>argumenttext</key>
<string>set:0.1,0.1,0.9,0.9</string>
<string>set:0,0,1,1:+1</string>
<key>hotkey</key>
<integer>0</integer>
<key>hotmod</key>
Expand Down
12 changes: 10 additions & 2 deletions src/layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,22 @@ def to_s()
end
end

def findMainWindow(process)
window = process.attributes().objectWithName_("AXMainWindow").value().get()
if window.nil?
window = process.attributes().objectWithName_("AXFocusedWindow").value().get()
end
window
end

def setWindowBounds(process, window, screen, bounds)
# these properties can be found in /System/Library/CoreServices/System Events.app/Contents/Resources/SystemEvents.sdef
# there is a little issue if the window is too big (i.e. partly outside screen), therefore we first move to 0,0
windowSize = window.propertyWithCode_(0x7074737a) # this is "ptsz" in hexcode
windowSize.setTo_([bounds.width, bounds.height])

# After this we do it anew since there might be some events swallowed otherwide
window = process.attributes().objectWithName_("AXMainWindow").value().get()
window = findMainWindow(process)
windowPosition = window.propertyWithCode_(0x706f736e) # this is "posn" in hexcode
windowPosition.setTo_([bounds.left, bounds.top])
windowSize = window.propertyWithCode_(0x7074737a) # this is "ptsz" in hexcode
Expand Down Expand Up @@ -78,7 +86,7 @@ def setWindowBounds(process, window, screen, bounds)

frontmostPredicate = OSX::NSPredicate.predicateWithFormat("frontmost == true")
frontmost = systemevents.processes().filteredArrayUsingPredicate_(frontmostPredicate).first
window = frontmost.attributes().objectWithName_("AXMainWindow").value().get()
window = findMainWindow(frontmost)
properties = window.properties()
appRect = Rect.new(properties['position'][0].to_i, properties['position'][1].to_i,
properties['position'][0].to_i + properties['size'][0].to_i, properties['position'][1].to_i + properties['size'][1].to_i)
Expand Down

0 comments on commit e4561ad

Please sign in to comment.