Browse Source

Add puglX11GrabFocus as a safer way to grab focus on X11

Signed-off-by: falkTX <falktx@falktx.com>
pull/309/head
falkTX 3 years ago
parent
commit
091c919cd6
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 27 additions and 1 deletions
  1. +1
    -1
      dgl/src/WindowPrivateData.cpp
  2. +22
    -0
      dgl/src/pugl.cpp
  3. +4
    -0
      dgl/src/pugl.hpp

+ 1
- 1
dgl/src/WindowPrivateData.cpp View File

@@ -363,7 +363,7 @@ void Window::PrivateData::focus()
if (! isEmbed)
puglRaiseWindow(view);

puglGrabFocus(view);
puglX11GrabFocus(view);
}

// -----------------------------------------------------------------------


+ 22
- 0
dgl/src/pugl.cpp View File

@@ -506,6 +506,28 @@ void puglWin32SetWindowResizable(PuglView* const view, const bool resizable)
#endif

#ifdef HAVE_X11
// --------------------------------------------------------------------------------------------------------------------
// X11 specific, safer way to grab focus

PuglStatus puglX11GrabFocus(PuglView* const view)
{
PuglInternals* const impl = view->impl;

XWindowAttributes wa;
std::memset(&wa, 0, sizeof(wa));

DISTRHO_SAFE_ASSERT_RETURN(XGetWindowAttributes(impl->display, impl->win, &wa), PUGL_UNKNOWN_ERROR);

if (wa.map_state == IsViewable)
{
XRaiseWindow(impl->display, impl->win);
XSetInputFocus(impl->display, impl->win, RevertToPointerRoot, CurrentTime);
XSync(impl->display, False);
}

return PUGL_SUCCESS;
}

// --------------------------------------------------------------------------------------------------------------------
// X11 specific, setup event loop filter for sofd file dialog



+ 4
- 0
dgl/src/pugl.hpp View File

@@ -120,6 +120,10 @@ puglWin32SetWindowResizable(PuglView* view, bool resizable);
#endif

#ifdef HAVE_X11
// X11 specific, safer way to grab focus
PUGL_API PuglStatus
puglX11GrabFocus(PuglView* view);

// X11 specific, setup event loop filter for sofd file dialog
PUGL_API void
sofdFileDialogSetup(PuglWorld* world);


Loading…
Cancel
Save