When developing pocketed macOS version of the input method,I encountered such a problem,That is the window priority issues。Before How to make NSWindow displayed in a different Space or the Screen This article I referred to himself realizes candidate field pocketed input method,In fact, with a NSWindow Implementation。So since it is a common (through the magic change) of Window ,Like it and other windows have a priority,That is window.level It determines the relationship between the laminated window displayed on your Desktop,in short,That is, if two windows overlap,High priority will show it to you,The low priority were "blocked" in the back。
Then the question came,This one level How much does this set? Swift is now not show the actual value,Specifically the following statement:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
extension NSWindow.Level { public static let normal: NSWindow.Level public static let floating: NSWindow.Level public static let submenu: NSWindow.Level public static let tornOffMenu: NSWindow.Level public static let mainMenu: NSWindow.Level public static let statusBar: NSWindow.Level @available(OSX, introduced: 10.0, deprecated: 10.13) public static let dock: NSWindow.Level public static let modalPanel: NSWindow.Level public static let popUpMenu: NSWindow.Level public static let screenSaver: NSWindow.Level } |
Then we can guess the name - of course proved screenSaver It is the most advanced,That is, screensavers level,This allows the candidate has been displayed in the input field such as roads above the Spotlight。
but,there is a question,If the user is playing a full screen game?
This time the game is that this may also be used screenSaver level,Then you just GG,We must seek a higher level,For example, this is 1000 if,Then we come to a 99999999 Not Miaozai?
of course,This can not be normal window priority in acquiring the,We use this API:
1 2 3 4 5 |
/* Returns the window level of the shield window for the captured display `display'. */ @available(OSX 10.0, *) public func CGShieldingWindowLevel() -> CGWindowLevel |
Such candidates in respect of all the windows are always in the top of the。
So is this specific implementation:
1 |
window.level = NSWindow.Level(rawValue: NSWindow.Level.RawValue(CGShieldingWindowLevel())) |
Original article written by LogStudio:R0uter's Blog » Avoid input candidate article hidden behind other windows
Reproduced Please keep the source and description link:https://www.logcg.com/archives/2854.html
Search ga! No wonder so quickly fix it ~
Although only one line of code,But behind the effort may be more than one minute to