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
|
|
716 if (string_length (XSTRING (prop)) == 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. */
|
|
766 if (!strcmp ((char *) string_data (XSTRING (str)), "width"))
|
|
767 {
|
|
768 CHECK_INT (val);
|
|
769 width = XINT (val);
|
|
770 width_specified_p = True;
|
|
771 continue;
|
|
772 }
|
|
773 if (!strcmp ((char *) string_data (XSTRING (str)), "height"))
|
|
774 {
|
|
775 CHECK_INT (val);
|
|
776 height = XINT (val);
|
|
777 height_specified_p = True;
|
|
778 continue;
|
|
779 }
|
|
780 /* Further kludge the x/y. */
|
|
781 if (!strcmp ((char *) string_data (XSTRING (str)), "x"))
|
|
782 {
|
|
783 CHECK_INT (val);
|
|
784 x = XINT (val);
|
|
785 x_position_specified_p = True;
|
|
786 continue;
|
|
787 }
|
|
788 if (!strcmp ((char *) string_data (XSTRING (str)), "y"))
|
|
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? */
|
|
797 if (!strcmp ((char *) string_data (XSTRING (str)),
|
|
798 "internalBorderWidth"))
|
|
799 {
|
|
800 internal_border_width_specified = True;
|
|
801 }
|
|
802
|
|
803 if (int_p)
|
|
804 {
|
|
805 CHECK_INT (val);
|
|
806 XtVaSetValues (w, (char *) string_data (XSTRING (str)),
|
|
807 XINT (val), 0);
|
|
808 }
|
|
809 else if (EQ (val, Qt))
|
|
810 XtVaSetValues (w,
|
|
811 /* XtN... */
|
|
812 (char *) string_data (XSTRING (str)),
|
|
813 True,
|
|
814 0);
|
|
815 else if (EQ (val, Qnil))
|
|
816 XtVaSetValues (w,
|
|
817 /* XtN... */
|
|
818 (char *) string_data (XSTRING (str)),
|
|
819 False,
|
|
820 0);
|
|
821 else
|
|
822 {
|
|
823 CHECK_STRING (val);
|
|
824 XtVaSetValues (w, XtVaTypedArg,
|
|
825 /* XtN... */
|
|
826 (char *) string_data (XSTRING (str)),
|
|
827 XtRString,
|
|
828 string_data (XSTRING (val)),
|
|
829 string_length (XSTRING (val)) + 1,
|
|
830 0);
|
|
831 }
|
|
832
|
|
833 #ifdef HAVE_SCROLLBARS
|
|
834 if (!strcmp ((char *) string_data (XSTRING (str)), "scrollBarWidth")
|
|
835 || !strcmp ((char *) string_data (XSTRING (str)),
|
|
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 {
|
2
|
944 char *filePath, *buf, *data;
|
0
|
945 int ii;
|
|
946 Lisp_Object path = Qnil;
|
|
947 Lisp_Object frame = Qnil;
|
|
948 struct gcpro gcpro1, gcpro2;
|
|
949
|
|
950 DtDndTransferCallbackStruct *transferInfo =
|
|
951 (DtDndTransferCallbackStruct *) callData;
|
|
952
|
|
953 if (transferInfo == NULL)
|
|
954 return;
|
|
955
|
|
956 GCPRO2 (path, frame);
|
|
957
|
|
958 frame = make_frame ((struct frame *) clientData);
|
|
959 if (transferInfo->dropData->protocol == DtDND_FILENAME_TRANSFER)
|
|
960 {
|
|
961 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
|
|
962 {
|
|
963 filePath = transferInfo->dropData->data.files[ii];
|
|
964 path = make_string (filePath, strlen (filePath));
|
|
965 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
966 }
|
|
967 }
|
2
|
968 else if (transferInfo->dropData->protocol == DtDND_BUFFER_TRANSFER)
|
|
969 {
|
|
970 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
|
|
971 {
|
|
972 filePath = transferInfo->dropData->data.buffers[ii].name;
|
|
973 path = (filePath != NULL) ?
|
|
974 make_string (filePath, strlen (filePath)) : Qnil;
|
|
975 buf = transferInfo->dropData->data.buffers[ii].bp;
|
|
976 data = make_string (buf, transferInfo->dropData->data.buffers[ii].size);
|
|
977 va_run_hook_with_args(Qdrag_and_drop_functions, 3, frame, path, data);
|
|
978 }
|
|
979 }
|
|
980
|
0
|
981 UNGCPRO;
|
|
982 return;
|
|
983 }
|
|
984 #endif
|
|
985
|
2
|
986 #ifdef HAVE_OFFIX_DND
|
|
987 #include <OffiX/DragAndDrop.h>
|
|
988
|
|
989 void
|
|
990 x_offix_drop_event_handler (Widget widget, XtPointer data, XEvent *event,
|
|
991 Boolean *b)
|
|
992 {
|
|
993 int i, len, Type;
|
|
994 unsigned char *Data;
|
|
995 unsigned long Size;
|
|
996
|
|
997 Lisp_Object path = Qnil;
|
|
998 Lisp_Object frame = Qnil;
|
|
999
|
|
1000 struct gcpro gcpro1, gcpro2;
|
|
1001
|
|
1002 Type = DndDataType (event);
|
|
1003 if ((Type != DndFile) && (Type != DndFiles) && (Type != DndExe))
|
|
1004 return;
|
|
1005 DndGetData (&Data, &Size);
|
|
1006
|
|
1007 GCPRO2 (path, frame);
|
|
1008
|
|
1009 frame = make_frame ((struct frame *) data);
|
|
1010
|
|
1011 if (Type == DndFiles)
|
|
1012 {
|
|
1013 while (*Data)
|
|
1014 {
|
|
1015 len = strlen ((char*) Data);
|
|
1016 path = make_string ((char*) Data, len);
|
|
1017 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
1018 Data += len+1;
|
|
1019 }
|
|
1020 }
|
|
1021 else
|
|
1022 {
|
|
1023 path = make_string ((char*) Data, strlen (Data));
|
|
1024 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
1025 }
|
|
1026
|
|
1027 UNGCPRO;
|
|
1028 return;
|
|
1029 }
|
|
1030 #endif /* HAVE_OFFIX_DND */
|
|
1031
|
0
|
1032
|
|
1033 /************************************************************************/
|
|
1034 /* widget creation */
|
|
1035 /************************************************************************/
|
|
1036
|
|
1037 /* The widget hierarchy is
|
|
1038
|
|
1039 argv[0] shell container FRAME-NAME
|
|
1040 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1041
|
|
1042 We accept geometry specs in this order:
|
|
1043
|
|
1044 *FRAME-NAME.geometry
|
|
1045 *EmacsFrame.geometry
|
|
1046 Emacs.geometry
|
|
1047
|
|
1048 Other possibilities for widget hierarchies might be
|
|
1049
|
|
1050 argv[0] frame container FRAME-NAME
|
|
1051 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1052 or
|
|
1053 argv[0] FRAME-NAME container FRAME-NAME
|
|
1054 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1055 or
|
|
1056 argv[0] FRAME-NAME container emacsTextPane
|
|
1057 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1058
|
|
1059 #ifdef EXTERNAL_WIDGET
|
|
1060 The ExternalShell widget is simply a replacement for the Shell widget
|
|
1061 which is able to deal with using an externally-supplied window instead
|
|
1062 of always creating its own.
|
|
1063 #endif
|
|
1064
|
|
1065 */
|
|
1066
|
|
1067 #ifdef EXTERNAL_WIDGET
|
|
1068
|
|
1069 static int
|
|
1070 is_valid_window (Window w, struct device *d)
|
|
1071 {
|
|
1072 XWindowAttributes xwa;
|
|
1073 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1074
|
|
1075 expect_x_error (dpy);
|
|
1076 XGetWindowAttributes (dpy, w, &xwa);
|
|
1077 return !x_error_occurred_p (dpy);
|
|
1078 }
|
|
1079
|
|
1080 #endif /* EXTERNAL_WIDGET */
|
|
1081
|
|
1082 /* This sends a synthetic mouse-motion event to the frame, if the mouse
|
|
1083 is over the frame. This ensures that the cursor gets set properly
|
|
1084 before the user moves the mouse for the first time. */
|
|
1085
|
|
1086 static void
|
|
1087 x_send_synthetic_mouse_event (struct frame *f)
|
|
1088 {
|
|
1089 /* #### write this function. */
|
|
1090 }
|
|
1091
|
|
1092 static int
|
|
1093 first_x_frame_p (struct frame *f)
|
|
1094 {
|
|
1095 Lisp_Object rest = DEVICE_FRAME_LIST (XDEVICE (f->device));
|
|
1096 while (!NILP (rest) &&
|
|
1097 (f == XFRAME (XCAR (rest)) ||
|
|
1098 !FRAME_X_P (XFRAME (XCAR (rest)))))
|
|
1099 rest = XCDR (rest);
|
|
1100 return (NILP (rest));
|
|
1101 }
|
|
1102
|
|
1103 /* Figure out what size the EmacsFrame widget should initially be,
|
|
1104 and set it. Should be called after the default font has been
|
|
1105 determined but before the widget has been realized. */
|
|
1106
|
|
1107 static void
|
|
1108 x_initialize_frame_size (struct frame *f)
|
|
1109 {
|
|
1110 /* Geometry of the AppShell */
|
|
1111 int app_flags = 0;
|
|
1112 int app_x = 0;
|
|
1113 int app_y = 0;
|
|
1114 unsigned int app_w = 0;
|
|
1115 unsigned int app_h = 0;
|
|
1116
|
|
1117 /* Geometry of the EmacsFrame */
|
|
1118 int frame_flags = 0;
|
|
1119 int frame_x = 0;
|
|
1120 int frame_y = 0;
|
|
1121 unsigned int frame_w = 0;
|
|
1122 unsigned int frame_h = 0;
|
|
1123
|
|
1124 /* Hairily merged geometry */
|
|
1125 int x = 0;
|
|
1126 int y = 0;
|
|
1127 unsigned int w = 80;
|
|
1128 unsigned int h = 40;
|
|
1129 int flags = 0;
|
|
1130
|
|
1131 char *geom = 0, *ew_geom = 0;
|
|
1132 Boolean iconic_p = False, ew_iconic_p = False;
|
|
1133
|
|
1134 Widget wmshell = FRAME_X_SHELL_WIDGET (f);
|
|
1135 /* #### This may not be an ApplicationShell any more, with the 'popup
|
|
1136 frame property. */
|
|
1137 Widget app_shell = XtParent (wmshell);
|
|
1138 Widget ew = FRAME_X_TEXT_WIDGET (f);
|
|
1139
|
|
1140 /* set the position of the frame's root window now. When the
|
|
1141 frame was created, the position was initialized to (0,0). */
|
|
1142 {
|
|
1143 struct window *win = XWINDOW (f->root_window);
|
|
1144
|
|
1145 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f);
|
|
1146 WINDOW_TOP (win) = FRAME_TOP_BORDER_END (f);
|
|
1147
|
|
1148 if (!NILP (f->minibuffer_window))
|
|
1149 {
|
|
1150 win = XWINDOW (f->minibuffer_window);
|
|
1151 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f);
|
|
1152 }
|
|
1153 }
|
|
1154
|
|
1155 #ifdef EXTERNAL_WIDGET
|
|
1156 /* If we're an external widget, then the size of the frame is predetermined
|
|
1157 (by the client) and is not our decision to make. */
|
|
1158 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1159 return;
|
|
1160 #endif
|
|
1161
|
|
1162 #if 0
|
|
1163 /* #### this junk has not been tested; therefore it's
|
|
1164 probably wrong. Doesn't really matter at this point because
|
|
1165 currently all frames are either top-level or external widgets. */
|
|
1166
|
|
1167 /* If we're not our own top-level window, then we shouldn't go messing around
|
|
1168 with top-level shells or "Emacs.geometry" or any such stuff. Therefore,
|
|
1169 we do as follows to determine the size of the frame:
|
|
1170
|
|
1171 1) If a value for the frame's "geometry" resource was specified, then
|
|
1172 use it. (This specifies a size in characters.)
|
|
1173 2) Else, if the "width" and "height" resources were specified, then
|
|
1174 leave them alone. (This is a value in pixels. Sorry, we can't break
|
|
1175 Xt conventions here.)
|
|
1176 3) Else, assume a size of 64x12. (This is somewhat arbitrary, but
|
|
1177 it's unlikely that a size of 80x40 is desirable because we're probably
|
|
1178 inside of a dialog box.)
|
|
1179
|
|
1180 Set the widget's x, y, height, and width as determined. Don't set the
|
|
1181 top-level container widget, because we don't necessarily know what it
|
|
1182 is. (Assume it is smart and pays attention to our values.)
|
|
1183 */
|
|
1184
|
|
1185 if (!FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1186 {
|
|
1187 XtVaGetValues (ew, XtNgeometry, &ew_geom, 0);
|
|
1188 if (ew_geom)
|
|
1189 frame_flags = XParseGeometry (ew_geom, &frame_x, &frame_y,
|
|
1190 &frame_w, &frame_h);
|
|
1191 if (! (frame_flags & (WidthValue | HeightValue)))
|
|
1192 {
|
|
1193 XtVaGetValues (ew, XtNwidth, &frame_w,
|
|
1194 XtNheight, &frame_h, 0);
|
|
1195 if (!frame_w && !frame_h)
|
|
1196 {
|
|
1197 frame_w = 64;
|
|
1198 frame_h = 12;
|
|
1199 frame_flags |= WidthValue | HeightValue;
|
|
1200 }
|
|
1201 }
|
|
1202 if (frame_flags & (WidthValue | HeightValue))
|
|
1203 EmacsFrameSetCharSize (ew, frame_w, frame_h);
|
|
1204 if (frame_flags & (XValue | YValue))
|
|
1205 {
|
|
1206 XtVaGetValues (ew, XtNwidth, &frame_w,
|
|
1207 XtNheight, &frame_h, 0);
|
|
1208 if (frame_flags & XNegative)
|
|
1209 frame_x += frame_w;
|
|
1210 if (frame_flags & YNegative)
|
|
1211 frame_y += frame_h;
|
|
1212 XtVaSetValues (ew, XtNx, frame_x, XtNy, frame_y, 0);
|
|
1213 }
|
|
1214 return;
|
|
1215 }
|
|
1216 #endif
|
|
1217
|
|
1218 /* OK, we're a top-level shell. */
|
|
1219
|
|
1220 if (!XtIsWMShell (wmshell))
|
|
1221 abort ();
|
|
1222
|
|
1223 /* If the EmacsFrame doesn't have a geometry but the shell does,
|
|
1224 treat that as the geometry of the frame. (Is this bogus?
|
|
1225 I'm not sure.) */
|
|
1226
|
|
1227 XtVaGetValues (ew, XtNgeometry, &ew_geom, 0);
|
|
1228 if (!ew_geom)
|
|
1229 {
|
|
1230 XtVaGetValues (wmshell, XtNgeometry, &geom, 0);
|
|
1231 if (geom)
|
|
1232 {
|
|
1233 ew_geom = geom;
|
|
1234 XtVaSetValues (ew, XtNgeometry, ew_geom, 0);
|
|
1235 }
|
|
1236 }
|
|
1237
|
|
1238 /* If the Shell is iconic, then the EmacsFrame is iconic. (Is
|
|
1239 this bogus? I'm not sure.) */
|
|
1240 XtVaGetValues (ew, XtNiconic, &ew_iconic_p, 0);
|
|
1241 if (!ew_iconic_p)
|
|
1242 {
|
|
1243 XtVaGetValues (wmshell, XtNiconic, &iconic_p, 0);
|
|
1244 if (iconic_p)
|
|
1245 {
|
|
1246 ew_iconic_p = iconic_p;
|
|
1247 XtVaSetValues (ew, XtNiconic, iconic_p, 0);
|
|
1248 }
|
|
1249 }
|
|
1250
|
|
1251 XtVaGetValues (app_shell, XtNgeometry, &geom, 0);
|
|
1252 if (geom)
|
|
1253 app_flags = XParseGeometry (geom, &app_x, &app_y, &app_w, &app_h);
|
|
1254
|
|
1255 if (ew_geom)
|
|
1256 frame_flags = XParseGeometry (ew_geom, &frame_x, &frame_y,
|
|
1257 &frame_w, &frame_h);
|
|
1258
|
|
1259 if (first_x_frame_p (f))
|
|
1260 {
|
|
1261 /* If this is the first frame created:
|
|
1262 ====================================
|
|
1263
|
|
1264 - Use the ApplicationShell's size/position, if specified.
|
|
1265 (This is "Emacs.geometry", or the "-geometry" command line arg.)
|
|
1266 - Else use the EmacsFrame's size/position.
|
|
1267 (This is "*FRAME-NAME.geometry")
|
|
1268
|
|
1269 - If the AppShell is iconic, the frame should be iconic.
|
|
1270
|
|
1271 AppShell comes first so that -geometry always applies to the first
|
|
1272 frame created, even if there is an "every frame" entry in the
|
|
1273 resource database.
|
|
1274 */
|
|
1275 if (app_flags & (XValue | YValue))
|
|
1276 {
|
|
1277 x = app_x; y = app_y;
|
|
1278 flags |= (app_flags & (XValue | YValue | XNegative | YNegative));
|
|
1279 }
|
|
1280 else if (frame_flags & (XValue | YValue))
|
|
1281 {
|
|
1282 x = frame_x; y = frame_y;
|
|
1283 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative));
|
|
1284 }
|
|
1285
|
|
1286 if (app_flags & (WidthValue | HeightValue))
|
|
1287 {
|
|
1288 w = app_w; h = app_h;
|
|
1289 flags |= (app_flags & (WidthValue | HeightValue));
|
|
1290 }
|
|
1291 else if (frame_flags & (WidthValue | HeightValue))
|
|
1292 {
|
|
1293 w = frame_w; h = frame_h;
|
|
1294 flags |= (frame_flags & (WidthValue | HeightValue));
|
|
1295 }
|
|
1296
|
|
1297 /* If the AppShell is iconic, then the EmacsFrame is iconic. */
|
|
1298 if (!ew_iconic_p)
|
|
1299 {
|
|
1300 XtVaGetValues (app_shell, XtNiconic, &iconic_p, 0);
|
|
1301 if (iconic_p)
|
|
1302 {
|
|
1303 ew_iconic_p = iconic_p;
|
|
1304 XtVaSetValues (ew, XtNiconic, iconic_p, 0);
|
|
1305 }
|
|
1306 }
|
|
1307 }
|
|
1308 else
|
|
1309 {
|
|
1310 /* If this is not the first frame created:
|
|
1311 ========================================
|
|
1312
|
|
1313 - use the EmacsFrame's size/position if specified
|
|
1314 - Otherwise, use the ApplicationShell's size, but not position.
|
|
1315
|
|
1316 So that means that one can specify the position of the first frame
|
|
1317 with "Emacs.geometry" or `-geometry'; but can only specify the
|
|
1318 position of subsequent frames with "*FRAME-NAME.geometry".
|
|
1319
|
|
1320 AppShell comes second so that -geometry does not apply to subsequent
|
|
1321 frames when there is an "every frame" entry in the resource db,
|
|
1322 but does apply to the first frame.
|
|
1323 */
|
|
1324 if (frame_flags & (XValue | YValue))
|
|
1325 {
|
|
1326 x = frame_x; y = frame_y;
|
|
1327 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative));
|
|
1328 }
|
|
1329
|
|
1330 if (frame_flags & (WidthValue | HeightValue))
|
|
1331 {
|
|
1332 w = frame_w; h = frame_h;
|
|
1333 flags |= (frame_flags & (WidthValue | HeightValue));
|
|
1334 }
|
|
1335 else if (app_flags & (WidthValue | HeightValue))
|
|
1336 {
|
|
1337 w = app_w;
|
|
1338 h = app_h;
|
|
1339 flags |= (app_flags & (WidthValue | HeightValue));
|
|
1340 }
|
|
1341 }
|
|
1342
|
|
1343 x_set_initial_frame_size (f, flags, x, y, w, h);
|
|
1344 }
|
|
1345
|
|
1346 static void
|
|
1347 x_get_layout_sizes (struct frame *f, Dimension *topbreadth)
|
|
1348 {
|
|
1349 int i;
|
|
1350
|
|
1351 /* compute height of all top-area widgets */
|
|
1352 for (i=0, *topbreadth = 0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
1353 {
|
|
1354 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
1355 if (wid && XtIsManaged (wid))
|
|
1356 *topbreadth += wid->core.height + 2*wid->core.border_width;
|
|
1357 }
|
|
1358 }
|
|
1359
|
|
1360 static void
|
|
1361 x_layout_widgets (Widget w, XtPointer client_data, XtPointer call_data)
|
|
1362 {
|
|
1363 struct frame *f = (struct frame *) client_data;
|
|
1364 EmacsManagerResizeStruct *emst = (EmacsManagerResizeStruct *) call_data;
|
|
1365 Dimension width = emst->width;
|
|
1366 Dimension height = emst->height;
|
|
1367 Widget text = FRAME_X_TEXT_WIDGET (f);
|
|
1368 Dimension textbord = text->core.border_width;
|
|
1369 Dimension topbreadth;
|
|
1370 Position text_x = 0, text_y = 0;
|
|
1371 int i;
|
|
1372
|
|
1373 x_get_layout_sizes (f, &topbreadth);
|
|
1374
|
|
1375 /* first the menubar and psheets ... */
|
|
1376 for (i=0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
1377 {
|
|
1378 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
1379 if (wid && XtIsManaged (wid))
|
|
1380 {
|
|
1381 Dimension bord = wid->core.border_width;
|
|
1382 XtConfigureWidget (wid, 0, text_y,
|
|
1383 width - 2*bord, wid->core.height,
|
|
1384 bord);
|
|
1385 text_y += wid->core.height + 2*bord;
|
|
1386 }
|
|
1387 }
|
|
1388
|
|
1389 #ifdef HAVE_SCROLLBARS
|
|
1390 {
|
|
1391 /* The scrollbar positioning is completely handled by redisplay. We
|
|
1392 just need to know which sides they are supposed to go on. */
|
|
1393 unsigned char scrollbar_placement;
|
|
1394 XtVaGetValues (text, XtNscrollBarPlacement, &scrollbar_placement, 0);
|
|
1395 f->scrollbar_on_left = (scrollbar_placement == XtTOP_LEFT ||
|
|
1396 scrollbar_placement == XtBOTTOM_LEFT);
|
|
1397 f->scrollbar_on_top = (scrollbar_placement == XtTOP_LEFT ||
|
|
1398 scrollbar_placement == XtTOP_RIGHT);
|
|
1399 f->scrollbar_y_offset = topbreadth + textbord;
|
|
1400 }
|
|
1401 #endif
|
|
1402
|
|
1403 /* finally the text area */
|
|
1404 XtConfigureWidget (text, text_x, text_y,
|
|
1405 width - 2*textbord,
|
|
1406 height - text_y - 2*textbord,
|
|
1407 textbord);
|
|
1408 }
|
|
1409
|
|
1410 static void
|
|
1411 x_do_query_geometry (Widget w, XtPointer client_data, XtPointer call_data)
|
|
1412 {
|
|
1413 struct frame *f = (struct frame *) client_data;
|
|
1414 EmacsManagerQueryGeometryStruct *emst =
|
|
1415 (EmacsManagerQueryGeometryStruct *) call_data;
|
|
1416 Widget text = FRAME_X_TEXT_WIDGET (f);
|
|
1417 Dimension textbord = text->core.border_width;
|
|
1418 Dimension topbreadth;
|
|
1419 XtWidgetGeometry req, repl;
|
|
1420 int mask = emst->request_mode & (CWWidth | CWHeight);
|
|
1421
|
|
1422 x_get_layout_sizes (f, &topbreadth);
|
|
1423
|
|
1424 /* strip away menubar from suggested size, and ask the text widget
|
|
1425 what size it wants to be */
|
|
1426 req.request_mode = mask;
|
|
1427 if (mask & CWWidth)
|
|
1428 req.width = emst->proposed_width - 2*textbord;
|
|
1429 if (mask & CWHeight)
|
|
1430 req.height = emst->proposed_height - topbreadth - 2*textbord;
|
|
1431 XtQueryGeometry (text, &req, &repl);
|
|
1432
|
|
1433 /* Now add the menubar back again */
|
|
1434 emst->proposed_width = repl.width + 2*textbord;
|
|
1435 emst->proposed_height = repl.height + topbreadth + 2*textbord;
|
|
1436 }
|
|
1437
|
|
1438 /* Creates the widgets for a frame.
|
|
1439 lisp_window_id is a Lisp description of an X window or Xt
|
|
1440 widget to parse.
|
|
1441
|
|
1442 This function does not create or map the windows. (That is
|
|
1443 done by x_popup_frame().)
|
|
1444 */
|
|
1445 static void
|
|
1446 x_create_widgets (struct frame *f, Lisp_Object lisp_window_id,
|
|
1447 Lisp_Object parent)
|
|
1448 {
|
|
1449 struct device *d = XDEVICE (f->device);
|
|
1450 #ifdef EXTERNAL_WIDGET
|
|
1451 Window window_id = 0;
|
|
1452 #endif
|
|
1453 CONST char *name;
|
|
1454 Arg av [25];
|
|
1455 int ac = 0;
|
|
1456 Widget text, container, shell;
|
|
1457 Widget parentwid = 0;
|
|
1458 #ifdef HAVE_MENUBARS
|
|
1459 int menubar_visible;
|
|
1460 Widget menubar;
|
|
1461 #endif
|
|
1462
|
|
1463 if (STRINGP (f->name))
|
|
1464 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, name);
|
|
1465 else
|
|
1466 name = "emacs";
|
|
1467
|
|
1468 /* The widget hierarchy is
|
|
1469
|
|
1470 argv[0] shell pane FRAME-NAME
|
|
1471 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1472
|
|
1473 (the type of the shell is ExternalShell if this frame is running
|
|
1474 in another client's window)
|
|
1475
|
|
1476 However the EmacsShell widget has WM_CLASS of FRAME-NAME/Emacs.
|
|
1477 Normally such shells have name/class shellname/appclass, which in this
|
|
1478 case would be "shell/Emacs" instead of "frame-name/Emacs". We could
|
|
1479 also get around this by naming the shell "frame-name", but that would
|
|
1480 be confusing because the text area (the EmacsFrame widget inferior of
|
|
1481 the shell) is also called that. So we just set the WM_CLASS property.
|
|
1482 */
|
|
1483
|
|
1484 #ifndef EXTERNAL_WIDGET
|
|
1485 if (!NILP (lisp_window_id))
|
|
1486 error ("support for external widgets was not enabled at compile-time");
|
|
1487 #else
|
|
1488 if (!NILP (lisp_window_id))
|
|
1489 {
|
|
1490 char *string;
|
|
1491
|
|
1492 CHECK_STRING (lisp_window_id);
|
|
1493 string = (char *) (string_data (XSTRING (lisp_window_id)));
|
|
1494 if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))
|
|
1495 sscanf (string+2, "%lxu", &window_id);
|
|
1496 #if 0
|
|
1497 else if (string[0] == 'w')
|
|
1498 {
|
|
1499 sscanf (string+1, "%x", &parent_widget);
|
|
1500 if (parent_widget)
|
|
1501 window_id = XtWindow (parent_widget);
|
|
1502 }
|
|
1503 #endif
|
|
1504 else
|
|
1505 sscanf (string, "%lu", &window_id);
|
|
1506 if (!is_valid_window (window_id, d))
|
|
1507 error ("Invalid window %lu", (unsigned long) window_id);
|
|
1508 FRAME_X_EXTERNAL_WINDOW_P (f) = 1;
|
|
1509 } else
|
|
1510 #endif /* EXTERNAL_WIDGET */
|
|
1511 FRAME_X_TOP_LEVEL_FRAME_P (f) = 1;
|
|
1512
|
|
1513 ac = 0;
|
|
1514 XtSetArg (av[ac], XtNallowShellResize, True); ac++;
|
|
1515 #ifdef LWLIB_USES_MOTIF
|
|
1516 /* Motif sucks beans. Without this in here, it will delete the window
|
|
1517 out from under us when it receives a WM_DESTROY_WINDOW message
|
|
1518 from the WM. */
|
|
1519 XtSetArg (av[ac], XmNdeleteResponse, XmDO_NOTHING); ac++;
|
|
1520 #endif
|
|
1521
|
|
1522 #ifdef EXTERNAL_WIDGET
|
|
1523 if (window_id)
|
|
1524 {
|
|
1525 XtSetArg (av[ac], XtNwindow, window_id); ac++;
|
|
1526 }
|
|
1527 else
|
|
1528 #endif
|
|
1529 {
|
|
1530 XtSetArg (av[ac], XtNinput, True); ac++;
|
2
|
1531 XtSetArg (av[ac], (String) XtNminWidthCells, 10); ac++;
|
|
1532 XtSetArg (av[ac], (String) XtNminHeightCells, 1); ac++;
|
0
|
1533 }
|
|
1534
|
|
1535 if (!NILP (parent))
|
|
1536 {
|
|
1537 parentwid = FRAME_X_SHELL_WIDGET (XFRAME (parent));
|
|
1538 XtSetArg (av[ac], XtNtransientFor, parentwid); ac++;
|
|
1539 }
|
|
1540
|
|
1541 shell = XtCreatePopupShell ("shell",
|
|
1542 (
|
|
1543 #ifdef EXTERNAL_WIDGET
|
|
1544 window_id ? externalShellWidgetClass :
|
|
1545 #endif
|
|
1546 parentwid ? transientEmacsShellWidgetClass :
|
|
1547 topLevelEmacsShellWidgetClass
|
|
1548 ),
|
|
1549 parentwid ? parentwid :
|
|
1550 DEVICE_XT_APP_SHELL (d),
|
|
1551 av, ac);
|
|
1552 FRAME_X_SHELL_WIDGET (f) = shell;
|
|
1553 maybe_set_frame_title_format (shell);
|
|
1554
|
|
1555 /* Create the manager widget */
|
|
1556 container = XtVaCreateWidget ("container",
|
|
1557 emacsManagerWidgetClass,
|
|
1558 shell, 0);
|
|
1559 FRAME_X_CONTAINER_WIDGET (f) = container;
|
|
1560 XtAddCallback (container, XtNresizeCallback, x_layout_widgets,
|
|
1561 (XtPointer) f);
|
|
1562 XtAddCallback (container, XtNqueryGeometryCallback, x_do_query_geometry,
|
|
1563 (XtPointer) f);
|
|
1564
|
|
1565 /* Create the text area */
|
|
1566 ac = 0;
|
|
1567 XtSetArg (av[ac], XtNborderWidth, 0); ac++; /* should this be settable? */
|
2
|
1568 XtSetArg (av[ac], (String) XtNemacsFrame, f); ac++;
|
0
|
1569 text = XtCreateWidget (name,
|
|
1570 emacsFrameClass,
|
|
1571 container, av, ac);
|
|
1572 FRAME_X_TEXT_WIDGET (f) = text;
|
|
1573
|
|
1574 #ifdef HAVE_MENUBARS
|
|
1575 /* Create the initial menubar widget. */
|
|
1576 menubar_visible = x_initialize_frame_menubar (f);
|
|
1577 FRAME_X_TOP_WIDGETS (f)[0] = menubar = FRAME_X_MENUBAR_WIDGET (f);
|
|
1578 FRAME_X_NUM_TOP_WIDGETS (f) = 1;
|
|
1579
|
|
1580 if (menubar_visible)
|
|
1581 XtManageChild (menubar);
|
|
1582 #endif
|
|
1583 XtManageChild (text);
|
|
1584 XtManageChild (container);
|
|
1585 }
|
|
1586
|
|
1587 /* We used to call XtPopup() in x_popup_frame, but that doesn't give
|
|
1588 you control over whether the widget is initially mapped or not
|
|
1589 because XtPopup() makes an unconditional call to XMapRaised().
|
|
1590 Boy, those Xt designers were clever.
|
|
1591
|
|
1592 When we first removed it we only kept the XtRealizeWidget call in
|
|
1593 XtPopup. For everything except HP's that was enough. For HP's,
|
|
1594 though, the failure to call the popup callbacks resulted in XEmacs
|
|
1595 not accepting any input. Bizarre but true. Stupid but true.
|
|
1596
|
|
1597 So, in case there are any other gotches floating out there along
|
|
1598 the same lines I've duplicated the majority of XtPopup here. It
|
|
1599 assumes no grabs and that the widget is not already popped up, both
|
|
1600 valid assumptions for the one place this is called from. */
|
|
1601 static void
|
|
1602 xemacs_XtPopup (Widget widget)
|
|
1603 {
|
|
1604 ShellWidget shell_widget = (ShellWidget) widget;
|
|
1605 XtGrabKind call_data = XtGrabNone;
|
|
1606
|
|
1607 XtCallCallbacks (widget, XtNpopupCallback, (XtPointer)&call_data);
|
|
1608
|
|
1609 shell_widget->shell.popped_up = TRUE;
|
|
1610 shell_widget->shell.grab_kind = XtGrabNone;
|
|
1611 shell_widget->shell.spring_loaded = False;
|
|
1612
|
|
1613 if (shell_widget->shell.create_popup_child_proc != NULL)
|
|
1614 (*(shell_widget->shell.create_popup_child_proc))(widget);
|
|
1615
|
|
1616 /* The XtVaSetValues below are not in XtPopup menu. We just want to
|
|
1617 make absolutely sure... */
|
|
1618 XtVaSetValues (widget, XtNmappedWhenManaged, False, NULL);
|
|
1619 XtRealizeWidget (widget);
|
|
1620 XtVaSetValues (widget, XtNmappedWhenManaged, True, NULL);
|
|
1621 }
|
|
1622
|
|
1623 #ifdef HAVE_CDE
|
|
1624 /* Does this have to be non-automatic? */
|
|
1625 /* hack frame to respond to dnd messages */
|
|
1626 static XtCallbackRec dnd_transfer_cb_rec[2];
|
|
1627 #endif
|
|
1628
|
|
1629 /* create the windows for the specified frame and display them.
|
|
1630 Note that the widgets have already been created, and any
|
|
1631 necessary geometry calculations have already been done. */
|
|
1632 static void
|
|
1633 x_popup_frame (struct frame *f)
|
|
1634 {
|
|
1635 Widget shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
1636 Widget frame_widget = FRAME_X_TEXT_WIDGET (f);
|
|
1637 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
1638
|
|
1639 /* Before mapping the window, make sure that the WMShell's notion of
|
|
1640 whether it should be iconified is synchronized with the EmacsFrame's
|
|
1641 notion.
|
|
1642 */
|
|
1643 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1644 x_wm_set_shell_iconic_p (shell_widget,
|
|
1645 ((EmacsFrame) frame_widget)
|
|
1646 ->emacs_frame.iconic);
|
|
1647
|
|
1648 xemacs_XtPopup (shell_widget);
|
|
1649
|
|
1650 if (!((EmacsFrame) frame_widget)->emacs_frame.initially_unmapped)
|
|
1651 XtMapWidget (shell_widget);
|
|
1652 else
|
|
1653 {
|
|
1654 /* We may have set f->visible to 1 in x_init_frame(), so undo
|
|
1655 that now. */
|
|
1656 FRAME_X_TOTALLY_VISIBLE_P (f) = 0;
|
|
1657 f->visible = 0;
|
|
1658 }
|
|
1659
|
|
1660 #ifdef EXTERNAL_WIDGET
|
|
1661 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1662 ExternalShellReady (shell_widget, XtWindow (frame_widget), KeyPressMask);
|
|
1663 else
|
|
1664 #endif
|
|
1665 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1666 {
|
|
1667 /* tell the window manager about us. */
|
|
1668 x_wm_store_class_hints (shell_widget, XtName (frame_widget));
|
|
1669 x_wm_maybe_store_wm_command (f);
|
|
1670 x_wm_hack_wm_protocols (shell_widget);
|
|
1671 }
|
|
1672
|
|
1673 #ifdef HACK_EDITRES
|
|
1674 /* Allow XEmacs to respond to EditRes requests. See the O'Reilly Xt */
|
|
1675 /* Instrinsics Programming Manual, Motif Edition, Aug 1993, Sect 14.14, */
|
|
1676 /* pp. 483-493. */
|
|
1677 XtAddEventHandler (shell_widget, /* the shell widget in question */
|
|
1678 (EventMask) NoEventMask,/* OR with existing mask */
|
|
1679 True, /* called on non-maskable events? */
|
|
1680 _XEditResCheckMessages, /* the handler */
|
|
1681 NULL);
|
|
1682 #endif
|
|
1683
|
|
1684 #ifdef HAVE_CDE
|
|
1685 {
|
|
1686 dnd_transfer_cb_rec[0].callback = x_cde_transfer_callback;
|
|
1687 dnd_transfer_cb_rec[0].closure = (XtPointer) f;
|
|
1688 dnd_transfer_cb_rec[1].callback = NULL;
|
|
1689 dnd_transfer_cb_rec[1].closure = NULL;
|
|
1690
|
|
1691 DtDndVaDropRegister (FRAME_X_TEXT_WIDGET (f),
|
2
|
1692 DtDND_FILENAME_TRANSFER | DtDND_BUFFER_TRANSFER,
|
|
1693 XmDROP_COPY, dnd_transfer_cb_rec,
|
|
1694 DtNtextIsBuffer, True,
|
0
|
1695 DtNpreserveRegistration, False,
|
|
1696 NULL);
|
|
1697 }
|
|
1698 #endif
|
|
1699
|
2
|
1700 #ifdef HAVE_OFFIX_DND
|
|
1701 {
|
|
1702 DndInitialize (FRAME_X_SHELL_WIDGET (f));
|
|
1703 DndRegisterDropWidget (FRAME_X_TEXT_WIDGET (f),
|
|
1704 x_offix_drop_event_handler,
|
|
1705 (XtPointer) f);
|
|
1706
|
|
1707 }
|
|
1708 #endif
|
|
1709
|
0
|
1710 /* Do a stupid property change to force the server to generate a
|
|
1711 propertyNotify event so that the event_stream server timestamp will
|
|
1712 be initialized to something relevant to the time we created the window.
|
|
1713 */
|
|
1714 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
|
|
1715 DEVICE_XATOM_WM_PROTOCOLS (d), XA_ATOM, 32, PropModeAppend,
|
|
1716 (unsigned char*) NULL, 0);
|
|
1717
|
|
1718 x_send_synthetic_mouse_event (f);
|
|
1719 }
|
|
1720
|
|
1721 static void
|
|
1722 allocate_x_frame_struct (struct frame *f)
|
|
1723 {
|
|
1724 /* zero out all slots. */
|
|
1725 f->frame_data = malloc_type_and_zero (struct x_frame);
|
|
1726
|
|
1727 /* yeah, except the lisp ones */
|
|
1728 FRAME_X_ICON_PIXMAP (f) = Qnil;
|
|
1729 FRAME_X_ICON_PIXMAP_MASK (f) = Qnil;
|
|
1730 #ifdef ENERGIZE
|
|
1731 FRAME_X_CURRENT_PSHEET_BUFFER (f) = Qnil;
|
|
1732 FRAME_X_DESIRED_PSHEET_BUFFER (f) = Qnil;
|
|
1733 #endif
|
|
1734 }
|
|
1735
|
|
1736
|
|
1737 /************************************************************************/
|
|
1738 /* Lisp functions */
|
|
1739 /************************************************************************/
|
|
1740
|
|
1741 static void
|
|
1742 x_init_frame_1 (struct frame *f, Lisp_Object props)
|
|
1743 {
|
|
1744 /* This function can GC */
|
|
1745 Lisp_Object device = FRAME_DEVICE (f);
|
|
1746 struct device *d = XDEVICE (device);
|
|
1747 Lisp_Object lisp_window_id;
|
|
1748 Lisp_Object popup;
|
|
1749
|
|
1750 lisp_window_id = Fplist_get (props, Qwindow_id, Qnil);
|
|
1751 popup = Fplist_get (props, Qpopup, Qnil);
|
|
1752 if (!NILP (popup))
|
|
1753 {
|
|
1754 if (EQ (popup, Qt))
|
|
1755 popup = Fselected_frame (device);
|
|
1756 CHECK_LIVE_FRAME (popup);
|
|
1757 if (!EQ (device, FRAME_DEVICE (XFRAME (popup))))
|
|
1758 signal_simple_error_2 ("Parent must be on same device as frame",
|
|
1759 device, popup);
|
|
1760 }
|
|
1761
|
|
1762 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
1763 {
|
|
1764 /* This means that this is the first frame on the device.
|
|
1765 So short-ciruit the delay in processing the initial MapNotify
|
|
1766 event so that output on the first frame shows up right
|
|
1767 away... */
|
|
1768 f->visible = 1;
|
|
1769 }
|
|
1770
|
|
1771 allocate_x_frame_struct (f);
|
|
1772 x_create_widgets (f, lisp_window_id, popup);
|
|
1773 }
|
|
1774
|
|
1775 static void
|
|
1776 x_init_frame_2 (struct frame *f, Lisp_Object props)
|
|
1777 {
|
|
1778 /* Set up the values of the widget/frame. A case could be made for putting
|
|
1779 this inside of the widget's initialize method. */
|
|
1780
|
|
1781 update_frame_face_values (f);
|
|
1782 x_initialize_frame_size (f);
|
|
1783 update_frame_title (f);
|
|
1784 }
|
|
1785
|
|
1786 static void
|
|
1787 x_init_frame_3 (struct frame *f)
|
|
1788 {
|
|
1789 /* Pop up the frame. */
|
|
1790
|
|
1791 x_popup_frame (f);
|
|
1792 }
|
|
1793
|
|
1794 static void
|
|
1795 x_mark_frame (struct frame *f, void (*markobj) (Lisp_Object))
|
|
1796 {
|
|
1797 ((markobj) (FRAME_X_ICON_PIXMAP (f)));
|
|
1798 ((markobj) (FRAME_X_ICON_PIXMAP_MASK (f)));
|
|
1799 #ifdef ENERGIZE
|
|
1800 ((markobj) (FRAME_X_CURRENT_PSHEET_BUFFER (f)));
|
|
1801 ((markobj) (FRAME_X_DESIRED_PSHEET_BUFFER (f)));
|
|
1802 #endif
|
|
1803 }
|
|
1804
|
|
1805 static void
|
|
1806 x_set_frame_icon (struct frame *f)
|
|
1807 {
|
|
1808 Pixmap x_pixmap, x_mask;
|
|
1809
|
|
1810 if (IMAGE_INSTANCEP (f->icon)
|
|
1811 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (f->icon)))
|
|
1812 {
|
|
1813 x_pixmap = XIMAGE_INSTANCE_X_PIXMAP (f->icon);
|
|
1814 x_mask = XIMAGE_INSTANCE_X_MASK (f->icon);
|
|
1815 }
|
|
1816 else
|
|
1817 {
|
|
1818 x_pixmap = 0;
|
|
1819 x_mask = 0;
|
|
1820 }
|
|
1821
|
|
1822 /* Store the X data into the widget. */
|
|
1823 {
|
|
1824 Arg av [10];
|
|
1825 int ac = 0;
|
|
1826 XtSetArg (av [ac], XtNiconPixmap, x_pixmap); ac++;
|
|
1827 XtSetArg (av [ac], XtNiconMask, x_mask); ac++;
|
|
1828 XtSetValues (FRAME_X_SHELL_WIDGET (f), av, ac);
|
|
1829 }
|
|
1830 }
|
|
1831
|
|
1832 static void
|
|
1833 x_set_frame_pointer (struct frame *f)
|
|
1834 {
|
|
1835 XDefineCursor (XtDisplay (FRAME_X_TEXT_WIDGET (f)),
|
|
1836 XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
1837 XIMAGE_INSTANCE_X_CURSOR (f->pointer));
|
|
1838 XSync (XtDisplay (FRAME_X_TEXT_WIDGET (f)), 0);
|
|
1839 }
|
|
1840
|
|
1841 static Lisp_Object
|
|
1842 x_get_frame_parent (struct frame *f)
|
|
1843 {
|
|
1844 Widget parentwid = 0;
|
|
1845 Arg av[1];
|
|
1846
|
|
1847 XtSetArg (av[0], XtNtransientFor, &parentwid);
|
|
1848 XtGetValues (FRAME_X_SHELL_WIDGET (f), av, 1);
|
|
1849 /* find the frame whose wid is parentwid */
|
|
1850 if (parentwid)
|
|
1851 {
|
|
1852 Lisp_Object frmcons;
|
|
1853 DEVICE_FRAME_LOOP (frmcons, XDEVICE (FRAME_DEVICE (f)))
|
|
1854 {
|
|
1855 Lisp_Object frame = XCAR (frmcons);
|
|
1856 if (FRAME_X_SHELL_WIDGET (XFRAME (frame)) == parentwid)
|
|
1857 return frame;
|
|
1858 }
|
|
1859 }
|
|
1860 return Qnil;
|
|
1861 }
|
|
1862
|
|
1863 DEFUN ("x-window-id", Fx_window_id, Sx_window_id, 0, 1, 0 /*
|
|
1864 Get the ID of the X11 window.
|
|
1865 This gives us a chance to manipulate the Emacs window from within a
|
|
1866 different program. Since the ID is an unsigned long, we return it as
|
|
1867 a string.
|
|
1868 */ )
|
|
1869 (frame)
|
|
1870 Lisp_Object frame;
|
|
1871 {
|
|
1872 char str[255];
|
|
1873 struct frame *f = decode_x_frame (frame);
|
|
1874
|
|
1875 sprintf (str, "%lu", XtWindow (FRAME_X_TEXT_WIDGET (f)));
|
|
1876 return build_string (str);
|
|
1877 }
|
|
1878
|
|
1879
|
|
1880 /************************************************************************/
|
|
1881 /* manipulating the X window */
|
|
1882 /************************************************************************/
|
|
1883
|
|
1884 static void
|
|
1885 x_set_frame_position (struct frame *f, int xoff, int yoff)
|
|
1886 {
|
|
1887 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
1888 Display *dpy = XtDisplay (w);
|
|
1889 Dimension frame_w = DisplayWidth (dpy, DefaultScreen (dpy));
|
|
1890 Dimension frame_h = DisplayHeight (dpy, DefaultScreen (dpy));
|
|
1891 Dimension shell_w, shell_h, shell_bord;
|
|
1892 int win_gravity;
|
|
1893
|
|
1894 XtVaGetValues (w,
|
|
1895 XtNwidth, &shell_w,
|
|
1896 XtNheight, &shell_h,
|
|
1897 XtNborderWidth, &shell_bord,
|
|
1898 0);
|
|
1899
|
|
1900 win_gravity =
|
|
1901 xoff >= 0 && yoff >= 0 ? NorthWestGravity :
|
|
1902 xoff >= 0 ? SouthWestGravity :
|
|
1903 yoff >= 0 ? NorthEastGravity :
|
|
1904 SouthEastGravity;
|
|
1905 if (xoff < 0)
|
|
1906 xoff += frame_w - shell_w - 2*shell_bord;
|
|
1907 if (yoff < 0)
|
|
1908 yoff += frame_h - shell_h - 2*shell_bord;
|
|
1909
|
|
1910 /* Update the hints so that, if this window is currently iconified, it will
|
|
1911 come back at the right place. We can't look at s->visible to determine
|
|
1912 whether it is iconified because it might not be up-to-date yet (the queue
|
|
1913 might not be processed). */
|
|
1914 XtVaSetValues (w,
|
|
1915 XtNwinGravity, win_gravity,
|
|
1916 XtNx, xoff,
|
|
1917 XtNy, yoff,
|
|
1918 0);
|
|
1919 /* Sometimes you will find that
|
|
1920
|
|
1921 (set-frame-position (selected-frame) -50 -50)
|
|
1922
|
|
1923 doesn't put the frame where you expect it to:
|
|
1924 i.e. it's closer to the lower-right corner than
|
2
|
1925 it should be, and it appears that the size of
|
0
|
1926 the WM decorations was not taken into account.
|
|
1927 This is *not* a problem with this function.
|
|
1928 Both mwm and twm have bugs in handling this
|
|
1929 situation. (mwm ignores the window gravity
|
|
1930 and always assumes NorthWest, except the first
|
|
1931 time you map the window; twm gets things almost
|
|
1932 right, but forgets to account for the border
|
|
1933 width of the top-level window.) This function
|
|
1934 does what it's supposed to according to the ICCCM,
|
|
1935 and I'm not about to hack around window-manager
|
|
1936 bugs. */
|
|
1937
|
|
1938 #if 0
|
|
1939 /* This is not necessary under either mwm or twm */
|
|
1940 x_wm_mark_shell_position_user_specified (w);
|
|
1941 #endif
|
|
1942 }
|
|
1943
|
|
1944 /* Call this to change the size of frame S's x-window. */
|
|
1945
|
|
1946 static void
|
|
1947 x_set_frame_size (struct frame *f, int cols, int rows)
|
|
1948 {
|
|
1949 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), cols, rows);
|
|
1950 #if 0
|
|
1951 /* this is not correct. x_set_frame_size() is called from
|
|
1952 Fset_frame_size(), which may or may not have been called
|
|
1953 by the user (e.g. update_EmacsFrame() calls it when the font
|
|
1954 changes). For now, don't bother with getting this right. */
|
|
1955 x_wm_mark_shell_size_user_specified (FRAME_X_SHELL_WIDGET (f));
|
|
1956 #endif
|
|
1957 }
|
|
1958
|
|
1959 static void
|
|
1960 x_set_mouse_position (struct window *w, int x, int y)
|
|
1961 {
|
|
1962 struct frame *f = XFRAME (w->frame);
|
|
1963
|
|
1964 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
1965 XWarpPointer (display, None, XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
1966 0, 0, 0, 0, w->pixel_left + x, w->pixel_top + y);
|
|
1967 }
|
|
1968
|
|
1969 static int
|
|
1970 x_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y)
|
|
1971 {
|
|
1972 Display *display = DEVICE_X_DISPLAY (d);
|
|
1973 Window child_window;
|
|
1974 Window root_window;
|
|
1975 Window win;
|
|
1976 int root_x, root_y;
|
|
1977 int win_x, win_y;
|
|
1978 unsigned int keys_and_buttons;
|
|
1979 struct frame *f;
|
|
1980
|
|
1981 if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
|
|
1982 &root_window, &child_window, &root_x, &root_y,
|
|
1983 &win_x, &win_y, &keys_and_buttons) == False)
|
|
1984 return 0;
|
|
1985
|
|
1986 if (child_window == None)
|
|
1987 return 0; /* not over any window. */
|
|
1988
|
|
1989 while (1)
|
|
1990 {
|
|
1991 win = child_window;
|
|
1992 if (XTranslateCoordinates (display, root_window, win, root_x, root_y,
|
|
1993 &win_x, &win_y, &child_window) == False)
|
|
1994 /* Huh? */
|
|
1995 return 0;
|
|
1996
|
|
1997 if (child_window == None)
|
|
1998 break;
|
|
1999 }
|
|
2000
|
|
2001 /* At this point, win is the innermost window containing the pointer
|
|
2002 and win_x and win_y are the coordinates of that window. */
|
|
2003 f = x_any_window_to_frame (d, win);
|
|
2004 if (!f)
|
|
2005 return 0;
|
|
2006 XSETFRAME (*frame, f);
|
|
2007
|
|
2008 if (XTranslateCoordinates (display, win,
|
|
2009 XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
2010 win_x, win_y, x, y, &child_window) == False)
|
|
2011 /* Huh? */
|
|
2012 return 0;
|
|
2013
|
|
2014 return 1;
|
|
2015 }
|
|
2016
|
|
2017 static void
|
|
2018 x_cant_notify_wm_error (void)
|
|
2019 {
|
|
2020 error ("Can't notify window manager of iconification.");
|
|
2021 }
|
|
2022
|
|
2023 /* Raise frame F. */
|
|
2024 static void
|
|
2025 x_raise_frame_1 (struct frame *f, int force)
|
|
2026 {
|
|
2027 Widget bottom_dialog;
|
|
2028 Window emacs_window;
|
|
2029 XWindowChanges xwc;
|
|
2030 unsigned int flags;
|
|
2031 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2032
|
|
2033 if (f->visible || force)
|
|
2034 {
|
|
2035 emacs_window = XtWindow (FRAME_X_SHELL_WIDGET (f));
|
|
2036 /* first raises all the dialog boxes, then put emacs just below the
|
|
2037 * bottom most dialog box */
|
|
2038 bottom_dialog = lw_raise_all_pop_up_widgets ();
|
|
2039 if (bottom_dialog && XtWindow (bottom_dialog))
|
|
2040 {
|
|
2041 xwc.sibling = XtWindow (bottom_dialog);
|
|
2042 xwc.stack_mode = Below;
|
|
2043 flags = CWSibling | CWStackMode;
|
|
2044 }
|
|
2045 else
|
|
2046 {
|
|
2047 xwc.stack_mode = Above;
|
|
2048 flags = CWStackMode;
|
|
2049 }
|
|
2050
|
|
2051 if (!XReconfigureWMWindow (display, emacs_window,
|
|
2052 DefaultScreen (display),
|
|
2053 flags, &xwc))
|
|
2054 x_cant_notify_wm_error ();
|
|
2055 }
|
|
2056 }
|
|
2057
|
|
2058 static void
|
|
2059 x_raise_frame (struct frame *f)
|
|
2060 {
|
|
2061 x_raise_frame_1 (f, 1);
|
|
2062 }
|
|
2063
|
|
2064 /* Lower frame F. */
|
|
2065 static void
|
|
2066 x_lower_frame (struct frame *f)
|
|
2067 {
|
|
2068 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2069 XWindowChanges xwc;
|
|
2070 unsigned int flags;
|
|
2071
|
|
2072 if (f->visible)
|
|
2073 {
|
|
2074 xwc.stack_mode = Below;
|
|
2075 flags = CWStackMode;
|
|
2076 if (!XReconfigureWMWindow (display, XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2077 DefaultScreen (display), flags, &xwc))
|
|
2078 x_cant_notify_wm_error ();
|
|
2079 }
|
|
2080 }
|
|
2081
|
|
2082 /* Change from withdrawn state to mapped state. */
|
|
2083 static void
|
|
2084 x_make_frame_visible (struct frame *f)
|
|
2085 {
|
|
2086 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2087
|
|
2088 if (!f->visible)
|
|
2089 XMapRaised (display, XtWindow (FRAME_X_SHELL_WIDGET (f)));
|
|
2090 else
|
|
2091 x_raise_frame_1 (f, 0);
|
|
2092 }
|
|
2093
|
|
2094 /* Change from mapped state to withdrawn state. */
|
|
2095 static void
|
|
2096 x_make_frame_invisible (struct frame *f)
|
|
2097 {
|
|
2098 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2099
|
|
2100 if (!f->visible)
|
|
2101 return;
|
|
2102
|
|
2103 if (!XWithdrawWindow (display,
|
|
2104 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2105 DefaultScreen (display)))
|
|
2106 x_cant_notify_wm_error ();
|
|
2107 }
|
|
2108
|
|
2109 static int
|
|
2110 x_frame_visible_p (struct frame *f)
|
|
2111 {
|
|
2112 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2113 XWindowAttributes xwa;
|
|
2114 int result;
|
|
2115
|
|
2116 if (!XGetWindowAttributes (display,
|
|
2117 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2118 &xwa))
|
|
2119 result = 0;
|
|
2120 else
|
|
2121 result = xwa.map_state == IsViewable;
|
|
2122
|
|
2123 f->visible = result;
|
|
2124 return result;
|
|
2125 }
|
|
2126
|
|
2127 static int
|
|
2128 x_frame_totally_visible_p (struct frame *f)
|
|
2129 {
|
|
2130 return FRAME_X_TOTALLY_VISIBLE_P (f);
|
|
2131 }
|
|
2132
|
|
2133 /* Change window state from mapped to iconified. */
|
|
2134 static void
|
|
2135 x_iconify_frame (struct frame *f)
|
|
2136 {
|
|
2137 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2138
|
|
2139 if (!XIconifyWindow (display,
|
|
2140 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2141 DefaultScreen (display)))
|
|
2142 x_cant_notify_wm_error ();
|
|
2143
|
|
2144 f->iconified = 1;
|
|
2145 }
|
|
2146
|
|
2147 /* Sets the X focus to frame f. */
|
|
2148 static void
|
|
2149 x_focus_on_frame (struct frame *f)
|
|
2150 {
|
|
2151 XWindowAttributes xwa;
|
|
2152 Widget shell_widget;
|
|
2153
|
|
2154 assert (FRAME_X_P (f));
|
|
2155
|
|
2156 shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
2157 if (!XtWindow (shell_widget))
|
|
2158 return;
|
|
2159
|
|
2160 #ifdef EXTERNAL_WIDGET
|
|
2161 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
2162 ExternalShellSetFocus (shell_widget);
|
|
2163 #endif /* EXTERNAL_WIDGET */
|
|
2164
|
|
2165 /* Do the ICCCM focus change if the window is still visible.
|
|
2166 The s->visible flag might not be up-to-date, because we might
|
|
2167 not have processed magic events recently. So make a server
|
|
2168 round-trip to find out whether it's really mapped right now.
|
|
2169 We grab the server to do this, because that's the only way to
|
|
2170 eliminate the race condition.
|
|
2171 */
|
|
2172 XGrabServer (XtDisplay (shell_widget));
|
|
2173 if (XGetWindowAttributes (XtDisplay (shell_widget),
|
|
2174 XtWindow (shell_widget),
|
|
2175 &xwa))
|
|
2176 f->visible = xwa.map_state == IsViewable;
|
|
2177
|
|
2178 if (f->visible)
|
|
2179 {
|
|
2180 Window focus;
|
|
2181 int revert_to;
|
|
2182 XGetInputFocus (XtDisplay (shell_widget), &focus, &revert_to);
|
|
2183 /* Don't explicitly set the focus on this window unless the focus
|
|
2184 was on some other window (not PointerRoot). Note that, even when
|
|
2185 running a point-to-type window manager like *twm, there is always
|
|
2186 a focus window; the window manager maintains that based on the
|
|
2187 mouse position. If you set the "NoTitleFocus" option in these
|
|
2188 window managers, then the server itself maintains the focus via
|
|
2189 PointerRoot, and changing that to focus on the window would make
|
|
2190 the window grab the focus. Very bad.
|
|
2191 */
|
|
2192 if (focus != PointerRoot)
|
|
2193 {
|
|
2194 XSetInputFocus (XtDisplay (shell_widget),
|
|
2195 XtWindow (shell_widget),
|
|
2196 RevertToParent,
|
|
2197 DEVICE_X_MOUSE_TIMESTAMP
|
|
2198 (XDEVICE (FRAME_DEVICE (f))));
|
|
2199 XFlush (XtDisplay (shell_widget));
|
|
2200 }
|
|
2201 }
|
|
2202 XUngrabServer (XtDisplay (shell_widget));
|
|
2203 XFlush (XtDisplay (shell_widget)); /* hey, I'd like to DEBUG this... */
|
|
2204 }
|
|
2205
|
|
2206 /* Destroy the X window of frame S. */
|
|
2207 static void
|
|
2208 x_delete_frame (struct frame *f)
|
|
2209 {
|
|
2210 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
2211 Lisp_Object popup, frame;
|
|
2212
|
|
2213 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
2214 x_wm_maybe_move_wm_command (f);
|
|
2215
|
|
2216 /* Frames with the popup property are using other frames as their
|
|
2217 widget parent. Deleting them are their parent has already been
|
|
2218 deleted can lead to crashes. */
|
|
2219 XSETFRAME (frame, f);
|
|
2220 popup = Fframe_property (frame, Qpopup, Qnil);
|
|
2221 if (!NILP (popup))
|
|
2222 {
|
|
2223 /* If popup isn't nil then it means the frame has that property
|
|
2224 and the value is supposed to be the parent frame. The FRAMEP
|
|
2225 check is to safeguard against it not being a frame. */
|
|
2226 if (!FRAMEP (popup) || !FRAME_LIVE_P (XFRAME (popup)))
|
|
2227 popup = Qt;
|
|
2228 else
|
|
2229 popup = Qnil;
|
|
2230 }
|
|
2231
|
|
2232 #ifdef EXTERNAL_WIDGET
|
|
2233 {
|
|
2234 Display *dpy = XtDisplay (w);
|
|
2235 expect_x_error (dpy);
|
|
2236 /* for obscure reasons having (I think) to do with the internal
|
|
2237 window-to-widget hierarchy maintained by Xt, we have to call
|
|
2238 XtUnrealizeWidget() here. Xt can really suck. */
|
|
2239 if (f->being_deleted)
|
|
2240 XtUnrealizeWidget (w);
|
|
2241 if (NILP (popup))
|
|
2242 XtDestroyWidget (w);
|
|
2243 x_error_occurred_p (dpy);
|
|
2244 }
|
|
2245 #else
|
|
2246 if (NILP (popup))
|
|
2247 XtDestroyWidget (w);
|
|
2248 #endif /* EXTERNAL_WIDGET */
|
|
2249
|
|
2250 if (FRAME_X_GEOM_FREE_ME_PLEASE (f))
|
|
2251 xfree (FRAME_X_GEOM_FREE_ME_PLEASE (f));
|
|
2252 xfree (f->frame_data);
|
|
2253 f->frame_data = 0;
|
|
2254 }
|
|
2255
|
|
2256
|
|
2257 /************************************************************************/
|
|
2258 /* initialization */
|
|
2259 /************************************************************************/
|
|
2260
|
|
2261 void
|
|
2262 syms_of_frame_x (void)
|
|
2263 {
|
|
2264 defsymbol (&Qwindow_id, "window-id");
|
|
2265 defsymbol (&Qpopup, "popup");
|
|
2266 defsymbol (&Qx_resource_name, "x-resource-name");
|
|
2267
|
|
2268 defsubr (&Sx_window_id);
|
|
2269 }
|
|
2270
|
|
2271 void
|
|
2272 console_type_create_frame_x (void)
|
|
2273 {
|
|
2274 /* frame methods */
|
|
2275 CONSOLE_HAS_METHOD (x, init_frame_1);
|
|
2276 CONSOLE_HAS_METHOD (x, init_frame_2);
|
|
2277 CONSOLE_HAS_METHOD (x, init_frame_3);
|
|
2278 CONSOLE_HAS_METHOD (x, mark_frame);
|
|
2279 CONSOLE_HAS_METHOD (x, focus_on_frame);
|
|
2280 CONSOLE_HAS_METHOD (x, delete_frame);
|
|
2281 CONSOLE_HAS_METHOD (x, get_mouse_position);
|
|
2282 CONSOLE_HAS_METHOD (x, set_mouse_position);
|
|
2283 CONSOLE_HAS_METHOD (x, raise_frame);
|
|
2284 CONSOLE_HAS_METHOD (x, lower_frame);
|
|
2285 CONSOLE_HAS_METHOD (x, make_frame_visible);
|
|
2286 CONSOLE_HAS_METHOD (x, make_frame_invisible);
|
|
2287 CONSOLE_HAS_METHOD (x, iconify_frame);
|
|
2288 CONSOLE_HAS_METHOD (x, set_frame_size);
|
|
2289 CONSOLE_HAS_METHOD (x, set_frame_position);
|
|
2290 CONSOLE_HAS_METHOD (x, frame_property);
|
|
2291 CONSOLE_HAS_METHOD (x, internal_frame_property_p);
|
|
2292 CONSOLE_HAS_METHOD (x, frame_properties);
|
|
2293 CONSOLE_HAS_METHOD (x, set_frame_properties);
|
2
|
2294 CONSOLE_HAS_METHOD (x, set_title_from_bufbyte);
|
|
2295 CONSOLE_HAS_METHOD (x, set_icon_name_from_bufbyte);
|
0
|
2296 CONSOLE_HAS_METHOD (x, frame_visible_p);
|
|
2297 CONSOLE_HAS_METHOD (x, frame_totally_visible_p);
|
|
2298 CONSOLE_HAS_METHOD (x, frame_iconified_p);
|
|
2299 CONSOLE_HAS_METHOD (x, set_frame_pointer);
|
|
2300 CONSOLE_HAS_METHOD (x, set_frame_icon);
|
|
2301 CONSOLE_HAS_METHOD (x, get_frame_parent);
|
|
2302 }
|
|
2303
|
|
2304 void
|
|
2305 vars_of_frame_x (void)
|
|
2306 {
|
|
2307 #ifdef EXTERNAL_WIDGET
|
|
2308 Fprovide (intern ("external-widget"));
|
|
2309 #endif
|
|
2310
|
|
2311 /* this call uses only safe functions from emacs.c */
|
|
2312 init_x_prop_symbols ();
|
|
2313
|
|
2314 DEFVAR_LISP ("default-x-frame-plist", &Vdefault_x_frame_plist /*
|
|
2315 Plist of default frame-creation properties for X frames.
|
|
2316 These override what is specified in the resource database and in
|
|
2317 `default-frame-plist', but are overridden by the arguments to the
|
|
2318 particular call to `make-frame'.
|
|
2319
|
|
2320 Note: In many cases, properties of a frame are available as specifiers
|
|
2321 instead of through the frame-properties mechanism.
|
|
2322
|
|
2323 Here is a list of recognized frame properties, other than those
|
|
2324 documented in `set-frame-properties' (they can be queried and
|
|
2325 set at any time, except as otherwise noted):
|
|
2326
|
|
2327 window-id The X window ID corresponding to the
|
|
2328 frame. May be set only at startup, and
|
|
2329 only if external widget support was
|
|
2330 compiled in; doing so causes the frame
|
|
2331 to be created as an \"external widget\"
|
|
2332 in another program that uses an existing
|
|
2333 window in the program rather than creating
|
|
2334 a new one.
|
|
2335 initially-unmapped If non-nil, the frame will not be visible
|
|
2336 when it is created. In this case, you
|
|
2337 need to call `make-frame-visible' to make
|
|
2338 the frame appear.
|
|
2339 popup If non-nil, it should be a frame, and this
|
|
2340 frame will be created as a \"popup\" frame
|
|
2341 whose parent is the given frame. This
|
|
2342 will make the window manager treat the
|
|
2343 frame as a dialog box, which may entail
|
|
2344 doing different things (e.g. not asking
|
|
2345 for positioning, and not iconifying
|
|
2346 separate from its parent).
|
|
2347 inter-line-space Not currently implemented.
|
|
2348 toolbar-shadow-thickness Thickness of toolbar shadows.
|
|
2349 background-toolbar-color Color of toolbar background.
|
|
2350 bottom-toolbar-shadow-color Color of bottom shadows on toolbars.
|
|
2351 (*Not* specific to the bottom-toolbar.)
|
|
2352 top-toolbar-shadow-color Color of top shadows on toolbars.
|
|
2353 (*Not* specifier to the top-toolbar.)
|
|
2354 internal-border-width Width of internal border around text area.
|
|
2355 border-width Width of external border around text area.
|
|
2356 top Y position (in pixels) of the upper-left
|
|
2357 outermost corner of the frame (i.e. the
|
|
2358 upper-left of the window-manager
|
|
2359 decorations).
|
|
2360 left X position (in pixels) of the upper-left
|
|
2361 outermost corner of the frame (i.e. the
|
|
2362 upper-left of the window-manager
|
|
2363 decorations).
|
|
2364 border-color Color of external border around text area.
|
|
2365 cursor-color Color of text cursor.
|
|
2366
|
|
2367 See also `default-frame-plist', which specifies properties which apply
|
|
2368 to all frames, not just X frames.
|
|
2369 */ );
|
|
2370 Vdefault_x_frame_plist = Qnil;
|
|
2371
|
|
2372 x_console_methods->device_specific_frame_props = &Vdefault_x_frame_plist;
|
|
2373 }
|