Emacs 获取到的屏幕分辨率不太对?

前两天编译的 emacs-29,发现用 (display-monitor-attributes-list) 拿到的屏幕尺寸似乎对不上,得到的是 1440x900,但是屏幕是 2560x1600,求教大家,难道是我误解了这个函数?

---- UPDATE ----

// Saved as a.m
// Compile and run with `clang -framework AppKit a.m && ./a.out`
#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[])
{
    NSArray *screens = [NSScreen screens];
    NSScreen *s = [screens objectAtIndex:0];
    NSRect fr = [s frame];
    int w = fr.size.width;
    int h = fr.size.height;
    printf("%d x %d\n", w, h);

    // from https://stackoverflow.com/a/12589799/3046402
    NSDictionary *description = [s deviceDescription];
    NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
    CGSize displayPhysicalSize = CGDisplayScreenSize(
                   [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);

    w = displayPixelSize.width;
    h = displayPixelSize.height;
    printf("%d x %d\n", w, h);

    w = displayPhysicalSize.width;
    h = displayPhysicalSize.height;
    printf("%d x %d\n", w, h);

    // https://stackoverflow.com/a/59899904/3046402
    auto mainDisplayId = CGMainDisplayID();
    w = CGDisplayPixelsWide(mainDisplayId);
    h = CGDisplayPixelsHigh(mainDisplayId);
    printf("%d x %d\n", w, h);

    return 0;
}

运行得到的结果是:

1440 x 900
1440 x 900
285 x 179
1440 x 900

我一定是忽略了什么 :joy:

我也得到了这个结果:

(cl-prettyprint (display-monitor-attributes-list))
(((geometry 0 0 1440 900)
  (workarea 0 25 1440 799)
  (mm-size 286 179)
  (frames #<frame *scratch* – Doom Emacs 0x108464430>)
  (source . "NS")))
(cl-prettyprint (emacs-version))
=>
"GNU Emacs 28.0.90 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00 Version 12.0.1 (Build 21A559))"
1 个赞

物理分辨率和逻辑分辨率是不一样的,试着将preferences->displays里面的scale改一下,就会发现这个数字是与scale有关的

有道理,在 display 里面可以手动设置分辨率,可能是和这个有关。

另外我发现 (display-pixel-width)(display-pixel-width) 拿到的数字和 (display-monitor-attributes-list) 也是不一样的。

这是比较严重的问题,建议不要在论坛上求助,而直接 report-emacs-bug。

获取的是逻辑分辨率,不是物理分辨率。macOS上字体都是有缩放的,尤其是高清显示屏上。