Skip to content

Commit

Permalink
Code Cleanup / Update UI
Browse files Browse the repository at this point in the history
Float and drop window items now act as toggles like transient window item. Remove 'Reset Window' item. Code cleanup and formatting. Update version number.
  • Loading branch information
jslegendre committed Dec 4, 2019
1 parent 95e6041 commit df0217b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
8 changes: 4 additions & 4 deletions AfloatX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.0.3;
CURRENT_PROJECT_VERSION = 1.0.7;
DEPLOYMENT_LOCATION = YES;
DEVELOPMENT_TEAM = 6LAE5ASX7M;
DSTROOT = /;
Expand All @@ -315,7 +315,7 @@
INFOPLIST_FILE = AfloatX/Info.plist;
INSTALL_PATH = "/Library/Application Support/MacEnhance/Plugins";
MACH_O_TYPE = mh_dylib;
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.7;
PRODUCT_BUNDLE_IDENTIFIER = com.github.jslegendre.AfloatX;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = bundle;
Expand All @@ -329,7 +329,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.0.3;
CURRENT_PROJECT_VERSION = 1.0.7;
DEPLOYMENT_LOCATION = YES;
DEVELOPMENT_TEAM = 6LAE5ASX7M;
DSTROOT = /;
Expand All @@ -339,7 +339,7 @@
INFOPLIST_FILE = AfloatX/Info.plist;
INSTALL_PATH = "/Library/Application Support/MacEnhance/Plugins";
MACH_O_TYPE = mh_dylib;
MARKETING_VERSION = 1.0.3;
MARKETING_VERSION = 1.0.7;
PRODUCT_BUNDLE_IDENTIFIER = com.github.jslegendre.AfloatX;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = bundle;
Expand Down
54 changes: 31 additions & 23 deletions AfloatX/AfloatX.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
NSMenu *AfloatXSubmenu;
NSMenuItem *floatItem;
NSMenuItem *dropItem;
NSMenuItem *resetItem;
NSMenuItem *transparencyItem;
NSMenu *transparencyItemSubMenu;
NSMenuItem *moreTransparentItem;
Expand Down Expand Up @@ -81,16 +80,20 @@ - (void)toggleTransientMainWindow {
}
}

- (void)floatMainWindow {
[[self windowToModify] setLevel:NSFloatingWindowLevel];
}

- (void)dropMainWindow {
[[self windowToModify] setLevel:kCGBackstopMenuLevel];
- (void)toggleFloatMainWindow {
if([[self windowToModify] level] == NSFloatingWindowLevel) {
[[self windowToModify] setLevel:NSNormalWindowLevel];
} else {
[[self windowToModify] setLevel:NSFloatingWindowLevel];
}
}

- (void)resetMainWindow {
[[self windowToModify] setLevel:NSNormalWindowLevel];
- (void)toggleDropMainWindow {
if([[self windowToModify] level] == kCGBackstopMenuLevel) {
[[self windowToModify] setLevel:NSNormalWindowLevel];
} else {
[[self windowToModify] setLevel:kCGBackstopMenuLevel];
}
}

- (void)moreTransparentMainWindow {
Expand All @@ -117,12 +120,13 @@ + (void)load {
AfloatXItem.title = @"AfloatX";
AfloatXSubmenu = [NSMenu new];
AfloatXItem.submenu = AfloatXSubmenu;
floatItem = [[NSMenuItem alloc] initWithTitle:@"Float Window" action:@selector(floatMainWindow) keyEquivalent:@""];

floatItem = [[NSMenuItem alloc] initWithTitle:@"Float Window" action:@selector(toggleFloatMainWindow) keyEquivalent:@""];
[floatItem setTarget:plugin];
dropItem = [[NSMenuItem alloc] initWithTitle:@"Drop Window" action:@selector(dropMainWindow) keyEquivalent:@""];

dropItem = [[NSMenuItem alloc] initWithTitle:@"Drop Window" action:@selector(toggleDropMainWindow) keyEquivalent:@""];
[dropItem setTarget:plugin];
resetItem = [[NSMenuItem alloc] initWithTitle:@"Reset Window" action:@selector(resetMainWindow) keyEquivalent:@""];
[resetItem setTarget:plugin];

transientItem = [[NSMenuItem alloc] initWithTitle:@"Transient Window" action:@selector(toggleTransientMainWindow) keyEquivalent:@""];
[transientItem setTarget:plugin];

Expand All @@ -131,16 +135,19 @@ + (void)load {
transparencyItemSubMenu = [NSMenu new];
transparencyItem.submenu = transparencyItemSubMenu;

NSString *s = [NSString stringWithFormat:@"T%C", 0x001f];
moreTransparentItem = [[NSMenuItem alloc] initWithTitle:@"More Transparent" action:@selector(moreTransparentMainWindow) keyEquivalent:s];
moreTransparentItem = [[NSMenuItem alloc] initWithTitle:@"More Transparent" action:@selector(moreTransparentMainWindow) keyEquivalent:@""];
[moreTransparentItem setTarget:plugin];

s = [NSString stringWithFormat:@"T%C", 0x001e];
lessTransparentItem = [[NSMenuItem alloc] initWithTitle:@"Less Transparent" action:@selector(lessTransparentMainWindow) keyEquivalent:s];
lessTransparentItem = [[NSMenuItem alloc] initWithTitle:@"Less Transparent" action:@selector(lessTransparentMainWindow) keyEquivalent:@""];
[lessTransparentItem setTarget:plugin];

[transparencyItemSubMenu setItemArray:@[moreTransparentItem, lessTransparentItem]];

afloatXItems = [[NSArray alloc] initWithObjects:floatItem, dropItem, transparencyItem, nil];
afloatXItems = [[NSArray alloc] initWithObjects:floatItem,
dropItem,
transientItem,
transparencyItem,
nil];
[AfloatXSubmenu setItemArray:afloatXItems];

// If the application has a custom dock menu, we will add ourselves to that
Expand Down Expand Up @@ -175,6 +182,7 @@ @implementation AXApplication
- (CFArrayRef)_flattenMenu:(NSMenu *)arg1 flatList:(NSArray *)arg2 {
// Make any necessary changes to our menu before it is 'flattened'
NSWindow *window = [[AfloatX sharedInstance] windowToModify];

if([[AfloatX sharedInstance] isWindowTransient:window]) {
[transientItem setState:NSControlStateValueOn];
} else {
Expand All @@ -183,15 +191,15 @@ - (CFArrayRef)_flattenMenu:(NSMenu *)arg1 flatList:(NSArray *)arg2 {

if([window level] != NSNormalWindowLevel) {
if([window level] == kCGBackstopMenuLevel) {
afloatXItems = @[floatItem, resetItem, transientItem, transparencyItem];
[dropItem setState:NSControlStateValueOn];
} else if([window level] == NSFloatingWindowLevel) {
afloatXItems = @[resetItem, dropItem, transientItem, transparencyItem];
[floatItem setState:NSControlStateValueOn];
}
} else {
afloatXItems = @[floatItem, dropItem, transientItem, transparencyItem];
[dropItem setState:NSControlStateValueOff];
[floatItem setState:NSControlStateValueOff];
}

[AfloatXSubmenu setItemArray:afloatXItems];

return ZKOrig(CFArrayRef, arg1, arg2);
}
@end

0 comments on commit df0217b

Please sign in to comment.