确定WindowServer是否可用? [英] Determine if WindowServer is available?

查看:141
本文介绍了确定WindowServer是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为OS X编写一个框架,可以在有或没有连接到OS X WindowServer的应用程序(即GUI应用和命令行应用都通过例如ssh会话运行)上使用。框架中的一个类是用于在网络作业和移动主目录中跟踪用户主文件夹中的文件(在OS X上,用户可以通过AFP通过服务器(网络主目录)来提供其主目录,相同的归属文件夹,用于离线访问 - 移动主目录)。



因为我需要跨文件系统跟踪文件,我们选择使用相对路径,而不是OS X别名(或10.6 NSURL 书签)。当无法找到文件时,我需要请求用户重新定位该文件的输入(像Alias管理器提示用户重新连接损坏的别名)。如果应用程序具有(或可以建立)到WindowServer的连接,这就像使用 NSOpenPanel 一样简单。但是,当应用程序无法连接到WindowServer时,我需要使用另一种方法来获取用户输入。



那么,我怎么知道在家庭作业代码中使用哪种方法呢?是否有一种方法来程序化地确定一个WindowServer连接是否可用(或可能)?



我认识到一个替代架构,其中框架客户端提供一个回调机制用户将让调用应用程序提供输入收集策略。我想让调用应用程序尽可能简单,但是,我的第一个选择是将这些细节封装在框架中,如果我可以。

解决方案

有一个名为 SECURITYSESSIONID 的环境变量,由loginwindow.app设置,get被传递给用户的应用程序。如果您通过ssh登录,则不设置该变量。



问题:这个变量的存在并不意味着这个用户当前正在控制窗口管理器

在ApplicationServices框架中有一个名为 CGSessionCopyCurrentDictionary 的函数:


返回值:窗口服务器会话字典,如果调用者未在Quartz GUI会话或窗口服务器中运行,则为NULL被禁用。完成使用后应该释放字典。有关此字典中键值对的信息,请参阅Window Server会话属性。



I'm writing a framework for OS X that may be used by applications with or without a connection to the OS X WindowServer (i.e. both GUI apps and command-line apps run via, e.g. an ssh session). One class in the framework is for tracking files in the user's home folder across netework and mobile home directories (on OS X, users can have their home directory served via AFP from a server--a "network home directory"--or have the same home folder syncrhonized for offline access--a "mobile home directory").

Because I need to track files across filesystems, we've chosen to use relative paths, rather than OS X aliases (or the 10.6 NSURL bookmarks). When a file can't be found, I need to ask the user for input to relocate that file (like how the Alias Manager prompts the user to reconnect a broken alias). If the application has (or can make) a connection to the WindowServer, this is as simple as using an NSOpenPanel. However, when the app can't make a connection to the WindowServer I need to use an alternative method to get the user input.

So, how can I tell which method to use from within the famework code? Is there a way to programatically determine if a WindowServer connection is available (or possible)?

I recognize that an alternative architecture, where the framework client provides a callback mechanism to prompt the user would let the input-gathering strategy be provided by the calling application. I'd like to make things as simple as possible for the calling application, however, so my first choice would be to encapsulate these details in the framework if I can.

解决方案

There's an environment variable named SECURITYSESSIONID that is set by loginwindow.app and get's passed to the user's applications. The variable is not set if you login via ssh. It serves as kind of a handle to talk to the window server.

Problem: The existence of this variable does not mean that this user currently controls the window manager (think fast user switching).

There's a function called CGSessionCopyCurrentDictionary in the ApplicationServices framework which looks promising:

Return Value: A window server session dictionary, or NULL if the caller is not running within a Quartz GUI session or the window server is disabled. You should release the dictionary when you are finished using it. For information about the key-value pairs in this dictionary, see "Window Server Session Properties."

这篇关于确定WindowServer是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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