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