Blame SOURCES/motif-2.3.4-motifzone_1564-88bdce1.patch

83fa91
commit 88bdce139baf89839b6e13d698576fc56211e845
83fa91
Author: Oleksiy Chernyavskyy <ochern@ics.com>
83fa91
Date:   Wed Mar 16 00:46:49 2016 +0200
83fa91
83fa91
    Reimplemented bugfix 1565
83fa91
    
83fa91
    Signed-off-by: Oleksiy Chernyavskyy <ochern@ics.com>
83fa91
83fa91
diff --git a/lib/Xm/ComboBox.c b/lib/Xm/ComboBox.c
83fa91
index 1472e45..cf507da 100644
83fa91
--- a/lib/Xm/ComboBox.c
83fa91
+++ b/lib/Xm/ComboBox.c
83fa91
@@ -3164,6 +3164,9 @@ CreatePulldown(Widget    parent,
83fa91
   Arg      args[4];
83fa91
   ArgList  merged_args;
83fa91
   Cardinal n;
83fa91
+#ifdef FIX_1565
83fa91
+  XmGrabShellWidget grabsh;
83fa91
+#endif
83fa91
 
83fa91
   n = 0;
83fa91
   XtSetArg(args[n], XmNlayoutDirection, LayoutM(parent)), n++;
83fa91
@@ -3175,6 +3178,11 @@ CreatePulldown(Widget    parent,
83fa91
 			     merged_args, n + *num_args);
83fa91
   XtFree((char*)merged_args);
83fa91
 
83fa91
+#ifdef FIX_1565
83fa91
+  grabsh = (XmGrabShellWidget) shell;
83fa91
+  grabsh->grab_shell.set_input_focus = False;
83fa91
+#endif
83fa91
+
83fa91
   return shell;
83fa91
 }
83fa91
 
83fa91
diff --git a/lib/Xm/DropDown.c b/lib/Xm/DropDown.c
83fa91
index 37fec03..5cd15ca 100644
83fa91
--- a/lib/Xm/DropDown.c
83fa91
+++ b/lib/Xm/DropDown.c
83fa91
@@ -2027,6 +2027,9 @@ CreatePopup(Widget w, ArgList args, Cardinal num_args)
83fa91
     Arg *new_list, largs[10];
83fa91
     Cardinal num_largs;
83fa91
     Widget sb;
83fa91
+#ifdef FIX_1565
83fa91
+    XmGrabShellWidget grabsh;
83fa91
+#endif
83fa91
 
83fa91
     num_largs = 0;
83fa91
     XtSetArg(largs[num_largs], XmNoverrideRedirect, True); num_largs++;
83fa91
@@ -2040,6 +2043,10 @@ CreatePopup(Widget w, ArgList args, Cardinal num_args)
83fa91
 						xmGrabShellWidgetClass, w,
83fa91
 						new_list,
83fa91
 						num_largs + num_args);
83fa91
+#ifdef FIX_1565
83fa91
+    grabsh = (XmGrabShellWidget) XmDropDown_popup_shell(cbw);
83fa91
+    grabsh->grab_shell.set_input_focus = False;
83fa91
+#endif
83fa91
     XtFree((char *) new_list);
83fa91
 
83fa91
 #ifdef FIX_1446
83fa91
diff --git a/lib/Xm/GrabShell.c b/lib/Xm/GrabShell.c
83fa91
index 88f3154..af13e0b 100644
83fa91
--- a/lib/Xm/GrabShell.c
83fa91
+++ b/lib/Xm/GrabShell.c
83fa91
@@ -283,6 +283,10 @@ Initialize(Widget req,		/* unused */
83fa91
 
83fa91
   /* CR 9920:  Popdown may be requested before MapNotify. */
83fa91
   grabsh->grab_shell.mapped = False;
83fa91
+
83fa91
+#ifdef FIX_1565
83fa91
+  grabsh->grab_shell.set_input_focus = True;
83fa91
+#endif
83fa91
 }
