Categories
Mac OS Swift

How to make NSWindow displayed in a different Space or the Screen

Among write off the grid input method the Mac version of the process,I encountered such a problem,Article candidate system API disrepair,Many API functions exists but is essentially useless,such as:

This method is used to set the style of a candidate bar,In addition to the default inside IMKCandidatesSendServerKeyEventFirst This can take effect outside,The other not ignore。

This awkward,Now pingming frequently high 4k to retina or,The default number of 16 candidates font looks also not blind the eyes。

So,Finally, I still have to achieve their own candidate for this article,How to say after layout,But here there is a very interesting point can talk about,That is how to make this NSWindow The user can input points to go along with,Instead of being "trapped" in the first screen。

First of all,I like this design

With a NSWindow Add to renovate,Then as a candidate bar,Call it makeKeyAndOrderFront To show,Then close To close,Then I encountered the first problem:transfer close Rear,This window has been released! Cause program execution to force the null pointer,Although Swift I like this statement where candidatesWindow:CandidateController

So,I began to think of the older generation learned valuable lessons in the OC,use self.ALPHAVALUE To get this thing。

transparency

after all,Transparent is equivalent to a hidden,Can not interact,After I rewrote a series of methods,It looks good job。but,Users will soon have reported problems,He said candidate bar sometimes missing,That can type but no candidate bar ...... I thought it was inserted into the coordinates of the cursor to get the error ...... eventually, after I accidentally switched Space to reproduce the problem,The original candidate bar and no deviation,Except that it is displayed in another screen space。

So I started looking for how to NSWindow Move to approach the target screen - in fact, after a lot of,Unfortunately really is not moving NSWindow Space the way to the target - which embarrassed。

Then after 3 hours,I gave up this road,Back to square one。

NSWindowController

Now back to square one,So I started the design concept is actually quite correct,So contradiction is how to let this window is not automatically released。Unfortunately, the Internet to find a circle,We are actually asking how to make the right release window - Well,I think it's very own release positive ........................

In short,This time I thought of this Controller,After all, it does not own their own to release - so the question is,If I close The NSWindowController ,It will be released it?

--fortunately,It should be clear that,will not。So,I changed to use NSWindowController ,Then during initialization to initialize the window。So when I need to show the candidate field,I can do it:

When I need to close when,To do so:

Such,On the whole window manager NSWindowController Automatic arrangements,Then the focus here:

Because each window is no longer simply moving position and modify the transparency,Window appears and disappears is a real addition and removal,This naturally support the display screen in any position,This time,Candidate bar can support multi-screen、A multi-Space。

Original article written by Gerber drop-off:R0uter's Blog » How to make NSWindow displayed in a different Space or the Screen

Reproduced Please keep the source and description link:https://www.logcg.com/archives/2769.html

By R0uter's Blog

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

1 reply on “How to make NSWindow displayed in a different Space or the Screen”

Leave a Reply

Your email address will not be published. Required fields are marked *