Add a focus
event to BrowserWindow
- Tested in OSX - Untested in GTK, but I expect it should work - Did not see any similar constructs for notifications in Windows
This commit is contained in:
parent
9721c4e761
commit
b08ec402d2
9 changed files with 27 additions and 0 deletions
|
@ -95,6 +95,10 @@ void Window::OnWindowBlur() {
|
||||||
Emit("blur");
|
Emit("blur");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::OnWindowFocus() {
|
||||||
|
Emit("focus");
|
||||||
|
}
|
||||||
|
|
||||||
void Window::OnRendererUnresponsive() {
|
void Window::OnRendererUnresponsive() {
|
||||||
Emit("unresponsive");
|
Emit("unresponsive");
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ class Window : public mate::EventEmitter,
|
||||||
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
|
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
|
||||||
virtual void OnWindowClosed() OVERRIDE;
|
virtual void OnWindowClosed() OVERRIDE;
|
||||||
virtual void OnWindowBlur() OVERRIDE;
|
virtual void OnWindowBlur() OVERRIDE;
|
||||||
|
virtual void OnWindowFocus() OVERRIDE;
|
||||||
virtual void OnRendererUnresponsive() OVERRIDE;
|
virtual void OnRendererUnresponsive() OVERRIDE;
|
||||||
virtual void OnRendererResponsive() OVERRIDE;
|
virtual void OnRendererResponsive() OVERRIDE;
|
||||||
|
|
||||||
|
|
|
@ -368,6 +368,10 @@ void NativeWindow::NotifyWindowBlur() {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::NotifyWindowFocus() {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowFocus());
|
||||||
|
}
|
||||||
|
|
||||||
// In atom-shell all reloads and navigations started by renderer process would
|
// In atom-shell all reloads and navigations started by renderer process would
|
||||||
// be redirected to this method, so we can have precise control of how we
|
// be redirected to this method, so we can have precise control of how we
|
||||||
// would open the url (in our case, is to restart the renderer process). See
|
// would open the url (in our case, is to restart the renderer process). See
|
||||||
|
|
|
@ -177,6 +177,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
// related notifications.
|
// related notifications.
|
||||||
void NotifyWindowClosed();
|
void NotifyWindowClosed();
|
||||||
void NotifyWindowBlur();
|
void NotifyWindowBlur();
|
||||||
|
void NotifyWindowFocus();
|
||||||
|
|
||||||
void AddObserver(NativeWindowObserver* obs) {
|
void AddObserver(NativeWindowObserver* obs) {
|
||||||
observers_.AddObserver(obs);
|
observers_.AddObserver(obs);
|
||||||
|
|
|
@ -492,6 +492,11 @@ gboolean NativeWindowGtk::OnWindowDeleteEvent(GtkWidget* widget,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean NativeWindowGtk::OnFocusIn(GtkWidget* window, GdkEventFocus*) {
|
||||||
|
NotifyWindowFocus();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean NativeWindowGtk::OnFocusOut(GtkWidget* window, GdkEventFocus*) {
|
gboolean NativeWindowGtk::OnFocusOut(GtkWidget* window, GdkEventFocus*) {
|
||||||
NotifyWindowBlur();
|
NotifyWindowBlur();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -101,6 +101,7 @@ class NativeWindowGtk : public NativeWindow,
|
||||||
|
|
||||||
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowDeleteEvent,
|
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowDeleteEvent,
|
||||||
GdkEvent*);
|
GdkEvent*);
|
||||||
|
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnFocusIn, GdkEventFocus*);
|
||||||
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnFocusOut, GdkEventFocus*);
|
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnFocusOut, GdkEventFocus*);
|
||||||
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowState,
|
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowState,
|
||||||
GdkEventWindowState*);
|
GdkEventWindowState*);
|
||||||
|
|
|
@ -48,6 +48,10 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||||
acceptsFirstMouse_ = accept;
|
acceptsFirstMouse_ = accept;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)windowDidBecomeMain:(NSNotification*)notification {
|
||||||
|
shell_->NotifyWindowFocus();
|
||||||
|
}
|
||||||
|
|
||||||
- (void)windowDidResignMain:(NSNotification*)notification {
|
- (void)windowDidResignMain:(NSNotification*)notification {
|
||||||
shell_->NotifyWindowBlur();
|
shell_->NotifyWindowBlur();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ class NativeWindowObserver {
|
||||||
// Called when window loses focus.
|
// Called when window loses focus.
|
||||||
virtual void OnWindowBlur() {}
|
virtual void OnWindowBlur() {}
|
||||||
|
|
||||||
|
// Called when window gains focus.
|
||||||
|
virtual void OnWindowFocus() {}
|
||||||
|
|
||||||
// Called when renderer is hung.
|
// Called when renderer is hung.
|
||||||
virtual void OnRendererUnresponsive() {}
|
virtual void OnRendererUnresponsive() {}
|
||||||
|
|
||||||
|
|
|
@ -134,6 +134,10 @@ Emitted when the unresponsive web page becomes responsive again.
|
||||||
|
|
||||||
Emitted when window loses focus.
|
Emitted when window loses focus.
|
||||||
|
|
||||||
|
### Event: 'focus'
|
||||||
|
|
||||||
|
Emitted when window gains focus.
|
||||||
|
|
||||||
### Class Method: BrowserWindow.getAllWindows()
|
### Class Method: BrowserWindow.getAllWindows()
|
||||||
|
|
||||||
Returns an array of all opened browser windows.
|
Returns an array of all opened browser windows.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue