检测 Mac OS X 中的空间中的空间何时发生变化
假设我想编写一个简单的 Cocoa 应用程序来使 Leopard 的 Spaces 功能更加有用。我想将每个空间配置为具有不同的
- 屏幕分辨率
- 键盘布局
- 音量(用于音频)
所以我的问题有两个部分:
- 我想有办法独立于空间来修改这三件事,对吧?如果是这样,怎么办?
- 如何在我的应用程序中检测何时发生空间更改,并在发生这种情况时确定用户刚刚切换到哪个空间? Leopard 会发出一些分布式通知之类的吗?
更新:从 Mac App Store 上所有与 Spaces 相关的应用程序来看,必须有一些公共 API 方法来执行此操作。
Let's say I want to write a simple Cocoa app to make the Spaces feature of Leopard more useful. I would like to configure each space to have, say, different
- screen resolutions
- keyboard layouts
- volume (for audio)
So there are two parts to my question:
- I suppose there are ways to modify these three things independently of Spaces, right? If so, how?
- How can I detect in my app when a space change occurs, and when that happens, determine what space the user just switched to? Does Leopard send out some distributed notifications or something?
Update: There has to be some public API way of doing this, judging from all the Spaces-related apps on the Mac App Store.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Peter 所说,在 10.6 中,您可以使用
NSWorkSpace
NSWorkspaceActiveSpaceDidChangeNotification
在工作区更改时获取通知。然后,您可以使用 Quartz API 确定当前空间,
kCGWindowWorkspace
字典键保存工作空间。例如:
您也可以使用私有 API 获取空间,请查看 CGPSrivate.h 它允许您执行此操作:
要更改屏幕分辨率,您需要查看 Quartz 服务,用于更改音量这可能有帮助。
As Peter says, in 10.6 you can use the
NSWorkSpace
NSWorkspaceActiveSpaceDidChangeNotification
to get a notification when the workspace changes.You can then determine the current space using Quartz API, the
kCGWindowWorkspace
dictionary key holds the workspace.e.g:
Alternatively you can get the Space using the private API, take a look at CGSPrivate.h which allows you to do this:
To change the screen resolution you'll want to look at Quartz services, for altering the volume this may be helpful.
NSWorkspace 在其自己的通知中心发布
NSWorkspaceActiveSpaceDidChangeNotification
,但仅限于 Snow Leopard。NSWorkspace posts a
NSWorkspaceActiveSpaceDidChangeNotification
on its own notification center, but only on Snow Leopard.