From f3c7ce206150fb39bdf32c8061f7c491cfc82026 Mon Sep 17 00:00:00 2001 From: RH12503 <48951973+RH12503@users.noreply.github.com> Date: Sun, 21 Feb 2021 06:11:55 +0800 Subject: [PATCH] Put main window into focus after a dialog closes (#609) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * v1.11.0 (#582) * v1.10.1 * Fix vue template dependencies versions (fixes #574) (#576) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commit e0aab7c27f0fac69efbe02d0870e2972cebcbfe7. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe Co-authored-by: Ilgıt Yıldırım Co-authored-by: Travis McLane Co-authored-by: Altynbek Co-authored-by: Kyle Muchmore Co-authored-by: Balakrishna Prasad Ganne * v1.10.1 (#572) * fix dependencies versions Co-authored-by: Arthur Wiebe Co-authored-by: Lea Anthony Co-authored-by: Ilgıt Yıldırım Co-authored-by: Travis McLane Co-authored-by: Altynbek Co-authored-by: Kyle Muchmore Co-authored-by: Balakrishna Prasad Ganne * v1.11.0-rc1 * v1.11.0-pre1 * Bump ini from 1.3.5 to 1.3.8 in /runtime/js/runtime (#575) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commit e0aab7c27f0fac69efbe02d0870e2972cebcbfe7. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe Co-authored-by: Ilgıt Yıldırım Co-authored-by: Travis McLane Co-authored-by: Altynbek Co-authored-by: Kyle Muchmore Co-authored-by: Balakrishna Prasad Ganne * v1.10.1 (#572) * Bump ini from 1.3.5 to 1.3.8 in /runtime/js/runtime Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8) Signed-off-by: dependabot[bot] Co-authored-by: Arthur Wiebe Co-authored-by: Lea Anthony Co-authored-by: Ilgıt Yıldırım Co-authored-by: Travis McLane Co-authored-by: Altynbek Co-authored-by: Kyle Muchmore Co-authored-by: Balakrishna Prasad Ganne Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump ini from 1.3.5 to 1.3.8 in /runtime/js (#573) * resolve angular routing broken when app is built * Revert "resolve angular routing broken when app is built" This reverts commit e0aab7c27f0fac69efbe02d0870e2972cebcbfe7. * Update issue templates * v1.8.1 (#546) * resolve angular routing broken when app is built * Updated contributors * handle Set error on Update method * Remove incorrect build flag * v1.8.1-pre1 * added Get method * fixed return * implement gopath handling during cross compilation * update messages to output xgo version TODO: allow image override * use wailsapp/xgo:1.0.1 for cross-compiling * Support platform list in templates * Add warnings for windows builds * add fields Tags to ProjectOptions * add args tags to func BuildNative * add tags to func BuildDocker * delete escape tags * Update Contributors * feat: Vue3, Vue Router, Vuex, and Typescript Template * converted spaces to tabs in vue.config.js * single quotes and tabs Converted vue.config.js to using single quotes Converted example.spec.ts to tabs instead of spaces. * Added semicolons and mocha import * Update contributors * Make vue 3 template linux/mac only * Add tags to build * Add v2 artefacts * Update Vuetify in package.json (#537) * Update contributors * Replaced the old v-content tag with the new v-main (#536) * v1.8.1-pre4 * v1.8.1-pre5 * Update issue templates (#541) * Updated Contributors * Remove zero copy string conversion * v1.8.1-pre6 * Initial support for firebug (#543) * Initial support for firebug * Remove windows message * v1.8.1-pre7 * Update contributors * Allow use of custom HTML * Allow use of custom HTML (#545) * v1.8.1 Co-authored-by: Arthur Wiebe Co-authored-by: Ilgıt Yıldırım Co-authored-by: Travis McLane Co-authored-by: Altynbek Co-authored-by: Kyle Muchmore Co-authored-by: Balakrishna Prasad Ganne * v1.10.1 (#572) * Bump ini from 1.3.5 to 1.3.8 in /runtime/js Bumps [ini](https://github.com/isaacs/ini) from 1.3.5 to 1.3.8. - [Release notes](https://github.com/isaacs/ini/releases) - [Commits](https://github.com/isaacs/ini/compare/v1.3.5...v1.3.8) Signed-off-by: dependabot[bot] Co-authored-by: Arthur Wiebe Co-authored-by: Lea Anthony Co-authored-by: Ilgıt Yıldırım Co-authored-by: Travis McLane Co-authored-by: Altynbek Co-authored-by: Kyle Muchmore Co-authored-by: Balakrishna Prasad Ganne Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Remove debug info * v1.11.0-pre2 * Limit v1 updates to v1 * v1.11.0-pre3 * Test fix for linux high CPU usage * v1.11.0 Co-authored-by: Elie Grenon (DrunkenPoney) Co-authored-by: Arthur Wiebe Co-authored-by: Ilgıt Yıldırım Co-authored-by: Travis McLane Co-authored-by: Altynbek Co-authored-by: Kyle Muchmore Co-authored-by: Balakrishna Prasad Ganne Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add Pace to Thanks * Redo thanks section * Put main window into focus after dialogs close Co-authored-by: Lea Anthony Co-authored-by: Elie Grenon (DrunkenPoney) Co-authored-by: Arthur Wiebe Co-authored-by: Ilgıt Yıldırım Co-authored-by: Travis McLane Co-authored-by: Altynbek Co-authored-by: Kyle Muchmore Co-authored-by: Balakrishna Prasad Ganne Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- CONTRIBUTORS.md | 3 ++- README.md | 3 ++- cmd/version.go | 1 + lib/renderer/webview.go | 16 ++++++++++++++++ lib/renderer/webview/webview.go | 12 ++++++++++++ lib/renderer/webview/webview.h | 16 ++++++++++++++++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 68e79c91..c1b5f4aa 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -42,4 +42,5 @@ Wails is what it is because of the time and effort given by these great people. * [misitebao](https://github.com/misitebao) * [Elie Grenon](https://github.com/DrunkenPoney) * [SophieAu](https://github.com/SophieAu) - * [Alexander Matviychuk](https://github.com/alexmat) \ No newline at end of file + * [Alexander Matviychuk](https://github.com/alexmat) + \ No newline at end of file diff --git a/README.md b/README.md index 5c279e02..f6fb2509 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,8 @@ This project was mainly coded to the following albums: ## Special Thanks

- A *huge* thanks to Pace for sponsoring the project and helping the efforts to get Wails ported to Apple Silicon!

+
+ A *huge* thanks to Pace for sponsoring the project and helping the efforts to get Wails ported to Apple Silicon!

If you are looking for a Project Management tool that's powerful but quick and easy to use, check them out!

diff --git a/cmd/version.go b/cmd/version.go index 0a15b77f..721809d5 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -2,3 +2,4 @@ package cmd // Version - Wails version const Version = "v1.12.0-pre4" + diff --git a/lib/renderer/webview.go b/lib/renderer/webview.go index c51e76bc..1c0ff73a 100644 --- a/lib/renderer/webview.go +++ b/lib/renderer/webview.go @@ -256,6 +256,9 @@ func (w *WebView) SelectFile(title string, filter string) string { wg.Done() }) }() + + defer w.focus() // Ensure the main window is put back into focus afterwards + wg.Wait() return result } @@ -274,6 +277,9 @@ func (w *WebView) SelectDirectory() string { wg.Done() }) }() + + defer w.focus() // Ensure the main window is put back into focus afterwards + wg.Wait() return result } @@ -292,10 +298,20 @@ func (w *WebView) SelectSaveFile(title string, filter string) string { wg.Done() }) }() + + defer w.focus() // Ensure the main window is put back into focus afterwards + wg.Wait() return result } +// focus puts the main window into focus +func (w *WebView) focus() { + w.window.Dispatch(func() { + w.window.Focus() + }) +} + // callback sends a callback to the frontend func (w *WebView) callback(data string) error { callbackCMD := fmt.Sprintf("window.wails._.Callback('%s');", data) diff --git a/lib/renderer/webview/webview.go b/lib/renderer/webview/webview.go index e9a760ab..0e5da75c 100755 --- a/lib/renderer/webview/webview.go +++ b/lib/renderer/webview/webview.go @@ -65,6 +65,10 @@ static inline void CgoWebViewSetTitle(void *w, char *title) { webview_set_title((struct webview *)w, title); } +static inline void CgoWebViewFocus(void *w) { + webview_focus((struct webview *)w); +} + static inline void CgoWebViewSetFullscreen(void *w, int fullscreen) { webview_set_fullscreen((struct webview *)w, fullscreen); } @@ -170,6 +174,10 @@ type WebView interface { // SetTitle() changes window title. This method must be called from the main // thread only. See Dispatch() for more details. SetTitle(title string) + + // Focus() puts the main window into focus + Focus() + // SetFullscreen() controls window full-screen mode. This method must be // called from the main thread only. See Dispatch() for more details. SetFullscreen(fullscreen bool) @@ -307,6 +315,10 @@ func (w *webview) SetColor(r, g, b, a uint8) { C.CgoWebViewSetColor(w.w, C.uint8_t(r), C.uint8_t(g), C.uint8_t(b), C.uint8_t(a)) } +func (w *webview) Focus() { + C.CgoWebViewFocus(w.w) +} + func (w *webview) SetFullscreen(fullscreen bool) { C.CgoWebViewSetFullscreen(w.w, C.int(boolToInt(fullscreen))) } diff --git a/lib/renderer/webview/webview.h b/lib/renderer/webview/webview.h index c08cb479..17e0e424 100644 --- a/lib/renderer/webview/webview.h +++ b/lib/renderer/webview/webview.h @@ -168,6 +168,7 @@ struct webview_priv WEBVIEW_API int webview_eval(struct webview *w, const char *js); WEBVIEW_API int webview_inject_css(struct webview *w, const char *css); WEBVIEW_API void webview_set_title(struct webview *w, const char *title); + WEBVIEW_API void webview_focus(struct webview *w); WEBVIEW_API void webview_set_fullscreen(struct webview *w, int fullscreen); WEBVIEW_API void webview_set_color(struct webview *w, uint8_t r, uint8_t g, uint8_t b, uint8_t a); @@ -396,6 +397,11 @@ struct webview_priv gtk_window_set_title(GTK_WINDOW(w->priv.window), title); } + WEBVIEW_API void webview_focus(struct webview *w) + { + gtk_window_present(GTK_WINDOW(w->priv.window)) + } + WEBVIEW_API void webview_set_fullscreen(struct webview *w, int fullscreen) { if (fullscreen) @@ -1641,6 +1647,11 @@ struct webview_priv #endif } + WEBVIEW_API void webview_focus(struct webview *w) + { + SetFocus(w->priv.hwnd); + } + WEBVIEW_API void webview_set_fullscreen(struct webview *w, int fullscreen) { if (w->priv.is_fullscreen == !!fullscreen) @@ -2208,6 +2219,11 @@ struct webview_priv [w->priv.window setTitle:nsTitle]; } + WEBVIEW_API void webview_focus(struct webview *w) + { + [w->priv.window makeKeyWindow]; + } + WEBVIEW_API void webview_set_fullscreen(struct webview *w, int fullscreen) { int b = ((([w->priv.window styleMask] & NSWindowStyleMaskFullScreen) ==