Example #1
0
static void EQResize (int pid) {
    ProcessSerialNumber psn;
    GetProcessForPID(pid, &psn);
    SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);

    AXValueRef temp;
    CGPoint windowPosition;
    AXUIElementRef frontMostApp;
    AXUIElementRef frontMostWindow;
    frontMostApp = AXUIElementCreateApplication(pid);
    AXUIElementSetAttributeValue(frontMostApp, kAXFrontmostAttribute, kCFBooleanTrue); // make application frontmost

    AXUIElementCopyAttributeValue(frontMostApp, kAXFocusedWindowAttribute, (CFTypeRef *)&frontMostWindow);
    AXUIElementSetAttributeValue(frontMostWindow, kAXMainAttribute, kCFBooleanTrue); // make window frontmost

    AXUIElementCopyAttributeValue(frontMostWindow, kAXPositionAttribute, (CFTypeRef *)&temp);
    AXValueGetValue(temp, kAXValueCGPointType, &windowPosition);
    CFRelease(temp);
    windowPosition.x = 0;
    windowPosition.y = -33;
    temp = AXValueCreate(kAXValueCGPointType, &windowPosition);
    AXUIElementSetAttributeValue(frontMostWindow, kAXPositionAttribute, temp);
    CFRelease(temp);

    CFRelease(frontMostWindow);
    CFRelease(frontMostApp);
}
Example #2
0
OSStatus activateSelf() {
	ProcessSerialNumber psn;
	OSErr err = GetCurrentProcess(&psn);
	OSStatus result = err;
	if (err == noErr) {
		result = SetFrontProcessWithOptions(&psn,kSetFrontProcessFrontWindowOnly);
	}

	return result;
}
void HelperMacX::processToFront(pid_t pid){
	OSStatus status;
	ProcessSerialNumber processSerialNumber;
	status = GetProcessForPID(pid, &processSerialNumber);
	if (noErr != status) {
		qWarning("HelperMacX::processToFront: GetProcessForPID error for pid %d: %d", pid, (int)status);
		return;
	}
	status = SetFrontProcessWithOptions(&processSerialNumber, kSetFrontProcessFrontWindowOnly);
	if (noErr != status) {
		qWarning("HelperMacX::processToFront: SetFrontProcessWithOptions for pid %d: %d", pid, (int)status);
		return;
	}
}
Example #4
0
void detect_window_below_cursor()
{
        window_lst.clear();

        CFArrayRef osx_window_list = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
        if(osx_window_list)
        {
                CFIndex osx_window_count = CFArrayGetCount(osx_window_list);
                for(CFIndex i = 0; i < osx_window_count; ++i)
                {
                        CFDictionaryRef elem = (CFDictionaryRef)CFArrayGetValueAtIndex(osx_window_list, i);
                        window_lst.push_back(app_info());
                        CFDictionaryApplyFunction(elem, print_keys, NULL);
                }

                CGEventRef event = CGEventCreate(NULL);
                CGPoint cursor = CGEventGetLocation(event);
                CFRelease(event);

                std::cout << "Mouse Pos: " << cursor.x << ", " << cursor.y << std::endl;
                for(int i = 0; i < window_lst.size(); ++i)
                {
                        if(window_lst[i].layer == 0)
                        {
                                if(cursor.x >= window_lst[i].x && cursor.x <= window_lst[i].x + window_lst[i].width
                                                && cursor.y >= window_lst[i].y && cursor.y <= window_lst[i].y + window_lst[i].height)
                                {
                                        window_lst_focus_index = i;
                                        pid = window_lst[i].pid;
                                        GetProcessForPID(pid, &psn);
                                        SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);
                                        break;
                                }

                                std::cout << "Owner: " << window_lst[i].owner << std::endl;
                                std::cout << "Name: " << window_lst[i].name << std::endl;
                                std::cout << "PID: " << window_lst[i].pid << std::endl;
                                std::cout << "Layer: " << window_lst[i].layer << std::endl;
                                std::cout << "X: " << window_lst[i].x << std::endl;
                                std::cout << "Y: " << window_lst[i].y << std::endl;
                                std::cout << "Width: " << window_lst[i].width << std::endl;
                                std::cout << "Height: " << window_lst[i].height << std::endl;

                        }
                }
                std::cout << "Keyboard focus: " << pid << std::endl;
        }
}
Example #5
0
OSStatus activateForProcessInfo(CFDictionaryRef pDict) {
	ProcessSerialNumber psn = getPSNFromDict(pDict);
	return SetFrontProcessWithOptions(&psn,kSetFrontProcessFrontWindowOnly);
}