📄 sdl_quartzevents.m
字号:
unsigned int currentMask, newMask; currentMask = current_mods & bit; newMask = newMods & bit; if ( currentMask && currentMask != newMask ) { /* modifier up event */ key.sym = mapping[i]; /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ if (bit == NSAlphaShiftKeyMask) SDL_PrivateKeyboard (SDL_PRESSED, &key); SDL_PrivateKeyboard (SDL_RELEASED, &key); } else if ( newMask && currentMask != newMask ) { /* modifier down event */ key.sym = mapping[i]; SDL_PrivateKeyboard (SDL_PRESSED, &key); /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ if (bit == NSAlphaShiftKeyMask) SDL_PrivateKeyboard (SDL_RELEASED, &key); } }}/* This is a helper function for QZ_HandleModifierSide. This * function reverts back to behavior before the distinction between * sides was made. */static void QZ_HandleNonDeviceModifier ( _THIS, unsigned int device_independent_mask, unsigned int newMods, unsigned int key_sym) { unsigned int currentMask, newMask; SDL_keysym key; key.scancode = 0; key.sym = key_sym; key.unicode = 0; key.mod = KMOD_NONE; /* Isolate just the bits we care about in the depedent bits so we can * figure out what changed */ currentMask = current_mods & device_independent_mask; newMask = newMods & device_independent_mask; if ( currentMask && currentMask != newMask ) { /* modifier up event */ SDL_PrivateKeyboard (SDL_RELEASED, &key); } else if ( newMask && currentMask != newMask ) { /* modifier down event */ SDL_PrivateKeyboard (SDL_PRESSED, &key); }}/* This is a helper function for QZ_HandleModifierSide. * This function sets the actual SDL_PrivateKeyboard event. */static void QZ_HandleModifierOneSide ( _THIS, unsigned int newMods, unsigned int key_sym, unsigned int sided_device_dependent_mask ) { SDL_keysym key; unsigned int current_dep_mask, new_dep_mask; key.scancode = 0; key.sym = key_sym; key.unicode = 0; key.mod = KMOD_NONE; /* Isolate just the bits we care about in the depedent bits so we can * figure out what changed */ current_dep_mask = current_mods & sided_device_dependent_mask; new_dep_mask = newMods & sided_device_dependent_mask; /* We now know that this side bit flipped. But we don't know if * it went pressed to released or released to pressed, so we must * find out which it is. */ if( new_dep_mask && current_dep_mask != new_dep_mask ) { /* Modifier down event */ SDL_PrivateKeyboard (SDL_PRESSED, &key); } else /* Modifier up event */ { SDL_PrivateKeyboard (SDL_RELEASED, &key); }}/* This is a helper function for QZ_DoSidedModifiers. * This function will figure out if the modifier key is the left or right side, * e.g. left-shift vs right-shift. */static void QZ_HandleModifierSide ( _THIS, int device_independent_mask, unsigned int newMods, unsigned int left_key_sym, unsigned int right_key_sym, unsigned int left_device_dependent_mask, unsigned int right_device_dependent_mask ) { unsigned int device_dependent_mask = 0; unsigned int diff_mod = 0; device_dependent_mask = left_device_dependent_mask | right_device_dependent_mask; /* On the basis that the device independent mask is set, but there are * no device dependent flags set, we'll assume that we can't detect this * keyboard and revert to the unsided behavior. */ if ( (device_dependent_mask & newMods) == 0 ) { /* Revert to the old behavior */ QZ_HandleNonDeviceModifier ( this, device_independent_mask, newMods, left_key_sym ); return; } /* XOR the previous state against the new state to see if there's a change */ diff_mod = (device_dependent_mask & current_mods) ^ (device_dependent_mask & newMods); if ( diff_mod ) { /* A change in state was found. Isolate the left and right bits * to handle them separately just in case the values can simulataneously * change or if the bits don't both exist. */ if ( left_device_dependent_mask & diff_mod ) { QZ_HandleModifierOneSide ( this, newMods, left_key_sym, left_device_dependent_mask ); } if ( right_device_dependent_mask & diff_mod ) { QZ_HandleModifierOneSide ( this, newMods, right_key_sym, right_device_dependent_mask ); } }} /* This is a helper function for QZ_DoSidedModifiers. * This function will release a key press in the case that * it is clear that the modifier has been released (i.e. one side * can't still be down). */static void QZ_ReleaseModifierSide ( _THIS, unsigned int device_independent_mask, unsigned int newMods, unsigned int left_key_sym, unsigned int right_key_sym, unsigned int left_device_dependent_mask, unsigned int right_device_dependent_mask ) { unsigned int device_dependent_mask = 0; SDL_keysym key; key.scancode = 0; key.sym = SDLK_UNKNOWN; key.unicode = 0; key.mod = KMOD_NONE; device_dependent_mask = left_device_dependent_mask | right_device_dependent_mask; /* On the basis that the device independent mask is set, but there are * no device dependent flags set, we'll assume that we can't detect this * keyboard and revert to the unsided behavior. */ if ( (device_dependent_mask & current_mods) == 0 ) { /* In this case, we can't detect the keyboard, so use the left side * to represent both, and release it. */ key.sym = left_key_sym; SDL_PrivateKeyboard (SDL_RELEASED, &key); return; } /* * This could have been done in an if-else case because at this point, * we know that all keys have been released when calling this function. * But I'm being paranoid so I want to handle each separately, * so I hope this doesn't cause other problems. */ if ( left_device_dependent_mask & current_mods ) { key.sym = left_key_sym; SDL_PrivateKeyboard (SDL_RELEASED, &key); } if ( right_device_dependent_mask & current_mods ) { key.sym = right_key_sym; SDL_PrivateKeyboard (SDL_RELEASED, &key); }}/* This is a helper function for QZ_DoSidedModifiers. * This function handles the CapsLock case. */static void QZ_HandleCapsLock (_THIS, unsigned int newMods) { unsigned int currentMask, newMask; SDL_keysym key; key.scancode = 0; key.sym = SDLK_CAPSLOCK; key.unicode = 0; key.mod = KMOD_NONE; currentMask = current_mods & NSAlphaShiftKeyMask; newMask = newMods & NSAlphaShiftKeyMask; if ( currentMask && currentMask != newMask ) { /* modifier up event */ /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ SDL_PrivateKeyboard (SDL_PRESSED, &key); SDL_PrivateKeyboard (SDL_RELEASED, &key); } else if ( newMask && currentMask != newMask ) { /* modifier down event */ /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ SDL_PrivateKeyboard (SDL_PRESSED, &key); SDL_PrivateKeyboard (SDL_RELEASED, &key); }}/* This function will handle the modifier keys and also determine the * correct side of the key. */static void QZ_DoSidedModifiers (_THIS, unsigned int newMods) { /* Set up arrays for the key syms for the left and right side. */ const unsigned int left_mapping[] = { SDLK_LSHIFT, SDLK_LCTRL, SDLK_LALT, SDLK_LMETA }; const unsigned int right_mapping[] = { SDLK_RSHIFT, SDLK_RCTRL, SDLK_RALT, SDLK_RMETA }; /* Set up arrays for the device dependent masks with indices that * correspond to the _mapping arrays */ const unsigned int left_device_mapping[] = { NX_DEVICELSHIFTKEYMASK, NX_DEVICELCTLKEYMASK, NX_DEVICELALTKEYMASK, NX_DEVICELCMDKEYMASK }; const unsigned int right_device_mapping[] = { NX_DEVICERSHIFTKEYMASK, NX_DEVICERCTLKEYMASK, NX_DEVICERALTKEYMASK, NX_DEVICERCMDKEYMASK }; unsigned int i; unsigned int bit; /* Handle CAPSLOCK separately because it doesn't have a left/right side */ QZ_HandleCapsLock ( this, newMods ); /* Iterate through the bits, testing each against the current modifiers */ for (i = 0, bit = NSShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) { unsigned int currentMask, newMask; currentMask = current_mods & bit; newMask = newMods & bit; /* If the bit is set, we must always examine it because the left * and right side keys may alternate or both may be pressed. */ if ( newMask ) { QZ_HandleModifierSide ( this, bit, newMods, left_mapping[i], right_mapping[i], left_device_mapping[i], right_device_mapping[i] ); } /* If the state changed from pressed to unpressed, we must examine * the device dependent bits to release the correct keys. */ else if ( currentMask && currentMask != newMask ) { /* modifier up event */ QZ_ReleaseModifierSide ( this, bit, newMods, left_mapping[i], right_mapping[i], left_device_mapping[i], right_device_mapping[i] ); } }}/* This function is called to handle the modifiers. * It will try to distinguish between the left side and right side * of the keyboard for those modifiers that qualify if the * operating system version supports it. Otherwise, the code * will not try to make the distinction. */static void QZ_DoModifiers (_THIS, unsigned int newMods) { if (current_mods == newMods) return; /* * Starting with Panther (10.3.0), the ability to distinguish between * left side and right side modifiers is available. */ if( system_version >= 0x1030 ) { QZ_DoSidedModifiers (this, newMods); } else { QZ_DoUnsidedModifiers (this, newMods); } current_mods = newMods;}static void QZ_GetMouseLocation (_THIS, NSPoint *p) { *p = [ NSEvent mouseLocation ]; /* global coordinates */ if (qz_window) QZ_PrivateGlobalToLocal (this, p); QZ_PrivateCocoaToSDL (this, p);}void QZ_DoActivate (_THIS) { SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS | (QZ_IsMouseInWindow (this) ? SDL_APPMOUSEFOCUS : 0)); QZ_UpdateCursor(this); /* Regrab input, only if it was previously grabbed */ if ( current_grab_mode == SDL_GRAB_ON ) { /* Restore cursor location if input was grabbed */ QZ_PrivateWarpCursor (this, cursor_loc.x, cursor_loc.y); QZ_ChangeGrabState (this, QZ_ENABLE_GRAB); } else { /* Update SDL's mouse location */ NSPoint p; QZ_GetMouseLocation (this, &p); SDL_PrivateMouseMotion (0, 0, p.x, p.y); }}void QZ_DoDeactivate (_THIS) { SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS | SDL_APPMOUSEFOCUS); /* Get the current cursor location, for restore on activate */ QZ_GetMouseLocation (this, &cursor_loc); /* Reassociate mouse and cursor */ CGAssociateMouseAndMouseCursorPosition (1); QZ_UpdateCursor(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -