Exemple #1
0
static void
_ibus_input_ctx_forward_key_event(void *data, const Eldbus_Message *msg)
{
   unsigned int val, code, modifiers, state = WL_KEYBOARD_KEY_STATE_PRESSED;

   _check_message_errors(msg);

   if (!eldbus_message_arguments_get(msg, "uuu", &val, &code, &modifiers))
     {
        ERR("Error reading message arguments");
        return;
     }

   if (modifiers & IBUS_RELEASE_MASK)
      state = WL_KEYBOARD_KEY_STATE_RELEASED;

   wl_input_method_context_keysym(wkb_ibus->input_ctx->wl_ctx,
                                  wkb_ibus->input_ctx->serial,
                                  0, val, state, modifiers);
}
Exemple #2
0
static void
keyboard_handle_key(struct keyboard *keyboard, uint32_t time, const struct key *key, struct input *input, enum wl_pointer_button_state state)
{
	const char *label = keyboard->state == keyboardstate_default ? key->label : key->alt;
	xkb_mod_mask_t mod_mask = keyboard->state == keyboardstate_default ? 0 : keyboard->keyboard->keysym.shift_mask;
	uint32_t key_state = (state == WL_POINTER_BUTTON_STATE_PRESSED) ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED;

	switch (key->key_type) {
		case keytype_default:
			if (state != WL_POINTER_BUTTON_STATE_PRESSED)
				break;

			keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string,
								    label);
			virtual_keyboard_send_preedit(keyboard->keyboard, -1);
			break;
		case keytype_backspace:
			if (state != WL_POINTER_BUTTON_STATE_PRESSED)
				break;

			if (strlen(keyboard->keyboard->preedit_string) == 0) {
				delete_before_cursor(keyboard->keyboard);
			} else {
				keyboard->keyboard->preedit_string[strlen(keyboard->keyboard->preedit_string) - 1] = '\0';
				virtual_keyboard_send_preedit(keyboard->keyboard, -1);
			}
			break;
		case keytype_enter:
			virtual_keyboard_commit_preedit(keyboard->keyboard);
			wl_input_method_context_keysym(keyboard->keyboard->context,
						       display_get_serial(keyboard->keyboard->display),
						       time, 
						       XKB_KEY_Return, key_state, mod_mask);
			break;
		case keytype_space:
			if (state != WL_POINTER_BUTTON_STATE_PRESSED)
				break;
			keyboard->keyboard->preedit_string = strcat(keyboard->keyboard->preedit_string,
								    " ");
			virtual_keyboard_commit_preedit(keyboard->keyboard);
			break;
		case keytype_switch:
			if (state != WL_POINTER_BUTTON_STATE_PRESSED)
				break;
			if (keyboard->state == keyboardstate_default)
				keyboard->state = keyboardstate_uppercase;
			else
				keyboard->state = keyboardstate_default;
			break;
		case keytype_symbols:
			if (state != WL_POINTER_BUTTON_STATE_PRESSED)
				break;
			break;
		case keytype_tab:
			virtual_keyboard_commit_preedit(keyboard->keyboard);
			wl_input_method_context_keysym(keyboard->keyboard->context,
						       display_get_serial(keyboard->keyboard->display),
						       time, 
						       XKB_KEY_Tab, key_state, mod_mask);
			break;
		case keytype_arrow_up:
			virtual_keyboard_commit_preedit(keyboard->keyboard);
			wl_input_method_context_keysym(keyboard->keyboard->context,
						       display_get_serial(keyboard->keyboard->display),
						       time, 
						       XKB_KEY_Up, key_state, mod_mask);
			break;
		case keytype_arrow_left:
			virtual_keyboard_commit_preedit(keyboard->keyboard);
			wl_input_method_context_keysym(keyboard->keyboard->context,
						       display_get_serial(keyboard->keyboard->display),
						       time, 
						       XKB_KEY_Left, key_state, mod_mask);
			break;
		case keytype_arrow_right:
			virtual_keyboard_commit_preedit(keyboard->keyboard);
			wl_input_method_context_keysym(keyboard->keyboard->context,
						       display_get_serial(keyboard->keyboard->display),
						       time, 
						       XKB_KEY_Right, key_state, mod_mask);
			break;
		case keytype_arrow_down:
			virtual_keyboard_commit_preedit(keyboard->keyboard);
			wl_input_method_context_keysym(keyboard->keyboard->context,
						       display_get_serial(keyboard->keyboard->display),
						       time, 
						       XKB_KEY_Down, key_state, mod_mask);
			break;
		case keytype_style:
			if (state != WL_POINTER_BUTTON_STATE_PRESSED)
				break;
			keyboard->keyboard->preedit_style = (keyboard->keyboard->preedit_style + 1) % 8; /* TODO */
			virtual_keyboard_send_preedit(keyboard->keyboard, -1);
			break;
	}
}