mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 20:18:22 +08:00
improve grab keys
This commit is contained in:
parent
6c5e20e17a
commit
8acc665617
@ -256,6 +256,7 @@ static ret_t input_device_status_init_key_event(input_device_status_t* ids, key_
|
||||
}
|
||||
|
||||
ret_t input_device_status_on_input_event(input_device_status_t* ids, widget_t* widget, event_t* e) {
|
||||
window_manager_t* wm = WINDOW_MANAGER(widget_get_window_manager(widget));
|
||||
return_value_if_fail(ids != NULL && e != NULL, RET_BAD_PARAMS);
|
||||
|
||||
ids->widget = widget;
|
||||
@ -316,7 +317,11 @@ ret_t input_device_status_on_input_event(input_device_status_t* ids, widget_t* w
|
||||
input_device_status_shift_key(ids, evt);
|
||||
|
||||
if (info == NULL || !info->should_abort) {
|
||||
widget_on_keydown(widget, evt);
|
||||
if (wm->widget_grab_key != NULL) {
|
||||
widget_on_keydown(wm->widget_grab_key, evt);
|
||||
} else {
|
||||
widget_on_keydown(widget, evt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -328,7 +333,11 @@ ret_t input_device_status_on_input_event(input_device_status_t* ids, widget_t* w
|
||||
input_device_status_shift_key(ids, evt);
|
||||
|
||||
if (info == NULL || !info->should_abort) {
|
||||
widget_on_keyup(widget, evt);
|
||||
if (wm->widget_grab_key != NULL) {
|
||||
widget_on_keyup(wm->widget_grab_key, evt);
|
||||
} else {
|
||||
widget_on_keyup(widget, evt);
|
||||
}
|
||||
}
|
||||
|
||||
input_device_status_update_key_status(ids, evt->key, FALSE);
|
||||
|
@ -1572,11 +1572,27 @@ static ret_t widget_on_grabbed_keys(void* ctx, event_t* e) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static widget_t* widget_get_top_widget_grab_key(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL, NULL);
|
||||
WIDGET_FOR_EACH_CHILD_BEGIN_R(widget, iter, i)
|
||||
value_t v;
|
||||
widget_t* widget_grab_key = widget_get_top_widget_grab_key(iter);
|
||||
if (widget_grab_key == NULL && iter != NULL && iter->visible) {
|
||||
ret_t ret = object_get_prop(iter->custom_props, WIDGET_PROP_GRAB_KEYS, &v);
|
||||
if (ret == RET_OK && value_bool(&v)) {
|
||||
return iter;
|
||||
}
|
||||
}
|
||||
WIDGET_FOR_EACH_CHILD_END();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static ret_t widget_on_ungrab_keys(void* ctx, event_t* e) {
|
||||
widget_t* widget = WIDGET(ctx);
|
||||
window_manager_t* wm = WINDOW_MANAGER(widget_get_window_manager(widget));
|
||||
|
||||
emitter_off_by_tag(wm->global_emitter, tk_pointer_to_int(widget));
|
||||
wm->widget_grab_key = widget_get_top_widget_grab_key(WIDGET(wm));
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
@ -1674,10 +1690,7 @@ ret_t widget_set_prop(widget_t* widget, const char* name, const value_t* v) {
|
||||
|
||||
if (value_bool(v)) {
|
||||
widget_on(widget, EVT_DESTROY, widget_on_ungrab_keys, widget);
|
||||
emitter_on_with_tag(wm->global_emitter, EVT_KEY_DOWN, widget_on_grabbed_keys, widget,
|
||||
tk_pointer_to_int(widget));
|
||||
emitter_on_with_tag(wm->global_emitter, EVT_KEY_UP, widget_on_grabbed_keys, widget,
|
||||
tk_pointer_to_int(widget));
|
||||
wm->widget_grab_key = widget;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,7 @@ typedef struct _window_manager_t {
|
||||
|
||||
/*private*/
|
||||
bool_t show_fps;
|
||||
widget_t* widget_grab_key;
|
||||
bool_t ignore_input_events;
|
||||
bool_t show_waiting_pointer_cursor;
|
||||
const window_manager_vtable_t* vt;
|
||||
|
Loading…
Reference in New Issue
Block a user