Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-4042

On X11, XSetInputFocus() is sometime called on a non-viewable window

    XMLWordPrintable

Details

    • 26b572903a800163972817cd717b5df454b96eb2

    Description

      In void QWidget::activateWindow(), XSetInputFocus() can be called on a window which is Unviewable or Unmapped. The call fails and return a BadMatch error (this behavior is not described in the man page, it is described in the XLib programming Manual).

      Here is a patch to avoid the issue:

      diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp
      index 79ee8c9..766a301 100644
      --- a/src/gui/kernel/qwidget_x11.cpp
      +++ b/src/gui/kernel/qwidget_x11.cpp
      @@ -1509,9 +1509,14 @@ QWidget *QWidget::keyboardGrabber()
      
       void QWidget::activateWindow()
       {
      -    Q_D(QWidget);
           QWidget *tlw = window();
           if (tlw->isVisible() && !tlw->d_func()->topData()->embedded && !X11->deferred_map.contains(tlw)) {
      +
      +        XWindowAttributes attributes;
      +        XGetWindowAttributes(X11->display, tlw->internalWinId(), &attributes);
      +        if(attributes.map_state != IsViewable)
      +            return;
      +
               if (X11->userTime == 0)
                   X11->userTime = X11->time;
               qt_net_update_user_time(tlw, X11->userTime);
      diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
      index e21c573..c8277bb 100644
      --- a/src/gui/kernel/qapplication_x11.cpp
      +++ b/src/gui/kernel/qapplication_x11.cpp
      @@ -632,11 +632,6 @@ static int qt_x_errhandler(Display *dpy, XErrorEvent *err)
                   return 0;
               break;
      
      -    case BadMatch:
      -        if (err->request_code == 42 /* X_SetInputFocus */)
      -            return 0;
      -        break;
      -
           default:
               if (err->request_code == X11->xinput_major
                   && err->error_code == (X11->xinput_errorbase + XI_BadDevice)
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            dzyubenk Denis Dzyubenko (Inactive)
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes