Re: clickCount question
Re: clickCount question
- Subject: Re: clickCount question
- From: Julien Jalon <email@hidden>
- Date: Sun, 20 Jul 2003 21:27:58 +0200
On Sunday, Jul 20, 2003, at 19:38 Europe/Paris, M. Uli Kusterer wrote:
At 17:39 Uhr +0100 20.07.2003, Ben Dougall wrote:
// a better thing would be to calculate double click interval here
#define DOUBLECLICK_INTERVAL 0.5
user defaults would be a better place to get this value
Actually, an *even better* thing would be to use a MacOS API. I don't
know whether Cocoa has one (is there a default stored in
NSUserDefaults by default?), but in Carbon there is GetDblTime() (or
something like that), which is part of the old event manager, and
returns the time in ticks (60ths of a second) that must elapse before
two clicks aren't considered a double click anymore.
Just hard-coding a value won't do, because users can specify their
preferred interval in System Preferences -> Mouse.
Of course, that what i meant by "calculate double click interval".
FYI, that interval is available via user defaults with the
"com.apple.mouse.doubleClickThreshold" key.
The problem is that due, to user defaults cache, the application may
not be aware of any change to this value. And since modifying this
value does not raise any distributed notification, it can be a pain to
make sure the application has it right.
I think, maybe using polling and synchronize on user defaults to be
sure...
Something like this:
--- MAIL COMPILED CODE ---
#define DCT_MAX_CACHED 2 * 60 // 2 minutes
float doubleClickThreshold()
{
static NSDate* lastDblClickThresholdCache = nil;
static float cachedDblClickThreshold = 0;
static NSUserDefaults* globalUserDefaults = nil;
if(!lastDblClickThresholdCache) {
globalUserDefaults = [[NSUserDefaults alloc] init];
[globalUserDefaults addSuiteNamed:@".GlobalPreferences"];
lastDblClickThresholdCache = [[NSDate distantPast] retain];
}
if([lastDblClickThresholdCache timeIntervalSinceNow] <
-DCT_MAX_CACHED) {
// be sure we are up to date for global defaults
[globalUserDefaults synchronize];
cachedDblClickThreshold = [globalUserDefaults
floatForKey:@"com.apple.mouse.doubleClickThreshold"];
if(cachedDblClickThreshold < 0.1) {
cachedDblClickThreshold = 0.1;
}
[lastDblClickThresholdCache release];
lastDblClickThresholdCache = [[NSDate date] retain];
}
return cachedDblClickThreshold;
}
--
Julien Jalon
http://www.julien-jalon.org/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.