Example #1
0
Qt::Native::Status insertEventHandler_Quartz(QNativeInput *nativeInput, int pid = 0)
{
    uid_t uid = geteuid();
    if (uid != 0)
        qWarning("MacNativeEvents: You must be root to listen for key events!");

    CFMachPortRef port;
    if (!pid){
        port = CGEventTapCreate(kCGHIDEventTap,
            kCGHeadInsertEventTap, kCGEventTapOptionListenOnly,
            kCGEventMaskForAllEvents, EventHandler_Quartz, nativeInput);
    } else {
        ProcessSerialNumber psn;
        GetProcessForPID(pid, &psn);
        port = CGEventTapCreateForPSN(&psn,
            kCGHeadInsertEventTap, kCGEventTapOptionListenOnly,
            kCGEventMaskForAllEvents, EventHandler_Quartz, nativeInput);
    }

    CFRunLoopSourceRef eventSrc = CFMachPortCreateRunLoopSource(NULL, port, 0);
    CFRunLoopAddSource((CFRunLoopRef) GetCFRunLoopFromEventLoop(GetMainEventLoop()),
        eventSrc, kCFRunLoopCommonModes);

    return Qt::Native::Success;
}
Example #2
0
CFStringRef WBProcessCopyNameForPID(pid_t pid) {
  /* if current process */
  if (pid == getpid()) {
    spx_assert(getprogname(), "progname required");
    return CFStringCreateWithCString(kCFAllocatorDefault, getprogname(), kCFStringEncodingUTF8);
  }
  /* try to use carbon process manager */
  ProcessSerialNumber psn;
  if (noErr == GetProcessForPID(pid, &psn)) {
    CFStringRef name = NULL;
    if (noErr == CopyProcessName(&psn, &name))
      return name;
  }

  CFStringRef name = NULL;
  /* fall back: use sysctl */
  size_t len = 0;
  char stackbuf[2048];
  char *buffer = stackbuf;
  int mig[] = { CTL_KERN, KERN_PROCARGS, pid };
  int err = sysctl(mig, 3, NULL, &len, NULL, 0);
  if (0 == err && len > 0) {
    if (len > 2048)
      buffer = malloc(len);
    buffer[0] = '\0';
    err = sysctl(mig, 3, buffer, &len, NULL, 0);
    if (0 == err && strlen(buffer) > 0) {
      name = CFStringCreateWithCString(kCFAllocatorDefault, basename(buffer), kCFStringEncodingUTF8);
    }
    if (buffer != stackbuf)
      free(buffer);
  }
  return name;
}
Example #3
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 #4
0
ax_application AXLibConstructApplication(pid_t PID, std::string Name)
{
    ax_application Application = {};

    Application.Ref = AXUIElementCreateApplication(PID);
    GetProcessForPID(PID, &Application.PSN);
    Application.Name = Name;
    Application.PID = PID;

    return Application;
}
Example #5
0
Qt::Native::Status sendNativeKeyEventToProcess_Quartz(const QNativeKeyEvent &event, int pid)
{
    ProcessSerialNumber psn;
    GetProcessForPID(pid, &psn);

    CGEventRef e = CGEventCreateKeyboardEvent(0, (uint)event.nativeKeyCode, event.press);
    setModifiersFromQNativeEvent(e, event);
    SetFrontProcess(&psn);
    CGEventPostToPSN(&psn, e);
    CFRelease(e);
    return Qt::Native::Success;
}
Boolean HelperMacX::isFrontProcess(pid_t pid){
	Boolean result;
	ProcessSerialNumber pidPSN;
	ProcessSerialNumber frontPSN;
	OSStatus status = GetProcessForPID(pid, &pidPSN);
	if (noErr != status) {
		qWarning("HelperMacX::isFrontProcess: GetProcessForPID error for pid %d: %d", pid, (int)status);
		return false;
	}
	GetFrontProcess(&frontPSN);
	SameProcess(&pidPSN, &frontPSN, &result);
	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 #8
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 #9
0
///
/// Detect if another instance of this application is running.
//  Returns true if there is, otherwise false
///
bool CBOINCGUIApp::DetectDuplicateInstance() {
#ifdef __WXMSW__
    if (CTaskBarIcon::FireAppRestore()) {
        return true;
    }
#endif
#ifdef __WXMAC__
    ProcessSerialNumber PSN;
    int iInstanceID = wxGetApp().IsAnotherInstanceRunning();
    if (iInstanceID) {
        // Bring other instance to the front and exit this instance
        OSStatus err = GetProcessForPID(iInstanceID, &PSN);
        if (!err) SetFrontProcess(&PSN);
        return true;
    }
#endif
    return false;
}
OSType HelperMacX::getProcessSignature(pid_t pid){
	OSErr err;
	ProcessSerialNumber processSerialNumber;
	ProcessInfoRec processInfoRec;
	processInfoRec.processInfoLength = sizeof(processInfoRec);
	processInfoRec.processAppSpec = NULL;
	processInfoRec.processName = NULL;
	err = GetProcessForPID(pid, &processSerialNumber);
	if (noErr != err) {
		qWarning("HelperMacX::getProcessSignature: GetProcessForPID error for pid %d: %d", pid, err);
		return 0;
	}
	err = GetProcessInformation(&processSerialNumber, &processInfoRec);
	if (noErr != err) {
		qWarning("HelperMacX::getProcessSignature: GetProcessInformation error for pid %d: %d\n", pid, err);
		return 0;
	}
	return processInfoRec.processSignature;
}
Example #11
0
Plugger::Plugger() {
    char temp[256];

    _searchpath = NULL;

    addsearchdir(PACKAGE_LIB_DIR);

    sprintf(temp,"%s/.freej/plugins",getenv("HOME"));
    addsearchdir(temp);

    addsearchdir("/usr/lib/FreeFrame");
    addsearchdir("/usr/local/lib/FreeFrame");
#ifdef WITH_FREI0R
    addsearchdir("/usr/lib/frei0r-1");
    addsearchdir("/usr/lib64/frei0r-1");
    addsearchdir("/usr/local/lib/frei0r-1");
    addsearchdir("/opt/local/lib/frei0r-1");
#endif

//   addsearchdir("/usr/lib/freej");
//   addsearchdir("/usr/local/lib/freej");
//   addsearchdir("/opt/video/lib/freej");
#ifdef HAVE_DARWIN
    ProcessSerialNumber psn;
    GetProcessForPID(getpid(), &psn);
    FSRef location;
    GetProcessBundleLocation(&psn, &location);
    // 238 == 256 - strlen("/Contents/Plugins") - 1
    FSRefMakePath(&location, (UInt8 *)temp, 238);
    strcat(temp, "/Contents/Plugins");
    addsearchdir(temp);
    sprintf(temp, "%s/Library/Application Support/FreeJ", getenv("HOME"));
    addsearchdir(temp);
    sprintf(temp, "%s/Library/Application Support/FreeFrame", getenv("HOME"));
    addsearchdir(temp);
    addsearchdir("/Library/Application Support/FreeJ");
    addsearchdir("/Library/Application Support/FreeFrame");
#endif

}
Example #12
0
static PyObject *AE_AddressDescToPath(PyObject *_self, PyObject *_args)
{
	AEDesc desc;
	ProcessSerialNumber psn;
	pid_t pid;
	OSType creatorType = kLSUnknownCreator;
	Size cSize;
	char *cStr;
	CFStringRef bundleID = NULL;
	FSRef fsref;
	UInt8 path[PATH_MAX];
	PyObject* pathObj;
	OSStatus err;
	
	if (!PyArg_ParseTuple(_args, "O&",
						  AE_AEDesc_Convert, &desc))
	return NULL;
	
	switch (desc.descriptorType) {
	
		case typeKernelProcessID:
			err = AEGetDescData(&desc, &pid, sizeof(pid));
			if (err) return AE_MacOSError(err);
			err = GetProcessForPID(pid, &psn);
			if (err) return AE_MacOSError(err);
			err = GetProcessBundleLocation(&psn, &fsref);
			if (err) return AE_MacOSError(err);
			break;
		
		case typeProcessSerialNumber:
			err = AEGetDescData(&desc, &psn, sizeof(psn));
			if (err) return AE_MacOSError(err);
			err = GetProcessBundleLocation(&psn, &fsref);
			if (err) return AE_MacOSError(err);
			break;
		
		case typeApplSignature:
			err = AEGetDescData(&desc, &creatorType, sizeof(creatorType));
			if (err) return AE_MacOSError(err);
			err = LSFindApplicationForInfo(creatorType, bundleID, NULL, &fsref, NULL);
			if (err) return AE_MacOSError(err);
			break;
		
		case typeApplicationBundleID:
			cSize = AEGetDescDataSize(&desc);
			cStr = malloc((size_t)cSize);
			if (!cStr) return AE_MacOSError(errAECoercionFail);
			err = AEGetDescData(&desc, cStr, cSize);
			if (err) return AE_MacOSError(err);
			bundleID = CFStringCreateWithBytes(NULL, (UInt8 *)cStr, (CFIndex)cSize, kCFStringEncodingUTF8, 0);
			free(cStr);
			if (!bundleID) return AE_MacOSError(errAECoercionFail);
			err = LSFindApplicationForInfo(creatorType, bundleID, NULL, &fsref, NULL);
			if (err) return AE_MacOSError(err);
			break;
		
		case typeMachPort: // unsupported
		case typeApplicationURL: // unsupported (remote applications)
		default: 
			return AE_MacOSError(errAECoercionFail);
	}

	err = FSRefMakePath(&fsref, path, sizeof(path));
	if (err) return AE_MacOSError(err);
	pathObj = PyUnicode_DecodeUTF8((char *)path, strlen((char *)path), NULL);
	return Py_BuildValue("O", pathObj);
}
Example #13
0
static int ioSetFullScreenActual(int fullScreen) {
    Rect                screen;
    int                 width, height, maxWidth, maxHeight;
    int                 oldWidth, oldHeight;
    static Rect			rememberOldLocation = {0,0,0,0};		
    GDHandle            dominantGDevice;
	windowDescriptorBlock *	targetWindowBlock  = windowBlockFromIndex(1);
	extern Boolean gSqueakBrowserWasHeadlessButMadeFullScreen;
	extern Boolean gSqueakBrowserSubProcess;

	
	if (browserActiveAndDrawingContextOk()) {
		if (!gSqueakBrowserWasHeadlessButMadeFullScreen) {
			gSqueakBrowserWasHeadlessButMadeFullScreen = true;
			SetUpMenus();
			AdjustMenus();
		}
		sqShowWindowActual(1);
		if (targetWindowBlock->context)  //Set context to NULL, if screen is same size as fullscreen we wouldn't get new context
				QDEndCGContext(GetWindowPort(targetWindowBlock->handle),&targetWindowBlock->context);
		targetWindowBlock->context = NULL;
	}

	if ((targetWindowBlock == NULL) || (fullScreen && getFullScreenFlag() && !targetWindowBlock->isInvisible))
		return 0;

	dominantGDevice = getThatDominateGDevice(targetWindowBlock->handle);
    if (dominantGDevice == null) {
        success(false);
        return 0;
    }
    screen = (**dominantGDevice).gdRect;
	        
    if (fullScreen) {
		GetPortBounds(GetWindowPort(targetWindowBlock->handle),&rememberOldLocation);
		oldWidth =  rememberOldLocation.right -  rememberOldLocation.left;
		oldHeight =  rememberOldLocation.bottom -  rememberOldLocation.top;

		if (targetWindowBlock->isInvisible) {
			rememberOldLocation.top = 44;
			rememberOldLocation.left = 8;
		}
		QDLocalToGlobalRect(GetWindowPort(targetWindowBlock->handle),&rememberOldLocation);
		if (gSqueakBrowserSubProcess) {
			ProcessSerialNumber psn = { 0, kCurrentProcess };
			ProcessInfoRec info;
			info.processName = NULL;
			info.processAppSpec = NULL;
			info.processInfoLength = sizeof(ProcessInfoRec);
			GetProcessInformation(&psn,&info);
			SetFrontProcess(&psn);
		}
		MenuBarHide();
		width  = screen.right - screen.left; 
		height = (screen.bottom - screen.top);
		MoveWindow(targetWindowBlock->handle, screen.left, screen.top, true);
		SizeWindow(targetWindowBlock->handle, width, height, true);
		setFullScreenFlag(true);
	} else {
		MenuBarRestore();
	
		if (gSqueakBrowserWasHeadlessButMadeFullScreen) {
			HideWindow(targetWindowBlock->handle);
			{
				ProcessSerialNumber psn;
				pid_t parent;
				OSStatus err;
				parent = getppid();
				if (parent != 1) {
					err = GetProcessForPID(parent,&psn); 
					if(err == 0) 
						SetFrontProcess(&psn);
				}
			}
		}

		if (EmptyRect(&rememberOldLocation)) {
			/* get old window size */
			width  = (unsigned) getSavedWindowSize() >> 16;
			height = getSavedWindowSize() & 0xFFFF;

			/* minimum size is 1 x 1 */
			width  = (width  > 0) ?  width : 64;
			height = (height > 0) ? height : 64;

			/* maximum size is screen size inset slightly */
			maxWidth  = (screen.right  - screen.left) - 16;
			maxHeight = (screen.bottom - screen.top)  - 52;
			width  = (width  <= maxWidth)  ?  width : maxWidth;
			height = (height <= maxHeight) ? height : maxHeight;
			MoveWindow(targetWindowBlock->handle, 8, 44, true);
			SizeWindow(targetWindowBlock->handle, width, height, true);
		} else {