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