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
|
20
|
489 #if 0
|
0
|
490 static void
|
|
491 x_smash_bastardly_shell_position (Widget shell)
|
|
492 {
|
|
493 /* Naturally those bastards who wrote Xt couldn't be bothered
|
|
494 to learn about race conditions and such. We can't trust
|
2
|
495 the X and Y values to have any semblance of correctness,
|
0
|
496 so we smash the right values in place. */
|
|
497
|
|
498 /* We might be called before we've actually realized the window (if
|
|
499 we're checking for the minibuffer resource). This will bomb in
|
|
500 that case so we don't bother calling it. */
|
|
501 if (XtWindow (shell))
|
|
502 x_get_top_level_position (XtDisplay (shell), XtWindow (shell),
|
|
503 &shell->core.x, &shell->core.y);
|
|
504 }
|
20
|
505 #endif /* 0 */
|
0
|
506
|
|
507 static Lisp_Object
|
|
508 x_frame_property (struct frame *f, Lisp_Object property)
|
|
509 {
|
|
510 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
|
511 EmacsFrame w = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
512 Widget gw = (Widget) w;
|
|
513
|
2
|
514 #define FROB(propprop, value) \
|
|
515 do { \
|
|
516 if (EQ (property, propprop)) \
|
20
|
517 return (value); \
|
0
|
518 } while (0)
|
|
519
|
20
|
520 #if 0
|
0
|
521 if (EQ (property, Qleft) || EQ (property, Qtop))
|
|
522 x_smash_bastardly_shell_position (shell);
|
20
|
523 #endif
|
|
524 if (EQ (property, Qleft) || EQ (property, Qtop))
|
|
525 {
|
|
526 Position x, y;
|
|
527 if (!XtWindow(shell))
|
|
528 return make_int (0);
|
|
529 x_get_top_level_position (XtDisplay (shell), XtWindow (shell), &x, &y);
|
|
530 FROB (Qleft, make_int (x));
|
|
531 FROB (Qtop, make_int (y));
|
|
532 }
|
|
533 #if 0
|
0
|
534 FROB (Qleft, make_int (shell->core.x));
|
|
535 FROB (Qtop, make_int (shell->core.y));
|
20
|
536 #endif
|
0
|
537 FROB (Qborder_width, make_int (w->core.border_width));
|
|
538 FROB (Qinternal_border_width,
|
|
539 make_int (w->emacs_frame.internal_border_width));
|
|
540 FROB (Qborder_color, color_to_string (gw, w->core.border_pixel));
|
|
541 #ifdef HAVE_TOOLBARS
|
|
542 FROB (Qtop_toolbar_shadow_color,
|
|
543 color_to_string (gw, w->emacs_frame.top_toolbar_shadow_pixel));
|
|
544 FROB (Qbottom_toolbar_shadow_color,
|
|
545 color_to_string (gw, w->emacs_frame.bottom_toolbar_shadow_pixel));
|
|
546 FROB (Qbackground_toolbar_color,
|
|
547 color_to_string (gw, w->emacs_frame.background_toolbar_pixel));
|
|
548 FROB (Qtoolbar_shadow_thickness,
|
|
549 make_int (w->emacs_frame.toolbar_shadow_thickness));
|
20
|
550 #endif /* HAVE_TOOLBARS */
|
0
|
551 FROB (Qinter_line_space, make_int (w->emacs_frame.interline));
|
|
552 FROB (Qwindow_id, Fx_window_id (make_frame (f)));
|
|
553
|
|
554 #undef FROB
|
|
555
|
|
556 return Qunbound;
|
|
557 }
|
|
558
|
|
559 static int
|
|
560 x_internal_frame_property_p (struct frame *f, Lisp_Object property)
|
|
561 {
|
20
|
562 return EQ (property, Qleft)
|
|
563 || EQ (property, Qtop)
|
|
564 || EQ (property, Qborder_width)
|
|
565 || EQ (property, Qinternal_border_width)
|
|
566 || EQ (property, Qborder_color)
|
0
|
567 #ifdef HAVE_TOOLBARS
|
20
|
568 || EQ (property, Qtop_toolbar_shadow_color)
|
|
569 || EQ (property, Qbottom_toolbar_shadow_color)
|
|
570 || EQ (property, Qbackground_toolbar_color)
|
|
571 || EQ (property, Qtoolbar_shadow_thickness)
|
0
|
572 #endif
|
20
|
573 || EQ (property, Qinter_line_space)
|
|
574 || EQ (property, Qwindow_id)
|
|
575 || STRINGP (property);
|
0
|
576 }
|
|
577
|
|
578 static Lisp_Object
|
|
579 x_frame_properties (struct frame *f)
|
|
580 {
|
|
581 Lisp_Object result = Qnil;
|
|
582 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
|
583 EmacsFrame w = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
584 Widget gw = (Widget) w;
|
20
|
585 Position x, y;
|
0
|
586
|
2
|
587 #define FROB(propprop, value) \
|
|
588 do { \
|
|
589 Lisp_Object temtem = (value); \
|
|
590 if (!NILP (temtem)) \
|
|
591 /* backwards order; we reverse it below */ \
|
|
592 result = Fcons (temtem, Fcons (propprop, result)); \
|
0
|
593 } while (0)
|
|
594
|
20
|
595 #if 0
|
0
|
596 x_smash_bastardly_shell_position (shell);
|
|
597 FROB (Qleft, make_int (shell->core.x));
|
|
598 FROB (Qtop, make_int (shell->core.y));
|
20
|
599 #endif
|
|
600 if (!XtWindow(shell))
|
|
601 x = y = 0;
|
|
602 else
|
|
603 x_get_top_level_position (XtDisplay (shell), XtWindow (shell), &x, &y);
|
|
604
|
|
605 FROB (Qleft, make_int (x));
|
|
606 FROB (Qtop, make_int (y));
|
|
607
|
0
|
608 FROB (Qborder_width, make_int (w->core.border_width));
|
|
609 FROB (Qinternal_border_width,
|
|
610 make_int (w->emacs_frame.internal_border_width));
|
|
611 FROB (Qborder_color, color_to_string (gw, w->core.border_pixel));
|
|
612 #ifdef HAVE_TOOLBARS
|
|
613 FROB (Qtop_toolbar_shadow_color,
|
|
614 color_to_string (gw, w->emacs_frame.top_toolbar_shadow_pixel));
|
|
615 FROB (Qbottom_toolbar_shadow_color,
|
|
616 color_to_string (gw, w->emacs_frame.bottom_toolbar_shadow_pixel));
|
|
617 FROB (Qbackground_toolbar_color,
|
|
618 color_to_string (gw, w->emacs_frame.background_toolbar_pixel));
|
|
619 FROB (Qtoolbar_shadow_thickness,
|
|
620 make_int (w->emacs_frame.toolbar_shadow_thickness));
|
20
|
621 #endif /* HAVE_TOOLBARS */
|
0
|
622 FROB (Qinter_line_space, make_int (w->emacs_frame.interline));
|
|
623 FROB (Qwindow_id, Fx_window_id (make_frame (f)));
|
|
624
|
|
625 #undef FROB
|
|
626
|
|
627 return result;
|
|
628 }
|
|
629
|
|
630
|
|
631 /* Functions called only from `x_set_frame_properties' to set
|
2
|
632 individual properties. */
|
0
|
633
|
2
|
634 static void
|
|
635 x_set_frame_text_value (struct frame *f, Bufbyte *value,
|
|
636 String Xt_resource_name,
|
|
637 String Xt_resource_encoding_name)
|
0
|
638 {
|
2
|
639 Atom encoding = XA_STRING;
|
|
640 String new_XtValue = (String) value;
|
4
|
641 String old_XtValue = NULL;
|
2
|
642 Arg av[2];
|
0
|
643
|
70
|
644 #ifdef MULE
|
|
645 Bufbyte *ptr;
|
|
646 /* Optimize for common ASCII case */
|
|
647 for (ptr = value; *ptr; ptr++)
|
|
648 if (!BYTE_ASCII_P (*ptr))
|
|
649 {
|
|
650 CONST char * tmp;
|
|
651 encoding = DEVICE_XATOM_COMPOUND_TEXT (XDEVICE (FRAME_DEVICE (f)));
|
|
652 GET_C_CHARPTR_EXT_CTEXT_DATA_ALLOCA ((CONST char *) value, tmp);
|
|
653 new_XtValue = (String) tmp;
|
|
654 break;
|
|
655 }
|
|
656 #endif /* MULE */
|
|
657
|
2
|
658 /* ### Caching is device-independent - belongs in update_frame_title. */
|
|
659 XtSetArg (av[0], Xt_resource_name, &old_XtValue);
|
0
|
660 XtGetValues (FRAME_X_SHELL_WIDGET (f), av, 1);
|
2
|
661 if (!old_XtValue || strcmp (new_XtValue, old_XtValue))
|
0
|
662 {
|
2
|
663 XtSetArg (av[0], Xt_resource_name, new_XtValue);
|
|
664 XtSetArg (av[1], Xt_resource_encoding_name, encoding);
|
|
665 XtSetValues (FRAME_X_SHELL_WIDGET (f), av, 2);
|
0
|
666 }
|
|
667 }
|
|
668
|
2
|
669 static void
|
|
670 x_set_title_from_bufbyte (struct frame *f, Bufbyte *name)
|
0
|
671 {
|
2
|
672 x_set_frame_text_value (f, name, XtNtitle, XtNtitleEncoding);
|
|
673 }
|
0
|
674
|
2
|
675 static void
|
|
676 x_set_icon_name_from_bufbyte (struct frame *f, Bufbyte *name)
|
|
677 {
|
|
678 x_set_frame_text_value (f, name, XtNiconName, XtNiconNameEncoding);
|
0
|
679 }
|
|
680
|
|
681 /* Set the initial frame size as specified. This function is used
|
|
682 when the frame's widgets have not yet been realized. In this
|
|
683 case, it is not sufficient just to set the width and height of
|
|
684 the EmacsFrame widget, because they will be ignored when the
|
|
685 widget is realized (instead, the shell's geometry resource is
|
|
686 used). */
|
|
687
|
|
688 static void
|
|
689 x_set_initial_frame_size (struct frame *f, int flags, int x, int y,
|
|
690 unsigned int w, unsigned int h)
|
|
691 {
|
|
692 char shell_geom [255];
|
|
693 int xval, yval;
|
|
694 char xsign, ysign;
|
|
695 char uspos = !!(flags & (XValue | YValue));
|
|
696 char ussize = !!(flags & (WidthValue | HeightValue));
|
|
697 char *temp;
|
|
698
|
|
699 /* assign the correct size to the EmacsFrame widget ... */
|
|
700 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), w, h);
|
|
701
|
|
702 /* and also set the WMShell's geometry */
|
|
703 (flags & XNegative) ? (xval = -x, xsign = '-') : (xval = x, xsign = '+');
|
|
704 (flags & YNegative) ? (yval = -y, ysign = '-') : (yval = y, ysign = '+');
|
|
705
|
|
706 if (uspos && ussize)
|
|
707 sprintf (shell_geom, "=%dx%d%c%d%c%d", w, h, xsign, xval, ysign, yval);
|
|
708 else if (uspos)
|
|
709 sprintf (shell_geom, "=%c%d%c%d", xsign, xval, ysign, yval);
|
|
710 else if (ussize)
|
|
711 sprintf (shell_geom, "=%dx%d", w, h);
|
|
712
|
|
713 if (uspos || ussize)
|
|
714 {
|
|
715 temp = xmalloc (1 + strlen (shell_geom));
|
|
716 strcpy (temp, shell_geom);
|
|
717 FRAME_X_GEOM_FREE_ME_PLEASE (f) = temp;
|
|
718 }
|
|
719 else
|
|
720 temp = NULL;
|
|
721 XtVaSetValues (FRAME_X_SHELL_WIDGET (f), XtNgeometry, temp, 0);
|
|
722 }
|
|
723
|
|
724 /* Report to X that a frame property of frame S is being set or changed.
|
|
725 If the property is not specially recognized, do nothing.
|
|
726 */
|
|
727
|
|
728 static void
|
|
729 x_set_frame_properties (struct frame *f, Lisp_Object plist)
|
|
730 {
|
20
|
731 Position x, y;
|
0
|
732 Dimension width = 0, height = 0;
|
|
733 Bool width_specified_p = False;
|
|
734 Bool height_specified_p = False;
|
|
735 Bool x_position_specified_p = False;
|
|
736 Bool y_position_specified_p = False;
|
|
737 Bool internal_border_width_specified = False;
|
|
738 Lisp_Object tail;
|
|
739 Widget w = FRAME_X_TEXT_WIDGET (f);
|
|
740
|
|
741 for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail)))
|
|
742 {
|
|
743 Lisp_Object prop = Fcar (tail);
|
|
744 Lisp_Object val = Fcar (Fcdr (tail));
|
|
745
|
|
746 if (STRINGP (prop))
|
|
747 {
|
|
748 CONST char *extprop;
|
|
749
|
14
|
750 if (XSTRING_LENGTH (prop) == 0)
|
0
|
751 continue;
|
|
752
|
|
753 GET_C_STRING_CTEXT_DATA_ALLOCA (prop, extprop);
|
|
754 if (STRINGP (val))
|
|
755 {
|
|
756 Extbyte *extval;
|
|
757 Extcount extvallen;
|
|
758
|
|
759 GET_STRING_CTEXT_DATA_ALLOCA (val, extval, extvallen);
|
|
760 XtVaSetValues (w, XtVaTypedArg, extprop,
|
|
761 XtRString, extval, extvallen + 1, 0);
|
|
762 }
|
|
763 else
|
|
764 XtVaSetValues (w, XtVaTypedArg,
|
|
765 extprop, XtRInt, XINT (val),
|
|
766 sizeof (int),
|
|
767 0);
|
|
768 }
|
|
769 else if (SYMBOLP (prop))
|
|
770 {
|
|
771 Lisp_Object str = Fget (prop, Qx_resource_name, Qnil);
|
|
772 int int_p = !NILP (Fget (prop, Qintegerp, Qnil));
|
|
773
|
|
774 if (NILP (prop) || NILP (str))
|
|
775 {
|
|
776 /* Kludge to handle the font property. */
|
|
777 if (EQ (prop, Qfont))
|
|
778 {
|
|
779 /* If the value is not a string we silently ignore it. */
|
|
780 if (STRINGP (val))
|
|
781 {
|
|
782 Lisp_Object frm, font_spec;
|
|
783
|
|
784 XSETFRAME (frm, f);
|
|
785 font_spec = Fget (Fget_face (Qdefault), Qfont, Qnil);
|
|
786
|
|
787 Fadd_spec_to_specifier (font_spec, val, frm, Qnil, Qnil);
|
|
788 update_frame_face_values (f);
|
|
789 }
|
|
790
|
|
791 continue;
|
|
792 }
|
|
793 else
|
|
794 continue;
|
|
795 }
|
|
796 CHECK_STRING (str);
|
|
797
|
|
798 /* Kludge the width/height so that we interpret them in characters
|
|
799 instead of pixels. Yuck yuck yuck. */
|
14
|
800 if (!strcmp ((char *) XSTRING_DATA (str), "width"))
|
0
|
801 {
|
|
802 CHECK_INT (val);
|
|
803 width = XINT (val);
|
|
804 width_specified_p = True;
|
|
805 continue;
|
|
806 }
|
14
|
807 if (!strcmp ((char *) XSTRING_DATA (str), "height"))
|
0
|
808 {
|
|
809 CHECK_INT (val);
|
|
810 height = XINT (val);
|
|
811 height_specified_p = True;
|
|
812 continue;
|
|
813 }
|
|
814 /* Further kludge the x/y. */
|
14
|
815 if (!strcmp ((char *) XSTRING_DATA (str), "x"))
|
0
|
816 {
|
|
817 CHECK_INT (val);
|
20
|
818 x = (Position) XINT (val);
|
0
|
819 x_position_specified_p = True;
|
|
820 continue;
|
|
821 }
|
14
|
822 if (!strcmp ((char *) XSTRING_DATA (str), "y"))
|
0
|
823 {
|
|
824 CHECK_INT (val);
|
20
|
825 y = (Position) XINT (val);
|
0
|
826 y_position_specified_p = True;
|
|
827 continue;
|
|
828 }
|
|
829 /* Have you figured out by now that this entire function is
|
|
830 one gigantic kludge? */
|
14
|
831 if (!strcmp ((char *) XSTRING_DATA (str),
|
0
|
832 "internalBorderWidth"))
|
|
833 {
|
|
834 internal_border_width_specified = True;
|
|
835 }
|
|
836
|
|
837 if (int_p)
|
|
838 {
|
|
839 CHECK_INT (val);
|
14
|
840 XtVaSetValues (w, (char *) XSTRING_DATA (str),
|
0
|
841 XINT (val), 0);
|
|
842 }
|
|
843 else if (EQ (val, Qt))
|
|
844 XtVaSetValues (w,
|
|
845 /* XtN... */
|
14
|
846 (char *) XSTRING_DATA (str),
|
0
|
847 True,
|
|
848 0);
|
|
849 else if (EQ (val, Qnil))
|
|
850 XtVaSetValues (w,
|
|
851 /* XtN... */
|
14
|
852 (char *) XSTRING_DATA (str),
|
0
|
853 False,
|
|
854 0);
|
|
855 else
|
|
856 {
|
|
857 CHECK_STRING (val);
|
|
858 XtVaSetValues (w, XtVaTypedArg,
|
|
859 /* XtN... */
|
14
|
860 (char *) XSTRING_DATA (str),
|
0
|
861 XtRString,
|
14
|
862 XSTRING_DATA (val),
|
|
863 XSTRING_LENGTH (val) + 1,
|
0
|
864 0);
|
|
865 }
|
|
866
|
|
867 #ifdef HAVE_SCROLLBARS
|
14
|
868 if (!strcmp ((char *) XSTRING_DATA (str), "scrollBarWidth")
|
|
869 || !strcmp ((char *) XSTRING_DATA (str),
|
0
|
870 "scrollBarHeight"))
|
|
871 {
|
|
872 x_update_frame_scrollbars (f);
|
|
873 }
|
20
|
874 #endif /* HAVE_SCROLLBARS */
|
0
|
875 }
|
|
876 }
|
|
877
|
|
878 /* Kludge kludge kludge. We need to deal with the size and position
|
|
879 specially. */
|
|
880 {
|
|
881 int size_specified_p = width_specified_p || height_specified_p;
|
|
882 int position_specified_p = x_position_specified_p ||
|
|
883 y_position_specified_p;
|
|
884
|
|
885 if (!width_specified_p)
|
|
886 width = FRAME_WIDTH (f);
|
|
887 if (!height_specified_p)
|
|
888 height = FRAME_HEIGHT (f);
|
|
889
|
|
890 /* Kludge kludge kludge kludge. */
|
20
|
891 if (position_specified_p &&
|
|
892 (!x_position_specified_p || !y_position_specified_p))
|
|
893 {
|
|
894 Position dummy;
|
|
895 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
|
896 x_get_top_level_position (XtDisplay (shell), XtWindow (shell),
|
|
897 (x_position_specified_p ? &dummy : &x),
|
|
898 (y_position_specified_p ? &dummy : &y));
|
|
899 #if 0
|
|
900 x = (int) (FRAME_X_SHELL_WIDGET (f)->core.x);
|
|
901 y = (int) (FRAME_X_SHELL_WIDGET (f)->core.y);
|
|
902 #endif
|
|
903 }
|
0
|
904
|
|
905 if (!f->init_finished)
|
|
906 {
|
|
907 int flags = (size_specified_p ? WidthValue | HeightValue : 0) |
|
20
|
908 (position_specified_p ?
|
|
909 XValue | YValue | (x < 0 ? XNegative : 0) | (y < 0 ? YNegative : 0)
|
|
910 : 0);
|
0
|
911 if (size_specified_p
|
|
912 || position_specified_p
|
|
913 || internal_border_width_specified)
|
|
914 x_set_initial_frame_size (f, flags, x, y, width, height);
|
|
915 }
|
|
916 else
|
|
917 {
|
|
918 if (size_specified_p || internal_border_width_specified)
|
|
919 {
|
|
920 Lisp_Object frame;
|
|
921 XSETFRAME (frame, f);
|
|
922 Fset_frame_size (frame, make_int (width),
|
|
923 make_int (height), Qnil);
|
|
924 }
|
|
925 if (position_specified_p)
|
|
926 {
|
|
927 Lisp_Object frame;
|
|
928 XSETFRAME (frame, f);
|
|
929 Fset_frame_position (frame, make_int (x), make_int (y));
|
|
930 }
|
|
931 }
|
|
932 }
|
|
933 }
|
|
934
|
|
935 static int frame_title_format_already_set;
|
|
936
|
|
937 static void
|
|
938 maybe_set_frame_title_format (Widget shell)
|
|
939 {
|
|
940
|
|
941 /* Only do this if this is the first X frame we're creating.
|
|
942
|
|
943 If the *title resource (or -title option) was specified, then
|
|
944 set frame-title-format to its value.
|
|
945 */
|
|
946
|
|
947 if (!frame_title_format_already_set)
|
|
948 {
|
|
949 /* No doubt there's a less stupid way to do this. */
|
|
950 char *results [2];
|
|
951 XtResource resources [2];
|
|
952 results [0] = results [1] = 0;
|
|
953 resources [0].resource_name = XtNtitle;
|
|
954 resources [0].resource_class = XtCTitle;
|
|
955 resources [0].resource_type = XtRString;
|
|
956 resources [0].resource_size = sizeof (String);
|
|
957 resources [0].resource_offset = 0;
|
|
958 resources [0].default_type = XtRString;
|
|
959 resources [0].default_addr = 0;
|
|
960 resources [1].resource_name = XtNiconName;
|
|
961 resources [1].resource_class = XtCIconName;
|
|
962 resources [1].resource_type = XtRString;
|
|
963 resources [1].resource_size = sizeof (String);
|
|
964 resources [1].resource_offset = sizeof (char *);
|
|
965 resources [1].default_type = XtRString;
|
|
966 resources [1].default_addr = 0;
|
|
967 XtGetSubresources (XtParent (shell), (XtPointer) results,
|
|
968 shell->core.name,
|
|
969 shell->core.widget_class->core_class.class_name,
|
|
970 resources, XtNumber (resources), 0, 0);
|
|
971 if (results[0])
|
|
972 Vframe_title_format = build_string (results[0]);
|
|
973 if (results[1])
|
|
974 Vframe_icon_title_format = build_string (results[1]);
|
|
975 }
|
|
976
|
|
977 frame_title_format_already_set = 1;
|
|
978 }
|
|
979
|
|
980 #ifdef HAVE_CDE
|
|
981 #include <Dt/Dt.h>
|
|
982 #include <Dt/Dnd.h>
|
|
983
|
20
|
984 static Widget CurrentDragWidget = NULL;
|
|
985
|
|
986 static void
|
|
987 x_cde_destroy_callback (Widget widget, XtPointer clientData,
|
|
988 XtPointer callData)
|
|
989 {
|
|
990 xfree (clientData);
|
|
991 CurrentDragWidget = NULL;
|
|
992 }
|
|
993
|
|
994 static void
|
|
995 x_cde_convert_callback (Widget widget, XtPointer clientData,
|
|
996 XtPointer callData)
|
|
997 {
|
|
998 DtDndConvertCallbackStruct *convertInfo =
|
|
999 (DtDndConvertCallbackStruct *) callData;
|
|
1000 char *textdata = (char *) clientData;
|
|
1001
|
|
1002 if(convertInfo == NULL)
|
|
1003 {
|
|
1004 return;
|
|
1005 }
|
|
1006
|
|
1007 if((convertInfo->dragData->protocol != DtDND_BUFFER_TRANSFER) ||
|
|
1008 (convertInfo->reason != DtCR_DND_CONVERT_DATA))
|
|
1009 {
|
|
1010 return;
|
|
1011 }
|
|
1012
|
|
1013 convertInfo->dragData->data.buffers[0].bp = XtNewString(textdata);
|
|
1014 convertInfo->dragData->data.buffers[0].size = strlen(textdata);
|
|
1015 convertInfo->dragData->data.buffers[0].name = NULL;
|
|
1016 convertInfo->dragData->numItems = 1;
|
|
1017 convertInfo->status = DtDND_SUCCESS;
|
|
1018 }
|
|
1019
|
|
1020
|
|
1021 static XtCallbackRec dnd_convert_cb_rec[2];
|
|
1022 static XtCallbackRec dnd_destroy_cb_rec[2];
|
|
1023 static int drag_not_done = 0;
|
|
1024
|
|
1025 static Lisp_Object
|
|
1026 abort_current_drag(Lisp_Object arg)
|
|
1027 {
|
|
1028 if(CurrentDragWidget && drag_not_done)
|
|
1029 {
|
|
1030 XmDragCancel(CurrentDragWidget);
|
|
1031 CurrentDragWidget = NULL;
|
|
1032 }
|
|
1033 return arg;
|
|
1034 }
|
|
1035
|
|
1036 DEFUN ("cde-start-drag-internal", Fcde_start_drag_internal, 1, 1, 0, /*
|
|
1037 Start a CDE drag from a buffer.
|
|
1038 */
|
|
1039 (text))
|
|
1040 {
|
|
1041 if (STRINGP (text))
|
|
1042 {
|
|
1043 struct frame *f = decode_x_frame (Fselected_frame (Qnil));
|
|
1044 XEvent event;
|
|
1045 Widget Wuh = FRAME_X_TEXT_WIDGET (f);
|
|
1046 char *Ctext;
|
|
1047 Display *display = XtDisplayOfObject (Wuh);
|
|
1048 Window root_window, child_window;
|
|
1049 int root_x, root_y, win_x, win_y;
|
|
1050 unsigned int keys_and_buttons;
|
|
1051
|
|
1052 if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
|
|
1053 &root_window, &child_window, &root_x, &root_y,
|
|
1054 &win_x, &win_y, &keys_and_buttons) == False)
|
70
|
1055 return Qnil;
|
20
|
1056
|
|
1057 Ctext = xstrdup ((char *) XSTRING_DATA (text));
|
|
1058
|
|
1059 /*
|
|
1060 * Eek - XEmacs doesn't keep the old X event around so we have to
|
|
1061 * build a dummy event. This is a truly gross hack.
|
|
1062 */
|
|
1063
|
|
1064 event.xbutton.type = ButtonPress;
|
|
1065 event.xbutton.send_event = False;
|
|
1066 event.xbutton.display = XtDisplayOfObject(Wuh);
|
|
1067 event.xbutton.window = XtWindowOfObject(Wuh);
|
|
1068 event.xbutton.root = XRootWindow(event.xkey.display, 0);
|
|
1069 event.xbutton.subwindow = 0;
|
|
1070 event.xbutton.time = 0;
|
|
1071 event.xbutton.x = win_x;
|
|
1072 event.xbutton.y = win_y;
|
|
1073 event.xbutton.x_root = root_x;
|
|
1074 event.xbutton.y_root = root_y;
|
|
1075 event.xbutton.state = 0;
|
|
1076 event.xbutton.button = 1;
|
|
1077 event.xkey.same_screen = True;
|
|
1078
|
|
1079 dnd_convert_cb_rec[0].callback = x_cde_convert_callback;
|
|
1080 dnd_convert_cb_rec[0].closure = (XtPointer) Ctext;
|
|
1081 dnd_convert_cb_rec[1].callback = NULL;
|
|
1082 dnd_convert_cb_rec[1].closure = NULL;
|
|
1083
|
|
1084 dnd_destroy_cb_rec[0].callback = x_cde_destroy_callback;
|
|
1085 dnd_destroy_cb_rec[0].closure = (XtPointer) Ctext;
|
|
1086 dnd_destroy_cb_rec[1].callback = NULL;
|
|
1087 dnd_destroy_cb_rec[1].closure = NULL;
|
|
1088
|
|
1089 CurrentDragWidget =
|
70
|
1090 DtDndDragStart (Wuh, &event, DtDND_BUFFER_TRANSFER, 1, XmDROP_COPY,
|
|
1091 dnd_convert_cb_rec,
|
|
1092 dnd_destroy_cb_rec,
|
|
1093 NULL, 0);
|
20
|
1094 return Qt;
|
|
1095 }
|
|
1096 return Qnil;
|
|
1097 }
|
|
1098
|
0
|
1099 void
|
|
1100 x_cde_transfer_callback (Widget widget, XtPointer clientData,
|
|
1101 XtPointer callData)
|
|
1102 {
|
16
|
1103 char *filePath, *buf;
|
0
|
1104 int ii;
|
20
|
1105 Lisp_Object path = Qnil;
|
0
|
1106 Lisp_Object frame = Qnil;
|
20
|
1107 Lisp_Object data = Qnil;
|
|
1108 struct gcpro gcpro1, gcpro2, gcpro3;
|
0
|
1109
|
|
1110 DtDndTransferCallbackStruct *transferInfo =
|
|
1111 (DtDndTransferCallbackStruct *) callData;
|
|
1112
|
|
1113 if (transferInfo == NULL)
|
|
1114 return;
|
|
1115
|
20
|
1116 GCPRO3 (path, frame, data);
|
0
|
1117
|
|
1118 frame = make_frame ((struct frame *) clientData);
|
|
1119 if (transferInfo->dropData->protocol == DtDND_FILENAME_TRANSFER)
|
|
1120 {
|
|
1121 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
|
|
1122 {
|
|
1123 filePath = transferInfo->dropData->data.files[ii];
|
70
|
1124 /* ### Mule-izing required */
|
76
|
1125 path = make_string ((Bufbyte *)filePath, strlen (filePath));
|
0
|
1126 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
1127 }
|
|
1128 }
|
2
|
1129 else if (transferInfo->dropData->protocol == DtDND_BUFFER_TRANSFER)
|
|
1130 {
|
20
|
1131 int speccount = specpdl_depth();
|
|
1132
|
|
1133 record_unwind_protect(abort_current_drag, Qnil);
|
|
1134 drag_not_done = 1;
|
2
|
1135 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
|
|
1136 {
|
|
1137 filePath = transferInfo->dropData->data.buffers[ii].name;
|
20
|
1138 /* ### Mule-izing required */
|
70
|
1139 path = (filePath == NULL) ? Qnil
|
76
|
1140 : make_string ((Bufbyte *)filePath, strlen (filePath));
|
2
|
1141 buf = transferInfo->dropData->data.buffers[ii].bp;
|
76
|
1142 data = make_string((Bufbyte *)buf,
|
70
|
1143 transferInfo->dropData->data.buffers[ii].size);
|
20
|
1144 va_run_hook_with_args(Qdrag_and_drop_functions, 3, frame, path,
|
70
|
1145 data);
|
2
|
1146 }
|
70
|
1147 drag_not_done = 0;
|
|
1148 unbind_to(speccount, Qnil);
|
2
|
1149 }
|
|
1150
|
0
|
1151 UNGCPRO;
|
|
1152 return;
|
|
1153 }
|
20
|
1154 #endif /* HAVE_CDE */
|
0
|
1155
|
2
|
1156 #ifdef HAVE_OFFIX_DND
|
|
1157 #include <OffiX/DragAndDrop.h>
|
|
1158
|
|
1159 void
|
|
1160 x_offix_drop_event_handler (Widget widget, XtPointer data, XEvent *event,
|
|
1161 Boolean *b)
|
|
1162 {
|
|
1163 int i, len, Type;
|
|
1164 unsigned char *Data;
|
|
1165 unsigned long Size;
|
|
1166
|
|
1167 Lisp_Object path = Qnil;
|
|
1168 Lisp_Object frame = Qnil;
|
|
1169
|
|
1170 struct gcpro gcpro1, gcpro2;
|
|
1171
|
|
1172 Type = DndDataType (event);
|
|
1173 if ((Type != DndFile) && (Type != DndFiles) && (Type != DndExe))
|
|
1174 return;
|
|
1175 DndGetData (&Data, &Size);
|
|
1176
|
|
1177 GCPRO2 (path, frame);
|
|
1178
|
|
1179 frame = make_frame ((struct frame *) data);
|
|
1180
|
|
1181 if (Type == DndFiles)
|
|
1182 {
|
|
1183 while (*Data)
|
|
1184 {
|
|
1185 len = strlen ((char*) Data);
|
|
1186 path = make_string ((char*) Data, len);
|
|
1187 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
1188 Data += len+1;
|
|
1189 }
|
|
1190 }
|
|
1191 else
|
|
1192 {
|
|
1193 path = make_string ((char*) Data, strlen (Data));
|
|
1194 va_run_hook_with_args (Qdrag_and_drop_functions, 2, frame, path);
|
|
1195 }
|
|
1196
|
|
1197 UNGCPRO;
|
|
1198 return;
|
|
1199 }
|
|
1200 #endif /* HAVE_OFFIX_DND */
|
|
1201
|
0
|
1202
|
|
1203 /************************************************************************/
|
|
1204 /* widget creation */
|
|
1205 /************************************************************************/
|
|
1206
|
|
1207 /* The widget hierarchy is
|
|
1208
|
|
1209 argv[0] shell container FRAME-NAME
|
|
1210 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1211
|
|
1212 We accept geometry specs in this order:
|
|
1213
|
|
1214 *FRAME-NAME.geometry
|
|
1215 *EmacsFrame.geometry
|
|
1216 Emacs.geometry
|
|
1217
|
|
1218 Other possibilities for widget hierarchies might be
|
|
1219
|
|
1220 argv[0] frame container FRAME-NAME
|
|
1221 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1222 or
|
|
1223 argv[0] FRAME-NAME container FRAME-NAME
|
|
1224 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1225 or
|
|
1226 argv[0] FRAME-NAME container emacsTextPane
|
|
1227 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1228
|
|
1229 #ifdef EXTERNAL_WIDGET
|
|
1230 The ExternalShell widget is simply a replacement for the Shell widget
|
|
1231 which is able to deal with using an externally-supplied window instead
|
|
1232 of always creating its own.
|
|
1233 #endif
|
|
1234
|
|
1235 */
|
|
1236
|
|
1237 #ifdef EXTERNAL_WIDGET
|
|
1238
|
|
1239 static int
|
|
1240 is_valid_window (Window w, struct device *d)
|
|
1241 {
|
|
1242 XWindowAttributes xwa;
|
|
1243 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1244
|
|
1245 expect_x_error (dpy);
|
|
1246 XGetWindowAttributes (dpy, w, &xwa);
|
|
1247 return !x_error_occurred_p (dpy);
|
|
1248 }
|
|
1249
|
|
1250 #endif /* EXTERNAL_WIDGET */
|
|
1251
|
|
1252 /* This sends a synthetic mouse-motion event to the frame, if the mouse
|
|
1253 is over the frame. This ensures that the cursor gets set properly
|
|
1254 before the user moves the mouse for the first time. */
|
|
1255
|
|
1256 static void
|
|
1257 x_send_synthetic_mouse_event (struct frame *f)
|
|
1258 {
|
|
1259 /* #### write this function. */
|
|
1260 }
|
|
1261
|
|
1262 static int
|
|
1263 first_x_frame_p (struct frame *f)
|
|
1264 {
|
|
1265 Lisp_Object rest = DEVICE_FRAME_LIST (XDEVICE (f->device));
|
|
1266 while (!NILP (rest) &&
|
|
1267 (f == XFRAME (XCAR (rest)) ||
|
|
1268 !FRAME_X_P (XFRAME (XCAR (rest)))))
|
|
1269 rest = XCDR (rest);
|
|
1270 return (NILP (rest));
|
|
1271 }
|
|
1272
|
|
1273 /* Figure out what size the EmacsFrame widget should initially be,
|
|
1274 and set it. Should be called after the default font has been
|
|
1275 determined but before the widget has been realized. */
|
|
1276
|
|
1277 static void
|
|
1278 x_initialize_frame_size (struct frame *f)
|
|
1279 {
|
|
1280 /* Geometry of the AppShell */
|
|
1281 int app_flags = 0;
|
|
1282 int app_x = 0;
|
|
1283 int app_y = 0;
|
|
1284 unsigned int app_w = 0;
|
|
1285 unsigned int app_h = 0;
|
|
1286
|
|
1287 /* Geometry of the EmacsFrame */
|
|
1288 int frame_flags = 0;
|
|
1289 int frame_x = 0;
|
|
1290 int frame_y = 0;
|
|
1291 unsigned int frame_w = 0;
|
|
1292 unsigned int frame_h = 0;
|
|
1293
|
|
1294 /* Hairily merged geometry */
|
|
1295 int x = 0;
|
|
1296 int y = 0;
|
|
1297 unsigned int w = 80;
|
|
1298 unsigned int h = 40;
|
|
1299 int flags = 0;
|
|
1300
|
|
1301 char *geom = 0, *ew_geom = 0;
|
|
1302 Boolean iconic_p = False, ew_iconic_p = False;
|
|
1303
|
|
1304 Widget wmshell = FRAME_X_SHELL_WIDGET (f);
|
|
1305 /* #### This may not be an ApplicationShell any more, with the 'popup
|
|
1306 frame property. */
|
|
1307 Widget app_shell = XtParent (wmshell);
|
|
1308 Widget ew = FRAME_X_TEXT_WIDGET (f);
|
|
1309
|
|
1310 /* set the position of the frame's root window now. When the
|
|
1311 frame was created, the position was initialized to (0,0). */
|
|
1312 {
|
|
1313 struct window *win = XWINDOW (f->root_window);
|
|
1314
|
|
1315 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f);
|
|
1316 WINDOW_TOP (win) = FRAME_TOP_BORDER_END (f);
|
|
1317
|
|
1318 if (!NILP (f->minibuffer_window))
|
|
1319 {
|
|
1320 win = XWINDOW (f->minibuffer_window);
|
|
1321 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f);
|
|
1322 }
|
|
1323 }
|
|
1324
|
|
1325 #ifdef EXTERNAL_WIDGET
|
|
1326 /* If we're an external widget, then the size of the frame is predetermined
|
|
1327 (by the client) and is not our decision to make. */
|
|
1328 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1329 return;
|
|
1330 #endif
|
|
1331
|
|
1332 #if 0
|
|
1333 /* #### this junk has not been tested; therefore it's
|
|
1334 probably wrong. Doesn't really matter at this point because
|
|
1335 currently all frames are either top-level or external widgets. */
|
|
1336
|
|
1337 /* If we're not our own top-level window, then we shouldn't go messing around
|
|
1338 with top-level shells or "Emacs.geometry" or any such stuff. Therefore,
|
|
1339 we do as follows to determine the size of the frame:
|
|
1340
|
|
1341 1) If a value for the frame's "geometry" resource was specified, then
|
|
1342 use it. (This specifies a size in characters.)
|
|
1343 2) Else, if the "width" and "height" resources were specified, then
|
|
1344 leave them alone. (This is a value in pixels. Sorry, we can't break
|
|
1345 Xt conventions here.)
|
|
1346 3) Else, assume a size of 64x12. (This is somewhat arbitrary, but
|
|
1347 it's unlikely that a size of 80x40 is desirable because we're probably
|
|
1348 inside of a dialog box.)
|
|
1349
|
|
1350 Set the widget's x, y, height, and width as determined. Don't set the
|
|
1351 top-level container widget, because we don't necessarily know what it
|
|
1352 is. (Assume it is smart and pays attention to our values.)
|
|
1353 */
|
|
1354
|
|
1355 if (!FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1356 {
|
|
1357 XtVaGetValues (ew, XtNgeometry, &ew_geom, 0);
|
|
1358 if (ew_geom)
|
|
1359 frame_flags = XParseGeometry (ew_geom, &frame_x, &frame_y,
|
|
1360 &frame_w, &frame_h);
|
|
1361 if (! (frame_flags & (WidthValue | HeightValue)))
|
|
1362 {
|
|
1363 XtVaGetValues (ew, XtNwidth, &frame_w,
|
|
1364 XtNheight, &frame_h, 0);
|
|
1365 if (!frame_w && !frame_h)
|
|
1366 {
|
|
1367 frame_w = 64;
|
|
1368 frame_h = 12;
|
|
1369 frame_flags |= WidthValue | HeightValue;
|
|
1370 }
|
|
1371 }
|
|
1372 if (frame_flags & (WidthValue | HeightValue))
|
|
1373 EmacsFrameSetCharSize (ew, frame_w, frame_h);
|
|
1374 if (frame_flags & (XValue | YValue))
|
|
1375 {
|
|
1376 XtVaGetValues (ew, XtNwidth, &frame_w,
|
|
1377 XtNheight, &frame_h, 0);
|
|
1378 if (frame_flags & XNegative)
|
|
1379 frame_x += frame_w;
|
|
1380 if (frame_flags & YNegative)
|
|
1381 frame_y += frame_h;
|
|
1382 XtVaSetValues (ew, XtNx, frame_x, XtNy, frame_y, 0);
|
|
1383 }
|
|
1384 return;
|
|
1385 }
|
|
1386 #endif
|
|
1387
|
|
1388 /* OK, we're a top-level shell. */
|
|
1389
|
|
1390 if (!XtIsWMShell (wmshell))
|
|
1391 abort ();
|
|
1392
|
|
1393 /* If the EmacsFrame doesn't have a geometry but the shell does,
|
|
1394 treat that as the geometry of the frame. (Is this bogus?
|
|
1395 I'm not sure.) */
|
|
1396
|
|
1397 XtVaGetValues (ew, XtNgeometry, &ew_geom, 0);
|
|
1398 if (!ew_geom)
|
|
1399 {
|
|
1400 XtVaGetValues (wmshell, XtNgeometry, &geom, 0);
|
|
1401 if (geom)
|
|
1402 {
|
|
1403 ew_geom = geom;
|
|
1404 XtVaSetValues (ew, XtNgeometry, ew_geom, 0);
|
|
1405 }
|
|
1406 }
|
|
1407
|
|
1408 /* If the Shell is iconic, then the EmacsFrame is iconic. (Is
|
|
1409 this bogus? I'm not sure.) */
|
|
1410 XtVaGetValues (ew, XtNiconic, &ew_iconic_p, 0);
|
|
1411 if (!ew_iconic_p)
|
|
1412 {
|
|
1413 XtVaGetValues (wmshell, XtNiconic, &iconic_p, 0);
|
|
1414 if (iconic_p)
|
|
1415 {
|
|
1416 ew_iconic_p = iconic_p;
|
|
1417 XtVaSetValues (ew, XtNiconic, iconic_p, 0);
|
|
1418 }
|
|
1419 }
|
|
1420
|
|
1421 XtVaGetValues (app_shell, XtNgeometry, &geom, 0);
|
|
1422 if (geom)
|
|
1423 app_flags = XParseGeometry (geom, &app_x, &app_y, &app_w, &app_h);
|
|
1424
|
|
1425 if (ew_geom)
|
|
1426 frame_flags = XParseGeometry (ew_geom, &frame_x, &frame_y,
|
|
1427 &frame_w, &frame_h);
|
|
1428
|
|
1429 if (first_x_frame_p (f))
|
|
1430 {
|
|
1431 /* If this is the first frame created:
|
|
1432 ====================================
|
|
1433
|
|
1434 - Use the ApplicationShell's size/position, if specified.
|
|
1435 (This is "Emacs.geometry", or the "-geometry" command line arg.)
|
|
1436 - Else use the EmacsFrame's size/position.
|
|
1437 (This is "*FRAME-NAME.geometry")
|
|
1438
|
|
1439 - If the AppShell is iconic, the frame should be iconic.
|
|
1440
|
|
1441 AppShell comes first so that -geometry always applies to the first
|
|
1442 frame created, even if there is an "every frame" entry in the
|
|
1443 resource database.
|
|
1444 */
|
|
1445 if (app_flags & (XValue | YValue))
|
|
1446 {
|
|
1447 x = app_x; y = app_y;
|
|
1448 flags |= (app_flags & (XValue | YValue | XNegative | YNegative));
|
|
1449 }
|
|
1450 else if (frame_flags & (XValue | YValue))
|
|
1451 {
|
|
1452 x = frame_x; y = frame_y;
|
|
1453 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative));
|
|
1454 }
|
|
1455
|
|
1456 if (app_flags & (WidthValue | HeightValue))
|
|
1457 {
|
|
1458 w = app_w; h = app_h;
|
|
1459 flags |= (app_flags & (WidthValue | HeightValue));
|
|
1460 }
|
|
1461 else if (frame_flags & (WidthValue | HeightValue))
|
|
1462 {
|
|
1463 w = frame_w; h = frame_h;
|
|
1464 flags |= (frame_flags & (WidthValue | HeightValue));
|
|
1465 }
|
|
1466
|
|
1467 /* If the AppShell is iconic, then the EmacsFrame is iconic. */
|
|
1468 if (!ew_iconic_p)
|
|
1469 {
|
|
1470 XtVaGetValues (app_shell, XtNiconic, &iconic_p, 0);
|
|
1471 if (iconic_p)
|
|
1472 {
|
|
1473 ew_iconic_p = iconic_p;
|
|
1474 XtVaSetValues (ew, XtNiconic, iconic_p, 0);
|
|
1475 }
|
|
1476 }
|
|
1477 }
|
|
1478 else
|
|
1479 {
|
|
1480 /* If this is not the first frame created:
|
|
1481 ========================================
|
|
1482
|
|
1483 - use the EmacsFrame's size/position if specified
|
|
1484 - Otherwise, use the ApplicationShell's size, but not position.
|
|
1485
|
|
1486 So that means that one can specify the position of the first frame
|
|
1487 with "Emacs.geometry" or `-geometry'; but can only specify the
|
|
1488 position of subsequent frames with "*FRAME-NAME.geometry".
|
|
1489
|
|
1490 AppShell comes second so that -geometry does not apply to subsequent
|
|
1491 frames when there is an "every frame" entry in the resource db,
|
|
1492 but does apply to the first frame.
|
|
1493 */
|
|
1494 if (frame_flags & (XValue | YValue))
|
|
1495 {
|
|
1496 x = frame_x; y = frame_y;
|
|
1497 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative));
|
|
1498 }
|
|
1499
|
|
1500 if (frame_flags & (WidthValue | HeightValue))
|
|
1501 {
|
|
1502 w = frame_w; h = frame_h;
|
|
1503 flags |= (frame_flags & (WidthValue | HeightValue));
|
|
1504 }
|
|
1505 else if (app_flags & (WidthValue | HeightValue))
|
|
1506 {
|
|
1507 w = app_w;
|
|
1508 h = app_h;
|
|
1509 flags |= (app_flags & (WidthValue | HeightValue));
|
|
1510 }
|
|
1511 }
|
|
1512
|
|
1513 x_set_initial_frame_size (f, flags, x, y, w, h);
|
|
1514 }
|
|
1515
|
|
1516 static void
|
|
1517 x_get_layout_sizes (struct frame *f, Dimension *topbreadth)
|
|
1518 {
|
|
1519 int i;
|
|
1520
|
|
1521 /* compute height of all top-area widgets */
|
|
1522 for (i=0, *topbreadth = 0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
1523 {
|
|
1524 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
1525 if (wid && XtIsManaged (wid))
|
|
1526 *topbreadth += wid->core.height + 2*wid->core.border_width;
|
|
1527 }
|
|
1528 }
|
|
1529
|
|
1530 static void
|
|
1531 x_layout_widgets (Widget w, XtPointer client_data, XtPointer call_data)
|
|
1532 {
|
|
1533 struct frame *f = (struct frame *) client_data;
|
|
1534 EmacsManagerResizeStruct *emst = (EmacsManagerResizeStruct *) call_data;
|
|
1535 Dimension width = emst->width;
|
|
1536 Dimension height = emst->height;
|
|
1537 Widget text = FRAME_X_TEXT_WIDGET (f);
|
|
1538 Dimension textbord = text->core.border_width;
|
|
1539 Dimension topbreadth;
|
|
1540 Position text_x = 0, text_y = 0;
|
|
1541 int i;
|
|
1542
|
|
1543 x_get_layout_sizes (f, &topbreadth);
|
|
1544
|
|
1545 /* first the menubar and psheets ... */
|
|
1546 for (i=0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
1547 {
|
|
1548 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
1549 if (wid && XtIsManaged (wid))
|
|
1550 {
|
|
1551 Dimension bord = wid->core.border_width;
|
|
1552 XtConfigureWidget (wid, 0, text_y,
|
|
1553 width - 2*bord, wid->core.height,
|
|
1554 bord);
|
|
1555 text_y += wid->core.height + 2*bord;
|
|
1556 }
|
|
1557 }
|
|
1558
|
|
1559 #ifdef HAVE_SCROLLBARS
|
|
1560 {
|
|
1561 /* The scrollbar positioning is completely handled by redisplay. We
|
|
1562 just need to know which sides they are supposed to go on. */
|
|
1563 unsigned char scrollbar_placement;
|
|
1564 XtVaGetValues (text, XtNscrollBarPlacement, &scrollbar_placement, 0);
|
|
1565 f->scrollbar_on_left = (scrollbar_placement == XtTOP_LEFT ||
|
|
1566 scrollbar_placement == XtBOTTOM_LEFT);
|
|
1567 f->scrollbar_on_top = (scrollbar_placement == XtTOP_LEFT ||
|
|
1568 scrollbar_placement == XtTOP_RIGHT);
|
|
1569 f->scrollbar_y_offset = topbreadth + textbord;
|
|
1570 }
|
20
|
1571 #endif /* HAVE_SCROLLBARS */
|
0
|
1572
|
|
1573 /* finally the text area */
|
|
1574 XtConfigureWidget (text, text_x, text_y,
|
|
1575 width - 2*textbord,
|
|
1576 height - text_y - 2*textbord,
|
|
1577 textbord);
|
|
1578 }
|
|
1579
|
|
1580 static void
|
|
1581 x_do_query_geometry (Widget w, XtPointer client_data, XtPointer call_data)
|
|
1582 {
|
|
1583 struct frame *f = (struct frame *) client_data;
|
|
1584 EmacsManagerQueryGeometryStruct *emst =
|
|
1585 (EmacsManagerQueryGeometryStruct *) call_data;
|
|
1586 Widget text = FRAME_X_TEXT_WIDGET (f);
|
|
1587 Dimension textbord = text->core.border_width;
|
|
1588 Dimension topbreadth;
|
|
1589 XtWidgetGeometry req, repl;
|
|
1590 int mask = emst->request_mode & (CWWidth | CWHeight);
|
|
1591
|
|
1592 x_get_layout_sizes (f, &topbreadth);
|
|
1593
|
20
|
1594 /* Strip away menubar from suggested size, and ask the text widget
|
|
1595 what size it wants to be. */
|
0
|
1596 req.request_mode = mask;
|
|
1597 if (mask & CWWidth)
|
|
1598 req.width = emst->proposed_width - 2*textbord;
|
|
1599 if (mask & CWHeight)
|
|
1600 req.height = emst->proposed_height - topbreadth - 2*textbord;
|
|
1601 XtQueryGeometry (text, &req, &repl);
|
|
1602
|
|
1603 /* Now add the menubar back again */
|
20
|
1604 emst->proposed_width = repl.width + 2*textbord;
|
0
|
1605 emst->proposed_height = repl.height + topbreadth + 2*textbord;
|
|
1606 }
|
|
1607
|
|
1608 /* Creates the widgets for a frame.
|
|
1609 lisp_window_id is a Lisp description of an X window or Xt
|
|
1610 widget to parse.
|
|
1611
|
|
1612 This function does not create or map the windows. (That is
|
|
1613 done by x_popup_frame().)
|
|
1614 */
|
|
1615 static void
|
|
1616 x_create_widgets (struct frame *f, Lisp_Object lisp_window_id,
|
|
1617 Lisp_Object parent)
|
|
1618 {
|
|
1619 struct device *d = XDEVICE (f->device);
|
|
1620 #ifdef EXTERNAL_WIDGET
|
|
1621 Window window_id = 0;
|
|
1622 #endif
|
|
1623 CONST char *name;
|
|
1624 Arg av [25];
|
|
1625 int ac = 0;
|
|
1626 Widget text, container, shell;
|
|
1627 Widget parentwid = 0;
|
|
1628 #ifdef HAVE_MENUBARS
|
|
1629 int menubar_visible;
|
|
1630 Widget menubar;
|
|
1631 #endif
|
|
1632
|
|
1633 if (STRINGP (f->name))
|
|
1634 GET_C_STRING_CTEXT_DATA_ALLOCA (f->name, name);
|
|
1635 else
|
|
1636 name = "emacs";
|
|
1637
|
|
1638 /* The widget hierarchy is
|
|
1639
|
|
1640 argv[0] shell pane FRAME-NAME
|
|
1641 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1642
|
|
1643 (the type of the shell is ExternalShell if this frame is running
|
|
1644 in another client's window)
|
|
1645
|
|
1646 However the EmacsShell widget has WM_CLASS of FRAME-NAME/Emacs.
|
|
1647 Normally such shells have name/class shellname/appclass, which in this
|
|
1648 case would be "shell/Emacs" instead of "frame-name/Emacs". We could
|
|
1649 also get around this by naming the shell "frame-name", but that would
|
|
1650 be confusing because the text area (the EmacsFrame widget inferior of
|
|
1651 the shell) is also called that. So we just set the WM_CLASS property.
|
|
1652 */
|
|
1653
|
|
1654 #ifndef EXTERNAL_WIDGET
|
|
1655 if (!NILP (lisp_window_id))
|
|
1656 error ("support for external widgets was not enabled at compile-time");
|
|
1657 #else
|
|
1658 if (!NILP (lisp_window_id))
|
|
1659 {
|
|
1660 char *string;
|
|
1661
|
|
1662 CHECK_STRING (lisp_window_id);
|
70
|
1663 string = (char *) (XSTRING_DATA (lisp_window_id));
|
0
|
1664 if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))
|
|
1665 sscanf (string+2, "%lxu", &window_id);
|
|
1666 #if 0
|
|
1667 else if (string[0] == 'w')
|
|
1668 {
|
|
1669 sscanf (string+1, "%x", &parent_widget);
|
|
1670 if (parent_widget)
|
|
1671 window_id = XtWindow (parent_widget);
|
|
1672 }
|
|
1673 #endif
|
|
1674 else
|
|
1675 sscanf (string, "%lu", &window_id);
|
|
1676 if (!is_valid_window (window_id, d))
|
|
1677 error ("Invalid window %lu", (unsigned long) window_id);
|
|
1678 FRAME_X_EXTERNAL_WINDOW_P (f) = 1;
|
|
1679 } else
|
|
1680 #endif /* EXTERNAL_WIDGET */
|
|
1681 FRAME_X_TOP_LEVEL_FRAME_P (f) = 1;
|
|
1682
|
|
1683 ac = 0;
|
|
1684 XtSetArg (av[ac], XtNallowShellResize, True); ac++;
|
|
1685 #ifdef LWLIB_USES_MOTIF
|
|
1686 /* Motif sucks beans. Without this in here, it will delete the window
|
|
1687 out from under us when it receives a WM_DESTROY_WINDOW message
|
|
1688 from the WM. */
|
|
1689 XtSetArg (av[ac], XmNdeleteResponse, XmDO_NOTHING); ac++;
|
|
1690 #endif
|
|
1691
|
|
1692 #ifdef EXTERNAL_WIDGET
|
|
1693 if (window_id)
|
|
1694 {
|
|
1695 XtSetArg (av[ac], XtNwindow, window_id); ac++;
|
|
1696 }
|
|
1697 else
|
20
|
1698 #endif /* EXTERNAL_WIDGET */
|
0
|
1699 {
|
|
1700 XtSetArg (av[ac], XtNinput, True); ac++;
|
2
|
1701 XtSetArg (av[ac], (String) XtNminWidthCells, 10); ac++;
|
|
1702 XtSetArg (av[ac], (String) XtNminHeightCells, 1); ac++;
|
0
|
1703 }
|
|
1704
|
|
1705 if (!NILP (parent))
|
|
1706 {
|
|
1707 parentwid = FRAME_X_SHELL_WIDGET (XFRAME (parent));
|
|
1708 XtSetArg (av[ac], XtNtransientFor, parentwid); ac++;
|
|
1709 }
|
|
1710
|
|
1711 shell = XtCreatePopupShell ("shell",
|
|
1712 (
|
|
1713 #ifdef EXTERNAL_WIDGET
|
|
1714 window_id ? externalShellWidgetClass :
|
|
1715 #endif
|
|
1716 parentwid ? transientEmacsShellWidgetClass :
|
|
1717 topLevelEmacsShellWidgetClass
|
|
1718 ),
|
|
1719 parentwid ? parentwid :
|
|
1720 DEVICE_XT_APP_SHELL (d),
|
|
1721 av, ac);
|
|
1722 FRAME_X_SHELL_WIDGET (f) = shell;
|
|
1723 maybe_set_frame_title_format (shell);
|
|
1724
|
|
1725 /* Create the manager widget */
|
|
1726 container = XtVaCreateWidget ("container",
|
|
1727 emacsManagerWidgetClass,
|
|
1728 shell, 0);
|
|
1729 FRAME_X_CONTAINER_WIDGET (f) = container;
|
|
1730 XtAddCallback (container, XtNresizeCallback, x_layout_widgets,
|
|
1731 (XtPointer) f);
|
|
1732 XtAddCallback (container, XtNqueryGeometryCallback, x_do_query_geometry,
|
|
1733 (XtPointer) f);
|
|
1734
|
|
1735 /* Create the text area */
|
|
1736 ac = 0;
|
|
1737 XtSetArg (av[ac], XtNborderWidth, 0); ac++; /* should this be settable? */
|
2
|
1738 XtSetArg (av[ac], (String) XtNemacsFrame, f); ac++;
|
0
|
1739 text = XtCreateWidget (name,
|
|
1740 emacsFrameClass,
|
|
1741 container, av, ac);
|
|
1742 FRAME_X_TEXT_WIDGET (f) = text;
|
|
1743
|
|
1744 #ifdef HAVE_MENUBARS
|
|
1745 /* Create the initial menubar widget. */
|
|
1746 menubar_visible = x_initialize_frame_menubar (f);
|
|
1747 FRAME_X_TOP_WIDGETS (f)[0] = menubar = FRAME_X_MENUBAR_WIDGET (f);
|
|
1748 FRAME_X_NUM_TOP_WIDGETS (f) = 1;
|
|
1749
|
|
1750 if (menubar_visible)
|
|
1751 XtManageChild (menubar);
|
20
|
1752 #endif /* HAVE_MENUBARS */
|
0
|
1753 XtManageChild (text);
|
|
1754 XtManageChild (container);
|
|
1755 }
|
|
1756
|
|
1757 /* We used to call XtPopup() in x_popup_frame, but that doesn't give
|
|
1758 you control over whether the widget is initially mapped or not
|
|
1759 because XtPopup() makes an unconditional call to XMapRaised().
|
|
1760 Boy, those Xt designers were clever.
|
|
1761
|
|
1762 When we first removed it we only kept the XtRealizeWidget call in
|
|
1763 XtPopup. For everything except HP's that was enough. For HP's,
|
|
1764 though, the failure to call the popup callbacks resulted in XEmacs
|
|
1765 not accepting any input. Bizarre but true. Stupid but true.
|
|
1766
|
|
1767 So, in case there are any other gotches floating out there along
|
|
1768 the same lines I've duplicated the majority of XtPopup here. It
|
|
1769 assumes no grabs and that the widget is not already popped up, both
|
|
1770 valid assumptions for the one place this is called from. */
|
|
1771 static void
|
|
1772 xemacs_XtPopup (Widget widget)
|
|
1773 {
|
|
1774 ShellWidget shell_widget = (ShellWidget) widget;
|
|
1775 XtGrabKind call_data = XtGrabNone;
|
|
1776
|
|
1777 XtCallCallbacks (widget, XtNpopupCallback, (XtPointer)&call_data);
|
|
1778
|
|
1779 shell_widget->shell.popped_up = TRUE;
|
|
1780 shell_widget->shell.grab_kind = XtGrabNone;
|
|
1781 shell_widget->shell.spring_loaded = False;
|
|
1782
|
|
1783 if (shell_widget->shell.create_popup_child_proc != NULL)
|
|
1784 (*(shell_widget->shell.create_popup_child_proc))(widget);
|
|
1785
|
|
1786 /* The XtVaSetValues below are not in XtPopup menu. We just want to
|
|
1787 make absolutely sure... */
|
|
1788 XtVaSetValues (widget, XtNmappedWhenManaged, False, NULL);
|
|
1789 XtRealizeWidget (widget);
|
|
1790 XtVaSetValues (widget, XtNmappedWhenManaged, True, NULL);
|
|
1791 }
|
|
1792
|
|
1793 #ifdef HAVE_CDE
|
|
1794 /* Does this have to be non-automatic? */
|
|
1795 /* hack frame to respond to dnd messages */
|
|
1796 static XtCallbackRec dnd_transfer_cb_rec[2];
|
20
|
1797 #endif /* HAVE_CDE */
|
0
|
1798
|
|
1799 /* create the windows for the specified frame and display them.
|
|
1800 Note that the widgets have already been created, and any
|
|
1801 necessary geometry calculations have already been done. */
|
|
1802 static void
|
|
1803 x_popup_frame (struct frame *f)
|
|
1804 {
|
|
1805 Widget shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
1806 Widget frame_widget = FRAME_X_TEXT_WIDGET (f);
|
|
1807 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
1808
|
|
1809 /* Before mapping the window, make sure that the WMShell's notion of
|
|
1810 whether it should be iconified is synchronized with the EmacsFrame's
|
|
1811 notion.
|
|
1812 */
|
|
1813 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1814 x_wm_set_shell_iconic_p (shell_widget,
|
|
1815 ((EmacsFrame) frame_widget)
|
|
1816 ->emacs_frame.iconic);
|
|
1817
|
|
1818 xemacs_XtPopup (shell_widget);
|
|
1819
|
|
1820 if (!((EmacsFrame) frame_widget)->emacs_frame.initially_unmapped)
|
|
1821 XtMapWidget (shell_widget);
|
|
1822 else
|
|
1823 {
|
|
1824 /* We may have set f->visible to 1 in x_init_frame(), so undo
|
|
1825 that now. */
|
|
1826 FRAME_X_TOTALLY_VISIBLE_P (f) = 0;
|
|
1827 f->visible = 0;
|
|
1828 }
|
|
1829
|
|
1830 #ifdef EXTERNAL_WIDGET
|
|
1831 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1832 ExternalShellReady (shell_widget, XtWindow (frame_widget), KeyPressMask);
|
|
1833 else
|
|
1834 #endif
|
|
1835 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1836 {
|
|
1837 /* tell the window manager about us. */
|
|
1838 x_wm_store_class_hints (shell_widget, XtName (frame_widget));
|
|
1839 x_wm_maybe_store_wm_command (f);
|
|
1840 x_wm_hack_wm_protocols (shell_widget);
|
|
1841 }
|
|
1842
|
70
|
1843 #ifdef HAVE_XIM
|
|
1844 XIM_init_frame (f);
|
|
1845 #endif /* HAVE_XIM */
|
|
1846
|
0
|
1847 #ifdef HACK_EDITRES
|
|
1848 /* Allow XEmacs to respond to EditRes requests. See the O'Reilly Xt */
|
|
1849 /* Instrinsics Programming Manual, Motif Edition, Aug 1993, Sect 14.14, */
|
|
1850 /* pp. 483-493. */
|
|
1851 XtAddEventHandler (shell_widget, /* the shell widget in question */
|
|
1852 (EventMask) NoEventMask,/* OR with existing mask */
|
|
1853 True, /* called on non-maskable events? */
|
|
1854 _XEditResCheckMessages, /* the handler */
|
|
1855 NULL);
|
20
|
1856 #endif /* HACK_EDITRES */
|
0
|
1857
|
|
1858 #ifdef HAVE_CDE
|
|
1859 {
|
|
1860 dnd_transfer_cb_rec[0].callback = x_cde_transfer_callback;
|
|
1861 dnd_transfer_cb_rec[0].closure = (XtPointer) f;
|
|
1862 dnd_transfer_cb_rec[1].callback = NULL;
|
|
1863 dnd_transfer_cb_rec[1].closure = NULL;
|
|
1864
|
|
1865 DtDndVaDropRegister (FRAME_X_TEXT_WIDGET (f),
|
2
|
1866 DtDND_FILENAME_TRANSFER | DtDND_BUFFER_TRANSFER,
|
|
1867 XmDROP_COPY, dnd_transfer_cb_rec,
|
|
1868 DtNtextIsBuffer, True,
|
0
|
1869 DtNpreserveRegistration, False,
|
|
1870 NULL);
|
|
1871 }
|
20
|
1872 #endif /* HAVE_CDE */
|
0
|
1873
|
2
|
1874 #ifdef HAVE_OFFIX_DND
|
|
1875 {
|
|
1876 DndInitialize (FRAME_X_SHELL_WIDGET (f));
|
|
1877 DndRegisterDropWidget (FRAME_X_TEXT_WIDGET (f),
|
|
1878 x_offix_drop_event_handler,
|
|
1879 (XtPointer) f);
|
|
1880
|
|
1881 }
|
|
1882 #endif
|
|
1883
|
0
|
1884 /* Do a stupid property change to force the server to generate a
|
|
1885 propertyNotify event so that the event_stream server timestamp will
|
|
1886 be initialized to something relevant to the time we created the window.
|
|
1887 */
|
|
1888 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
|
|
1889 DEVICE_XATOM_WM_PROTOCOLS (d), XA_ATOM, 32, PropModeAppend,
|
|
1890 (unsigned char*) NULL, 0);
|
|
1891
|
|
1892 x_send_synthetic_mouse_event (f);
|
|
1893 }
|
|
1894
|
|
1895 static void
|
|
1896 allocate_x_frame_struct (struct frame *f)
|
|
1897 {
|
|
1898 /* zero out all slots. */
|
|
1899 f->frame_data = malloc_type_and_zero (struct x_frame);
|
|
1900
|
|
1901 /* yeah, except the lisp ones */
|
|
1902 FRAME_X_ICON_PIXMAP (f) = Qnil;
|
|
1903 FRAME_X_ICON_PIXMAP_MASK (f) = Qnil;
|
|
1904 #ifdef ENERGIZE
|
|
1905 FRAME_X_CURRENT_PSHEET_BUFFER (f) = Qnil;
|
|
1906 FRAME_X_DESIRED_PSHEET_BUFFER (f) = Qnil;
|
|
1907 #endif
|
|
1908 }
|
|
1909
|
|
1910
|
|
1911 /************************************************************************/
|
|
1912 /* Lisp functions */
|
|
1913 /************************************************************************/
|
|
1914
|
|
1915 static void
|
|
1916 x_init_frame_1 (struct frame *f, Lisp_Object props)
|
|
1917 {
|
|
1918 /* This function can GC */
|
|
1919 Lisp_Object device = FRAME_DEVICE (f);
|
|
1920 struct device *d = XDEVICE (device);
|
|
1921 Lisp_Object lisp_window_id;
|
|
1922 Lisp_Object popup;
|
|
1923
|
|
1924 lisp_window_id = Fplist_get (props, Qwindow_id, Qnil);
|
|
1925 popup = Fplist_get (props, Qpopup, Qnil);
|
|
1926 if (!NILP (popup))
|
|
1927 {
|
|
1928 if (EQ (popup, Qt))
|
|
1929 popup = Fselected_frame (device);
|
|
1930 CHECK_LIVE_FRAME (popup);
|
|
1931 if (!EQ (device, FRAME_DEVICE (XFRAME (popup))))
|
|
1932 signal_simple_error_2 ("Parent must be on same device as frame",
|
|
1933 device, popup);
|
|
1934 }
|
|
1935
|
|
1936 if (NILP (DEVICE_SELECTED_FRAME (d)))
|
|
1937 {
|
|
1938 /* This means that this is the first frame on the device.
|
|
1939 So short-ciruit the delay in processing the initial MapNotify
|
|
1940 event so that output on the first frame shows up right
|
|
1941 away... */
|
|
1942 f->visible = 1;
|
|
1943 }
|
|
1944
|
|
1945 allocate_x_frame_struct (f);
|
|
1946 x_create_widgets (f, lisp_window_id, popup);
|
|
1947 }
|
|
1948
|
|
1949 static void
|
|
1950 x_init_frame_2 (struct frame *f, Lisp_Object props)
|
|
1951 {
|
|
1952 /* Set up the values of the widget/frame. A case could be made for putting
|
|
1953 this inside of the widget's initialize method. */
|
|
1954
|
|
1955 update_frame_face_values (f);
|
|
1956 x_initialize_frame_size (f);
|
|
1957 update_frame_title (f);
|
|
1958 }
|
|
1959
|
|
1960 static void
|
|
1961 x_init_frame_3 (struct frame *f)
|
|
1962 {
|
|
1963 /* Pop up the frame. */
|
|
1964
|
|
1965 x_popup_frame (f);
|
|
1966 }
|
|
1967
|
|
1968 static void
|
|
1969 x_mark_frame (struct frame *f, void (*markobj) (Lisp_Object))
|
|
1970 {
|
|
1971 ((markobj) (FRAME_X_ICON_PIXMAP (f)));
|
|
1972 ((markobj) (FRAME_X_ICON_PIXMAP_MASK (f)));
|
|
1973 #ifdef ENERGIZE
|
|
1974 ((markobj) (FRAME_X_CURRENT_PSHEET_BUFFER (f)));
|
|
1975 ((markobj) (FRAME_X_DESIRED_PSHEET_BUFFER (f)));
|
|
1976 #endif
|
|
1977 }
|
|
1978
|
|
1979 static void
|
|
1980 x_set_frame_icon (struct frame *f)
|
|
1981 {
|
|
1982 Pixmap x_pixmap, x_mask;
|
|
1983
|
|
1984 if (IMAGE_INSTANCEP (f->icon)
|
|
1985 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (f->icon)))
|
|
1986 {
|
|
1987 x_pixmap = XIMAGE_INSTANCE_X_PIXMAP (f->icon);
|
|
1988 x_mask = XIMAGE_INSTANCE_X_MASK (f->icon);
|
|
1989 }
|
|
1990 else
|
|
1991 {
|
|
1992 x_pixmap = 0;
|
|
1993 x_mask = 0;
|
|
1994 }
|
|
1995
|
|
1996 /* Store the X data into the widget. */
|
|
1997 {
|
|
1998 Arg av [10];
|
|
1999 int ac = 0;
|
|
2000 XtSetArg (av [ac], XtNiconPixmap, x_pixmap); ac++;
|
|
2001 XtSetArg (av [ac], XtNiconMask, x_mask); ac++;
|
|
2002 XtSetValues (FRAME_X_SHELL_WIDGET (f), av, ac);
|
|
2003 }
|
|
2004 }
|
|
2005
|
|
2006 static void
|
|
2007 x_set_frame_pointer (struct frame *f)
|
|
2008 {
|
|
2009 XDefineCursor (XtDisplay (FRAME_X_TEXT_WIDGET (f)),
|
|
2010 XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
2011 XIMAGE_INSTANCE_X_CURSOR (f->pointer));
|
|
2012 XSync (XtDisplay (FRAME_X_TEXT_WIDGET (f)), 0);
|
|
2013 }
|
|
2014
|
|
2015 static Lisp_Object
|
|
2016 x_get_frame_parent (struct frame *f)
|
|
2017 {
|
|
2018 Widget parentwid = 0;
|
|
2019 Arg av[1];
|
|
2020
|
|
2021 XtSetArg (av[0], XtNtransientFor, &parentwid);
|
|
2022 XtGetValues (FRAME_X_SHELL_WIDGET (f), av, 1);
|
|
2023 /* find the frame whose wid is parentwid */
|
|
2024 if (parentwid)
|
|
2025 {
|
|
2026 Lisp_Object frmcons;
|
|
2027 DEVICE_FRAME_LOOP (frmcons, XDEVICE (FRAME_DEVICE (f)))
|
|
2028 {
|
|
2029 Lisp_Object frame = XCAR (frmcons);
|
|
2030 if (FRAME_X_SHELL_WIDGET (XFRAME (frame)) == parentwid)
|
|
2031 return frame;
|
|
2032 }
|
|
2033 }
|
|
2034 return Qnil;
|
|
2035 }
|
|
2036
|
20
|
2037 DEFUN ("x-window-id", Fx_window_id, 0, 1, 0, /*
|
0
|
2038 Get the ID of the X11 window.
|
|
2039 This gives us a chance to manipulate the Emacs window from within a
|
|
2040 different program. Since the ID is an unsigned long, we return it as
|
|
2041 a string.
|
20
|
2042 */
|
|
2043 (frame))
|
0
|
2044 {
|
|
2045 char str[255];
|
|
2046 struct frame *f = decode_x_frame (frame);
|
|
2047
|
|
2048 sprintf (str, "%lu", XtWindow (FRAME_X_TEXT_WIDGET (f)));
|
|
2049 return build_string (str);
|
|
2050 }
|
|
2051
|
|
2052
|
|
2053 /************************************************************************/
|
|
2054 /* manipulating the X window */
|
|
2055 /************************************************************************/
|
|
2056
|
|
2057 static void
|
|
2058 x_set_frame_position (struct frame *f, int xoff, int yoff)
|
|
2059 {
|
|
2060 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
2061 Display *dpy = XtDisplay (w);
|
20
|
2062 Dimension frame_w = DisplayWidth (dpy, DefaultScreen (dpy));
|
0
|
2063 Dimension frame_h = DisplayHeight (dpy, DefaultScreen (dpy));
|
|
2064 Dimension shell_w, shell_h, shell_bord;
|
|
2065 int win_gravity;
|
|
2066
|
|
2067 XtVaGetValues (w,
|
20
|
2068 XtNwidth, &shell_w,
|
|
2069 XtNheight, &shell_h,
|
0
|
2070 XtNborderWidth, &shell_bord,
|
|
2071 0);
|
|
2072
|
|
2073 win_gravity =
|
|
2074 xoff >= 0 && yoff >= 0 ? NorthWestGravity :
|
|
2075 xoff >= 0 ? SouthWestGravity :
|
|
2076 yoff >= 0 ? NorthEastGravity :
|
|
2077 SouthEastGravity;
|
|
2078 if (xoff < 0)
|
|
2079 xoff += frame_w - shell_w - 2*shell_bord;
|
|
2080 if (yoff < 0)
|
|
2081 yoff += frame_h - shell_h - 2*shell_bord;
|
|
2082
|
|
2083 /* Update the hints so that, if this window is currently iconified, it will
|
|
2084 come back at the right place. We can't look at s->visible to determine
|
|
2085 whether it is iconified because it might not be up-to-date yet (the queue
|
|
2086 might not be processed). */
|
|
2087 XtVaSetValues (w,
|
|
2088 XtNwinGravity, win_gravity,
|
|
2089 XtNx, xoff,
|
|
2090 XtNy, yoff,
|
|
2091 0);
|
70
|
2092
|
0
|
2093 /* Sometimes you will find that
|
|
2094
|
|
2095 (set-frame-position (selected-frame) -50 -50)
|
|
2096
|
20
|
2097 doesn't put the frame where you expect it to: i.e. it's closer to
|
|
2098 the lower-right corner than it should be, and it appears that the
|
|
2099 size of the WM decorations was not taken into account. This is
|
|
2100 *not* a problem with this function. Both mwm and twm have bugs
|
|
2101 in handling this situation. (mwm ignores the window gravity and
|
|
2102 always assumes NorthWest, except the first time you map the
|
|
2103 window; twm gets things almost right, but forgets to account for
|
|
2104 the border width of the top-level window.) This function does
|
|
2105 what it's supposed to according to the ICCCM, and I'm not about
|
|
2106 to hack around window-manager bugs. */
|
0
|
2107
|
|
2108 #if 0
|
|
2109 /* This is not necessary under either mwm or twm */
|
|
2110 x_wm_mark_shell_position_user_specified (w);
|
|
2111 #endif
|
|
2112 }
|
|
2113
|
|
2114 /* Call this to change the size of frame S's x-window. */
|
|
2115
|
|
2116 static void
|
|
2117 x_set_frame_size (struct frame *f, int cols, int rows)
|
|
2118 {
|
|
2119 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), cols, rows);
|
|
2120 #if 0
|
|
2121 /* this is not correct. x_set_frame_size() is called from
|
|
2122 Fset_frame_size(), which may or may not have been called
|
|
2123 by the user (e.g. update_EmacsFrame() calls it when the font
|
|
2124 changes). For now, don't bother with getting this right. */
|
|
2125 x_wm_mark_shell_size_user_specified (FRAME_X_SHELL_WIDGET (f));
|
|
2126 #endif
|
|
2127 }
|
|
2128
|
|
2129 static void
|
|
2130 x_set_mouse_position (struct window *w, int x, int y)
|
|
2131 {
|
|
2132 struct frame *f = XFRAME (w->frame);
|
|
2133
|
|
2134 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2135 XWarpPointer (display, None, XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
2136 0, 0, 0, 0, w->pixel_left + x, w->pixel_top + y);
|
|
2137 }
|
|
2138
|
|
2139 static int
|
|
2140 x_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y)
|
|
2141 {
|
|
2142 Display *display = DEVICE_X_DISPLAY (d);
|
|
2143 Window child_window;
|
|
2144 Window root_window;
|
|
2145 Window win;
|
|
2146 int root_x, root_y;
|
|
2147 int win_x, win_y;
|
|
2148 unsigned int keys_and_buttons;
|
|
2149 struct frame *f;
|
|
2150
|
|
2151 if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
|
|
2152 &root_window, &child_window, &root_x, &root_y,
|
|
2153 &win_x, &win_y, &keys_and_buttons) == False)
|
|
2154 return 0;
|
|
2155
|
|
2156 if (child_window == None)
|
|
2157 return 0; /* not over any window. */
|
|
2158
|
|
2159 while (1)
|
|
2160 {
|
|
2161 win = child_window;
|
|
2162 if (XTranslateCoordinates (display, root_window, win, root_x, root_y,
|
|
2163 &win_x, &win_y, &child_window) == False)
|
|
2164 /* Huh? */
|
|
2165 return 0;
|
|
2166
|
|
2167 if (child_window == None)
|
|
2168 break;
|
|
2169 }
|
|
2170
|
|
2171 /* At this point, win is the innermost window containing the pointer
|
|
2172 and win_x and win_y are the coordinates of that window. */
|
|
2173 f = x_any_window_to_frame (d, win);
|
|
2174 if (!f)
|
|
2175 return 0;
|
|
2176 XSETFRAME (*frame, f);
|
|
2177
|
|
2178 if (XTranslateCoordinates (display, win,
|
|
2179 XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
2180 win_x, win_y, x, y, &child_window) == False)
|
|
2181 /* Huh? */
|
|
2182 return 0;
|
|
2183
|
|
2184 return 1;
|
|
2185 }
|
|
2186
|
|
2187 static void
|
|
2188 x_cant_notify_wm_error (void)
|
|
2189 {
|
|
2190 error ("Can't notify window manager of iconification.");
|
|
2191 }
|
|
2192
|
|
2193 /* Raise frame F. */
|
|
2194 static void
|
|
2195 x_raise_frame_1 (struct frame *f, int force)
|
|
2196 {
|
|
2197 Widget bottom_dialog;
|
|
2198 Window emacs_window;
|
|
2199 XWindowChanges xwc;
|
|
2200 unsigned int flags;
|
|
2201 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2202
|
70
|
2203 if (f->visible || force)
|
0
|
2204 {
|
|
2205 emacs_window = XtWindow (FRAME_X_SHELL_WIDGET (f));
|
|
2206 /* first raises all the dialog boxes, then put emacs just below the
|
|
2207 * bottom most dialog box */
|
|
2208 bottom_dialog = lw_raise_all_pop_up_widgets ();
|
|
2209 if (bottom_dialog && XtWindow (bottom_dialog))
|
|
2210 {
|
|
2211 xwc.sibling = XtWindow (bottom_dialog);
|
|
2212 xwc.stack_mode = Below;
|
|
2213 flags = CWSibling | CWStackMode;
|
|
2214 }
|
|
2215 else
|
|
2216 {
|
|
2217 xwc.stack_mode = Above;
|
|
2218 flags = CWStackMode;
|
|
2219 }
|
|
2220
|
|
2221 if (!XReconfigureWMWindow (display, emacs_window,
|
|
2222 DefaultScreen (display),
|
|
2223 flags, &xwc))
|
|
2224 x_cant_notify_wm_error ();
|
|
2225 }
|
|
2226 }
|
|
2227
|
|
2228 static void
|
|
2229 x_raise_frame (struct frame *f)
|
|
2230 {
|
|
2231 x_raise_frame_1 (f, 1);
|
|
2232 }
|
|
2233
|
|
2234 /* Lower frame F. */
|
|
2235 static void
|
|
2236 x_lower_frame (struct frame *f)
|
|
2237 {
|
|
2238 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2239 XWindowChanges xwc;
|
|
2240 unsigned int flags;
|
|
2241
|
70
|
2242 if (f->visible)
|
0
|
2243 {
|
|
2244 xwc.stack_mode = Below;
|
|
2245 flags = CWStackMode;
|
|
2246 if (!XReconfigureWMWindow (display, XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2247 DefaultScreen (display), flags, &xwc))
|
|
2248 x_cant_notify_wm_error ();
|
|
2249 }
|
|
2250 }
|
|
2251
|
|
2252 /* Change from withdrawn state to mapped state. */
|
|
2253 static void
|
|
2254 x_make_frame_visible (struct frame *f)
|
|
2255 {
|
|
2256 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2257
|
70
|
2258 if (!f->visible)
|
0
|
2259 XMapRaised (display, XtWindow (FRAME_X_SHELL_WIDGET (f)));
|
|
2260 else
|
|
2261 x_raise_frame_1 (f, 0);
|
|
2262 }
|
|
2263
|
|
2264 /* Change from mapped state to withdrawn state. */
|
|
2265 static void
|
|
2266 x_make_frame_invisible (struct frame *f)
|
|
2267 {
|
|
2268 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2269
|
70
|
2270 if (!f->visible)
|
0
|
2271 return;
|
|
2272
|
|
2273 if (!XWithdrawWindow (display,
|
|
2274 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2275 DefaultScreen (display)))
|
|
2276 x_cant_notify_wm_error ();
|
|
2277 }
|
|
2278
|
|
2279 static int
|
|
2280 x_frame_visible_p (struct frame *f)
|
|
2281 {
|
|
2282 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2283 XWindowAttributes xwa;
|
|
2284 int result;
|
|
2285
|
|
2286 if (!XGetWindowAttributes (display,
|
|
2287 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2288 &xwa))
|
|
2289 result = 0;
|
|
2290 else
|
|
2291 result = xwa.map_state == IsViewable;
|
102
|
2292
|
0
|
2293 f->visible = result;
|
|
2294 return result;
|
|
2295 }
|
|
2296
|
|
2297 static int
|
|
2298 x_frame_totally_visible_p (struct frame *f)
|
|
2299 {
|
|
2300 return FRAME_X_TOTALLY_VISIBLE_P (f);
|
|
2301 }
|
|
2302
|
|
2303 /* Change window state from mapped to iconified. */
|
|
2304 static void
|
|
2305 x_iconify_frame (struct frame *f)
|
|
2306 {
|
|
2307 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2308
|
|
2309 if (!XIconifyWindow (display,
|
|
2310 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2311 DefaultScreen (display)))
|
|
2312 x_cant_notify_wm_error ();
|
|
2313
|
|
2314 f->iconified = 1;
|
|
2315 }
|
|
2316
|
|
2317 /* Sets the X focus to frame f. */
|
|
2318 static void
|
|
2319 x_focus_on_frame (struct frame *f)
|
|
2320 {
|
|
2321 XWindowAttributes xwa;
|
|
2322 Widget shell_widget;
|
|
2323
|
|
2324 assert (FRAME_X_P (f));
|
|
2325
|
|
2326 shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
2327 if (!XtWindow (shell_widget))
|
|
2328 return;
|
|
2329
|
|
2330 #ifdef EXTERNAL_WIDGET
|
|
2331 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
2332 ExternalShellSetFocus (shell_widget);
|
|
2333 #endif /* EXTERNAL_WIDGET */
|
|
2334
|
|
2335 /* Do the ICCCM focus change if the window is still visible.
|
|
2336 The s->visible flag might not be up-to-date, because we might
|
|
2337 not have processed magic events recently. So make a server
|
|
2338 round-trip to find out whether it's really mapped right now.
|
|
2339 We grab the server to do this, because that's the only way to
|
|
2340 eliminate the race condition.
|
|
2341 */
|
|
2342 XGrabServer (XtDisplay (shell_widget));
|
|
2343 if (XGetWindowAttributes (XtDisplay (shell_widget),
|
|
2344 XtWindow (shell_widget),
|
|
2345 &xwa))
|
70
|
2346 f->visible = xwa.map_state == IsViewable;
|
0
|
2347
|
70
|
2348 if (f->visible)
|
0
|
2349 {
|
|
2350 Window focus;
|
|
2351 int revert_to;
|
|
2352 XGetInputFocus (XtDisplay (shell_widget), &focus, &revert_to);
|
|
2353 /* Don't explicitly set the focus on this window unless the focus
|
|
2354 was on some other window (not PointerRoot). Note that, even when
|
|
2355 running a point-to-type window manager like *twm, there is always
|
|
2356 a focus window; the window manager maintains that based on the
|
|
2357 mouse position. If you set the "NoTitleFocus" option in these
|
|
2358 window managers, then the server itself maintains the focus via
|
|
2359 PointerRoot, and changing that to focus on the window would make
|
|
2360 the window grab the focus. Very bad.
|
|
2361 */
|
|
2362 if (focus != PointerRoot)
|
|
2363 {
|
|
2364 XSetInputFocus (XtDisplay (shell_widget),
|
|
2365 XtWindow (shell_widget),
|
|
2366 RevertToParent,
|
|
2367 DEVICE_X_MOUSE_TIMESTAMP
|
|
2368 (XDEVICE (FRAME_DEVICE (f))));
|
|
2369 XFlush (XtDisplay (shell_widget));
|
|
2370 }
|
|
2371 }
|
|
2372 XUngrabServer (XtDisplay (shell_widget));
|
|
2373 XFlush (XtDisplay (shell_widget)); /* hey, I'd like to DEBUG this... */
|
|
2374 }
|
|
2375
|
|
2376 /* Destroy the X window of frame S. */
|
|
2377 static void
|
|
2378 x_delete_frame (struct frame *f)
|
|
2379 {
|
|
2380 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
2381 Lisp_Object popup, frame;
|
|
2382
|
|
2383 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
2384 x_wm_maybe_move_wm_command (f);
|
|
2385
|
|
2386 /* Frames with the popup property are using other frames as their
|
|
2387 widget parent. Deleting them are their parent has already been
|
|
2388 deleted can lead to crashes. */
|
|
2389 XSETFRAME (frame, f);
|
|
2390 popup = Fframe_property (frame, Qpopup, Qnil);
|
|
2391 if (!NILP (popup))
|
|
2392 {
|
|
2393 /* If popup isn't nil then it means the frame has that property
|
|
2394 and the value is supposed to be the parent frame. The FRAMEP
|
|
2395 check is to safeguard against it not being a frame. */
|
|
2396 if (!FRAMEP (popup) || !FRAME_LIVE_P (XFRAME (popup)))
|
|
2397 popup = Qt;
|
|
2398 else
|
|
2399 popup = Qnil;
|
|
2400 }
|
|
2401
|
|
2402 #ifdef EXTERNAL_WIDGET
|
|
2403 {
|
|
2404 Display *dpy = XtDisplay (w);
|
|
2405 expect_x_error (dpy);
|
|
2406 /* for obscure reasons having (I think) to do with the internal
|
|
2407 window-to-widget hierarchy maintained by Xt, we have to call
|
|
2408 XtUnrealizeWidget() here. Xt can really suck. */
|
|
2409 if (f->being_deleted)
|
|
2410 XtUnrealizeWidget (w);
|
|
2411 if (NILP (popup))
|
|
2412 XtDestroyWidget (w);
|
|
2413 x_error_occurred_p (dpy);
|
|
2414 }
|
|
2415 #else
|
|
2416 if (NILP (popup))
|
|
2417 XtDestroyWidget (w);
|
|
2418 #endif /* EXTERNAL_WIDGET */
|
|
2419
|
|
2420 if (FRAME_X_GEOM_FREE_ME_PLEASE (f))
|
|
2421 xfree (FRAME_X_GEOM_FREE_ME_PLEASE (f));
|
|
2422 xfree (f->frame_data);
|
|
2423 f->frame_data = 0;
|
|
2424 }
|
|
2425
|
|
2426
|
|
2427 /************************************************************************/
|
|
2428 /* initialization */
|
|
2429 /************************************************************************/
|
|
2430
|
|
2431 void
|
|
2432 syms_of_frame_x (void)
|
|
2433 {
|
|
2434 defsymbol (&Qwindow_id, "window-id");
|
|
2435 defsymbol (&Qpopup, "popup");
|
|
2436 defsymbol (&Qx_resource_name, "x-resource-name");
|
|
2437
|
20
|
2438 DEFSUBR (Fx_window_id);
|
|
2439 #ifdef HAVE_CDE
|
|
2440 DEFSUBR (Fcde_start_drag_internal);
|
|
2441 #endif
|
0
|
2442 }
|
|
2443
|
|
2444 void
|
|
2445 console_type_create_frame_x (void)
|
|
2446 {
|
|
2447 /* frame methods */
|
|
2448 CONSOLE_HAS_METHOD (x, init_frame_1);
|
|
2449 CONSOLE_HAS_METHOD (x, init_frame_2);
|
|
2450 CONSOLE_HAS_METHOD (x, init_frame_3);
|
|
2451 CONSOLE_HAS_METHOD (x, mark_frame);
|
|
2452 CONSOLE_HAS_METHOD (x, focus_on_frame);
|
|
2453 CONSOLE_HAS_METHOD (x, delete_frame);
|
|
2454 CONSOLE_HAS_METHOD (x, get_mouse_position);
|
|
2455 CONSOLE_HAS_METHOD (x, set_mouse_position);
|
|
2456 CONSOLE_HAS_METHOD (x, raise_frame);
|
|
2457 CONSOLE_HAS_METHOD (x, lower_frame);
|
|
2458 CONSOLE_HAS_METHOD (x, make_frame_visible);
|
|
2459 CONSOLE_HAS_METHOD (x, make_frame_invisible);
|
|
2460 CONSOLE_HAS_METHOD (x, iconify_frame);
|
|
2461 CONSOLE_HAS_METHOD (x, set_frame_size);
|
|
2462 CONSOLE_HAS_METHOD (x, set_frame_position);
|
|
2463 CONSOLE_HAS_METHOD (x, frame_property);
|
|
2464 CONSOLE_HAS_METHOD (x, internal_frame_property_p);
|
|
2465 CONSOLE_HAS_METHOD (x, frame_properties);
|
|
2466 CONSOLE_HAS_METHOD (x, set_frame_properties);
|
2
|
2467 CONSOLE_HAS_METHOD (x, set_title_from_bufbyte);
|
|
2468 CONSOLE_HAS_METHOD (x, set_icon_name_from_bufbyte);
|
0
|
2469 CONSOLE_HAS_METHOD (x, frame_visible_p);
|
|
2470 CONSOLE_HAS_METHOD (x, frame_totally_visible_p);
|
|
2471 CONSOLE_HAS_METHOD (x, frame_iconified_p);
|
|
2472 CONSOLE_HAS_METHOD (x, set_frame_pointer);
|
|
2473 CONSOLE_HAS_METHOD (x, set_frame_icon);
|
|
2474 CONSOLE_HAS_METHOD (x, get_frame_parent);
|
|
2475 }
|
|
2476
|
|
2477 void
|
|
2478 vars_of_frame_x (void)
|
|
2479 {
|
|
2480 #ifdef EXTERNAL_WIDGET
|
|
2481 Fprovide (intern ("external-widget"));
|
|
2482 #endif
|
|
2483
|
|
2484 /* this call uses only safe functions from emacs.c */
|
|
2485 init_x_prop_symbols ();
|
|
2486
|
|
2487 DEFVAR_LISP ("default-x-frame-plist", &Vdefault_x_frame_plist /*
|
|
2488 Plist of default frame-creation properties for X frames.
|
|
2489 These override what is specified in the resource database and in
|
|
2490 `default-frame-plist', but are overridden by the arguments to the
|
|
2491 particular call to `make-frame'.
|
|
2492
|
|
2493 Note: In many cases, properties of a frame are available as specifiers
|
|
2494 instead of through the frame-properties mechanism.
|
|
2495
|
|
2496 Here is a list of recognized frame properties, other than those
|
|
2497 documented in `set-frame-properties' (they can be queried and
|
|
2498 set at any time, except as otherwise noted):
|
|
2499
|
|
2500 window-id The X window ID corresponding to the
|
|
2501 frame. May be set only at startup, and
|
|
2502 only if external widget support was
|
|
2503 compiled in; doing so causes the frame
|
|
2504 to be created as an \"external widget\"
|
|
2505 in another program that uses an existing
|
|
2506 window in the program rather than creating
|
|
2507 a new one.
|
|
2508 initially-unmapped If non-nil, the frame will not be visible
|
|
2509 when it is created. In this case, you
|
|
2510 need to call `make-frame-visible' to make
|
|
2511 the frame appear.
|
|
2512 popup If non-nil, it should be a frame, and this
|
|
2513 frame will be created as a \"popup\" frame
|
|
2514 whose parent is the given frame. This
|
|
2515 will make the window manager treat the
|
|
2516 frame as a dialog box, which may entail
|
|
2517 doing different things (e.g. not asking
|
|
2518 for positioning, and not iconifying
|
|
2519 separate from its parent).
|
|
2520 inter-line-space Not currently implemented.
|
|
2521 toolbar-shadow-thickness Thickness of toolbar shadows.
|
|
2522 background-toolbar-color Color of toolbar background.
|
|
2523 bottom-toolbar-shadow-color Color of bottom shadows on toolbars.
|
|
2524 (*Not* specific to the bottom-toolbar.)
|
|
2525 top-toolbar-shadow-color Color of top shadows on toolbars.
|
|
2526 (*Not* specifier to the top-toolbar.)
|
|
2527 internal-border-width Width of internal border around text area.
|
|
2528 border-width Width of external border around text area.
|
|
2529 top Y position (in pixels) of the upper-left
|
|
2530 outermost corner of the frame (i.e. the
|
|
2531 upper-left of the window-manager
|
|
2532 decorations).
|
|
2533 left X position (in pixels) of the upper-left
|
|
2534 outermost corner of the frame (i.e. the
|
|
2535 upper-left of the window-manager
|
|
2536 decorations).
|
|
2537 border-color Color of external border around text area.
|
|
2538 cursor-color Color of text cursor.
|
|
2539
|
|
2540 See also `default-frame-plist', which specifies properties which apply
|
|
2541 to all frames, not just X frames.
|
|
2542 */ );
|
|
2543 Vdefault_x_frame_plist = Qnil;
|
|
2544
|
|
2545 x_console_methods->device_specific_frame_props = &Vdefault_x_frame_plist;
|
|
2546 }
|