Skip to content
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

Rewrite dock detection and handling #22

Open
apaszke opened this issue Aug 19, 2015 · 10 comments
Open

Rewrite dock detection and handling #22

apaszke opened this issue Aug 19, 2015 · 10 comments

Comments

@apaszke
Copy link
Owner

apaszke commented Aug 19, 2015

The whole dock logic has to be rewritten. It's too hacky now. There are too many magic constants and unreliable ways of detecting it's position.

  1. How dock scale slider affects it's size in pixels (maybe it depends on screen size)?
  2. Why visibleFrame in getScreenInfo sometimes doesn't detect the dock on the bottom edge (or why and when can you resize windows to be underneath the dock)?

@ezig I'd be grateful for any hints 😊 Thanks for your help with all these issues!

@ezig
Copy link
Contributor

ezig commented Aug 19, 2015

Here's something weird:

If you use tell dock preferences, you can get back dock size which seems to be a scale from 0 to 1 of the but, as you said, that doesn't tell you the pixel size. But, if you access the preferences file directly, you can actually get out the pixel size:

set prefsFile to ((path to preferences from user domain) as text) & "com.apple.dock.plist"
tell application "System Events"
    set _dockSize to (value of property list item "tilesize" of property list file prefsFile)
end tell

I'd be happy to take this issue on and try out some different solutions to rework the dock handling :)

@apaszke
Copy link
Owner Author

apaszke commented Aug 19, 2015

Oh wow, that looks awesome! But, it returns 64 for me, while my dock has 80px 😕 Anyway, if there's any way to convert this number to true pixel values, then the whole thing is nearly solved!
I will be probably away for the next one or two days so go ahead if you wish 😊

@apaszke
Copy link
Owner Author

apaszke commented Aug 19, 2015

The value is different because it's an icon size as far as I can see. We have to figure out whether the remaining 16px is constant or not. I've also found this snippet:

tell application "System Events" to tell process "Dock"
    set dock_dimensions to size in list 1
    set dock_width to item 1 of dock_dimensions
    set dock_height to item 2 of dock_dimensions
end tell

which works perfectly, but requires assistive access.

@apaszke
Copy link
Owner Author

apaszke commented Aug 21, 2015

@ezig Let's move the discussion here.

I've done some measurements and put them in google spreadsheet. I hope that they're consistent across screen proportions. What kind of mac do you have @ezig?

https://docs.google.com/spreadsheets/d/1eScVnzvKZINspm_4Ky6FmtYpubE6Svci-0DDAscTixw/edit?usp=sharing

It looks promising. If it's similar on different resolutions then we can just use some kind of a lookup table. I can write a script to make it even more fine grained later.

image

The blue line was recorded in 1440x900, the orange one is 1920x1200, and the red one is what was read from .plist preferences (it was consistent across resolutions).

@ezig
Copy link
Contributor

ezig commented Aug 21, 2015

I'm using a 2013 15" Macbook Pro with retina.

A lookup table seems like it would work if there was enough data, as long as things are pretty consistent for different resolutions. It seems like there should be an easier way to do this (without needing accessibility), but we haven't found it yet 😕 .

@apaszke
Copy link
Owner Author

apaszke commented Aug 21, 2015

I now think that the lookup table might not be such a good idea, because the number of icons in the dock affects it's size too... It doesn't seem reliable (unless we find a formula - the icons are listed in plist file as well).
I really don't want to require accessibility permissions for script runner (which doesn't feel safe at all).

@ezig
Copy link
Contributor

ezig commented Aug 22, 2015

It seems like the Objective-C utility might be the most reliable things we have for now? The AppleScript alternatives we've found don't seem any more reliable.

@apaszke
Copy link
Owner Author

apaszke commented Aug 22, 2015

I have no idea why, but suddenly visibleFrame started to work. If the dock is on the left, then it reports that originX is 64 😮

@apaszke
Copy link
Owner Author

apaszke commented Aug 22, 2015

I think that modifying the dock properties with AppleScript somehow messes up the values of visibleFrame. It's all good after a reboot.

@apaszke
Copy link
Owner Author

apaszke commented Aug 22, 2015

I've changed a bit in 9e9ac33 and it seems to be better now. I'm getting much more consistent behaviour now. What's left to be done is to write a better fallback in case something goes wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants