Skip to content
This repository was archived by the owner on Dec 17, 2023. It is now read-only.
Open
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 .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.o
RDM.app
SetResX
.DS_Store
13 changes: 9 additions & 4 deletions ResMenuItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -40,7 +42,10 @@ static inline CFDictionaryRef CGDisplayModeGetDictionary(CGDisplayModeRef mode)
- (int) height;
- (float) refreshRate;
- (float) scale;
- (int) _w;
- (int) _h;
- (float) aspect;

- (NSComparisonResult) compareResMenuItem: (ResMenuItem*) otherItem;

@end
@end
78 changes: 58 additions & 20 deletions ResMenuItem.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,35 @@ - (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, %.0f Hz ⚡️", width, height, refreshRate];
}
else
{
Expand All @@ -51,7 +65,7 @@ - (id) initWithDisplay: (CGDirectDisplayID) display andMode: (modes_D4*) mode
}
}
[self setTitle: title];

return self;
}
else
Expand All @@ -74,16 +88,16 @@ - (void) setTextFormat: (int) textFormat
title = [NSString stringWithFormat: @"%d × %d", width, height];
}
}

if(textFormat == 2)
{
title = [NSString stringWithFormat: @"%.0f Hz", refreshRate];
}
if(title)
[self setTitle: title];



}

- (CGDirectDisplayID) display
Expand Down Expand Up @@ -111,6 +125,16 @@ - (int) height
return height;
}

- (int) _w
{
return _w;
}

- (int) _h
{
return _h;
}

- (float) refreshRate
{
return refreshRate;
Expand All @@ -121,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)
Expand All @@ -137,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;
}
{
Expand All @@ -159,4 +197,4 @@ - (NSComparisonResult) compareResMenuItem: (ResMenuItem*) otherItem

}

@end
@end
Loading