83fa91
 
83fa91
 /*
83fa91
@@ -395,8 +399,16 @@ MapNotifyHandler(Widget shell, XtPointer client_data,
83fa91
   XGetInputFocus(XtDisplay(shell), &grabshell->grab_shell.old_focus,
83fa91
 		 &grabshell->grab_shell.old_revert_to);
83fa91
   old_handler = XSetErrorHandler(IgnoreXErrors);
83fa91
-  XSetInputFocus(XtDisplay(shell), XtWindow(shell), RevertToParent, time);
83fa91
-  XSync(XtDisplay(shell), False);
83fa91
+#ifdef FIX_1565
83fa91
+  if (! grabshell->grab_shell.set_input_focus) {
83fa91
+    XmForceGrabKeyboard(shell, time);
83fa91
+  } else {
83fa91
+#endif
83fa91
+    XSetInputFocus(XtDisplay(shell), XtWindow(shell), RevertToParent, time);
83fa91
+    XSync(XtDisplay(shell), False);
83fa91
+#ifdef FIX_1565
83fa91
+  }
83fa91
+#endif
83fa91
   XSetErrorHandler(old_handler);
83fa91
 }
83fa91
 
83fa91
diff --git a/lib/Xm/GrabShellP.h b/lib/Xm/GrabShellP.h
83fa91
index 92fe508..025f001 100644
83fa91
--- a/lib/Xm/GrabShellP.h
83fa91
+++ b/lib/Xm/GrabShellP.h
83fa91
@@ -30,6 +30,7 @@
83fa91
 #include <Xm/GrabShell.h>
83fa91
 #include <Xm/XmP.h>
83fa91
 #include <X11/ShellP.h>
83fa91
+#include "XmI.h"
83fa91
 
83fa91
 #ifdef __cplusplus
83fa91
 extern "C" {
83fa91
@@ -55,6 +56,9 @@ typedef struct
83fa91
   Boolean	mapped;
83fa91
   Window	old_focus;
83fa91
   int		old_revert_to;
83fa91
+#ifdef FIX_1565
83fa91
+  Boolean	set_input_focus;
83fa91
+#endif
83fa91
 } XmGrabShellPart;
83fa91
 
83fa91
 
83fa91
diff --git a/lib/Xm/MenuShell.c b/lib/Xm/MenuShell.c
83fa91
index 2ed3dd8..9887087 100644
83fa91
--- a/lib/Xm/MenuShell.c
83fa91
+++ b/lib/Xm/MenuShell.c
83fa91
@@ -1514,9 +1514,7 @@ ChangeManaged(
83fa91
 
83fa91
 	       /** the real grab ***/
83fa91
          _XmMenuGrabKeyboardAndPointer((Widget)rowcol, _time);
83fa91
-#ifndef FIX_1565
83fa91
 	 _XmMenuFocus(XtParent(rowcol), XmMENU_BEGIN, _time);
83fa91
-#endif
83fa91
 
83fa91
 	 /* To support menu replay, keep the pointer in sync mode */
83fa91
 	 XAllowEvents(XtDisplay(rowcol), SyncPointer, CurrentTime);
