diff --git a/docs/changes.md b/docs/changes.md index 5f79ec67e..904bd163a 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,7 +1,10 @@ # 最新动态 +2024/12/13 + * 增加EVT\_NATIVE\_WINDOW\_FOCUS\_GAINED(感谢兆坤提供补丁) + 2024/12/10 - * 修复scroll_bar_d不指定max时控件内的dragger不显示的问题(感谢雨欣提供补丁) + * 修复scroll\_bar\_d不指定max时控件内的dragger不显示的问题(感谢雨欣提供补丁) * 修复 dialog 对话框在退出过程中还会被传递事件的问题 (感谢高源提供补丁) 2024/12/08 diff --git a/src/base/native_window.h b/src/base/native_window.h index 65e0c15be..dfba9e1d0 100644 --- a/src/base/native_window.h +++ b/src/base/native_window.h @@ -343,6 +343,7 @@ typedef enum _native_window_event_type_t { EVT_NATIVE_WINDOW_DESTROY, EVT_NATIVE_WINDOW_ENTER, EVT_NATIVE_WINDOW_LEAVE, + EVT_NATIVE_WINDOW_FOCUS_GAINED, EVT_NATIVE_WINDOW_FOCUS_LOST, } native_window_event_type_t; diff --git a/src/main_loop/main_loop_sdl.c b/src/main_loop/main_loop_sdl.c index 6c76c3b4c..a094fd9c5 100644 --- a/src/main_loop/main_loop_sdl.c +++ b/src/main_loop/main_loop_sdl.c @@ -302,9 +302,14 @@ static ret_t main_loop_sdl2_dispatch_window_event(main_loop_simple_t* loop, SDL_ window_manager_dispatch_native_window_event(l->wm, &e, win); break; } - case SDL_WINDOWEVENT_FOCUS_GAINED: + case SDL_WINDOWEVENT_FOCUS_GAINED: { + event_t e = event_init(EVT_NATIVE_WINDOW_FOCUS_GAINED, NULL); + SDL_Window* win = SDL_GetWindowFromID(event->window.windowID); + log_debug("Window %d gained keyboard focus\n", event->window.windowID); + window_manager_dispatch_native_window_event(l->wm, &e, win); break; + } case SDL_WINDOWEVENT_FOCUS_LOST: { event_t e = event_init(EVT_NATIVE_WINDOW_FOCUS_LOST, NULL); SDL_Window* win = SDL_GetWindowFromID(event->window.windowID); diff --git a/src/window_manager/window_manager_default.c b/src/window_manager/window_manager_default.c index f32fe6c4a..0a19ec03e 100644 --- a/src/window_manager/window_manager_default.c +++ b/src/window_manager/window_manager_default.c @@ -1885,8 +1885,11 @@ static ret_t window_manager_default_dispatch_native_window_event(widget_t* widge input_device_status_on_pointer_enter(ids, widget, x, y); } else if (e->type == EVT_NATIVE_WINDOW_LEAVE) { input_device_status_on_pointer_leave(ids, widget); + } else if (e->type == EVT_NATIVE_WINDOW_FOCUS_GAINED) { + widget_dispatch_simple_event(widget, EVT_FOCUS); } else if (e->type == EVT_NATIVE_WINDOW_FOCUS_LOST) { input_device_status_abort_keys_and_mouse(ids); + widget_dispatch_simple_event(widget, EVT_BLUR); } return RET_OK;