CGDisplayCopyAllDisplayModes排除了一种有效模式 [英] CGDisplayCopyAllDisplayModes leaves out one valid mode

查看:228
本文介绍了CGDisplayCopyAllDisplayModes排除了一种有效模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OS X中以编程方式使用显示模式时(文档),我发现CGDisplayCopyAllDisplayModes遗漏了系统偏好设置"中显示的最右边的选项.

When programmatically working with display modes in OS X (documentation), I've found that the CGDisplayCopyAllDisplayModes leaves out the rightmost option that is presented in System Preferences.

一个简单实用程序,可打印当前显示模式的大小以及所有可用的显示方式显示模式尺寸输出

A simple utility that prints the size of the current display mode and all available display mode sizes outputs this

current size: 1920x1200
available sizes:
2880x1800
1440x900
2560x1600
2048x1280
1024x768
800x600
640x480
1680x1050
1280x800

1920x1200是有效选项

系统偏好设置"提供的所有其他选项都在列表中表示.有谁知道为什么可能不包含1920x1200?我曾尝试将其更改为系统首选项中的另一个预定义值,但这并未导致包含1920x1200.

All of the other options that System Preferences gives are represented in the list. Does anyone have any idea why 1920x1200 may not be included? I have tried changing to another one of the pre-defined values in system prefs, but it did not cause 1920x1200 to be included.

按比例缩放"可以通过引用私有API找到显示模式.

The "scaled" display modes can be found by referencing a private API.

您可以创建一个使私有方法可用的头文件:请参见此要点此项目借来的.

You can create a header file that makes the private methods available: see this gist that I borrowed from this project.

然后您可以看到所有模式,包括像这样的缩放模式

Then you can see all modes, including the scaled ones like this

print("Private modes:\n")

var numDisplayModes: Int32 = 0
CGSGetNumberOfDisplayModes(mainDisplayID, &numDisplayModes)
print("Num modes \(numDisplayModes)")

for i in 0...(numDisplayModes-1) {
    var pmode: CGPrivDisplayMode = CGPrivDisplayMode()
    CGSGetDisplayModeDescriptionOfLength(mainDisplayID, CInt(i), &pmode, CInt(sizeof(CGPrivDisplayMode)))
    
    print("\t\(pmode.modeNumber): \(pmode.width)x\(pmode.height) -- \(pmode.density)  \n")
}

推荐答案

仅在标头中记录了公共API. CGDisplayCopyAllDisplayModes()带有options参数,该参数是字典.文档(甚至标题)都说它尚未使用,您必须传递NULL,但是您可以传递包含键kCGDisplayShowDuplicateLowResolutionModes和值kCFBooleanTrue的字典.

There's public API that's only documented in the header. CGDisplayCopyAllDisplayModes() takes an options parameter, which is a dictionary. The docs (and even the headers) say that it's unused and you must pass NULL, but you can pass a dictionary with the key kCGDisplayShowDuplicateLowResolutionModes and value kCFBooleanTrue.

选项名称不清楚.它包括许多额外的模式.

The option name is not really clear. It includes a bunch of extra modes.

此外,您可能需要使用CGDisplayModeGetPixelWidth()CGDisplayModeGetPixelHeight()来区分后备存储的点大小和像素大小. (CGDisplayModeGetWidth()CGDisplayModeGetHeight()返回点大小.通过比较这些值,可以确定模式是否已缩放.)

Also, you may need to use CGDisplayModeGetPixelWidth() and CGDisplayModeGetPixelHeight() to distinguish between the point size and the pixel size of the backing store. (CGDisplayModeGetWidth() and CGDisplayModeGetHeight() return point size. By comparing those values, you can determine if the mode is scaled.)

这篇关于CGDisplayCopyAllDisplayModes排除了一种有效模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