Re: Unique ID for a Window?

2015-07-29 Thread Jean-Daniel Dupas

 Le 29 juil. 2015 à 12:25, Dave d...@looktowindward.com a écrit :
 
 Hi,
 
 For reasons that are too complex to go in to, I need to somehow create a 
 Unique ID that is valid for the life of a Window. The Window I am trying to 
 identify is not owned by my App (think Screen Dump, like “Grab”). 
 
 I ran this code:
 
 CFArrayRef windowList = 
 CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
 for (NSMutableDictionary* entry in (NSArray*)windowList) 
 {
NSString* ownerName = [entry objectForKey:(id)kCGWindowOwnerName];
NSInteger ownerPID = [[entry objectForKey:(id)kCGWindowOwnerPID] 
 integerValue];
NSLog(@%@:%ld, ownerName, (long)ownerPID);
 }
 CFRelease(windowList);  
 
 This is the dictionary returned for this Email message:
 
 {
kCGWindowAlpha = 1;
kCGWindowBounds = {
Height = 858;
Width = 1003;
X = 874;
Y = 342;
};
kCGWindowIsOnscreen = 1;
kCGWindowLayer = 0;
kCGWindowMemoryUsage = 3462288;
kCGWindowName = New Message;
kCGWindowNumber = 2895;
kCGWindowOwnerName = Mail;
kCGWindowOwnerPID = 507;
kCGWindowSharingState = 1;
kCGWindowStoreType = 2;
 },
 
 Are one or more of these values guaranteed to be Unique (within the Window 
 List) and not to change during the life-time of the Window? 
 
 Thanks a lot.
 
 All the Best
 Dave

From the Window Services Reference:

kCGWindowNumber
The value for this key is a CFNumberRef 
https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFNumberRef/index.html#//apple_ref/c/tdef/CFNumberRef
 type (encoded as kCGWindowIDCFNumberType 
https://developer.apple.com/library/mac/documentation/Carbon/Reference/CGWindow_Reference/Constants/Constants.html#//apple_ref/c/macro/kCGWindowIDCFNumberType)
 that contains the window ID. The window ID is unique within the current user 
session. 




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Unique ID for a Window?

2015-07-29 Thread Dave
Hi,

For reasons that are too complex to go in to, I need to somehow create a Unique 
ID that is valid for the life of a Window. The Window I am trying to identify 
is not owned by my App (think Screen Dump, like “Grab”). 

I ran this code:

CFArrayRef windowList = 
CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
for (NSMutableDictionary* entry in (NSArray*)windowList) 
{
NSString* ownerName = [entry objectForKey:(id)kCGWindowOwnerName];
NSInteger ownerPID = [[entry objectForKey:(id)kCGWindowOwnerPID] 
integerValue];
NSLog(@%@:%ld, ownerName, (long)ownerPID);
}
CFRelease(windowList);  

This is the dictionary returned for this Email message:

{
kCGWindowAlpha = 1;
kCGWindowBounds = {
Height = 858;
Width = 1003;
X = 874;
Y = 342;
};
kCGWindowIsOnscreen = 1;
kCGWindowLayer = 0;
kCGWindowMemoryUsage = 3462288;
kCGWindowName = New Message;
kCGWindowNumber = 2895;
kCGWindowOwnerName = Mail;
kCGWindowOwnerPID = 507;
kCGWindowSharingState = 1;
kCGWindowStoreType = 2;
},

Are one or more of these values guaranteed to be Unique (within the Window 
List) and not to change during the life-time of the Window? 

Thanks a lot.

All the Best
Dave


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Unique ID for a Window?

2015-07-29 Thread Dave
 
 From the Window Services Reference:
 
 kCGWindowNumber
 The value for this key is a CFNumberRef 
 https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFNumberRef/index.html#//apple_ref/c/tdef/CFNumberRef
  type (encoded as kCGWindowIDCFNumberType 
 https://developer.apple.com/library/mac/documentation/Carbon/Reference/CGWindow_Reference/Constants/Constants.html#//apple_ref/c/macro/kCGWindowIDCFNumberType)
  that contains the window ID. The window ID is unique within the current user 
 session. 

Yes I saw this, I wasn’t sure what “Current User Session” meant in this case. 
Also if there could be a window owned by one App with the same CGWindowNumber 
as another App, IOW, if there could be more than one Window in the Window Array 
that has the same number? e.g. I need more than once piece of info to ensure it 
is unique.

Cheers
Dave


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Unique ID for a Window?

2015-07-29 Thread Dave

 On 29 Jul 2015, at 13:12, Uli Kusterer witness.of.teacht...@gmx.net wrote:
 

  Note that I'm saying at a time. There is no guarantee that an application 
 might not close the window whose number you have, then open a new one, and 
 get a new window with the same number. It's unlikely to happen, but I don't 
 think it's stated anywhere that that is impossible. OTOH, also keep in mind 
 that an application might close a window and re-open it instead of just 
 hiding and showing it, which might change its window number.

That’s ok, because I track Window Close/Open and will just create a new ID when 
a window is opened.

Thanks for the clarification.

All the Best
Dave


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Unique ID for a Window?

2015-07-29 Thread Uli Kusterer
On 29 Jul 2015, at 13:25, Dave d...@looktowindward.com wrote:
 Yes I saw this, I wasn’t sure what “Current User Session” meant in this case. 
 Also if there could be a window owned by one App with the same CGWindowNumber 
 as another App, IOW, if there could be more than one Window in the Window 
 Array that has the same number? e.g. I need more than once piece of info to 
 ensure it is unique.


 AFAIK it's the number the window server uses to identify a window. So unless 
you have multiple user sessions (i.e. you have a second user logged in using 
Fast User Switching), there is only one window with that ID at a time. It is 
unique across all the applications running under the same user's account. Which 
usually is all windows your application can see (unless your app is running as 
root, but really, nobody except maybe login screen plugin developers would do 
that).

 Note that I'm saying at a time. There is no guarantee that an application 
might not close the window whose number you have, then open a new one, and get 
a new window with the same number. It's unlikely to happen, but I don't think 
it's stated anywhere that that is impossible. OTOH, also keep in mind that an 
application might close a window and re-open it instead of just hiding and 
showing it, which might change its window number.

Cheers,
-- Uli Kusterer
The Witnesses of TeachtText are everywhere...



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com