First Revision (from Archive)
[~jspiros/WindowBlur.git] / CGSInternal / CGSConnection.h
1 /*
2  * Copyright (C) 2007-2008 Alacatia Labs
3  * 
4  * This software is provided 'as-is', without any express or implied
5  * warranty.  In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  * 
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  * 
12  * 1. The origin of this software must not be misrepresented; you must not
13  *    claim that you wrote the original software. If you use this software
14  *    in a product, an acknowledgment in the product documentation would be
15  *    appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  *    misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  * 
20  * Joe Ranieri joe@alacatia.com
21  *
22  */
23
24 #pragma once
25
26 typedef int CGSConnectionID;
27 static const CGSConnectionID kCGSNullConnectionID = 0;
28
29
30 CG_EXTERN_C_BEGIN
31
32 /*! DOCUMENTATION PENDING - verify this is Leopard only! */
33 CG_EXTERN CGError CGSSetLoginwindowConnection(CGSConnectionID cid) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
34 CG_EXTERN CGError CGSSetLoginwindowConnectionWithOptions(CGSConnectionID cid, CFDictionaryRef options) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
35
36 /*! Enables or disables updates on a connection. The WindowServer will forcibly reenable updates after 1 second. */
37 CG_EXTERN CGError CGSDisableUpdate(CGSConnectionID cid);
38 CG_EXTERN CGError CGSReenableUpdate(CGSConnectionID cid);
39
40 /*! Is there a menubar associated with this connection? */
41 CG_EXTERN bool CGSMenuBarExists(CGSConnectionID cid);
42
43
44
45 #pragma mark notifications
46 /*! Registers or removes a function to get notified when a connection is created. Only gets notified for connections created in the current application. */
47 typedef void (*CGSNewConnectionNotificationProc)(CGSConnectionID cid);
48 CG_EXTERN CGError CGSRegisterForNewConnectionNotification(CGSNewConnectionNotificationProc proc);
49 CG_EXTERN CGError CGSRemoveNewConnectionNotification(CGSNewConnectionNotificationProc proc);
50
51 /*! Registers or removes a function to get notified when a connection is released. Only gets notified for connections created in the current application. */
52 typedef void (*CGSConnectionDeathNotificationProc)(CGSConnectionID cid);
53 CG_EXTERN CGError CGSRegisterForConnectionDeathNotification(CGSConnectionDeathNotificationProc proc);
54 CG_EXTERN CGError CGSRemoveConnectionDeathNotification(CGSConnectionDeathNotificationProc proc);
55
56 /*! Creates a new connection to the window server. */
57 CG_EXTERN CGError CGSNewConnection(int unused, CGSConnectionID *outConnection);
58
59 /*! Releases a CGSConnection and all CGSWindows owned by it. */
60 CG_EXTERN CGError CGSReleaseConnection(CGSConnectionID cid);
61
62 /*! Gets the default connection for this process. `CGSMainConnectionID` is just a more modern name. */
63 CG_EXTERN CGSConnectionID _CGSDefaultConnection(void);
64 CG_EXTERN CGSConnectionID CGSMainConnectionID(void);
65
66 /*! Gets the default connection for the current thread. */
67 CG_EXTERN CGSConnectionID CGSDefaultConnectionForThread(void);
68
69 /* Gets the `pid` that owns this CGSConnection. */ 
70 CG_EXTERN CGError CGSConnectionGetPID(CGSConnectionID cid, pid_t *outPID);
71
72 /*! Gets the CGSConnection for the PSN. */
73 CG_EXTERN CGError CGSGetConnectionIDForPSN(CGSConnectionID cid, const ProcessSerialNumber *psn, CGSConnectionID *outOwnerCID);
74
75 /*! Gets and sets a connection's property. */
76 CG_EXTERN CGError CGSGetConnectionProperty(CGSConnectionID cid, CGSConnectionID targetCID, CFStringRef key, CFTypeRef *outValue);
77 CG_EXTERN CGError CGSSetConnectionProperty(CGSConnectionID cid, CGSConnectionID targetCID, CFStringRef key, CFTypeRef value);
78
79 /*! Closes ALL connections used by the current application. Essentially, it turns it into a console application. */
80 CG_EXTERN CGError CGSShutdownServerConnections(void);
81
82 /*! Only the owner of a window can manipulate it. So, Apple has the concept of a universal owner that owns all windows and can manipulate them all. There can only be one universal owner at a time (the Dock). */
83 CG_EXTERN CGError CGSSetUniversalOwner(CGSConnectionID cid);
84
85 /*! Sets a connection to be a universal owner. This call requires `cid` be a universal connection. */
86 CG_EXTERN CGError CGSSetOtherUniversalConnection(CGSConnectionID cid, CGSConnectionID otherConnection);
87
88 CG_EXTERN_C_END