From fc9954d9672c54b7538c4742b6124f9d75e9f180 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 4 Jun 2016 17:24:46 +0200 Subject: [PATCH] Create window_focused callback --- ui/drivers/cocoa/ui_cocoa_window.m | 10 ++++++++++ ui/drivers/null/ui_null_window.c | 6 ++++++ ui/drivers/win32/ui_win32_window.c | 7 +++++++ ui/ui_companion_driver.h | 1 + 4 files changed, 24 insertions(+) diff --git a/ui/drivers/cocoa/ui_cocoa_window.m b/ui/drivers/cocoa/ui_cocoa_window.m index cb0d3361e0..29264ab798 100644 --- a/ui/drivers/cocoa/ui_cocoa_window.m +++ b/ui/drivers/cocoa/ui_cocoa_window.m @@ -70,11 +70,21 @@ void ui_window_cocoa_set_droppable(void *data, bool droppable) } } +bool ui_window_cocoa_focused(void *data) +{ + ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data; + CocoaView *cocoa_view = (CocoaView*)cocoa->data; + if ([[cocoa_view window] isMainWindow] == YES) + return true; + return false; +} + const ui_window_t ui_window_cocoa = { ui_window_cocoa_destroy, ui_window_cocoa_set_focused, ui_window_cocoa_set_visible, ui_window_cocoa_set_title, ui_window_cocoa_set_droppable, + ui_window_cocoa_focused, "cocoa" }; diff --git a/ui/drivers/null/ui_null_window.c b/ui/drivers/null/ui_null_window.c index 8298ef118c..9a26741397 100644 --- a/ui/drivers/null/ui_null_window.c +++ b/ui/drivers/null/ui_null_window.c @@ -42,11 +42,17 @@ static void ui_window_null_set_droppable(void *data, bool droppable) { } +static bool ui_window_null_focused(void *data) +{ + return true; +} + const ui_window_t ui_window_null = { ui_window_null_destroy, ui_window_null_set_focused, ui_window_null_set_visible, ui_window_null_set_title, ui_window_null_set_droppable, + ui_window_null_focused, "null" }; diff --git a/ui/drivers/win32/ui_win32_window.c b/ui/drivers/win32/ui_win32_window.c index b8f1495f50..ae50eb0540 100644 --- a/ui/drivers/win32/ui_win32_window.c +++ b/ui/drivers/win32/ui_win32_window.c @@ -79,11 +79,18 @@ void ui_window_win32_set_droppable(void *data, bool droppable) DragAcceptFiles(window->hwnd, droppable); } +bool ui_window_win32_focused(void *data) +{ + ui_window_win32_t *window = (ui_window_win32_t*)data; + return (GetForeGroundWindow() == window->hwnd); +} + const ui_window_t ui_window_win32 = { ui_window_win32_destroy, ui_window_win32_set_focused, ui_window_win32_set_visible, ui_window_win32_set_title, ui_window_win32_set_droppable, + ui_window_win32_focused, "win32" }; diff --git a/ui/ui_companion_driver.h b/ui/ui_companion_driver.h index 9113b9ef88..dafeb1c774 100644 --- a/ui/ui_companion_driver.h +++ b/ui/ui_companion_driver.h @@ -38,6 +38,7 @@ typedef struct ui_window void (*set_visible)(void *data, bool visible); void (*set_title)(void *data, char *buf); void (*set_droppable)(void *data, bool droppable); + bool (*focused)(void *data); const char *ident; } ui_window_t;