Merge pull request #5888 from electron/linux-focus
Fix NativeWindow::Focus not moving focus to window
This commit is contained in:
commit
3e809901e0
1 changed files with 26 additions and 2 deletions
|
@ -89,6 +89,21 @@ bool IsAltModifier(const content::NativeWebKeyboardEvent& event) {
|
|||
(modifiers == (Modifiers::AltKey | Modifiers::IsRight));
|
||||
}
|
||||
|
||||
#if defined(USE_X11)
|
||||
int SendClientEvent(XDisplay* display, ::Window window, const char* msg) {
|
||||
XEvent event = {};
|
||||
event.xclient.type = ClientMessage;
|
||||
event.xclient.send_event = True;
|
||||
event.xclient.message_type = XInternAtom(display, msg, False);
|
||||
event.xclient.window = window;
|
||||
event.xclient.format = 32;
|
||||
XSendEvent(display, DefaultRootWindow(display), False,
|
||||
SubstructureRedirectMask | SubstructureNotifyMask, &event);
|
||||
XFlush(display);
|
||||
return True;
|
||||
}
|
||||
#endif
|
||||
|
||||
class NativeWindowClientView : public views::ClientView {
|
||||
public:
|
||||
NativeWindowClientView(views::Widget* widget,
|
||||
|
@ -298,11 +313,20 @@ void NativeWindowViews::CloseImmediately() {
|
|||
}
|
||||
|
||||
void NativeWindowViews::Focus(bool focus) {
|
||||
if (focus)
|
||||
if (focus) {
|
||||
#if defined(OS_WIN)
|
||||
window_->Activate();
|
||||
else
|
||||
#elif defined(USE_X11)
|
||||
// The "Activate" implementation of Chromium is not reliable on Linux.
|
||||
::Window window = GetAcceleratedWidget();
|
||||
XDisplay* xdisplay = gfx::GetXDisplay();
|
||||
SendClientEvent(xdisplay, window, "_NET_ACTIVE_WINDOW");
|
||||
XMapRaised(xdisplay, window);
|
||||
#endif
|
||||
} else {
|
||||
window_->Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
bool NativeWindowViews::IsFocused() {
|
||||
return window_->IsActive();
|
||||
|
|
Loading…
Reference in a new issue