1 /* External client, raw Xlib version.
2 Copyright (C) 1993, 1994 Sun Microsystems, Inc.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this library; if not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 /* Synched up with: Not in FSF. */
21 /* Written by Ben Wing, February 1994. */
24 #include <X11/Xresource.h>
25 #include <X11/Xutil.h>
26 #include "extw-Xlib.h"
28 /* this is not a perfect solution, but otherwise we have to include all
31 #define XtGeometryNo 1
33 #if (XlibSpecificationRelease < 5)
34 # define XPointer char *
37 static int context_inited;
38 static XContext focus_context;
40 /* does the specified window have the focus, given that the pointer just
41 entered (or left) the window (according to enter_p)? This question
42 does not have an obvious answer in X. (Basically, X sucks.) */
45 window_has_focus_p (Display *display, Window win, int enter_p)
50 XGetInputFocus(display, &focuswin, &dummy);
51 if (focuswin == PointerRoot)
60 Window root_win, parent_win;
64 st = XQueryTree(display, win, &root_win, &parent_win, &child_win,
68 XFree((XPointer)child_win);
69 if (parent_win == focuswin)
71 if (parent_win == root_win)
79 /* External entry points when using XLib directly */
81 void ExternalClientInitialize (Display *display, Window win);
83 ExternalClientInitialize (Display *display, Window win)
85 extw_initialize_atoms(display);
86 extw_which_side = extw_client_send;
89 focus_context = XUniqueContext();
92 XSaveContext(display, win, focus_context, 0);
93 XSelectInput(display, win, EnterWindowMask | LeaveWindowMask |
97 void ExternalClientEventHandler (Display *display, Window win, XEvent *event);
99 ExternalClientEventHandler (Display *display, Window win, XEvent *event)
101 if (win != event->xany.window)
104 if (event->type == ClientMessage &&
105 event->xclient.message_type == a_EXTW_NOTIFY &&
106 event->xclient.data.l[0] == extw_shell_send)
107 switch (event->xclient.data.l[1]) {
109 /* for the moment, just refuse geometry requests. */
110 extw_send_notify_3(display, win, extw_notify_gm, XtGeometryNo, 0, 0);
113 case extw_notify_init:
114 extw_send_notify_3(display, win, extw_notify_init, EXTW_TYPE_XLIB, 0, 0);
117 case extw_notify_end:
118 XClearArea(display, win, 0, 0, 0, 0, True);
124 XPointer current_focus;
126 if (event->type == FocusIn)
128 else if (event->type == FocusOut)
130 else if (event->type == EnterNotify &&
131 event->xcrossing.detail != NotifyInferior)
132 focus_status = window_has_focus_p(display, win, 1);
133 else if (event->type == LeaveNotify &&
134 event->xcrossing.detail != NotifyInferior)
135 focus_status = window_has_focus_p(display, win, 0);
138 XFindContext(display, win, focus_context, ¤t_focus);
139 if (focus_status != (int) current_focus)
141 XSaveContext(display, win, focus_context, (XPointer) focus_status);
142 extw_send_notify_3(display, win, focus_status ?
143 extw_notify_focus_in : extw_notify_focus_out,