Skip to content

Commit

Permalink
Use performSelector to wait an application to become active
Browse files Browse the repository at this point in the history
  • Loading branch information
dabaopku committed Feb 9, 2012
1 parent 2e1a0f4 commit aab58e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
28 changes: 11 additions & 17 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions iStroke/EventListener.m
Expand Up @@ -61,18 +61,23 @@ -(void) stop
CGEventTapEnable(eventTap, false);
}

-(CGEventRef) callback:(CGEventTapProxy)proxy :(CGEventType)type :(CGEventRef)event :(void *)refcon
- (void) findActiveProcess
{
NSString *process=[ProcessHooker getActiveProcessIdentifier];
NSLog(@"%@",process);

state= kListen;
iStrokeAppDelegate *app=[[NSApplication sharedApplication] delegate];
[app doneChooseWindow];
}

- (CGEventRef) callback:(CGEventTapProxy)proxy :(CGEventType)type :(CGEventRef)event :(void *)refcon
{
if (state== kFindWindow)
{
if(type==kCGEventLeftMouseUp)
{

[[[ProcessHooker alloc] init] performSelector:@selector(getActiveProcess) withObject:nil afterDelay:0.2];
state= kListen;

iStrokeAppDelegate *app=[[NSApplication sharedApplication] delegate];
[app doneChooseWindow];
[self performSelector:@selector(findActiveProcess) withObject:nil afterDelay:0.2];
}
return event;
}
Expand Down
7 changes: 1 addition & 6 deletions iStroke/ProcessHooker.m
Expand Up @@ -11,11 +11,6 @@ @implementation ProcessHooker

+ (NSDictionary *)getActiveProcess
{
for (NSRunningApplication *currApp in [[NSWorkspace sharedWorkspace] runningApplications]) {
if ([currApp isActive]) {
NSLog(@"* %@", [currApp localizedName]);
}
}
NSDictionary * dict=[[NSWorkspace sharedWorkspace] activeApplication];
return dict;
/*
Expand All @@ -41,7 +36,7 @@ + (NSString *) getActiveProcessIdentifier

static NSString *iStrokeIdentifier=@"cn.edu.pku.dabao.iStroke";

+ (bool)isStoke {
+ (bool)isStroke {
NSString *str=[self getActiveProcessIdentifier];
bool res=[str isEqualToString:iStrokeIdentifier];
return res;
Expand Down

0 comments on commit aab58e1

Please sign in to comment.