1 /* Generic frame functions.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Copyright (C) 1995, 1996 Ben Wing.
4 Copyright (C) 1995 Sun Microsystems, Inc.
6 This file is part of SXEmacs
8 SXEmacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 SXEmacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* Synched up with: FSF 19.30. */
24 /* This file has been Mule-ized. */
29 #include "buffer.h" /* for Vbuffer_alist */
31 #define INCLUDE_EVENTS_H_PRIVATE_SPHERE
32 #include "events/events.h"
39 #include "redisplay.h"
40 #include "scrollbar.h"
43 Lisp_Object Vselect_frame_hook, Qselect_frame_hook;
44 Lisp_Object Vdeselect_frame_hook, Qdeselect_frame_hook;
45 Lisp_Object Vcreate_frame_hook, Qcreate_frame_hook;
46 Lisp_Object Vdelete_frame_hook, Qdelete_frame_hook;
47 Lisp_Object Vmouse_enter_frame_hook, Qmouse_enter_frame_hook;
48 Lisp_Object Vmouse_leave_frame_hook, Qmouse_leave_frame_hook;
49 Lisp_Object Vmap_frame_hook, Qmap_frame_hook;
50 Lisp_Object Vunmap_frame_hook, Qunmap_frame_hook;
51 int allow_deletion_of_last_visible_frame;
52 Lisp_Object Vadjust_frame_function;
53 Lisp_Object Vmouse_motion_handler;
54 Lisp_Object Vsynchronize_minibuffers;
55 Lisp_Object Qsynchronize_minibuffers;
56 Lisp_Object Qbuffer_predicate;
57 Lisp_Object Qmake_initial_minibuffer_frame;
58 Lisp_Object Qcustom_initialize_frame;
60 /* We declare all these frame properties here even though many of them
61 are currently only used in frame-x.c, because we should generalize
64 Lisp_Object Qminibuffer;
65 Lisp_Object Qunsplittable;
66 Lisp_Object Qinternal_border_width;
67 Lisp_Object Qtop_toolbar_shadow_color;
68 Lisp_Object Qbottom_toolbar_shadow_color;
69 Lisp_Object Qbackground_toolbar_color;
70 Lisp_Object Qtop_toolbar_shadow_pixmap;
71 Lisp_Object Qbottom_toolbar_shadow_pixmap;
72 Lisp_Object Qtoolbar_shadow_thickness;
73 Lisp_Object Qscrollbar_placement;
74 Lisp_Object Qinter_line_space;
75 Lisp_Object Qvisual_bell;
76 Lisp_Object Qbell_volume;
77 Lisp_Object Qpointer_background;
78 Lisp_Object Qpointer_color;
79 Lisp_Object Qtext_pointer;
80 Lisp_Object Qspace_pointer;
81 Lisp_Object Qmodeline_pointer;
82 Lisp_Object Qgc_pointer;
83 Lisp_Object Qinitially_unmapped;
84 Lisp_Object Quse_backing_store;
85 Lisp_Object Qborder_color;
86 Lisp_Object Qborder_width;
88 Lisp_Object Qframep, Qframe_live_p;
89 Lisp_Object Qdelete_frame;
91 Lisp_Object Qframe_title_format, Vframe_title_format;
92 Lisp_Object Qframe_icon_title_format, Vframe_icon_title_format;
94 Lisp_Object Vdefault_frame_name;
95 Lisp_Object Vdefault_frame_plist;
97 Lisp_Object Vframe_icon_glyph;
101 Lisp_Object Qvisible, Qiconic, Qinvisible, Qvisible_iconic, Qinvisible_iconic;
102 Lisp_Object Qnomini, Qvisible_nomini, Qiconic_nomini, Qinvisible_nomini;
103 Lisp_Object Qvisible_iconic_nomini, Qinvisible_iconic_nomini;
105 Lisp_Object Qset_specifier, Qset_face_property;
106 Lisp_Object Qface_property_instance;
108 Lisp_Object Qframe_property_alias;
110 /* If this is non-nil, it is the frame that make-frame is currently
111 creating. We can't set the current frame to this in case the
112 debugger goes off because it would try and display to it. However,
113 there are some places which need to reference it which have no
114 other way of getting it if it isn't the selected frame. */
115 Lisp_Object Vframe_being_created;
116 Lisp_Object Qframe_being_created;
118 static void store_minibuf_frame_prop(struct frame *f, Lisp_Object val);
119 static void frame_conversion_internal(struct frame *f, int pixel_to_char,
120 int *pixel_width, int *pixel_height,
121 int *char_width, int *char_height,
123 static struct display_line title_string_display_line;
124 /* Used by generate_title_string. Global because they get used so much that
125 the dynamic allocation time adds up. */
126 static Emchar_dynarr *title_string_emchar_dynarr;
128 static Lisp_Object mark_frame(Lisp_Object obj)
130 struct frame *f = XFRAME(obj);
132 #define MARKED_SLOT(x) mark_object (f->x)
133 #include "frameslots.h"
135 if (FRAME_LIVE_P(f)) /* device is nil for a dead frame */
136 MAYBE_FRAMEMETH(f, mark_frame, (f));
142 print_frame(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
144 struct frame *frm = XFRAME(obj);
147 error("printing unreadable object #<frame %s 0x%x>",
148 XSTRING_DATA(frm->name), frm->header.uid);
150 write_fmt_string(printcharfun, "#<%s-frame ",
151 (!FRAME_LIVE_P(frm) ? "dead" : FRAME_TYPE_NAME(frm)));
152 print_internal(frm->name, printcharfun, 1);
153 write_fmt_str(printcharfun, " 0x%x>", frm->header.uid);
156 DEFINE_LRECORD_IMPLEMENTATION("frame", frame,
157 mark_frame, print_frame, 0, 0, 0, 0,
160 static void nuke_all_frame_slots(struct frame *f)
162 #define MARKED_SLOT(x) f->x = Qnil
163 #include "frameslots.h"
166 /* Allocate a new frame object and set all its fields to reasonable
167 values. The root window is created but the minibuffer will be done
170 static struct frame *allocate_frame_core(Lisp_Object device)
172 /* This function can GC */
174 Lisp_Object root_window;
175 struct frame *f = alloc_lcrecord_type(struct frame, &lrecord_frame);
178 nuke_all_frame_slots(f);
182 f->framemeths = XDEVICE(device)->devmeths;
183 f->buffer_alist = Fcopy_sequence(Vbuffer_alist);
185 root_window = allocate_window();
186 XWINDOW(root_window)->frame = frame;
189 Just so that there is "something there."
190 Correct size will be set up later with change_frame_size. */
195 XWINDOW(root_window)->pixel_width = 10;
196 XWINDOW(root_window)->pixel_height = 9;
198 f->root_window = root_window;
199 f->selected_window = root_window;
200 f->last_nonminibuf_window = root_window;
202 /* cache of subwindows visible on frame */
203 f->subwindow_instance_cache = make_weak_list(WEAK_LIST_SIMPLE);
205 /* associated exposure ignore list */
206 f->subwindow_exposures = 0;
207 f->subwindow_exposures_tail = 0;
209 FRAME_SET_PAGENUMBER(f, 1);
211 /* Choose a buffer for the frame's root window. */
212 XWINDOW(root_window)->buffer = Qt;
214 Lisp_Object buf = Fcurrent_buffer();
215 Lisp_Object tmp = Fbuffer_name(buf);
217 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
218 a space), try to find another one. */
219 if (string_char(XSTRING(tmp), 0) == ' ') {
220 buf = Fother_buffer(buf, Qnil, Qnil);
222 Fset_window_buffer(root_window, buf, Qnil);
228 static void setup_normal_frame(struct frame *f)
230 Lisp_Object mini_window;
235 mini_window = allocate_window();
236 XWINDOW(f->root_window)->next = mini_window;
237 XWINDOW(mini_window)->prev = f->root_window;
238 XWINDOW(mini_window)->mini_p = Qt;
239 XWINDOW(mini_window)->frame = frame;
240 f->minibuffer_window = mini_window;
241 f->has_minibuffer = 1;
243 XWINDOW(mini_window)->buffer = Qt;
244 Fset_window_buffer(mini_window, Vminibuffer_zero, Qt);
247 /* Make a frame using a separate minibuffer window on another frame.
248 MINI_WINDOW is the minibuffer window to use. nil means use the
249 default-minibuffer-frame. */
252 setup_frame_without_minibuffer(struct frame *f, Lisp_Object mini_window)
254 /* This function can GC */
255 Lisp_Object device = f->device;
257 if (!NILP(mini_window))
258 CHECK_LIVE_WINDOW(mini_window);
260 if (!NILP(mini_window)
261 && !EQ(DEVICE_CONSOLE(XDEVICE(device)),
262 FRAME_CONSOLE(XFRAME(XWINDOW(mini_window)->frame))))
263 error("frame and minibuffer must be on the same console");
265 /* Do not create a default minibuffer frame on printer devices. */
266 if (NILP(mini_window)
267 && DEVICE_DISPLAY_P(XDEVICE(FRAME_DEVICE(f)))) {
268 struct console *con = XCONSOLE(FRAME_CONSOLE(f));
269 /* Use default-minibuffer-frame if possible. */
270 if (!FRAMEP(con->default_minibuffer_frame)
271 || !FRAME_LIVE_P(XFRAME(con->default_minibuffer_frame))) {
272 /* If there's no minibuffer frame to use, create one. */
273 con->default_minibuffer_frame
274 = call1(Qmake_initial_minibuffer_frame, device);
277 XFRAME(con->default_minibuffer_frame)->minibuffer_window;
280 /* Install the chosen minibuffer window, with proper buffer. */
281 if (!NILP(mini_window)) {
282 store_minibuf_frame_prop(f, mini_window);
283 Fset_window_buffer(mini_window, Vminibuffer_zero, Qt);
285 f->minibuffer_window = Qnil;
288 /* Make a frame containing only a minibuffer window. */
290 static void setup_minibuffer_frame(struct frame *f)
292 /* This function can GC */
293 /* First make a frame containing just a root window, no minibuffer. */
294 Lisp_Object mini_window;
300 f->has_minibuffer = 1;
302 /* Now label the root window as also being the minibuffer.
303 Avoid infinite looping on the window chain by marking next pointer
306 mini_window = f->minibuffer_window = f->root_window;
307 XWINDOW(mini_window)->mini_p = Qt;
308 XWINDOW(mini_window)->next = Qnil;
309 XWINDOW(mini_window)->prev = Qnil;
310 XWINDOW(mini_window)->frame = frame;
312 /* Put the proper buffer in that window. */
314 Fset_window_buffer(mini_window, Vminibuffer_zero, Qt);
317 static Lisp_Object make_sure_its_a_fresh_plist(Lisp_Object foolist)
319 Lisp_Object tmp = Fcar(foolist);
321 /* looks like an alist to me. */
322 foolist = Fcopy_alist(foolist);
323 foolist = Fdestructive_alist_to_plist(foolist);
325 foolist = Fcopy_sequence(foolist);
330 DEFUN("make-frame", Fmake_frame, 0, 2, "", /*
331 Create and return a new frame, displaying the current buffer.
332 Runs the functions listed in `create-frame-hook' after frame creation.
334 Optional argument PROPS is a property list (a list of alternating
335 keyword-value specifications) of properties for the new frame.
336 \(An alist is accepted for backward compatibility but should not
339 See `set-frame-properties', `default-x-frame-plist', and
340 `default-tty-frame-plist' for the specially-recognized properties.
346 Lisp_Object frame = Qnil, name = Qnil, minibuf;
347 struct gcpro gcpro1, gcpro2, gcpro3;
348 int speccount = specpdl_depth();
349 int first_frame_on_device = 0;
350 int first_frame_on_console = 0;
352 d = decode_device(device);
353 XSETDEVICE(device, d);
355 /* PROPS and NAME may be freshly-created, so make sure to GCPRO. */
356 GCPRO3(frame, props, name);
358 props = make_sure_its_a_fresh_plist(props);
359 if (DEVICE_SPECIFIC_FRAME_PROPS(d))
360 /* Put the device-specific props before the more general ones so
361 that they override them. */
362 props = nconc2(props,
363 make_sure_its_a_fresh_plist
364 (*DEVICE_SPECIFIC_FRAME_PROPS(d)));
366 nconc2(props, make_sure_its_a_fresh_plist(Vdefault_frame_plist));
367 Fcanonicalize_lax_plist(props, Qnil);
369 name = Flax_plist_get(props, Qname, Qnil);
372 else if (STRINGP(Vdefault_frame_name))
373 name = Vdefault_frame_name;
375 name = build_string("SXEmacs");
377 if (!NILP(Fstring_match(make_string((const Bufbyte *)"\\.", 2), name,
379 signal_simple_error(". not allowed in frame names", name);
381 f = allocate_frame_core(device);
384 specbind(Qframe_being_created, name);
387 FRAMEMETH(f, init_frame_1, (f, props));
389 minibuf = Flax_plist_get(props, Qminibuffer, Qunbound);
390 if (UNBOUNDP(minibuf)) {
391 /* If minibuf is unspecified, then look for a minibuffer X resource. */
392 /* #### Not implemented any more. We need to fix things up so
393 that we search out all X resources and append them to the end of
394 props, above. This is the only way in general to assure
395 coherent behavior for all frame properties/resources/etc. */
397 props = Flax_plist_remprop(props, Qminibuffer);
399 if (EQ(minibuf, Qnone) || NILP(minibuf))
400 setup_frame_without_minibuffer(f, Qnil);
401 else if (EQ(minibuf, Qonly))
402 setup_minibuffer_frame(f);
403 else if (WINDOWP(minibuf))
404 setup_frame_without_minibuffer(f, minibuf);
405 else if (EQ(minibuf, Qt) || UNBOUNDP(minibuf))
406 setup_normal_frame(f);
408 signal_simple_error("Invalid value for `minibuffer'", minibuf);
410 update_frame_window_mirror(f);
412 if (initialized && !DEVICE_STREAM_P(d)) {
413 if (!NILP(f->minibuffer_window))
414 reset_face_cachels(XWINDOW(f->minibuffer_window));
415 reset_face_cachels(XWINDOW(f->root_window));
418 /* If no frames on this device formerly existed, say this is the
419 first frame. It kind of assumes that frameless devices don't
420 exist, but it shouldn't be too harmful. */
421 if (NILP(DEVICE_FRAME_LIST(d)))
422 first_frame_on_device = 1;
424 /* This *must* go before the init_*() methods. Those functions
425 call Lisp code, and if any of them causes a warning to be displayed
426 and the *Warnings* buffer to be created, it won't get added to
427 the frame-specific version of the buffer-alist unless the frame
428 is accessible from the device. */
431 DEVICE_FRAME_LIST(d) = nconc2(DEVICE_FRAME_LIST(d), Fcons(frame, Qnil));
433 DEVICE_FRAME_LIST(d) = Fcons(frame, DEVICE_FRAME_LIST(d));
434 RESET_CHANGED_SET_FLAGS;
436 /* Now make sure that the initial cached values are set correctly.
437 Do this after the init_frame method is called because that may
438 do things (e.g. create widgets) that are necessary for the
439 specifier value-changed methods to work OK. */
440 recompute_all_cached_specifiers_in_frame(f);
442 if (!DEVICE_STREAM_P(d)) {
445 #ifdef HAVE_SCROLLBARS
446 /* Finish up resourcing the scrollbars. */
447 init_frame_scrollbars(f);
451 /* Create the initial toolbars. We have to do this after the frame
452 methods are called because it may potentially call some things itself
453 which depend on the normal frame methods having initialized
455 init_frame_toolbars(f);
457 reset_face_cachels(XWINDOW(FRAME_SELECTED_WINDOW(f)));
458 reset_glyph_cachels(XWINDOW(FRAME_SELECTED_WINDOW(f)));
460 change_frame_size(f, f->height, f->width, 0);
463 MAYBE_FRAMEMETH(f, init_frame_2, (f, props));
464 Fset_frame_properties(frame, props);
465 MAYBE_FRAMEMETH(f, init_frame_3, (f));
467 /* Hallelujah, praise the lord. */
468 f->init_finished = 1;
470 /* If this is the first frame on the device, make it the selected one. */
471 if (first_frame_on_device && NILP(DEVICE_SELECTED_FRAME(d)))
472 set_device_selected_frame(d, frame);
474 /* If at startup or if the current console is a stream console
475 (usually also at startup), make this console the selected one
476 so that messages show up on it. */
478 Lisp_Object tmp = Fselected_console();
479 if (NILP(tmp) || CONSOLE_STREAM_P(XCONSOLE(tmp))) {
480 Fselect_console(DEVICE_CONSOLE(d));
484 first_frame_on_console =
485 (first_frame_on_device &&
486 XINT(Flength(CONSOLE_DEVICE_LIST(XCONSOLE(DEVICE_CONSOLE(d)))))
489 /* #### all this calling of frame methods at various odd times
490 is somewhat of a mess. It's necessary to do it this way due
491 to strange console-type-specific things that need to be done. */
492 MAYBE_FRAMEMETH(f, after_init_frame, (f, first_frame_on_device,
493 first_frame_on_console));
495 if (!DEVICE_STREAM_P(d)) {
496 /* Now initialise the gutters. This won't change the frame size,
497 but is needed as input to the layout that change_frame_size
498 will eventually do. Unfortunately gutter sizing code relies
499 on the frame in question being visible so we can't do this
501 init_frame_gutters(f);
503 change_frame_size(f, f->height, f->width, 0);
506 if (first_frame_on_device) {
507 if (first_frame_on_console)
508 va_run_hook_with_args(Qcreate_console_hook, 1,
510 va_run_hook_with_args(Qcreate_device_hook, 1, device);
512 va_run_hook_with_args(Qcreate_frame_hook, 1, frame);
514 /* Initialize custom-specific stuff. */
515 if (!UNBOUNDP(symbol_function(XSYMBOL(Qcustom_initialize_frame))))
516 call1(Qcustom_initialize_frame, frame);
518 unbind_to(speccount, Qnil);
524 /* this function should be used in most cases when a Lisp function is passed
525 a FRAME argument. Use this unless you don't accept nil == current frame
526 (in which case, do a CHECK_LIVE_FRAME() and then an XFRAME()) or you
527 allow dead frames. Note that very few functions should accept dead
528 frames. It could be argued that functions should just do nothing when
529 given a dead frame, but the presence of a dead frame usually indicates
530 an oversight in the Lisp code that could potentially lead to strange
531 results and so it is better to catch the error early.
533 If you only accept X frames, use decode_x_frame(), which does what this
534 function does but also makes sure the frame is an X frame. */
536 struct frame *decode_frame(Lisp_Object frame)
539 return selected_frame();
541 CHECK_LIVE_FRAME(frame);
542 return XFRAME(frame);
545 struct frame *decode_frame_or_selected(Lisp_Object cdf)
548 cdf = CONSOLE_SELECTED_DEVICE(decode_console(cdf));
550 cdf = DEVICE_SELECTED_FRAME(decode_device(cdf));
551 return decode_frame(cdf);
554 Lisp_Object make_frame(struct frame * f)
562 * window size changes are held up during critical regions. Afterwards,
563 * we want to deal with any delayed changes.
565 void hold_frame_size_changes(void)
570 void unhold_one_frame_size_changes(struct frame *f)
574 if (f->size_change_pending)
575 change_frame_size(f, f->new_height, f->new_width, 0);
578 void unhold_frame_size_changes(void)
580 Lisp_Object frmcons, devcons, concons;
582 FRAME_LOOP_NO_BREAK(frmcons, devcons, concons)
583 unhold_one_frame_size_changes(XFRAME(XCAR(frmcons)));
586 void invalidate_vertical_divider_cache_in_frame(struct frame *f)
588 /* Invalidate cached value of needs_vertical_divider_p in
589 every and all windows */
590 map_windows(f, invalidate_vertical_divider_cache_in_window, 0);
594 * Frame size may change due to changes in scrollbars, toolbars,
595 * default font etc. These changes are applied early in redisplay
598 void adjust_frame_size(struct frame *f)
600 int keep_char_size = 0;
604 if (!f->size_slipped)
607 /* Don't adjust tty frames. #### May break when TTY have menubars.
608 Then, write an Vadjust_frame_function which will return t for TTY
609 frames. Another solution is frame_size_fixed_p method for TTYs,
610 which always returned yes it's fixed.
612 if (!FRAME_WIN_P(f)) {
613 CLEAR_FRAME_SIZE_SLIPPED(f);
617 /* frame_size_fixed_p tells that frame size cannot currently
618 be changed change due to external conditions */
619 if (!FRAMEMETH_OR_GIVEN(f, frame_size_fixed_p, (f), 0)) {
620 if (NILP(Vadjust_frame_function))
622 else if (EQ(Vadjust_frame_function, Qt))
626 NILP(call1_trapping_errors
627 ("Error in adjust-frame-function",
628 Vadjust_frame_function, frame));
631 Fset_frame_size(frame, make_int(FRAME_CHARWIDTH(f)),
632 make_int(FRAME_CHARHEIGHT(f)), Qnil);
635 if (!keep_char_size) {
637 pixel_to_char_size(f, FRAME_PIXWIDTH(f), FRAME_PIXHEIGHT(f),
639 change_frame_size(f, height, width, 0);
640 CLEAR_FRAME_SIZE_SLIPPED(f);
645 * This is a "specifier changed in frame" handler for various specifiers
646 * changing which causes frame size adjustment
649 frame_size_slipped(Lisp_Object specifier, struct frame *f, Lisp_Object oldval)
651 MARK_FRAME_SIZE_SLIPPED(f);
654 DEFUN("framep", Fframep, 1, 1, 0, /*
655 Return non-nil if OBJECT is a frame.
656 Also see `frame-live-p'.
657 Note that FSF Emacs kludgily returns a value indicating what type of
658 frame this is. Use the cleaner function `frame-type' for that.
662 return FRAMEP(object) ? Qt : Qnil;
665 DEFUN("frame-live-p", Fframe_live_p, 1, 1, 0, /*
666 Return non-nil if OBJECT is a frame which has not been deleted.
670 return FRAMEP(object) && FRAME_LIVE_P(XFRAME(object)) ? Qt : Qnil;
673 DEFUN("focus-frame", Ffocus_frame, 1, 1, 0, /*
674 Select FRAME and give it the window system focus.
675 This function is not affected by the value of `focus-follows-mouse'.
679 CHECK_LIVE_FRAME(frame);
681 MAYBE_DEVMETH(XDEVICE(FRAME_DEVICE(XFRAME(frame))), focus_on_frame,
683 /* FRAME will be selected by the time we receive the next event.
684 However, it is better to select it explicitly now, in case the
685 Lisp code depends on frame being selected. */
686 Fselect_frame(frame);
690 /* Called from Fselect_window() */
691 void select_frame_1(Lisp_Object frame)
693 struct frame *f = XFRAME(frame);
694 Lisp_Object old_selected_frame = Fselected_frame(Qnil);
696 if (EQ(frame, old_selected_frame))
699 /* now select the frame's device */
700 set_device_selected_frame(XDEVICE(FRAME_DEVICE(f)), frame);
701 select_device_1(FRAME_DEVICE(f));
703 update_frame_window_mirror(f);
706 DEFUN("select-frame", Fselect_frame, 1, 1, 0, /*
707 Select the frame FRAME.
708 Subsequent editing commands apply to its selected window.
709 The selection of FRAME lasts until the next time the user does
710 something to select a different frame, or until the next time this
713 Note that this does not actually cause the window-system focus to be
714 set to this frame, or the `select-frame-hook' or `deselect-frame-hook'
715 to be run, until the next time that SXEmacs is waiting for an event.
717 Also note that when focus-follows-mouse is non-nil, the frame
718 selection is temporary and is reverted when the current command
719 terminates, much like the buffer selected by `set-buffer'. In order
720 to effect a permanent focus change, use `focus-frame'.
724 CHECK_LIVE_FRAME(frame);
726 /* select the frame's selected window. This will call
727 selected_frame_1(). */
728 Fselect_window(FRAME_SELECTED_WINDOW(XFRAME(frame)), Qnil);
730 /* Nothing should be depending on the return value of this function.
731 But, of course, there is stuff out there which is. */
735 /* use this to retrieve the currently selected frame. You should use
736 this in preference to Fselected_frame (Qnil) unless you are prepared
737 to handle the possibility of there being no selected frame (this
738 happens at some points during startup). */
740 struct frame *selected_frame(void)
742 Lisp_Object device = Fselected_device(Qnil);
743 Lisp_Object frame = DEVICE_SELECTED_FRAME(XDEVICE(device));
745 signal_simple_error("No frames exist on device", device);
746 return XFRAME(frame);
749 /* use this instead of XFRAME (DEVICE_SELECTED_FRAME (d)) to catch
750 the possibility of there being no frames on the device (just created).
751 There is no point doing this inside of redisplay because errors
752 cause an abort(), indicating a flaw in the logic, and error_check_frame()
753 will catch this just as well. */
755 struct frame *device_selected_frame(struct device *d)
757 Lisp_Object frame = DEVICE_SELECTED_FRAME(d);
760 XSETDEVICE(device, d);
761 signal_simple_error("No frames exist on device", device);
763 return XFRAME(frame);
768 xxDEFUN("handle-switch-frame", Fhandle_switch_frame, 1, 2, "e", /*
769 Handle a switch-frame event EVENT.
770 Switch-frame events are usually bound to this function.
771 A switch-frame event tells Emacs that the window manager has requested
772 that the user's events be directed to the frame mentioned in the event.
773 This function selects the selected window of the frame of EVENT.
775 If EVENT is frame object, handle it as if it were a switch-frame event
780 /* Preserve prefix arg that the command loop just cleared. */
781 XCONSOLE(Vselected_console)->prefix_arg = Vcurrent_prefix_arg;
783 run_hook(Qmouse_leave_buffer_hook);
785 return do_switch_frame(frame, no_enter, 0);
788 /* A load of garbage. */
789 xxDEFUN("ignore-event", Fignore_event, 0, 0, "", /*
790 Do nothing, but preserve any prefix argument already specified.
791 This is a suitable binding for iconify-frame and make-frame-visible.
795 struct console *c = XCONSOLE(Vselected_console);
797 c->prefix_arg = Vcurrent_prefix_arg;
803 DEFUN("selected-frame", Fselected_frame, 0, 1, 0, /*
804 Return the frame that is now selected on device DEVICE.
805 If DEVICE is not specified, the selected device will be used.
806 If no frames exist on the device, nil is returned.
810 if (NILP(device) && NILP(Fselected_device(Qnil)))
811 return Qnil; /* happens early in temacs */
812 return DEVICE_SELECTED_FRAME(decode_device(device));
815 Lisp_Object frame_first_window(struct frame * f)
817 Lisp_Object w = f->root_window;
820 if (!NILP(XWINDOW(w)->hchild))
821 w = XWINDOW(w)->hchild;
822 else if (!NILP(XWINDOW(w)->vchild))
823 w = XWINDOW(w)->vchild;
831 DEFUN("active-minibuffer-window", Factive_minibuffer_window, 0, 0, 0, /*
832 Return the currently active minibuffer window, or nil if none.
836 return minibuf_level ? minibuf_window : Qnil;
839 DEFUN("last-nonminibuf-frame", Flast_nonminibuf_frame, 0, 1, 0, /*
840 Return the most-recently-selected non-minibuffer-only frame on CONSOLE.
841 This will always be the same as (selected-frame device) unless the
842 selected frame is a minibuffer-only frame.
843 CONSOLE defaults to the selected console if omitted.
849 XSETCONSOLE(console, decode_console(console));
850 /* Just in case the machinations in delete_frame_internal() resulted
851 in the last-nonminibuf-frame getting out of sync, make sure and
852 return the selected frame if it's acceptable. */
853 result = Fselected_frame(CONSOLE_SELECTED_DEVICE(XCONSOLE(console)));
854 if (!NILP(result) && !FRAME_MINIBUF_ONLY_P(XFRAME(result)))
856 return CONSOLE_LAST_NONMINIBUF_FRAME(XCONSOLE(console));
859 DEFUN("frame-root-window", Fframe_root_window, 0, 1, 0, /*
860 Return the root-window of FRAME.
861 If omitted, FRAME defaults to the currently selected frame.
865 struct frame *f = decode_frame(frame);
866 return FRAME_ROOT_WINDOW(f);
869 DEFUN("frame-selected-window", Fframe_selected_window, 0, 1, 0, /*
870 Return the selected window of frame object FRAME.
871 If omitted, FRAME defaults to the currently selected frame.
875 struct frame *f = decode_frame(frame);
876 return FRAME_SELECTED_WINDOW(f);
879 void set_frame_selected_window(struct frame *f, Lisp_Object window)
881 assert(XFRAME(WINDOW_FRAME(XWINDOW(window))) == f);
882 f->selected_window = window;
883 if (!MINI_WINDOW_P(XWINDOW(window)) || FRAME_MINIBUF_ONLY_P(f)) {
884 if (!EQ(f->last_nonminibuf_window, window)) {
886 MARK_TOOLBAR_CHANGED;
890 f->last_nonminibuf_window = window;
894 DEFUN("set-frame-selected-window", Fset_frame_selected_window, 2, 2, 0, /*
895 Set the selected window of FRAME to WINDOW.
896 If FRAME is nil, the selected frame is used.
897 If FRAME is the selected frame, this makes WINDOW the selected window.
901 XSETFRAME(frame, decode_frame(frame));
902 CHECK_LIVE_WINDOW(window);
904 if (!EQ(frame, WINDOW_FRAME(XWINDOW(window))))
905 error("In `set-frame-selected-window', WINDOW is not on FRAME");
907 if (XFRAME(frame) == selected_frame())
908 return Fselect_window(window, Qnil);
910 set_frame_selected_window(XFRAME(frame), window);
914 DEFUN("frame-device", Fframe_device, 0, 1, 0, /*
915 Return the device that FRAME is on.
916 If omitted, FRAME defaults to the currently selected frame.
920 return FRAME_DEVICE(decode_frame(frame));
923 int is_surrogate_for_selected_frame(struct frame *f)
925 struct device *d = XDEVICE(f->device);
926 struct frame *dsf = device_selected_frame(d);
928 /* Can't be a surrogate for ourselves. */
932 if (!FRAME_HAS_MINIBUF_P(dsf) &&
933 f == XFRAME(WINDOW_FRAME(XWINDOW(FRAME_MINIBUF_WINDOW(dsf)))))
939 static int frame_matches_frame_spec(Lisp_Object frame, Lisp_Object type)
941 struct frame *f = XFRAME(frame);
944 CHECK_LIVE_WINDOW(type);
946 if (EQ(FRAME_MINIBUF_WINDOW(f), type)
947 /* Check that F either is, or has forwarded
948 its focus to, TYPE's frame. */
949 && (EQ(WINDOW_FRAME(XWINDOW(type)), frame)
950 || EQ(WINDOW_FRAME(XWINDOW(type)),
951 FRAME_FOCUS_FRAME(f))))
957 if (EQ(type, Qvisible) || EQ(type, Qiconic) || EQ(type, Qvisible_iconic)
958 || EQ(type, Qvisible_nomini) || EQ(type, Qiconic_nomini)
959 || EQ(type, Qvisible_iconic_nomini))
960 FRAME_SAMPLE_VISIBILITY(f);
966 type = Qvisible_iconic;
968 if (EQ(type, Qvisible))
969 return FRAME_VISIBLE_P(f);
970 if (EQ(type, Qiconic))
971 return FRAME_ICONIFIED_P(f);
972 if (EQ(type, Qinvisible))
973 return !FRAME_VISIBLE_P(f) && !FRAME_ICONIFIED_P(f);
974 if (EQ(type, Qvisible_iconic))
975 return FRAME_VISIBLE_P(f) || FRAME_ICONIFIED_P(f);
976 if (EQ(type, Qinvisible_iconic))
977 return !FRAME_VISIBLE_P(f);
979 if (EQ(type, Qnomini))
980 return !FRAME_MINIBUF_ONLY_P(f);
981 if (EQ(type, Qvisible_nomini))
982 return FRAME_VISIBLE_P(f) && !FRAME_MINIBUF_ONLY_P(f);
983 if (EQ(type, Qiconic_nomini))
984 return FRAME_ICONIFIED_P(f) && !FRAME_MINIBUF_ONLY_P(f);
985 if (EQ(type, Qinvisible_nomini))
986 return !FRAME_VISIBLE_P(f) && !FRAME_ICONIFIED_P(f) &&
987 !FRAME_MINIBUF_ONLY_P(f);
988 if (EQ(type, Qvisible_iconic_nomini))
989 return ((FRAME_VISIBLE_P(f) || FRAME_ICONIFIED_P(f))
990 && !FRAME_MINIBUF_ONLY_P(f));
991 if (EQ(type, Qinvisible_iconic_nomini))
992 return !FRAME_VISIBLE_P(f) && !FRAME_MINIBUF_ONLY_P(f);
997 int device_matches_device_spec(Lisp_Object device, Lisp_Object device_spec)
999 if (EQ(device_spec, Qwindow_system))
1000 return DEVICE_WIN_P(XDEVICE(device));
1001 if (DEVICEP(device_spec))
1002 return EQ(device, device_spec);
1003 if (CONSOLEP(device_spec))
1004 return EQ(DEVICE_CONSOLE(XDEVICE(device)), device_spec);
1005 if (valid_console_type_p(device_spec))
1006 return EQ(DEVICE_TYPE(XDEVICE(device)), device_spec);
1010 /* Return the next frame in the frame list after FRAME.
1011 WHICH-FRAMES and WHICH-DEVICES control which frames and devices
1012 are considered; see `next-frame'. */
1015 next_frame(Lisp_Object frame, Lisp_Object which_frames,
1016 Lisp_Object which_devices)
1018 Lisp_Object first = Qnil;
1019 Lisp_Object devcons, concons;
1022 CHECK_LIVE_FRAME(frame);
1024 DEVICE_LOOP_NO_BREAK(devcons, concons) {
1025 Lisp_Object device = XCAR(devcons);
1026 Lisp_Object frmcons;
1028 if (!device_matches_device_spec(device, which_devices)) {
1029 if (EQ(device, FRAME_DEVICE(XFRAME(frame))))
1034 DEVICE_FRAME_LOOP(frmcons, XDEVICE(device)) {
1035 Lisp_Object f = XCAR(frmcons);
1038 if (frame_matches_frame_spec(f, which_frames))
1045 && frame_matches_frame_spec(f,
1054 /* We went through the whole frame list without finding a single
1055 acceptable frame. Return the original frame. */
1058 /* There were no acceptable frames in the list after FRAME; otherwise,
1059 we would have returned directly from the loop. Since FIRST is the last
1060 acceptable frame in the list, return it. */
1064 /* Return the previous frame in the frame list before FRAME.
1065 WHICH-FRAMES and WHICH-DEVICES control which frames and devices
1066 are considered; see `next-frame'. */
1069 previous_frame(Lisp_Object frame, Lisp_Object which_frames,
1070 Lisp_Object which_devices)
1072 Lisp_Object devcons, concons;
1073 Lisp_Object last = Qnil;
1075 CHECK_LIVE_FRAME(frame);
1077 DEVICE_LOOP_NO_BREAK(devcons, concons) {
1078 Lisp_Object device = XCAR(devcons);
1079 Lisp_Object frmcons;
1081 if (!device_matches_device_spec(device, which_devices)) {
1082 if (EQ(device, FRAME_DEVICE(XFRAME(frame)))
1088 DEVICE_FRAME_LOOP(frmcons, XDEVICE(device)) {
1089 Lisp_Object f = XCAR(frmcons);
1095 if (frame_matches_frame_spec(f, which_frames))
1102 /* We went through the whole frame list without finding a single
1103 acceptable frame. Return the original frame. */
1106 /* There were no acceptable frames in the list before FRAME; otherwise,
1107 we would have returned directly from the loop. Since LAST is the last
1108 acceptable frame in the list, return it. */
1112 DEFUN("next-frame", Fnext_frame, 0, 3, 0, /*
1113 Return the next frame of the right type in the frame list after FRAME.
1114 WHICH-FRAMES controls which frames are eligible to be returned; all
1115 others will be skipped. Note that if there is only one eligible
1116 frame, then `next-frame' called repeatedly will always return
1117 the same frame, and if there is no eligible frame, then FRAME is
1120 Possible values for WHICH-FRAMES are
1122 'visible Consider only frames that are visible.
1123 'iconic Consider only frames that are iconic.
1124 'invisible Consider only frames that are invisible
1125 (this is different from iconic).
1126 'visible-iconic Consider frames that are visible or iconic.
1127 'invisible-iconic Consider frames that are invisible or iconic.
1128 'nomini Consider all frames except minibuffer-only ones.
1129 'visible-nomini Like `visible' but omits minibuffer-only frames.
1130 'iconic-nomini Like `iconic' but omits minibuffer-only frames.
1131 'invisible-nomini Like `invisible' but omits minibuffer-only frames.
1132 'visible-iconic-nomini Like `visible-iconic' but omits minibuffer-only
1134 'invisible-iconic-nomini Like `invisible-iconic' but omits minibuffer-only
1136 any other value Consider all frames.
1138 If WHICH-FRAMES is omitted, 'nomini is used. A value for WHICH-FRAMES
1139 of 0 (a number) is treated like 'iconic, for backwards compatibility.
1141 If WHICH-FRAMES is a window, include only its own frame and any frame
1142 now using that window as the minibuffer.
1144 The optional third argument WHICH-DEVICES further clarifies on which
1145 devices to search for frames as specified by WHICH-FRAMES.
1146 If nil or omitted, search all devices on FRAME's console.
1147 If a device, only search that device.
1148 If a console, search all devices on that console.
1149 If a device type, search all devices of that type.
1150 If `window-system', search all window-system devices.
1151 Any other non-nil value means search all devices.
1153 (frame, which_frames, which_devices))
1155 XSETFRAME(frame, decode_frame(frame));
1157 return next_frame(frame, which_frames, which_devices);
1160 DEFUN("previous-frame", Fprevious_frame, 0, 3, 0, /*
1161 Return the next frame of the right type in the frame list after FRAME.
1162 WHICH-FRAMES controls which frames are eligible to be returned; all
1163 others will be skipped. Note that if there is only one eligible
1164 frame, then `previous-frame' called repeatedly will always return
1165 the same frame, and if there is no eligible frame, then FRAME is
1168 See `next-frame' for an explanation of the WHICH-FRAMES and WHICH-DEVICES
1171 (frame, which_frames, which_devices))
1173 XSETFRAME(frame, decode_frame(frame));
1175 return previous_frame(frame, which_frames, which_devices);
1178 /* Return any frame for which PREDICATE is non-zero, or return Qnil
1179 if there aren't any. */
1182 find_some_frame(int (*predicate) (Lisp_Object, void *), void *closure)
1184 Lisp_Object framecons, devcons, concons;
1186 FRAME_LOOP_NO_BREAK(framecons, devcons, concons) {
1187 Lisp_Object frame = XCAR(framecons);
1189 if ((predicate) (frame, closure))
1196 /* extern void free_line_insertion_deletion_costs (struct frame *f); */
1198 /* Return 1 if it is ok to delete frame F;
1199 0 if all frames aside from F are invisible.
1200 (Exception: if F is a stream frame, it's OK to delete if
1201 any other frames exist.) */
1203 int other_visible_frames(struct frame *f)
1207 XSETFRAME(frame, f);
1208 if (FRAME_STREAM_P(f))
1209 return !EQ(frame, next_frame(frame, Qt, Qt));
1210 return !EQ(frame, next_frame(frame, Qvisible_iconic_nomini, Qt));
1215 If FORCE is non-zero, allow deletion of the only frame.
1217 If CALLED_FROM_DELETE_DEVICE is non-zero, then, if
1218 deleting the last frame on a device, just delete it,
1219 instead of calling `delete-device'.
1221 If FROM_IO_ERROR is non-zero, then the frame is gone due
1222 to an I/O error. This affects what happens if we exit
1223 (we do an emergency exit instead of `save-buffers-kill-emacs'.)
1227 delete_frame_internal(struct frame *f, int force,
1228 int called_from_delete_device, int from_io_error)
1230 /* This function can GC */
1231 int minibuffer_selected;
1233 struct console *con;
1236 Lisp_Object console;
1237 struct gcpro gcpro1;
1239 /* OK to delete an already deleted frame. */
1240 if (!FRAME_LIVE_P(f))
1243 XSETFRAME(frame, f);
1246 device = FRAME_DEVICE(f);
1247 d = XDEVICE(device);
1248 console = DEVICE_CONSOLE(d);
1249 con = XCONSOLE(console);
1251 if (!called_from_delete_device
1252 && !DEVICE_IMPL_FLAG(d, XDEVIMPF_FRAMELESS_OK)) {
1253 /* If we're deleting the only non-minibuffer frame on the
1254 device, delete the device. */
1255 if (EQ(frame, next_frame(frame, Qnomini, FRAME_DEVICE(f)))) {
1256 delete_device_internal(d, force, 0, from_io_error);
1262 /* In FSF, delete-frame will not normally allow you to delete the
1263 last visible frame. This was too annoying, so we changed it to the
1264 only frame. However, this would let people shoot themselves by
1265 deleting all frames which were either visible or iconified and thus
1266 losing any way of communicating with the still running SXEmacs process.
1267 So we put it back. */
1268 if (!force && !allow_deletion_of_last_visible_frame &&
1269 !other_visible_frames(f))
1270 error("Attempt to delete the sole visible or iconified frame");
1272 /* Does this frame have a minibuffer, and is it the surrogate
1273 minibuffer for any other frame? */
1274 if (FRAME_HAS_MINIBUF_P(f)) {
1275 Lisp_Object frmcons, devcons, concons;
1277 FRAME_LOOP_NO_BREAK(frmcons, devcons, concons) {
1278 Lisp_Object this = XCAR(frmcons);
1280 if (!EQ(this, frame)
1281 && EQ(frame, (WINDOW_FRAME
1283 (FRAME_MINIBUF_WINDOW
1284 (XFRAME(this))))))) {
1285 /* We've found another frame whose minibuffer is on
1288 ("Attempt to delete a surrogate minibuffer frame",
1294 /* Test for popup frames hanging around. */
1295 /* Deletion of a parent frame with popups is deadly. */
1297 Lisp_Object frmcons, devcons, concons;
1299 FRAME_LOOP_NO_BREAK(frmcons, devcons, concons) {
1300 Lisp_Object this = XCAR(frmcons);
1302 if (!EQ(this, frame)) {
1303 struct device *devcons_d =
1304 XDEVICE(XCAR(devcons));
1307 DEVMETH_OR_GIVEN(devcons_d,
1309 (XFRAME(this)), Qnil)))
1310 /* We've found a popup frame whose parent is this frame. */
1312 ("Attempt to delete a frame with live popups",
1318 /* Before here, we haven't made any dangerous changes (just checked for
1319 error conditions). Now run the delete-frame-hook. Remember that
1320 user code there could do any number of dangerous things, including
1321 signalling an error. */
1323 va_run_hook_with_args(Qdelete_frame_hook, 1, frame);
1325 if (!FRAME_LIVE_P(f)) { /* Make sure the delete-frame-hook didn't *//* go ahead and delete anything. */
1330 /* Call the delete-device-hook and delete-console-hook now if
1331 appropriate, before we do any dangerous things -- they too could
1333 if (XINT(Flength(DEVICE_FRAME_LIST(d))) == 1) {
1334 va_run_hook_with_args(Qdelete_device_hook, 1, device);
1335 if (!FRAME_LIVE_P(f)) { /* Make sure the delete-device-hook didn't *//* go ahead and delete anything. */
1340 if (XINT(Flength(CONSOLE_DEVICE_LIST(con))) == 1) {
1341 va_run_hook_with_args(Qdelete_console_hook, 1, console);
1342 if (!FRAME_LIVE_P(f)) { /* Make sure the delete-console-hook didn't *//* go ahead and delete anything. */
1349 minibuffer_selected = EQ(minibuf_window, Fselected_window(Qnil));
1351 /* If we were focused on this frame, then we're not any more.
1352 Assume that we lost the focus; that way, the call to
1353 Fselect_frame() below won't end up making us explicitly
1354 focus on another frame, which is generally undesirable in
1355 a point-to-type world. If our mouse ends up sitting over
1356 another frame, we will receive a FocusIn event and end up
1357 making that frame the selected frame.
1359 #### This may not be an ideal solution in a click-to-type
1360 world (in that case, we might want to explicitly choose
1361 another frame to have the focus, rather than relying on
1362 the WM, which might focus on a frame in a different app
1363 or focus on nothing at all). But there's no easy way
1364 to detect which focus model we're running on, and the
1365 alternative is more heinous. */
1367 if (EQ(frame, DEVICE_FRAME_WITH_FOCUS_REAL(d)))
1368 DEVICE_FRAME_WITH_FOCUS_REAL(d) = Qnil;
1369 if (EQ(frame, DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS(d)))
1370 DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS(d) = Qnil;
1371 if (EQ(frame, DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS(d)))
1372 DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS(d) = Qnil;
1374 /* Don't allow the deleted frame to remain selected.
1375 Note that in the former scheme of things, this would
1376 have caused us to regain the focus. This no longer
1377 applies (see above); I think the new behavior is more
1378 logical. If someone disagrees, it can always be
1379 changed (or a new user variable can be introduced, ugh.) */
1380 if (EQ(frame, DEVICE_SELECTED_FRAME(d))) {
1383 /* If this is a popup frame, select its parent if possible.
1384 Otherwise, find another visible frame; if none, just take any frame.
1385 First try the same device, then the same console. */
1387 next = DEVMETH_OR_GIVEN(d, get_frame_parent, (f), Qnil);
1388 if (NILP(next) || EQ(next, frame)
1389 || !FRAME_LIVE_P(XFRAME(next)))
1390 next = next_frame(frame, Qvisible, device);
1391 if (NILP(next) || EQ(next, frame))
1392 next = next_frame(frame, Qvisible, console);
1393 if (NILP(next) || EQ(next, frame))
1394 next = next_frame(frame, Qvisible, Qt);
1395 if (NILP(next) || EQ(next, frame))
1396 next = next_frame(frame, Qt, device);
1397 if (NILP(next) || EQ(next, frame))
1398 next = next_frame(frame, Qt, console);
1399 if (NILP(next) || EQ(next, frame))
1400 next = next_frame(frame, Qt, Qt);
1402 /* if we haven't found another frame at this point
1403 then there aren't any. */
1404 if (NILP(next) || EQ(next, frame)) ;
1407 /* if this is the global selected frame, select another one. */
1408 if (EQ(frame, Fselected_frame(Qnil))) {
1409 Fselect_frame(next);
1413 * If the new frame we just selected is on a different
1414 * device then we still need to change DEVICE_SELECTED_FRAME(d)
1415 * to a live frame, if there are any left on this device.
1417 if (!EQ(device, FRAME_DEVICE(XFRAME(next)))) {
1418 Lisp_Object next_f =
1419 next_frame(frame, Qt, device);
1420 if (NILP(next_f) || EQ(next_f, frame))
1421 set_device_selected_frame(d, Qnil);
1423 set_device_selected_frame(d, next_f);
1424 } else if (!did_select)
1425 set_device_selected_frame(d, next);
1430 /* Don't allow minibuf_window to remain on a deleted frame. */
1431 if (EQ(f->minibuffer_window, minibuf_window)) {
1432 struct frame *sel_frame = selected_frame();
1433 Fset_window_buffer(sel_frame->minibuffer_window,
1434 XWINDOW(minibuf_window)->buffer, Qt);
1435 minibuf_window = sel_frame->minibuffer_window;
1437 /* If the dying minibuffer window was selected,
1438 select the new one. */
1439 if (minibuffer_selected)
1440 Fselect_window(minibuf_window, Qnil);
1443 /* After this point, no errors must be allowed to occur. */
1445 #ifdef HAVE_MENUBARS
1446 free_frame_menubars(f);
1448 #ifdef HAVE_SCROLLBARS
1449 free_frame_scrollbars(f);
1451 #ifdef HAVE_TOOLBARS
1452 free_frame_toolbars(f);
1454 free_frame_gutters(f);
1455 /* Unfortunately deleting the frame will also delete the parent of
1456 all of the subwindow instances current on the frame. I think this
1457 can lead to bad things when trying to finalize the
1458 instances. Thus we loop over all instance caches calling the
1459 finalize method for each instance. */
1460 free_frame_subwindow_instances(f);
1462 /* This must be done before the window and window_mirror structures
1463 are freed. The scrollbar information is attached to them. */
1464 MAYBE_FRAMEMETH(f, delete_frame, (f));
1466 /* Mark all the windows that used to be on FRAME as deleted, and then
1467 remove the reference to them. */
1468 delete_all_subwindows(XWINDOW(f->root_window));
1469 f->root_window = Qnil;
1471 /* clear out the cached glyph information */
1472 f->subwindow_instance_cache = Qnil;
1474 /* Remove the frame now from the list. This way, any events generated
1475 on this frame by the maneuvers below will disperse themselves. */
1477 /* This used to be Fdelq(), but that will cause a seg fault if the
1478 QUIT checker happens to get invoked, because the frame list is in
1479 an inconsistent state. */
1480 d->frame_list = delq_no_quit(frame, d->frame_list);
1481 RESET_CHANGED_SET_FLAGS;
1486 free_window_mirror(f->root_mirror);
1487 /* free_line_insertion_deletion_costs (f); */
1489 /* If we've deleted the last non-minibuf frame, then try to find
1491 if (EQ(frame, CONSOLE_LAST_NONMINIBUF_FRAME(con))) {
1492 Lisp_Object frmcons, devcons;
1494 set_console_last_nonminibuf_frame(con, Qnil);
1496 CONSOLE_FRAME_LOOP_NO_BREAK(frmcons, devcons, con) {
1497 Lisp_Object ecran = XCAR(frmcons);
1498 if (!FRAME_MINIBUF_ONLY_P(XFRAME(ecran))) {
1499 set_console_last_nonminibuf_frame(con, ecran);
1500 goto double_break_1;
1507 /* The following test is degenerate FALSE */
1508 if (called_from_delete_device < 0)
1509 /* then we're being called from delete-console, and we shouldn't
1510 try to find another default-minibuffer frame for the console.
1512 con->default_minibuffer_frame = Qnil;
1515 /* If we've deleted this console's default_minibuffer_frame, try to
1516 find another one. Prefer minibuffer-only frames, but also notice
1517 frames with other windows. */
1518 if (EQ(frame, con->default_minibuffer_frame)) {
1519 Lisp_Object frmcons, devcons;
1520 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1521 Lisp_Object frame_with_minibuf;
1522 /* Some frame we found on the same console, or nil if there are none. */
1523 Lisp_Object frame_on_same_console;
1525 frame_on_same_console = Qnil;
1526 frame_with_minibuf = Qnil;
1528 set_console_last_nonminibuf_frame(con, Qnil);
1530 CONSOLE_FRAME_LOOP_NO_BREAK(frmcons, devcons, con) {
1534 this = XCAR(frmcons);
1537 /* Consider only frames on the same console
1538 and only those with minibuffers. */
1539 if (FRAME_HAS_MINIBUF_P(f1)) {
1540 frame_with_minibuf = this;
1541 if (FRAME_MINIBUF_ONLY_P(f1))
1542 goto double_break_2;
1545 frame_on_same_console = this;
1549 if (!NILP(frame_on_same_console)) {
1550 /* We know that there must be some frame with a minibuffer out
1551 there. If this were not true, all of the frames present
1552 would have to be minibuffer-less, which implies that at some
1553 point their minibuffer frames must have been deleted, but
1554 that is prohibited at the top; you can't delete surrogate
1555 minibuffer frames. */
1556 if (NILP(frame_with_minibuf))
1559 con->default_minibuffer_frame = frame_with_minibuf;
1561 /* No frames left on this console--say no minibuffer either. */
1562 con->default_minibuffer_frame = Qnil;
1565 nuke_all_frame_slots(f); /* nobody should be accessing the device
1566 or anything else any more, and making
1567 them Qnil allows for better GC'ing
1568 in case a pointer to the dead frame
1569 continues to hang around. */
1570 f->framemeths = dead_console_methods;
1574 void io_error_delete_frame(Lisp_Object frame)
1576 delete_frame_internal(XFRAME(frame), 1, 0, 1);
1579 DEFUN("delete-frame", Fdelete_frame, 0, 2, "", /*
1580 Delete FRAME, permanently eliminating it from use.
1581 If omitted, FRAME defaults to the selected frame.
1582 A frame may not be deleted if its minibuffer is used by other frames.
1583 Normally, you cannot delete the last non-minibuffer-only frame (you must
1584 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
1585 second argument FORCE is non-nil, you can delete the last frame. (This
1586 will automatically call `save-buffers-kill-emacs'.)
1590 /* This function can GC */
1594 f = selected_frame();
1595 XSETFRAME(frame, f);
1601 delete_frame_internal(f, !NILP(force), 0, 0);
1605 /* Return mouse position in character cell units. */
1608 mouse_pixel_position_1(struct device *d, Lisp_Object * frame, int *x, int *y)
1610 switch (DEVMETH_OR_GIVEN(d, get_mouse_position, (d, frame, x, y), -1)) {
1619 *frame = DEVICE_SELECTED_FRAME(d);
1623 abort(); /* method is incorrectly written */
1629 DEFUN("mouse-pixel-position", Fmouse_pixel_position, 0, 1, 0, /*
1630 Return a list (WINDOW X . Y) giving the current mouse window and position.
1631 The position is given in pixel units, where (0, 0) is the upper-left corner