Fix window auto-focus on Linux

This commit is contained in:
mafiesto4
2021-02-09 21:52:34 +01:00
parent 4ce6882fc0
commit 8fe04d6db4
3 changed files with 25 additions and 6 deletions

View File

@@ -1691,6 +1691,15 @@ void LinuxPlatform::Tick()
}
}
break;
case MapNotify:
// Auto-focus shown windows
window = WindowsManager::GetByNativePtr((void*)event.xmap.window);
if (window && window->_focusOnMapped)
{
window->_focusOnMapped = false;
window->Focus();
}
break;
case FocusIn:
// Update input context focus
X11::XSetICFocus(IC);

View File

@@ -242,10 +242,7 @@ void LinuxWindow::Show()
LINUX_WINDOW_PROLOG;
X11::XMapWindow(display, window);
X11::XFlush(display);
if (_settings.AllowInput && _settings.ActivateWhenFirstShown)
{
Focus();
}
_focusOnMapped = _settings.AllowInput && _settings.ActivateWhenFirstShown;
// Base
WindowBase::Show();
@@ -306,6 +303,11 @@ bool LinuxWindow::IsClosed() const
return _isClosing;
}
bool LinuxWindow::IsForegroundWindow() const
{
return _focused || _focusOnMapped;
}
void LinuxWindow::SetClientBounds(const Rectangle& clientArea)
{
int32 x = Math::TruncToInt(clientArea.GetX());
@@ -673,7 +675,14 @@ void LinuxWindow::SetOpacity(const float opacity)
void LinuxWindow::Focus()
{
// TODO: impl this
if (_focused || !IsWindowMapped())
return;
LINUX_WINDOW_PROLOG;
X11::XSetInputFocus(display, window, RevertToPointerRoot, CurrentTime);
X11::XFlush(display);
X11::XSync(display, 0);
}
void LinuxWindow::SetTitle(const StringView& title)

View File

@@ -20,7 +20,7 @@ public:
private:
bool _resizeDisabled;
bool _resizeDisabled, _focusOnMapped = false;
float _opacity = 1.0f;
HandleType _window;
@@ -74,6 +74,7 @@ public:
void Maximize() override;
void Restore() override;
bool IsClosed() const override;
bool IsForegroundWindow() const override;
void BringToFront(bool force = false) override;
void SetClientBounds(const Rectangle& clientArea) override;
void SetPosition(const Vector2& position) override;