Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions AutoRaise.mm
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
static NSString * const NoTitle = @"";
static CGPoint desktopOrigin = {0, 0};
static CGPoint oldPoint = {0, 0};

static bool needs_raise = false;

static bool propagateMouseMoved = false;
static bool ignoreSpaceChanged = false;
static bool invertIgnoreApps = false;
Expand Down Expand Up @@ -1064,19 +1067,20 @@ void onTick() {

NSRunningApplication *frontmostApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
abort = abort || [stayFocusedBundleIds containsObject: frontmostApp.bundleIdentifier];

/*
if (abort) {
if (verbose) { NSLog(@"Abort focus/raise"); }
raiseTimes = 0;
delayTicks = 0;
return;
}

*/
AXUIElementRef _mouseWindow = get_mousewindow(mousePoint);
if (_mouseWindow) {
pid_t mouseWindow_pid;
if (AXUIElementGetPid(_mouseWindow, &mouseWindow_pid) == kAXErrorSuccess) {
bool needs_raise = !invertIgnoreApps;
// bool needs_raise = !invertIgnoreApps;
needs_raise = !invertIgnoreApps;
AXUIElementRef _mouseWindowApp = AXUIElementCreateApplication(mouseWindow_pid);
if (needs_raise && titleEquals(_mouseWindow, @[NoTitle, Untitled])) {
needs_raise = is_main_window(_mouseWindowApp, _mouseWindow, is_chrome_app(
Expand Down Expand Up @@ -1152,6 +1156,7 @@ void onTick() {
}

if (needs_raise) {
/*
if (!delayTicks) {
// start the delay
delayTicks = delayCount;
Expand Down Expand Up @@ -1195,6 +1200,7 @@ void onTick() {
}
#endif
}
*/
} else {
raiseTimes = 0;
delayTicks = 0;
Expand All @@ -1208,6 +1214,7 @@ void onTick() {
}
#endif
} else {
needs_raise = false;
raiseTimes = 0;
delayTicks = 0;
}
Expand Down Expand Up @@ -1243,6 +1250,26 @@ CGEventRef eventTapHandler(CGEventTapProxy proxy, CGEventType type, CGEventRef e
CGEventFlags flags = CGEventGetFlags(event);
commandGravePressed = (flags & kCGEventFlagMaskCommand) == kCGEventFlagMaskCommand;
}
} else if (type == kCGEventLeftMouseDown) {
///*
if (needs_raise) {
needs_raise = false;
if (verbose) { NSLog(@"Generate another mouse down"); }

// click down and up for focus
CGPoint mousePoint = CGEventGetLocation(event);
CGEventRef _event = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown,
{mousePoint.x, mousePoint.y}, kCGMouseButtonLeft);
CGEventPost(kCGHIDEventTap, _event);
CGEventSetType(_event, kCGEventLeftMouseUp);
CGEventPost(kCGHIDEventTap, _event);
CFRelease(_event);

// pass original down event
CGEventPost(kCGHIDEventTap, event);
return NULL;
}
//*/
} else if (type == kCGEventTapDisabledByTimeout || type == kCGEventTapDisabledByUserInput) {
if (verbose) { NSLog(@"Got event tap disabled event, re-enabling..."); }
CGEventTapEnable(eventTap, true);
Expand Down Expand Up @@ -1378,9 +1405,15 @@ int main(int argc, const char * argv[]) {
if (verbose) { NSLog(@"System cursor scale: %f", oldScale); }

CFRunLoopSourceRef runLoopSource = NULL;
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault,
CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventFlagsChanged),
eventTapHandler, NULL);
eventTap = CGEventTapCreate(
kCGSessionEventTap,
kCGHeadInsertEventTap,
kCGEventTapOptionDefault, // kCGEventTapOptionListenOnly
CGEventMaskBit(kCGEventKeyDown) |
CGEventMaskBit(kCGEventFlagsChanged) |
CGEventMaskBit(kCGEventLeftMouseDown),
eventTapHandler,
NULL);
if (eventTap) {
runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
if (runLoopSource) {
Expand Down