Set windows size of QuickLook Plugin

跟風遠走 提交于 2019-12-03 15:13:22

Thought I'd dig a little on this. I have not tried any of the following suggestions, so nobody get their hopes up. I'll assume you're using the generator callback:

OSStatus (*GeneratePreviewForURL)(
    void *thisInterface,
    QLPreviewRequestRef preview,
    CFURLRef url,
    CFStringRef contentTypeUTI,
    CFDictionaryRef options
);

Before anything else, you might manually check the options dictionary argument and verify that the kQLPreviewPropertyWidthKey and kQLPreviewPropertyHeightKey keys are indeed mapped to the desired CFNumber values.

Referring to each of these properties, the Apple QuickLook programming guide says:

Note that this property is a hint; Quick Look might set the width automatically for some types of previews. The value must be encapsulated in a CFNumber object.

(Edit: If your preview representation is flexible, you might try finding a preview type for which QuickLook honors your size hints, as per the statement above. Just a thought.)

Running nm on the QuickLook framework binary revealed some undocumented kQLPreviewProperty-- constants as well as the aforementioned width and height keys. One that caught my attention was kQLPreviewPropertyAutoSizeKey. Recalling Apple's statement about ignoring the hints to set the size automatically, this might be significant? Following the convention in QuickLook.framework/Headers/QLBase.h, you might try declaring

extern const CFStringRef kQLPreviewPropertyAutoSizeKey;

Then you could try associating a CFNumber 0 with that property key in the options dictionary. There are other undocumented keys of note, such as kQLPreviewPropertyAttributesKey.

Back to the Info.plist you mentioned, Apple says about those keys QLPreviewWidth and QLPreviewHeight:

This number gives Quick Look a hint for the width (in points) of previews. It uses these values if the generator takes too long to produce the preview. (emphasis added)

This is where someone makes the terrible suggestion of calling sleep() in your generator. But I'm perplexed as to why Apple would make following the size hints dependent on the generator latency. (?)

Edit: Also note the above statement says the Info.plist hints must be expressed in points (not pixels), a unit dependent on the user's screen resolution.

Recently I was developing a Quick Look Plugin myself which uses HTML+CSS and faced the same problem. The solution for my was to test the plugin not within Xcode and qlmanage as the executable but instead to try the real .qlgenerator from my user library.

When invoking the generator from my user library, the Quick Look window was resized exactly the way I specified in the *-Info.plist.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!