From: David Herrmann Date: Mon, 1 Oct 2012 15:00:58 +0000 (+0200) Subject: wlt: toolkit: notify keyboard-cbs whether a key was handled X-Git-Tag: kmscon-7~417 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c28ea5c9744ebc5a393c974041b79a9aff818965;p=platform%2Fupstream%2Fkmscon.git wlt: toolkit: notify keyboard-cbs whether a key was handled All keyboard-cbs have to return whether they handled a key now. Furthermore, they get as parameter a flag that notifies them whether a previous handled already handled the key. Signed-off-by: David Herrmann --- diff --git a/src/wlt_terminal.c b/src/wlt_terminal.c index 31f792e..06792b3 100644 --- a/src/wlt_terminal.c +++ b/src/wlt_terminal.c @@ -306,14 +306,14 @@ static void widget_prepare_resize(struct wlt_widget *widget, } } -static void widget_key(struct wlt_widget *widget, unsigned int mask, - uint32_t sym, uint32_t state, void *data) +static bool widget_key(struct wlt_widget *widget, unsigned int mask, + uint32_t sym, uint32_t state, bool handled, void *data) { struct wlt_terminal *term = data; uint32_t ucs4; - if (state != WL_KEYBOARD_KEY_STATE_PRESSED) - return; + if (handled || state != WL_KEYBOARD_KEY_STATE_PRESSED) + return false; ucs4 = xkb_keysym_to_utf32(sym) ? : TSM_VTE_INVALID; @@ -321,31 +321,34 @@ static void widget_key(struct wlt_widget *widget, unsigned int mask, sym == wlt_conf.grab_scroll_up->keysym) { tsm_screen_sb_up(term->scr, 1); wlt_window_schedule_redraw(term->wnd); - return; + return true; } if (SHL_HAS_BITS(mask, wlt_conf.grab_scroll_down->mods) && sym == wlt_conf.grab_scroll_down->keysym) { tsm_screen_sb_down(term->scr, 1); wlt_window_schedule_redraw(term->wnd); - return; + return true; } if (SHL_HAS_BITS(mask, wlt_conf.grab_page_up->mods) && sym == wlt_conf.grab_page_up->keysym) { tsm_screen_sb_page_up(term->scr, 1); wlt_window_schedule_redraw(term->wnd); - return; + return true; } if (SHL_HAS_BITS(mask, wlt_conf.grab_page_down->mods) && sym == wlt_conf.grab_page_down->keysym) { tsm_screen_sb_page_down(term->scr, 1); wlt_window_schedule_redraw(term->wnd); - return; + return true; } if (tsm_vte_handle_keyboard(term->vte, sym, mask, ucs4)) { tsm_screen_sb_reset(term->scr); wlt_window_schedule_redraw(term->wnd); + return true; } + + return false; } static void vte_event(struct tsm_vte *vte, const char *u8, size_t len, diff --git a/src/wlt_toolkit.c b/src/wlt_toolkit.c index 88dbde3..e9bd860 100644 --- a/src/wlt_toolkit.c +++ b/src/wlt_toolkit.c @@ -633,6 +633,7 @@ static void keyboard_key(void *data, struct wl_keyboard *keyboard, struct shl_dlist *iter; struct wlt_widget *widget; struct itimerspec spec; + bool handled; disp->last_serial = serial; if (!disp->xkb_state) @@ -648,11 +649,14 @@ static void keyboard_key(void *data, struct wl_keyboard *keyboard, if (num_syms == 1) sym = syms[0]; + handled = false; shl_dlist_for_each(iter, &wnd->widget_list) { widget = shl_dlist_entry(iter, struct wlt_widget, list); - if (widget->keyboard_cb) - widget->keyboard_cb(widget, mask, sym, state, - widget->data); + if (widget->keyboard_cb) { + if (widget->keyboard_cb(widget, mask, sym, state, + handled, widget->data)) + handled = true; + } } if (state == WL_KEYBOARD_KEY_STATE_RELEASED && @@ -675,17 +679,21 @@ static void repeat_event(struct ev_timer *timer, uint64_t num, void *data) struct wlt_widget *widget; struct shl_dlist *iter; unsigned int mask; + bool handled; if (!wnd) return; mask = shl_get_xkb_mods(disp->xkb_state); + handled = false; shl_dlist_for_each(iter, &wnd->widget_list) { widget = shl_dlist_entry(iter, struct wlt_widget, list); - if (widget->keyboard_cb) - widget->keyboard_cb(widget, mask, disp->repeat_sym, - WL_KEYBOARD_KEY_STATE_PRESSED, - widget->data); + if (widget->keyboard_cb) { + if (widget->keyboard_cb(widget, mask, disp->repeat_sym, + WL_KEYBOARD_KEY_STATE_PRESSED, + handled, widget->data)) + handled = true; + } } } diff --git a/src/wlt_toolkit.h b/src/wlt_toolkit.h index f3d4140..01d557b 100644 --- a/src/wlt_toolkit.h +++ b/src/wlt_toolkit.h @@ -112,10 +112,11 @@ typedef void (*wlt_widget_pointer_button_cb) (struct wlt_widget *widget, uint32_t button, uint32_t state, void *data); -typedef void (*wlt_widget_keyboard_cb) (struct wlt_widget *widget, +typedef bool (*wlt_widget_keyboard_cb) (struct wlt_widget *widget, unsigned int mods, uint32_t key, uint32_t state, + bool handled, void *data); int wlt_display_new(struct wlt_display **out,