1 /* External client, raw Xlib version.
2 Copyright (C) 1993, 1994 Sun Microsystems, Inc.
4 This file is part of SXEmacs
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: Not in FSF. */
22 /* Written by Ben Wing, February 1994. */
25 #include <X11/Xresource.h>
26 #include <X11/Xutil.h>
27 #include "ui/X11/extw-Xlib.h"
29 /* this is not a perfect solution, but otherwise we have to include all
32 #define XtGeometryNo 1
34 #if (XlibSpecificationRelease < 5)
35 # define XPointer char *
38 static int context_inited;
39 static XContext focus_context;
41 /* does the specified window have the focus, given that the pointer just
42 entered (or left) the window (according to enter_p)? This question
43 does not have an obvious answer in X. (Basically, X sucks.) */
45 static int window_has_focus_p(Display * display, Window win, int enter_p)
50 XGetInputFocus(display, &focuswin, &dummy);
51 if (focuswin == PointerRoot)
59 Window root_win, parent_win;
63 st = XQueryTree(display, win, &root_win, &parent_win,
67 XFree((XPointer) child_win);
68 if (parent_win == focuswin)
70 if (parent_win == root_win)
77 /* External entry points when using XLib directly */
79 void ExternalClientInitialize(Display * display, Window win);
80 void ExternalClientInitialize(Display * display, Window win)
82 extw_initialize_atoms(display);
83 extw_which_side = extw_client_send;
84 if (!context_inited) {
85 focus_context = XUniqueContext();
88 XSaveContext(display, win, focus_context, 0);
89 XSelectInput(display, win, EnterWindowMask | LeaveWindowMask |
93 void ExternalClientEventHandler(Display * display, Window win, XEvent * event);
94 void ExternalClientEventHandler(Display * display, Window win, XEvent * event)
96 if (win != event->xany.window)
99 if (event->type == ClientMessage &&
100 event->xclient.message_type == a_EXTW_NOTIFY &&
101 event->xclient.data.l[0] == extw_shell_send)
102 switch (event->xclient.data.l[1]) {
104 /* for the moment, just refuse geometry requests. */
105 extw_send_notify_3(display, win, extw_notify_gm,
109 case extw_notify_init:
110 extw_send_notify_3(display, win, extw_notify_init,
111 EXTW_TYPE_XLIB, 0, 0);
114 case extw_notify_end:
115 XClearArea(display, win, 0, 0, 0, 0, True);
119 XPointer current_focus;
121 if (event->type == FocusIn)
123 else if (event->type == FocusOut)
125 else if (event->type == EnterNotify &&
126 event->xcrossing.detail != NotifyInferior)
127 focus_status = window_has_focus_p(display, win, 1);
128 else if (event->type == LeaveNotify &&
129 event->xcrossing.detail != NotifyInferior)
130 focus_status = window_has_focus_p(display, win, 0);
133 XFindContext(display, win, focus_context, ¤t_focus);
134 if (focus_status != (int)current_focus) {
135 XSaveContext(display, win, focus_context,
136 (XPointer) focus_status);
137 extw_send_notify_3(display, win,
138 focus_status ? extw_notify_focus_in :
139 extw_notify_focus_out, 0, 0, 0);