From 107fca2f457265b24feb56f48eeeb8b6542a9658 Mon Sep 17 00:00:00 2001 From: Dima Budaragin Date: Wed, 1 Apr 2020 17:07:56 -0700 Subject: [PATCH 1/3] feat: display aspect ratio --- .gitignore | 2 ++ ResMenuItem.h | 12 ++++--- ResMenuItem.mm | 58 +++++++++++++++++++++--------- SRApplicationDelegate.mm | 78 ++++++++++++++++++++-------------------- 4 files changed, 90 insertions(+), 60 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bea433 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/ResMenuItem.h b/ResMenuItem.h index 12db822..a55f798 100644 --- a/ResMenuItem.h +++ b/ResMenuItem.h @@ -10,16 +10,18 @@ static inline CFDictionaryRef CGDisplayModeGetDictionary(CGDisplayModeRef mode) @interface ResMenuItem : NSMenuItem { CGDirectDisplayID _display; - + int modeNum; - + //CGDisplayModeRef _mode; - + float refreshRate; float scale; int colorDepth; int width; int height; + int _w; + int _h; } @@ -40,7 +42,9 @@ static inline CFDictionaryRef CGDisplayModeGetDictionary(CGDisplayModeRef mode) - (int) height; - (float) refreshRate; - (float) scale; +- (int) _w; +- (int) _h; - (NSComparisonResult) compareResMenuItem: (ResMenuItem*) otherItem; -@end \ No newline at end of file +@end diff --git a/ResMenuItem.mm b/ResMenuItem.mm index 38932dc..8aa3054 100644 --- a/ResMenuItem.mm +++ b/ResMenuItem.mm @@ -18,40 +18,54 @@ - (id) initWithDisplay: (CGDirectDisplayID) display andMode: (modes_D4*) mode modeNum = mode->derived.mode; scale = mode->derived.density; - + width = mode->derived.width; height = mode->derived.height; - + refreshRate = mode->derived.freq; - + colorDepth = (mode->derived.depth == 4) ? 32 : 16; - - + + int a = width; + int b = height; + int t; + while (b != 0) { + t = b; + b = a % b; + a = t; + } + _w = width / a; + _h = height / a; + if (_h == 5) { + _w *= 2; + _h *= 2; + } + NSString* title; if(scale == 2.0f) { if(refreshRate) { - title = [NSString stringWithFormat: @"%d × %d ⚡️, %.0f Hz", width, height, refreshRate]; + title = [NSString stringWithFormat: @"⚡️ %d × %d — %d:%d, %.0f Hz", width, height, _w, _h, refreshRate]; } else { - title = [NSString stringWithFormat: @"%d × %d ⚡️", width, height]; + title = [NSString stringWithFormat: @"⚡️ %d × %d — %d:%d", width, height, _w, _h]; } } else { if(refreshRate) { - title = [NSString stringWithFormat: @"%d × %d, %.0f Hz", width, height, refreshRate]; + title = [NSString stringWithFormat: @"%d × %d — %d:%d, %.0f Hz", width, height, _w, _h, refreshRate]; } else { - title = [NSString stringWithFormat: @"%d × %d", width, height]; + title = [NSString stringWithFormat: @"%d × %d — %d:%d", width, height, _w, _h]; } } [self setTitle: title]; - + return self; } else @@ -67,23 +81,23 @@ - (void) setTextFormat: (int) textFormat { if(scale == 2.0f) { - title = [NSString stringWithFormat: @"%d × %d ⚡", width, height]; + title = [NSString stringWithFormat: @"⚡ %d × %d — %d:%d", width, height, _w, _h]; } else { - title = [NSString stringWithFormat: @"%d × %d", width, height]; + title = [NSString stringWithFormat: @"%d × %d — %d:%d", width, height, _w, _h]; } } - + if(textFormat == 2) { title = [NSString stringWithFormat: @"%.0f Hz", refreshRate]; } if(title) [self setTitle: title]; - - - + + + } - (CGDirectDisplayID) display @@ -111,6 +125,16 @@ - (int) height return height; } +- (int) _w +{ + return _w; +} + +- (int) _h +{ + return _h; +} + - (float) refreshRate { return refreshRate; @@ -159,4 +183,4 @@ - (NSComparisonResult) compareResMenuItem: (ResMenuItem*) otherItem } -@end \ No newline at end of file +@end diff --git a/SRApplicationDelegate.mm b/SRApplicationDelegate.mm index 7226fb4..1bf4d2e 100644 --- a/SRApplicationDelegate.mm +++ b/SRApplicationDelegate.mm @@ -33,13 +33,13 @@ - (void) refreshStatusMenu { if(statusMenu) [statusMenu release]; - + statusMenu = [[NSMenu alloc] initWithTitle: @""]; - + uint32_t nDisplays; CGDirectDisplayID displays[0x10]; CGGetOnlineDisplayList(0x10, displays, &nDisplays); - + for(int i=0; i 1) { [freq setSubmenu: submenu]; @@ -201,21 +201,21 @@ - (void) refreshStatusMenu [freq release]; } [submenu release]; - + [displayMenuItems release]; - + } - - + + free(modes); - - + + [statusMenu addItem: [NSMenuItem separatorItem]]; } - + [statusMenu addItemWithTitle: @"About RDM" action: @selector(showAbout) keyEquivalent: @""]; - - + + [statusMenu addItemWithTitle: @"Quit" action: @selector(quit) keyEquivalent: @""]; [statusMenu setDelegate: self]; [statusItem setMenu: statusMenu]; @@ -226,10 +226,10 @@ - (void) setMode: (ResMenuItem*) item { CGDirectDisplayID display = [item display]; int modeNum = [item modeNum]; - + SetDisplayModeNum(display, modeNum); /* - + CGDisplayConfigRef config; if (CGBeginDisplayConfiguration(&config) == kCGErrorSuccess) { CGConfigureDisplayWithDisplayMode(config, display, mode, NULL); @@ -242,7 +242,7 @@ - (void) applicationDidFinishLaunching: (NSNotification*) notification { // NSLog(@"Finished launching"); statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength: NSSquareStatusItemLength] retain]; - + NSImage* statusImage = [NSImage imageNamed: @"StatusIcon"]; [statusItem setImage: statusImage]; [statusItem setHighlightMode: YES]; @@ -253,7 +253,7 @@ - (void) applicationDidFinishLaunching: (NSNotification*) notification } [self refreshStatusMenu]; - + } @end From aba3fe1e8543fb6b64deb1d970f99044ac8a37b3 Mon Sep 17 00:00:00 2001 From: Dima Budaragin Date: Tue, 29 Dec 2020 22:49:32 -0800 Subject: [PATCH 2/3] feat(ui): show aspect ratios in submenu --- .gitignore | 4 +++- ResMenuItem.h | 1 + ResMenuItem.mm | 42 ++++++++++++++++++++++++++-------------- SRApplicationDelegate.mm | 34 ++++++++++---------------------- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 9bea433..46ed1ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ - +*.o +RDM.app +SetResX .DS_Store diff --git a/ResMenuItem.h b/ResMenuItem.h index a55f798..0576871 100644 --- a/ResMenuItem.h +++ b/ResMenuItem.h @@ -44,6 +44,7 @@ static inline CFDictionaryRef CGDisplayModeGetDictionary(CGDisplayModeRef mode) - (float) scale; - (int) _w; - (int) _h; +- (float) aspect; - (NSComparisonResult) compareResMenuItem: (ResMenuItem*) otherItem; diff --git a/ResMenuItem.mm b/ResMenuItem.mm index 8aa3054..0ee85ab 100644 --- a/ResMenuItem.mm +++ b/ResMenuItem.mm @@ -46,22 +46,22 @@ - (id) initWithDisplay: (CGDirectDisplayID) display andMode: (modes_D4*) mode { if(refreshRate) { - title = [NSString stringWithFormat: @"⚡️ %d × %d — %d:%d, %.0f Hz", width, height, _w, _h, refreshRate]; + title = [NSString stringWithFormat: @"%d × %d, %.0f Hz ⚡️", width, height, refreshRate]; } else { - title = [NSString stringWithFormat: @"⚡️ %d × %d — %d:%d", width, height, _w, _h]; + title = [NSString stringWithFormat: @"%d × %d ⚡️", width, height]; } } else { if(refreshRate) { - title = [NSString stringWithFormat: @"%d × %d — %d:%d, %.0f Hz", width, height, _w, _h, refreshRate]; + title = [NSString stringWithFormat: @"%d × %d, %.0f Hz", width, height, refreshRate]; } else { - title = [NSString stringWithFormat: @"%d × %d — %d:%d", width, height, _w, _h]; + title = [NSString stringWithFormat: @"%d × %d", width, height]; } } [self setTitle: title]; @@ -81,11 +81,11 @@ - (void) setTextFormat: (int) textFormat { if(scale == 2.0f) { - title = [NSString stringWithFormat: @"⚡ %d × %d — %d:%d", width, height, _w, _h]; + title = [NSString stringWithFormat: @"%d × %d ⚡", width, height]; } else { - title = [NSString stringWithFormat: @"%d × %d — %d:%d", width, height, _w, _h]; + title = [NSString stringWithFormat: @"%d × %d", width, height]; } } @@ -145,8 +145,30 @@ - (float) scale return scale; } +- (float) aspect +{ + return float(_w) / _h; +} + - (NSComparisonResult) compareResMenuItem: (ResMenuItem*) otherItem { + { + float aspect = [self aspect]; + float o_aspect = [otherItem aspect]; + if (aspect < o_aspect) + return NSOrderedAscending; + else if (aspect > o_aspect) + return NSOrderedDescending; +// return NSOrderedSame; + } + { + int o_height = [otherItem height]; + if(height < o_height) + return NSOrderedDescending; + else if(height > o_height) + return NSOrderedAscending; +// return NSOrderedSame; + } { int o_width = [otherItem width]; if(width < o_width) @@ -161,14 +183,6 @@ - (NSComparisonResult) compareResMenuItem: (ResMenuItem*) otherItem return NSOrderedDescending; else if(scale > o_scale) return NSOrderedAscending; -// return NSOrderedSame; - } - { - int o_height = [otherItem height]; - if(height < o_height) - return NSOrderedDescending; - else if(height > o_height) - return NSOrderedAscending; // return NSOrderedSame; } { diff --git a/SRApplicationDelegate.mm b/SRApplicationDelegate.mm index 1bf4d2e..b522a70 100644 --- a/SRApplicationDelegate.mm +++ b/SRApplicationDelegate.mm @@ -97,31 +97,17 @@ - (void) refreshStatusMenu ResMenuItem* item = [displayMenuItems objectAtIndex: j]; if([item colorDepth] == idealColorDepth) { - if([item refreshRate] == idealRefreshRate) + if (!lastAddedItem || [lastAddedItem _w] != [item _w] || [lastAddedItem _h] != [item _h]) { - [item setTextFormat: 1]; + NSMenuItem* aspect; + NSString* title = [NSString stringWithFormat: @"%d:%d", [item _w], [item _h]]; + aspect = [[NSMenuItem alloc] initWithTitle: title action: nil keyEquivalent: @""]; + [aspect setEnabled: NO]; + [submenu addItem: aspect]; } - if(lastAddedItem && [lastAddedItem width]==[item width] && [lastAddedItem height]==[item height] && [lastAddedItem scale]==[item scale]) - { - double lastRefreshRate = lastAddedItem ? [lastAddedItem refreshRate] : 0; - double refreshRate = [item refreshRate]; - if(!lastAddedItem || (lastRefreshRate != idealRefreshRate && (refreshRate == idealRefreshRate || refreshRate > lastRefreshRate))) - { - if(lastAddedItem) - { - [submenu removeItem: lastAddedItem]; - lastAddedItem = nil; - } - [submenu addItem: item]; - lastAddedItem = item; - } - } - else - { - [submenu addItem: item]; - lastAddedItem = item; - } + [submenu addItem: item]; + lastAddedItem = item; } } @@ -129,11 +115,11 @@ - (void) refreshStatusMenu { if([mainItem scale] == 2.0f) { - title = [NSString stringWithFormat: @"⚡️ %d × %d — %d:%d", [mainItem width], [mainItem height], [mainItem _w], [mainItem _h]]; + title = [NSString stringWithFormat: @"⚡️ %d:%d — %d × %d", [mainItem _w], [mainItem _h], [mainItem width], [mainItem height]]; } else { - title = [NSString stringWithFormat: @"%d × %d — %d:%d", [mainItem width], [mainItem height], [mainItem _w], [mainItem _h]]; + title = [NSString stringWithFormat: @"%d:%d — %d × %d", [mainItem _w], [mainItem _h], [mainItem width], [mainItem height]]; } } From b7cc119580174358a27f17ba3623b0767290a733 Mon Sep 17 00:00:00 2001 From: Dima Budaragin Date: Fri, 5 Feb 2021 18:17:12 +0000 Subject: [PATCH 3/3] only show highest frequency for every resolution --- SRApplicationDelegate.mm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SRApplicationDelegate.mm b/SRApplicationDelegate.mm index b522a70..29a5635 100644 --- a/SRApplicationDelegate.mm +++ b/SRApplicationDelegate.mm @@ -106,7 +106,9 @@ - (void) refreshStatusMenu [submenu addItem: aspect]; } - [submenu addItem: item]; + if (!lastAddedItem || [lastAddedItem width] != [item width] || [lastAddedItem height] != [item height]) { + [submenu addItem: item]; + } lastAddedItem = item; } }