-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: add support for window zoom #181
Comments
@cmsj We implemented it nearly simultaneously... 👍 |
@mgee haha, sorry! |
Nevermind ;-) |
commit f91a490 does not implement the behavior I was expecting from this feature request. (the code was eventually refectored under the window_pressbutton function) Clicking kAXZoomButtonAttribute on OSX < 10.10 it calls toggleZoom and on OSX 10.10 it calls toggleFullScreen unless option is pressed then toggleZoom is called. This has the effect that toggleZoom has a different behavior depending on your OS X version. No ideal IMO. To remedy that, I believe the proper implementation for hs.window:toggleZoom() would be to call NSWindow 's zoom: method as opposed to simply clicking the button kAXZoomButtonAttribute. This would at least be consistent accross OS X versions. |
reopening, but note that we don't have access to the nswindow object, just the accessibility API |
would it be possible to fake a keypress on option while clicking kAXZoomButtonAttribute? In OSX > 10.9 clicking the zoom button toggle the zoom stateand option+click toggle the maximized state which was the previous default in OSX < 10.9 hs.window:toggleZoom(), clicks kAXZoomButtonAttribute |
faking keypresses gets very complex, because we can't be sure what the user is pressing at the time, so they might end up confusing things. Also I'm not sure if the accessibility layer would even care about it. I think a better option here would be to wrap this up at the Lua layer and store the current frame of a window, call :maximize() on it, note that that has happened, then when called again, restore the original frame. |
I ended up implementing it in lua hs.hotkey.bind(mash, 'RETURN', function()
local win = hs.window.focusedWindow()
local frame = win:frame()
local id = win:id()
-- init table to save window state
savedwin = savedwin or {}
savedwin[id] = savedwin[id] or {}
if (savedwin[id].maximized == nil or savedwin[id].maximized == false) then
savedwin[id].frame = frame
savedwin[id].maximized = true
win:maximize()
else
savedwin[id].maximized = false
win:setFrame(savedwin[id].frame)
end
end) |
@jfchevrette looks good. One thing I might suggest is that in the else section, you actually do savedwin[id] = nil, otherwise you're going to slowly leak references to windows that don't exist anymore. I'm going to close out this issue for now, but I do think we should have some generic abstraction in hs.window for snapshotting the frame and restoring it later, very much like how your savedwin code works. |
Sorry to comment on a closed issue, but I'd like to point out that zoom is not the same as maximize. In many Apple applications, clicking the zoom button doesn't make the window fill the screen, but makes the window large enough to fit whatever the content is (e.g. in Preview, it makes it big enough to fit the page). Of course, I have no idea how to activate this if they changed what the meaning of "zoom" is in the API... |
@tmandry yes, the zoom button is weird and inconsistent (and thus, imho, useless), which is why we didn't support it for a long time, but we do now, so if people want to use it, they can :) |
When using hs.window:maximize() the window will be resized to fill the screen w/o the dock. It is my understanding that hs does this manually by setting the window position/size as opposed to using OS capabilities.
It would be useful to add window zoom functionnality using OS X zoom capabilities (when an app/window supports it). Then we can also support "unzooming" so that the window previous position/size is restored.
The AppKit zoom method is available in OS X 10.0 and later and should be all that's needed to toggle between zoomed/unzoomed. If the window does not support zooming, a beep sound is triggered by the OS.
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/index.html#//apple_ref/occ/instm/NSWindow/zoom:
The text was updated successfully, but these errors were encountered: