objective-c – 设置非所有窗口总是在顶部 – 像应用程序“Afloat”

前端之家收集整理的这篇文章主要介绍了objective-c – 设置非所有窗口总是在顶部 – 像应用程序“Afloat”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经用RegisterEventHotkey设置了全局热键.当用户按下它时,它会获得当前关注的窗口,其中包含CGWindowListCopyWindowInfo,然后我需要将其设置在顶部.

如果当前窗口在我的进程中(我正在执行代码),我可以将windowNumber从CGWindowListCopyWindowInfo转换为NSWindow并执行setLevel:

nswin = [NSApp windowWithWindowNumber:windowNumber]
[nswin setLevel: Int(CGWindowLevelForKey(kCGFloatingWindowLevelKey))]

我的问题如果当前关注的窗口不在我的过程中,我无法做到这一点.你能告诉我怎么样

我试过的东西

>这个名为“Afloat”的应用程序使用“SIMBL”完成此操作.从任何窗口,你可以打Cmd A,它将永远在顶部.但是,我正在尝试使用C / ObjC从我的普通桌面应用程序,而不使用像SIMBL之类的帮助者.

来源:Force keeping app window on top – Mac OS X
> SIMBL:http://www.culater.net/software/SIMBL/SIMBL.php
> Afloat:https://www.macupdate.com/app/mac/22237/afloat

>我在CGPrivate.h中遇到了CGSSetWindowLe – 未记录的东西 – https://gist.github.com/Noitidart/3664c5c2059c9aa6779f#file-cgsprivate-h-L63 – 但是我记得我过去尝试过这样的东西,但是当我尝试连接到不在调用进程中的窗口时会收到错误.

它在这里说 – https://github.com/lipidity/CLIMac/blob/114dfee39d24809f62ccb000ea22dfda15c11ce8/src/CGS/CGSInternal/.svn/text-base/CGSConnection.h.svn-base#L82

Only the owner of a window can manipulate it. So,Apple has the concept of a universal owner that owns all windows and can manipulate them all. There can only be one universal owner at a time (the Dock).

>也许,有没有假装我的通话过程暂时成为码头?可能CGSGetConnectionIDForPSN为Dock,然后使用该连接?

我的用途:我试图复制我的开源,免费,浏览器插件https://addons.mozilla.org/en-US/firefox/addon/topick/功能,所以我的呼叫过程如果Firefox.它现在在Windows和Linux上工作,只需要找出如何在mac中为非Firefox窗口.

解决方法

this answer中所述,如果您使用orderFront或orderFrontRegard而不是setLevel,它将工作.

并且在this的答案中解释了setLevel和orderFront的区别.

For another,orderFront:,makeKeyAndOrderFront:,and setLevel: do
work. In particular,setLevel: puts the window on an entire other
plane,so it will always be in front of (or behind,depending on the
level you choose) windows with the default level,no matter what you
do.

正如你已经可以关注的那个窗口,这应该是你失踪的步骤.
希望这可以帮助.

要控制其他进程的窗口,您可以使用Apple脚本,并使用像ASTranslate这样的工具将其转换为客观的c代码.

例:

tell application "System Events"
 set theprocess to the first process whose frontmost is true
 set thewindow to the value of attribute "AXFocusedWindow" of theprocess
end tell

为了保持最高的使用AXRaise,或者如果要更改可见性,则说明here

原文链接:https://www.f2er.com/c/115894.html

猜你在找的C&C++相关文章