检测Mac OS X中的空间何时更改空间 [英] Detecting when a space changes in Spaces in Mac OS X

查看:109
本文介绍了检测Mac OS X中的空间何时更改空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想写一个简单的Cocoa应用程序,使Leopard的Spaces功能更有用。我想配置每个空间有不同的

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


  • 屏幕分辨率

  • 键盘布局

  • 音量(音频)

所以对我的问题有两个部分: p>

So there are two parts to my question:


  1. 我想有办法独立于Spaces修改这三个东西,对吗?如果是,如何?

  2. 当空间发生变化时,如何在我的应用程序中检测到,当发生时,确定用户刚切换到什么空间? Leopard是否发出了一些分布式通知或某事?

更新:必须有一些公共API方式,

Update: There has to be some public API way of doing this, judging from all the Spaces-related apps on the Mac App Store.

推荐答案

如同Peter所说,在10.6版本中,您可以使用 NSWorkSpace NSWorkspaceActiveSpaceDidChangeNotification 在工作区更改时获取通知。

As Peter says, in 10.6 you can use the NSWorkSpace NSWorkspaceActiveSpaceDidChangeNotification to get a notification when the workspace changes.

然后,您可以使用Quartz API确定当前空间, kCGWindowWorkspace 字典键保存工作区。
例如:

You can then determine the current space using Quartz API, the kCGWindowWorkspace dictionary key holds the workspace. e.g:

int currentSpace;
// get an array of all the windows in the current Space
CFArrayRef windowsInSpace = CGWindowListCopyWindowInfo(kCGWindowListOptionAll | kCGWindowListOptionOnScreenOnly, kCGNullWindowID);      

// now loop over the array looking for a window with the kCGWindowWorkspace key
for (NSMutableDictionary *thisWindow in (NSArray *)windowsInSpace)
{
     if ([thisWindow objectForKey:(id)kCGWindowWorkspace])
       {
           currentSpace = [thisWindow objectForKey(id)kCGWindowWorkspace] intValue];
           break;
       }
}

也可以使用私有API获取Space,请查看 CGSPrivate.h ,您可以执行此操作:

Alternatively you can get the Space using the private API, take a look at CGSPrivate.h which allows you to do this:

int currentSpace = 0;
CGSGetWorkspace(_CGSDefaultConnection(), &currentSpace);

要更改屏幕分辨率,您需要查看 Quartz服务,以更改音量这可能是有帮助的

To change the screen resolution you'll want to look at Quartz services, for altering the volume this may be helpful.

这篇关于检测Mac OS X中的空间何时更改空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