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

Ticket 266 #268

Merged
merged 5 commits into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Changelog

Release: dd.mm.yyyy

### Changes

- Add temporary workaround for Apple bug that breaks `activateWithOptions:` starting with BigSur ([#266](https://github.com/kasper/phoenix/issues/266)).

2.6.5
-----

Expand Down
1 change: 1 addition & 0 deletions Phoenix/NSProcessInfo+PHExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
#pragma mark - Operating System

+ (BOOL) isOperatingSystemAtLeastElCapitan;
+ (BOOL) isOperatingSystemAtLeastBigSur;

@end
6 changes: 6 additions & 0 deletions Phoenix/NSProcessInfo+PHExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ + (BOOL) isOperatingSystemAtLeastElCapitan {
return [[self processInfo] isOperatingSystemAtLeastVersion:elCapitan];
}

+ (BOOL) isOperatingSystemAtLeastBigSur {

NSOperatingSystemVersion bigSur = { .majorVersion = 11, .minorVersion = 0, .patchVersion = 0 };
return [[self processInfo] isOperatingSystemAtLeastVersion:bigSur];
}

@end
25 changes: 25 additions & 0 deletions Phoenix/PHApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Phoenix is released under the MIT License. Refer to https://github.com/kasper/phoenix/blob/master/LICENSE.md
*/

#import "NSProcessInfo+PHExtension.h"
#import "PHApp.h"
#import "PHWindow.h"

Expand Down Expand Up @@ -166,6 +167,30 @@ - (BOOL) activate {

- (BOOL) focus {

// FIX: Workaround for the buggy focus behaviour in Big Sur, see issue #266. For
// reference see https://stackoverflow.com/a/65464683/525411
if ([NSProcessInfo isOperatingSystemAtLeastBigSur]) {

if (!self.app || [self.app processIdentifier] == -1) {
return false;
}

ProcessSerialNumber process;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
OSStatus error = GetProcessForPID(self.app.processIdentifier, &process);
#pragma GCC diagnostic pop
if (error != noErr) {
return false;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
error = SetFrontProcessWithOptions(&process, kSetFrontProcessFrontWindowOnly);
#pragma GCC diagnostic pop
return error == noErr;
}

return [self.app activateWithOptions:NSApplicationActivateIgnoringOtherApps];
}

Expand Down