示例#1
0
文件: execview.c 项目: nysan/alpine
void
osx_launch_special_handling(MCAP_CMD_S *mc_cmd, char *image_file)
{
    CFStringRef str_ref = NULL;
    CFURLRef url_ref = NULL;
    LSLaunchFSRefSpec launch_spec;
    FSRef app_ref, file_ref;
    static EXEC_EVENT_DATA_S event_data;

    install_app_launch_cb((void *)&event_data);
    if((str_ref = CFStringCreateWithCString(NULL, mc_cmd->command,
					kCFStringEncodingASCII)) == NULL)
      return;
    if((url_ref = CFURLCreateWithString(NULL, str_ref, NULL)) == NULL)
      return;
    if(CFURLGetFSRef(url_ref, &app_ref) == false)
      return;
    if(FSPathMakeRef((unsigned char *)image_file,
		     &file_ref, NULL) != noErr)
      return;
    launch_spec.appRef = &app_ref;
    launch_spec.numDocs = 1;
    launch_spec.itemRefs = &file_ref;
    launch_spec.passThruParams = NULL;
    launch_spec.launchFlags = kLSLaunchDontAddToRecents | kLSLaunchNoParams
      | kLSLaunchAsync | kLSLaunchNewInstance;
    /* would want to use this if we ever did true event handling */
    launch_spec.asyncRefCon = 0;

    if(LSOpenFromRefSpec( &launch_spec, NULL) == noErr){
	/*
	 * Here's the strategy:  we want to be able to just launch
	 * the app and then just delete the temp file, but that
	 * doesn't work because the called app needs the temp file
	 * at least until it's finished loading.  Being that there's
	 * no way to tell when the app has finished loading, we wait
	 * until the program has exited, which is the safest thing to
	 * do and is what we do for windows.  Since we haven't totally
	 * embraced event handling at this point, we must do the waiting
	 * synchronously.  We allow for a keystroke to stop waiting, and
	 * just delete the temp file.
	 *   Ideally, we would launch the app, and keep running, checking
	 * the events until the process terminates, and then delete the
	 * temp file.  In this method, we would delete the temp file
	 * at close time if the app was still running.
	 */
	int ch;
	OSStatus rne_rv;
	EventTargetRef target;
	EventRef out_event;
	EventTypeSpec event_types[2] = {
	    {kEventClassApplication, kEventAppTerminated},
	    {kEventClassApplication, kEventAppLaunchNotification}};

	q_status_message(SM_ORDER, 0, 4,
	  "Waiting for program to finish, or press a key to stop waiting...");
	flush_status_messages(1);
	target = GetEventDispatcherTarget();
	event_data.done = 0;
	event_data.set_pid = 0;
	while(!event_data.done){
	    if((rne_rv = ReceiveNextEvent(2, event_types, 1,
					  true, &out_event)) == noErr){
		SendEventToEventTarget(out_event, target);
		ReleaseEvent(out_event);
	    }
	    else if(rne_rv == eventLoopTimedOutErr){
		ch = read_char(1);
		if(ch)
		  event_data.done = 1;
	    }
	    else if(rne_rv == eventLoopQuitErr)
	      event_data.done = 1;
	}
	our_unlink(image_file);
    }
    q_status_message(SM_ORDER, 0, 4, "VIEWER command completed");
}
/*****************************************************
*
* Handle_TextShouldChangeInRange(inHandlerCallRef, inEvent, inUserData) 
*
* Purpose:  called to intercept text changes which are destined for a text control
*
* Inputs:   inHandlerCallRef    - reference to the current handler call chain
*           inEvent             - the event
*           inUserData          - app-specified data you passed in the call to InstallEventHandler
*
* Returns:  OSStatus            - noErr indicates the event was handled
*                                 eventNotHandledErr indicates the event was not handled and the Toolbox should take over
*/
static pascal OSStatus Handle_TextShouldChangeInRange(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
	{
	OSStatus status;

	CFStringRef theCFString = NULL;
	status = GetEventParameter(inEvent, kEventParamCandidateText, typeCFStringRef, NULL, sizeof(theCFString), NULL, &theCFString);
	require_noerr(status, ExitShouldChange);
	require_action(theCFString != NULL, ExitShouldChange, status = userCanceledErr);
	
	UniChar *buffer = NULL;
	CFIndex i, j, len = CFStringGetLength(theCFString);
	if (len == 0) goto ExitShouldChange; // there's nothing to filter
	
	// Grabbing the characters as Unicode chars
	buffer = (UniChar *)malloc(len * sizeof(UniChar));
	require(buffer != NULL, ExitShouldChange);
	CFStringGetCharacters(theCFString, CFRangeMake(0, len), buffer);
	
	// Checking if we just have the return code
	if ((len == 1) && (buffer[0] == kReturnCharCode))
		{
		EventRef theEvent;
		CreateEvent(NULL, kEventClassCommand, kEventCommandProcess, GetCurrentEventTime(), kEventAttributeUserEvent, &theEvent);
		HICommandExtended theCommand;
		theCommand.attributes = kHICommandFromControl;
		theCommand.commandID = 'SVet';
		theCommand.source.control = (ControlRef)inUserData;
		SetEventParameter(theEvent, kEventParamDirectObject, typeHICommand, sizeof(theCommand), &theCommand);
		SendEventToEventTarget(theEvent, GetWindowEventTarget(GetControlOwner((ControlRef)inUserData)));
		ReleaseEvent(theEvent);
		// we don't want the return character to be added to the text so we abort the input
		status = userCanceledErr;
		}
	else
		{
		// Checking to see if we have only digits
		Boolean ok = true;
		for (i = 0; (i < len) && ok; i++)
			ok = (buffer[i] >= '0') && (buffer[i] <= '9');
		
		if (!ok)
			{
			// if not, we remove the offending characters
			for (i = 0, j = 0; i < len; i++)
				if ((buffer[i] >= '0') && (buffer[i] <= '9')) buffer[j++] = buffer[i];
			
			if (j == 0)
				// not a single digit in the candidate text, we abort the inout
				status = userCanceledErr;
			else
				{
				theCFString = CFStringCreateWithCharacters(NULL, buffer, j);
				require_action(theCFString != NULL, ExitShouldChange, status = userCanceledErr);

				status = SetEventParameter(inEvent, kEventParamReplacementText, typeCFStringRef, sizeof(theCFString), &theCFString);
				require_noerr(status, ExitShouldChange);
				// if we reach here, status is already set to noErr so we don't set it again
				}
			}
		else
			// only digits, we just let the HIToolbox do its job
			status = eventNotHandledErr;
		}

ExitShouldChange:

	if (buffer != NULL) free(buffer);

	return status;
	}   // Handle_TextShouldChangeInRange
示例#3
0
void check_input_events()      {
  OSStatus err;
  EventTargetRef target;
  EventRef event;
  UInt32 event_class, event_kind;
  byte mac_keycode;
  UInt32 keycode;
  UInt32 modifiers;
  Point mouse_point, mouse_delta_point;
  WindowRef window_ref;
  int button, button_state;
  EventMouseButton mouse_button;
  int handled;
  int mouse_events;
  int is_up;
  int in_win;
  int ignore;

  if(g_quit_seen) {
    exit(0);
  }

  SetPortWindowPort(g_main_window);

  mouse_events = 0;
  target = GetEventDispatcherTarget();
  while(1) {
    err = ReceiveNextEvent(0, NULL, kEventDurationNoWait,
                           true, &event);

    if(err == eventLoopTimedOutErr) {
      break;
    }
    if(err != noErr) {
      printf("ReceiveNextEvent err: %d\n", (int)err);
      break;
    }

    event_class = GetEventClass(event);
    event_kind = GetEventKind(event);
    handled = 0;
    switch(event_class) {
      case kEventClassKeyboard:
        handled = 1;
        keycode = 0;
        modifiers = 0;
        GetEventParameter(event, kEventParamKeyMacCharCodes,
                          typeChar, NULL, sizeof(byte), NULL,
                          &mac_keycode);
        GetEventParameter(event, kEventParamKeyCode,
                          typeUInt32, NULL, sizeof(UInt32), NULL,
                          &keycode);
        GetEventParameter(event, kEventParamKeyModifiers,
                          typeUInt32, NULL, sizeof(UInt32), NULL,
                          &modifiers);

        mac_update_modifiers((word32)modifiers);

        // Key up/down event
        is_up = -1;
        switch(event_kind) {
          case kEventRawKeyDown:
            is_up = 0;
            //printf("key down: %02x, %08x\n",
            //	(int)mac_keycode, (int)keycode);
            break;
          case kEventRawKeyUp:
            is_up = 1;
            //printf("key up: %02x, %08x\n",
            //	(int)mac_keycode, (int)keycode);
            break;
          case kEventRawKeyModifiersChanged:
            is_up = -1;
            //printf("key xxx: %08x\n", (int)modifiers);
            break;
        }
        if(is_up >= 0) {
          adb_physical_key_update((int)keycode, is_up);
        }
        break;
      case kEventClassMouse:
        handled = 2;
        mouse_events++;
        GetEventParameter(event, kEventParamMouseLocation,
                          typeQDPoint, NULL, sizeof(Point), NULL,
                          &mouse_point);
        GetWindowRegion(g_main_window, kWindowContentRgn,
                        g_event_rgnhandle);
        in_win =  PtInRgn(mouse_point, g_event_rgnhandle);
        // in_win = 1 if it was in the contect region of window
        err = GetEventParameter(event, kEventParamMouseDelta,
                                typeQDPoint, NULL, sizeof(Point), NULL,
                                &mouse_delta_point);
        button = 0;
        button_state = -1;
        switch(event_kind) {
          case kEventMouseDown:
            button_state = 7;
            handled = 3;
            break;
          case kEventMouseUp:
            button_state = 0;
            handled = 3;
            break;
        }
        if(button_state >= 0) {
          GetEventParameter(event, kEventParamMouseButton,
                            typeMouseButton, NULL,
                            sizeof(EventMouseButton), NULL,
                            &mouse_button);
          button = mouse_button;
          if(button > 1) {
            button = 4 - button;
            button = 1 << button;
          }
          ignore = (button_state != 0) &&
                   (!in_win || g_ignore_next_click);
          ignore = ignore || !g_mainwin_active;
          if(ignore) {
            // Outside of A2 window, ignore clicks
            button = 0;
          }
          if(button_state == 0) {
            g_ignore_next_click = 0;
          }
        }

        GlobalToLocal(&mouse_point);

        if(g_warp_pointer) {
          if(err == 0) {
            g_mac_mouse_x += mouse_delta_point.h;
            g_mac_mouse_y += mouse_delta_point.v;
          }
          mac_warp_mouse();
        } else {
          g_mac_mouse_x = mouse_point.h -
                          g_video_act_margin_left;
          g_mac_mouse_y = mouse_point.v -
                          g_video_act_margin_top;
        }

#if 0
        printf("Mouse %d at: %d,%d button:%d, button_st:%d\n",
               mouse_events, g_mac_mouse_x, g_mac_mouse_y,
               button, button_state);
        printf("Mouse deltas: err:%d, %d,%d\n", (int)err,
               mouse_delta_point.h, mouse_delta_point.v);
#endif

        update_mouse(g_mac_mouse_x, g_mac_mouse_y,
                     button_state, button & 7);
        if(g_warp_pointer) {
          g_mac_mouse_x = A2_WINDOW_WIDTH/2;
          g_mac_mouse_y = A2_WINDOW_HEIGHT/2;
          update_mouse(g_mac_mouse_x, g_mac_mouse_y,0,-1);
        }
        break;
      case kEventClassApplication:
        switch(event_kind) {
          case kEventAppActivated:
            handled = 1;
            g_mainwin_active = 1;
            window_ref = 0;
            GetEventParameter(event, kEventParamWindowRef,
                              typeWindowRef, NULL, sizeof(WindowRef),
                              NULL, &window_ref);
            if(window_ref == g_main_window) {
              g_ignore_next_click = 1;
            }
            break;
          case kEventAppDeactivated:
            handled = 1;
            g_mainwin_active = 0;
            g_ignore_next_click = 1;
            break;
        }
        break;
    }
    //	show_event(event_class, event_kind, handled);
    if(handled != 1) {
      (void)SendEventToEventTarget(event, target);
    }
    ReleaseEvent(event);
  }

  return;
}
示例#4
0
void Sys_SendKeyEvents(void)
{
	EventRef theEvent;
	EventTargetRef theTarget;

	// Start by processing the asynchronous events we received since the previous frame
	VID_ProcessPendingAsyncEvents();

	theTarget = GetEventDispatcherTarget();
	while (ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &theEvent) == noErr)
	{
		UInt32 eventClass = GetEventClass(theEvent);
		UInt32 eventKind = GetEventKind(theEvent);

		switch (eventClass)
		{
			case kEventClassMouse:
			{
				EventMouseButton theButton;
				int key;

				switch (eventKind)
				{
					case kEventMouseDown:
					case kEventMouseUp:
						GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(theButton), NULL, &theButton);
						switch (theButton)
						{
							default:
							case kEventMouseButtonPrimary:
								key = K_MOUSE1;
								break;
							case kEventMouseButtonSecondary:
								key = K_MOUSE2;
								break;
							case kEventMouseButtonTertiary:
								key = K_MOUSE3;
								break;
						}
						Key_Event(key, '\0', eventKind == kEventMouseDown);
						break;

					// Note: These two events are mutual exclusives
					// Treat MouseDragged in the same statement, so we don't block MouseMoved while a mousebutton is held
					case kEventMouseMoved:
					case kEventMouseDragged:
					{
						HIPoint deltaPos;
						HIPoint windowPos;

						GetEventParameter(theEvent, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(deltaPos), NULL, &deltaPos);
						GetEventParameter(theEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(windowPos), NULL, &windowPos);

						if (vid_usingmouse)
						{
							in_mouse_x += deltaPos.x;
							in_mouse_y += deltaPos.y;
						}

						in_windowmouse_x = windowPos.x;
						in_windowmouse_y = windowPos.y;
						break;
					}

					case kEventMouseWheelMoved:
					{
						SInt32 delta;
						unsigned int wheelEvent;

						GetEventParameter(theEvent, kEventParamMouseWheelDelta, typeSInt32, NULL, sizeof(delta), NULL, &delta);

						wheelEvent = (delta > 0) ? K_MWHEELUP : K_MWHEELDOWN;
						Key_Event(wheelEvent, 0, true);
						Key_Event(wheelEvent, 0, false);
						break;
					}

					default:
						Con_Printf (">> kEventClassMouse (UNKNOWN eventKind: %u) <<\n", (unsigned)eventKind);
						break;
				}
			}

			case kEventClassKeyboard:
			{
				char charcode;
				UInt32 keycode;

				switch (eventKind)
				{
					case kEventRawKeyDown:
						GetEventParameter(theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(charcode), NULL, &charcode);
						GetEventParameter(theEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(keycode), NULL, &keycode);
						Handle_Key(charcode, keycode, true);
						break;

					case kEventRawKeyRepeat:
						break;

					case kEventRawKeyUp:
						GetEventParameter(theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(charcode), NULL, &charcode);
						GetEventParameter(theEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(keycode), NULL, &keycode);
						Handle_Key(charcode, keycode, false);
						break;

					case kEventRawKeyModifiersChanged:
					{
						UInt32 keymod = 0;
						GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(keymod), NULL, &keymod);
						Handle_KeyMod(keymod);
						break;
					}

					case kEventHotKeyPressed:
						break;

					case kEventHotKeyReleased:
						break;

					case kEventMouseWheelMoved:
						break;

					default:
						Con_Printf (">> kEventClassKeyboard (UNKNOWN eventKind: %u) <<\n", (unsigned)eventKind);
						break;
				}
				break;
			}

			case kEventClassTextInput:
				Con_Printf(">> kEventClassTextInput (%d) <<\n", (int)eventKind);
				break;

			case kEventClassApplication:
				switch (eventKind)
				{
					case kEventAppActivated :
						VID_AppFocusChanged(true);
						break;
					case kEventAppDeactivated:
						VID_AppFocusChanged(false);
						break;
					case kEventAppQuit:
						Sys_Quit(0);
						break;
					case kEventAppActiveWindowChanged:
						break;
					default:
						Con_Printf(">> kEventClassApplication (UNKNOWN eventKind: %u) <<\n", (unsigned)eventKind);
						break;
				}
				break;

			case kEventClassAppleEvent:
				switch (eventKind)
				{
					case kEventAppleEvent :
						break;
					default:
						Con_Printf(">> kEventClassAppleEvent (UNKNOWN eventKind: %u) <<\n", (unsigned)eventKind);
						break;
				}
				break;

			case kEventClassWindow:
				switch (eventKind)
				{
					case kEventWindowUpdate :
						break;
					default:
						Con_Printf(">> kEventClassWindow (UNKNOWN eventKind: %u) <<\n", (unsigned)eventKind);
						break;
				}
				break;

			case kEventClassControl:
				break;

			default:
				/*Con_Printf(">> UNKNOWN eventClass: %c%c%c%c, eventKind: %d <<\n",
							eventClass >> 24, (eventClass >> 16) & 0xFF,
							(eventClass >> 8) & 0xFF, eventClass & 0xFF,
							eventKind);*/
				break;
		}

		SendEventToEventTarget (theEvent, theTarget);
		ReleaseEvent(theEvent);
	}
}
示例#5
0
int main(int argc, char **argv)
#endif
{
	ll_init_apr();

	// Set up llerror logging
	{
		LLError::initForApplication(".");
		LLError::setDefaultLevel(LLError::LEVEL_INFO);
//		LLError::setTagLevel("Plugin", LLError::LEVEL_DEBUG);
//		LLError::logToFile("slplugin.log");
	}

#if LL_WINDOWS
	if( strlen( lpCmdLine ) == 0 )
	{
		LL_ERRS("slplugin") << "usage: " << "SLPlugin" << " launcher_port" << LL_ENDL;
	};

	U32 port = 0;
	if(!LLStringUtil::convertToU32(lpCmdLine, port))
	{
		LL_ERRS("slplugin") << "port number must be numeric" << LL_ENDL;
	};

	// Insert our exception handler into the system so this plugin doesn't
	// display a crash message if something bad happens. The host app will
	// see the missing heartbeat and log appropriately.
	initExceptionHandler();
#elif LL_DARWIN || LL_LINUX
	if(argc < 2)
	{
		LL_ERRS("slplugin") << "usage: " << argv[0] << " launcher_port" << LL_ENDL;
	}

	U32 port = 0;
	if(!LLStringUtil::convertToU32(argv[1], port))
	{
		LL_ERRS("slplugin") << "port number must be numeric" << LL_ENDL;
	}

	// Catch signals that most kinds of crashes will generate, and exit cleanly so the system crash dialog isn't shown.
	signal(SIGILL, &crash_handler);		// illegal instruction
# if LL_DARWIN
	signal(SIGEMT, &crash_handler);		// emulate instruction executed
# endif // LL_DARWIN
	signal(SIGFPE, &crash_handler);		// floating-point exception
	signal(SIGBUS, &crash_handler);		// bus error
	signal(SIGSEGV, &crash_handler);	// segmentation violation
	signal(SIGSYS, &crash_handler);		// non-existent system call invoked
#endif

#if LL_DARWIN
	setupCocoa();
	createAutoReleasePool();
#endif

	LLPluginProcessChild *plugin = new LLPluginProcessChild();

	plugin->init(port);

#if LL_DARWIN
		deleteAutoReleasePool();
#endif

	LLTimer timer;
	timer.start();

#if LL_WINDOWS
	checkExceptionHandler();
#endif

#if LL_DARWIN
	// If the plugin opens a new window (such as the Flash plugin's fullscreen player), we may need to bring this plugin process to the foreground.
	// Use this to track the current frontmost window and bring this process to the front if it changes.
	WindowRef front_window = NULL;
	WindowGroupRef layer_group = NULL;
	int window_hack_state = 0;
	CreateWindowGroup(kWindowGroupAttrFixedLevel, &layer_group);
	if(layer_group)
	{
		// Start out with a window layer that's way out in front (fixes the problem with the menubar not getting hidden on first switch to fullscreen youtube)
		SetWindowGroupName(layer_group, CFSTR("SLPlugin Layer"));
		SetWindowGroupLevel(layer_group, kCGOverlayWindowLevel);		
	}
#endif

#if LL_DARWIN
	EventTargetRef event_target = GetEventDispatcherTarget();
#endif
	while(!plugin->isDone())
	{
#if LL_DARWIN
		createAutoReleasePool();
#endif
		timer.reset();
		plugin->idle();
#if LL_DARWIN
		{
			// Some plugins (webkit at least) will want an event loop.  This qualifies.
			EventRef event;
			if(ReceiveNextEvent(0, 0, kEventDurationNoWait, true, &event) == noErr)
			{
				SendEventToEventTarget (event, event_target);
				ReleaseEvent(event);
			}
			
			// Check for a change in this process's frontmost window.
			if(GetFrontWindowOfClass(kAllWindowClasses, true) != front_window)
			{
				ProcessSerialNumber self = { 0, kCurrentProcess };
				ProcessSerialNumber parent = { 0, kNoProcess };
				ProcessSerialNumber front = { 0, kNoProcess };
				Boolean this_is_front_process = false;
				Boolean parent_is_front_process = false;
				{
					// Get this process's parent
					ProcessInfoRec info;
					info.processInfoLength = sizeof(ProcessInfoRec);
					info.processName = NULL;
					info.processAppSpec = NULL;
					if(GetProcessInformation( &self, &info ) == noErr)
					{
						parent = info.processLauncher;
					}
					
					// and figure out whether this process or its parent are currently frontmost
					if(GetFrontProcess(&front) == noErr)
					{
						(void) SameProcess(&self, &front, &this_is_front_process);
						(void) SameProcess(&parent, &front, &parent_is_front_process);
					}
				}
								
				if((GetFrontWindowOfClass(kAllWindowClasses, true) != NULL) && (front_window == NULL))
				{
					// Opening the first window
					
					if(window_hack_state == 0)
					{
						// Next time through the event loop, lower the window group layer
						window_hack_state = 1;
					}

					if(layer_group)
					{
						SetWindowGroup(GetFrontWindowOfClass(kAllWindowClasses, true), layer_group);
					}
					
					if(parent_is_front_process)
					{
						// Bring this process's windows to the front.
						(void) SetFrontProcess( &self );
					}

					ActivateWindow(GetFrontWindowOfClass(kAllWindowClasses, true), true);
				}
				else if((GetFrontWindowOfClass(kAllWindowClasses, true) == NULL) && (front_window != NULL))
				{
					// Closing the last window
					
					if(this_is_front_process)
					{
						// Try to bring this process's parent to the front
						(void) SetFrontProcess(&parent);
					}
				}
				else if(window_hack_state == 1)
				{
					if(layer_group)
					{
						// Set the window group level back to something less extreme
						SetWindowGroupLevel(layer_group, kCGNormalWindowLevel);
					}
					window_hack_state = 2;
				}

				front_window = GetFrontWindowOfClass(kAllWindowClasses, true);

			}
		}
#endif
		F64 elapsed = timer.getElapsedTimeF64();
		F64 remaining = plugin->getSleepTime() - elapsed;

		if(remaining <= 0.0f)
		{
			// We've already used our full allotment.
//			LL_INFOS("slplugin") << "elapsed = " << elapsed * 1000.0f << " ms, remaining = " << remaining * 1000.0f << " ms, not sleeping" << LL_ENDL;

			// Still need to service the network...
			plugin->pump();
		}
		else
		{

//			LL_INFOS("slplugin") << "elapsed = " << elapsed * 1000.0f << " ms, remaining = " << remaining * 1000.0f << " ms, sleeping for " << remaining * 1000.0f << " ms" << LL_ENDL;
//			timer.reset();

			// This also services the network as needed.
			plugin->sleep(remaining);

//			LL_INFOS("slplugin") << "slept for "<< timer.getElapsedTimeF64() * 1000.0f << " ms" <<  LL_ENDL;
		}

#if LL_WINDOWS
	// More agressive checking of interfering exception handlers.
	// Doesn't appear to be required so far - even for plugins
	// that do crash with a single call to the intercept
	// exception handler such as QuickTime.
	//checkExceptionHandler();
#endif

#if LL_DARWIN
		deleteAutoReleasePool();
#endif
	}

	delete plugin;

	ll_cleanup_apr();

	return 0;
}
示例#6
0
void
COSXScreen::handleSystemEvent(const CEvent& event, void*)
{
	EventRef* carbonEvent = reinterpret_cast<EventRef*>(event.getData());
	assert(carbonEvent != NULL);

	UInt32 eventClass = GetEventClass(*carbonEvent);

	switch (eventClass) {
	case kEventClassMouse:
		switch (GetEventKind(*carbonEvent)) {
		case kEventMouseDown:
		{
			UInt16 myButton;
			GetEventParameter(*carbonEvent,
					kEventParamMouseButton,
					typeMouseButton,
					NULL,
					sizeof(myButton),
					NULL,
					&myButton);
			onMouseButton(true, myButton);
			break;
		}

		case kEventMouseUp:
		{
			UInt16 myButton;
			GetEventParameter(*carbonEvent,
					kEventParamMouseButton,
					typeMouseButton,
					NULL,
					sizeof(myButton),
					NULL,
					&myButton);
			onMouseButton(false, myButton);
			break;
		}

		case kEventMouseDragged:
		case kEventMouseMoved:
		{
			HIPoint point;
			GetEventParameter(*carbonEvent,
					kEventParamMouseLocation,
					typeHIPoint,
					NULL,
					sizeof(point),
					NULL,
					&point);
			onMouseMove((SInt32)point.x, (SInt32)point.y);
			break;
		}

		case kEventMouseWheelMoved:
		{
			EventMouseWheelAxis axis;
			SInt32 delta;
			GetEventParameter(*carbonEvent,
					kEventParamMouseWheelAxis,
					typeMouseWheelAxis,
					NULL,
					sizeof(axis),
					NULL,
					&axis);
			if (axis == kEventMouseWheelAxisX ||
				axis == kEventMouseWheelAxisY) {
				GetEventParameter(*carbonEvent,
					kEventParamMouseWheelDelta,
					typeLongInteger,
					NULL,
					sizeof(delta),
					NULL,
					&delta);
				if (axis == kEventMouseWheelAxisX) {
					onMouseWheel(-mapScrollWheelToSynergy((SInt32)delta), 0);
				}
				else {
					onMouseWheel(0, mapScrollWheelToSynergy((SInt32)delta));
				}
			}
			break;
		}

		case kSynergyEventMouseScroll:
		{
			OSStatus r;
			long xScroll;
			long yScroll;

			// get scroll amount
			r = GetEventParameter(*carbonEvent,
					kSynergyMouseScrollAxisX,
					typeLongInteger,
					NULL,
					sizeof(xScroll),
					NULL,
					&xScroll);
			if (r != noErr) {
				xScroll = 0;
			}
			r = GetEventParameter(*carbonEvent,
					kSynergyMouseScrollAxisY,
					typeLongInteger,
					NULL,
					sizeof(yScroll),
					NULL,
					&yScroll);
			if (r != noErr) {
				yScroll = 0;
			}

			if (xScroll != 0 || yScroll != 0) {
				onMouseWheel(-mapScrollWheelToSynergy(xScroll),
								mapScrollWheelToSynergy(yScroll));
			}
		}
		}
		break;

	case kEventClassKeyboard: 
		switch (GetEventKind(*carbonEvent)) {
		case kEventRawKeyUp:
		case kEventRawKeyDown:
		case kEventRawKeyRepeat:
		case kEventRawKeyModifiersChanged:
			onKey(*carbonEvent);
			break;

		case kEventHotKeyPressed:
		case kEventHotKeyReleased:
			onHotKey(*carbonEvent);
			break;
		}

		break;

	case kEventClassWindow:
		SendEventToWindow(*carbonEvent, m_userInputWindow);
		switch (GetEventKind(*carbonEvent)) {
		case kEventWindowActivated:
			LOG((CLOG_DEBUG1 "window activated"));
			break;

		case kEventWindowDeactivated:
			LOG((CLOG_DEBUG1 "window deactivated"));
			break;

		case kEventWindowFocusAcquired:
			LOG((CLOG_DEBUG1 "focus acquired"));
			break;

		case kEventWindowFocusRelinquish:
			LOG((CLOG_DEBUG1 "focus released"));
			break;
		}
		break;

	default:
		SendEventToEventTarget(*carbonEvent, GetEventDispatcherTarget());
		break;
	}
}