summaryrefslogtreecommitdiffstats
path: root/Mac/Modules
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2003-02-21 16:31:11 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2003-02-21 16:31:11 (GMT)
commitd7c17237420e68e298aa549fb671ad17d6afebc1 (patch)
tree2a23614962724b4a3ab6136663d8992d08772873 /Mac/Modules
parent0fd583ce4d1500938c96c12c698a535ad0938470 (diff)
downloadcpython-d7c17237420e68e298aa549fb671ad17d6afebc1.zip
cpython-d7c17237420e68e298aa549fb671ad17d6afebc1.tar.gz
cpython-d7c17237420e68e298aa549fb671ad17d6afebc1.tar.bz2
Added a method WMAvailable(). This will return True if and only if there
is a window manager and we can connect to it, i.e. if it is safe to try and put up windows. As a side effect the first call will make the current process frontmost.
Diffstat (limited to 'Mac/Modules')
-rw-r--r--Mac/Modules/macosmodule.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/Mac/Modules/macosmodule.c b/Mac/Modules/macosmodule.c
index 5b445c0..8018839 100644
--- a/Mac/Modules/macosmodule.c
+++ b/Mac/Modules/macosmodule.c
@@ -36,6 +36,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <Events.h>
#else
#include <Carbon/Carbon.h>
+#include <ApplicationServices/ApplicationServices.h>
#endif
static PyObject *MacOS_Error; /* Exception MacOS.Error */
@@ -521,6 +522,47 @@ MacOS_SysBeep(PyObject *self, PyObject *args)
return Py_None;
}
+static char WMAvailable_doc[] =
+ "True if this process can interact with the display."
+ "Will foreground the application on the first call as a side-effect."
+ ;
+
+static PyObject *
+MacOS_WMAvailable(PyObject *self, PyObject *args)
+{
+ static PyObject *rv = NULL;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ if (!rv) {
+#if TARGET_API_MAC_OSX
+ ProcessSerialNumber psn;
+
+ /*
+ ** This is a fairly innocuous call to make if we don't have a window
+ ** manager, or if we have no permission to talk to it. It will print
+ ** a message on stderr, but at least it won't abort the process.
+ ** It appears the function caches the result itself, and it's cheap, so
+ ** no need for us to cache.
+ */
+ if (CGMainDisplayID() == 0) {
+ rv = Py_False;
+ } else {
+ if (GetCurrentProcess(&psn) < 0 ||
+ SetFrontProcess(&psn) < 0) {
+ rv = Py_False;
+ } else {
+ rv = Py_True;
+ }
+ }
+#else
+ rv = Py_True;
+#endif
+ }
+ Py_INCREF(rv);
+ return rv;
+}
+
static char GetTicks_doc[] = "Return number of ticks since bootup";
static PyObject *
@@ -672,6 +714,7 @@ static PyMethodDef MacOS_Methods[] = {
{"DebugStr", MacOS_DebugStr, 1, DebugStr_doc},
{"GetTicks", MacOS_GetTicks, 1, GetTicks_doc},
{"SysBeep", MacOS_SysBeep, 1, SysBeep_doc},
+ {"WMAvailable", MacOS_WMAvailable, 1, WMAvailable_doc},
#if !TARGET_API_MAC_OSX
{"FreeMem", MacOS_FreeMem, 1, FreeMem_doc},
{"MaxBlock", MacOS_MaxBlock, 1, MaxBlock_doc},