Mac OS X Lion:检测另一个应用程序是否正在全屏模式下运行?

发布于 2024-11-30 10:16:24 字数 487 浏览 0 评论 0原文

在 Cocoa 应用程序中,有没有办法判断另一个应用程序当前是否处于全屏模式?

我的应用程序配置为显示在所有空间上,并侦听 mouseEntered 事件以将其自身排序到前面。

问题是,当另一个应用程序处于全屏模式并且用户碰巧将鼠标移过我的应用程序窗口所在的黑色区域时,它会被带到前面(在多个显示器上发生)。

我只在启用 [self setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces]; 的情况下看到了上述行为。

这是我的应用程序的其他相关代码。

- (void) mouseEntered:(NSEvent *)theEvent
{
    // Don't do this when another app is in full screen mode:
    [[self window] orderFront:self];
}

In a Cocoa app, is there a way to tell if another application currently is in full screen mode?

My application is configured to show up on all Spaces and listens for mouseEntered events to order itself to the front.

Problem is that when another app is in full screen mode and the user happens to move the mouse across the black area where my app's window is located, it is brought to the front (happens with multiple monitors).

I've only seen the above behavior with [self setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces]; enabled.

Here the other relevant code for my app.

- (void) mouseEntered:(NSEvent *)theEvent
{
    // Don't do this when another app is in full screen mode:
    [[self window] orderFront:self];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼眸印温柔 2024-12-07 10:16:24

上面提到的注册

“NSWindowWillEnterFullScreenNotification”

的方法不起作用,它们可以用来通知您自己的应用程序,使用它们我们无法检测任何其他应用程序是否处于全屏模式。

然而,在尝试了这么多选项之后,在 github 上找到了全屏检测器应用程序,这个有用的链接..:):)

https: //github.com/shinypb/FullScreenDetector.git

The above mentioned methods of registering for

"NSWindowWillEnterFullScreenNotification"

does not work, they can be used to notify your own app, using them we cannot detect whether any other application is in full screen mode or not.

However After trying out so many options found out FullScreen detector app at github this usefull link ..:):)

https://github.com/shinypb/FullScreenDetector.git

我是有多爱你 2024-12-07 10:16:24

经过一番挫败之后,这对我来说是有效的,让我获得了一个浮动在除全屏空间之外的所有空间上的窗口。我看到了 fullScreenNone 常量名称,因为它描述了我想要的内容,所以我尝试了一下,发现它有效。

    window.level = .floating
    window.collectionBehavior = [.canJoinAllSpaces, .fullScreenNone]
    window.canHide = false

After a great deal of frustration, this worked for me to get a window that floats on all spaces except full-screen ones. I saw the fullScreenNone constant name, and since it described what I wanted, I tried it and found that it worked.

    window.level = .floating
    window.collectionBehavior = [.canJoinAllSpaces, .fullScreenNone]
    window.canHide = false
老旧海报 2024-12-07 10:16:24

嗯,你排除使用 applescript/scriptingbridge 了吗?您可以从 applescript 获取窗口的大小,并将它们与屏幕的大小进行比较。 (或者您不知道给定应用程序位于哪个屏幕上?)
某些可访问的应用程序的窗口上将具有“AXFullScreen”属性。例如,这适用于某些应用程序:

  tell application "System Events"
    tell process "Pages"
        repeat with myWin in windows
            get value of attribute "AXFullScreen" of myWin
        end repeat
    end tell 
end tell

真正的操作似乎是在碳中......MacWindows.h和CarbonEvents.h在其中引用了“FullScreen”。

不过,您需要对此进行研究。

Hmm, have you ruled out using applescript/scriptingbridge? You can get the size of windows from applescript and compare them to the size of the screen. (or do you not know which screen a given app is on?)
Certain apps which are accessible will have an 'AXFullScreen' attribute on their windows. For example this works for some apps:

  tell application "System Events"
    tell process "Pages"
        repeat with myWin in windows
            get value of attribute "AXFullScreen" of myWin
        end repeat
    end tell 
end tell

The real action seems to be down in carbon... MacWindows.h and CarbonEvents.h have references to "FullScreen" in them.

You will need to research this though.

碍人泪离人颜 2024-12-07 10:16:24

使用通知。例如:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(willEnterFull:)
                                             name:NSWindowWillEnterFullScreenNotification
                                           object:nil];

实际上,您可能想使用 NSDistributedNotificationCenter 来代替,因为它跨进程。

您将对象添加为观察者,以便当其他对象发布它将进入全屏的通知时,您的对象将收到该通知。

选择器是您希望通知进程调用的消息/方法。

name 参数是通知的实际名称。这些都是标准的,除非您要为要使用的内容创建自定义通知。

object 参数用于指定您要从哪个对象接收通知。由于您想知道任何应用程序何时全屏显示,因此您需要将此值保留为零。

请记住在释放对象之前将其作为观察者删除!

Use notifications. For example:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(willEnterFull:)
                                             name:NSWindowWillEnterFullScreenNotification
                                           object:nil];

Actually, you'll probably want to use NSDistributedNotificationCenter instead, since it goes across processes.

You're adding your object as an observer, so that when something else posts a notification that it will enter full screen, your object will receive that notification.

The selector is the message/method you want called by the notification process.

The name parameter is the actual name of the notification. These are standard, unless you were to create a custom notification for something you would be using.

The object parameter is for specifying which object you want to receive notifications from. Since you want to know when ANY app is going full screen, you'd want to leave this nil.

Remember to remove your object as an observer before it's deallocated!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文