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