428
|
1 /* Functions for the X window system.
|
|
2 Copyright (C) 1989, 1992-5, 1997 Free Software Foundation, Inc.
|
826
|
3 Copyright (C) 1995, 1996, 2001, 2002 Ben Wing.
|
428
|
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
|
442
|
26 /* 7-8-00 !!#### This file needs definite Mule review. */
|
|
27
|
428
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
800
|
31 #include "buffer.h"
|
872
|
32 #include "device-impl.h"
|
800
|
33 #include "events.h"
|
|
34 #include "extents.h"
|
|
35 #include "faces.h"
|
872
|
36 #include "frame-impl.h"
|
800
|
37 #include "gutter.h"
|
872
|
38 #include "window.h"
|
|
39
|
|
40 #include "console-x-impl.h"
|
800
|
41 #include "glyphs-x.h"
|
872
|
42 #include "objects-x-impl.h"
|
800
|
43 #include "scrollbar-x.h"
|
|
44
|
428
|
45 #include "xintrinsicp.h" /* CoreP.h needs this */
|
|
46 #include <X11/CoreP.h> /* Numerous places access the fields of
|
|
47 a core widget directly. We could
|
|
48 use XtGetValues(), but ... */
|
|
49 #include <X11/Shell.h>
|
|
50 #include <X11/ShellP.h>
|
|
51 #include "xmu.h"
|
|
52 #include "EmacsManager.h"
|
|
53 #include "EmacsFrameP.h"
|
|
54 #include "EmacsShell.h"
|
|
55 #ifdef EXTERNAL_WIDGET
|
|
56 #include "ExternalShell.h"
|
|
57 #endif
|
|
58
|
|
59 #ifdef HAVE_DRAGNDROP
|
|
60 #include "dragdrop.h"
|
|
61 #endif
|
|
62
|
|
63 #ifdef HAVE_OFFIX_DND
|
|
64 #include "offix.h"
|
|
65 #endif
|
|
66
|
|
67 /* Default properties to use when creating frames. */
|
|
68 Lisp_Object Vdefault_x_frame_plist;
|
|
69
|
|
70 Lisp_Object Qx_resource_name;
|
|
71
|
1204
|
72 static const struct memory_description x_frame_data_description_1 [] = {
|
1346
|
73 { XD_LISP_OBJECT, offsetof (struct x_frame, last_menubar_buffer) },
|
1204
|
74 { XD_LISP_OBJECT, offsetof (struct x_frame, icon_pixmap) },
|
|
75 { XD_LISP_OBJECT, offsetof (struct x_frame, icon_pixmap_mask) },
|
|
76 { XD_END }
|
|
77 };
|
|
78
|
|
79 extern const struct sized_memory_description x_frame_data_description;
|
|
80
|
|
81 const struct sized_memory_description x_frame_data_description = {
|
|
82 sizeof (struct x_frame), x_frame_data_description_1
|
|
83 };
|
|
84
|
428
|
85 EXFUN (Fx_window_id, 1);
|
|
86
|
|
87
|
|
88 /************************************************************************/
|
|
89 /* helper functions */
|
|
90 /************************************************************************/
|
|
91
|
|
92 /* Return the Emacs frame-object corresponding to an X window */
|
|
93 struct frame *
|
|
94 x_window_to_frame (struct device *d, Window wdesc)
|
|
95 {
|
|
96 Lisp_Object tail, frame;
|
|
97 struct frame *f;
|
|
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 frame = XCAR (tail);
|
|
106 if (!FRAMEP (frame))
|
|
107 continue;
|
|
108 f = XFRAME (frame);
|
|
109 if (FRAME_X_P (f) && XtWindow (FRAME_X_TEXT_WIDGET (f)) == wdesc)
|
|
110 return f;
|
|
111 }
|
|
112 return 0;
|
|
113 }
|
|
114
|
|
115 /* Like x_window_to_frame but also compares the window with the widget's
|
|
116 windows */
|
|
117 struct frame *
|
|
118 x_any_window_to_frame (struct device *d, Window wdesc)
|
|
119 {
|
|
120 Widget w;
|
|
121 assert (DEVICE_X_P (d));
|
|
122
|
|
123 w = XtWindowToWidget (DEVICE_X_DISPLAY (d), wdesc);
|
|
124
|
|
125 if (!w)
|
|
126 return 0;
|
|
127
|
|
128 /* We used to map over all frames here and then map over all widgets
|
|
129 belonging to that frame. However it turns out that this was very fragile
|
442
|
130 as it requires our display structures to be in sync _and_ that the
|
428
|
131 loop is told about every new widget somebody adds. Therefore we
|
|
132 now let Xt find it for us (which does a bottom-up search which
|
|
133 could even be faster) */
|
|
134 return x_any_widget_or_parent_to_frame (d, w);
|
|
135 }
|
|
136
|
|
137 static struct frame *
|
|
138 x_find_frame_for_window (struct device *d, Window wdesc)
|
|
139 {
|
|
140 Lisp_Object tail, frame;
|
|
141 struct frame *f;
|
|
142 /* This function was previously written to accept only a window argument
|
|
143 (and to loop over all devices looking for a matching window), but
|
|
144 that is incorrect because window ID's are not unique across displays. */
|
|
145
|
|
146 for (tail = DEVICE_FRAME_LIST (d); CONSP (tail); tail = XCDR (tail))
|
|
147 {
|
|
148 frame = XCAR (tail);
|
|
149 f = XFRAME (frame);
|
|
150 /* This frame matches if the window is any of its widgets. */
|
|
151 if (wdesc == XtWindow (FRAME_X_SHELL_WIDGET (f)) ||
|
|
152 wdesc == XtWindow (FRAME_X_CONTAINER_WIDGET (f)) ||
|
|
153 wdesc == XtWindow (FRAME_X_TEXT_WIDGET (f)))
|
|
154 return f;
|
|
155
|
|
156 /* Match if the window is one of the widgets at the top of the frame
|
|
157 (menubar, Energize psheets). */
|
|
158
|
|
159 /* Note: Jamie once said
|
|
160
|
|
161 "Do *not* match if the window is this frame's psheet."
|
|
162
|
|
163 But this is wrong and will screw up some functions that expect
|
|
164 x_any_window_to_frame() to work as advertised. I think the reason
|
|
165 for this statement is that, in the old (broken) event loop, where
|
|
166 not all events went through XtDispatchEvent(), psheet events
|
|
167 would incorrectly get sucked away by Emacs if this function matched
|
|
168 on psheet widgets. */
|
|
169
|
|
170 /* Note: that this called only from
|
|
171 x_any_widget_or_parent_to_frame it is unnecessary to iterate
|
|
172 over the top level widgets. */
|
|
173
|
|
174 /* Note: we use to special case scrollbars but this turns out to be a bad idea
|
|
175 because
|
|
176 1. We sometimes get events for _unmapped_ scrollbars and our
|
|
177 callers don't want us to fail.
|
|
178 2. Starting with the 21.2 widget stuff there are now loads of
|
|
179 widgets to check and it is easy to forget adding them in a loop here.
|
|
180 See x_any_window_to_frame
|
|
181 3. We pick up all widgets now anyway. */
|
|
182 }
|
|
183
|
|
184 return 0;
|
|
185 }
|
|
186
|
|
187 struct frame *
|
|
188 x_any_widget_or_parent_to_frame (struct device *d, Widget widget)
|
|
189 {
|
|
190 while (widget)
|
|
191 {
|
|
192 struct frame *f = x_find_frame_for_window (d, XtWindow (widget));
|
|
193 if (f)
|
|
194 return f;
|
|
195 widget = XtParent (widget);
|
|
196 }
|
|
197
|
|
198 return 0;
|
|
199 }
|
|
200
|
|
201 struct frame *
|
|
202 decode_x_frame (Lisp_Object frame)
|
|
203 {
|
|
204 if (NILP (frame))
|
793
|
205 frame = wrap_frame (selected_frame ());
|
428
|
206 CHECK_LIVE_FRAME (frame);
|
|
207 /* this will also catch dead frames, but putting in the above check
|
|
208 results in a more useful error */
|
|
209 CHECK_X_FRAME (frame);
|
|
210 return XFRAME (frame);
|
|
211 }
|
|
212
|
|
213
|
|
214 /************************************************************************/
|
|
215 /* window-manager interactions */
|
|
216 /************************************************************************/
|
|
217
|
|
218 #if 0
|
|
219 /* Not currently used. */
|
|
220
|
|
221 void
|
|
222 x_wm_mark_shell_size_user_specified (Widget wmshell)
|
|
223 {
|
|
224 if (! XtIsWMShell (wmshell)) abort ();
|
|
225 EmacsShellSetSizeUserSpecified (wmshell);
|
|
226 }
|
|
227
|
|
228 void
|
|
229 x_wm_mark_shell_position_user_specified (Widget wmshell)
|
|
230 {
|
|
231 if (! XtIsWMShell (wmshell)) abort ();
|
|
232 EmacsShellSetPositionUserSpecified (wmshell);
|
|
233 }
|
|
234
|
|
235 #endif
|
|
236
|
|
237 void
|
|
238 x_wm_set_shell_iconic_p (Widget shell, int iconic_p)
|
|
239 {
|
|
240 if (! XtIsWMShell (shell)) abort ();
|
|
241
|
|
242 /* Because of questionable logic in Shell.c, this sequence can't work:
|
|
243
|
|
244 w = XtCreatePopupShell (...);
|
|
245 Xt_SET_VALUE (w, XtNiconic, True);
|
|
246 XtRealizeWidget (w);
|
|
247
|
|
248 The iconic resource is only consulted at initialization time (when
|
|
249 XtCreatePopupShell is called) instead of at realization time (just
|
|
250 before the window gets created, which would be more sensible) or
|
|
251 at management-time (just before the window gets mapped, which would
|
|
252 be most sensible of all).
|
|
253
|
|
254 The bug is that Shell's SetValues method doesn't do anything to
|
|
255 w->wm.wm_hints.initial_state until after the widget has been realized.
|
|
256 Calls to XtSetValues are ignored in the window between creation and
|
|
257 realization. This is true of MIT X11R5 patch level 25, at least.
|
|
258 (Apparently some other versions of Xt don't have this bug?)
|
|
259 */
|
|
260 Xt_SET_VALUE (shell, XtNiconic, iconic_p);
|
|
261 EmacsShellSmashIconicHint (shell, iconic_p);
|
|
262 }
|
|
263
|
|
264 void
|
|
265 x_wm_set_cell_size (Widget wmshell, int cw, int ch)
|
|
266 {
|
|
267 Arg al [2];
|
|
268
|
|
269 if (!XtIsWMShell (wmshell))
|
|
270 abort ();
|
|
271 if (cw <= 0 || ch <= 0)
|
|
272 abort ();
|
|
273
|
|
274 XtSetArg (al [0], XtNwidthInc, cw);
|
|
275 XtSetArg (al [1], XtNheightInc, ch);
|
|
276 XtSetValues (wmshell, al, 2);
|
|
277 }
|
|
278
|
|
279 void
|
|
280 x_wm_set_variable_size (Widget wmshell, int width, int height)
|
|
281 {
|
|
282 Arg al [2];
|
|
283
|
|
284 if (!XtIsWMShell (wmshell))
|
|
285 abort ();
|
|
286 #ifdef DEBUG_GEOMETRY_MANAGEMENT
|
|
287 /* See comment in EmacsShell.c */
|
|
288 printf ("x_wm_set_variable_size: %d %d\n", width, height);
|
|
289 fflush (stdout);
|
|
290 #endif
|
|
291
|
|
292 XtSetArg (al [0], XtNwidthCells, width);
|
|
293 XtSetArg (al [1], XtNheightCells, height);
|
|
294 XtSetValues (wmshell, al, 2);
|
|
295 }
|
|
296
|
|
297 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS
|
|
298 and WM_DELETE_WINDOW, then add them. (They may already be present
|
|
299 because of the toolkit (Motif adds them, for example, but Xt doesn't).
|
|
300 */
|
|
301 static void
|
|
302 x_wm_hack_wm_protocols (Widget widget)
|
|
303 {
|
|
304 Display *dpy = XtDisplay (widget);
|
|
305 struct device *d = get_device_from_display (dpy);
|
|
306 Window w = XtWindow (widget);
|
|
307 int need_delete = 1;
|
|
308 int need_focus = 1;
|
|
309
|
|
310 assert (XtIsWMShell (widget));
|
|
311
|
|
312 {
|
|
313 Atom type, *atoms = 0;
|
|
314 int format = 0;
|
|
315 unsigned long nitems = 0;
|
|
316 unsigned long bytes_after;
|
|
317
|
|
318 if (Success == XGetWindowProperty (dpy, w, DEVICE_XATOM_WM_PROTOCOLS (d),
|
|
319 0, 100, False, XA_ATOM,
|
|
320 &type, &format, &nitems, &bytes_after,
|
|
321 (unsigned char **) &atoms)
|
|
322 && format == 32 && type == XA_ATOM)
|
|
323 while (nitems > 0)
|
|
324 {
|
|
325 nitems--;
|
|
326 if (atoms [nitems] == DEVICE_XATOM_WM_DELETE_WINDOW (d))
|
|
327 need_delete = 0;
|
|
328 else if (atoms [nitems] == DEVICE_XATOM_WM_TAKE_FOCUS (d))
|
|
329 need_focus = 0;
|
|
330 }
|
|
331 if (atoms) XFree ((char *) atoms);
|
|
332 }
|
|
333 {
|
|
334 Atom props [10];
|
|
335 int count = 0;
|
|
336 if (need_delete) props[count++] = DEVICE_XATOM_WM_DELETE_WINDOW (d);
|
|
337 if (need_focus) props[count++] = DEVICE_XATOM_WM_TAKE_FOCUS (d);
|
|
338 if (count)
|
|
339 XChangeProperty (dpy, w, DEVICE_XATOM_WM_PROTOCOLS (d), XA_ATOM, 32,
|
|
340 PropModeAppend, (unsigned char *) props, count);
|
|
341 }
|
|
342 }
|
|
343
|
|
344 static void
|
|
345 x_wm_store_class_hints (Widget shell, char *frame_name)
|
|
346 {
|
|
347 Display *dpy = XtDisplay (shell);
|
|
348 char *app_name, *app_class;
|
|
349 XClassHint classhint;
|
|
350
|
|
351 if (!XtIsWMShell (shell))
|
|
352 abort ();
|
|
353
|
|
354 XtGetApplicationNameAndClass (dpy, &app_name, &app_class);
|
|
355 classhint.res_name = frame_name;
|
|
356 classhint.res_class = app_class;
|
|
357 XSetClassHint (dpy, XtWindow (shell), &classhint);
|
|
358 }
|
|
359
|
|
360 #ifndef HAVE_WMCOMMAND
|
|
361 static void
|
|
362 x_wm_maybe_store_wm_command (struct frame *f)
|
|
363 {
|
|
364 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
365 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
366
|
|
367 if (!XtIsWMShell (w))
|
|
368 abort ();
|
|
369
|
|
370 if (NILP (DEVICE_X_WM_COMMAND_FRAME (d)))
|
|
371 {
|
|
372 int argc;
|
|
373 char **argv;
|
|
374 make_argc_argv (Vcommand_line_args, &argc, &argv);
|
|
375 XSetCommand (XtDisplay (w), XtWindow (w), argv, argc);
|
|
376 free_argc_argv (argv);
|
793
|
377 DEVICE_X_WM_COMMAND_FRAME (d) = wrap_frame (f);
|
428
|
378 }
|
|
379 }
|
|
380
|
|
381 /* If we're deleting the frame on which the WM_COMMAND property has been
|
|
382 set, then move that property to another frame so that there is exactly
|
|
383 one frame that has that property set.
|
|
384 */
|
|
385 static void
|
|
386 x_wm_maybe_move_wm_command (struct frame *f)
|
|
387 {
|
|
388 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
389
|
|
390 /* There may not be a frame in DEVICE_X_WM_COMMAND_FRAME()
|
|
391 if we C-c'ed at startup at the right time. */
|
|
392 if (FRAMEP (DEVICE_X_WM_COMMAND_FRAME (d))
|
|
393 && f == XFRAME (DEVICE_X_WM_COMMAND_FRAME (d)))
|
|
394 {
|
|
395 Lisp_Object rest = DEVICE_FRAME_LIST (d);
|
|
396 DEVICE_X_WM_COMMAND_FRAME (d) = Qnil;
|
|
397 /* find some random other X frame that is not this one, or give up */
|
|
398 /* skip non-top-level (ExternalClient) frames */
|
|
399 while (!NILP (rest) &&
|
|
400 (f == XFRAME (XCAR (rest)) ||
|
|
401 !FRAME_X_TOP_LEVEL_FRAME_P (XFRAME (XCAR (rest)))))
|
|
402 rest = XCDR (rest);
|
|
403 if (NILP (rest))
|
|
404 return;
|
|
405 f = XFRAME (XCAR (rest));
|
|
406
|
|
407 x_wm_maybe_store_wm_command (f);
|
|
408
|
|
409 }
|
|
410 }
|
|
411 #endif /* !HAVE_WMCOMMAND */
|
|
412
|
593
|
413 int
|
|
414 x_frame_window_state (struct frame *f)
|
428
|
415 {
|
|
416 Atom actual_type;
|
|
417 int actual_format;
|
|
418 unsigned long nitems, bytesafter;
|
|
419 unsigned long *datap = 0;
|
|
420 Widget widget;
|
593
|
421 int result = -1;
|
428
|
422 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
423
|
|
424 widget = FRAME_X_SHELL_WIDGET (f);
|
|
425 if (Success == XGetWindowProperty (XtDisplay (widget), XtWindow (widget),
|
|
426 DEVICE_XATOM_WM_STATE (d), 0, 2, False,
|
|
427 DEVICE_XATOM_WM_STATE (d), &actual_type,
|
|
428 &actual_format, &nitems, &bytesafter,
|
|
429 (unsigned char **) &datap)
|
|
430 && datap)
|
|
431 {
|
593
|
432 if (nitems <= 2) /* "suggested" by ICCCM version 1 */
|
|
433 result = (int) datap[0];
|
428
|
434 XFree ((char *) datap);
|
|
435 }
|
593
|
436
|
428
|
437 return result;
|
|
438 }
|
|
439
|
593
|
440 static int
|
|
441 x_frame_iconified_p (struct frame *f)
|
|
442 {
|
|
443 return x_frame_window_state (f) == IconicState;
|
|
444 }
|
|
445
|
428
|
446
|
|
447 /************************************************************************/
|
|
448 /* frame properties */
|
|
449 /************************************************************************/
|
|
450
|
|
451 /* Connect the frame-property names (symbols) to the corresponding
|
|
452 X Resource Manager names. The name of a property, as a Lisp symbol,
|
793
|
453 has an `x-resource-name' property which is a Lisp string. */
|
428
|
454
|
|
455 static void
|
|
456 init_x_prop_symbols (void)
|
|
457 {
|
|
458 #define def(sym, rsrc) \
|
|
459 Fput (sym, Qx_resource_name, build_string (rsrc))
|
|
460 #define defi(sym,rsrc) \
|
|
461 def (sym, rsrc); Fput (sym, Qintegerp, Qt)
|
|
462
|
|
463 #if 0 /* this interferes with things. #### fix this right */
|
|
464 def (Qminibuffer, XtNminibuffer);
|
|
465 def (Qunsplittable, XtNunsplittable);
|
|
466 #endif
|
|
467 defi(Qinternal_border_width, XtNinternalBorderWidth);
|
|
468 def (Qscrollbar_placement, XtNscrollBarPlacement);
|
|
469 defi(Qinter_line_space, XtNinterline);
|
|
470 /* font, foreground */
|
|
471 def (Qiconic, XtNiconic);
|
|
472 def (Qbar_cursor, XtNbarCursor);
|
|
473 def (Qvisual_bell, XtNvisualBell);
|
|
474 defi(Qbell_volume, XtNbellVolume);
|
|
475 def (Qpointer_background, XtNpointerBackground);
|
|
476 def (Qpointer_color, XtNpointerColor);
|
|
477 def (Qtext_pointer, XtNtextPointer);
|
|
478 def (Qspace_pointer, XtNspacePointer);
|
|
479 def (Qmodeline_pointer, XtNmodeLinePointer);
|
|
480 def (Qgc_pointer, XtNgcPointer);
|
|
481 /* geometry, initial_geometry */
|
|
482 def (Qinitially_unmapped, XtNinitiallyUnmapped);
|
|
483 /* preferred_width, preferred_height */
|
|
484 def (Quse_backing_store, XtNuseBackingStore);
|
|
485
|
|
486 /* inherited: */
|
|
487
|
|
488 def (Qborder_color, XtNborderColor);
|
|
489 defi(Qborder_width, XtNborderWidth);
|
|
490 defi(Qwidth, XtNwidth);
|
|
491 defi(Qheight, XtNheight);
|
|
492 defi(Qleft, XtNx);
|
|
493 defi(Qtop, XtNy);
|
|
494
|
|
495 #undef def
|
|
496 }
|
|
497
|
|
498 static Lisp_Object
|
|
499 color_to_string (Widget w, unsigned long pixel)
|
|
500 {
|
867
|
501 Ibyte buf[255];
|
428
|
502
|
|
503 XColor color;
|
|
504 color.pixel = pixel;
|
|
505 XQueryColor (XtDisplay (w), w->core.colormap, &color);
|
771
|
506 qxesprintf (buf, "#%04x%04x%04x", color.red, color.green, color.blue);
|
|
507 return build_intstring (buf);
|
428
|
508 }
|
|
509
|
|
510 static void
|
|
511 x_get_top_level_position (Display *d, Window w, Position *x, Position *y)
|
|
512 {
|
|
513 Window root, parent = w, *children;
|
|
514 unsigned int nchildren;
|
|
515 XWindowAttributes xwa;
|
|
516
|
|
517 do
|
|
518 {
|
|
519 w = parent;
|
|
520 if (!XQueryTree (d, w, &root, &parent, &children, &nchildren))
|
|
521 {
|
|
522 *x = 0;
|
|
523 *y = 0;
|
|
524 return;
|
|
525 }
|
|
526 XFree (children);
|
|
527 }
|
|
528 while (root != parent);
|
|
529 XGetWindowAttributes (d, w, &xwa);
|
|
530 *x = xwa.x;
|
|
531 *y = xwa.y;
|
|
532 }
|
|
533
|
|
534 #if 0
|
|
535 static void
|
|
536 x_smash_bastardly_shell_position (Widget shell)
|
|
537 {
|
|
538 /* Naturally those bastards who wrote Xt couldn't be bothered
|
|
539 to learn about race conditions and such. We can't trust
|
|
540 the X and Y values to have any semblance of correctness,
|
|
541 so we smash the right values in place. */
|
|
542
|
|
543 /* We might be called before we've actually realized the window (if
|
|
544 we're checking for the minibuffer resource). This will bomb in
|
|
545 that case so we don't bother calling it. */
|
|
546 if (XtWindow (shell))
|
|
547 x_get_top_level_position (XtDisplay (shell), XtWindow (shell),
|
|
548 &shell->core.x, &shell->core.y);
|
|
549 }
|
|
550 #endif /* 0 */
|
|
551
|
|
552 static Lisp_Object
|
|
553 x_frame_property (struct frame *f, Lisp_Object property)
|
|
554 {
|
|
555 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
|
556 EmacsFrame w = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
557 Widget gw = (Widget) w;
|
|
558
|
|
559 if (EQ (Qleft, property) || EQ (Qtop, property))
|
|
560 {
|
|
561 Position x, y;
|
|
562 if (!XtWindow(shell))
|
|
563 return Qzero;
|
|
564 x_get_top_level_position (XtDisplay (shell), XtWindow (shell), &x, &y);
|
|
565 if (EQ (Qleft, property)) return make_int (x);
|
|
566 if (EQ (Qtop, property)) return make_int (y);
|
|
567 }
|
|
568 if (EQ (Qborder_width, property))
|
|
569 return make_int (w->core.border_width);
|
|
570 if (EQ (Qinternal_border_width, property))
|
|
571 return make_int (w->emacs_frame.internal_border_width);
|
|
572 if (EQ (Qborder_color, property))
|
|
573 return color_to_string (gw, w->core.border_pixel);
|
|
574 if (EQ (Qinter_line_space, property))
|
|
575 return make_int (w->emacs_frame.interline);
|
|
576 if (EQ (Qwindow_id, property))
|
771
|
577 return Fx_window_id (wrap_frame (f));
|
428
|
578
|
|
579 return Qunbound;
|
|
580 }
|
|
581
|
|
582 static int
|
|
583 x_internal_frame_property_p (struct frame *f, Lisp_Object property)
|
|
584 {
|
|
585 return EQ (property, Qleft)
|
|
586 || EQ (property, Qtop)
|
|
587 || EQ (property, Qborder_width)
|
|
588 || EQ (property, Qinternal_border_width)
|
|
589 || EQ (property, Qborder_color)
|
|
590 || EQ (property, Qinter_line_space)
|
|
591 || EQ (property, Qwindow_id)
|
|
592 || STRINGP (property);
|
|
593 }
|
|
594
|
|
595 static Lisp_Object
|
|
596 x_frame_properties (struct frame *f)
|
|
597 {
|
|
598 Lisp_Object props = Qnil;
|
|
599 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
|
600 EmacsFrame w = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
601 Widget gw = (Widget) w;
|
|
602 Position x, y;
|
|
603
|
771
|
604 props = cons3 (Qwindow_id, Fx_window_id (wrap_frame (f)), props);
|
428
|
605 props = cons3 (Qinter_line_space, make_int (w->emacs_frame.interline), props);
|
|
606
|
|
607 props = cons3 (Qborder_color,
|
|
608 color_to_string (gw, w->core.border_pixel), props);
|
|
609 props = cons3 (Qinternal_border_width,
|
|
610 make_int (w->emacs_frame.internal_border_width), props);
|
|
611 props = cons3 (Qborder_width, make_int (w->core.border_width), props);
|
|
612
|
|
613 if (!XtWindow(shell))
|
|
614 x = y = 0;
|
|
615 else
|
|
616 x_get_top_level_position (XtDisplay (shell), XtWindow (shell), &x, &y);
|
|
617
|
|
618 props = cons3 (Qtop, make_int (y), props);
|
|
619 props = cons3 (Qleft, make_int (x), props);
|
|
620
|
|
621 return props;
|
|
622 }
|
|
623
|
|
624
|
|
625 /* Functions called only from `x_set_frame_properties' to set
|
|
626 individual properties. */
|
|
627
|
|
628 static void
|
867
|
629 x_set_frame_text_value (struct frame *f, Ibyte *value,
|
428
|
630 String Xt_resource_name,
|
|
631 String Xt_resource_encoding_name)
|
|
632 {
|
|
633 Atom encoding = XA_STRING;
|
|
634 String new_XtValue = (String) value;
|
|
635 String old_XtValue = NULL;
|
|
636
|
|
637 #ifdef MULE
|
867
|
638 Ibyte *ptr;
|
428
|
639 /* Optimize for common ASCII case */
|
|
640 for (ptr = value; *ptr; ptr++)
|
826
|
641 if (!byte_ascii_p (*ptr))
|
428
|
642 {
|
442
|
643 const char * tmp;
|
428
|
644 encoding = DEVICE_XATOM_COMPOUND_TEXT (XDEVICE (FRAME_DEVICE (f)));
|
442
|
645 C_STRING_TO_EXTERNAL (value, tmp, Qctext);
|
428
|
646 new_XtValue = (String) tmp;
|
|
647 break;
|
|
648 }
|
|
649 #endif /* MULE */
|
|
650
|
440
|
651 /* #### Caching is device-independent - belongs in update_frame_title. */
|
428
|
652 Xt_GET_VALUE (FRAME_X_SHELL_WIDGET (f), Xt_resource_name, &old_XtValue);
|
|
653 if (!old_XtValue || strcmp (new_XtValue, old_XtValue))
|
|
654 {
|
|
655 Arg al[2];
|
|
656 XtSetArg (al[0], Xt_resource_name, new_XtValue);
|
|
657 XtSetArg (al[1], Xt_resource_encoding_name, encoding);
|
|
658 XtSetValues (FRAME_X_SHELL_WIDGET (f), al, 2);
|
|
659 }
|
|
660 }
|
|
661
|
|
662 static void
|
867
|
663 x_set_title_from_ibyte (struct frame *f, Ibyte *name)
|
428
|
664 {
|
|
665 x_set_frame_text_value (f, name, XtNtitle, XtNtitleEncoding);
|
|
666 }
|
|
667
|
|
668 static void
|
867
|
669 x_set_icon_name_from_ibyte (struct frame *f, Ibyte *name)
|
428
|
670 {
|
|
671 x_set_frame_text_value (f, name, XtNiconName, XtNiconNameEncoding);
|
|
672 }
|
|
673
|
|
674 /* Set the initial frame size as specified. This function is used
|
|
675 when the frame's widgets have not yet been realized. In this
|
|
676 case, it is not sufficient just to set the width and height of
|
|
677 the EmacsFrame widget, because they will be ignored when the
|
|
678 widget is realized (instead, the shell's geometry resource is
|
|
679 used). */
|
|
680
|
|
681 static void
|
|
682 x_set_initial_frame_size (struct frame *f, int flags, int x, int y,
|
647
|
683 int w, int h)
|
428
|
684 {
|
|
685 char shell_geom [255];
|
|
686 int xval, yval;
|
|
687 char xsign, ysign;
|
|
688 char uspos = !!(flags & (XValue | YValue));
|
|
689 char ussize = !!(flags & (WidthValue | HeightValue));
|
|
690 char *temp;
|
|
691
|
|
692 /* assign the correct size to the EmacsFrame widget ... */
|
|
693 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), w, h);
|
|
694
|
|
695 /* and also set the WMShell's geometry */
|
|
696 (flags & XNegative) ? (xval = -x, xsign = '-') : (xval = x, xsign = '+');
|
|
697 (flags & YNegative) ? (yval = -y, ysign = '-') : (yval = y, ysign = '+');
|
|
698
|
|
699 if (uspos && ussize)
|
|
700 sprintf (shell_geom, "=%dx%d%c%d%c%d", w, h, xsign, xval, ysign, yval);
|
|
701 else if (uspos)
|
|
702 sprintf (shell_geom, "=%c%d%c%d", xsign, xval, ysign, yval);
|
|
703 else if (ussize)
|
|
704 sprintf (shell_geom, "=%dx%d", w, h);
|
|
705
|
|
706 if (uspos || ussize)
|
|
707 {
|
|
708 temp = (char *) xmalloc (1 + strlen (shell_geom));
|
|
709 strcpy (temp, shell_geom);
|
|
710 FRAME_X_GEOM_FREE_ME_PLEASE (f) = temp;
|
|
711 }
|
|
712 else
|
|
713 temp = NULL;
|
|
714
|
|
715 Xt_SET_VALUE (FRAME_X_SHELL_WIDGET (f), XtNgeometry, temp);
|
|
716 }
|
|
717
|
|
718 /* Report to X that a frame property of frame S is being set or changed.
|
|
719 If the property is not specially recognized, do nothing.
|
|
720 */
|
|
721
|
|
722 static void
|
|
723 x_set_frame_properties (struct frame *f, Lisp_Object plist)
|
|
724 {
|
|
725 Position x, y;
|
|
726 Dimension width = 0, height = 0;
|
|
727 Bool width_specified_p = False;
|
|
728 Bool height_specified_p = False;
|
|
729 Bool x_position_specified_p = False;
|
|
730 Bool y_position_specified_p = False;
|
|
731 Bool internal_border_width_specified = False;
|
|
732 Lisp_Object tail;
|
|
733 Widget w = FRAME_X_TEXT_WIDGET (f);
|
|
734
|
|
735 for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail)))
|
|
736 {
|
|
737 Lisp_Object prop = Fcar (tail);
|
|
738 Lisp_Object val = Fcar (Fcdr (tail));
|
|
739
|
|
740 if (STRINGP (prop))
|
|
741 {
|
442
|
742 const char *extprop;
|
428
|
743
|
|
744 if (XSTRING_LENGTH (prop) == 0)
|
|
745 continue;
|
|
746
|
442
|
747 LISP_STRING_TO_EXTERNAL (prop, extprop, Qctext);
|
428
|
748 if (STRINGP (val))
|
|
749 {
|
442
|
750 const Extbyte *extval;
|
665
|
751 Bytecount extvallen;
|
428
|
752
|
440
|
753 TO_EXTERNAL_FORMAT (LISP_STRING, val,
|
|
754 ALLOCA, (extval, extvallen),
|
|
755 Qctext);
|
428
|
756 XtVaSetValues (w, XtVaTypedArg, extprop,
|
|
757 XtRString, extval, extvallen + 1,
|
|
758 (XtArgVal) NULL);
|
|
759 }
|
|
760 else
|
|
761 XtVaSetValues (w, XtVaTypedArg, extprop, XtRInt,
|
|
762 XINT (val), sizeof (int),
|
|
763 (XtArgVal) NULL);
|
|
764 }
|
|
765 else if (SYMBOLP (prop))
|
|
766 {
|
|
767 Lisp_Object str = Fget (prop, Qx_resource_name, Qnil);
|
|
768 int int_p = !NILP (Fget (prop, Qintegerp, Qnil));
|
|
769
|
|
770 if (NILP (prop) || NILP (str))
|
|
771 {
|
|
772 /* Kludge to handle the font property. */
|
|
773 if (EQ (prop, Qfont))
|
|
774 {
|
|
775 /* If the value is not a string we silently ignore it. */
|
|
776 if (STRINGP (val))
|
|
777 {
|
|
778 Lisp_Object frm, font_spec;
|
|
779
|
793
|
780 frm = wrap_frame (f);
|
428
|
781 font_spec = Fget (Fget_face (Qdefault), Qfont, Qnil);
|
|
782
|
|
783 Fadd_spec_to_specifier (font_spec, val, frm, Qnil, Qnil);
|
|
784 update_frame_face_values (f);
|
|
785 }
|
|
786
|
|
787 continue;
|
|
788 }
|
|
789 else
|
|
790 continue;
|
|
791 }
|
|
792 CHECK_STRING (str);
|
|
793
|
|
794 /* Kludge the width/height so that we interpret them in characters
|
|
795 instead of pixels. Yuck yuck yuck. */
|
|
796 if (!strcmp ((char *) XSTRING_DATA (str), "width"))
|
|
797 {
|
|
798 CHECK_INT (val);
|
|
799 width = XINT (val);
|
|
800 width_specified_p = True;
|
|
801 continue;
|
|
802 }
|
|
803 if (!strcmp ((char *) XSTRING_DATA (str), "height"))
|
|
804 {
|
|
805 CHECK_INT (val);
|
|
806 height = XINT (val);
|
|
807 height_specified_p = True;
|
|
808 continue;
|
|
809 }
|
|
810 /* Further kludge the x/y. */
|
|
811 if (!strcmp ((char *) XSTRING_DATA (str), "x"))
|
|
812 {
|
|
813 CHECK_INT (val);
|
|
814 x = (Position) XINT (val);
|
|
815 x_position_specified_p = True;
|
|
816 continue;
|
|
817 }
|
|
818 if (!strcmp ((char *) XSTRING_DATA (str), "y"))
|
|
819 {
|
|
820 CHECK_INT (val);
|
|
821 y = (Position) XINT (val);
|
|
822 y_position_specified_p = True;
|
|
823 continue;
|
|
824 }
|
|
825 /* Have you figured out by now that this entire function is
|
|
826 one gigantic kludge? */
|
|
827 if (!strcmp ((char *) XSTRING_DATA (str),
|
|
828 "internalBorderWidth"))
|
|
829 {
|
|
830 internal_border_width_specified = True;
|
|
831 }
|
|
832
|
|
833 if (int_p)
|
|
834 {
|
|
835 CHECK_INT (val);
|
|
836 Xt_SET_VALUE (w, (char *) XSTRING_DATA (str), XINT (val));
|
|
837 }
|
|
838 else if (EQ (val, Qt))
|
|
839 {
|
|
840 Xt_SET_VALUE (w, (char *) XSTRING_DATA (str), True); /* XtN...*/
|
|
841 }
|
|
842 else if (EQ (val, Qnil))
|
|
843 {
|
|
844 Xt_SET_VALUE (w, (char *) XSTRING_DATA (str), False); /* XtN...*/
|
|
845 }
|
|
846 else
|
|
847 {
|
|
848 CHECK_STRING (val);
|
|
849 XtVaSetValues (w, XtVaTypedArg,
|
|
850 /* XtN... */
|
|
851 (char *) XSTRING_DATA (str),
|
|
852 XtRString,
|
|
853 XSTRING_DATA (val),
|
|
854 XSTRING_LENGTH (val) + 1,
|
|
855 (XtArgVal) NULL);
|
|
856 }
|
|
857
|
|
858 #ifdef HAVE_SCROLLBARS
|
|
859 if (!strcmp ((char *) XSTRING_DATA (str), "scrollBarWidth")
|
|
860 || !strcmp ((char *) XSTRING_DATA (str),
|
|
861 "scrollBarHeight"))
|
|
862 {
|
|
863 x_update_frame_scrollbars (f);
|
|
864 }
|
|
865 #endif /* HAVE_SCROLLBARS */
|
|
866 }
|
|
867 }
|
|
868
|
|
869 /* Kludge kludge kludge. We need to deal with the size and position
|
|
870 specially. */
|
|
871 {
|
|
872 int size_specified_p = width_specified_p || height_specified_p;
|
|
873 int position_specified_p = x_position_specified_p ||
|
|
874 y_position_specified_p;
|
|
875
|
|
876 if (!width_specified_p)
|
|
877 width = FRAME_WIDTH (f);
|
|
878 if (!height_specified_p)
|
|
879 height = FRAME_HEIGHT (f);
|
|
880
|
|
881 /* Kludge kludge kludge kludge. */
|
|
882 if (position_specified_p &&
|
|
883 (!x_position_specified_p || !y_position_specified_p))
|
|
884 {
|
|
885 Position dummy;
|
|
886 Widget shell = FRAME_X_SHELL_WIDGET (f);
|
|
887 x_get_top_level_position (XtDisplay (shell), XtWindow (shell),
|
|
888 (x_position_specified_p ? &dummy : &x),
|
|
889 (y_position_specified_p ? &dummy : &y));
|
|
890 #if 0
|
|
891 x = (int) (FRAME_X_SHELL_WIDGET (f)->core.x);
|
|
892 y = (int) (FRAME_X_SHELL_WIDGET (f)->core.y);
|
|
893 #endif
|
|
894 }
|
|
895
|
|
896 if (!f->init_finished)
|
|
897 {
|
|
898 int flags = (size_specified_p ? WidthValue | HeightValue : 0) |
|
|
899 (position_specified_p ?
|
|
900 XValue | YValue | (x < 0 ? XNegative : 0) | (y < 0 ? YNegative : 0)
|
|
901 : 0);
|
|
902 if (size_specified_p
|
|
903 || position_specified_p
|
|
904 || internal_border_width_specified)
|
|
905 x_set_initial_frame_size (f, flags, x, y, width, height);
|
|
906 }
|
|
907 else
|
|
908 {
|
|
909 if (size_specified_p || internal_border_width_specified)
|
|
910 {
|
793
|
911 Lisp_Object frame = wrap_frame (f);
|
|
912
|
428
|
913 Fset_frame_size (frame, make_int (width),
|
|
914 make_int (height), Qnil);
|
|
915 }
|
|
916 if (position_specified_p)
|
|
917 {
|
793
|
918 Lisp_Object frame = wrap_frame (f);
|
|
919
|
428
|
920 Fset_frame_position (frame, make_int (x), make_int (y));
|
|
921 }
|
|
922 }
|
|
923 }
|
|
924 }
|
|
925
|
|
926 static int frame_title_format_already_set;
|
|
927
|
|
928 static void
|
|
929 maybe_set_frame_title_format (Widget shell)
|
|
930 {
|
|
931
|
|
932 /* Only do this if this is the first X frame we're creating.
|
|
933
|
|
934 If the *title resource (or -title option) was specified, then
|
|
935 set frame-title-format to its value.
|
|
936 */
|
|
937
|
|
938 if (!frame_title_format_already_set)
|
|
939 {
|
|
940 /* No doubt there's a less stupid way to do this. */
|
|
941 char *results [2];
|
|
942 XtResource resources [2];
|
|
943 results [0] = results [1] = 0;
|
|
944 resources [0].resource_name = XtNtitle;
|
|
945 resources [0].resource_class = XtCTitle;
|
|
946 resources [0].resource_type = XtRString;
|
|
947 resources [0].resource_size = sizeof (String);
|
|
948 resources [0].resource_offset = 0;
|
|
949 resources [0].default_type = XtRString;
|
|
950 resources [0].default_addr = 0;
|
|
951 resources [1].resource_name = XtNiconName;
|
|
952 resources [1].resource_class = XtCIconName;
|
|
953 resources [1].resource_type = XtRString;
|
|
954 resources [1].resource_size = sizeof (String);
|
|
955 resources [1].resource_offset = sizeof (char *);
|
|
956 resources [1].default_type = XtRString;
|
|
957 resources [1].default_addr = 0;
|
|
958 XtGetSubresources (XtParent (shell), (XtPointer) results,
|
|
959 shell->core.name,
|
|
960 shell->core.widget_class->core_class.class_name,
|
|
961 resources, XtNumber (resources), 0, 0);
|
|
962 if (results[0])
|
|
963 Vframe_title_format = build_string (results[0]);
|
|
964 if (results[1])
|
|
965 Vframe_icon_title_format = build_string (results[1]);
|
|
966 }
|
|
967
|
|
968 frame_title_format_already_set = 1;
|
|
969 }
|
|
970
|
|
971 #ifdef HAVE_CDE
|
|
972 #include <Dt/Dt.h>
|
|
973 #include <Dt/Dnd.h>
|
|
974
|
|
975 static Widget CurrentDragWidget = NULL;
|
|
976 static XtCallbackRec dnd_convert_cb_rec[2];
|
|
977 static XtCallbackRec dnd_destroy_cb_rec[2];
|
|
978 static int drag_not_done = 0;
|
|
979
|
|
980 static void
|
|
981 x_cde_destroy_callback (Widget widget, XtPointer clientData,
|
|
982 XtPointer callData)
|
|
983 {
|
|
984 DtDndDragFinishCallbackStruct *dragFinishInfo =
|
|
985 (DtDndDragFinishCallbackStruct *)callData;
|
|
986 DtDndContext *dragData = dragFinishInfo->dragData;
|
|
987 int i;
|
|
988
|
|
989 /* free the items */
|
|
990 if (callData != NULL && dragData != NULL)
|
|
991 {
|
|
992 if (dragData->protocol == DtDND_BUFFER_TRANSFER)
|
|
993 {
|
|
994 for (i = 0; i < dragData->numItems; i++)
|
|
995 {
|
|
996 XtFree((char *) dragData->data.buffers[i].bp);
|
|
997 if (dragData->data.buffers[i].name)
|
|
998 XtFree(dragData->data.buffers[i].name);
|
|
999 }
|
|
1000 }
|
|
1001 else
|
|
1002 {
|
|
1003 for (i = 0; i < dragData->numItems; i++)
|
|
1004 XtFree(dragData->data.files[i]);
|
|
1005 }
|
|
1006 }
|
|
1007
|
|
1008 /* free the data string */
|
1726
|
1009 xfree (clientData, XtPointer);
|
428
|
1010
|
|
1011 CurrentDragWidget = NULL;
|
|
1012 }
|
|
1013
|
|
1014 static void
|
|
1015 x_cde_convert_callback (Widget widget, XtPointer clientData,
|
|
1016 XtPointer callData)
|
|
1017 {
|
|
1018 DtDndConvertCallbackStruct *convertInfo =
|
|
1019 (DtDndConvertCallbackStruct *) callData;
|
|
1020 char *textdata = (char *) clientData;
|
|
1021 char *textptr = NULL;
|
|
1022 int i;
|
|
1023
|
|
1024 if (convertInfo == NULL)
|
|
1025 {
|
|
1026 return;
|
|
1027 }
|
|
1028
|
|
1029 if ((convertInfo->dragData->protocol != DtDND_BUFFER_TRANSFER
|
|
1030 && convertInfo->dragData->protocol != DtDND_FILENAME_TRANSFER) ||
|
|
1031 (convertInfo->reason != DtCR_DND_CONVERT_DATA))
|
|
1032 {
|
|
1033 return;
|
|
1034 }
|
|
1035
|
|
1036 for (textptr=textdata, i=0;
|
|
1037 i<convertInfo->dragData->numItems;
|
|
1038 textptr+=strlen(textptr)+1, i++)
|
|
1039 {
|
|
1040 if (convertInfo->dragData->protocol == DtDND_BUFFER_TRANSFER)
|
|
1041 {
|
|
1042 convertInfo->dragData->data.buffers[i].bp = XtNewString(textptr);
|
|
1043 convertInfo->dragData->data.buffers[i].size = strlen(textptr);
|
|
1044 convertInfo->dragData->data.buffers[i].name = NULL;
|
|
1045 }
|
|
1046 else
|
|
1047 {
|
|
1048 convertInfo->dragData->data.files[i] = XtNewString(textptr);
|
|
1049 }
|
|
1050 }
|
|
1051
|
|
1052 convertInfo->status = DtDND_SUCCESS;
|
|
1053 }
|
|
1054
|
|
1055 static Lisp_Object
|
|
1056 abort_current_drag(Lisp_Object arg)
|
|
1057 {
|
|
1058 if (CurrentDragWidget && drag_not_done)
|
|
1059 {
|
|
1060 XmDragCancel(CurrentDragWidget);
|
|
1061 CurrentDragWidget = NULL;
|
|
1062 }
|
|
1063 return arg;
|
|
1064 }
|
|
1065
|
|
1066 DEFUN ("cde-start-drag-internal", Fcde_start_drag_internal, 3, 3, 0, /*
|
|
1067 Start a CDE drag from a buffer.
|
|
1068 First argument is the event that started the drag (must be a
|
|
1069 button-press-event),
|
|
1070 second arg defines if the data should be treated as a buffer or
|
|
1071 a filename transfer (set to nil for buffer transfer),
|
|
1072 and the third argument is a list of data strings.
|
|
1073 WARNING: can only handle plain/text and file: transfers!
|
|
1074 */
|
|
1075 (event, dragtype, dragdata))
|
|
1076 {
|
|
1077 if (EVENTP (event))
|
|
1078 {
|
|
1079 struct frame *f = decode_x_frame (Fselected_frame (Qnil));
|
|
1080 XEvent x_event;
|
|
1081 Widget wid = FRAME_X_TEXT_WIDGET (f);
|
|
1082 Display *display = XtDisplayOfObject (wid);
|
|
1083 struct device *d = get_device_from_display (display);
|
|
1084 struct x_device *xd = DEVICE_X_DATA (d);
|
|
1085 XWindowAttributes win_attrib;
|
647
|
1086 int modifier = 0, state = 0;
|
428
|
1087 char *Ctext;
|
|
1088 int numItems = 0, textlen = 0, pos = 0;
|
440
|
1089 Lisp_Event *lisp_event = XEVENT (event);
|
428
|
1090 Lisp_Object item = Qnil;
|
|
1091 struct gcpro gcpro1;
|
|
1092
|
|
1093 /* only drag if this is really a press */
|
|
1094 if (EVENT_TYPE(lisp_event) != button_press_event
|
|
1095 || !LISTP(dragdata))
|
|
1096 return Qnil;
|
|
1097
|
|
1098 GCPRO1 (item);
|
|
1099
|
|
1100 /*
|
|
1101 * not so cross hack that converts a emacs event back to a XEvent
|
|
1102 */
|
|
1103
|
|
1104 x_event.xbutton.type = ButtonPress;
|
|
1105 x_event.xbutton.send_event = False;
|
|
1106 x_event.xbutton.display = XtDisplayOfObject(wid);
|
|
1107 x_event.xbutton.window = XtWindowOfObject(wid);
|
|
1108 x_event.xbutton.root = XRootWindow(x_event.xbutton.display, 0);
|
|
1109 x_event.xbutton.subwindow = 0;
|
|
1110 x_event.xbutton.time = lisp_event->timestamp;
|
1204
|
1111 x_event.xbutton.x = EVENT_BUTTON_X (lisp_event);
|
|
1112 x_event.xbutton.y = EVENT_BUTTON_Y (lisp_event);
|
428
|
1113 if (Success == XGetWindowAttributes (x_event.xbutton.display,
|
|
1114 x_event.xbutton.window,
|
|
1115 &win_attrib))
|
|
1116 {
|
1204
|
1117 x_event.xbutton.x_root = win_attrib.x + EVENT_BUTTON_X (lisp_event);
|
|
1118 x_event.xbutton.y_root = win_attrib.y + EVENT_BUTTON_Y (lisp_event);
|
428
|
1119 }
|
|
1120 else
|
|
1121 {
|
1204
|
1122 x_event.xbutton.x_root = EVENT_BUTTON_X (lisp_event); /* this is wrong */
|
|
1123 x_event.xbutton.y_root = EVENT_BUTTON_Y (lisp_event);
|
428
|
1124 }
|
1204
|
1125 modifier = EVENT_BUTTON_MODIFIERS (lisp_event);
|
442
|
1126 if (modifier & XEMACS_MOD_SHIFT) state |= ShiftMask;
|
|
1127 if (modifier & XEMACS_MOD_CONTROL) state |= ControlMask;
|
|
1128 if (modifier & XEMACS_MOD_META) state |= xd->MetaMask;
|
|
1129 if (modifier & XEMACS_MOD_SUPER) state |= xd->SuperMask;
|
|
1130 if (modifier & XEMACS_MOD_HYPER) state |= xd->HyperMask;
|
|
1131 if (modifier & XEMACS_MOD_ALT) state |= xd->AltMask;
|
1204
|
1132 state |= Button1Mask << (EVENT_BUTTON_BUTTON (lisp_event)-1);
|
428
|
1133
|
|
1134 x_event.xbutton.state = state;
|
1204
|
1135 x_event.xbutton.button = EVENT_BUTTON_BUTTON (lisp_event);
|
428
|
1136 x_event.xkey.same_screen = True;
|
|
1137
|
|
1138 /* convert data strings into a big string */
|
|
1139 item = dragdata;
|
|
1140 while (!NILP (item))
|
|
1141 {
|
|
1142 if (!STRINGP (XCAR (item)))
|
|
1143 {
|
|
1144 numItems=0;
|
|
1145 break;
|
|
1146 }
|
|
1147 textlen += XSTRING_LENGTH (XCAR (item)) + 1;
|
|
1148 numItems++;
|
|
1149 item = XCDR (item);
|
|
1150 }
|
|
1151
|
|
1152 if (numItems)
|
|
1153 {
|
|
1154 /*
|
|
1155 * concatenate all strings given to one large string, with
|
|
1156 * \0 as separator. List is ended by \0.
|
|
1157 */
|
|
1158 Ctext = (char *)xmalloc (textlen+1);
|
|
1159 Ctext[0] = 0;
|
|
1160
|
|
1161 item = dragdata;
|
|
1162 while (!NILP (item))
|
|
1163 {
|
|
1164 if (!STRINGP (XCAR (item)))
|
|
1165 {
|
|
1166 numItems=0;
|
1726
|
1167 xfree(Ctext, char *);
|
428
|
1168 Ctext=NULL;
|
|
1169 break;
|
|
1170 }
|
442
|
1171 strcpy (Ctext+pos, (const char *)XSTRING_DATA (XCAR (item)));
|
428
|
1172 pos += XSTRING_LENGTH (XCAR (item)) + 1;
|
|
1173 item = XCDR (item);
|
|
1174 }
|
|
1175 Ctext[pos] = 0;
|
|
1176
|
|
1177 dnd_convert_cb_rec[0].callback = x_cde_convert_callback;
|
|
1178 dnd_convert_cb_rec[0].closure = (XtPointer) Ctext;
|
|
1179 dnd_convert_cb_rec[1].callback = NULL;
|
|
1180 dnd_convert_cb_rec[1].closure = NULL;
|
|
1181
|
|
1182 dnd_destroy_cb_rec[0].callback = x_cde_destroy_callback;
|
|
1183 dnd_destroy_cb_rec[0].closure = (XtPointer) Ctext;
|
|
1184 dnd_destroy_cb_rec[1].callback = NULL;
|
|
1185 dnd_destroy_cb_rec[1].closure = NULL;
|
|
1186
|
|
1187 CurrentDragWidget =
|
|
1188 DtDndDragStart (wid, &x_event,
|
|
1189 (NILP(dragtype)?DtDND_BUFFER_TRANSFER:DtDND_FILENAME_TRANSFER),
|
|
1190 numItems,
|
|
1191 XmDROP_COPY,
|
|
1192 dnd_convert_cb_rec,
|
|
1193 dnd_destroy_cb_rec,
|
|
1194 NULL, 0);
|
|
1195 }
|
|
1196
|
|
1197 UNGCPRO;
|
|
1198
|
|
1199 return numItems?Qt:Qnil;
|
|
1200 }
|
|
1201
|
|
1202 return Qnil;
|
|
1203 }
|
|
1204
|
|
1205 static void
|
|
1206 x_cde_transfer_callback (Widget widget, XtPointer clientData,
|
|
1207 XtPointer callData)
|
|
1208 {
|
|
1209 char *filePath, *hurl;
|
|
1210 int ii, enqueue=1;
|
|
1211 Lisp_Object frame = Qnil;
|
|
1212 Lisp_Object l_type = Qnil;
|
|
1213 Lisp_Object l_data = Qnil;
|
|
1214 DtDndTransferCallbackStruct *transferInfo = NULL;
|
|
1215 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1216
|
|
1217 /*
|
|
1218 this needs to be changed to the new protocol:
|
|
1219 - we need the button, modifier and pointer states to create a
|
|
1220 correct misc_user_event
|
|
1221 - the data must be converted to the new format (URL/MIME)
|
|
1222 */
|
|
1223 /* return; */
|
|
1224
|
|
1225 transferInfo = (DtDndTransferCallbackStruct *) callData;
|
|
1226 if (transferInfo == NULL)
|
|
1227 return;
|
|
1228
|
|
1229 GCPRO3 (frame, l_type, l_data);
|
|
1230
|
771
|
1231 frame = wrap_frame ((struct frame *) clientData);
|
428
|
1232
|
|
1233 if (transferInfo->dropData->protocol == DtDND_FILENAME_TRANSFER)
|
|
1234 {
|
|
1235 l_type = Qdragdrop_URL;
|
|
1236
|
|
1237 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
|
|
1238 {
|
|
1239 filePath = transferInfo->dropData->data.files[ii];
|
|
1240 hurl = dnd_url_hexify_string ((char *)filePath, "file:");
|
440
|
1241 /* #### Mule-izing required */
|
867
|
1242 l_data = Fcons (make_string ((Ibyte* )hurl,
|
428
|
1243 strlen (hurl)),
|
|
1244 l_data);
|
1726
|
1245 xfree (hurl, char *);
|
428
|
1246 }
|
|
1247 }
|
|
1248 else if (transferInfo->dropData->protocol == DtDND_BUFFER_TRANSFER)
|
|
1249 {
|
|
1250 int speccount = specpdl_depth();
|
|
1251
|
|
1252 /* Problem: all buffers a treated as text/plain!!!
|
|
1253 Solution: Also support DtDND_TEXT_TRANSFER
|
|
1254 perhaps implementation of the Motif protocol
|
|
1255 (which is the base of CDE) will clear this */
|
|
1256 l_type = Qdragdrop_MIME;
|
|
1257 record_unwind_protect(abort_current_drag, Qnil);
|
|
1258 drag_not_done = 1;
|
|
1259 for (ii = 0; ii < transferInfo->dropData->numItems; ii++)
|
|
1260 {
|
|
1261 /* let us forget this name thing for now... */
|
|
1262 /* filePath = transferInfo->dropData->data.buffers[ii].name;
|
|
1263 path = (filePath == NULL) ? Qnil
|
867
|
1264 : make_string ((Ibyte *)filePath, strlen (filePath)); */
|
428
|
1265 /* what, if the data is no text, and how can I tell it? */
|
867
|
1266 l_data = Fcons ( list3 ( list1 ( make_string ((Ibyte *)"text/plain", 10) ),
|
|
1267 make_string ((Ibyte *)"8bit", 4),
|
|
1268 make_string ((Ibyte *)transferInfo->dropData->data.buffers[ii].bp,
|
428
|
1269 transferInfo->dropData->data.buffers[ii].size) ),
|
|
1270 l_data );
|
|
1271 }
|
|
1272 drag_not_done = 0;
|
771
|
1273 unbind_to (speccount);
|
428
|
1274 }
|
|
1275 else /* the other cases: NOOP_TRANSFER */
|
|
1276 enqueue=0;
|
|
1277
|
|
1278 /* The Problem: no button and mods from CDE... */
|
|
1279 if (enqueue)
|
|
1280 enqueue_misc_user_event_pos ( frame, Qdragdrop_drop_dispatch,
|
|
1281 Fcons (l_type, l_data),
|
|
1282 0 /* this is the button */,
|
|
1283 0 /* these are the mods */,
|
|
1284 transferInfo->x,
|
|
1285 transferInfo->y);
|
|
1286
|
|
1287 UNGCPRO;
|
|
1288 return;
|
|
1289 }
|
|
1290 #endif /* HAVE_CDE */
|
|
1291
|
|
1292 #ifdef HAVE_OFFIX_DND
|
|
1293
|
|
1294 DEFUN ("offix-start-drag-internal", Foffix_start_drag_internal, 2, 3, 0, /*
|
|
1295 Start a OffiX drag from a buffer.
|
|
1296 First arg is the event that started the drag,
|
|
1297 second arg should be some string, and the third
|
|
1298 is the type of the data (this should be an int).
|
|
1299 The type defaults to DndText (4).
|
|
1300 */
|
|
1301 (event, data, dtyp))
|
|
1302 {
|
|
1303 if (EVENTP(event))
|
|
1304 {
|
|
1305 struct frame *f = decode_x_frame (Fselected_frame (Qnil));
|
|
1306 XEvent x_event;
|
|
1307 Widget wid = FRAME_X_TEXT_WIDGET (f);
|
|
1308 Display *display = XtDisplayOfObject (wid);
|
|
1309 struct device *d = get_device_from_display (display);
|
|
1310 struct x_device *xd = DEVICE_X_DATA (d);
|
|
1311 XWindowAttributes win_attrib;
|
647
|
1312 int modifier = 0, state = 0;
|
428
|
1313 char *dnd_data = NULL;
|
647
|
1314 long dnd_len = 0;
|
428
|
1315 int dnd_typ = DndText, dnd_dealloc = 0;
|
440
|
1316 Lisp_Event *lisp_event = XEVENT (event);
|
428
|
1317
|
|
1318 /* only drag if this is really a press */
|
|
1319 if (EVENT_TYPE(lisp_event) != button_press_event)
|
|
1320 return Qnil;
|
|
1321
|
|
1322 /* get the desired type */
|
|
1323 if (!NILP (dtyp) && INTP (dtyp))
|
|
1324 dnd_typ = XINT (dtyp);
|
|
1325
|
|
1326 if (dnd_typ == DndFiles)
|
|
1327 {
|
|
1328 Lisp_Object run = data;
|
|
1329 int len = 0;
|
|
1330
|
|
1331 if (NILP ( Flistp (data)))
|
|
1332 return Qnil;
|
|
1333
|
|
1334 /* construct the data from a list of files */
|
|
1335 dnd_len = 1;
|
|
1336 dnd_data = (char *) xmalloc (1);
|
|
1337 *dnd_data = 0;
|
|
1338 while (!NILP (run))
|
|
1339 {
|
|
1340 if (!STRINGP (XCAR (run)))
|
|
1341 {
|
1726
|
1342 xfree (dnd_data, char *);
|
428
|
1343 return Qnil;
|
|
1344 }
|
|
1345 len = XSTRING_LENGTH (XCAR (run)) + 1;
|
|
1346 dnd_data = (char *) xrealloc (dnd_data, dnd_len + len);
|
442
|
1347 strcpy (dnd_data + dnd_len - 1, (const char *)XSTRING_DATA (XCAR (run)));
|
428
|
1348 dnd_len += len;
|
|
1349 run = XCDR (run);
|
|
1350 }
|
|
1351
|
|
1352 dnd_data[dnd_len - 1] = 0; /* the list-ending zero */
|
|
1353 dnd_dealloc = 1;
|
|
1354
|
|
1355 }
|
|
1356 else
|
|
1357 {
|
|
1358 if (!STRINGP (data))
|
|
1359 return Qnil;
|
|
1360
|
|
1361 /* and what's with MULE data ??? */
|
|
1362 dnd_data = (char *)XSTRING_DATA (data);
|
|
1363 dnd_len = XSTRING_LENGTH (data) + 1; /* the zero */
|
|
1364
|
|
1365 }
|
|
1366
|
|
1367 /* not so gross hack that converts an emacs event back to a XEvent */
|
|
1368
|
|
1369 x_event.xbutton.type = ButtonPress;
|
|
1370 x_event.xbutton.send_event = False;
|
|
1371 x_event.xbutton.display = XtDisplayOfObject(wid);
|
|
1372 x_event.xbutton.window = XtWindowOfObject(wid);
|
|
1373 x_event.xbutton.root = XRootWindow(x_event.xkey.display, 0);
|
|
1374 x_event.xbutton.subwindow = 0;
|
|
1375 x_event.xbutton.time = lisp_event->timestamp;
|
1204
|
1376 x_event.xbutton.x = EVENT_BUTTON_X (lisp_event);
|
|
1377 x_event.xbutton.y = EVENT_BUTTON_Y (lisp_event);
|
428
|
1378 if (Success == XGetWindowAttributes (x_event.xbutton.display,
|
|
1379 x_event.xbutton.window,
|
|
1380 &win_attrib))
|
|
1381 {
|
1204
|
1382 x_event.xbutton.x_root = win_attrib.x + EVENT_BUTTON_X (lisp_event);
|
|
1383 x_event.xbutton.y_root = win_attrib.y + EVENT_BUTTON_Y (lisp_event);
|
428
|
1384 }
|
|
1385 else
|
|
1386 {
|
1204
|
1387 x_event.xbutton.x_root = EVENT_BUTTON_X (lisp_event); /* this is wrong */
|
|
1388 x_event.xbutton.y_root = EVENT_BUTTON_Y (lisp_event);
|
428
|
1389 }
|
|
1390
|
1204
|
1391 modifier = EVENT_BUTTON_MODIFIERS (lisp_event);
|
442
|
1392 if (modifier & XEMACS_MOD_SHIFT) state |= ShiftMask;
|
|
1393 if (modifier & XEMACS_MOD_CONTROL) state |= ControlMask;
|
|
1394 if (modifier & XEMACS_MOD_META) state |= xd->MetaMask;
|
|
1395 if (modifier & XEMACS_MOD_SUPER) state |= xd->SuperMask;
|
|
1396 if (modifier & XEMACS_MOD_HYPER) state |= xd->HyperMask;
|
|
1397 if (modifier & XEMACS_MOD_ALT) state |= xd->AltMask;
|
1204
|
1398 state |= Button1Mask << (EVENT_BUTTON_BUTTON (lisp_event)-1);
|
428
|
1399
|
|
1400 x_event.xbutton.state = state;
|
1204
|
1401 x_event.xbutton.button = EVENT_BUTTON_BUTTON (lisp_event);
|
428
|
1402 x_event.xkey.same_screen = True;
|
|
1403
|
|
1404 DndSetData(dnd_typ, (unsigned char *)dnd_data, dnd_len);
|
|
1405 if (dnd_dealloc)
|
1726
|
1406 xfree (dnd_data, char *);
|
428
|
1407
|
|
1408 /* the next thing blocks everything... */
|
|
1409 if (DndHandleDragging(wid, &x_event))
|
|
1410 return Qt;
|
|
1411 }
|
|
1412 return Qnil;
|
|
1413 }
|
|
1414
|
|
1415 #endif /* HAVE_OFFIX_DND */
|
|
1416
|
|
1417
|
|
1418 /************************************************************************/
|
|
1419 /* widget creation */
|
|
1420 /************************************************************************/
|
|
1421
|
|
1422 /* The widget hierarchy is
|
|
1423
|
|
1424 argv[0] shell container FRAME-NAME
|
|
1425 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1426
|
|
1427 We accept geometry specs in this order:
|
|
1428
|
|
1429 *FRAME-NAME.geometry
|
|
1430 *EmacsFrame.geometry
|
|
1431 Emacs.geometry
|
|
1432
|
|
1433 Other possibilities for widget hierarchies might be
|
|
1434
|
|
1435 argv[0] frame container FRAME-NAME
|
|
1436 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1437 or
|
|
1438 argv[0] FRAME-NAME container FRAME-NAME
|
|
1439 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1440 or
|
|
1441 argv[0] FRAME-NAME container emacsTextPane
|
|
1442 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1443
|
|
1444 #ifdef EXTERNAL_WIDGET
|
|
1445 The ExternalShell widget is simply a replacement for the Shell widget
|
|
1446 which is able to deal with using an externally-supplied window instead
|
|
1447 of always creating its own.
|
|
1448 #endif
|
|
1449
|
|
1450 */
|
|
1451
|
|
1452 #ifdef EXTERNAL_WIDGET
|
|
1453
|
|
1454 static int
|
|
1455 is_valid_window (Window w, struct device *d)
|
|
1456 {
|
|
1457 XWindowAttributes xwa;
|
|
1458 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1459
|
|
1460 expect_x_error (dpy);
|
|
1461 XGetWindowAttributes (dpy, w, &xwa);
|
|
1462 return !x_error_occurred_p (dpy);
|
|
1463 }
|
|
1464
|
|
1465 #endif /* EXTERNAL_WIDGET */
|
|
1466
|
|
1467 /* This sends a synthetic mouse-motion event to the frame, if the mouse
|
|
1468 is over the frame. This ensures that the cursor gets set properly
|
|
1469 before the user moves the mouse for the first time. */
|
|
1470
|
|
1471 static void
|
|
1472 x_send_synthetic_mouse_event (struct frame *f)
|
|
1473 {
|
|
1474 /* #### write this function. */
|
|
1475 }
|
|
1476
|
|
1477 static int
|
|
1478 first_x_frame_p (struct frame *f)
|
|
1479 {
|
|
1480 Lisp_Object rest = DEVICE_FRAME_LIST (XDEVICE (f->device));
|
|
1481 while (!NILP (rest) &&
|
|
1482 (f == XFRAME (XCAR (rest)) ||
|
|
1483 !FRAME_X_P (XFRAME (XCAR (rest)))))
|
|
1484 rest = XCDR (rest);
|
|
1485 return NILP (rest);
|
|
1486 }
|
|
1487
|
|
1488 /* Figure out what size the EmacsFrame widget should initially be,
|
|
1489 and set it. Should be called after the default font has been
|
|
1490 determined but before the widget has been realized. */
|
|
1491
|
|
1492 static void
|
|
1493 x_initialize_frame_size (struct frame *f)
|
|
1494 {
|
|
1495 /* Geometry of the AppShell */
|
|
1496 int app_flags = 0;
|
|
1497 int app_x = 0;
|
|
1498 int app_y = 0;
|
|
1499 unsigned int app_w = 0;
|
|
1500 unsigned int app_h = 0;
|
|
1501
|
|
1502 /* Geometry of the EmacsFrame */
|
|
1503 int frame_flags = 0;
|
|
1504 int frame_x = 0;
|
|
1505 int frame_y = 0;
|
|
1506 unsigned int frame_w = 0;
|
|
1507 unsigned int frame_h = 0;
|
|
1508
|
|
1509 /* Hairily merged geometry */
|
|
1510 int x = 0;
|
|
1511 int y = 0;
|
|
1512 unsigned int w = 80;
|
|
1513 unsigned int h = 40;
|
|
1514 int flags = 0;
|
|
1515
|
|
1516 char *geom = 0, *ew_geom = 0;
|
|
1517 Boolean iconic_p = False, ew_iconic_p = False;
|
|
1518
|
|
1519 Widget wmshell = FRAME_X_SHELL_WIDGET (f);
|
|
1520 /* #### This may not be an ApplicationShell any more, with the 'popup
|
|
1521 frame property. */
|
|
1522 Widget app_shell = XtParent (wmshell);
|
|
1523 Widget ew = FRAME_X_TEXT_WIDGET (f);
|
|
1524
|
|
1525 /* set the position of the frame's root window now. When the
|
|
1526 frame was created, the position was initialized to (0,0). */
|
|
1527 {
|
|
1528 struct window *win = XWINDOW (f->root_window);
|
|
1529
|
442
|
1530 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f)
|
|
1531 + FRAME_LEFT_GUTTER_BOUNDS (f);
|
|
1532 WINDOW_TOP (win) = FRAME_TOP_BORDER_END (f)
|
|
1533 + FRAME_TOP_GUTTER_BOUNDS (f);
|
428
|
1534
|
|
1535 if (!NILP (f->minibuffer_window))
|
|
1536 {
|
|
1537 win = XWINDOW (f->minibuffer_window);
|
442
|
1538 WINDOW_LEFT (win) = FRAME_LEFT_BORDER_END (f)
|
|
1539 + FRAME_LEFT_GUTTER_BOUNDS (f);
|
428
|
1540 }
|
|
1541 }
|
|
1542
|
|
1543 #ifdef EXTERNAL_WIDGET
|
|
1544 /* If we're an external widget, then the size of the frame is predetermined
|
|
1545 (by the client) and is not our decision to make. */
|
|
1546 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1547 return;
|
|
1548 #endif
|
|
1549
|
|
1550 #if 0
|
|
1551 /* #### this junk has not been tested; therefore it's
|
|
1552 probably wrong. Doesn't really matter at this point because
|
|
1553 currently all frames are either top-level or external widgets. */
|
|
1554
|
|
1555 /* If we're not our own top-level window, then we shouldn't go messing around
|
|
1556 with top-level shells or "Emacs.geometry" or any such stuff. Therefore,
|
|
1557 we do as follows to determine the size of the frame:
|
|
1558
|
|
1559 1) If a value for the frame's "geometry" resource was specified, then
|
|
1560 use it. (This specifies a size in characters.)
|
|
1561 2) Else, if the "width" and "height" resources were specified, then
|
|
1562 leave them alone. (This is a value in pixels. Sorry, we can't break
|
|
1563 Xt conventions here.)
|
|
1564 3) Else, assume a size of 64x12. (This is somewhat arbitrary, but
|
|
1565 it's unlikely that a size of 80x40 is desirable because we're probably
|
|
1566 inside of a dialog box.)
|
|
1567
|
|
1568 Set the widget's x, y, height, and width as determined. Don't set the
|
|
1569 top-level container widget, because we don't necessarily know what it
|
|
1570 is. (Assume it is smart and pays attention to our values.)
|
|
1571 */
|
|
1572
|
|
1573 if (!FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
1574 {
|
|
1575 Xt_GET_VALUE (ew, XtNgeometry, &ew_geom);
|
|
1576 if (ew_geom)
|
|
1577 frame_flags = XParseGeometry (ew_geom,
|
|
1578 &frame_x, &frame_y,
|
|
1579 &frame_w, &frame_h);
|
|
1580 if (! (frame_flags & (WidthValue | HeightValue)))
|
|
1581 {
|
|
1582 Arg al[2];
|
|
1583 XtSetArg (al [0], XtNwidth, &frame_w);
|
|
1584 XtSetArg (al [1], XtNheight, &frame_h);
|
|
1585 XtGetValues (ew, al, 2);
|
|
1586 if (!frame_w && !frame_h)
|
|
1587 {
|
|
1588 frame_w = 64;
|
|
1589 frame_h = 12;
|
|
1590 frame_flags |= WidthValue | HeightValue;
|
|
1591 }
|
|
1592 }
|
|
1593 if (frame_flags & (WidthValue | HeightValue))
|
|
1594 EmacsFrameSetCharSize (ew, frame_w, frame_h);
|
|
1595 if (frame_flags & (XValue | YValue))
|
|
1596 {
|
|
1597 Arg al[2];
|
|
1598 XtSetArg (al [0], XtNwidth, &frame_w);
|
|
1599 XtSetArg (al [1], XtNheight, &frame_h);
|
|
1600 XtGetValues (ew, al, 2);
|
|
1601
|
|
1602 if (frame_flags & XNegative)
|
|
1603 frame_x += frame_w;
|
|
1604 if (frame_flags & YNegative)
|
|
1605 frame_y += frame_h;
|
|
1606
|
|
1607 XtSetArg (al [0], XtNx, frame_x);
|
|
1608 XtSetArg (al [1], XtNy, frame_y);
|
|
1609 XtSetValues (ew, al, 2);
|
|
1610 }
|
|
1611 return;
|
|
1612 }
|
|
1613 #endif
|
|
1614
|
|
1615 /* OK, we're a top-level shell. */
|
|
1616
|
|
1617 if (!XtIsWMShell (wmshell))
|
|
1618 abort ();
|
|
1619
|
|
1620 /* If the EmacsFrame doesn't have a geometry but the shell does,
|
|
1621 treat that as the geometry of the frame.
|
|
1622 (Is this bogus? I'm not sure.) */
|
|
1623
|
|
1624 Xt_GET_VALUE (ew, XtNgeometry, &ew_geom);
|
|
1625 if (!ew_geom)
|
|
1626 {
|
|
1627 Xt_GET_VALUE (wmshell, XtNgeometry, &geom);
|
|
1628 if (geom)
|
|
1629 {
|
|
1630 ew_geom = geom;
|
|
1631 Xt_SET_VALUE (ew, XtNgeometry, ew_geom);
|
|
1632 }
|
|
1633 }
|
|
1634
|
|
1635 /* If the Shell is iconic, then the EmacsFrame is iconic.
|
|
1636 (Is this bogus? I'm not sure.) */
|
|
1637 Xt_GET_VALUE (ew, XtNiconic, &ew_iconic_p);
|
|
1638 if (!ew_iconic_p)
|
|
1639 {
|
|
1640 Xt_GET_VALUE (wmshell, XtNiconic, &iconic_p);
|
|
1641 if (iconic_p)
|
|
1642 {
|
|
1643 ew_iconic_p = iconic_p;
|
|
1644 Xt_SET_VALUE (ew, XtNiconic, iconic_p);
|
|
1645 }
|
|
1646 }
|
|
1647
|
|
1648 Xt_GET_VALUE (app_shell, XtNgeometry, &geom);
|
|
1649 if (geom)
|
|
1650 app_flags = XParseGeometry (geom, &app_x, &app_y, &app_w, &app_h);
|
|
1651
|
|
1652 if (ew_geom)
|
|
1653 frame_flags = XParseGeometry (ew_geom,
|
|
1654 &frame_x, &frame_y,
|
|
1655 &frame_w, &frame_h);
|
|
1656
|
|
1657 if (first_x_frame_p (f))
|
|
1658 {
|
|
1659 /* If this is the first frame created:
|
|
1660 ====================================
|
|
1661
|
|
1662 - Use the ApplicationShell's size/position, if specified.
|
|
1663 (This is "Emacs.geometry", or the "-geometry" command line arg.)
|
|
1664 - Else use the EmacsFrame's size/position.
|
|
1665 (This is "*FRAME-NAME.geometry")
|
|
1666
|
|
1667 - If the AppShell is iconic, the frame should be iconic.
|
|
1668
|
|
1669 AppShell comes first so that -geometry always applies to the first
|
|
1670 frame created, even if there is an "every frame" entry in the
|
|
1671 resource database.
|
|
1672 */
|
|
1673 if (app_flags & (XValue | YValue))
|
|
1674 {
|
|
1675 x = app_x; y = app_y;
|
|
1676 flags |= (app_flags & (XValue | YValue | XNegative | YNegative));
|
|
1677 }
|
|
1678 else if (frame_flags & (XValue | YValue))
|
|
1679 {
|
|
1680 x = frame_x; y = frame_y;
|
|
1681 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative));
|
|
1682 }
|
|
1683
|
|
1684 if (app_flags & (WidthValue | HeightValue))
|
|
1685 {
|
|
1686 w = app_w; h = app_h;
|
|
1687 flags |= (app_flags & (WidthValue | HeightValue));
|
|
1688 }
|
|
1689 else if (frame_flags & (WidthValue | HeightValue))
|
|
1690 {
|
|
1691 w = frame_w; h = frame_h;
|
|
1692 flags |= (frame_flags & (WidthValue | HeightValue));
|
|
1693 }
|
|
1694
|
|
1695 /* If the AppShell is iconic, then the EmacsFrame is iconic. */
|
|
1696 if (!ew_iconic_p)
|
|
1697 {
|
|
1698 Xt_GET_VALUE (app_shell, XtNiconic, &iconic_p);
|
|
1699 if (iconic_p)
|
|
1700 {
|
|
1701 ew_iconic_p = iconic_p;
|
|
1702 Xt_SET_VALUE (ew, XtNiconic, iconic_p);
|
|
1703 }
|
|
1704 }
|
|
1705 }
|
|
1706 else
|
|
1707 {
|
|
1708 /* If this is not the first frame created:
|
|
1709 ========================================
|
|
1710
|
|
1711 - use the EmacsFrame's size/position if specified
|
|
1712 - Otherwise, use the ApplicationShell's size, but not position.
|
|
1713
|
|
1714 So that means that one can specify the position of the first frame
|
|
1715 with "Emacs.geometry" or `-geometry'; but can only specify the
|
|
1716 position of subsequent frames with "*FRAME-NAME.geometry".
|
|
1717
|
|
1718 AppShell comes second so that -geometry does not apply to subsequent
|
|
1719 frames when there is an "every frame" entry in the resource db,
|
|
1720 but does apply to the first frame.
|
|
1721 */
|
|
1722 if (frame_flags & (XValue | YValue))
|
|
1723 {
|
|
1724 x = frame_x; y = frame_y;
|
|
1725 flags |= (frame_flags & (XValue | YValue | XNegative | YNegative));
|
|
1726 }
|
|
1727
|
|
1728 if (frame_flags & (WidthValue | HeightValue))
|
|
1729 {
|
|
1730 w = frame_w; h = frame_h;
|
|
1731 flags |= (frame_flags & (WidthValue | HeightValue));
|
|
1732 }
|
|
1733 else if (app_flags & (WidthValue | HeightValue))
|
|
1734 {
|
|
1735 w = app_w;
|
|
1736 h = app_h;
|
|
1737 flags |= (app_flags & (WidthValue | HeightValue));
|
|
1738 }
|
|
1739 }
|
|
1740
|
|
1741 x_set_initial_frame_size (f, flags, x, y, w, h);
|
|
1742 }
|
|
1743
|
|
1744 static void
|
|
1745 x_get_layout_sizes (struct frame *f, Dimension *topbreadth)
|
|
1746 {
|
|
1747 int i;
|
|
1748
|
|
1749 /* compute height of all top-area widgets */
|
|
1750 for (i=0, *topbreadth = 0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
1751 {
|
|
1752 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
1753 if (wid && XtIsManaged (wid))
|
|
1754 *topbreadth += wid->core.height + 2*wid->core.border_width;
|
|
1755 }
|
|
1756 }
|
|
1757
|
|
1758 static void
|
|
1759 x_layout_widgets (Widget w, XtPointer client_data, XtPointer call_data)
|
|
1760 {
|
|
1761 struct frame *f = (struct frame *) client_data;
|
|
1762 EmacsManagerResizeStruct *emst = (EmacsManagerResizeStruct *) call_data;
|
|
1763 Dimension width = emst->width;
|
|
1764 Dimension height = emst->height;
|
|
1765 Widget text = FRAME_X_TEXT_WIDGET (f);
|
|
1766 Dimension textbord = text->core.border_width;
|
|
1767 Dimension topbreadth;
|
|
1768 Position text_x = 0, text_y = 0;
|
|
1769 int i;
|
|
1770
|
|
1771 x_get_layout_sizes (f, &topbreadth);
|
|
1772
|
|
1773 /* first the menubar and psheets ... */
|
|
1774 for (i=0; i<FRAME_X_NUM_TOP_WIDGETS (f); i++)
|
|
1775 {
|
|
1776 Widget wid = FRAME_X_TOP_WIDGETS (f)[i];
|
|
1777 if (wid && XtIsManaged (wid))
|
|
1778 {
|
|
1779 Dimension bord = wid->core.border_width;
|
|
1780 XtConfigureWidget (wid, 0, text_y,
|
|
1781 width - 2*bord, wid->core.height,
|
|
1782 bord);
|
|
1783 text_y += wid->core.height + 2*bord;
|
|
1784 }
|
|
1785 }
|
|
1786
|
|
1787 #ifdef HAVE_SCROLLBARS
|
|
1788 f->scrollbar_y_offset = topbreadth + textbord;
|
|
1789 #endif
|
|
1790
|
|
1791 /* finally the text area */
|
|
1792 XtConfigureWidget (text, text_x, text_y,
|
|
1793 width - 2*textbord,
|
|
1794 height - text_y - 2*textbord,
|
|
1795 textbord);
|
|
1796 }
|
|
1797
|
|
1798 static void
|
|
1799 x_do_query_geometry (Widget w, XtPointer client_data, XtPointer call_data)
|
|
1800 {
|
|
1801 struct frame *f = (struct frame *) client_data;
|
|
1802 EmacsManagerQueryGeometryStruct *emst =
|
|
1803 (EmacsManagerQueryGeometryStruct *) call_data;
|
|
1804 Widget text = FRAME_X_TEXT_WIDGET (f);
|
|
1805 Dimension textbord = text->core.border_width;
|
|
1806 Dimension topbreadth;
|
|
1807 XtWidgetGeometry req, repl;
|
|
1808 int mask = emst->request_mode & (CWWidth | CWHeight);
|
|
1809
|
|
1810 x_get_layout_sizes (f, &topbreadth);
|
|
1811
|
|
1812 /* Strip away menubar from suggested size, and ask the text widget
|
|
1813 what size it wants to be. */
|
|
1814 req.request_mode = mask;
|
|
1815 if (mask & CWWidth)
|
|
1816 req.width = emst->proposed_width - 2*textbord;
|
|
1817 if (mask & CWHeight)
|
|
1818 req.height = emst->proposed_height - topbreadth - 2*textbord;
|
|
1819 XtQueryGeometry (text, &req, &repl);
|
|
1820
|
|
1821 /* Now add the menubar back again */
|
|
1822 emst->proposed_width = repl.width + 2*textbord;
|
|
1823 emst->proposed_height = repl.height + topbreadth + 2*textbord;
|
|
1824 }
|
|
1825
|
|
1826 /* Creates the widgets for a frame.
|
|
1827 lisp_window_id is a Lisp description of an X window or Xt
|
|
1828 widget to parse.
|
|
1829
|
|
1830 This function does not create or map the windows. (That is
|
|
1831 done by x_popup_frame().)
|
|
1832 */
|
|
1833 static void
|
|
1834 x_create_widgets (struct frame *f, Lisp_Object lisp_window_id,
|
|
1835 Lisp_Object parent)
|
|
1836 {
|
|
1837 struct device *d = XDEVICE (f->device);
|
|
1838 Visual *visual = DEVICE_X_VISUAL (d);
|
|
1839 int depth = DEVICE_X_DEPTH (d);
|
|
1840 Colormap cmap = DEVICE_X_COLORMAP (d);
|
|
1841 #ifdef EXTERNAL_WIDGET
|
|
1842 Window window_id = 0;
|
|
1843 #endif
|
442
|
1844 const char *name;
|
428
|
1845 Arg al [25];
|
|
1846 int ac = 0;
|
|
1847 Widget text, container, shell;
|
|
1848 Widget parentwid = 0;
|
|
1849 #ifdef HAVE_MENUBARS
|
|
1850 int menubar_visible;
|
|
1851 Widget menubar;
|
|
1852 #endif
|
|
1853
|
|
1854 if (STRINGP (f->name))
|
442
|
1855 LISP_STRING_TO_EXTERNAL (f->name, name, Qctext);
|
428
|
1856 else
|
|
1857 name = "emacs";
|
|
1858
|
|
1859 /* The widget hierarchy is
|
|
1860
|
|
1861 argv[0] shell pane FRAME-NAME
|
|
1862 ApplicationShell EmacsShell EmacsManager EmacsFrame
|
|
1863
|
|
1864 (the type of the shell is ExternalShell if this frame is running
|
|
1865 in another client's window)
|
|
1866
|
|
1867 However the EmacsShell widget has WM_CLASS of FRAME-NAME/Emacs.
|
|
1868 Normally such shells have name/class shellname/appclass, which in this
|
|
1869 case would be "shell/Emacs" instead of "frame-name/Emacs". We could
|
|
1870 also get around this by naming the shell "frame-name", but that would
|
|
1871 be confusing because the text area (the EmacsFrame widget inferior of
|
|
1872 the shell) is also called that. So we just set the WM_CLASS property.
|
|
1873 */
|
|
1874
|
|
1875 #ifndef EXTERNAL_WIDGET
|
|
1876 if (!NILP (lisp_window_id))
|
563
|
1877 signal_error (Qunimplemented, "support for external widgets was not enabled at compile-time", Qunbound);
|
428
|
1878 #else
|
|
1879 if (!NILP (lisp_window_id))
|
|
1880 {
|
|
1881 char *string;
|
|
1882
|
|
1883 CHECK_STRING (lisp_window_id);
|
|
1884 string = (char *) XSTRING_DATA (lisp_window_id);
|
|
1885 if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X'))
|
|
1886 sscanf (string+2, "%lxu", &window_id);
|
|
1887 #if 0
|
|
1888 else if (string[0] == 'w')
|
|
1889 {
|
|
1890 sscanf (string+1, "%x", &parent_widget);
|
|
1891 if (parent_widget)
|
|
1892 window_id = XtWindow (parent_widget);
|
|
1893 }
|
|
1894 #endif
|
|
1895 else
|
|
1896 sscanf (string, "%lu", &window_id);
|
|
1897 if (!is_valid_window (window_id, d))
|
563
|
1898 signal_ferror (Qinvalid_argument, "Invalid window %lu",
|
|
1899 (unsigned long) window_id);
|
428
|
1900 FRAME_X_EXTERNAL_WINDOW_P (f) = 1;
|
|
1901 } else
|
|
1902 #endif /* EXTERNAL_WIDGET */
|
|
1903 FRAME_X_TOP_LEVEL_FRAME_P (f) = 1;
|
|
1904
|
|
1905 ac = 0;
|
|
1906 XtSetArg (al[ac], XtNallowShellResize, True); ac++;
|
|
1907 #ifdef LWLIB_USES_MOTIF
|
|
1908 /* Motif sucks beans. Without this in here, it will delete the window
|
|
1909 out from under us when it receives a WM_DESTROY_WINDOW message
|
|
1910 from the WM. */
|
|
1911 XtSetArg (al[ac], XmNdeleteResponse, XmDO_NOTHING); ac++;
|
|
1912 #endif
|
|
1913
|
|
1914 #ifdef EXTERNAL_WIDGET
|
|
1915 if (window_id)
|
|
1916 {
|
|
1917 XtSetArg (al[ac], XtNwindow, window_id); ac++;
|
|
1918 }
|
|
1919 else
|
|
1920 #endif /* EXTERNAL_WIDGET */
|
|
1921 {
|
|
1922 XtSetArg (al[ac], XtNinput, True); ac++;
|
|
1923 XtSetArg (al[ac], XtNminWidthCells, 10); ac++;
|
|
1924 XtSetArg (al[ac], XtNminHeightCells, 1); ac++;
|
|
1925 XtSetArg (al[ac], XtNvisual, visual); ac++;
|
|
1926 XtSetArg (al[ac], XtNdepth, depth); ac++;
|
|
1927 XtSetArg (al[ac], XtNcolormap, cmap); ac++;
|
|
1928 }
|
|
1929
|
|
1930 if (!NILP (parent))
|
|
1931 {
|
|
1932 parentwid = FRAME_X_SHELL_WIDGET (XFRAME (parent));
|
|
1933 XtSetArg (al[ac], XtNtransientFor, parentwid); ac++;
|
|
1934 }
|
|
1935
|
|
1936 shell = XtCreatePopupShell ("shell",
|
|
1937 (
|
|
1938 #ifdef EXTERNAL_WIDGET
|
|
1939 window_id ? externalShellWidgetClass :
|
|
1940 #endif
|
|
1941 parentwid ? transientEmacsShellWidgetClass :
|
|
1942 topLevelEmacsShellWidgetClass
|
|
1943 ),
|
|
1944 parentwid ? parentwid :
|
|
1945 DEVICE_XT_APP_SHELL (d),
|
|
1946 al, ac);
|
|
1947 FRAME_X_SHELL_WIDGET (f) = shell;
|
|
1948 maybe_set_frame_title_format (shell);
|
|
1949
|
|
1950 /* Create the manager widget */
|
|
1951 ac = 0;
|
|
1952 XtSetArg (al[ac], XtNvisual, visual); ac++;
|
|
1953 XtSetArg (al[ac], XtNdepth, depth); ac++;
|
|
1954 XtSetArg (al[ac], XtNcolormap, cmap); ac++;
|
|
1955
|
|
1956 container = XtCreateWidget ("container",
|
|
1957 emacsManagerWidgetClass, shell, al, ac);
|
|
1958 FRAME_X_CONTAINER_WIDGET (f) = container;
|
|
1959 XtAddCallback (container, XtNresizeCallback, x_layout_widgets,
|
|
1960 (XtPointer) f);
|
|
1961 XtAddCallback (container, XtNqueryGeometryCallback, x_do_query_geometry,
|
|
1962 (XtPointer) f);
|
|
1963
|
|
1964 /* Create the text area */
|
|
1965 ac = 0;
|
|
1966 XtSetArg (al[ac], XtNvisual, visual); ac++;
|
|
1967 XtSetArg (al[ac], XtNdepth, depth); ac++;
|
|
1968 XtSetArg (al[ac], XtNcolormap, cmap); ac++;
|
|
1969 XtSetArg (al[ac], XtNborderWidth, 0); ac++; /* should this be settable? */
|
|
1970 XtSetArg (al[ac], XtNemacsFrame, f); ac++;
|
|
1971 text = XtCreateWidget (name, emacsFrameClass, container, al, ac);
|
|
1972 FRAME_X_TEXT_WIDGET (f) = text;
|
|
1973
|
|
1974 #ifdef HAVE_MENUBARS
|
|
1975 /* Create the initial menubar widget. */
|
|
1976 menubar_visible = x_initialize_frame_menubar (f);
|
|
1977 FRAME_X_TOP_WIDGETS (f)[0] = menubar = FRAME_X_MENUBAR_WIDGET (f);
|
|
1978 FRAME_X_NUM_TOP_WIDGETS (f) = 1;
|
|
1979
|
|
1980 if (menubar_visible)
|
|
1981 XtManageChild (menubar);
|
|
1982 #endif /* HAVE_MENUBARS */
|
|
1983 XtManageChild (text);
|
|
1984 XtManageChild (container);
|
|
1985 }
|
|
1986
|
|
1987 /* We used to call XtPopup() in x_popup_frame, but that doesn't give
|
|
1988 you control over whether the widget is initially mapped or not
|
|
1989 because XtPopup() makes an unconditional call to XMapRaised().
|
|
1990 Boy, those Xt designers were clever.
|
|
1991
|
|
1992 When we first removed it we only kept the XtRealizeWidget call in
|
|
1993 XtPopup. For everything except HP's that was enough. For HP's,
|
|
1994 though, the failure to call the popup callbacks resulted in XEmacs
|
|
1995 not accepting any input. Bizarre but true. Stupid but true.
|
|
1996
|
|
1997 So, in case there are any other gotchas floating out there along
|
|
1998 the same lines I've duplicated the majority of XtPopup here. It
|
|
1999 assumes no grabs and that the widget is not already popped up, both
|
|
2000 valid assumptions for the one place this is called from. */
|
|
2001 static void
|
|
2002 xemacs_XtPopup (Widget widget)
|
|
2003 {
|
|
2004 ShellWidget shell_widget = (ShellWidget) widget;
|
|
2005 XtGrabKind call_data = XtGrabNone;
|
|
2006
|
|
2007 XtCallCallbacks (widget, XtNpopupCallback, (XtPointer)&call_data);
|
|
2008
|
|
2009 shell_widget->shell.popped_up = TRUE;
|
|
2010 shell_widget->shell.grab_kind = XtGrabNone;
|
|
2011 shell_widget->shell.spring_loaded = False;
|
|
2012
|
|
2013 if (shell_widget->shell.create_popup_child_proc != NULL)
|
|
2014 (*(shell_widget->shell.create_popup_child_proc))(widget);
|
|
2015
|
|
2016 /* The XtSetValues below are not in XtPopup menu. We just want to
|
|
2017 make absolutely sure... */
|
|
2018 Xt_SET_VALUE (widget, XtNmappedWhenManaged, False);
|
|
2019 XtRealizeWidget (widget);
|
|
2020 Xt_SET_VALUE (widget, XtNmappedWhenManaged, True);
|
|
2021 }
|
|
2022
|
|
2023 /* create the windows for the specified frame and display them.
|
|
2024 Note that the widgets have already been created, and any
|
|
2025 necessary geometry calculations have already been done. */
|
|
2026 static void
|
|
2027 x_popup_frame (struct frame *f)
|
|
2028 {
|
|
2029 Widget shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
2030 Widget frame_widget = FRAME_X_TEXT_WIDGET (f);
|
|
2031 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
2032
|
|
2033 /* Before mapping the window, make sure that the WMShell's notion of
|
|
2034 whether it should be iconified is synchronized with the EmacsFrame's
|
|
2035 notion.
|
|
2036 */
|
|
2037 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
2038 x_wm_set_shell_iconic_p (shell_widget,
|
|
2039 ((EmacsFrame) frame_widget)
|
|
2040 ->emacs_frame.iconic);
|
|
2041
|
|
2042 xemacs_XtPopup (shell_widget);
|
|
2043
|
|
2044 if (!((EmacsFrame) frame_widget)->emacs_frame.initially_unmapped)
|
|
2045 XtMapWidget (shell_widget);
|
|
2046 else
|
|
2047 {
|
|
2048 /* We may have set f->visible to 1 in x_init_frame(), so undo
|
|
2049 that now. */
|
|
2050 FRAME_X_TOTALLY_VISIBLE_P (f) = 0;
|
|
2051 f->visible = 0;
|
|
2052 }
|
|
2053
|
|
2054 #ifdef EXTERNAL_WIDGET
|
|
2055 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
2056 ExternalShellReady (shell_widget, XtWindow (frame_widget), KeyPressMask);
|
|
2057 else
|
|
2058 #endif
|
|
2059 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
2060 {
|
|
2061 /* tell the window manager about us. */
|
|
2062 x_wm_store_class_hints (shell_widget, XtName (frame_widget));
|
|
2063
|
|
2064 #ifndef HAVE_WMCOMMAND
|
|
2065 x_wm_maybe_store_wm_command (f);
|
|
2066 #endif /* HAVE_WMCOMMAND */
|
|
2067
|
|
2068 x_wm_hack_wm_protocols (shell_widget);
|
|
2069 }
|
|
2070
|
|
2071 #ifdef HAVE_XIM
|
|
2072 XIM_init_frame (f);
|
|
2073 #endif /* HAVE_XIM */
|
|
2074
|
|
2075 #ifdef HACK_EDITRES
|
|
2076 /* Allow XEmacs to respond to EditRes requests. See the O'Reilly Xt */
|
|
2077 /* Intrinsics Programming Manual, Motif Edition, Aug 1993, Sect 14.14, */
|
|
2078 /* pp. 483-493. */
|
|
2079 XtAddEventHandler (shell_widget, /* the shell widget in question */
|
|
2080 (EventMask) NoEventMask,/* OR with existing mask */
|
|
2081 True, /* called on non-maskable events? */
|
|
2082 (XtEventHandler) _XEditResCheckMessages, /* the handler */
|
|
2083 NULL);
|
|
2084 #endif /* HACK_EDITRES */
|
|
2085
|
|
2086 #ifdef HAVE_CDE
|
|
2087 {
|
|
2088 XtCallbackRec dnd_transfer_cb_rec[2];
|
|
2089
|
|
2090 dnd_transfer_cb_rec[0].callback = x_cde_transfer_callback;
|
|
2091 dnd_transfer_cb_rec[0].closure = (XtPointer) f;
|
|
2092 dnd_transfer_cb_rec[1].callback = NULL;
|
|
2093 dnd_transfer_cb_rec[1].closure = NULL;
|
|
2094
|
|
2095 DtDndVaDropRegister (FRAME_X_TEXT_WIDGET (f),
|
|
2096 DtDND_FILENAME_TRANSFER | DtDND_BUFFER_TRANSFER,
|
|
2097 XmDROP_COPY, dnd_transfer_cb_rec,
|
|
2098 DtNtextIsBuffer, True,
|
|
2099 DtNregisterChildren, True,
|
|
2100 DtNpreserveRegistration, False,
|
|
2101 NULL);
|
|
2102 }
|
|
2103 #endif /* HAVE_CDE */
|
|
2104
|
|
2105 /* Do a stupid property change to force the server to generate a
|
|
2106 propertyNotify event so that the event_stream server timestamp will
|
|
2107 be initialized to something relevant to the time we created the window.
|
|
2108 */
|
|
2109 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
|
|
2110 DEVICE_XATOM_WM_PROTOCOLS (d), XA_ATOM, 32, PropModeAppend,
|
|
2111 (unsigned char*) NULL, 0);
|
|
2112
|
|
2113 x_send_synthetic_mouse_event (f);
|
|
2114 }
|
|
2115
|
|
2116 static void
|
|
2117 allocate_x_frame_struct (struct frame *f)
|
|
2118 {
|
|
2119 /* zero out all slots. */
|
|
2120 f->frame_data = xnew_and_zero (struct x_frame);
|
|
2121
|
|
2122 /* yeah, except the lisp ones */
|
1346
|
2123 FRAME_X_LAST_MENUBAR_BUFFER (f) = Qnil;
|
428
|
2124 FRAME_X_ICON_PIXMAP (f) = Qnil;
|
|
2125 FRAME_X_ICON_PIXMAP_MASK (f) = Qnil;
|
|
2126 }
|
|
2127
|
|
2128
|
|
2129 /************************************************************************/
|
|
2130 /* Lisp functions */
|
|
2131 /************************************************************************/
|
|
2132
|
|
2133 static void
|
771
|
2134 x_init_frame_1 (struct frame *f, Lisp_Object props,
|
|
2135 int frame_name_is_defaulted)
|
428
|
2136 {
|
|
2137 /* This function can GC */
|
|
2138 Lisp_Object device = FRAME_DEVICE (f);
|
|
2139 Lisp_Object lisp_window_id = Fplist_get (props, Qwindow_id, Qnil);
|
|
2140 Lisp_Object popup = Fplist_get (props, Qpopup, Qnil);
|
|
2141
|
|
2142 if (!NILP (popup))
|
|
2143 {
|
|
2144 if (EQ (popup, Qt))
|
|
2145 popup = Fselected_frame (device);
|
|
2146 CHECK_LIVE_FRAME (popup);
|
|
2147 if (!EQ (device, FRAME_DEVICE (XFRAME (popup))))
|
563
|
2148 invalid_argument_2 ("Parent must be on same device as frame",
|
|
2149 device, popup);
|
428
|
2150 }
|
|
2151
|
|
2152 /*
|
|
2153 * Previously we set this only if NILP (DEVICE_SELECTED_FRAME (d))
|
|
2154 * to make sure that messages were displayed as soon as possible
|
|
2155 * if we're creating the first frame on a device. But it is
|
|
2156 * better to just set this all the time, so that when a new frame
|
|
2157 * is created that covers the selected frame, echo area status
|
|
2158 * messages can still be seen. f->visible is reset later if the
|
|
2159 * initially-unmapped property is found to be non-nil in the
|
|
2160 * frame properties.
|
|
2161 */
|
|
2162 f->visible = 1;
|
|
2163
|
|
2164 allocate_x_frame_struct (f);
|
|
2165 x_create_widgets (f, lisp_window_id, popup);
|
|
2166 }
|
|
2167
|
|
2168 static void
|
|
2169 x_init_frame_2 (struct frame *f, Lisp_Object props)
|
|
2170 {
|
|
2171 /* Set up the values of the widget/frame. A case could be made for putting
|
|
2172 this inside of the widget's initialize method. */
|
|
2173
|
|
2174 update_frame_face_values (f);
|
|
2175 x_initialize_frame_size (f);
|
|
2176 /* Kyle:
|
|
2177 * update_frame_title() can't be done here, because some of the
|
|
2178 * modeline specs depend on the frame's device having a selected
|
|
2179 * frame, and that may not have been set up yet. The redisplay
|
|
2180 * will update the frame title anyway, so nothing is lost.
|
|
2181 * JV:
|
|
2182 * It turns out it gives problems with FVWMs name based mapping.
|
|
2183 * We'll just need to be careful in the modeline specs.
|
|
2184 */
|
|
2185 update_frame_title (f);
|
|
2186 }
|
|
2187
|
|
2188 static void
|
|
2189 x_init_frame_3 (struct frame *f)
|
|
2190 {
|
|
2191 /* Pop up the frame. */
|
|
2192
|
|
2193 x_popup_frame (f);
|
|
2194 }
|
|
2195
|
|
2196 static void
|
|
2197 x_mark_frame (struct frame *f)
|
|
2198 {
|
1346
|
2199 mark_object (FRAME_X_LAST_MENUBAR_BUFFER (f));
|
428
|
2200 mark_object (FRAME_X_ICON_PIXMAP (f));
|
|
2201 mark_object (FRAME_X_ICON_PIXMAP_MASK (f));
|
|
2202 }
|
|
2203
|
|
2204 static void
|
|
2205 x_set_frame_icon (struct frame *f)
|
|
2206 {
|
|
2207 Pixmap x_pixmap, x_mask;
|
|
2208
|
|
2209 if (IMAGE_INSTANCEP (f->icon)
|
|
2210 && IMAGE_INSTANCE_PIXMAP_TYPE_P (XIMAGE_INSTANCE (f->icon)))
|
|
2211 {
|
|
2212 x_pixmap = XIMAGE_INSTANCE_X_PIXMAP (f->icon);
|
|
2213 x_mask = XIMAGE_INSTANCE_X_MASK (f->icon);
|
|
2214 }
|
|
2215 else
|
|
2216 {
|
|
2217 x_pixmap = 0;
|
|
2218 x_mask = 0;
|
|
2219 }
|
|
2220
|
|
2221 /* Store the X data into the widget. */
|
|
2222 {
|
|
2223 Arg al [2];
|
|
2224 XtSetArg (al [0], XtNiconPixmap, x_pixmap);
|
|
2225 XtSetArg (al [1], XtNiconMask, x_mask);
|
|
2226 XtSetValues (FRAME_X_SHELL_WIDGET (f), al, 2);
|
|
2227 }
|
|
2228 }
|
|
2229
|
|
2230 static void
|
|
2231 x_set_frame_pointer (struct frame *f)
|
|
2232 {
|
|
2233 XDefineCursor (XtDisplay (FRAME_X_TEXT_WIDGET (f)),
|
|
2234 XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
2235 XIMAGE_INSTANCE_X_CURSOR (f->pointer));
|
|
2236 XSync (XtDisplay (FRAME_X_TEXT_WIDGET (f)), 0);
|
|
2237 }
|
|
2238
|
|
2239 static Lisp_Object
|
|
2240 x_get_frame_parent (struct frame *f)
|
|
2241 {
|
|
2242 Widget parentwid = 0;
|
|
2243
|
|
2244 Xt_GET_VALUE (FRAME_X_SHELL_WIDGET (f), XtNtransientFor, &parentwid);
|
|
2245 /* find the frame whose wid is parentwid */
|
|
2246 if (parentwid)
|
|
2247 {
|
|
2248 Lisp_Object frmcons;
|
|
2249 DEVICE_FRAME_LOOP (frmcons, XDEVICE (FRAME_DEVICE (f)))
|
|
2250 {
|
|
2251 Lisp_Object frame = XCAR (frmcons);
|
|
2252 if (FRAME_X_SHELL_WIDGET (XFRAME (frame)) == parentwid)
|
|
2253 return frame;
|
|
2254 }
|
|
2255 }
|
|
2256 return Qnil;
|
|
2257 }
|
|
2258
|
|
2259 DEFUN ("x-window-id", Fx_window_id, 0, 1, 0, /*
|
|
2260 Get the ID of the X11 window.
|
|
2261 This gives us a chance to manipulate the Emacs window from within a
|
|
2262 different program. Since the ID is an unsigned long, we return it as
|
|
2263 a string.
|
|
2264 */
|
|
2265 (frame))
|
|
2266 {
|
867
|
2267 Ibyte str[255];
|
428
|
2268 struct frame *f = decode_x_frame (frame);
|
|
2269
|
771
|
2270 qxesprintf (str, "%lu", XtWindow (FRAME_X_TEXT_WIDGET (f)));
|
|
2271 return build_intstring (str);
|
428
|
2272 }
|
|
2273
|
|
2274
|
|
2275 /************************************************************************/
|
|
2276 /* manipulating the X window */
|
|
2277 /************************************************************************/
|
|
2278
|
|
2279 static void
|
|
2280 x_set_frame_position (struct frame *f, int xoff, int yoff)
|
|
2281 {
|
|
2282 Widget w = FRAME_X_SHELL_WIDGET (f);
|
|
2283 Display *dpy = XtDisplay (w);
|
|
2284 Dimension frame_w = DisplayWidth (dpy, DefaultScreen (dpy));
|
|
2285 Dimension frame_h = DisplayHeight (dpy, DefaultScreen (dpy));
|
|
2286 Dimension shell_w, shell_h, shell_bord;
|
|
2287 int win_gravity;
|
|
2288 Arg al [3];
|
|
2289
|
|
2290 XtSetArg (al [0], XtNwidth, &shell_w);
|
|
2291 XtSetArg (al [1], XtNheight, &shell_h);
|
|
2292 XtSetArg (al [2], XtNborderWidth, &shell_bord);
|
|
2293 XtGetValues (w, al, 3);
|
|
2294
|
|
2295 win_gravity =
|
|
2296 xoff >= 0 && yoff >= 0 ? NorthWestGravity :
|
|
2297 xoff >= 0 ? SouthWestGravity :
|
|
2298 yoff >= 0 ? NorthEastGravity :
|
|
2299 SouthEastGravity;
|
|
2300 if (xoff < 0)
|
|
2301 xoff += frame_w - shell_w - 2*shell_bord;
|
|
2302 if (yoff < 0)
|
|
2303 yoff += frame_h - shell_h - 2*shell_bord;
|
|
2304
|
|
2305 /* Update the hints so that, if this window is currently iconified, it will
|
|
2306 come back at the right place. We can't look at s->visible to determine
|
|
2307 whether it is iconified because it might not be up-to-date yet (the queue
|
|
2308 might not be processed). */
|
|
2309 XtSetArg (al [0], XtNwinGravity, win_gravity);
|
|
2310 XtSetArg (al [1], XtNx, xoff);
|
|
2311 XtSetArg (al [2], XtNy, yoff);
|
|
2312 XtSetValues (w, al, 3);
|
|
2313
|
|
2314 /* Sometimes you will find that
|
|
2315
|
|
2316 (set-frame-position (selected-frame) -50 -50)
|
|
2317
|
|
2318 doesn't put the frame where you expect it to: i.e. it's closer to
|
|
2319 the lower-right corner than it should be, and it appears that the
|
|
2320 size of the WM decorations was not taken into account. This is
|
|
2321 *not* a problem with this function. Both mwm and twm have bugs
|
|
2322 in handling this situation. (mwm ignores the window gravity and
|
|
2323 always assumes NorthWest, except the first time you map the
|
|
2324 window; twm gets things almost right, but forgets to account for
|
|
2325 the border width of the top-level window.) This function does
|
|
2326 what it's supposed to according to the ICCCM, and I'm not about
|
|
2327 to hack around window-manager bugs. */
|
|
2328
|
|
2329 #if 0
|
|
2330 /* This is not necessary under either mwm or twm */
|
|
2331 x_wm_mark_shell_position_user_specified (w);
|
|
2332 #endif
|
|
2333 }
|
|
2334
|
|
2335 /* Call this to change the size of frame S's x-window. */
|
|
2336
|
|
2337 static void
|
|
2338 x_set_frame_size (struct frame *f, int cols, int rows)
|
|
2339 {
|
|
2340 EmacsFrameSetCharSize (FRAME_X_TEXT_WIDGET (f), cols, rows);
|
|
2341 #if 0
|
|
2342 /* this is not correct. x_set_frame_size() is called from
|
|
2343 Fset_frame_size(), which may or may not have been called
|
|
2344 by the user (e.g. update_EmacsFrame() calls it when the font
|
|
2345 changes). For now, don't bother with getting this right. */
|
|
2346 x_wm_mark_shell_size_user_specified (FRAME_X_SHELL_WIDGET (f));
|
|
2347 #endif
|
|
2348 }
|
|
2349
|
|
2350 static void
|
|
2351 x_set_mouse_position (struct window *w, int x, int y)
|
|
2352 {
|
|
2353 struct frame *f = XFRAME (w->frame);
|
|
2354
|
|
2355 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2356 XWarpPointer (display, None, XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
2357 0, 0, 0, 0, w->pixel_left + x, w->pixel_top + y);
|
|
2358 }
|
|
2359
|
|
2360 static int
|
|
2361 x_get_mouse_position (struct device *d, Lisp_Object *frame, int *x, int *y)
|
|
2362 {
|
|
2363 Display *display = DEVICE_X_DISPLAY (d);
|
|
2364 Window child_window;
|
|
2365 Window root_window;
|
|
2366 Window win;
|
|
2367 int root_x, root_y;
|
|
2368 int win_x, win_y;
|
|
2369 unsigned int keys_and_buttons;
|
|
2370 struct frame *f;
|
|
2371
|
|
2372 if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
|
|
2373 &root_window, &child_window, &root_x, &root_y,
|
|
2374 &win_x, &win_y, &keys_and_buttons) == False)
|
|
2375 return 0;
|
|
2376
|
|
2377 if (child_window == None)
|
|
2378 return 0; /* not over any window. */
|
|
2379
|
|
2380 while (1)
|
|
2381 {
|
|
2382 win = child_window;
|
|
2383 if (XTranslateCoordinates (display, root_window, win, root_x, root_y,
|
|
2384 &win_x, &win_y, &child_window) == False)
|
|
2385 /* Huh? */
|
|
2386 return 0;
|
|
2387
|
|
2388 if (child_window == None)
|
|
2389 break;
|
|
2390 }
|
|
2391
|
|
2392 /* At this point, win is the innermost window containing the pointer
|
|
2393 and win_x and win_y are the coordinates of that window. */
|
|
2394 f = x_any_window_to_frame (d, win);
|
|
2395 if (!f)
|
|
2396 return 0;
|
793
|
2397 *frame = wrap_frame (f);
|
428
|
2398
|
|
2399 if (XTranslateCoordinates (display, win,
|
|
2400 XtWindow (FRAME_X_TEXT_WIDGET (f)),
|
|
2401 win_x, win_y, x, y, &child_window) == False)
|
|
2402 /* Huh? */
|
|
2403 return 0;
|
|
2404
|
|
2405 return 1;
|
|
2406 }
|
|
2407
|
|
2408 static void
|
|
2409 x_cant_notify_wm_error (void)
|
|
2410 {
|
563
|
2411 signal_error (Qgui_error, "Can't notify window manager of iconification", Qunbound);
|
428
|
2412 }
|
|
2413
|
|
2414 /* Raise frame F. */
|
|
2415 static void
|
|
2416 x_raise_frame_1 (struct frame *f, int force)
|
|
2417 {
|
|
2418 if (FRAME_VISIBLE_P (f) || force)
|
|
2419 {
|
|
2420 Widget bottom_dialog;
|
|
2421 XWindowChanges xwc;
|
|
2422 unsigned int flags;
|
|
2423 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2424 Window emacs_window = XtWindow (FRAME_X_SHELL_WIDGET (f));
|
|
2425
|
|
2426 /* first raises all the dialog boxes, then put emacs just below the
|
|
2427 * bottom most dialog box */
|
|
2428 bottom_dialog = lw_raise_all_pop_up_widgets ();
|
|
2429 if (bottom_dialog && XtWindow (bottom_dialog))
|
|
2430 {
|
|
2431 xwc.sibling = XtWindow (bottom_dialog);
|
|
2432 xwc.stack_mode = Below;
|
|
2433 flags = CWSibling | CWStackMode;
|
|
2434 }
|
|
2435 else
|
|
2436 {
|
|
2437 xwc.stack_mode = Above;
|
|
2438 flags = CWStackMode;
|
|
2439 }
|
|
2440
|
|
2441 if (!XReconfigureWMWindow (display, emacs_window,
|
|
2442 DefaultScreen (display),
|
|
2443 flags, &xwc))
|
|
2444 x_cant_notify_wm_error ();
|
|
2445 }
|
|
2446 }
|
|
2447
|
|
2448 static void
|
|
2449 x_raise_frame (struct frame *f)
|
|
2450 {
|
|
2451 x_raise_frame_1 (f, 1);
|
|
2452 }
|
|
2453
|
|
2454 /* Lower frame F. */
|
|
2455 static void
|
|
2456 x_lower_frame (struct frame *f)
|
|
2457 {
|
|
2458 if (FRAME_VISIBLE_P (f))
|
|
2459 {
|
|
2460 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2461 XWindowChanges xwc;
|
|
2462 unsigned int flags = CWStackMode;
|
|
2463
|
|
2464 xwc.stack_mode = Below;
|
|
2465 if (!XReconfigureWMWindow (display, XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2466 DefaultScreen (display), flags, &xwc))
|
|
2467 x_cant_notify_wm_error ();
|
|
2468 }
|
|
2469 }
|
|
2470
|
442
|
2471 static void
|
|
2472 x_enable_frame (struct frame *f)
|
|
2473 {
|
|
2474 XtSetSensitive (FRAME_X_SHELL_WIDGET (f), True);
|
|
2475 }
|
|
2476
|
|
2477 static void
|
|
2478 x_disable_frame (struct frame *f)
|
|
2479 {
|
|
2480 XtSetSensitive (FRAME_X_SHELL_WIDGET (f), False);
|
|
2481 }
|
|
2482
|
428
|
2483 /* Change from withdrawn state to mapped state. */
|
|
2484 static void
|
|
2485 x_make_frame_visible (struct frame *f)
|
|
2486 {
|
|
2487 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2488
|
|
2489 if (!FRAME_VISIBLE_P(f))
|
|
2490 XMapRaised (display, XtWindow (FRAME_X_SHELL_WIDGET (f)));
|
|
2491 else
|
|
2492 x_raise_frame_1 (f, 0);
|
|
2493 }
|
|
2494
|
|
2495 /* Change from mapped state to withdrawn state. */
|
|
2496 static void
|
|
2497 x_make_frame_invisible (struct frame *f)
|
|
2498 {
|
|
2499 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2500
|
|
2501 if (!FRAME_VISIBLE_P(f))
|
|
2502 return;
|
|
2503
|
|
2504 if (!XWithdrawWindow (display,
|
|
2505 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2506 DefaultScreen (display)))
|
|
2507 x_cant_notify_wm_error ();
|
|
2508 }
|
|
2509
|
|
2510 static int
|
|
2511 x_frame_visible_p (struct frame *f)
|
|
2512 {
|
|
2513 #if 0
|
593
|
2514
|
|
2515 /* #### Ben suggests using x_frame_window_state (f) == NormalState. */
|
|
2516
|
428
|
2517 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2518 XWindowAttributes xwa;
|
|
2519 int result;
|
|
2520
|
|
2521 /* JV:
|
|
2522 This is bad, very bad :-(
|
|
2523 It is not compatible with our tristate visible and
|
|
2524 it should never ever change the visibility for us, this leads to
|
|
2525 the frame-freeze problem under fvwm because with the pager
|
|
2526
|
|
2527 Mappedness != Viewability != Visibility != Emacs f->visible
|
|
2528
|
|
2529 This first unequalness is the reason for the frame freezing problem
|
|
2530 under fvwm (it happens when the frame is another fvwm-page)
|
|
2531
|
|
2532 The second unequalness happen when it is on the same fvwm-page
|
|
2533 but in an invisible part of the visible screen.
|
|
2534
|
|
2535 For now we just return the XEmacs internal value --- which might not be up
|
|
2536 to date. Is that a problem? ---. Otherwise we should
|
|
2537 use async visibility like in standard Emacs.
|
|
2538 */
|
|
2539
|
|
2540 if (!XGetWindowAttributes (display,
|
|
2541 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2542 &xwa))
|
|
2543 result = 0;
|
|
2544 else
|
|
2545 result = xwa.map_state == IsViewable;
|
|
2546 /* In this implementation it should at least be != IsUnmapped
|
|
2547 JV */
|
|
2548
|
|
2549 f->visible = result;
|
|
2550 return result;
|
|
2551 #endif /* 0 */
|
|
2552
|
|
2553 return f->visible;
|
|
2554 }
|
|
2555
|
|
2556 static int
|
|
2557 x_frame_totally_visible_p (struct frame *f)
|
|
2558 {
|
|
2559 return FRAME_X_TOTALLY_VISIBLE_P (f);
|
|
2560 }
|
|
2561
|
|
2562 /* Change window state from mapped to iconified. */
|
|
2563 static void
|
|
2564 x_iconify_frame (struct frame *f)
|
|
2565 {
|
|
2566 Display *display = DEVICE_X_DISPLAY (XDEVICE (f->device));
|
|
2567
|
|
2568 if (!XIconifyWindow (display,
|
|
2569 XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
2570 DefaultScreen (display)))
|
|
2571 x_cant_notify_wm_error ();
|
|
2572
|
|
2573 f->iconified = 1;
|
|
2574 }
|
|
2575
|
|
2576 /* Sets the X focus to frame f. */
|
|
2577 static void
|
|
2578 x_focus_on_frame (struct frame *f)
|
|
2579 {
|
|
2580 XWindowAttributes xwa;
|
|
2581 Widget shell_widget;
|
|
2582 int viewable = 0;
|
|
2583
|
|
2584 assert (FRAME_X_P (f));
|
|
2585
|
|
2586 shell_widget = FRAME_X_SHELL_WIDGET (f);
|
|
2587 if (!XtWindow (shell_widget))
|
|
2588 return;
|
|
2589
|
|
2590 #ifdef EXTERNAL_WIDGET
|
|
2591 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
2592 ExternalShellSetFocus (shell_widget);
|
|
2593 #endif /* EXTERNAL_WIDGET */
|
|
2594
|
|
2595 /* Do the ICCCM focus change if the window is still visible.
|
|
2596 The s->visible flag might not be up-to-date, because we might
|
|
2597 not have processed magic events recently. So make a server
|
|
2598 round-trip to find out whether it's really mapped right now.
|
|
2599 We grab the server to do this, because that's the only way to
|
|
2600 eliminate the race condition.
|
|
2601 */
|
|
2602 XGrabServer (XtDisplay (shell_widget));
|
|
2603 if (XGetWindowAttributes (XtDisplay (shell_widget),
|
|
2604 XtWindow (shell_widget),
|
|
2605 &xwa))
|
|
2606 /* JV: it is bad to change the visibility like this, so we don't for the
|
|
2607 moment, at least change_frame_visibility should be called
|
|
2608 Note also that under fvwm a frame can be Viewable (and thus Mapped)
|
|
2609 but still X-invisible
|
|
2610 f->visible = xwa.map_state == IsViewable; */
|
|
2611 viewable = xwa.map_state == IsViewable;
|
|
2612
|
|
2613
|
|
2614 if (viewable)
|
|
2615 {
|
|
2616 Window focus;
|
|
2617 int revert_to;
|
|
2618 XGetInputFocus (XtDisplay (shell_widget), &focus, &revert_to);
|
|
2619 /* Don't explicitly set the focus on this window unless the focus
|
|
2620 was on some other window (not PointerRoot). Note that, even when
|
|
2621 running a point-to-type window manager like *twm, there is always
|
|
2622 a focus window; the window manager maintains that based on the
|
|
2623 mouse position. If you set the "NoTitleFocus" option in these
|
|
2624 window managers, then the server itself maintains the focus via
|
|
2625 PointerRoot, and changing that to focus on the window would make
|
|
2626 the window grab the focus. Very bad.
|
|
2627 */
|
|
2628 if (focus != PointerRoot)
|
|
2629 {
|
|
2630 XSetInputFocus (XtDisplay (shell_widget),
|
|
2631 XtWindow (shell_widget),
|
|
2632 RevertToParent,
|
|
2633 DEVICE_X_MOUSE_TIMESTAMP
|
|
2634 (XDEVICE (FRAME_DEVICE (f))));
|
|
2635 XFlush (XtDisplay (shell_widget));
|
|
2636 }
|
|
2637 }
|
|
2638 XUngrabServer (XtDisplay (shell_widget));
|
|
2639 XFlush (XtDisplay (shell_widget)); /* hey, I'd like to DEBUG this... */
|
|
2640 }
|
|
2641
|
450
|
2642 /* Destroy the X window of frame F. */
|
428
|
2643 static void
|
|
2644 x_delete_frame (struct frame *f)
|
|
2645 {
|
|
2646 Display *dpy;
|
|
2647
|
|
2648 #ifndef HAVE_WMCOMMAND
|
|
2649 if (FRAME_X_TOP_LEVEL_FRAME_P (f))
|
|
2650 x_wm_maybe_move_wm_command (f);
|
|
2651 #endif /* HAVE_WMCOMMAND */
|
|
2652
|
|
2653 #ifdef HAVE_CDE
|
|
2654 DtDndDropUnregister (FRAME_X_TEXT_WIDGET (f));
|
|
2655 #endif /* HAVE_CDE */
|
|
2656
|
|
2657 assert (FRAME_X_SHELL_WIDGET (f) != 0);
|
|
2658 dpy = XtDisplay (FRAME_X_SHELL_WIDGET (f));
|
|
2659
|
|
2660 #ifdef EXTERNAL_WIDGET
|
1024
|
2661 expect_x_error (dpy);
|
428
|
2662 /* for obscure reasons having (I think) to do with the internal
|
|
2663 window-to-widget hierarchy maintained by Xt, we have to call
|
|
2664 XtUnrealizeWidget() here. Xt can really suck. */
|
|
2665 if (f->being_deleted)
|
|
2666 XtUnrealizeWidget (FRAME_X_SHELL_WIDGET (f));
|
|
2667 XtDestroyWidget (FRAME_X_SHELL_WIDGET (f));
|
1024
|
2668 x_error_occurred_p (dpy);
|
428
|
2669 #else
|
|
2670 XtDestroyWidget (FRAME_X_SHELL_WIDGET (f));
|
|
2671 /* make sure the windows are really gone! */
|
440
|
2672 /* #### Is this REALLY necessary? */
|
428
|
2673 XFlush (dpy);
|
|
2674 #endif /* EXTERNAL_WIDGET */
|
|
2675
|
|
2676 FRAME_X_SHELL_WIDGET (f) = 0;
|
|
2677
|
|
2678 if (FRAME_X_GEOM_FREE_ME_PLEASE (f))
|
|
2679 {
|
1726
|
2680 xfree (FRAME_X_GEOM_FREE_ME_PLEASE (f), char *);
|
428
|
2681 FRAME_X_GEOM_FREE_ME_PLEASE (f) = 0;
|
|
2682 }
|
|
2683
|
|
2684 if (f->frame_data)
|
|
2685 {
|
1726
|
2686 xfree (f->frame_data, void *);
|
428
|
2687 f->frame_data = 0;
|
|
2688 }
|
|
2689 }
|
|
2690
|
|
2691 static void
|
|
2692 x_update_frame_external_traits (struct frame* frm, Lisp_Object name)
|
|
2693 {
|
|
2694 Arg al[10];
|
|
2695 int ac = 0;
|
793
|
2696 Lisp_Object frame = wrap_frame (frm);
|
|
2697
|
428
|
2698
|
|
2699 if (EQ (name, Qforeground))
|
|
2700 {
|
|
2701 Lisp_Object color = FACE_FOREGROUND (Vdefault_face, frame);
|
|
2702 XColor fgc;
|
|
2703
|
|
2704 if (!EQ (color, Vthe_null_color_instance))
|
|
2705 {
|
|
2706 fgc = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color));
|
|
2707 XtSetArg (al[ac], XtNforeground, (void *) fgc.pixel); ac++;
|
|
2708 }
|
|
2709 }
|
|
2710 else if (EQ (name, Qbackground))
|
|
2711 {
|
|
2712 Lisp_Object color = FACE_BACKGROUND (Vdefault_face, frame);
|
|
2713 XColor bgc;
|
|
2714
|
|
2715 if (!EQ (color, Vthe_null_color_instance))
|
|
2716 {
|
|
2717 bgc = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color));
|
|
2718 XtSetArg (al[ac], XtNbackground, (void *) bgc.pixel); ac++;
|
|
2719 }
|
|
2720
|
|
2721 /* Really crappy way to force the modeline shadows to be
|
|
2722 redrawn. But effective. */
|
|
2723 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (frm);
|
|
2724 MARK_FRAME_CHANGED (frm);
|
|
2725 }
|
|
2726 else if (EQ (name, Qfont))
|
|
2727 {
|
|
2728 Lisp_Object font = FACE_FONT (Vdefault_face, frame, Vcharset_ascii);
|
|
2729
|
|
2730 if (!EQ (font, Vthe_null_font_instance))
|
1746
|
2731 {
|
|
2732 XtSetArg (al[ac], XtNfont,
|
|
2733 (void *) FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font)));
|
|
2734 ac++;
|
|
2735 }
|
428
|
2736 }
|
|
2737 else
|
|
2738 abort ();
|
|
2739
|
|
2740 XtSetValues (FRAME_X_TEXT_WIDGET (frm), al, ac);
|
|
2741
|
|
2742 #ifdef HAVE_TOOLBARS
|
|
2743 /* Setting the background clears the entire frame area
|
|
2744 including the toolbar so we force an immediate redraw of
|
|
2745 it. */
|
|
2746 if (EQ (name, Qbackground))
|
|
2747 MAYBE_DEVMETH (XDEVICE (frm->device), redraw_frame_toolbars, (frm));
|
|
2748 #endif /* HAVE_TOOLBARS */
|
|
2749
|
|
2750 /* Set window manager resize increment hints according to
|
|
2751 the new character size */
|
|
2752 if (EQ (name, Qfont))
|
|
2753 EmacsFrameRecomputeCellSize (FRAME_X_TEXT_WIDGET (frm));
|
|
2754 }
|
|
2755
|
|
2756
|
|
2757 /************************************************************************/
|
|
2758 /* initialization */
|
|
2759 /************************************************************************/
|
|
2760
|
|
2761 void
|
|
2762 syms_of_frame_x (void)
|
|
2763 {
|
563
|
2764 DEFSYMBOL (Qx_resource_name);
|
428
|
2765
|
|
2766 DEFSUBR (Fx_window_id);
|
|
2767 #ifdef HAVE_CDE
|
|
2768 DEFSUBR (Fcde_start_drag_internal);
|
|
2769 #endif
|
|
2770 #ifdef HAVE_OFFIX_DND
|
|
2771 DEFSUBR (Foffix_start_drag_internal);
|
|
2772 #endif
|
|
2773 }
|
|
2774
|
|
2775 void
|
|
2776 console_type_create_frame_x (void)
|
|
2777 {
|
|
2778 /* frame methods */
|
|
2779 CONSOLE_HAS_METHOD (x, init_frame_1);
|
|
2780 CONSOLE_HAS_METHOD (x, init_frame_2);
|
|
2781 CONSOLE_HAS_METHOD (x, init_frame_3);
|
|
2782 CONSOLE_HAS_METHOD (x, mark_frame);
|
|
2783 CONSOLE_HAS_METHOD (x, focus_on_frame);
|
|
2784 CONSOLE_HAS_METHOD (x, delete_frame);
|
|
2785 CONSOLE_HAS_METHOD (x, get_mouse_position);
|
|
2786 CONSOLE_HAS_METHOD (x, set_mouse_position);
|
|
2787 CONSOLE_HAS_METHOD (x, raise_frame);
|
|
2788 CONSOLE_HAS_METHOD (x, lower_frame);
|
442
|
2789 CONSOLE_HAS_METHOD (x, enable_frame);
|
|
2790 CONSOLE_HAS_METHOD (x, disable_frame);
|
428
|
2791 CONSOLE_HAS_METHOD (x, make_frame_visible);
|
|
2792 CONSOLE_HAS_METHOD (x, make_frame_invisible);
|
|
2793 CONSOLE_HAS_METHOD (x, iconify_frame);
|
|
2794 CONSOLE_HAS_METHOD (x, set_frame_size);
|
|
2795 CONSOLE_HAS_METHOD (x, set_frame_position);
|
|
2796 CONSOLE_HAS_METHOD (x, frame_property);
|
|
2797 CONSOLE_HAS_METHOD (x, internal_frame_property_p);
|
|
2798 CONSOLE_HAS_METHOD (x, frame_properties);
|
|
2799 CONSOLE_HAS_METHOD (x, set_frame_properties);
|
867
|
2800 CONSOLE_HAS_METHOD (x, set_title_from_ibyte);
|
|
2801 CONSOLE_HAS_METHOD (x, set_icon_name_from_ibyte);
|
428
|
2802 CONSOLE_HAS_METHOD (x, frame_visible_p);
|
|
2803 CONSOLE_HAS_METHOD (x, frame_totally_visible_p);
|
|
2804 CONSOLE_HAS_METHOD (x, frame_iconified_p);
|
|
2805 CONSOLE_HAS_METHOD (x, set_frame_pointer);
|
|
2806 CONSOLE_HAS_METHOD (x, set_frame_icon);
|
|
2807 CONSOLE_HAS_METHOD (x, get_frame_parent);
|
|
2808 CONSOLE_HAS_METHOD (x, update_frame_external_traits);
|
|
2809 }
|
|
2810
|
|
2811 void
|
|
2812 vars_of_frame_x (void)
|
|
2813 {
|
|
2814 #ifdef EXTERNAL_WIDGET
|
|
2815 Fprovide (intern ("external-widget"));
|
|
2816 #endif
|
|
2817
|
|
2818 /* this call uses only safe functions from emacs.c */
|
|
2819 init_x_prop_symbols ();
|
|
2820
|
|
2821 DEFVAR_LISP ("default-x-frame-plist", &Vdefault_x_frame_plist /*
|
|
2822 Plist of default frame-creation properties for X frames.
|
|
2823 These override what is specified in the resource database and in
|
|
2824 `default-frame-plist', but are overridden by the arguments to the
|
|
2825 particular call to `make-frame'.
|
|
2826
|
|
2827 Note: In many cases, properties of a frame are available as specifiers
|
|
2828 instead of through the frame-properties mechanism.
|
|
2829
|
|
2830 Here is a list of recognized frame properties, other than those
|
|
2831 documented in `set-frame-properties' (they can be queried and
|
|
2832 set at any time, except as otherwise noted):
|
|
2833
|
|
2834 window-id The X window ID corresponding to the
|
|
2835 frame. May be set only at startup, and
|
|
2836 only if external widget support was
|
|
2837 compiled in; doing so causes the frame
|
|
2838 to be created as an "external widget"
|
|
2839 in another program that uses an existing
|
|
2840 window in the program rather than creating
|
|
2841 a new one.
|
|
2842 initially-unmapped If non-nil, the frame will not be visible
|
|
2843 when it is created. In this case, you
|
|
2844 need to call `make-frame-visible' to make
|
|
2845 the frame appear.
|
|
2846 popup If non-nil, it should be a frame, and this
|
|
2847 frame will be created as a "popup" frame
|
|
2848 whose parent is the given frame. This
|
|
2849 will make the window manager treat the
|
|
2850 frame as a dialog box, which may entail
|
|
2851 doing different things (e.g. not asking
|
|
2852 for positioning, and not iconifying
|
|
2853 separate from its parent).
|
|
2854 inter-line-space Not currently implemented.
|
|
2855 toolbar-shadow-thickness Thickness of toolbar shadows.
|
|
2856 background-toolbar-color Color of toolbar background.
|
|
2857 bottom-toolbar-shadow-color Color of bottom shadows on toolbars.
|
|
2858 (*Not* specific to the bottom-toolbar.)
|
|
2859 top-toolbar-shadow-color Color of top shadows on toolbars.
|
|
2860 (*Not* specific to the top-toolbar.)
|
|
2861 internal-border-width Width of internal border around text area.
|
|
2862 border-width Width of external border around text area.
|
|
2863 top Y position (in pixels) of the upper-left
|
|
2864 outermost corner of the frame (i.e. the
|
|
2865 upper-left of the window-manager
|
|
2866 decorations).
|
|
2867 left X position (in pixels) of the upper-left
|
|
2868 outermost corner of the frame (i.e. the
|
|
2869 upper-left of the window-manager
|
|
2870 decorations).
|
|
2871 border-color Color of external border around text area.
|
|
2872 cursor-color Color of text cursor.
|
|
2873
|
|
2874 See also `default-frame-plist', which specifies properties which apply
|
|
2875 to all frames, not just X frames.
|
|
2876 */ );
|
|
2877 Vdefault_x_frame_plist = Qnil;
|
|
2878
|
|
2879 x_console_methods->device_specific_frame_props = &Vdefault_x_frame_plist;
|
|
2880 }
|