Beispiel #1
0
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
  // MACRODOWN only works in this function
    switch(id) {
        case 0 ... END_UC:
            if (record->event.pressed) {
                send_unicode(unicode_chars[id]);
            }
            break;
        case M_CSA_SFT:
            // BÉPO over CSA: toggle shift layer
            layer_invert(LR_CSA_SFT);
            if (record->event.pressed) {
                hold_shift();
            } else {
                release_shift();
            }
            break;
        case M_CSA_SFT_AGR:
            // BÉPO over CSA: from shift layer, momentary altgr+shift layer
            layer_invert(LR_CSA_AGR);
            layer_invert(LR_CSA_AGR_SFT);
            if (record->event.pressed) {
                // shift not needed for LR_CSA_AGR_SFT
                release_shift();
            } else {
                // back to shift layer
                hold_shift();
            }
            break;
        case M_CSA_AGR_SFT:
            // BÉPO over CSA: from altgr layer, momentary altgr+shift layer
            layer_invert(LR_CSA_SFT);
            layer_invert(LR_CSA_AGR_SFT);
            break;
        case M_1 ... M_0:
        case M_DEGR:
        case M_SCLN:
        case M_GRV:
        case M_NBSP:
            // macros of the shift layer that require to release shift
            if (record->event.pressed) {
                release_shift();
                switch (id) {
                    case M_1 ... M_0:
                        register_code(KC_1 + (id - M_1));
                        break;
                    case M_DEGR:
                        return MACRO(DOWN(CSA_ALTGR), D(SCLN), END);
                    case M_SCLN:
                        return MACRO(D(SCLN), END);
                    case M_GRV:
                        return MACRO(I(75), DOWN(CSA_ALTGR), TYPE(CSA_DCRC), UP(CSA_ALTGR), T(SPACE), END);
                    case M_NBSP:
                        // use weak mod such that pressing another key will not be affected
                        add_weak_mods(MOD_BIT(CSA_ALTGR));
                        return MACRO(D(SPACE), END);
                }
            } else {
Beispiel #2
0
static void sdlPollInput(void)
{
	static int buttonState=0;
	static int pressure = 0;
	SDL_Event event;

	//printf("sdlPollInput() %d\n", SDL_GetTicks());

	while ( SDL_PollEvent(&event) ) {
		switch (event.type) {
			case SDL_MOUSEMOTION:
				//printf("SDL_MOUSEMOTION pressure %d\n", pressure);
				KdEnqueuePointerEvent(sdlPointer, mouseState, event.motion.x, event.motion.y, pressure);
				break;
			case SDL_MOUSEBUTTONDOWN:
				switch(event.button.button)
				{
					case SDL_BUTTON_LEFT:
						buttonState = KD_BUTTON_1;
						break;
					case SDL_BUTTON_MIDDLE:
						buttonState = KD_BUTTON_2;
						break;
					case SDL_BUTTON_RIGHT:
						buttonState = KD_BUTTON_3;
						break;
					case SDL_BUTTON_WHEELUP:
						buttonState = KD_BUTTON_4;
						break;
					case SDL_BUTTON_WHEELDOWN:
						buttonState = KD_BUTTON_5;
						break;
					/*
					case SDL_BUTTON_X1:
						buttonState = KD_BUTTON_6;
						break;
					case SDL_BUTTON_X2:
						buttonState = KD_BUTTON_7;
						break;
					*/
					default:
						buttonState = 1 << (event.button.button - 1);
						break;
				}
				mouseState |= buttonState;
				KdEnqueuePointerEvent(sdlPointer, mouseState|KD_MOUSE_DELTA, 0, 0, pressure);
				break;
			case SDL_MOUSEBUTTONUP:
				switch(event.button.button)
				{
					case SDL_BUTTON_LEFT:
						buttonState = KD_BUTTON_1;
						pressure = 0;
						break;
					case SDL_BUTTON_MIDDLE:
						buttonState = KD_BUTTON_2;
						break;
					case SDL_BUTTON_RIGHT:
						buttonState = KD_BUTTON_3;
						break;
					case SDL_BUTTON_WHEELUP:
						buttonState = KD_BUTTON_4;
						break;
					case SDL_BUTTON_WHEELDOWN:
						buttonState = KD_BUTTON_5;
						break;
					/*
					case SDL_BUTTON_X1:
						buttonState = KD_BUTTON_6;
						break;
					case SDL_BUTTON_X2:
						buttonState = KD_BUTTON_7;
						break;
					*/
					default:
						buttonState = 1 << (event.button.button - 1);
						break;
				}
				mouseState &= ~buttonState;
				KdEnqueuePointerEvent(sdlPointer, mouseState|KD_MOUSE_DELTA, 0, 0, pressure);
				break;
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				//printf("Key sym %d scancode %d unicode %d", event.key.keysym.sym, event.key.keysym.scancode, event.key.keysym.unicode);
#ifdef __ANDROID__
				if (event.key.keysym.sym == SDLK_HELP)
				{
					if(event.type == SDL_KEYUP)
						SDL_ANDROID_ToggleScreenKeyboardWithoutTextInput();
				}
				else
#endif
				if (event.key.keysym.sym == SDLK_UNDO)
				{
					if(event.type == SDL_KEYUP)
					{
						// Send Ctrl-Z
						KdEnqueueKeyboardEvent (sdlKeyboard, 37, 0); // LCTRL
						KdEnqueueKeyboardEvent (sdlKeyboard, 52, 0); // Z
						KdEnqueueKeyboardEvent (sdlKeyboard, 52, 1); // Z
						KdEnqueueKeyboardEvent (sdlKeyboard, 37, 1); // LCTRL
					}
				}
/*
 * On some platforms (OSX) keystrokes like (Alt-X) have a unicode
 * character associated with them: ≈.
 * OSX makes the choice to propagate this character with key events.
 * Multi-byte IMEs likely do the same, but without a keycode.
 *
 * The Android port this was based on uses the approach of shelling
 * out to xset using the clipboard as a mechanism to emit unicode reliably.
 * Unfortunately our NaCl port doesn't yet have this utility.
 * Additionally, even if it did, it is unclear if passing along all unicode
 * this way is desirable, as for instance this blocks Emacs from receiving
 * Alt-X. For Android it was clear cut that using the Android IME would be
 * preferred over the remote one, but this is less clear on the desktop.
 *
 * Sending only raw key codes for now.
 */
#if !defined(__native_client__)
				else if((event.key.keysym.unicode & 0xFF80) != 0)
				{
					send_unicode (event.key.keysym.unicode);
				}
#endif
				else
					KdEnqueueKeyboardEvent (sdlKeyboard, event.key.keysym.scancode, event.type==SDL_KEYUP);
				// Force SDL screen update, so SDL virtual on-screen buttons will change their images
				{
					SDL_Rect r = {0, 0, 1, 1};
					SDL_UpdateRects(SDL_GetVideoSurface(), 1, &r);
				}
				break;
			case SDL_JOYAXISMOTION:
				if (event.jaxis.which == 0 && event.jaxis.axis == 4 && pressure != event.jaxis.value)
				{
					pressure = event.jaxis.value;
					if (mouseState & KD_BUTTON_1)
						KdEnqueuePointerEvent(sdlPointer, mouseState|KD_MOUSE_DELTA, 0, 0, pressure);
				}
				break;
			case SDL_ACTIVEEVENT:
				// We need this to re-init OpenGL and redraw screen
				// And we need to also call this when OpenGL context was destroyed
				// Oherwise SDL will stuck and we will get a permanent black screen
				SDL_Flip(SDL_GetVideoSurface());
				break;
			//case SDL_QUIT:
				/* this should never happen */
				//SDL_Quit(); // SDL_Quit() on Android is buggy
		}
	}
	/*
	if ( nextFullScreenRefresh && nextFullScreenRefresh < SDL_GetTicks() )
	{
		//printf("SDL_Flip from sdlPollInput");
		SDL_Flip(SDL_GetVideoSurface());
		nextFullScreenRefresh = 0;
	}
	*/
}