-
Notifications
You must be signed in to change notification settings - Fork 127
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
Ticket 266 #268
Ticket 266 #268
Conversation
Apple broke NSRunningApplication's activateWithOptions method (so it wrongly always brings all windows to the front). This work-around calls the older (deprecated) SetFrontProcessWithOptions to restore the desired effect. Once Apple fixes their bug, this code can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you! Added some things to address, could you also add the change to the CHANGELOG?
Phoenix.xcodeproj/project.pbxproj
Outdated
@@ -748,7 +748,7 @@ | |||
COMBINE_HIDPI_IMAGES = YES; | |||
CURRENT_PROJECT_VERSION = 92; | |||
ENABLE_HARDENED_RUNTIME = YES; | |||
GCC_TREAT_WARNINGS_AS_ERRORS = YES; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert changes to this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phoenix/Phoenix/PHApp.m:179:26: error: 'GetProcessForPID' is deprecated: first deprecated in macOS 10.9
[-Werror,-Wdeprecated-declarations]
OSStatus error = GetProcessForPID(self.app.processIdentifier, &process);
phoenix/Phoenix/PHApp.m:184:16: error: 'SetFrontProcessWithOptions' is deprecated: first deprecated in macOS 10.9
[-Werror,-Wdeprecated-declarations]
return SetFrontProcessWithOptions(&process, kSetFrontProcessFrontWindowOnly);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm. I used #pragma
to suppress just those two warnings.
Phoenix/PHApp.m
Outdated
@@ -166,7 +167,27 @@ - (BOOL) activate { | |||
|
|||
- (BOOL) focus { | |||
|
|||
return [self.app activateWithOptions:NSApplicationActivateIgnoringOtherApps]; | |||
if (![NSProcessInfo isOperatingSystemAtLeastBigSur]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would reverse this. So:
- check if version is Big Sur, call
SetFrontProcessWithOptions
- do an early return
- always default to
activateWithOptions:
without the else as the last thing of this method
Phoenix/PHApp.m
Outdated
|
||
ProcessSerialNumber process; | ||
OSStatus error = GetProcessForPID(self.app.processIdentifier, &process); | ||
if (error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use noErr
constant for the comparison, see
phoenix/Phoenix/PHOpenAtLoginHelper.m
Line 84 in 53c45c5
if (error != noErr) { |
Phoenix/PHApp.m
Outdated
if (!self.app || self.app.processIdentifier == -1) { | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove redundant newlines.
Phoenix/PHApp.m
Outdated
} | ||
|
||
error = SetFrontProcessWithOptions(&process, kSetFrontProcessFrontWindowOnly); | ||
return (error == 0) ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just return the result of the conditional (i.e. no need for the explicit ternary).
Phoenix/PHApp.m
Outdated
return [self.app activateWithOptions:NSApplicationActivateIgnoringOtherApps]; | ||
} else { | ||
|
||
// Source https://stackoverflow.com/a/65464683/525411 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Source https://stackoverflow.com/a/65464683/525411 | |
// FIX: Workaround for the buggy focus behaviour in Big Sur, see issue #266. For reference see https://stackoverflow.com/a/65464683/525411. |
I incorporated your changes, but I made one additional change. I found that some windows (those from Emacs.app) would fail in (I'm a total Mac programming n00b, so I apologize if I've made this more difficult than it should be! I really appreciate all your help with this.) |
Hmn. Something is still wrong. I don't really understand it. Now PHWindow's focused method is broken. That is, |
@cfraizer Hmm, could you also verify that it triggers the relevant events for focusing? |
I'm not sure what you mean. (Sorry that I'm a bozo!) It certainly moves the focus—that is, it raises the correct window and that window has keyboard input focus, but after moving it, then |
Ah, never mind on that other problem. I was returning the wrong value from I've tested as many variations I can think of and the problem no longer occurs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable, thanks @cfraizer! I’ll test around before releasing a new version.
Updated related documentations
Added the change to the Changelog
I wasn't sure how you wanted to document this, so I didn't.
The only significant change is in
PHApp
'sfocus
method.Of course, I'd be happy to make any changes you suggest.