~bratsche/ubuntu/maverick/gtk+2.0/menu-activation-fix

« back to all changes in this revision

Viewing changes to gdk/x11/gdkasync.c

Import upstream version 2.17.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
typedef struct _ListChildrenState ListChildrenState;
58
58
typedef struct _SendEventState SendEventState;
59
59
typedef struct _SetInputFocusState SetInputFocusState;
 
60
typedef struct _RoundtripState RoundtripState;
60
61
 
61
62
typedef enum {
62
63
  CHILD_INFO_GET_PROPERTY,
112
113
  gulong get_input_focus_req;
113
114
};
114
115
 
 
116
struct _RoundtripState
 
117
{
 
118
  Display *dpy;
 
119
  _XAsyncHandler async;
 
120
  gulong get_input_focus_req;
 
121
  GdkDisplay *display;
 
122
  GdkRoundTripCallback callback;
 
123
  gpointer data;
 
124
};
 
125
 
115
126
static gboolean
116
127
callback_idle (gpointer data)
117
128
{
743
754
  return !state.have_error;
744
755
}
745
756
 
 
757
static gboolean
 
758
roundtrip_callback_idle (gpointer data)
 
759
{
 
760
  RoundtripState *state = (RoundtripState *)data;  
 
761
  
 
762
  state->callback (state->display, state->data, state->get_input_focus_req);
 
763
 
 
764
  g_free (state);
 
765
 
 
766
  return FALSE;
 
767
}
 
768
 
 
769
static Bool
 
770
roundtrip_handler (Display *dpy,
 
771
                   xReply  *rep,
 
772
                   char    *buf,
 
773
                   int      len,
 
774
                   XPointer data)
 
775
{
 
776
  RoundtripState *state = (RoundtripState *)data;  
 
777
  
 
778
  if (dpy->last_request_read == state->get_input_focus_req)
 
779
    {
 
780
      xGetInputFocusReply replbuf;
 
781
      xGetInputFocusReply *repl;
 
782
      
 
783
      if (rep->generic.type != X_Error)
 
784
        {
 
785
          /* Actually does nothing, since there are no additional bytes
 
786
           * to read, but maintain good form.
 
787
           */
 
788
          repl = (xGetInputFocusReply *)
 
789
            _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
 
790
                            (sizeof(xGetInputFocusReply) - sizeof(xReply)) >> 2,
 
791
                            True);
 
792
        }
 
793
 
 
794
      
 
795
      if (state->callback)
 
796
        gdk_threads_add_idle (roundtrip_callback_idle, state);
 
797
 
 
798
      DeqAsyncHandler(state->dpy, &state->async);
 
799
 
 
800
      return (rep->generic.type != X_Error);
 
801
    }
 
802
 
 
803
  return False;
 
804
}
 
805
 
 
806
void
 
807
_gdk_x11_roundtrip_async (GdkDisplay           *display, 
 
808
                          GdkRoundTripCallback callback,
 
809
                          gpointer              data)
 
810
{
 
811
  Display *dpy;
 
812
  RoundtripState *state;
 
813
  
 
814
  dpy = GDK_DISPLAY_XDISPLAY (display);
 
815
 
 
816
  state = g_new (RoundtripState, 1);
 
817
 
 
818
  state->display = display;
 
819
  state->dpy = dpy;
 
820
  state->callback = callback;
 
821
  state->data = data;
 
822
  
 
823
  LockDisplay(dpy);
 
824
 
 
825
  state->async.next = dpy->async_handlers;
 
826
  state->async.handler = roundtrip_handler;
 
827
  state->async.data = (XPointer) state;
 
828
  dpy->async_handlers = &state->async;
 
829
 
 
830
  /*
 
831
   * XSync (dpy, 0)
 
832
   */
 
833
  {
 
834
    xReq *req;
 
835
    
 
836
    GetEmptyReq(GetInputFocus, req);
 
837
    state->get_input_focus_req = dpy->request;
 
838
  }
 
839
  
 
840
  UnlockDisplay(dpy);
 
841
  SyncHandle();
 
842
}
 
843
 
746
844
#define __GDK_ASYNC_C__
747
845
#include "gdkaliasdef.c"