Skip to content

Commit b542877

Browse files
committed
Call Focus and Blur only for devtools
Fix nwjs#1387
1 parent 2b7de41 commit b542877

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/api/window/window.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ void Window::Call(const std::string& method,
203203
shell_->window()->Minimize();
204204
} else if (method == "Restore") {
205205
shell_->window()->Restore();
206+
} else if (method == "Focus") {
207+
shell_->window()->Focus(true);
208+
} else if (method == "Blur") {
209+
shell_->window()->Focus(false);
206210
} else if (method == "EnterFullscreen") {
207211
shell_->window()->SetFullscreen(true);
208212
} else if (method == "LeaveFullscreen") {

src/api/window_bindings.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,21 @@ Window.prototype.resizeBy = function(width, height) {
266266
}
267267

268268
Window.prototype.focus = function(flag) {
269-
if (typeof flag == 'undefined' || Boolean(flag))
270-
this.window.focus();
271-
else
269+
if (typeof flag == 'undefined' || Boolean(flag)) {
270+
if (this.__nw_is_devtools)
271+
CallObjectMethod(this, 'Focus', []);
272+
else
273+
this.window.focus();
274+
} else
272275
this.blur();
273-
}
276+
};
274277

275278
Window.prototype.blur = function() {
276-
this.window.blur();
277-
}
279+
if (this.__nw_is_devtools)
280+
CallObjectMethod(this, 'Blur', []);
281+
else
282+
this.window.blur();
283+
};
278284

279285
Window.prototype.show = function(flag) {
280286
if (typeof flag == 'undefined' || Boolean(flag))
@@ -351,8 +357,10 @@ Window.prototype.showDevTools = function(frm, headless) {
351357
var ret;
352358
if (typeof win_id == 'number' && win_id > 0) {
353359
ret = global.__nwWindowsStore[win_id];
354-
if (!ret)
360+
if (!ret) {
355361
ret = new global.Window(this.window.nwDispatcher.getRoutingIDForCurrentContext(), true, win_id);
362+
ret.__nw_is_devtools = true;
363+
}
356364
return ret;
357365
}
358366
}

0 commit comments

Comments
 (0)