83fa91
diff --git a/lib/Xm/MenuUtil.c b/lib/Xm/MenuUtil.c
83fa91
index 1d88390..2fb6a27 100644
83fa91
--- a/lib/Xm/MenuUtil.c
83fa91
+++ b/lib/Xm/MenuUtil.c
83fa91
@@ -1053,11 +1053,7 @@ _XmMenuGrabKeyboardAndPointer(
83fa91
 
83fa91
    register int status =
83fa91
            (_XmGrabKeyboard(widget,
83fa91
-#ifdef FIX_1565
83fa91
-                            False,
83fa91
-#else
83fa91
                             True,
83fa91
-#endif
83fa91
                             GrabModeSync,
83fa91
                             GrabModeAsync,
83fa91
                             time) != GrabSuccess);
83fa91
diff --git a/lib/Xm/RCMenu.c b/lib/Xm/RCMenu.c
83fa91
index 2c698d4..8b156da 100644
83fa91
--- a/lib/Xm/RCMenu.c
83fa91
+++ b/lib/Xm/RCMenu.c
83fa91
@@ -85,6 +85,9 @@ static char *rcsid = "$TOG: RCMenu.c /main/25 1999/05/24 18:06:57 samborn $";
83fa91
 #include "TraversalI.h"
83fa91
 #include "UniqueEvnI.h"
83fa91
 #include "VendorSI.h"
83fa91
+#ifdef FIX_1565
83fa91
+#include <Xm/GrabShell.h>
83fa91
+#endif
83fa91
 
83fa91
 #define FIX_1535
83fa91
 
83fa91
@@ -943,6 +946,13 @@ _XmMenuFocus(
83fa91
    XmMenuState mst = _XmGetMenuState((Widget)w);
83fa91
    Window tmpWindow;
83fa91
    int tmpRevert;
83fa91
+#ifdef FIX_1565
83fa91
+   Widget shell;
83fa91
+
83fa91
+   shell = w;
83fa91
+   while (! XtIsSubclass(shell, shellWidgetClass))
83fa91
+     shell = XtParent(shell);
83fa91
+#endif
83fa91
  
83fa91
    if (_time == CurrentTime) 
83fa91
      _time = XtLastTimestampProcessed(XtDisplay(w));
83fa91
@@ -983,6 +993,11 @@ _XmMenuFocus(
83fa91
 			  shell.popped_up))
83fa91
 **/
83fa91
 		     {
83fa91
+#ifdef FIX_1565
83fa91
+               if (XtIsSubclass(shell, xmGrabShellWidgetClass) || XtIsSubclass(shell, xmMenuShellWidgetClass))
83fa91
+                 XmForceGrabKeyboard(w, _time);
83fa91
+               else
83fa91
+#endif
83fa91
 		       SetInputFocus(XtDisplay(w), mst->RC_menuFocus.oldFocus,
83fa91
 				     mst->RC_menuFocus.oldRevert,
83fa91
 				     mst->RC_menuFocus.oldTime);
83fa91
@@ -996,6 +1011,11 @@ _XmMenuFocus(
83fa91
  	      */
83fa91
  	     else
83fa91
  	       {
83fa91
+#ifdef FIX_1565
83fa91
+               if (XtIsSubclass(shell, xmGrabShellWidgetClass) || XtIsSubclass(shell, xmMenuShellWidgetClass))
83fa91
+                 XmForceGrabKeyboard(w, _time);
83fa91
+               else
83fa91
+#endif
83fa91
  		  SetInputFocus(XtDisplay(w), mst->RC_menuFocus.oldFocus,
83fa91
 				mst->RC_menuFocus.oldRevert,
83fa91
 				mst->RC_menuFocus.oldTime);
83fa91
@@ -1014,6 +1034,11 @@ _XmMenuFocus(
83fa91
 	     RC_menuFocus.oldFocus);
83fa91
 	  mst->RC_menuFocus.oldTime = _time - 1;
83fa91
 
83fa91
+#ifdef FIX_1565
83fa91
+      if (XtIsSubclass(shell, xmGrabShellWidgetClass) || XtIsSubclass(shell, xmMenuShellWidgetClass))
83fa91
+        XmForceGrabKeyboard(w, _time);
83fa91
+      else
83fa91
+#endif
83fa91
 	  SetInputFocus(XtDisplay(w), XtWindow(w), mst->RC_menuFocus.oldRevert,
83fa91
 			mst->RC_menuFocus.oldTime);
83fa91
 
83fa91
@@ -1027,6 +1052,11 @@ _XmMenuFocus(
83fa91
 	  XGetInputFocus(XtDisplay(w), &tmpWindow, &tmpRevert);
83fa91
 	  if (tmpWindow != XtWindow(w))
83fa91
 	  {
83fa91
+#ifdef FIX_1565
83fa91
+        if (XtIsSubclass(shell, xmGrabShellWidgetClass) || XtIsSubclass(shell, xmMenuShellWidgetClass))
83fa91
+          XmForceGrabKeyboard(w, _time);
83fa91
+        else
83fa91
+#endif
83fa91
 	    SetInputFocus(XtDisplay(w), XtWindow(w), tmpRevert, _time);
83fa91
 
83fa91
 	    mst->RC_menuFocus.oldRevert = tmpRevert;
83fa91
@@ -1048,6 +1078,11 @@ _XmMenuFocus(
83fa91
 
83fa91
 	  break;
83fa91
 	case XmMENU_MIDDLE:
83fa91
+#ifdef FIX_1565
83fa91
+      if (XtIsSubclass(shell, xmGrabShellWidgetClass) || XtIsSubclass(shell, xmMenuShellWidgetClass))
83fa91
+        XmForceGrabKeyboard(w, _time);
83fa91
+      else
83fa91
+#endif
83fa91
 	  SetInputFocus(XtDisplay(w), XtWindow(w),
83fa91
 			mst->RC_menuFocus.oldRevert,
83fa91
 			mst->RC_menuFocus.oldTime);
83fa91
@@ -1062,6 +1097,11 @@ _XmMenuFocus(
83fa91
 	  if ((tmpWindow != XtWindow(w)) &&
83fa91
 	      (_time > mst->RC_menuFocus.oldTime))
83fa91
 	  {
83fa91
+#ifdef FIX_1565
83fa91
+        if (XtIsSubclass(shell, xmGrabShellWidgetClass) || XtIsSubclass(shell, xmMenuShellWidgetClass))
83fa91
+          XmForceGrabKeyboard(w, _time);
83fa91
+        else
83fa91
+#endif
83fa91
 	    SetInputFocus(XtDisplay(w), XtWindow(w), tmpRevert, _time);
83fa91
 
83fa91
 	    mst->RC_menuFocus.oldRevert = tmpRevert;
83fa91
diff --git a/lib/Xm/Xm.c b/lib/Xm/Xm.c
83fa91
index 3dfd794..45d48b6 100644
83fa91
--- a/lib/Xm/Xm.c
83fa91
+++ b/lib/Xm/Xm.c
83fa91
@@ -40,6 +40,10 @@
83fa91
 #ifdef FIX_345
83fa91
 #include <X11/keysym.h>
83fa91
 #endif
83fa91
+#ifdef FIX_1565
83fa91
+#include <Xm/GrabShell.h>
83fa91
+#include <Xm/MenuShell.h>
83fa91
+#endif
83fa91
 
83fa91
 
83fa91
 /**************************************************************************
83fa91
@@ -530,3 +534,173 @@ _XmAssignInsensitiveColor(Widget w)
83fa91
 	return p;
83fa91
 }
83fa91
 #endif
83fa91
+
83fa91
+#ifdef FIX_1565
83fa91
+
83fa91
+typedef struct _GrabData GrabData;
83fa91
+struct _GrabData {
83fa91
+  Widget w;
83fa91
+  GrabData *next;
83fa91
+};
83fa91
+
83fa91
+static void _XmSendFocusEvent(Widget child, int type);
83fa91
+static void _XmStartDispatcher(Display *display);
83fa91
+static Boolean _XmEventDispatcher(XEvent *event);
83fa91
+static void UnmapHandler(Widget w, XtPointer client_data, XEvent *event, Boolean *cont);
83fa91
+static Boolean _UngrabKeyboard(Widget w);
83fa91
+
83fa91
+static GrabData *grabw_top = NULL;
83fa91
+static int xm_dispatcher_on = 0;
83fa91
+static XtEventDispatchProc saved_dispatcher_proc = NULL;
83fa91
+static XtEventDispatchProc xt_dispatcher_proc = NULL;
83fa91
+
83fa91
+/*
83fa91
+   XmForceGrabKeyboard function is defined to be a substitutor of XSetInputFocus calls
83fa91
+   for popup and pulldown menus that should grab keyboard focus yet main window at the
83fa91
+   same time should visually stay in focus for window manager. This resolves focus flip
83fa91
+   issue when popup or pulldown menu is raised. ~ochern
83fa91
+ */
83fa91
+void XmForceGrabKeyboard(Widget w, Time time)
83fa91
+{
83fa91
+  GrabData *grabw;
83fa91
+
83fa91
+  if (!w)
83fa91
+    return;
83fa91
+
83fa91
+  while (! XtIsSubclass(w, shellWidgetClass))
83fa91
+    w = XtParent(w);
83fa91
+
83fa91
+  if (! (XtIsSubclass(w, xmGrabShellWidgetClass) || XtIsSubclass(w, xmMenuShellWidgetClass)))
83fa91
+    return;
83fa91
+
83fa91
+  _XmStartDispatcher(XtDisplay(w));
83fa91
+
83fa91
+  _UngrabKeyboard(w);
83fa91
+
83fa91
+  grabw = (GrabData *) XtMalloc(sizeof(GrabData));
83fa91
+  grabw->w = w;
83fa91
+  _XmProcessLock();
83fa91
+  grabw->next = grabw_top;
83fa91
+  grabw_top = grabw;
83fa91
+  _XmProcessUnlock();
83fa91
+
83fa91
+  XtInsertEventHandler(w, StructureNotifyMask, False, UnmapHandler, NULL, XtListHead);
83fa91
+
83fa91
+  _XmSendFocusEvent(w, FocusIn);
83fa91
+
83fa91
+  /* Following the XSetInputFocus behaviour we force sending FocusOut (see XGrabKeyboard(3))
83fa91
+     event to a previous keyboard holder */
83fa91
+  XtGrabKeyboard(w, True, GrabModeAsync, GrabModeAsync, time);
83fa91
+}
83fa91
+
83fa91
+static void _XmStartDispatcher(Display *display)
83fa91
+{
83fa91
+  if (!display)
83fa91
+    return;
83fa91
+
83fa91
+  _XmProcessLock();
83fa91
+
83fa91
+  if (xm_dispatcher_on) {
83fa91
+    _XmProcessUnlock();
83fa91
+    return;
83fa91
+  }
83fa91
+
83fa91
+  saved_dispatcher_proc = XtSetEventDispatcher(display, KeyPress, _XmEventDispatcher);
83fa91
+  if (! xt_dispatcher_proc)
83fa91
+    xt_dispatcher_proc = saved_dispatcher_proc;
83fa91
+  XtSetEventDispatcher(display, KeyRelease, _XmEventDispatcher);
83fa91
+  xm_dispatcher_on = 1;
83fa91
+
83fa91
+  _XmProcessUnlock();
83fa91
+}
83fa91
+
83fa91
+static Boolean _XmEventDispatcher(XEvent *event)
83fa91
+{
83fa91
+  _XmProcessLock();
83fa91
+  if (grabw_top) {
83fa91
+    if (event->type == KeyPress || event->type == KeyRelease)
83fa91
+      event->xany.window = XtWindow(grabw_top->w);
83fa91
+  }
83fa91
+  _XmProcessUnlock();
83fa91
+
83fa91
+  if (saved_dispatcher_proc) {
83fa91
+    return (*saved_dispatcher_proc)(event);
83fa91
+  } else if (xt_dispatcher_proc) {
83fa91
+    return (*xt_dispatcher_proc)(event);
83fa91
+  } else {
83fa91
+    if (grabw_top)
83fa91
+      XtSetEventDispatcher(XtDisplay(grabw_top->w), event->type, NULL);
83fa91
+    return XtDispatchEvent(event);
83fa91
+  }
83fa91
+}
83fa91
+
83fa91
+static void UnmapHandler(Widget w, XtPointer client_data, XEvent *event, Boolean *cont)
83fa91
+{
83fa91
+  if (event->type == UnmapNotify)
83fa91
+    _UngrabKeyboard(w);
83fa91
+  if (! grabw_top) {
83fa91
+    XtSetEventDispatcher(XtDisplay(w), KeyPress, saved_dispatcher_proc);
83fa91
+    XtSetEventDispatcher(XtDisplay(w), KeyRelease, saved_dispatcher_proc);
83fa91
+    xm_dispatcher_on = 0;
83fa91
+  }
83fa91
+
83fa91
+  /* we do not call XtUngrabKeyboard since X server automatically performs an
83fa91
+     UngrabKeyboard request if the event window for an active keyboard grab becomes
83fa91
+     not viewable. ~ochern */
83fa91
+}
83fa91
+
83fa91
+static Boolean _UngrabKeyboard(Widget w)
83fa91
+{
83fa91
+  GrabData *grabw, *grabw_prev;
83fa91
+
83fa91
+  _XmProcessLock();
83fa91
+  if (! grabw_top) {
83fa91
+    _XmProcessUnlock();
83fa91
+    return False;
83fa91
+  }
83fa91
+
83fa91
+  grabw = grabw_top;
83fa91
+  grabw_prev = NULL;
83fa91
+  while(grabw && grabw->w != w) {
83fa91
+    grabw_prev = grabw;
83fa91
+    grabw = grabw->next;
83fa91
+  }
83fa91
+  if (grabw) {
83fa91
+    if (grabw_prev)
83fa91
+      grabw_prev->next = grabw->next;
83fa91
+    else
83fa91
+      grabw_top = grabw->next;
83fa91
+    XtFree((char*) grabw);
83fa91
+
83fa91
+    _XmProcessUnlock();
83fa91
+    return True;
83fa91
+  }
83fa91
+
83fa91
+  _XmProcessUnlock();
83fa91
+  return False;
83fa91
+}
83fa91
+
83fa91
+static void _XmSendFocusEvent(Widget child, int type)
83fa91
+{
83fa91
+  child = XtIsWidget(child) ? child : _XtWindowedAncestor(child);
83fa91
+  if (XtIsSensitive(child) && !child->core.being_destroyed
83fa91
+      && XtIsRealized(child) && (XtBuildEventMask(child) & FocusChangeMask))
83fa91
+  {
83fa91
+    XFocusChangeEvent event;
83fa91
+    Display* dpy = XtDisplay (child);
83fa91
+
83fa91
+    event.type = type;
83fa91
+    event.serial = LastKnownRequestProcessed(dpy);
83fa91
+    event.send_event = True;
83fa91
+    event.display = dpy;
83fa91
+    event.window = XtWindow(child);
83fa91
+    event.mode = NotifyNormal;
83fa91
+    event.detail = NotifyAncestor;
83fa91
+    if (XFilterEvent((XEvent*)&event, XtWindow(child)))
83fa91
+      return;
83fa91
+    XtDispatchEventToWidget(child, (XEvent*)&event);
83fa91
+  }
83fa91
+}
83fa91
+
83fa91
+#endif
83fa91
+
83fa91
diff --git a/lib/Xm/XmI.h b/lib/Xm/XmI.h
83fa91
index b4420d3..c2b819e 100644
83fa91
--- a/lib/Xm/XmI.h
83fa91
+++ b/lib/Xm/XmI.h
83fa91
@@ -242,7 +242,9 @@ extern Boolean _XmIsISO10646(Display *dpy,
83fa91
 extern XChar2b* _XmUtf8ToUcs2(char *draw_text,
83fa91
                               size_t seg_len,
83fa91
 			      size_t *ret_str_len);
83fa91
-
83fa91
+#ifdef FIX_1565
83fa91
+extern void XmForceGrabKeyboard(Widget w, Time time);
83fa91
+#endif
83fa91
 
83fa91
 /********    End Private Function Declarations    ********/
83fa91