1 /* GTK - The GIMP Toolkit
2 * gdkasync.c: Utility functions using the Xlib asynchronous interfaces
3 * Copyright (C) 2003, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 /* Portions of code in this file are based on code from Xlib
23 Copyright 1986, 1998 The Open Group
25 Permission to use, copy, modify, distribute, and sell this software and its
26 documentation for any purpose is hereby granted without fee, provided that
27 the above copyright notice appear in all copies and that both that
28 copyright notice and this permission notice appear in supporting
31 The above copyright notice and this permission notice shall be included in
32 all copies or substantial portions of the Software.
34 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
38 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 Except as contained in this notice, the name of The Open Group shall not be
42 used in advertising or otherwise to promote the sale, use or other dealings
43 in this Software without prior written authorization from The Open Group.
46 #include <X11/Xlibint.h>
50 typedef struct _SetInputFocusState SetInputFocusState;
52 struct _SetInputFocusState
57 gulong set_input_focus_req;
58 gulong get_input_focus_req;
60 GdkSendXEventCallback callback;
65 set_input_focus_handler (Display *dpy,
71 SetInputFocusState *state = (SetInputFocusState *)data;
73 if (dpy->last_request_read == state->set_input_focus_req)
75 if (rep->generic.type == X_Error &&
76 rep->error.errorCode == BadMatch)
78 /* Consume BadMatch errors, since we have no control
85 if (dpy->last_request_read == state->get_input_focus_req)
87 xGetInputFocusReply replbuf;
88 xGetInputFocusReply *repl;
90 if (rep->generic.type != X_Error)
92 /* Actually does nothing, since there are no additional bytes
93 * to read, but maintain good form.
95 repl = (xGetInputFocusReply *)
96 _XGetAsyncReply(dpy, (char *)&replbuf, rep, buf, len,
97 (sizeof(xGetInputFocusReply) - sizeof(xReply)) >> 2,
101 DeqAsyncHandler(state->dpy, &state->async);
105 return (rep->generic.type != X_Error);
112 _gdk_x11_set_input_focus_safe (GdkDisplay *display,
118 SetInputFocusState *state;
120 dpy = GDK_DISPLAY_XDISPLAY (display);
122 state = g_new (SetInputFocusState, 1);
125 state->window = window;
129 state->async.next = dpy->async_handlers;
130 state->async.handler = set_input_focus_handler;
131 state->async.data = (XPointer) state;
132 dpy->async_handlers = &state->async;
135 xSetInputFocusReq *req;
137 GetReq(SetInputFocus, req);
139 req->revertTo = revert_to;
141 state->set_input_focus_req = dpy->request;
150 GetEmptyReq(GetInputFocus, req);
151 state->get_input_focus_req = dpy->request;