0
|
1 /* Functions for the X window system.
|
|
2 Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995, 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not synched with FSF. */
|
|
23
|
|
24 /* Substantially rewritten for XEmacs. */
|
|
25
|
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28
|
|
29 #include "console-x.h"
|
|
30 #include "xintrinsicp.h" /* CoreP.h needs this */
|
|
31 #include <X11/CoreP.h> /* Numerous places access the fields of
|
|
32 a core widget directly. We could
|
|
33 use XtVaGetValues(), but ... */
|
|
34 #include <X11/Shell.h>
|
|
35 #include <X11/ShellP.h>
|
|
36 #include "xmu.h"
|
|
37 #include "EmacsManager.h"
|
|
38 #include "EmacsFrameP.h"
|
|
39 #include "EmacsShell.h"
|
|
40 #ifdef EXTERNAL_WIDGET
|
|
41 #include "ExternalShell.h"
|
|
42 #endif
|
|
43 #include "glyphs-x.h"
|
|
44 #include "objects-x.h"
|
|
45 #include "scrollbar-x.h"
|
|
46
|
|
47 #include "buffer.h"
|
|
48 #include "events.h"
|
|
49 #include "extents.h"
|
|
50 #include "faces.h"
|
|
51 #include "frame.h"
|
|
52 #include "window.h"
|
|
53
|
|
54 /* Default properties to use when creating frames. */
|
|
55 Lisp_Object Vdefault_x_frame_plist;
|
|
56
|
|
57 Lisp_Object Qwindow_id;
|
|
58 Lisp_Object Qpopup;
|
|
59 Lisp_Object Qx_resource_name;
|
|
60
|
|
61
|
|
62 /************************************************************************/
|
|
63 /* helper functions */
|
|
64 /************************************************************************/
|
|
65
|
|
66 /* Return the Emacs frame-object corresponding to an X window */
|
|
67 struct frame *
|
|
68 x_window_to_frame (struct device *d, Window wdesc)
|
|
69 {
|
|
70 Lisp_Object tail, frame;
|
|
71 struct frame *f;
|
|
72
|
|
73 /* This function was previously written to accept only a window argument
|
|
74 (and to loop over all devices looking for a matching window), but
|
|
75 that is incorrect because window ID's are not unique across displays. */
|
|
76
|
|
77 for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail))
|
|
78 {
|
|
79 frame = XCAR (tail);
|
|
80 if (!FRAMEP (frame))
|
|
81 continue;
|
|
82 f = XFRAME (frame);
|
|
83 if (FRAME_X_P (f) && XtWindow (FRAME_X_TEXT_WIDGET (f)) == wdesc)
|
|
84 return f;
|
|
85 }
|
|
86 return 0;
|
|
87 }
|
|
88
|
|
89 /* Like x_window_to_frame but also compares the window with the widget's
|
|
90 windows */
|
|
91 struct frame *
|
|
92 x_any_window_to_frame (struct device *d, Window wdesc)
|
|
93 {
|
|
94 Lisp_Object tail, frame;
|
|
95 struct frame *f;
|
|
96
|
|
97 assert (DEVICE_X_P (d));
|
|
98
|
|
99 /* This function was previously written to accept only a window argument
|
|
100 (and to loop over all devices looking for a matching window), but
|
|
101 that is incorrect because window ID's are not unique across displays. */
|
|
102
|
|
103 for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail))
|
|
104 {
|
|
105 int i;
|
|
106
|
|
107 frame = XCAR (tail);
|
|
108 f = XFRAME (frame);
|
|
109 /* This frame matches if the window is any of its widgets. */
|
|
110 if (wdesc == XtWindow (FRAME_X_SHELL_WIDGET (f)) ||
|
|
111 wdesc == XtWindow (FRAME_X_CONTAINER_WIDGET (f)) ||
|
|
112 wdesc == XtWindow (FRAME_X_TEXT_WIDGET (f)))
|
|
113 return f;
|
|
114
|
|
115 /* Match if the window is one of the widgets at the top of the frame
|
|
116 (menubar, Energize psheets). */
|
|
117
|
|
118 /* Note: Jamie once said
|
|
119
|
|
120 "Do *not* match if the window is this frame's psheet."
|
|
121
|
|
122 But this is wrong and will screw up some functions that expect
|
|
123 x_any_window_to_frame() to work as advertised. I think the reason
|
|
124 for this statement is that, in the old (broken) event loop, where
|
|
125 not all events went through XtDispatchEvent(), psheet events
|
|
126 would incorrectly get sucked away by Emacs if this function matched
|
|
127 on psheet widgets. */
|
|
128
|
|
129 for (i = 0; i < FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
130 {
|
|
131 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
132 if (wid && XtIsManaged (wid) && wdesc == XtWindow (wid))
|
|
133 return f;
|
|
134 }
|
|
135
|
|
136 #ifdef HAVE_SCROLLBARS
|
|
137 /* Match if the window is one of this frame's scrollbars. */
|
|
138 if (x_window_is_scrollbar (f, wdesc))
|
|
139 return f;
|
|
140 #endif
|
|
141 }
|
|
142
|
|
143 return 0;
|
|
144 }
|
|
145
|
|
146 struct frame *
|
|
147 x_any_widget_or_parent_to_frame (struct device *d, Widget widget)
|
|
148 {
|
|
149 while (widget)
|
|
150 {
|
|
151 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
152 if (f)
|
|
153 return f;
|
|
154 widget = XtParent (widget);
|
|
155 }
|
|
156
|
|
157 return 0;
|
|
158 }
|
|
159
|
|
160 struct frame *
|
|
161 decode_x_frame (Lisp_Object frame)
|
|
162 {
|
|
163 if (NILP (frame))
|
|
164 XSETFRAME (frame, selected_frame ());
|
|
165 CHECK_LIVE_FRAME (frame);
|
|
166 /* this will also catch dead frames, but putting in the above check
|
|
167 results in a more useful error */
|
|
168 CHECK_X_FRAME (frame);
|
|
169 return XFRAME (frame);
|
|
170 }
|
|
171
|
|
172
|
|
173 /************************************************************************/
|
|
174 /* window-manager interactions */
|
|
175 /************************************************************************/
|
|
176
|
|
177 #if 0
|
|
178 /* Not currently used. */
|
|
179
|
|
180 void
|
|
181 x_wm_mark_shell_size_user_specified (Widget wmshell)
|
|
182 {
|
|
183 if (! XtIsWMShell (wmshell)) abort ();
|
|
184 EmacsShellSetSizeUserSpecified (wmshell);
|
|
185 }
|
|
186
|
|
187 void
|
|
188 x_wm_mark_shell_position_user_specified (Widget wmshell)
|
|
189 {
|
|
190 if (! XtIsWMShell (wmshell)) abort ();
|
|
191 EmacsShellSetPositionUserSpecified (wmshell);
|
|
192 }
|
|
193
|
|
194 #endif
|
|
195
|
|
196 void
|
|
197 x_wm_set_shell_iconic_p (Widget shell, int iconic_p)
|
|
198 {
|
|
199 if (! XtIsWMShell (shell)) abort ();
|
|
200
|
|
201 /* Because of questionable logic in Shell.c, this sequence can't work:
|
|
202
|
|
203 w = XtCreatePopupShell (...);
|
|
204 XtVaSetValues (w, XtNiconic, True, 0);
|
|
205 XtRealizeWidget (w);
|
|
206
|
|
207 The iconic resource is only consulted at initialization time (when
|
|
208 XtCreatePopupShell is called) instead of at realization time (just
|
|
209 before the window gets created, which would be more sensible) or
|
|
210 at management-time (just before the window gets mapped, which would
|
|
211 be most sensible of all).
|
|
212
|
|
213 The bug is that Shell's SetValues method doesn't do anything to
|
|
214 w->wm.wm_hints.initial_state until after the widget has been realized.
|
|
215 Calls to XtSetValues are ignored in the window between creation and
|
|
216 realization. This is true of MIT X11R5 patch level 25, at least.
|
|
217 (Apparently some other versions of Xt don't have this bug?)
|
|
218 */
|
|
219 XtVaSetValues (shell, XtNiconic, iconic_p, 0);
|
|
220 EmacsShellSmashIconicHint (shell, iconic_p);
|
|
221 }
|
|
222
|
|
223 void
|
|
224 x_wm_set_cell_size (Widget wmshell, int cw, int ch)
|
|
225 {
|
|
226 if (!XtIsWMShell (wmshell))
|
|
227 abort ();
|
|
228 if (cw <= 0 || ch <= 0)
|
|
229 abort ();
|
|
230
|
|
231 XtVaSetValues (wmshell,
|
|
232 XtNwidthInc, cw,
|
|
233 XtNheightInc, ch,
|
|
234 0);
|
|
235 }
|
|
236
|
|
237 void
|
|
238 x_wm_set_variable_size (Widget wmshell, int width, int height)
|
|
239 {
|
|
240 if (!XtIsWMShell (wmshell))
|
|
241 abort ();
|
|
242 #ifdef DEBUG_GEOMETRY_MANAGEMENT
|
|
243 /* See comment in EmacsShell.c */
|
|
244 printf ("x_wm_set_variable_size: %d %d\n", width, height);
|
|
245 fflush (stdout);
|
|
246 #endif
|
|
247 XtVaSetValues (wmshell,
|
|
248 XtNwidthCells, width,
|
|
249 XtNheightCells, height,
|
|
250 0);
|
|
251 }
|
|
252
|
|
253 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS
|
|
254 and WM_DELETE_WINDOW, then add them. (They may already be present
|
|
255 because of the toolkit (Motif adds them, for example, but Xt doesn't).
|
|
256 */
|
|
257 static void
|
|
258 x_wm_hack_wm_protocols (Widget widget)
|
|
259 {
|
|
260 Display *dpy = XtDisplay (widget);
|
|
261 struct device *d = get_device_from_display (dpy);
|
|
262 Window w = XtWindow (widget);
|
|
263 int need_delete = 1;
|
|
264 int need_focus = 1;
|
|
265
|
|
266 if (!XtIsWMShell (widget))
|
|
267 abort ();
|
|
268
|
|
269 {
|
|
270 Atom type, *atoms = 0;
|
|
271 int format = 0;
|
|
272 unsigned long nitems = 0;
|
|
273 unsigned long bytes_after;
|
|
274
|
|
275 if (Success == XGetWindowProperty (dpy, w, DEVICE_XATOM_WM_PROTOCOLS (d),
|
|
276 0, 100, False, XA_ATOM,
|
|
277 &type, &format, &nitems, &bytes_after,
|
|
278 (unsigned char **) &atoms)
|
|
279 && format == 32 && type == XA_ATOM)
|
|
280 while (nitems > 0)
|
|
281 {
|
|
282 nitems--;
|
|
283 if (atoms [nitems] == DEVICE_XATOM_WM_DELETE_WINDOW (d))
|
|
284 need_delete = 0;
|
|
285 else if (atoms [nitems] == DEVICE_XATOM_WM_TAKE_FOCUS (d))
|
|
286 need_focus = 0;
|
|
287 }
|
|
288 if (atoms) XFree ((char *) atoms);
|
|
289 }
|
|
290 {
|
|
291 Atom props [10];
|
|
292 int count = 0;
|
|
293 if (need_delete) props[count++] = DEVICE_XATOM_WM_DELETE_WINDOW (d);
|
|
294 if (need_focus) props[count++] = DEVICE_XATOM_WM_TAKE_FOCUS (d);
|
|
295 if (count)
|
|
296 XChangeProperty (dpy, w, DEVICE_XATOM_WM_PROTOCOLS (d), XA_ATOM, 32,
|
|
297 PropModeAppend, (unsigned char *) props, count);
|
|
298 }
|
|
299 }
|
|
300
|
|
301 static void
|
|
302 x_wm_store_class_hints (Widget shell, char *frame_name)
|
|
303 {
|
|
304 Display *dpy = XtDisplay (shell);
|
|
305 char *app_name, *app_class;
|
|
306 XClassHint classhint;
|
|
307
|
|
308 if (!XtIsWMShell (shell))
|
|
309 abort ();
|
|
310
|
|
311 XtGetApplicationNameAndClass (dpy, &app_name, &app_class);
|
|
312 classhint.res_name = frame_name;
|
|
313 classhint.res_class = app_class;
|
|
314 XSetClassHint (dpy, XtWindow (shell), &classhint);
|
|
315 }
|
|
316
|
|
317 static void
|
|
318 x_wm_maybe_store_wm_command (struct frame *f)
|
|
319 {
|
|
320 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
321 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
322
|
|
323 if (!XtIsWMShell (w))
|
|
324 abort ();
|
|
325
|
|
326 if (NILP (DEVICE_X_WM_COMMAND_FRAME (d)))
|
|
327 {
|
|
328 int argc;
|
|
329 char **argv;
|
|
330 make_argc_argv (Vcommand_line_args, &argc, &argv);
|
|
331 XSetCommand (XtDisplay (w), XtWindow (w), argv, argc);
|
|
332 free_argc_argv (argv);
|
|
333 XSETFRAME (DEVICE_X_WM_COMMAND_FRAME (d), f);
|
|
334 }
|
|
335 }
|
|
336
|
|
337 /* If we're deleting the frame on which the WM_COMMAND property has been
|
|
338 set, then move that property to another frame so that there is exactly
|
|
339 one frame that has that property set.
|
|
340 */
|
|
341 static void
|
|
342 x_wm_maybe_move_wm_command (struct frame *f)
|
|
343 {
|
|
344 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
345
|
|
346 /* There may not be a frame in DEVICE_X_WM_COMMAND_FRAME()
|
|
347 if we C-c'ed at startup at the right time. */
|
|
348 if (FRAMEP (DEVICE_X_WM_COMMAND_FRAME (d))
|
|
349 && f == XFRAME (DEVICE_X_WM_COMMAND_FRAME (d)))
|
|
350 {
|
|
351 Lisp_Object rest = DEVICE_FRAME_LIST (d);
|
|
352 DEVICE_X_WM_COMMAND_FRAME (d) = Qnil;
|
|
353 /* find some random other X frame that is not this one, or give up */
|
|
354 /* skip non-top-level (ExternalClient) frames */
|
|
355 while (!NILP (rest) &&
|
|
356 (f == XFRAME (XCAR (rest)) ||
|
|
357 !FRAME_X_TOP_LEVEL_FRAME_P (XFRAME (XCAR (rest)))))
|
|
358 rest = XCDR (rest);
|
|
359 if (NILP (rest))
|
|
360 return;
|
|
361 f = XFRAME (XCAR (rest));
|
|
362 x_wm_maybe_store_wm_command (f);
|
|
363 }
|
|
364 }
|
|
365
|
|
366 static int
|
|
367 x_frame_iconified_p (struct frame *f)
|
|
368 {
|
|
369 Atom actual_type;
|
|
370 int actual_format;
|
|
371 unsigned long nitems, bytesafter;
|
|
372 unsigned long *datap = 0;
|
|
373 Widget widget;
|
|
374 int result = 0;
|
|
375 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
376
|
|
377 widget = FRAME_X_SHELL_WIDGET (f);
|
|
378 if (Success == XGetWindowProperty (XtDisplay (widget), XtWindow (widget),
|
|
379 DEVICE_XATOM_WM_STATE (d), 0, 2, False,
|
|
380 DEVICE_XATOM_WM_STATE (d), &actual_type,
|
|
381 &actual_format, &nitems, &bytesafter,
|
|
382 (unsigned char **) &datap)
|
|
383 && datap)
|
|
384 {
|
|
385 if (nitems <= 2 /* "suggested" by ICCCM version 1 */
|
|
386 && datap[0] == IconicState)
|
|
387 result = 1;
|
|
388 XFree ((char *) datap);
|
|
389 }
|
|
390 return result;
|
|
391 }
|
|
392
|
|
393
|
|
394 /************************************************************************/
|
|
395 /* frame properties */
|
|
396 /************************************************************************/
|
|
397
|
|
398 /* Connect the frame-property names (symbols) to the corresponding
|
|
399 X Resource Manager names. The name of a property, as a Lisp symbol,
|
|
400 has an `x-resource-name' property which is a Lisp_String. */
|
|
401
|
|
402 static void
|
|
403 init_x_prop_symbols (void)
|
|
404 {
|
|
405 #define def(sym, rsrc) \
|
|
406 pure_put (sym, Qx_resource_name, build_string (rsrc))
|
|
407 #define defi(sym,rsrc) \
|
|
408 def (sym, rsrc); pure_put (sym, Qintegerp, Qt)
|
|
409
|
|
410 #if 0 /* this interferes with things. #### fix this right */
|
|
411 def (Qminibuffer, XtNminibuffer);
|
|
412 def (Qunsplittable, XtNunsplittable);
|
|
413 #endif
|
|
414 defi(Qinternal_border_width, XtNinternalBorderWidth);
|
|
415 #ifdef HAVE_TOOLBARS
|
|
416 def (Qtop_toolbar_shadow_color, XtNtopToolBarShadowColor);
|
|
417 def (Qbottom_toolbar_shadow_color, XtNbottomToolBarShadowColor);
|
|
418 def (Qbackground_toolbar_color, XtNbackgroundToolBarColor);
|
|
419 def (Qtop_toolbar_shadow_pixmap, XtNtopToolBarShadowPixmap);
|
|
420 def (Qbottom_toolbar_shadow_pixmap, XtNbottomToolBarShadowPixmap);
|
|
421 defi(Qtoolbar_shadow_thickness, XtNtoolBarShadowThickness);
|
|
422 #endif
|
|
423 def (Qscrollbar_placement, XtNscrollBarPlacement);
|
|
424 defi(Qinter_line_space, XtNinterline);
|
|
425 /* font, foreground */
|
|
426 def (Qiconic, XtNiconic);
|
|
427 def (Qbar_cursor, XtNbarCursor);
|
|
428 def (Qvisual_bell, XtNvisualBell);
|
|
429 defi(Qbell_volume, XtNbellVolume);
|
|
430 def (Qpointer_background, XtNpointerBackground);
|
|
431 def (Qpointer_color, XtNpointerColor);
|
|
432 def (Qtext_pointer, XtNtextPointer);
|
|
433 def (Qspace_pointer, XtNspacePointer);
|
|
434 def (Qmodeline_pointer, XtNmodeLinePointer);
|
|
435 def (Qgc_pointer, XtNgcPointer);
|
|
436 /* geometry, initial_geometry */
|
|
437 def (Qinitially_unmapped, XtNinitiallyUnmapped);
|
|
438 /* preferred_width, preferred_height */
|
|
439 def (Quse_backing_store, XtNuseBackingStore);
|
|
440
|
|
441 /* inherited: */
|
|
442
|
|
443 def (Qborder_color, XtNborderColor);
|
|
444 defi(Qborder_width, XtNborderWidth);
|
|
445 defi(Qwidth, XtNwidth);
|
|
446 defi(Qheight, XtNheight);
|
|
447 defi(Qleft, XtNx);
|
|
448 defi(Qtop, XtNy);
|
|
449
|
|
450 #undef def
|
|
451 }
|
|
452
|
|
453 static Lisp_Object
|
|
454 color_to_string (Widget w, unsigned long pixel)
|
|
455 {
|
|
456 char buf[255];
|
|
457
|
|
458 XColor color;
|
|
459 color.pixel = pixel;
|
|
460 XQueryColor (XtDisplay (w), w->core.colormap, &color);
|
|
461 sprintf (buf, "#%04x%04x%04x", color.red, color.green, color.blue);
|
|
462 return build_string (buf);
|
|
463 }
|
|
464
|
|
465 static void
|
|
466 x_get_top_level_position (Display *d, Window w, Position *x, Position *y)
|
|
467 {
|
|
468 Window root, parent = w, *children;
|
|
469 unsigned int nchildren;
|
|
470 XWindowAttributes xwa;
|
|
471
|
|
472 do
|
|
473 {
|
|
474 w = parent;
|
|
475 if (!XQueryTree (d, w, &root, &parent, &children, &nchildren))
|
|
476 {
|
|
477 *x = 0;
|
|
478 *y = 0;
|
|
479 return;
|
|
480 }
|
|
481 XFree (children);
|
|
482 }
|
|
483 while (root != parent);
|
|
484 XGetWindowAttributes (d, w, &xwa);
|
|
485 *x = xwa.x;
|
|
486 *y = xwa.y;
|
|
487 }
|
|
488
|
|
489 static void
|
|
490 x_smash_bastardly_shell_position (Widget shell)
|
|
491 {
|
|
492 /* Naturally those bastards who wrote Xt couldn't be bothered
|
|
493 to learn about race conditions and such. We can't trust
|
2
|
494 the X and Y values to have any semblance of correctness,
|
0
|
495 so we smash the right values in place. */
|
|
496
|
|
497 /* We might be called before we've actually realized the window (if
|
|
498 we're checking for the minibuffer resource). This will bomb in
|
|
499 that case so we don't bother calling it. */
|
|
500 if (XtWindow (shell))
|
|
501 x_get_top_level_position (XtDisplay (shell), XtWindow (shell),
|
|
502 &shell->core.x, &shell->core.y);
|
|
503 }
|
|
504
|
|
505 static Lisp_Object
|
|
506 x_frame_property (struct frame *f, Lisp_Object property)
|
|
507 {
|
|
508 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
|
509 EmacsFrame w = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
510 Widget gw = (Widget) w;
|
|
511
|
2
|
512 #define FROB(propprop, value) \
|
|
513 do { \
|
|
514 if (EQ (property, propprop)) \
|
|
515 { \
|
|
516 return (value); \
|
|
517 } \
|
0
|
518 } while (0)
|
|
519
|
|
520 if (EQ (property, Qleft) || EQ (property, Qtop))
|
|
521 x_smash_bastardly_shell_position (shell);
|
|
522 FROB (Qleft, make_int (shell->core.x));
|
|
523 FROB (Qtop, make_int (shell->core.y));
|
|
524 FROB (Qborder_width, make_int (w->core.border_width));
|
|
525 FROB (Qinternal_border_width,
|
|
526 make_int (w->emacs_frame.internal_border_width));
|
|
527 FROB (Qborder_color, color_to_string (gw, w->core.border_pixel));
|
|
528 #ifdef HAVE_TOOLBARS
|
|
529 FROB (Qtop_toolbar_shadow_color,
|
|
530 color_to_string (gw, w->emacs_frame.top_toolbar_shadow_pixel));
|
|
531 FROB (Qbottom_toolbar_shadow_color,
|
|
532 color_to_string (gw, w->emacs_frame.bottom_toolbar_shadow_pixel));
|
|
533 FROB (Qbackground_toolbar_color,
|
|
534 color_to_string (gw, w->emacs_frame.background_toolbar_pixel));
|
|
535 FROB (Qtoolbar_shadow_thickness,
|
|
536 make_int (w->emacs_frame.toolbar_shadow_thickness));
|
|
537 #endif
|
|
538 FROB (Qinter_line_space, make_int (w->emacs_frame.interline));
|
|
539 FROB (Qwindow_id, Fx_window_id (make_frame (f)));
|
|
540
|
|
541 #undef FROB
|
|
542
|
|
543 return Qunbound;
|
|
544 }
|
|
545
|
|
546 static int
|
|
547 x_internal_frame_property_p (struct frame *f, Lisp_Object property)
|
|
548 {
|
|
549 if (EQ (property, Qleft)
|
|
550 || EQ (property, Qtop)
|
|
551 || EQ (property, Qborder_width)
|
|
552 || EQ (property, Qinternal_border_width)
|
|
553 || EQ (property, Qborder_color)
|
|
554 #ifdef HAVE_TOOLBARS
|
|
555 || EQ (property, Qtop_toolbar_shadow_color)
|
|
556 || EQ (property, Qbottom_toolbar_shadow_color)
|
|
557 || EQ (property, Qbackground_toolbar_color)
|
|
558 || EQ (property, Qtoolbar_shadow_thickness)
|
|
559 #endif
|
|
560 || EQ (property, Qinter_line_space)
|
|
561 || EQ (property, Qwindow_id)
|
|
562 || STRINGP (property))
|
|
563 return 1;
|
|
564
|
|
565 return 0;
|
|
566 }
|
|
567
|
|
568 static Lisp_Object
|
|
569 x_frame_properties (struct frame *f)
|
|
570 {
|
|
571 Lisp_Object result = Qnil;
|
|
572 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
|
573 EmacsFrame w = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
574 Widget gw = (Widget) w;
|
|
575
|
2
|
576 #define FROB(propprop, value) \
|
|
577 do { \
|
|
578 Lisp_Object temtem = (value); \
|
|
579 if (!NILP (temtem)) \
|
|
580 /* backwards order; we reverse it below */ \
|
|
581 result = Fcons (temtem, Fcons (propprop, result)); \
|
0
|
582 } while (0)
|
|
583
|
|
584 x_smash_bastardly_shell_position (shell);
|
|
585 FROB (Qleft, make_int (shell->core.x));
|
|
586 FROB (Qtop, make_int (shell->core.y));
|
|
587 FROB (Qborder_width, make_int (w->core.border_width));
|
|
588 FROB (Qinternal_border_width,
|
|
589 make_int (w->emacs_frame.internal_border_width));
|
|
590 FROB (Qborder_color, color_to_string (gw, w->core.border_pixel));
|
|
591 #ifdef HAVE_TOOLBARS
|
|
592 FROB (Qtop_toolbar_shadow_color,
|
|
593 color_to_string (gw, w->emacs_frame.top_toolbar_shadow_pixel));
|
|
594 FROB (Qbottom_toolbar_shadow_color,
|
|
595 color_to_string (gw, w->emacs_frame.bottom_toolbar_shadow_pixel));
|
|
596 FROB (Qbackground_toolbar_color,
|
|
597 color_to_string (gw, w->emacs_frame.background_toolbar_pixel));
|
|
598 FROB (Qtoolbar_shadow_thickness,
|
|
599 make_int (w->emacs_frame.toolbar_shadow_thickness));
|
|
600 #endif
|
|
601 FROB (Qinter_line_space, make_int (w->emacs_frame.interline));
|
|
602 FROB (Qwindow_id, Fx_window_id (make_frame (f)));
|
|
603
|
|
604 #undef FROB
|
|
605
|
|
606 return result;
|
|
607 }
|
|
608
|
|
609
|
|
610 /* Functions called only from `x_set_frame_properties' to set
|
2
|
611 individual properties. */
|
0
|
612
|
2
|
613 static void
|
|
614 x_set_frame_text_value (struct frame *f, Bufbyte *value,
|
|
615 String Xt_resource_name,
|
|
616 String Xt_resource_encoding_name)
|
0
|
617 {
|
2
|
618 Atom encoding = XA_STRING;
|
|
619 String new_XtValue = (String) value;
|
4
|
620 String old_XtValue = NULL;
|
2
|
621 Bufbyte *ptr;
|
|
622 Arg av[2];
|
0
|
623
|
2
|
624 /* ### Caching is device-independent - belongs in update_frame_title. */
|
|
625 XtSetArg (av[0], Xt_resource_name, &old_XtValue);
|
0
|
626 XtGetValues (FRAME_X_SHELL_WIDGET (f), av, 1);
|
2
|
627 if (!old_XtValue || strcmp (new_XtValue, old_XtValue))
|
0
|
628 {
|
2
|
629 XtSetArg (av[0], Xt_resource_name, new_XtValue);
|
|
630 XtSetArg (av[1], Xt_resource_encoding_name, encoding);
|
|
631 XtSetValues (FRAME_X_SHELL_WIDGET (f), av, 2);
|
0
|
632 }
|
|
633 }
|
|
634
|
2
|
635 static void
|
|
636 x_set_title_from_bufbyte (struct frame *f, Bufbyte *name)
|
0
|
637 {
|
2
|
638 x_set_frame_text_value (f, name, XtNtitle, XtNtitleEncoding);
|
|
639 }
|
0
|
640
|
2
|
641 static void
|
|
642 x_set_icon_name_from_bufbyte (struct frame *f, Bufbyte *name)
|
|
643 {
|
|
644 x_set_frame_text_value (f, name, XtNiconName, XtNiconNameEncoding);
|
0
|
645 }
|
|
646
|
|
647 /* Set the initial frame size as specified. This function is used
|
|
648 when the frame's widgets have not yet been realized. In this
|
|
649 case, it is not sufficient just to set the width and height of
|
|
650 the EmacsFrame widget, because they will be ignored when the
|
|
651 widget is realized (instead, the shell's geometry resource is
|
|
652 used). */
|
|
653
|
|
654 static void
|
|
655 x_set_initial_frame_size (struct frame *f, int flags, int x, int y,
|
|
656 unsigned int w, unsigned int h)
|
|
657 {
|
|
658 char shell_geom [255];
|
|
659 int xval, yval;
|
|
660 char xsign, ysign;
|
|
661 char uspos = !!(flags & (XValue | YValue));
|
|
662 char ussize = !!(flags & (WidthValue | HeightValue));
|
|
663 char *temp;
|
|
664
|
|
665 /* assign the correct size to the EmacsFrame widget ... */
|
|
666 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), w, h);
|
|
667
|
|
668 /* and also set the WMShell's geometry */
|
|
669 (flags & XNegative) ? (xval = -x, xsign = '-') : (xval = x, xsign = '+');
|
|
670 (flags & YNegative) ? (yval = -y, ysign = '-') : (yval = y, ysign = '+');
|
|
671
|
|
672 if (uspos && ussize)
|
|
673 sprintf (shell_geom, "=%dx%d%c%d%c%d", w, h, xsign, xval, ysign, yval);
|
|
674 else if (uspos)
|
|
675 sprintf (shell_geom, "=%c%d%c%d", xsign, xval, ysign, yval);
|
|
676 else if (ussize)
|
|
677 sprintf (shell_geom, "=%dx%d", w, h);
|
|
678
|
|
679 if (uspos || ussize)
|
|
680 {
|
|
681 temp = xmalloc (1 + strlen (shell_geom));
|
|
682 strcpy (temp, shell_geom);
|
|
683 FRAME_X_GEOM_FREE_ME_PLEASE (f) = temp;
|
|
684 }
|
|
685 else
|
|
686 temp = NULL;
|
|
687 XtVaSetValues (FRAME_X_SHELL_WIDGET (f), XtNgeometry, temp, 0);
|
|
688 }
|
|
689
|
|
690 /* Report to X that a frame property of frame S is being set or changed.
|
|
691 If the property is not specially recognized, do nothing.
|
|
692 */
|
|
693
|
|
694 static void
|
|
695 x_set_frame_properties (struct frame *f, Lisp_Object plist)
|
|
696 {
|
|
697 int x = 0, y = 0;
|
|
698 Dimension width = 0, height = 0;
|
|
699 Bool width_specified_p = False;
|
|
700 Bool height_specified_p = False;
|
|
701 Bool x_position_specified_p = False;
|
|
702 Bool y_position_specified_p = False;
|
|
703 Bool internal_border_width_specified = False;
|
|
704 Lisp_Object tail;
|
|
705 Widget w = FRAME_X_TEXT_WIDGET (f);
|
|
706
|
|
707 for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail)))
|
|
708 {
|
|
709 Lisp_Object prop = Fcar (tail);
|
|
710 Lisp_Object val = Fcar (Fcdr (tail));
|
|
711
|
|
712 if (STRINGP (prop))
|
|
713 {
|
|
714 CONST char *extprop;
|
|
715
|
14
|
716 if (XSTRING_LENGTH (prop) == 0)
|
0
|
717 continue;
|
|
718
|
|
719 GET_C_STRING_CTEXT_DATA_ALLOCA (prop, extprop);
|
|
720 if (STRINGP (val))
|
|
721 {
|
|
722 Extbyte *extval;
|
|
723 Extcount extvallen;
|
|
724
|
|
725 GET_STRING_CTEXT_DATA_ALLOCA (val, extval, extvallen);
|
|
726 XtVaSetValues (w, XtVaTypedArg, extprop,
|
|
727 XtRString, extval, extvallen + 1, 0);
|
|
728 }
|
|
729 else
|
|
730 XtVaSetValues (w, XtVaTypedArg,
|
|
731 extprop, XtRInt, XINT (val),
|
|
732 sizeof (int),
|
|
733 0);
|
|
734 }
|
|
735 else if (SYMBOLP (prop))
|
|
736 {
|
|
737 Lisp_Object str = Fget (prop, Qx_resource_name, Qnil);
|
|
738 int int_p = !NILP (Fget (prop, Qintegerp, Qnil));
|
|
739
|
|
740 if (NILP (prop) || NILP (str))
|
|
741 {
|
|
742 /* Kludge to handle the font property. */
|
|
743 if (EQ (prop, Qfont))
|
|
744 {
|
|
745 /* If the value is not a string we silently ignore it. */
|
|
746 if (STRINGP (val))
|
|
747 {
|
|
748 Lisp_Object frm, font_spec;
|
|
749
|
|
750 XSETFRAME (frm, f);
|
|
751 font_spec = Fget (Fget_face (Qdefault), Qfont, Qnil);
|
|
752
|
|
753 Fadd_spec_to_specifier (font_spec, val, frm, Qnil, Qnil);
|
|
754 update_frame_face_values (f);
|
|
755 }
|
|
756
|
|
757 continue;
|
|
758 }
|
|
759 else
|
|
760 continue;
|
|
761 }
|
|
762 CHECK_STRING (str);
|
|
763
|
|
764 /* Kludge the width/height so that we interpret them in characters
|
|
765 instead of pixels. Yuck yuck yuck. */
|
14
|
766 if (!strcmp ((char *) XSTRING_DATA (str), "width"))
|
0
|
767 {
|
|
768 CHECK_INT (val);
|
|
769 width = XINT (val);
|
|
770 width_specified_p = True;
|
|
771 continue;
|
|
772 }
|
14
|
773 if (!strcmp ((char *) XSTRING_DATA (str), "height"))
|
0
|
774 {
|
|
775 CHECK_INT (val);
|
|
776 height = XINT (val);
|
|
777 height_specified_p = True;
|
|
778 continue;
|
|
779 }
|
|
780 /* Further kludge the x/y. */
|
14
|
781 if (!strcmp ((char *) XSTRING_DATA (str), "x"))
|
0
|
782 {
|
|
783 CHECK_INT (val);
|
|
784 x = XINT (val);
|
|
785 x_position_specified_p = True;
|
|
786 continue;
|
|
787 }
|
14
|
788 if (!strcmp ((char *) XSTRING_DATA (str), "y"))
|
0
|
789 {
|
|
790 CHECK_INT (val);
|
|
791 y = XINT (val);
|
|
792 y_position_specified_p = True;
|
|
793 continue;
|
|
794 }
|
|
795 /* Have you figured out by now that this entire function is
|
|
796 one gigantic kludge? */
|
14
|
797 if (!strcmp ((char *) XSTRING_DATA (str),
|
0
|
798 "internalBorderWidth"))
|
|
799 {
|
|
800 internal_border_width_specified = True;
|
|
801 }
|
|
802
|
|
803 if (int_p)
|
|
804 {
|
|
805 CHECK_INT (val);
|
14
|
806 XtVaSetValues (w, (char *) XSTRING_DATA (str),
|
0
|
807 XINT (val), 0);
|
|
808 }
|
|
809 else if (EQ (val, Qt))
|
|
810 XtVaSetValues (w,
|
|
811 /* XtN... */
|
14
|
812 (char *) XSTRING_DATA (str),
|
0
|
813 True,
|
|
814 0);
|
|
815 else if (EQ (val, Qnil))
|
|
816 XtVaSetValues (w,
|
|
817 /* XtN... */
|
14
|
818 (char *) XSTRING_DATA (str),
|
0
|
819 False,
|
|
820 0);
|
|
821 else
|
|
822 {
|
|
823 CHECK_STRING (val);
|
|
824 XtVaSetValues (w, XtVaTypedArg,
|
|
825 /* XtN... */
|
14
|
826 (char *) XSTRING_DATA (str),
|
0
|
827 XtRString,
|
14
|
828 XSTRING_DATA (val),
|
|
829 XSTRING_LENGTH (val) + 1,
|
0
|
830 0);
|
|
831 }
|
|
832
|
|
833 #ifdef HAVE_SCROLLBARS
|
14
|
834 if (!strcmp ((char *) XSTRING_DATA (str), "scrollBarWidth")
|
|
835 || !strcmp ((char *) XSTRING_DATA (str),
|
0
|
836 "scrollBarHeight"))
|
|
837 {
|
|
838 x_update_frame_scrollbars (f);
|
|
839 }
|
|
840 #endif
|
|
841 }
|
|
842 }
|
|
843
|
|
844 /* Kludge kludge kludge. We need to deal with the size and position
|
|
845 specially. */
|
|
846 {
|
|
847 int size_specified_p = width_specified_p || height_specified_p;
|
|
848 int position_specified_p = x_position_specified_p ||
|
|
849 y_position_specified_p;
|
|
850
|
|
851 if (!width_specified_p)
|
|
852 width = FRAME_WIDTH (f);
|
|
853 if (!height_specified_p)
|
|
854 height = FRAME_HEIGHT (f);
|
|
855
|
|
856 /* Kludge kludge kludge kludge. */
|
|
857 if (!x_position_specified_p)
|
|
858 x = (int) (FRAME_X_SHELL_WIDGET (f)->core.x);
|
|
859 if (!y_position_specified_p)
|
|
860 y = (int) (FRAME_X_SHELL_WIDGET (f)->core.y);
|
|
861
|
|
862 if (!f->init_finished)
|
|
863 {
|
|
864 int flags = (size_specified_p ? WidthValue | HeightValue : 0) |
|
|
865 (position_specified_p ? XValue | YValue : 0) |
|
|
866 (x < 0 ? XNegative : 0) | (y < 0 ? YNegative : 0);
|
|
867 if (size_specified_p
|
|
868 || position_specified_p
|
|
869 || internal_border_width_specified)
|
|
870 x_set_initial_frame_size (f, flags, x, y, width, height);
|
|
871 }
|
|
872 else
|
|
873 {
|
|
874 if (size_specified_p || internal_border_width_specified)
|
|
875 {
|
|
876 Lisp_Object frame;
|
|
877 XSETFRAME (frame, f);
|
|
878 Fset_frame_size (frame, make_int (width),
|
|
879 make_int (height), Qnil);
|
|
880 }
|
|
881 if (position_specified_p)
|
|
882 {
|
|
883 Lisp_Object frame;
|
|
884 XSETFRAME (frame, f);
|
|
885 Fset_frame_position (frame, make_int (x), make_int (y));
|
|
886 }
|
|
887 }
|
|
888 }
|
|
889 }
|
|
890
|
|
891 static int frame_title_format_already_set;
|
|
892
|
|
893 static void
|
|
894 maybe_set_frame_title_format (Widget shell)
|
|
895 {
|
|
896
|
|
897 /* Only do this if this is the first X frame we're creating.
|
|
898
|
|
899 If the *title resource (or -title option) was specified, then
|
|
900 set frame-title-format to its value.
|
|
901 */
|
|
902
|
|
903 if (!frame_title_format_already_set)
|
|
904 {
|
|
905 /* No doubt there's a less stupid way to do this. */
|
|
906 char *results [2];
|
|
907 XtResource resources [2];
|
|
908 results [0] = results [1] = 0;
|
|
909 resources [0].resource_name = XtNtitle;
|
|
910 resources [0].resource_class = XtCTitle;
|
|
911 resources [0].resource_type = XtRString;
|
|
912 resources [0].resource_size = sizeof (String);
|
|
913 resources [0].resource_offset = 0;
|
|
914 resources [0].default_type = XtRString;
|
|
915 resources [0].default_addr = 0;
|
|
916 resources [1].resource_name = XtNiconName;
|
|
917 resources [1].resource_class = XtCIconName;
|
|
918 resources [1].resource_type = XtRString;
|
|
919 resources [1].resource_size = sizeof (String);
|
|
920 resources [1].resource_offset = sizeof (char *);
|
|
921 resources [1].default_type = XtRString;
|
|
922 resources [1].default_addr = 0;
|
|
923 XtGetSubresources (XtParent (shell), (XtPointer) results,
|
|
924 shell->core.name,
|
|
925 shell->core.widget_class->core_class.class_name,
|
|
926 resources, XtNumber (resources), 0, 0);
|
|
927 if (results[0])
|
|
928 Vframe_title_format = build_string (results[0]);
|
|
929 if (results[1])
|
|
930 Vframe_icon_title_format = build_string (results[1]);
|
|
931 }
|
|
932
|
|
933 frame_title_format_already_set = 1;
|
|
934 }
|
|
935
|
|
936 #ifdef HAVE_CDE
|
|
937 #include <Dt/Dt.h>
|
|
938 #include <Dt/Dnd.h>
|
|
939
|
|
940 void
|
|
941 x_cde_transfer_callback (Widget widget, XtPointer clientData,
|
|
942 XtPointer callData)
|
|
943 {
|
16
|
944 char *filePath, *buf;
|
0
|
945 int ii;
|
16
|
946 Lisp_Object data = Qnil;
|
0
|
947 Lisp_Object path = Qnil;
|
|
948 Lisp_Object frame = Qnil;
|
|
949 struct gcpro gcpro1, gcpro2;
|
|
950
|
|
951 DtDndTransferCallbackStruct *transferInfo =
|
|
952 (DtDndTransferCallbackStruct *) callData;
|
|
953
|
|
954 if (transferInfo == NULL)
|
|
955 return;
|
|
956
|
|
957 GCPRO2 (path, frame);
|
|
958
|
|
959 frame = make_frame ((struct frame *) clientData);
|
|
960 if (transferInfo->dropData->protocol == DtDND_FILENAME_TRANSFER)
|
|
961 {
|
|
962 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
|
|
963 {
|
|
964 filePath = transferInfo->dropData->data.files[ii];
|
10
|
965 path = make_string ((Bufbyte *)filePath, strlen (filePath));
|
0
|
966 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
967 }
|
|
968 }
|
2
|
969 else if (transferInfo->dropData->protocol == DtDND_BUFFER_TRANSFER)
|
|
970 {
|
|
971 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
|
|
972 {
|
|
973 filePath = transferInfo->dropData->data.buffers[ii].name;
|
|
974 path = (filePath != NULL) ?
|
10
|
975 make_string ((Bufbyte *)filePath, strlen (filePath)) : Qnil;
|
2
|
976 buf = transferInfo->dropData->data.buffers[ii].bp;
|
10
|
977 data = make_string ((Bufbyte *)buf,
|
|
978 transferInfo->dropData->data.buffers[ii].size);
|
2
|
979 va_run_hook_with_args(Qdrag_and_drop_functions, 3, frame, path, data);
|
|
980 }
|
|
981 }
|
|
982
|
0
|
983 UNGCPRO;
|
|
984 return;
|
|
985 }
|
|
986 #endif
|
|
987
|
2
|
988 #ifdef HAVE_OFFIX_DND
|
|
989 #include <OffiX/DragAndDrop.h>
|
|
990
|
|
991 void
|
|
992 x_offix_drop_event_handler (Widget widget, XtPointer data, XEvent *event,
|
|
993 Boolean *b)
|
|
994 {
|
|
995 int i, len, Type;
|
|
996 unsigned char *Data;
|
|
997 unsigned long Size;
|
|
998
|
|
999 Lisp_Object path = Qnil;
|
|
1000 Lisp_Object frame = Qnil;
|
|
1001
|
|
1002 struct gcpro gcpro1, gcpro2;
|
|
1003
|
|
1004 Type = DndDataType (event);
|
|
1005 if ((Type != DndFile) && (Type != DndFiles) && (Type != DndExe))
|
|
1006 return;
|
|
1007 DndGetData (&Data, &Size);
|
|
1008
|
|
1009 GCPRO2 (path, frame);
|
|
1010
|
|
1011 frame = make_frame ((struct frame *) data);
|
|
1012
|
|
1013 if (Type == DndFiles)
|
|
1014 {
|
|
1015 while (*Data)
|
|
1016 {
|
|
1017 len = strlen ((char*) Data);
|
|
1018 path = make_string ((char*) Data, len);
|
|
1019 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
1020 Data += len+1;
|
|
1021 }
|
|
1022 }
|
|
1023 else
|
|
1024 {
|
|
1025 path = make_string ((char*) Data, strlen (Data));
|
|
1026 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
1027 }
|
|
1028
|
|
1029 UNGCPRO;
|
|
1030 return;
|
|
1031 }
|
|
1032 #endif /* HAVE_OFFIX_DND */
|
|
1033
|
0
|
1034
|
|
1035 /************************************************************************/
|
|
1036 /* widget creation */
|
|
1037 /************************************************************************/
|
|
1038
|
|
1039 /* The widget hierarchy is
|
|
1040
|
|
1041 argv[0] shell container FRAME-NAME
|
|
1042 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1043
|
|
1044 We accept geometry specs in this order:
|
|
1045
|
|
1046 *FRAME-NAME.geometry
|
|
1047 *EmacsFrame.geometry
|
|
1048 Emacs.geometry
|
|
1049
|
|
1050 Other possibilities for widget hierarchies might be
|
|
1051
|
|
1052 argv[0] frame container FRAME-NAME
|
|
1053 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1054 or
|
|
1055 argv[0] FRAME-NAME container FRAME-NAME
|
|
1056 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1057 or
|
|
1058 argv[0] FRAME-NAME container emacsTextPane
|
|
1059 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1060
|
|
1061 #ifdef EXTERNAL_WIDGET
|
|
1062 The ExternalShell widget is simply a replacement for the Shell widget
|
|
1063 which is able to deal with using an externally-supplied window instead
|
|
1064 of always creating its own.
|
|
1065 #endif
|
|
1066
|
|
1067 */
|
|
1068
|
|
1069 #ifdef EXTERNAL_WIDGET
|
|
1070
|
|
1071 static int
|
|
1072 is_valid_window (Window w, struct device *d)
|
|
1073 {
|
|
1074 XWindowAttributes xwa;
|
|
1075 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1076
|
|
1077 expect_x_error (dpy);
|
|
1078 XGetWindowAttributes (dpy, w, &xwa);
|
|
1079 return !x_error_occurred_p (dpy);
|
|
1080 }
|
|
1081
|
|
1082 #endif /* EXTERNAL_WIDGET */
|
|
1083
|
|
1084 /* This sends a synthetic mouse-motion event to the frame, if the mouse
|
|
1085 is over the frame. This ensures that the cursor gets set properly
|
|
1086 before the user moves the mouse for the first time. */
|
|
1087
|
|
1088 static void
|
|
1089 x_send_synthetic_mouse_event (struct frame *f)
|
|
1090 {
|
|
1091 /* #### write this function. */
|
|
1092 }
|
|
1093
|
|
1094 static int
|
|
1095 first_x_frame_p (struct frame *f)
|
|
1096 {
|
|
1097 Lisp_Object rest = DEVICE_FRAME_LIST (XDEVICE (f->device));
|
|
1098 while (!NILP (rest) &&
|
|
1099 (f == XFRAME (XCAR (rest)) ||
|
|
1100 !FRAME_X_P (XFRAME (XCAR (rest)))))
|
|
1101 rest = XCDR (rest);
|
|
1102 return (NILP (rest));
|
|
1103 }
|
|
1104
|
|
1105 /* Figure out what size the EmacsFrame widget should initially be,
|
|
1106 and set it. Should be called after the default font has been
|
|
1107 determined but before the widget has been realized. */
|
|
1108
|
|
1109 static void
|
|
1110 x_initialize_frame_size (struct frame *f)
|
|
1111 {
|
|
1112 /* Geometry of the AppShell */
|
|
1113 int app_flags = 0;
|
|
1114 int app_x = 0;
|
|
1115 int app_y = 0;
|
|
1116 unsigned int app_w = 0;
|
|
1117 unsigned int app_h = 0;
|
|
1118
|
|
1119 /* Geometry of the EmacsFrame */
|
|
1120 int frame_flags = 0;
|
|
1121 int frame_x = 0;
|
|
1122 int frame_y = 0;
|
|
1123 unsigned int frame_w = 0;
|
|
1124 unsigned int frame_h = 0;
|
|
1125
|
|
1126 /* Hairily merged geometry */
|
|
1127 int x = 0;
|
|
1128 int y = 0;
|
|
1129 unsigned int w = 80;
|
|
1130 unsigned int h = 40;
|
|
1131 int flags = 0;
|
|
1132
|
|
1133 char *geom = 0, *ew_geom = 0;
|
|
1134 Boolean iconic_p = False, ew_iconic_p = False;
|
|
1135
|
|
1136 Widget wmshell = FRAME_X_SHELL_WIDGET (f);
|
|
1137 /* #### This may not be an ApplicationShell any more, with the 'popup
|
|
1138 frame property. */
|
|
1139 Widget app_shell = XtParent (wmshell);
|
|
1140 Widget ew = FRAME_X_TEXT_WIDGET (f);
|
|
1141
|
|
1142 /* set the position of the frame's root window now. When the
|
|
1143 frame was created, the position was initialized to (0,0). */
|
|
1144 {
|
|
1145 struct window *win = XWINDOW (f->root_window);
|
|
1146
|
|
1147 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f);
|
|
1148 WINDOW_TOP (win) = FRAME_TOP_BORDER_END (f);
|
|
1149
|
|
1150 if (!NILP (f->minibuffer_window))
|
|
1151 {
|
|
1152 win = XWINDOW (f->minibuffer_window);
|
|
1153 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f);
|
|
1154 }
|
|
1155 }
|
|
1156
|
|
1157 #ifdef EXTERNAL_WIDGET
|
|
1158 /* If we're an external widget, then the size of the frame is predetermined
|
|
1159 (by the client) and is not our decision to make. */
|
|
1160 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1161 return;
|
|
1162 #endif
|
|
1163
|
|
1164 #if 0
|
|
1165 /* #### this junk has not been tested; therefore it's
|
|
1166 probably wrong. Doesn't really matter at this point because
|
|
1167 currently all frames are either top-level or external widgets. */
|
|
1168
|
|
1169 /* If we're not our own top-level window, then we shouldn't go messing around
|
|
1170 with top-level shells or "Emacs.geometry" or any such stuff. Therefore,
|
|
1171 we do as follows to determine the size of the frame:
|
|
1172
|
|
1173 1) If a value for the frame's "geometry" resource was specified, then
|
|
1174 use it. (This specifies a size in characters.)
|
|
1175 2) Else, if the "width" and "height" resources were specified, then
|
|
1176 leave them alone. (This is a value in pixels. Sorry, we can't break
|
|
1177 Xt conventions here.)
|
|
1178 3) Else, assume a size of 64x12. (This is somewhat arbitrary, but
|
|
1179 it's unlikely that a size of 80x40 is desirable because we're probably
|
|
1180 inside of a dialog box.)
|
|
1181
|
|
1182 Set the widget's x, y, height, and width as determined. Don't set the
|
|
1183 top-level container widget, because we don't necessarily know what it
|
|
1184 is. (Assume it is smart and pays attention to our values.)
|
|
1185 */
|
|
1186
|
|
1187 if (!FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1188 {
|
|
1189 XtVaGetValues (ew, XtNgeometry, &ew_geom, 0);
|
|
1190 if (ew_geom)
|
|
1191 frame_flags = XParseGeometry (ew_geom, &frame_x, &frame_y,
|
|
1192 &frame_w, &frame_h);
|
|
1193 if (! (frame_flags & (WidthValue | HeightValue)))
|
|
1194 {
|
|
1195 XtVaGetValues (ew, XtNwidth, &frame_w,
|
|
1196 XtNheight, &frame_h, 0);
|
|
1197 if (!frame_w && !frame_h)
|
|
1198 {
|
|
1199 frame_w = 64;
|
|
1200 frame_h = 12;
|
|
1201 frame_flags |= WidthValue | HeightValue;
|
|
1202 }
|
|
1203 }
|
|
1204 if (frame_flags & (WidthValue | HeightValue))
|
|
1205 EmacsFrameSetCharSize (ew, frame_w, frame_h);
|
|
1206 if (frame_flags & (XValue | YValue))
|
|
1207 {
|
|
1208 XtVaGetValues (ew, XtNwidth, &frame_w,
|
|
1209 XtNheight, &frame_h, 0);
|
|
1210 if (frame_flags & XNegative)
|
|
1211 frame_x += frame_w;
|
|
1212 if (frame_flags & YNegative)
|
|
1213 frame_y += frame_h;
|
|
1214 XtVaSetValues (ew, XtNx, frame_x, XtNy, frame_y, 0);
|
|
1215 }
|
|
1216 return;
|
|
1217 }
|
|
1218 #endif
|
|
1219
|
|
1220 /* OK, we're a top-level shell. */
|
|
1221
|
|
1222 if (!XtIsWMShell (wmshell))
|
|
1223 abort ();
|
|
1224
|
|
1225 /* If the EmacsFrame doesn't have a geometry but the shell does,
|
|
1226 treat that as the geometry of the frame. (Is this bogus?
|
|
1227 I'm not sure.) */
|
|
1228
|
|
1229 XtVaGetValues (ew, XtNgeometry, &ew_geom, 0);
|
|
1230 if (!ew_geom)
|
|
1231 {
|
|
1232 XtVaGetValues (wmshell, XtNgeometry, &geom, 0);
|
|
1233 if (geom)
|
|
1234 {
|
|
1235 ew_geom = geom;
|
|
1236 XtVaSetValues (ew, XtNgeometry, ew_geom, 0);
|
|
1237 }
|
|
1238 }
|
|
1239
|
|
1240 /* If the Shell is iconic, then the EmacsFrame is iconic. (Is
|
|
1241 this bogus? I'm not sure.) */
|
|
1242 XtVaGetValues (ew, XtNiconic, &ew_iconic_p, 0);
|
|
1243 if (!ew_iconic_p)
|
|
1244 {
|
|
1245 XtVaGetValues (wmshell, XtNiconic, &iconic_p, 0);
|
|
1246 if (iconic_p)
|
|
1247 {
|
|
1248 ew_iconic_p = iconic_p;
|
|
1249 XtVaSetValues (ew, XtNiconic, iconic_p, 0);
|
|
1250 }
|
|
1251 }
|
|
1252
|
|
1253 XtVaGetValues (app_shell, XtNgeometry, &geom, 0);
|
|
1254 if (geom)
|
|
1255 app_flags = XParseGeometry (geom, &app_x, &app_y, &app_w, &app_h);
|
|
1256
|
|
1257 if (ew_geom)
|
|
1258 frame_flags = XParseGeometry (ew_geom, &frame_x, &frame_y,
|
|
1259 &frame_w, &frame_h);
|
|
1260
|
|
1261 if (first_x_frame_p (f))
|
|
1262 {
|
|
1263 /* If this is the first frame created:
|
|
1264 ====================================
|
|
1265
|
|
1266 - Use the ApplicationShell's size/position, if specified.
|
|
1267 (This is "Emacs.geometry", or the "-geometry" command line arg.)
|
|
1268 - Else use the EmacsFrame's size/position.
|
|
1269 (This is "*FRAME-NAME.geometry")
|
|
1270
|
|
1271 - If the AppShell is iconic, the frame should be iconic.
|
|
1272
|
|
1273 AppShell comes first so that -geometry always applies to the first
|
|
1274 frame created, even if there is an "every frame" entry in the
|
|
1275 resource database.
|
|
1276 */
|
|
1277 if (app_flags & (XValue | YValue))
|
|
1278 {
|
|
1279 x = app_x; y = app_y;
|
|
1280 flags |= (app_flags & (XValue | YValue | XNegative | YNegative));
|
|
1281 }
|
|
1282 else if (frame_flags & (XValue | YValue))
|
|
1283 {
|
|
1284 x = frame_x; y = frame_y;
|
|
1285 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative));
|
|
1286 }
|
|
1287
|
|
1288 if (app_flags & (WidthValue | HeightValue))
|
|
1289 {
|
|
1290 w = app_w; h = app_h;
|
|
1291 flags |= (app_flags & (WidthValue | HeightValue));
|
|
1292 }
|
|
1293 else if (frame_flags & (WidthValue | HeightValue))
|
|
1294 {
|
|
1295 w = frame_w; h = frame_h;
|
|
1296 flags |= (frame_flags & (WidthValue | HeightValue));
|
|
1297 }
|
|
1298
|
|
1299 /* If the AppShell is iconic, then the EmacsFrame is iconic. */
|
|
1300 if (!ew_iconic_p)
|
|
1301 {
|
|
1302 XtVaGetValues (app_shell, XtNiconic, &iconic_p, 0);
|
|
1303 if (iconic_p)
|
|
1304 {
|
|
1305 ew_iconic_p = iconic_p;
|
|
1306 XtVaSetValues (ew, XtNiconic, iconic_p, 0);
|
|
1307 }
|
|
1308 }
|
|
1309 }
|
|
1310 else
|
|
1311 {
|
|
1312 /* If this is not the first frame created:
|
|
1313 ========================================
|
|
1314
|
|
1315 - use the EmacsFrame's size/position if specified
|
|
1316 - Otherwise, use the ApplicationShell's size, but not position.
|
|
1317
|
|
1318 So that means that one can specify the position of the first frame
|
|
1319 with "Emacs.geometry" or `-geometry'; but can only specify the
|
|
1320 position of subsequent frames with "*FRAME-NAME.geometry".
|
|
1321
|
|
1322 AppShell comes second so that -geometry does not apply to subsequent
|
|
1323 frames when there is an "every frame" entry in the resource db,
|
|
1324 but does apply to the first frame.
|
|
1325 */
|
|
1326 if (frame_flags & (XValue | YValue))
|
|
1327 {
|
|
1328 x = frame_x; y = frame_y;
|
|
1329 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative));
|
|
1330 }
|
|
1331
|
|
1332 if (frame_flags & (WidthValue | HeightValue))
|
|
1333 {
|
|
1334 w = frame_w; h = frame_h;
|
|
1335 flags |= (frame_flags & (WidthValue | HeightValue));
|
|
1336 }
|
|
1337 else if (app_flags & (WidthValue | HeightValue))
|
|
1338 {
|
|
1339 w = app_w;
|
|
1340 h = app_h;
|
|
1341 flags |= (app_flags & (WidthValue | HeightValue));
|
|
1342 }
|
|
1343 }
|
|
1344
|
|
1345 x_set_initial_frame_size (f, flags, x, y, w, h);
|
|
1346 }
|
|
1347
|
|
1348 static void
|
|
1349 x_get_layout_sizes (struct frame *f, Dimension *topbreadth)
|
|
1350 {
|
|
1351 int i;
|
|
1352
|
|
1353 /* compute height of all top-area widgets */
|
|
1354 for (i=0, *topbreadth = 0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
1355 {
|
|
1356 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
1357 if (wid && XtIsManaged (wid))
|
|
1358 *topbreadth += wid->core.height + 2*wid->core.border_width;
|
|
1359 }
|
|
1360 }
|
|
1361
|
|
1362 static void
|
|
1363 x_layout_widgets (Widget w, XtPointer client_data, XtPointer call_data)
|
|
1364 {
|
|
1365 struct frame *f = (struct frame *) client_data;
|
|
1366 EmacsManagerResizeStruct *emst = (EmacsManagerResizeStruct *) call_data;
|
|
1367 Dimension width = emst->width;
|
|
1368 Dimension height = emst->height;
|
|
1369 Widget text = FRAME_X_TEXT_WIDGET (f);
|
|
1370 Dimension textbord = text->core.border_width;
|
|
1371 Dimension topbreadth;
|
|
1372 Position text_x = 0, text_y = 0;
|
|
1373 int i;
|
|
1374
|
|
1375 x_get_layout_sizes (f, &topbreadth);
|
|
1376
|
|
1377 /* first the menubar and psheets ... */
|
|
1378 for (i=0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
1379 {
|
|
1380 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
1381 if (wid && XtIsManaged (wid))
|
|
1382 {
|
|
1383 Dimension bord = wid->core.border_width;
|
|
1384 XtConfigureWidget (wid, 0, text_y,
|
|
1385 width - 2*bord, wid->core.height,
|
|
1386 bord);
|
|
1387 text_y += wid->core.height + 2*bord;
|
|
1388 }
|
|
1389 }
|
|
1390
|
|
1391 #ifdef HAVE_SCROLLBARS
|
|
1392 {
|
|
1393 /* The scrollbar positioning is completely handled by redisplay. We
|
|
1394 just need to know which sides they are supposed to go on. */
|
|
1395 unsigned char scrollbar_placement;
|
|
1396 XtVaGetValues (text, XtNscrollBarPlacement, &scrollbar_placement, 0);
|
|
1397 f->scrollbar_on_left = (scrollbar_placement == XtTOP_LEFT ||
|
|
1398 scrollbar_placement == XtBOTTOM_LEFT);
|
|
1399 f->scrollbar_on_top = (scrollbar_placement == XtTOP_LEFT ||
|
|
1400 scrollbar_placement == XtTOP_RIGHT);
|
|
1401 f->scrollbar_y_offset = topbreadth + textbord;
|
|
1402 }
|
|
1403 #endif
|
|
1404
|
|
1405 /* finally the text area */
|
|
1406 XtConfigureWidget (text, text_x, text_y,
|
|
1407 width - 2*textbord,
|
|
1408 height - text_y - 2*textbord,
|
|
1409 textbord);
|
|
1410 }
|
|
1411
|
|
1412 static void
|
|
1413 x_do_query_geometry (Widget w, XtPointer client_data, XtPointer call_data)
|
|
1414 {
|
|
1415 struct frame *f = (struct frame *) client_data;
|
|
1416 EmacsManagerQueryGeometryStruct *emst =
|
|
1417 (EmacsManagerQueryGeometryStruct *) call_data;
|
|
1418 Widget text = FRAME_X_TEXT_WIDGET (f);
|
|
1419 Dimension textbord = text->core.border_width;
|
|
1420 Dimension topbreadth;
|
|
1421 XtWidgetGeometry req, repl;
|
|
1422 int mask = emst->request_mode & (CWWidth | CWHeight);
|
|
1423
|
|
1424 x_get_layout_sizes (f, &topbreadth);
|
|
1425
|
|
1426 /* strip away menubar from suggested size, and ask the text widget
|
|
1427 what size it wants to be */
|
|
1428 req.request_mode = mask;
|
|
1429 if (mask & CWWidth)
|
|
1430 req.width = emst->proposed_width - 2*textbord;
|
|
1431 if (mask & CWHeight)
|
|
1432 req.height = emst->proposed_height - topbreadth - 2*textbord;
|
|
1433 XtQueryGeometry (text, &req, &repl);
|
|
1434
|
|
1435 /* Now add the menubar back again */
|
|
1436 emst->proposed_width = repl.width + 2*textbord;
|
|
1437 emst->proposed_height = repl.height + topbreadth + 2*textbord;
|
|
1438 }
|
|
1439
|
|
1440 /* Creates the widgets for a frame.
|
|
1441 lisp_window_id is a Lisp description of an X window or Xt
|
|
1442 widget to parse.
|
|
1443
|
|
1444 This function does not create or map the windows. (That is
|
|
1445 done by x_popup_frame().)
|
|
1446 */
|
|
1447 static void
|
|
1448 x_create_widgets (struct frame *f, Lisp_Object lisp_window_id,
|
|
1449 Lisp_Object parent)
|
|
1450 {
|
|
1451 struct device *d = XDEVICE (f->device);
|
|
1452 #ifdef EXTERNAL_WIDGET
|
|
1453 Window window_id = 0;
|
|
1454 #endif
|
|
1455 CONST char *name;
|
|
1456 Arg av [25];
|
|
1457 int ac = 0;
|
|
1458 Widget text, container, shell;
|
|
1459 Widget parentwid = 0;
|
|
1460 #ifdef HAVE_MENUBARS
|
|
1461 int menubar_visible;
|
|
1462 Widget menubar;
|
|
1463 #endif
|
|
1464
|
|
1465 if (STRINGP (f->name))
|
|
1466 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, name);
|
|
1467 else
|
|
1468 name = "emacs";
|
|
1469
|
|
1470 /* The widget hierarchy is
|
|
1471
|
|
1472 argv[0] shell pane FRAME-NAME
|
|
1473 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1474
|
|
1475 (the type of the shell is ExternalShell if this frame is running
|
|
1476 in another client's window)
|
|
1477
|
|
1478 However the EmacsShell widget has WM_CLASS of FRAME-NAME/Emacs.
|
|
1479 Normally such shells have name/class shellname/appclass, which in this
|
|
1480 case would be "shell/Emacs" instead of "frame-name/Emacs". We could
|
|
1481 also get around this by naming the shell "frame-name", but that would
|
|
1482 be confusing because the text area (the EmacsFrame widget inferior of
|
|
1483 the shell) is also called that. So we just set the WM_CLASS property.
|
|
1484 */
|
|
1485
|
|
1486 #ifndef EXTERNAL_WIDGET
|
|
1487 if (!NILP (lisp_window_id))
|
|
1488 error ("support for external widgets was not enabled at compile-time");
|
|
1489 #else
|
|
1490 if (!NILP (lisp_window_id))
|
|
1491 {
|
|
1492 char *string;
|
|
1493
|
|
1494 CHECK_STRING (lisp_window_id);
|
14
|
1495 string = (char *) XSTRING_DATA (lisp_window_id);
|
0
|
1496 if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))
|
|
1497 sscanf (string+2, "%lxu", &window_id);
|
|
1498 #if 0
|
|
1499 else if (string[0] == 'w')
|
|
1500 {
|
|
1501 sscanf (string+1, "%x", &parent_widget);
|
|
1502 if (parent_widget)
|
|
1503 window_id = XtWindow (parent_widget);
|
|
1504 }
|
|
1505 #endif
|
|
1506 else
|
|
1507 sscanf (string, "%lu", &window_id);
|
|
1508 if (!is_valid_window (window_id, d))
|
|
1509 error ("Invalid window %lu", (unsigned long) window_id);
|
|
1510 FRAME_X_EXTERNAL_WINDOW_P (f) = 1;
|
|
1511 } else
|
|
1512 #endif /* EXTERNAL_WIDGET */
|
|
1513 FRAME_X_TOP_LEVEL_FRAME_P (f) = 1;
|
|
1514
|
|
1515 ac = 0;
|
|
1516 XtSetArg (av[ac], XtNallowShellResize, True); ac++;
|
|
1517 #ifdef LWLIB_USES_MOTIF
|
|
1518 /* Motif sucks beans. Without this in here, it will delete the window
|
|
1519 out from under us when it receives a WM_DESTROY_WINDOW message
|
|
1520 from the WM. */
|
|
1521 XtSetArg (av[ac], XmNdeleteResponse, XmDO_NOTHING); ac++;
|
|
1522 #endif
|
|
1523
|
|
1524 #ifdef EXTERNAL_WIDGET
|
|
1525 if (window_id)
|
|
1526 {
|
|
1527 XtSetArg (av[ac], XtNwindow, window_id); ac++;
|
|
1528 }
|
|
1529 else
|
|
1530 #endif
|
|
1531 {
|
|
1532 XtSetArg (av[ac], XtNinput, True); ac++;
|
2
|
1533 XtSetArg (av[ac], (String) XtNminWidthCells, 10); ac++;
|
|
1534 XtSetArg (av[ac], (String) XtNminHeightCells, 1); ac++;
|
0
|
1535 }
|
|
1536
|
|
1537 if (!NILP (parent))
|
|
1538 {
|
|
1539 parentwid = FRAME_X_SHELL_WIDGET (XFRAME (parent));
|
|
1540 XtSetArg (av[ac], XtNtransientFor, parentwid); ac++;
|
|
1541 }
|
|
1542
|
|
1543 shell = XtCreatePopupShell ("shell",
|
|
1544 (
|
|
1545 #ifdef EXTERNAL_WIDGET
|
|
1546 window_id ? externalShellWidgetClass :
|
|
1547 #endif
|
|
1548 parentwid ? transientEmacsShellWidgetClass :
|
|
1549 topLevelEmacsShellWidgetClass
|
|
1550 ),
|
|
1551 parentwid ? parentwid :
|
|
1552 DEVICE_XT_APP_SHELL (d),
|
|
1553 av, ac);
|
|
1554 FRAME_X_SHELL_WIDGET (f) = shell;
|
|
1555 maybe_set_frame_title_format (shell);
|
|
1556
|
|
1557 /* Create the manager widget */
|
|
1558 container = XtVaCreateWidget ("container",
|
|
1559 emacsManagerWidgetClass,
|
|
1560 shell, 0);
|
|
1561 FRAME_X_CONTAINER_WIDGET (f) = container;
|
|
1562 XtAddCallback (container, XtNresizeCallback, x_layout_widgets,
|
|
1563 (XtPointer) f);
|
|
1564 XtAddCallback (container, XtNqueryGeometryCallback, x_do_query_geometry,
|
|
1565 (XtPointer) f);
|
|
1566
|
|
1567 /* Create the text area */
|
|
1568 ac = 0;
|
|
1569 XtSetArg (av[ac], XtNborderWidth, 0); ac++; /* should this be settable? */
|
2
|
1570 XtSetArg (av[ac], (String) XtNemacsFrame, f); ac++;
|
0
|
1571 text = XtCreateWidget (name,
|
|
1572 emacsFrameClass,
|
|
1573 container, av, ac);
|
|
1574 FRAME_X_TEXT_WIDGET (f) = text;
|
|
1575
|
|
1576 #ifdef HAVE_MENUBARS
|
|
1577 /* Create the initial menubar widget. */
|
|
1578 menubar_visible = x_initialize_frame_menubar (f);
|
|
1579 FRAME_X_TOP_WIDGETS (f)[0] = menubar = FRAME_X_MENUBAR_WIDGET (f);
|
|
1580 FRAME_X_NUM_TOP_WIDGETS (f) = 1;
|
|
1581
|
|
1582 if (menubar_visible)
|
|
1583 XtManageChild (menubar);
|
|
1584 #endif
|
|
1585 XtManageChild (text);
|
|
1586 XtManageChild (container);
|
|
1587 }
|
|
1588
|
|
1589 /* We used to call XtPopup() in x_popup_frame, but that doesn't give
|
|
1590 you control over whether the widget is initially mapped or not
|
|
1591 because XtPopup() makes an unconditional call to XMapRaised().
|
|
1592 Boy, those Xt designers were clever.
|
|
1593
|
|
1594 When we first removed it we only kept the XtRealizeWidget call in
|
|
1595 XtPopup. For everything except HP's that was enough. For HP's,
|
|
1596 though, the failure to call the popup callbacks resulted in XEmacs
|
|
1597 not accepting any input. Bizarre but true. Stupid but true.
|
|
1598
|
|
1599 So, in case there are any other gotches floating out there along
|
|
1600 the same lines I've duplicated the majority of XtPopup here. It
|
|
1601 assumes no grabs and that the widget is not already popped up, both
|
|
1602 valid assumptions for the one place this is called from. */
|
|
1603 static void
|
|
1604 xemacs_XtPopup (Widget widget)
|
|
1605 {
|
|
1606 ShellWidget shell_widget = (ShellWidget) widget;
|
|
1607 XtGrabKind call_data = XtGrabNone;
|
|
1608
|
|
1609 XtCallCallbacks (widget, XtNpopupCallback, (XtPointer)&call_data);
|
|
1610
|
|
1611 shell_widget->shell.popped_up = TRUE;
|
|
1612 shell_widget->shell.grab_kind = XtGrabNone;
|
|
1613 shell_widget->shell.spring_loaded = False;
|
|
1614
|
|
1615 if (shell_widget->shell.create_popup_child_proc != NULL)
|
|
1616 (*(shell_widget->shell.create_popup_child_proc))(widget);
|
|
1617
|
|
1618 /* The XtVaSetValues below are not in XtPopup menu. We just want to
|
|
1619 make absolutely sure... */
|
|
1620 XtVaSetValues (widget, XtNmappedWhenManaged, False, NULL);
|
|
1621 XtRealizeWidget (widget);
|
|
1622 XtVaSetValues (widget, XtNmappedWhenManaged, True, NULL);
|
|
1623 }
|
|
1624
|
|
1625 #ifdef HAVE_CDE
|
|
1626 /* Does this have to be non-automatic? */
|
|
1627 /* hack frame to respond to dnd messages */
|
|
1628 static XtCallbackRec dnd_transfer_cb_rec[2];
|
|
1629 #endif
|
|
1630
|
|
1631 /* create the windows for the specified frame and display them.
|
|
1632 Note that the widgets have already been created, and any
|
|
1633 necessary geometry calculations have already been done. */
|
|
1634 static void
|
|
1635 x_popup_frame (struct frame *f)
|
|
1636 {
|
|
1637 Widget shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
1638 Widget frame_widget = FRAME_X_TEXT_WIDGET (f);
|
|
1639 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
1640
|
|
1641 /* Before mapping the window, make sure that the WMShell's notion of
|
|
1642 whether it should be iconified is synchronized with the EmacsFrame's
|
|
1643 notion.
|
|
1644 */
|
|
1645 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1646 x_wm_set_shell_iconic_p (shell_widget,
|
|
1647 ((EmacsFrame) frame_widget)
|
|
1648 ->emacs_frame.iconic);
|
|
1649
|
|
1650 xemacs_XtPopup (shell_widget);
|
|
1651
|
|
1652 if (!((EmacsFrame) frame_widget)->emacs_frame.initially_unmapped)
|
|
1653 XtMapWidget (shell_widget);
|
|
1654 else
|
|
1655 {
|
|
1656 /* We may have set f->visible to 1 in x_init_frame(), so undo
|
|
1657 that now. */
|
|
1658 FRAME_X_TOTALLY_VISIBLE_P (f) = 0;
|
|
1659 f->visible = 0;
|
|
1660 }
|
|
1661
|
|
1662 #ifdef EXTERNAL_WIDGET
|
|
1663 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1664 ExternalShellReady (shell_widget, XtWindow (frame_widget), KeyPressMask);
|
|
1665 else
|
|
1666 #endif
|
|
1667 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1668 {
|
|
1669 /* tell the window manager about us. */
|
|
1670 x_wm_store_class_hints (shell_widget, XtName (frame_widget));
|
|
1671 x_wm_maybe_store_wm_command (f);
|
|
1672 x_wm_hack_wm_protocols (shell_widget);
|
|
1673 }
|
|
1674
|
|
1675 #ifdef HACK_EDITRES
|
|
1676 /* Allow XEmacs to respond to EditRes requests. See the O'Reilly Xt */
|
|
1677 /* Instrinsics Programming Manual, Motif Edition, Aug 1993, Sect 14.14, */
|
|
1678 /* pp. 483-493. */
|
|
1679 XtAddEventHandler (shell_widget, /* the shell widget in question */
|
|
1680 (EventMask) NoEventMask,/* OR with existing mask */
|
|
1681 True, /* called on non-maskable events? */
|
|
1682 _XEditResCheckMessages, /* the handler */
|
|
1683 NULL);
|
|
1684 #endif
|
|
1685
|
|
1686 #ifdef HAVE_CDE
|
|
1687 {
|
|
1688 dnd_transfer_cb_rec[0].callback = x_cde_transfer_callback;
|
|
1689 dnd_transfer_cb_rec[0].closure = (XtPointer) f;
|
|
1690 dnd_transfer_cb_rec[1].callback = NULL;
|
|
1691 dnd_transfer_cb_rec[1].closure = NULL;
|
|
1692
|
|
1693 DtDndVaDropRegister (FRAME_X_TEXT_WIDGET (f),
|
2
|
1694 DtDND_FILENAME_TRANSFER | DtDND_BUFFER_TRANSFER,
|
|
1695 XmDROP_COPY, dnd_transfer_cb_rec,
|
|
1696 DtNtextIsBuffer, True,
|
0
|
1697 DtNpreserveRegistration, False,
|
|
1698 NULL);
|
|
1699 }
|
|
1700 #endif
|
|
1701
|
2
|
1702 #ifdef HAVE_OFFIX_DND
|
|
1703 {
|
|
1704 DndInitialize (FRAME_X_SHELL_WIDGET (f));
|
|
1705 DndRegisterDropWidget (FRAME_X_TEXT_WIDGET (f),
|
|
1706 x_offix_drop_event_handler,
|
|
1707 (XtPointer) f);
|
|
1708
|
|
1709 }
|
|
1710 #endif
|
|
1711
|
0
|
1712 /* Do a stupid property change to force the server to generate a
|
|
1713 propertyNotify event so that the event_stream server timestamp will
|
|
1714 be initialized to something relevant to the time we created the window.
|
|
1715 */
|
|
1716 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
|
|
1717 DEVICE_XATOM_WM_PROTOCOLS (d), XA_ATOM, 32, PropModeAppend,
|
|
1718 (unsigned char*) NULL, 0);
|
|
1719
|
|
1720 x_send_synthetic_mouse_event (f);
|
|
1721 }
|
|
1722
|
|
1723 static void
|
|
1724 allocate_x_frame_struct (struct frame *f)
|
|
1725 {
|
|
1726 /* zero out all slots. */
|
|
1727 f->frame_data = malloc_type_and_zero (struct x_frame);
|
|
1728
|
|
1729 /* yeah, except the lisp ones */
|
|
1730 FRAME_X_ICON_PIXMAP (f) = Qnil;
|
|
1731 FRAME_X_ICON_PIXMAP_MASK (f) = Qnil;
|
|
1732 #ifdef ENERGIZE
|
|
1733 FRAME_X_CURRENT_PSHEET_BUFFER (f) = Qnil;
|
|
1734 FRAME_X_DESIRED_PSHEET_BUFFER (f) = Qnil;
|
|
1735 #endif
|
|
1736 }
|
|
1737
|
|
1738
|
|
1739 /************************************************************************/
|
|
1740 /* Lisp functions */
|
|
1741 /************************************************************************/
|
|
1742
|
|
1743 static void
|
|
1744 x_init_frame_1 (struct frame *f, Lisp_Object props)
|
|
1745 {
|
|
1746 /* This function can GC */
|
|
1747 Lisp_Object device = FRAME_DEVICE (f);
|
|
1748 struct device *d = XDEVICE (device);
|
|
1749 Lisp_Object lisp_window_id;
|
|
1750 Lisp_Object popup;
|
|
1751
|
|
1752 lisp_window_id = Fplist_get (props, Qwindow_id, Qnil);
|
|
1753 popup = Fplist_get (props, Qpopup, Qnil);
|
|
1754 if (!NILP (popup))
|
|
1755 {
|
|
1756 if (EQ (popup, Qt))
|
|
1757 popup = Fselected_frame (device);
|
|
1758 CHECK_LIVE_FRAME (popup);
|
|
1759 if (!EQ (device, FRAME_DEVICE (XFRAME (popup))))
|
|
1760 signal_simple_error_2 ("Parent must be on same device as frame",
|
|
1761 device, popup);
|
|
1762 }
|
|
1763
|
|
1764 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
1765 {
|
|
1766 /* This means that this is the first frame on the device.
|
|
1767 So short-ciruit the delay in processing the initial MapNotify
|
|
1768 event so that output on the first frame shows up right
|
|
1769 away... */
|
|
1770 f->visible = 1;
|
|
1771 }
|
|
1772
|
|
1773 allocate_x_frame_struct (f);
|
|
1774 x_create_widgets (f, lisp_window_id, popup);
|
|
1775 }
|
|
1776
|
|
1777 static void
|
|
1778 x_init_frame_2 (struct frame *f, Lisp_Object props)
|
|
1779 {
|
|
1780 /* Set up the values of the widget/frame. A case could be made for putting
|
|
1781 this inside of the widget's initialize method. */
|
|
1782
|
|
1783 update_frame_face_values (f);
|
|
1784 x_initialize_frame_size (f);
|
|
1785 update_frame_title (f);
|
|
1786 }
|
|
1787
|
|
1788 static void
|
|
1789 x_init_frame_3 (struct frame *f)
|
|
1790 {
|
|
1791 /* Pop up the frame. */
|
|
1792
|
|
1793 x_popup_frame (f);
|
|
1794 }
|
|
1795
|
|
1796 static void
|
|
1797 x_mark_frame (struct frame *f, void (*markobj) (Lisp_Object))
|
|
1798 {
|
|
1799 ((markobj) (FRAME_X_ICON_PIXMAP (f)));
|
|
1800 ((markobj) (FRAME_X_ICON_PIXMAP_MASK (f)));
|
|
1801 #ifdef ENERGIZE
|
|
1802 ((markobj) (FRAME_X_CURRENT_PSHEET_BUFFER (f)));
|
|
1803 ((markobj) (FRAME_X_DESIRED_PSHEET_BUFFER (f)));
|
|
1804 #endif
|
|
1805 }
|
|
1806
|
|
1807 static void
|
|
1808 x_set_frame_icon (struct frame *f)
|
|
1809 {
|
|
1810 Pixmap x_pixmap, x_mask;
|
|
1811
|
|
1812 if (IMAGE_INSTANCEP (f->icon)
|
|
1813 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (f->icon)))
|
|
1814 {
|
|
1815 x_pixmap = XIMAGE_INSTANCE_X_PIXMAP (f->icon);
|
|
1816 x_mask = XIMAGE_INSTANCE_X_MASK (f->icon);
|
|
1817 }
|
|
1818 else
|
|
1819 {
|
|
1820 x_pixmap = 0;
|
|
1821 x_mask = 0;
|
|
1822 }
|
|
1823
|
|
1824 /* Store the X data into the widget. */
|
|
1825 {
|
|
1826 Arg av [10];
|
|
1827 int ac = 0;
|
|
1828 XtSetArg (av [ac], XtNiconPixmap, x_pixmap); ac++;
|
|
1829 XtSetArg (av [ac], XtNiconMask, x_mask); ac++;
|
|
1830 XtSetValues (FRAME_X_SHELL_WIDGET (f), av, ac);
|
|
1831 }
|
|
1832 }
|
|
1833
|
|
1834 static void
|
|
1835 x_set_frame_pointer (struct frame *f)
|
|
1836 {
|
|
1837 XDefineCursor (XtDisplay (FRAME_X_TEXT_WIDGET (f)),
|
|
1838 XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
1839 XIMAGE_INSTANCE_X_CURSOR (f->pointer));
|
|
1840 XSync (XtDisplay (FRAME_X_TEXT_WIDGET (f)), 0);
|
|
1841 }
|
|
1842
|
|
1843 static Lisp_Object
|
|
1844 x_get_frame_parent (struct frame *f)
|
|
1845 {
|
|
1846 Widget parentwid = 0;
|
|
1847 Arg av[1];
|
|
1848
|
|
1849 XtSetArg (av[0], XtNtransientFor, &parentwid);
|
|
1850 XtGetValues (FRAME_X_SHELL_WIDGET (f), av, 1);
|
|
1851 /* find the frame whose wid is parentwid */
|
|
1852 if (parentwid)
|
|
1853 {
|
|
1854 Lisp_Object frmcons;
|
|
1855 DEVICE_FRAME_LOOP (frmcons, XDEVICE (FRAME_DEVICE (f)))
|
|
1856 {
|
|
1857 Lisp_Object frame = XCAR (frmcons);
|
|
1858 if (FRAME_X_SHELL_WIDGET (XFRAME (frame)) == parentwid)
|
|
1859 return frame;
|
|
1860 }
|
|
1861 }
|
|
1862 return Qnil;
|
|
1863 }
|
|
1864
|
|
1865 DEFUN ("x-window-id", Fx_window_id, Sx_window_id, 0, 1, 0 /*
|
|
1866 Get the ID of the X11 window.
|
|
1867 This gives us a chance to manipulate the Emacs window from within a
|
|
1868 different program. Since the ID is an unsigned long, we return it as
|
|
1869 a string.
|
|
1870 */ )
|
|
1871 (frame)
|
|
1872 Lisp_Object frame;
|
|
1873 {
|
|
1874 char str[255];
|
|
1875 struct frame *f = decode_x_frame (frame);
|
|
1876
|
|
1877 sprintf (str, "%lu", XtWindow (FRAME_X_TEXT_WIDGET (f)));
|
|
1878 return build_string (str);
|
|
1879 }
|
|
1880
|
|
1881
|
|
1882 /************************************************************************/
|
|
1883 /* manipulating the X window */
|
|
1884 /************************************************************************/
|
|
1885
|
|
1886 static void
|
|
1887 x_set_frame_position (struct frame *f, int xoff, int yoff)
|
|
1888 {
|
|
1889 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
1890 Display *dpy = XtDisplay (w);
|
|
1891 Dimension frame_w = DisplayWidth (dpy, DefaultScreen (dpy));
|
|
1892 Dimension frame_h = DisplayHeight (dpy, DefaultScreen (dpy));
|
|
1893 Dimension shell_w, shell_h, shell_bord;
|
|
1894 int win_gravity;
|
|
1895
|
|
1896 XtVaGetValues (w,
|
|
1897 XtNwidth, &shell_w,
|
|
1898 XtNheight, &shell_h,
|
|
1899 XtNborderWidth, &shell_bord,
|
|
1900 0);
|
|
1901
|
|
1902 win_gravity =
|
|
1903 xoff >= 0 && yoff >= 0 ? NorthWestGravity :
|
|
1904 xoff >= 0 ? SouthWestGravity :
|
|
1905 yoff >= 0 ? NorthEastGravity :
|
|
1906 SouthEastGravity;
|
|
1907 if (xoff < 0)
|
|
1908 xoff += frame_w - shell_w - 2*shell_bord;
|
|
1909 if (yoff < 0)
|
|
1910 yoff += frame_h - shell_h - 2*shell_bord;
|
|
1911
|
|
1912 /* Update the hints so that, if this window is currently iconified, it will
|
|
1913 come back at the right place. We can't look at s->visible to determine
|
|
1914 whether it is iconified because it might not be up-to-date yet (the queue
|
|
1915 might not be processed). */
|
|
1916 XtVaSetValues (w,
|
|
1917 XtNwinGravity, win_gravity,
|
|
1918 XtNx, xoff,
|
|
1919 XtNy, yoff,
|
|
1920 0);
|
|
1921 /* Sometimes you will find that
|
|
1922
|
|
1923 (set-frame-position (selected-frame) -50 -50)
|
|
1924
|
|
1925 doesn't put the frame where you expect it to:
|
|
1926 i.e. it's closer to the lower-right corner than
|
2
|
1927 it should be, and it appears that the size of
|
0
|
1928 the WM decorations was not taken into account.
|
|
1929 This is *not* a problem with this function.
|
|
1930 Both mwm and twm have bugs in handling this
|
|
1931 situation. (mwm ignores the window gravity
|
|
1932 and always assumes NorthWest, except the first
|
|
1933 time you map the window; twm gets things almost
|
|
1934 right, but forgets to account for the border
|
|
1935 width of the top-level window.) This function
|
|
1936 does what it's supposed to according to the ICCCM,
|
|
1937 and I'm not about to hack around window-manager
|
|
1938 bugs. */
|
|
1939
|
|
1940 #if 0
|
|
1941 /* This is not necessary under either mwm or twm */
|
|
1942 x_wm_mark_shell_position_user_specified (w);
|
|
1943 #endif
|
|
1944 }
|
|
1945
|
|
1946 /* Call this to change the size of frame S's x-window. */
|
|
1947
|
|
1948 static void
|
|
1949 x_set_frame_size (struct frame *f, int cols, int rows)
|
|
1950 {
|
|
1951 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), cols, rows);
|
|
1952 #if 0
|
|
1953 /* this is not correct. x_set_frame_size() is called from
|
|
1954 Fset_frame_size(), which may or may not have been called
|
|
1955 by the user (e.g. update_EmacsFrame() calls it when the font
|
|
1956 changes). For now, don't bother with getting this right. */
|
|
1957 x_wm_mark_shell_size_user_specified (FRAME_X_SHELL_WIDGET (f));
|
|
1958 #endif
|
|
1959 }
|
|
1960
|
|
1961 static void
|
|
1962 x_set_mouse_position (struct window *w, int x, int y)
|
|
1963 {
|
|
1964 struct frame *f = XFRAME (w->frame);
|
|
1965
|
|
1966 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
1967 XWarpPointer (display, None, XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
1968 0, 0, 0, 0, w->pixel_left + x, w->pixel_top + y);
|
|
1969 }
|
|
1970
|
|
1971 static int
|
|
1972 x_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y)
|
|
1973 {
|
|
1974 Display *display = DEVICE_X_DISPLAY (d);
|
|
1975 Window child_window;
|
|
1976 Window root_window;
|
|
1977 Window win;
|
|
1978 int root_x, root_y;
|
|
1979 int win_x, win_y;
|
|
1980 unsigned int keys_and_buttons;
|
|
1981 struct frame *f;
|
|
1982
|
|
1983 if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
|
|
1984 &root_window, &child_window, &root_x, &root_y,
|
|
1985 &win_x, &win_y, &keys_and_buttons) == False)
|
|
1986 return 0;
|
|
1987
|
|
1988 if (child_window == None)
|
|
1989 return 0; /* not over any window. */
|
|
1990
|
|
1991 while (1)
|
|
1992 {
|
|
1993 win = child_window;
|
|
1994 if (XTranslateCoordinates (display, root_window, win, root_x, root_y,
|
|
1995 &win_x, &win_y, &child_window) == False)
|
|
1996 /* Huh? */
|
|
1997 return 0;
|
|
1998
|
|
1999 if (child_window == None)
|
|
2000 break;
|
|
2001 }
|
|
2002
|
|
2003 /* At this point, win is the innermost window containing the pointer
|
|
2004 and win_x and win_y are the coordinates of that window. */
|
|
2005 f = x_any_window_to_frame (d, win);
|
|
2006 if (!f)
|
|
2007 return 0;
|
|
2008 XSETFRAME (*frame, f);
|
|
2009
|
|
2010 if (XTranslateCoordinates (display, win,
|
|
2011 XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
2012 win_x, win_y, x, y, &child_window) == False)
|
|
2013 /* Huh? */
|
|
2014 return 0;
|
|
2015
|
|
2016 return 1;
|
|
2017 }
|
|
2018
|
|
2019 static void
|
|
2020 x_cant_notify_wm_error (void)
|
|
2021 {
|
|
2022 error ("Can't notify window manager of iconification.");
|
|
2023 }
|
|
2024
|
|
2025 /* Raise frame F. */
|
|
2026 static void
|
|
2027 x_raise_frame_1 (struct frame *f, int force)
|
|
2028 {
|
|
2029 Widget bottom_dialog;
|
|
2030 Window emacs_window;
|
|
2031 XWindowChanges xwc;
|
|
2032 unsigned int flags;
|
|
2033 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2034
|
|
2035 if (f->visible || force)
|
|
2036 {
|
|
2037 emacs_window = XtWindow (FRAME_X_SHELL_WIDGET (f));
|
|
2038 /* first raises all the dialog boxes, then put emacs just below the
|
|
2039 * bottom most dialog box */
|
|
2040 bottom_dialog = lw_raise_all_pop_up_widgets ();
|
|
2041 if (bottom_dialog && XtWindow (bottom_dialog))
|
|
2042 {
|
|
2043 xwc.sibling = XtWindow (bottom_dialog);
|
|
2044 xwc.stack_mode = Below;
|
|
2045 flags = CWSibling | CWStackMode;
|
|
2046 }
|
|
2047 else
|
|
2048 {
|
|
2049 xwc.stack_mode = Above;
|
|
2050 flags = CWStackMode;
|
|
2051 }
|
|
2052
|
|
2053 if (!XReconfigureWMWindow (display, emacs_window,
|
|
2054 DefaultScreen (display),
|
|
2055 flags, &xwc))
|
|
2056 x_cant_notify_wm_error ();
|
|
2057 }
|
|
2058 }
|
|
2059
|
|
2060 static void
|
|
2061 x_raise_frame (struct frame *f)
|
|
2062 {
|
|
2063 x_raise_frame_1 (f, 1);
|
|
2064 }
|
|
2065
|
|
2066 /* Lower frame F. */
|
|
2067 static void
|
|
2068 x_lower_frame (struct frame *f)
|
|
2069 {
|
|
2070 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2071 XWindowChanges xwc;
|
|
2072 unsigned int flags;
|
|
2073
|
|
2074 if (f->visible)
|
|
2075 {
|
|
2076 xwc.stack_mode = Below;
|
|
2077 flags = CWStackMode;
|
|
2078 if (!XReconfigureWMWindow (display, XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2079 DefaultScreen (display), flags, &xwc))
|
|
2080 x_cant_notify_wm_error ();
|
|
2081 }
|
|
2082 }
|
|
2083
|
|
2084 /* Change from withdrawn state to mapped state. */
|
|
2085 static void
|
|
2086 x_make_frame_visible (struct frame *f)
|
|
2087 {
|
|
2088 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2089
|
|
2090 if (!f->visible)
|
|
2091 XMapRaised (display, XtWindow (FRAME_X_SHELL_WIDGET (f)));
|
|
2092 else
|
|
2093 x_raise_frame_1 (f, 0);
|
|
2094 }
|
|
2095
|
|
2096 /* Change from mapped state to withdrawn state. */
|
|
2097 static void
|
|
2098 x_make_frame_invisible (struct frame *f)
|
|
2099 {
|
|
2100 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2101
|
|
2102 if (!f->visible)
|
|
2103 return;
|
|
2104
|
|
2105 if (!XWithdrawWindow (display,
|
|
2106 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2107 DefaultScreen (display)))
|
|
2108 x_cant_notify_wm_error ();
|
|
2109 }
|
|
2110
|
|
2111 static int
|
|
2112 x_frame_visible_p (struct frame *f)
|
|
2113 {
|
|
2114 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2115 XWindowAttributes xwa;
|
|
2116 int result;
|
|
2117
|
|
2118 if (!XGetWindowAttributes (display,
|
|
2119 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2120 &xwa))
|
|
2121 result = 0;
|
|
2122 else
|
|
2123 result = xwa.map_state == IsViewable;
|
|
2124
|
|
2125 f->visible = result;
|
|
2126 return result;
|
|
2127 }
|
|
2128
|
|
2129 static int
|
|
2130 x_frame_totally_visible_p (struct frame *f)
|
|
2131 {
|
|
2132 return FRAME_X_TOTALLY_VISIBLE_P (f);
|
|
2133 }
|
|
2134
|
|
2135 /* Change window state from mapped to iconified. */
|
|
2136 static void
|
|
2137 x_iconify_frame (struct frame *f)
|
|
2138 {
|
|
2139 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2140
|
|
2141 if (!XIconifyWindow (display,
|
|
2142 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2143 DefaultScreen (display)))
|
|
2144 x_cant_notify_wm_error ();
|
|
2145
|
|
2146 f->iconified = 1;
|
|
2147 }
|
|
2148
|
|
2149 /* Sets the X focus to frame f. */
|
|
2150 static void
|
|
2151 x_focus_on_frame (struct frame *f)
|
|
2152 {
|
|
2153 XWindowAttributes xwa;
|
|
2154 Widget shell_widget;
|
|
2155
|
|
2156 assert (FRAME_X_P (f));
|
|
2157
|
|
2158 shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
2159 if (!XtWindow (shell_widget))
|
|
2160 return;
|
|
2161
|
|
2162 #ifdef EXTERNAL_WIDGET
|
|
2163 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
2164 ExternalShellSetFocus (shell_widget);
|
|
2165 #endif /* EXTERNAL_WIDGET */
|
|
2166
|
|
2167 /* Do the ICCCM focus change if the window is still visible.
|
|
2168 The s->visible flag might not be up-to-date, because we might
|
|
2169 not have processed magic events recently. So make a server
|
|
2170 round-trip to find out whether it's really mapped right now.
|
|
2171 We grab the server to do this, because that's the only way to
|
|
2172 eliminate the race condition.
|
|
2173 */
|
|
2174 XGrabServer (XtDisplay (shell_widget));
|
|
2175 if (XGetWindowAttributes (XtDisplay (shell_widget),
|
|
2176 XtWindow (shell_widget),
|
|
2177 &xwa))
|
|
2178 f->visible = xwa.map_state == IsViewable;
|
|
2179
|
|
2180 if (f->visible)
|
|
2181 {
|
|
2182 Window focus;
|
|
2183 int revert_to;
|
|
2184 XGetInputFocus (XtDisplay (shell_widget), &focus, &revert_to);
|
|
2185 /* Don't explicitly set the focus on this window unless the focus
|
|
2186 was on some other window (not PointerRoot). Note that, even when
|
|
2187 running a point-to-type window manager like *twm, there is always
|
|
2188 a focus window; the window manager maintains that based on the
|
|
2189 mouse position. If you set the "NoTitleFocus" option in these
|
|
2190 window managers, then the server itself maintains the focus via
|
|
2191 PointerRoot, and changing that to focus on the window would make
|
|
2192 the window grab the focus. Very bad.
|
|
2193 */
|
|
2194 if (focus != PointerRoot)
|
|
2195 {
|
|
2196 XSetInputFocus (XtDisplay (shell_widget),
|
|
2197 XtWindow (shell_widget),
|
|
2198 RevertToParent,
|
|
2199 DEVICE_X_MOUSE_TIMESTAMP
|
|
2200 (XDEVICE (FRAME_DEVICE (f))));
|
|
2201 XFlush (XtDisplay (shell_widget));
|
|
2202 }
|
|
2203 }
|
|
2204 XUngrabServer (XtDisplay (shell_widget));
|
|
2205 XFlush (XtDisplay (shell_widget)); /* hey, I'd like to DEBUG this... */
|
|
2206 }
|
|
2207
|
|
2208 /* Destroy the X window of frame S. */
|
|
2209 static void
|
|
2210 x_delete_frame (struct frame *f)
|
|
2211 {
|
|
2212 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
2213 Lisp_Object popup, frame;
|
|
2214
|
|
2215 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
2216 x_wm_maybe_move_wm_command (f);
|
|
2217
|
|
2218 /* Frames with the popup property are using other frames as their
|
|
2219 widget parent. Deleting them are their parent has already been
|
|
2220 deleted can lead to crashes. */
|
|
2221 XSETFRAME (frame, f);
|
|
2222 popup = Fframe_property (frame, Qpopup, Qnil);
|
|
2223 if (!NILP (popup))
|
|
2224 {
|
|
2225 /* If popup isn't nil then it means the frame has that property
|
|
2226 and the value is supposed to be the parent frame. The FRAMEP
|
|
2227 check is to safeguard against it not being a frame. */
|
|
2228 if (!FRAMEP (popup) || !FRAME_LIVE_P (XFRAME (popup)))
|
|
2229 popup = Qt;
|
|
2230 else
|
|
2231 popup = Qnil;
|
|
2232 }
|
|
2233
|
|
2234 #ifdef EXTERNAL_WIDGET
|
|
2235 {
|
|
2236 Display *dpy = XtDisplay (w);
|
|
2237 expect_x_error (dpy);
|
|
2238 /* for obscure reasons having (I think) to do with the internal
|
|
2239 window-to-widget hierarchy maintained by Xt, we have to call
|
|
2240 XtUnrealizeWidget() here. Xt can really suck. */
|
|
2241 if (f->being_deleted)
|
|
2242 XtUnrealizeWidget (w);
|
|
2243 if (NILP (popup))
|
|
2244 XtDestroyWidget (w);
|
|
2245 x_error_occurred_p (dpy);
|
|
2246 }
|
|
2247 #else
|
|
2248 if (NILP (popup))
|
|
2249 XtDestroyWidget (w);
|
|
2250 #endif /* EXTERNAL_WIDGET */
|
|
2251
|
|
2252 if (FRAME_X_GEOM_FREE_ME_PLEASE (f))
|
|
2253 xfree (FRAME_X_GEOM_FREE_ME_PLEASE (f));
|
|
2254 xfree (f->frame_data);
|
|
2255 f->frame_data = 0;
|
|
2256 }
|
|
2257
|
|
2258
|
|
2259 /************************************************************************/
|
|
2260 /* initialization */
|
|
2261 /************************************************************************/
|
|
2262
|
|
2263 void
|
|
2264 syms_of_frame_x (void)
|
|
2265 {
|
|
2266 defsymbol (&Qwindow_id, "window-id");
|
|
2267 defsymbol (&Qpopup, "popup");
|
|
2268 defsymbol (&Qx_resource_name, "x-resource-name");
|
|
2269
|
|
2270 defsubr (&Sx_window_id);
|
|
2271 }
|
|
2272
|
|
2273 void
|
|
2274 console_type_create_frame_x (void)
|
|
2275 {
|
|
2276 /* frame methods */
|
|
2277 CONSOLE_HAS_METHOD (x, init_frame_1);
|
|
2278 CONSOLE_HAS_METHOD (x, init_frame_2);
|
|
2279 CONSOLE_HAS_METHOD (x, init_frame_3);
|
|
2280 CONSOLE_HAS_METHOD (x, mark_frame);
|
|
2281 CONSOLE_HAS_METHOD (x, focus_on_frame);
|
|
2282 CONSOLE_HAS_METHOD (x, delete_frame);
|
|
2283 CONSOLE_HAS_METHOD (x, get_mouse_position);
|
|
2284 CONSOLE_HAS_METHOD (x, set_mouse_position);
|
|
2285 CONSOLE_HAS_METHOD (x, raise_frame);
|
|
2286 CONSOLE_HAS_METHOD (x, lower_frame);
|
|
2287 CONSOLE_HAS_METHOD (x, make_frame_visible);
|
|
2288 CONSOLE_HAS_METHOD (x, make_frame_invisible);
|
|
2289 CONSOLE_HAS_METHOD (x, iconify_frame);
|
|
2290 CONSOLE_HAS_METHOD (x, set_frame_size);
|
|
2291 CONSOLE_HAS_METHOD (x, set_frame_position);
|
|
2292 CONSOLE_HAS_METHOD (x, frame_property);
|
|
2293 CONSOLE_HAS_METHOD (x, internal_frame_property_p);
|
|
2294 CONSOLE_HAS_METHOD (x, frame_properties);
|
|
2295 CONSOLE_HAS_METHOD (x, set_frame_properties);
|
2
|
2296 CONSOLE_HAS_METHOD (x, set_title_from_bufbyte);
|
|
2297 CONSOLE_HAS_METHOD (x, set_icon_name_from_bufbyte);
|
0
|
2298 CONSOLE_HAS_METHOD (x, frame_visible_p);
|
|
2299 CONSOLE_HAS_METHOD (x, frame_totally_visible_p);
|
|
2300 CONSOLE_HAS_METHOD (x, frame_iconified_p);
|
|
2301 CONSOLE_HAS_METHOD (x, set_frame_pointer);
|
|
2302 CONSOLE_HAS_METHOD (x, set_frame_icon);
|
|
2303 CONSOLE_HAS_METHOD (x, get_frame_parent);
|
|
2304 }
|
|
2305
|
|
2306 void
|
|
2307 vars_of_frame_x (void)
|
|
2308 {
|
|
2309 #ifdef EXTERNAL_WIDGET
|
|
2310 Fprovide (intern ("external-widget"));
|
|
2311 #endif
|
|
2312
|
|
2313 /* this call uses only safe functions from emacs.c */
|
|
2314 init_x_prop_symbols ();
|
|
2315
|
|
2316 DEFVAR_LISP ("default-x-frame-plist", &Vdefault_x_frame_plist /*
|
|
2317 Plist of default frame-creation properties for X frames.
|
|
2318 These override what is specified in the resource database and in
|
|
2319 `default-frame-plist', but are overridden by the arguments to the
|
|
2320 particular call to `make-frame'.
|
|
2321
|
|
2322 Note: In many cases, properties of a frame are available as specifiers
|
|
2323 instead of through the frame-properties mechanism.
|
|
2324
|
|
2325 Here is a list of recognized frame properties, other than those
|
|
2326 documented in `set-frame-properties' (they can be queried and
|
|
2327 set at any time, except as otherwise noted):
|
|
2328
|
|
2329 window-id The X window ID corresponding to the
|
|
2330 frame. May be set only at startup, and
|
|
2331 only if external widget support was
|
|
2332 compiled in; doing so causes the frame
|
|
2333 to be created as an \"external widget\"
|
|
2334 in another program that uses an existing
|
|
2335 window in the program rather than creating
|
|
2336 a new one.
|
|
2337 initially-unmapped If non-nil, the frame will not be visible
|
|
2338 when it is created. In this case, you
|
|
2339 need to call `make-frame-visible' to make
|
|
2340 the frame appear.
|
|
2341 popup If non-nil, it should be a frame, and this
|
|
2342 frame will be created as a \"popup\" frame
|
|
2343 whose parent is the given frame. This
|
|
2344 will make the window manager treat the
|
|
2345 frame as a dialog box, which may entail
|
|
2346 doing different things (e.g. not asking
|
|
2347 for positioning, and not iconifying
|
|
2348 separate from its parent).
|
|
2349 inter-line-space Not currently implemented.
|
|
2350 toolbar-shadow-thickness Thickness of toolbar shadows.
|
|
2351 background-toolbar-color Color of toolbar background.
|
|
2352 bottom-toolbar-shadow-color Color of bottom shadows on toolbars.
|
|
2353 (*Not* specific to the bottom-toolbar.)
|
|
2354 top-toolbar-shadow-color Color of top shadows on toolbars.
|
|
2355 (*Not* specifier to the top-toolbar.)
|
|
2356 internal-border-width Width of internal border around text area.
|
|
2357 border-width Width of external border around text area.
|
|
2358 top Y position (in pixels) of the upper-left
|
|
2359 outermost corner of the frame (i.e. the
|
|
2360 upper-left of the window-manager
|
|
2361 decorations).
|
|
2362 left X position (in pixels) of the upper-left
|
|
2363 outermost corner of the frame (i.e. the
|
|
2364 upper-left of the window-manager
|
|
2365 decorations).
|
|
2366 border-color Color of external border around text area.
|
|
2367 cursor-color Color of text cursor.
|
|
2368
|
|
2369 See also `default-frame-plist', which specifies properties which apply
|
|
2370 to all frames, not just X frames.
|
|
2371 */ );
|
|
2372 Vdefault_x_frame_plist = Qnil;
|
|
2373
|
|
2374 x_console_methods->device_specific_frame_props = &Vdefault_x_frame_plist;
|
|
2375 }
|