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 XEmacs.
8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with XEmacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Synched up with: FSF 19.30. */
25 /* This file has been Mule-ized. */
30 #include "buffer.h" /* for Vbuffer_alist */
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 struct display_line title_string_display_line;
120 /* Used by generate_title_string. Global because they get used so much that
121 the dynamic allocation time adds up. */
122 static Charc_dynarr *title_string_charc_dynarr;
126 mark_frame (Lisp_Object obj)
128 struct frame *f = XFRAME (obj);
130 #define MARKED_SLOT(x) mark_object (f->x)
131 #include "frameslots.h"
133 if (FRAME_LIVE_P (f)) /* device is nil for a dead frame */
134 MAYBE_FRAMEMETH (f, mark_frame, (f));
140 print_frame (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
142 struct frame *frm = XFRAME (obj);
146 error ("printing unreadable object #<frame %s 0x%x>",
147 XSTRING_DATA (frm->name), frm->header.uid);
149 sprintf (buf, "#<%s-frame ", !FRAME_LIVE_P (frm) ? "dead" :
150 FRAME_TYPE_NAME (frm));
151 write_c_string (buf, printcharfun);
152 print_internal (frm->name, printcharfun, 1);
153 sprintf (buf, " 0x%x>", frm->header.uid);
154 write_c_string (buf, printcharfun);
157 DEFINE_LRECORD_IMPLEMENTATION ("frame", frame,
158 mark_frame, print_frame, 0, 0, 0, 0,
162 nuke_all_frame_slots (struct frame *f)
164 #define MARKED_SLOT(x) f->x = Qnil
165 #include "frameslots.h"
168 /* Allocate a new frame object and set all its fields to reasonable
169 values. The root window is created but the minibuffer will be done
172 static struct frame *
173 allocate_frame_core (Lisp_Object device)
175 /* This function can GC */
177 Lisp_Object root_window;
178 struct frame *f = alloc_lcrecord_type (struct frame, &lrecord_frame);
181 nuke_all_frame_slots (f);
182 XSETFRAME (frame, f);
185 f->framemeths = XDEVICE (device)->devmeths;
186 f->buffer_alist = Fcopy_sequence (Vbuffer_alist);
188 root_window = allocate_window ();
189 XWINDOW (root_window)->frame = frame;
192 Just so that there is "something there."
193 Correct size will be set up later with change_frame_size. */
198 XWINDOW (root_window)->pixel_width = 10;
199 XWINDOW (root_window)->pixel_height = 9;
201 f->root_window = root_window;
202 f->selected_window = root_window;
203 f->last_nonminibuf_window = root_window;
205 /* cache of subwindows visible on frame */
206 f->subwindow_instance_cache = make_weak_list (WEAK_LIST_SIMPLE);
208 /* associated exposure ignore list */
209 f->subwindow_exposures = 0;
210 f->subwindow_exposures_tail = 0;
212 FRAME_SET_PAGENUMBER (f, 1);
214 /* Choose a buffer for the frame's root window. */
215 XWINDOW (root_window)->buffer = Qt;
219 buf = Fcurrent_buffer ();
220 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
221 a space), try to find another one. */
222 if (string_char (XSTRING (Fbuffer_name (buf)), 0) == ' ')
223 buf = Fother_buffer (buf, Qnil, Qnil);
224 Fset_window_buffer (root_window, buf, Qnil);
231 setup_normal_frame (struct frame *f)
233 Lisp_Object mini_window;
236 XSETFRAME (frame, f);
238 mini_window = allocate_window ();
239 XWINDOW (f->root_window)->next = mini_window;
240 XWINDOW (mini_window)->prev = f->root_window;
241 XWINDOW (mini_window)->mini_p = Qt;
242 XWINDOW (mini_window)->frame = frame;
243 f->minibuffer_window = mini_window;
244 f->has_minibuffer = 1;
246 XWINDOW (mini_window)->buffer = Qt;
247 Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
250 /* Make a frame using a separate minibuffer window on another frame.
251 MINI_WINDOW is the minibuffer window to use. nil means use the
252 default-minibuffer-frame. */
255 setup_frame_without_minibuffer (struct frame *f, Lisp_Object mini_window)
257 /* This function can GC */
258 Lisp_Object device = f->device;
260 if (!NILP (mini_window))
261 CHECK_LIVE_WINDOW (mini_window);
263 if (!NILP (mini_window)
264 && !EQ (DEVICE_CONSOLE (XDEVICE (device)),
265 FRAME_CONSOLE (XFRAME (XWINDOW (mini_window)->frame))))
266 error ("frame and minibuffer must be on the same console");
268 /* Do not create a default minibuffer frame on printer devices. */
269 if (NILP (mini_window)
270 && DEVICE_DISPLAY_P (XDEVICE (FRAME_DEVICE (f))))
272 struct console *con = XCONSOLE (FRAME_CONSOLE (f));
273 /* Use default-minibuffer-frame if possible. */
274 if (!FRAMEP (con->default_minibuffer_frame)
275 || ! FRAME_LIVE_P (XFRAME (con->default_minibuffer_frame)))
277 /* If there's no minibuffer frame to use, create one. */
278 con->default_minibuffer_frame
279 = call1 (Qmake_initial_minibuffer_frame, device);
281 mini_window = XFRAME (con->default_minibuffer_frame)->minibuffer_window;
284 /* Install the chosen minibuffer window, with proper buffer. */
285 if (!NILP (mini_window))
287 store_minibuf_frame_prop (f, mini_window);
288 Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
291 f->minibuffer_window = Qnil;
294 /* Make a frame containing only a minibuffer window. */
297 setup_minibuffer_frame (struct frame *f)
299 /* This function can GC */
300 /* First make a frame containing just a root window, no minibuffer. */
301 Lisp_Object mini_window;
304 XSETFRAME (frame, f);
307 f->has_minibuffer = 1;
309 /* Now label the root window as also being the minibuffer.
310 Avoid infinite looping on the window chain by marking next pointer
313 mini_window = f->minibuffer_window = f->root_window;
314 XWINDOW (mini_window)->mini_p = Qt;
315 XWINDOW (mini_window)->next = Qnil;
316 XWINDOW (mini_window)->prev = Qnil;
317 XWINDOW (mini_window)->frame = frame;
319 /* Put the proper buffer in that window. */
321 Fset_window_buffer (mini_window, Vminibuffer_zero, Qt);
325 make_sure_its_a_fresh_plist (Lisp_Object foolist)
327 if (CONSP (Fcar (foolist)))
329 /* looks like an alist to me. */
330 foolist = Fcopy_alist (foolist);
331 foolist = Fdestructive_alist_to_plist (foolist);
334 foolist = Fcopy_sequence (foolist);
339 DEFUN ("make-frame", Fmake_frame, 0, 2, "", /*
340 Create and return a new frame, displaying the current buffer.
341 Runs the functions listed in `create-frame-hook' after frame creation.
343 Optional argument PROPS is a property list (a list of alternating
344 keyword-value specifications) of properties for the new frame.
345 \(An alist is accepted for backward compatibility but should not
348 See `set-frame-properties', `default-x-frame-plist', and
349 `default-tty-frame-plist' for the specially-recognized properties.
355 Lisp_Object frame = Qnil, name = Qnil, minibuf;
356 struct gcpro gcpro1, gcpro2, gcpro3;
357 int speccount = specpdl_depth ();
358 int first_frame_on_device = 0;
359 int first_frame_on_console = 0;
361 d = decode_device (device);
362 XSETDEVICE (device, d);
364 /* PROPS and NAME may be freshly-created, so make sure to GCPRO. */
365 GCPRO3 (frame, props, name);
367 props = make_sure_its_a_fresh_plist (props);
368 if (DEVICE_SPECIFIC_FRAME_PROPS (d))
369 /* Put the device-specific props before the more general ones so
370 that they override them. */
371 props = nconc2 (props,
372 make_sure_its_a_fresh_plist
373 (*DEVICE_SPECIFIC_FRAME_PROPS (d)));
374 props = nconc2 (props, make_sure_its_a_fresh_plist (Vdefault_frame_plist));
375 Fcanonicalize_lax_plist (props, Qnil);
377 name = Flax_plist_get (props, Qname, Qnil);
380 else if (STRINGP (Vdefault_frame_name))
381 name = Vdefault_frame_name;
383 name = build_string ("emacs");
385 if (!NILP (Fstring_match (make_string ((const Bufbyte *) "\\.", 2), name,
387 signal_simple_error (". not allowed in frame names", name);
389 f = allocate_frame_core (device);
390 XSETFRAME (frame, f);
392 specbind (Qframe_being_created, name);
395 FRAMEMETH (f, init_frame_1, (f, props));
397 minibuf = Flax_plist_get (props, Qminibuffer, Qunbound);
398 if (UNBOUNDP (minibuf))
400 /* If minibuf is unspecified, then look for a minibuffer X resource. */
401 /* #### Not implemented any more. We need to fix things up so
402 that we search out all X resources and append them to the end of
403 props, above. This is the only way in general to assure
404 coherent behavior for all frame properties/resources/etc. */
407 props = Flax_plist_remprop (props, Qminibuffer);
409 if (EQ (minibuf, Qnone) || NILP (minibuf))
410 setup_frame_without_minibuffer (f, Qnil);
411 else if (EQ (minibuf, Qonly))
412 setup_minibuffer_frame (f);
413 else if (WINDOWP (minibuf))
414 setup_frame_without_minibuffer (f, minibuf);
415 else if (EQ (minibuf, Qt) || UNBOUNDP (minibuf))
416 setup_normal_frame (f);
418 signal_simple_error ("Invalid value for `minibuffer'", minibuf);
420 update_frame_window_mirror (f);
422 if (initialized && !DEVICE_STREAM_P (d))
424 if (!NILP (f->minibuffer_window))
425 reset_face_cachels (XWINDOW (f->minibuffer_window));
426 reset_face_cachels (XWINDOW (f->root_window));
429 /* If no frames on this device formerly existed, say this is the
430 first frame. It kind of assumes that frameless devices don't
431 exist, but it shouldn't be too harmful. */
432 if (NILP (DEVICE_FRAME_LIST (d)))
433 first_frame_on_device = 1;
435 /* This *must* go before the init_*() methods. Those functions
436 call Lisp code, and if any of them causes a warning to be displayed
437 and the *Warnings* buffer to be created, it won't get added to
438 the frame-specific version of the buffer-alist unless the frame
439 is accessible from the device. */
442 DEVICE_FRAME_LIST (d) = nconc2 (DEVICE_FRAME_LIST (d), Fcons (frame, Qnil));
444 DEVICE_FRAME_LIST (d) = Fcons (frame, DEVICE_FRAME_LIST (d));
445 RESET_CHANGED_SET_FLAGS;
447 /* Now make sure that the initial cached values are set correctly.
448 Do this after the init_frame method is called because that may
449 do things (e.g. create widgets) that are necessary for the
450 specifier value-changed methods to work OK. */
451 recompute_all_cached_specifiers_in_frame (f);
453 if (!DEVICE_STREAM_P (d))
455 init_frame_faces (f);
457 #ifdef HAVE_SCROLLBARS
458 /* Finish up resourcing the scrollbars. */
459 init_frame_scrollbars (f);
463 /* Create the initial toolbars. We have to do this after the frame
464 methods are called because it may potentially call some things itself
465 which depend on the normal frame methods having initialized
467 init_frame_toolbars (f);
469 reset_face_cachels (XWINDOW (FRAME_SELECTED_WINDOW (f)));
470 reset_glyph_cachels (XWINDOW (FRAME_SELECTED_WINDOW (f)));
472 change_frame_size (f, f->height, f->width, 0);
475 MAYBE_FRAMEMETH (f, init_frame_2, (f, props));
476 Fset_frame_properties (frame, props);
477 MAYBE_FRAMEMETH (f, init_frame_3, (f));
479 /* Hallelujah, praise the lord. */
480 f->init_finished = 1;
482 /* If this is the first frame on the device, make it the selected one. */
483 if (first_frame_on_device && NILP (DEVICE_SELECTED_FRAME (d)))
484 set_device_selected_frame (d, frame);
486 /* If at startup or if the current console is a stream console
487 (usually also at startup), make this console the selected one
488 so that messages show up on it. */
489 if (NILP (Fselected_console ()) ||
490 CONSOLE_STREAM_P (XCONSOLE (Fselected_console ())))
491 Fselect_console (DEVICE_CONSOLE (d));
493 first_frame_on_console =
494 (first_frame_on_device &&
495 XINT (Flength (CONSOLE_DEVICE_LIST (XCONSOLE (DEVICE_CONSOLE (d)))))
498 /* #### all this calling of frame methods at various odd times
499 is somewhat of a mess. It's necessary to do it this way due
500 to strange console-type-specific things that need to be done. */
501 MAYBE_FRAMEMETH (f, after_init_frame, (f, first_frame_on_device,
502 first_frame_on_console));
504 if (!DEVICE_STREAM_P (d))
506 /* Now initialise the gutters. This won't change the frame size,
507 but is needed as input to the layout that change_frame_size
508 will eventually do. Unfortunately gutter sizing code relies
509 on the frame in question being visible so we can't do this
511 init_frame_gutters (f);
513 change_frame_size (f, f->height, f->width, 0);
516 if (first_frame_on_device)
518 if (first_frame_on_console)
519 va_run_hook_with_args (Qcreate_console_hook, 1, DEVICE_CONSOLE (d));
520 va_run_hook_with_args (Qcreate_device_hook, 1, device);
522 va_run_hook_with_args (Qcreate_frame_hook, 1, frame);
524 /* Initialize custom-specific stuff. */
525 if (!UNBOUNDP (symbol_function (XSYMBOL (Qcustom_initialize_frame))))
526 call1 (Qcustom_initialize_frame, frame);
528 unbind_to (speccount, Qnil);
535 /* this function should be used in most cases when a Lisp function is passed
536 a FRAME argument. Use this unless you don't accept nil == current frame
537 (in which case, do a CHECK_LIVE_FRAME() and then an XFRAME()) or you
538 allow dead frames. Note that very few functions should accept dead
539 frames. It could be argued that functions should just do nothing when
540 given a dead frame, but the presence of a dead frame usually indicates
541 an oversight in the Lisp code that could potentially lead to strange
542 results and so it is better to catch the error early.
544 If you only accept X frames, use decode_x_frame(), which does what this
545 function does but also makes sure the frame is an X frame. */
548 decode_frame (Lisp_Object frame)
551 return selected_frame ();
553 CHECK_LIVE_FRAME (frame);
554 return XFRAME (frame);
558 decode_frame_or_selected (Lisp_Object cdf)
561 cdf = CONSOLE_SELECTED_DEVICE (decode_console (cdf));
563 cdf = DEVICE_SELECTED_FRAME (decode_device (cdf));
564 return decode_frame (cdf);
568 make_frame (struct frame *f)
571 XSETFRAME (frame, f);
577 * window size changes are held up during critical regions. Afterwards,
578 * we want to deal with any delayed changes.
581 hold_frame_size_changes (void)
587 unhold_one_frame_size_changes (struct frame *f)
591 if (f->size_change_pending)
592 change_frame_size (f, f->new_height, f->new_width, 0);
596 unhold_frame_size_changes (void)
598 Lisp_Object frmcons, devcons, concons;
600 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
601 unhold_one_frame_size_changes (XFRAME (XCAR (frmcons)));
605 invalidate_vertical_divider_cache_in_frame (struct frame *f)
607 /* Invalidate cached value of needs_vertical_divider_p in
608 every and all windows */
609 map_windows (f, invalidate_vertical_divider_cache_in_window, 0);
613 * Frame size may change due to changes in scrollbars, toolbars,
614 * default font etc. These changes are applied early in redisplay
618 adjust_frame_size (struct frame *f)
620 int keep_char_size = 0;
622 XSETFRAME (frame, f);
624 if (!f->size_slipped)
627 /* Don't adjust tty frames. #### May break when TTY have menubars.
628 Then, write an Vadjust_frame_function which will return t for TTY
629 frames. Another solution is frame_size_fixed_p method for TTYs,
630 which always returned yes it's fixed.
632 if (!FRAME_WIN_P (f))
634 CLEAR_FRAME_SIZE_SLIPPED (f);
638 /* frame_size_fixed_p tells that frame size cannot currently
639 be changed change due to external conditions */
640 if (!FRAMEMETH_OR_GIVEN (f, frame_size_fixed_p, (f), 0))
642 if (NILP (Vadjust_frame_function))
644 else if (EQ (Vadjust_frame_function, Qt))
648 NILP (call1_trapping_errors ("Error in adjust-frame-function",
649 Vadjust_frame_function, frame));
652 Fset_frame_size (frame, make_int (FRAME_CHARWIDTH(f)),
653 make_int (FRAME_CHARHEIGHT(f)), Qnil);
659 pixel_to_char_size (f, FRAME_PIXWIDTH(f), FRAME_PIXHEIGHT(f),
661 change_frame_size (f, height, width, 0);
662 CLEAR_FRAME_SIZE_SLIPPED (f);
667 * This is a "specifier changed in frame" handler for various specifiers
668 * changing which causes frame size adjustment
671 frame_size_slipped (Lisp_Object specifier, struct frame *f,
674 MARK_FRAME_SIZE_SLIPPED(f);
677 DEFUN ("framep", Fframep, 1, 1, 0, /*
678 Return non-nil if OBJECT is a frame.
679 Also see `frame-live-p'.
680 Note that FSF Emacs kludgily returns a value indicating what type of
681 frame this is. Use the cleaner function `frame-type' for that.
685 return FRAMEP (object) ? Qt : Qnil;
688 DEFUN ("frame-live-p", Fframe_live_p, 1, 1, 0, /*
689 Return non-nil if OBJECT is a frame which has not been deleted.
693 return FRAMEP (object) && FRAME_LIVE_P (XFRAME (object)) ? Qt : Qnil;
697 DEFUN ("focus-frame", Ffocus_frame, 1, 1, 0, /*
698 Select FRAME and give it the window system focus.
699 This function is not affected by the value of `focus-follows-mouse'.
703 CHECK_LIVE_FRAME (frame);
705 MAYBE_DEVMETH (XDEVICE (FRAME_DEVICE (XFRAME (frame))), focus_on_frame,
707 /* FRAME will be selected by the time we receive the next event.
708 However, it is better to select it explicitly now, in case the
709 Lisp code depends on frame being selected. */
710 Fselect_frame (frame);
714 /* Called from Fselect_window() */
716 select_frame_1 (Lisp_Object frame)
718 struct frame *f = XFRAME (frame);
719 Lisp_Object old_selected_frame = Fselected_frame (Qnil);
721 if (EQ (frame, old_selected_frame))
724 /* now select the frame's device */
725 set_device_selected_frame (XDEVICE (FRAME_DEVICE (f)), frame);
726 select_device_1 (FRAME_DEVICE (f));
728 update_frame_window_mirror (f);
731 DEFUN ("select-frame", Fselect_frame, 1, 1, 0, /*
732 Select the frame FRAME.
733 Subsequent editing commands apply to its selected window.
734 The selection of FRAME lasts until the next time the user does
735 something to select a different frame, or until the next time this
738 Note that this does not actually cause the window-system focus to be
739 set to this frame, or the `select-frame-hook' or `deselect-frame-hook'
740 to be run, until the next time that XEmacs is waiting for an event.
742 Also note that when focus-follows-mouse is non-nil, the frame
743 selection is temporary and is reverted when the current command
744 terminates, much like the buffer selected by `set-buffer'. In order
745 to effect a permanent focus change, use `focus-frame'.
749 CHECK_LIVE_FRAME (frame);
751 /* select the frame's selected window. This will call
752 selected_frame_1(). */
753 Fselect_window (FRAME_SELECTED_WINDOW (XFRAME (frame)), Qnil);
755 /* Nothing should be depending on the return value of this function.
756 But, of course, there is stuff out there which is. */
760 /* use this to retrieve the currently selected frame. You should use
761 this in preference to Fselected_frame (Qnil) unless you are prepared
762 to handle the possibility of there being no selected frame (this
763 happens at some points during startup). */
766 selected_frame (void)
768 Lisp_Object device = Fselected_device (Qnil);
769 Lisp_Object frame = DEVICE_SELECTED_FRAME (XDEVICE (device));
771 signal_simple_error ("No frames exist on device", device);
772 return XFRAME (frame);
775 /* use this instead of XFRAME (DEVICE_SELECTED_FRAME (d)) to catch
776 the possibility of there being no frames on the device (just created).
777 There is no point doing this inside of redisplay because errors
778 cause an abort(), indicating a flaw in the logic, and error_check_frame()
779 will catch this just as well. */
782 device_selected_frame (struct device *d)
784 Lisp_Object frame = DEVICE_SELECTED_FRAME (d);
788 XSETDEVICE (device, d);
789 signal_simple_error ("No frames exist on device", device);
791 return XFRAME (frame);
796 xxDEFUN ("handle-switch-frame", Fhandle_switch_frame, 1, 2, "e", /*
797 Handle a switch-frame event EVENT.
798 Switch-frame events are usually bound to this function.
799 A switch-frame event tells Emacs that the window manager has requested
800 that the user's events be directed to the frame mentioned in the event.
801 This function selects the selected window of the frame of EVENT.
803 If EVENT is frame object, handle it as if it were a switch-frame event
808 /* Preserve prefix arg that the command loop just cleared. */
809 XCONSOLE (Vselected_console)->prefix_arg = Vcurrent_prefix_arg;
811 run_hook (Qmouse_leave_buffer_hook);
813 return do_switch_frame (frame, no_enter, 0);
816 /* A load of garbage. */
817 xxDEFUN ("ignore-event", Fignore_event, 0, 0, "", /*
818 Do nothing, but preserve any prefix argument already specified.
819 This is a suitable binding for iconify-frame and make-frame-visible.
823 struct console *c = XCONSOLE (Vselected_console);
825 c->prefix_arg = Vcurrent_prefix_arg;
831 DEFUN ("selected-frame", Fselected_frame, 0, 1, 0, /*
832 Return the frame that is now selected on device DEVICE.
833 If DEVICE is not specified, the selected device will be used.
834 If no frames exist on the device, nil is returned.
838 if (NILP (device) && NILP (Fselected_device (Qnil)))
839 return Qnil; /* happens early in temacs */
840 return DEVICE_SELECTED_FRAME (decode_device (device));
844 frame_first_window (struct frame *f)
846 Lisp_Object w = f->root_window;
850 if (! NILP (XWINDOW (w)->hchild))
851 w = XWINDOW (w)->hchild;
852 else if (! NILP (XWINDOW (w)->vchild))
853 w = XWINDOW (w)->vchild;
861 DEFUN ("active-minibuffer-window", Factive_minibuffer_window, 0, 0, 0, /*
862 Return the currently active minibuffer window, or nil if none.
866 return minibuf_level ? minibuf_window : Qnil;
869 DEFUN ("last-nonminibuf-frame", Flast_nonminibuf_frame, 0, 1, 0, /*
870 Return the most-recently-selected non-minibuffer-only frame on CONSOLE.
871 This will always be the same as (selected-frame device) unless the
872 selected frame is a minibuffer-only frame.
873 CONSOLE defaults to the selected console if omitted.
879 XSETCONSOLE (console, decode_console (console));
880 /* Just in case the machinations in delete_frame_internal() resulted
881 in the last-nonminibuf-frame getting out of sync, make sure and
882 return the selected frame if it's acceptable. */
883 result = Fselected_frame (CONSOLE_SELECTED_DEVICE (XCONSOLE (console)));
884 if (!NILP (result) && !FRAME_MINIBUF_ONLY_P (XFRAME (result)))
886 return CONSOLE_LAST_NONMINIBUF_FRAME (XCONSOLE (console));
889 DEFUN ("frame-root-window", Fframe_root_window, 0, 1, 0, /*
890 Return the root-window of FRAME.
891 If omitted, FRAME defaults to the currently selected frame.
895 struct frame *f = decode_frame (frame);
896 return FRAME_ROOT_WINDOW (f);
899 DEFUN ("frame-selected-window", Fframe_selected_window, 0, 1, 0, /*
900 Return the selected window of frame object FRAME.
901 If omitted, FRAME defaults to the currently selected frame.
905 struct frame *f = decode_frame (frame);
906 return FRAME_SELECTED_WINDOW (f);
910 set_frame_selected_window (struct frame *f, Lisp_Object window)
912 assert (XFRAME (WINDOW_FRAME (XWINDOW (window))) == f);
913 f->selected_window = window;
914 if (!MINI_WINDOW_P (XWINDOW (window)) || FRAME_MINIBUF_ONLY_P (f))
916 if (!EQ (f->last_nonminibuf_window, window))
919 MARK_TOOLBAR_CHANGED;
923 f->last_nonminibuf_window = window;
927 DEFUN ("set-frame-selected-window", Fset_frame_selected_window, 2, 2, 0, /*
928 Set the selected window of frame object FRAME to WINDOW.
929 If FRAME is nil, the selected frame is used.
930 If FRAME is the selected frame, this makes WINDOW the selected window.
934 XSETFRAME (frame, decode_frame (frame));
935 CHECK_LIVE_WINDOW (window);
937 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
938 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
940 if (XFRAME (frame) == selected_frame ())
941 return Fselect_window (window, Qnil);
943 set_frame_selected_window (XFRAME (frame), window);
948 DEFUN ("frame-device", Fframe_device, 0, 1, 0, /*
949 Return the device that FRAME is on.
950 If omitted, FRAME defaults to the currently selected frame.
954 return FRAME_DEVICE (decode_frame (frame));
958 is_surrogate_for_selected_frame (struct frame *f)
960 struct device *d = XDEVICE (f->device);
961 struct frame *dsf = device_selected_frame (d);
963 /* Can't be a surrogate for ourselves. */
967 if (!FRAME_HAS_MINIBUF_P (dsf) &&
968 f == XFRAME (WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (dsf)))))
975 frame_matches_frame_spec (Lisp_Object frame, Lisp_Object type)
977 struct frame *f = XFRAME (frame);
981 CHECK_LIVE_WINDOW (type);
983 if (EQ (FRAME_MINIBUF_WINDOW (f), type)
984 /* Check that F either is, or has forwarded
985 its focus to, TYPE's frame. */
986 && (EQ (WINDOW_FRAME (XWINDOW (type)), frame)
987 || EQ (WINDOW_FRAME (XWINDOW (type)),
988 FRAME_FOCUS_FRAME (f))))
995 if (EQ (type, Qvisible) || EQ (type, Qiconic) || EQ (type, Qvisible_iconic)
996 || EQ (type, Qvisible_nomini) || EQ (type, Qiconic_nomini)
997 || EQ (type, Qvisible_iconic_nomini))
998 FRAME_SAMPLE_VISIBILITY (f);
1004 type = Qvisible_iconic;
1006 if (EQ (type, Qvisible))
1007 return FRAME_VISIBLE_P (f);
1008 if (EQ (type, Qiconic))
1009 return FRAME_ICONIFIED_P (f);
1010 if (EQ (type, Qinvisible))
1011 return !FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f);
1012 if (EQ (type, Qvisible_iconic))
1013 return FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f);
1014 if (EQ (type, Qinvisible_iconic))
1015 return !FRAME_VISIBLE_P (f);
1017 if (EQ (type, Qnomini))
1018 return !FRAME_MINIBUF_ONLY_P (f);
1019 if (EQ (type, Qvisible_nomini))
1020 return FRAME_VISIBLE_P (f) && !FRAME_MINIBUF_ONLY_P (f);
1021 if (EQ (type, Qiconic_nomini))
1022 return FRAME_ICONIFIED_P (f) && !FRAME_MINIBUF_ONLY_P (f);
1023 if (EQ (type, Qinvisible_nomini))
1024 return !FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P (f) &&
1025 !FRAME_MINIBUF_ONLY_P (f);
1026 if (EQ (type, Qvisible_iconic_nomini))
1027 return ((FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f))
1028 && !FRAME_MINIBUF_ONLY_P (f));
1029 if (EQ (type, Qinvisible_iconic_nomini))
1030 return !FRAME_VISIBLE_P (f) && !FRAME_MINIBUF_ONLY_P (f);
1036 device_matches_device_spec (Lisp_Object device, Lisp_Object device_spec)
1038 if (EQ (device_spec, Qwindow_system))
1039 return DEVICE_WIN_P (XDEVICE (device));
1040 if (DEVICEP (device_spec))
1041 return EQ (device, device_spec);
1042 if (CONSOLEP (device_spec))
1043 return EQ (DEVICE_CONSOLE (XDEVICE (device)), device_spec);
1044 if (valid_console_type_p (device_spec))
1045 return EQ (DEVICE_TYPE (XDEVICE (device)), device_spec);
1049 /* Return the next frame in the frame list after FRAME.
1050 WHICH-FRAMES and WHICH-DEVICES control which frames and devices
1051 are considered; see `next-frame'. */
1054 next_frame (Lisp_Object frame, Lisp_Object which_frames, Lisp_Object which_devices)
1056 Lisp_Object first = Qnil;
1057 Lisp_Object devcons, concons;
1060 CHECK_LIVE_FRAME (frame);
1062 DEVICE_LOOP_NO_BREAK (devcons, concons)
1064 Lisp_Object device = XCAR (devcons);
1065 Lisp_Object frmcons;
1067 if (!device_matches_device_spec (device, which_devices))
1069 if (EQ (device, FRAME_DEVICE (XFRAME (frame))))
1074 DEVICE_FRAME_LOOP (frmcons, XDEVICE (device))
1076 Lisp_Object f = XCAR (frmcons);
1080 if (frame_matches_frame_spec (f, which_frames))
1091 if (NILP (first) && frame_matches_frame_spec (f, which_frames))
1099 /* We went through the whole frame list without finding a single
1100 acceptable frame. Return the original frame. */
1103 /* There were no acceptable frames in the list after FRAME; otherwise,
1104 we would have returned directly from the loop. Since FIRST is the last
1105 acceptable frame in the list, return it. */
1109 /* Return the previous frame in the frame list before FRAME.
1110 WHICH-FRAMES and WHICH-DEVICES control which frames and devices
1111 are considered; see `next-frame'. */
1114 previous_frame (Lisp_Object frame, Lisp_Object which_frames, Lisp_Object which_devices)
1116 Lisp_Object devcons, concons;
1117 Lisp_Object last = Qnil;
1119 CHECK_LIVE_FRAME (frame);
1121 DEVICE_LOOP_NO_BREAK (devcons, concons)
1123 Lisp_Object device = XCAR (devcons);
1124 Lisp_Object frmcons;
1126 if (!device_matches_device_spec (device, which_devices))
1128 if (EQ (device, FRAME_DEVICE (XFRAME (frame)))
1134 DEVICE_FRAME_LOOP (frmcons, XDEVICE (device))
1136 Lisp_Object f = XCAR (frmcons);
1145 if (frame_matches_frame_spec (f, which_frames))
1152 /* We went through the whole frame list without finding a single
1153 acceptable frame. Return the original frame. */
1156 /* There were no acceptable frames in the list before FRAME; otherwise,
1157 we would have returned directly from the loop. Since LAST is the last
1158 acceptable frame in the list, return it. */
1162 DEFUN ("next-frame", Fnext_frame, 0, 3, 0, /*
1163 Return the next frame of the right type in the frame list after FRAME.
1164 WHICH-FRAMES controls which frames are eligible to be returned; all
1165 others will be skipped. Note that if there is only one eligible
1166 frame, then `next-frame' called repeatedly will always return
1167 the same frame, and if there is no eligible frame, then FRAME is
1170 Possible values for WHICH-FRAMES are
1172 'visible Consider only frames that are visible.
1173 'iconic Consider only frames that are iconic.
1174 'invisible Consider only frames that are invisible
1175 (this is different from iconic).
1176 'visible-iconic Consider frames that are visible or iconic.
1177 'invisible-iconic Consider frames that are invisible or iconic.
1178 'nomini Consider all frames except minibuffer-only ones.
1179 'visible-nomini Like `visible' but omits minibuffer-only frames.
1180 'iconic-nomini Like `iconic' but omits minibuffer-only frames.
1181 'invisible-nomini Like `invisible' but omits minibuffer-only frames.
1182 'visible-iconic-nomini Like `visible-iconic' but omits minibuffer-only
1184 'invisible-iconic-nomini Like `invisible-iconic' but omits minibuffer-only
1186 any other value Consider all frames.
1188 If WHICH-FRAMES is omitted, 'nomini is used. A value for WHICH-FRAMES
1189 of 0 (a number) is treated like 'iconic, for backwards compatibility.
1191 If WHICH-FRAMES is a window, include only its own frame and any frame
1192 now using that window as the minibuffer.
1194 The optional third argument WHICH-DEVICES further clarifies on which
1195 devices to search for frames as specified by WHICH-FRAMES.
1196 If nil or omitted, search all devices on FRAME's console.
1197 If a device, only search that device.
1198 If a console, search all devices on that console.
1199 If a device type, search all devices of that type.
1200 If `window-system', search all window-system devices.
1201 Any other non-nil value means search all devices.
1203 (frame, which_frames, which_devices))
1205 XSETFRAME (frame, decode_frame (frame));
1207 return next_frame (frame, which_frames, which_devices);
1210 DEFUN ("previous-frame", Fprevious_frame, 0, 3, 0, /*
1211 Return the next frame of the right type in the frame list after FRAME.
1212 WHICH-FRAMES controls which frames are eligible to be returned; all
1213 others will be skipped. Note that if there is only one eligible
1214 frame, then `previous-frame' called repeatedly will always return
1215 the same frame, and if there is no eligible frame, then FRAME is
1218 See `next-frame' for an explanation of the WHICH-FRAMES and WHICH-DEVICES
1221 (frame, which_frames, which_devices))
1223 XSETFRAME (frame, decode_frame (frame));
1225 return previous_frame (frame, which_frames, which_devices);
1228 /* Return any frame for which PREDICATE is non-zero, or return Qnil
1229 if there aren't any. */
1232 find_some_frame (int (*predicate) (Lisp_Object, void *),
1235 Lisp_Object framecons, devcons, concons;
1237 FRAME_LOOP_NO_BREAK (framecons, devcons, concons)
1239 Lisp_Object frame = XCAR (framecons);
1241 if ((predicate) (frame, closure))
1250 /* extern void free_line_insertion_deletion_costs (struct frame *f); */
1252 /* Return 1 if it is ok to delete frame F;
1253 0 if all frames aside from F are invisible.
1254 (Exception: if F is a stream frame, it's OK to delete if
1255 any other frames exist.) */
1258 other_visible_frames (struct frame *f)
1262 XSETFRAME (frame, f);
1263 if (FRAME_STREAM_P (f))
1264 return !EQ (frame, next_frame (frame, Qt, Qt));
1265 return !EQ (frame, next_frame (frame, Qvisible_iconic_nomini, Qt));
1270 If FORCE is non-zero, allow deletion of the only frame.
1272 If CALLED_FROM_DELETE_DEVICE is non-zero, then, if
1273 deleting the last frame on a device, just delete it,
1274 instead of calling `delete-device'.
1276 If FROM_IO_ERROR is non-zero, then the frame is gone due
1277 to an I/O error. This affects what happens if we exit
1278 (we do an emergency exit instead of `save-buffers-kill-emacs'.)
1282 delete_frame_internal (struct frame *f, int force,
1283 int called_from_delete_device,
1286 /* This function can GC */
1287 int minibuffer_selected;
1289 struct console *con;
1292 Lisp_Object console;
1293 struct gcpro gcpro1;
1295 /* OK to delete an already deleted frame. */
1296 if (! FRAME_LIVE_P (f))
1299 XSETFRAME (frame, f);
1302 device = FRAME_DEVICE (f);
1303 d = XDEVICE (device);
1304 console = DEVICE_CONSOLE (d);
1305 con = XCONSOLE (console);
1307 if (!called_from_delete_device &&
1308 !(MAYBE_INT_DEVMETH (d, device_implementation_flags, ())
1309 & XDEVIMPF_FRAMELESS_OK))
1311 /* If we're deleting the only non-minibuffer frame on the
1312 device, delete the device. */
1313 if (EQ (frame, next_frame (frame, Qnomini, FRAME_DEVICE (f))))
1315 delete_device_internal (d, force, 0, from_io_error);
1321 /* In FSF, delete-frame will not normally allow you to delete the
1322 last visible frame. This was too annoying, so we changed it to the
1323 only frame. However, this would let people shoot themselves by
1324 deleting all frames which were either visible or iconified and thus
1325 losing any way of communicating with the still running XEmacs process.
1326 So we put it back. */
1327 if (!force && !allow_deletion_of_last_visible_frame &&
1328 !other_visible_frames (f))
1329 error ("Attempt to delete the sole visible or iconified frame");
1331 /* Does this frame have a minibuffer, and is it the surrogate
1332 minibuffer for any other frame? */
1333 if (FRAME_HAS_MINIBUF_P (f))
1335 Lisp_Object frmcons, devcons, concons;
1337 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
1339 Lisp_Object this = XCAR (frmcons);
1341 if (! EQ (this, frame)
1342 && EQ (frame, (WINDOW_FRAME
1344 (FRAME_MINIBUF_WINDOW (XFRAME (this)))))))
1346 /* We've found another frame whose minibuffer is on
1349 ("Attempt to delete a surrogate minibuffer frame", frame);
1354 /* Test for popup frames hanging around. */
1355 /* Deletion of a parent frame with popups is deadly. */
1357 Lisp_Object frmcons, devcons, concons;
1359 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
1361 Lisp_Object this = XCAR (frmcons);
1364 if (! EQ (this, frame))
1366 struct device *devcons_d = XDEVICE (XCAR (devcons));
1367 if (EQ (frame, DEVMETH_OR_GIVEN (devcons_d, get_frame_parent,
1370 /* We've found a popup frame whose parent is this frame. */
1372 ("Attempt to delete a frame with live popups", frame);
1377 /* Before here, we haven't made any dangerous changes (just checked for
1378 error conditions). Now run the delete-frame-hook. Remember that
1379 user code there could do any number of dangerous things, including
1380 signalling an error. */
1382 va_run_hook_with_args (Qdelete_frame_hook, 1, frame);
1384 if (!FRAME_LIVE_P (f)) /* Make sure the delete-frame-hook didn't */
1385 { /* go ahead and delete anything. */
1390 /* Call the delete-device-hook and delete-console-hook now if
1391 appropriate, before we do any dangerous things -- they too could
1393 if (XINT (Flength (DEVICE_FRAME_LIST (d))) == 1)
1395 va_run_hook_with_args (Qdelete_device_hook, 1, device);
1396 if (!FRAME_LIVE_P (f)) /* Make sure the delete-device-hook didn't */
1397 { /* go ahead and delete anything. */
1402 if (XINT (Flength (CONSOLE_DEVICE_LIST (con))) == 1)
1404 va_run_hook_with_args (Qdelete_console_hook, 1, console);
1405 if (!FRAME_LIVE_P (f)) /* Make sure the delete-console-hook didn't */
1406 { /* go ahead and delete anything. */
1413 minibuffer_selected = EQ (minibuf_window, Fselected_window (Qnil));
1415 /* If we were focused on this frame, then we're not any more.
1416 Assume that we lost the focus; that way, the call to
1417 Fselect_frame() below won't end up making us explicitly
1418 focus on another frame, which is generally undesirable in
1419 a point-to-type world. If our mouse ends up sitting over
1420 another frame, we will receive a FocusIn event and end up
1421 making that frame the selected frame.
1423 #### This may not be an ideal solution in a click-to-type
1424 world (in that case, we might want to explicitly choose
1425 another frame to have the focus, rather than relying on
1426 the WM, which might focus on a frame in a different app
1427 or focus on nothing at all). But there's no easy way
1428 to detect which focus model we're running on, and the
1429 alternative is more heinous. */
1431 if (EQ (frame, DEVICE_FRAME_WITH_FOCUS_REAL (d)))
1432 DEVICE_FRAME_WITH_FOCUS_REAL (d) = Qnil;
1433 if (EQ (frame, DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d)))
1434 DEVICE_FRAME_WITH_FOCUS_FOR_HOOKS (d) = Qnil;
1435 if (EQ (frame, DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS (d)))
1436 DEVICE_FRAME_THAT_OUGHT_TO_HAVE_FOCUS (d) = Qnil;
1438 /* Don't allow the deleted frame to remain selected.
1439 Note that in the former scheme of things, this would
1440 have caused us to regain the focus. This no longer
1441 applies (see above); I think the new behavior is more
1442 logical. If someone disagrees, it can always be
1443 changed (or a new user variable can be introduced, ugh.) */
1444 if (EQ (frame, DEVICE_SELECTED_FRAME (d)))
1448 /* If this is a popup frame, select its parent if possible.
1449 Otherwise, find another visible frame; if none, just take any frame.
1450 First try the same device, then the same console. */
1452 next = DEVMETH_OR_GIVEN (d, get_frame_parent, (f), Qnil);
1453 if (NILP (next) || EQ (next, frame) || ! FRAME_LIVE_P (XFRAME (next)))
1454 next = next_frame (frame, Qvisible, device);
1455 if (NILP (next) || EQ (next, frame))
1456 next = next_frame (frame, Qvisible, console);
1457 if (NILP (next) || EQ (next, frame))
1458 next = next_frame (frame, Qvisible, Qt);
1459 if (NILP (next) || EQ (next, frame))
1460 next = next_frame (frame, Qt, device);
1461 if (NILP (next) || EQ (next, frame))
1462 next = next_frame (frame, Qt, console);
1463 if (NILP (next) || EQ (next, frame))
1464 next = next_frame (frame, Qt, Qt);
1466 /* if we haven't found another frame at this point
1467 then there aren't any. */
1468 if (NILP (next) || EQ (next, frame))
1473 /* if this is the global selected frame, select another one. */
1474 if (EQ (frame, Fselected_frame (Qnil)))
1476 Fselect_frame (next);
1480 * If the new frame we just selected is on a different
1481 * device then we still need to change DEVICE_SELECTED_FRAME(d)
1482 * to a live frame, if there are any left on this device.
1484 if (!EQ (device, FRAME_DEVICE(XFRAME(next))))
1486 Lisp_Object next_f = next_frame (frame, Qt, device);
1487 if (NILP (next_f) || EQ (next_f, frame))
1488 set_device_selected_frame (d, Qnil);
1490 set_device_selected_frame (d, next_f);
1492 else if (! did_select)
1493 set_device_selected_frame (d, next);
1498 /* Don't allow minibuf_window to remain on a deleted frame. */
1499 if (EQ (f->minibuffer_window, minibuf_window))
1501 struct frame *sel_frame = selected_frame ();
1502 Fset_window_buffer (sel_frame->minibuffer_window,
1503 XWINDOW (minibuf_window)->buffer, Qt);
1504 minibuf_window = sel_frame->minibuffer_window;
1506 /* If the dying minibuffer window was selected,
1507 select the new one. */
1508 if (minibuffer_selected)
1509 Fselect_window (minibuf_window, Qnil);
1512 /* After this point, no errors must be allowed to occur. */
1514 #ifdef HAVE_MENUBARS
1515 free_frame_menubars (f);
1517 #ifdef HAVE_SCROLLBARS
1518 free_frame_scrollbars (f);
1520 #ifdef HAVE_TOOLBARS
1521 free_frame_toolbars (f);
1523 free_frame_gutters (f);
1524 /* Unfortunately deleting the frame will also delete the parent of
1525 all of the subwindow instances current on the frame. I think this
1526 can lead to bad things when trying to finalize the
1527 instances. Thus we loop over all instance caches calling the
1528 finalize method for each instance. */
1529 free_frame_subwindow_instances (f);
1531 /* This must be done before the window and window_mirror structures
1532 are freed. The scrollbar information is attached to them. */
1533 MAYBE_FRAMEMETH (f, delete_frame, (f));
1535 /* Mark all the windows that used to be on FRAME as deleted, and then
1536 remove the reference to them. */
1537 delete_all_subwindows (XWINDOW (f->root_window));
1538 f->root_window = Qnil;
1540 /* clear out the cached glyph information */
1541 f->subwindow_instance_cache = Qnil;
1543 /* Remove the frame now from the list. This way, any events generated
1544 on this frame by the maneuvers below will disperse themselves. */
1546 /* This used to be Fdelq(), but that will cause a seg fault if the
1547 QUIT checker happens to get invoked, because the frame list is in
1548 an inconsistent state. */
1549 d->frame_list = delq_no_quit (frame, d->frame_list);
1550 RESET_CHANGED_SET_FLAGS;
1555 free_window_mirror (f->root_mirror);
1556 /* free_line_insertion_deletion_costs (f); */
1558 /* If we've deleted the last non-minibuf frame, then try to find
1560 if (EQ (frame, CONSOLE_LAST_NONMINIBUF_FRAME (con)))
1562 Lisp_Object frmcons, devcons;
1564 set_console_last_nonminibuf_frame (con, Qnil);
1566 CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, con)
1568 Lisp_Object ecran = XCAR (frmcons);
1569 if (!FRAME_MINIBUF_ONLY_P (XFRAME (ecran)))
1571 set_console_last_nonminibuf_frame (con, ecran);
1572 goto double_break_1;
1579 /* The following test is degenerate FALSE */
1580 if (called_from_delete_device < 0)
1581 /* then we're being called from delete-console, and we shouldn't
1582 try to find another default-minibuffer frame for the console.
1584 con->default_minibuffer_frame = Qnil;
1587 /* If we've deleted this console's default_minibuffer_frame, try to
1588 find another one. Prefer minibuffer-only frames, but also notice
1589 frames with other windows. */
1590 if (EQ (frame, con->default_minibuffer_frame))
1592 Lisp_Object frmcons, devcons;
1593 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1594 Lisp_Object frame_with_minibuf;
1595 /* Some frame we found on the same console, or nil if there are none. */
1596 Lisp_Object frame_on_same_console;
1598 frame_on_same_console = Qnil;
1599 frame_with_minibuf = Qnil;
1601 set_console_last_nonminibuf_frame (con, Qnil);
1603 CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, con)
1608 this = XCAR (frmcons);
1611 /* Consider only frames on the same console
1612 and only those with minibuffers. */
1613 if (FRAME_HAS_MINIBUF_P (f1))
1615 frame_with_minibuf = this;
1616 if (FRAME_MINIBUF_ONLY_P (f1))
1617 goto double_break_2;
1620 frame_on_same_console = this;
1624 if (!NILP (frame_on_same_console))
1626 /* We know that there must be some frame with a minibuffer out
1627 there. If this were not true, all of the frames present
1628 would have to be minibuffer-less, which implies that at some
1629 point their minibuffer frames must have been deleted, but
1630 that is prohibited at the top; you can't delete surrogate
1631 minibuffer frames. */
1632 if (NILP (frame_with_minibuf))
1635 con->default_minibuffer_frame = frame_with_minibuf;
1638 /* No frames left on this console--say no minibuffer either. */
1639 con->default_minibuffer_frame = Qnil;
1642 nuke_all_frame_slots (f); /* nobody should be accessing the device
1643 or anything else any more, and making
1644 them Qnil allows for better GC'ing
1645 in case a pointer to the dead frame
1646 continues to hang around. */
1647 f->framemeths = dead_console_methods;
1652 io_error_delete_frame (Lisp_Object frame)
1654 delete_frame_internal (XFRAME (frame), 1, 0, 1);
1657 DEFUN ("delete-frame", Fdelete_frame, 0, 2, "", /*
1658 Delete FRAME, permanently eliminating it from use.
1659 If omitted, FRAME defaults to the selected frame.
1660 A frame may not be deleted if its minibuffer is used by other frames.
1661 Normally, you cannot delete the last non-minibuffer-only frame (you must
1662 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
1663 second argument FORCE is non-nil, you can delete the last frame. (This
1664 will automatically call `save-buffers-kill-emacs'.)
1668 /* This function can GC */
1673 f = selected_frame ();
1674 XSETFRAME (frame, f);
1678 CHECK_FRAME (frame);
1682 delete_frame_internal (f, !NILP (force), 0, 0);
1687 /* Return mouse position in character cell units. */
1690 mouse_pixel_position_1 (struct device *d, Lisp_Object *frame,
1693 switch (DEVMETH_OR_GIVEN (d, get_mouse_position, (d, frame, x, y), -1))
1703 *frame = DEVICE_SELECTED_FRAME (d);
1707 abort (); /* method is incorrectly written */
1713 DEFUN ("mouse-pixel-position", Fmouse_pixel_position, 0, 1, 0, /*
1714 Return a list (WINDOW X . Y) giving the current mouse window and position.
1715 The position is given in pixel units, where (0, 0) is the upper-left corner
1718 When the cursor is not over a window, the return value is a list (nil nil).
1720 DEVICE specifies the device on which to read the mouse position, and
1721 defaults to the selected device. If the device is a mouseless terminal
1722 or XEmacs hasn't been programmed to read its mouse position, it returns
1723 the device's selected window for WINDOW and nil for X and Y.
1727 struct device *d = decode_device (device);
1729 Lisp_Object window = Qnil;
1730 Lisp_Object x = Qnil;
1731 Lisp_Object y = Qnil;
1734 if (mouse_pixel_position_1 (d, &frame, &intx, &inty) > 0)
1737 find_window_by_pixel_pos (intx, inty, XFRAME (frame)->root_window);
1740 XSETWINDOW (window, w);
1742 /* Adjust the position to be relative to the window. */
1743 intx -= w->pixel_left;
1744 inty -= w->pixel_top;
1749 else if (FRAMEP (frame))
1750 window = FRAME_SELECTED_WINDOW (XFRAME (frame));
1752 return Fcons (window, Fcons (x, y));
1755 DEFUN ("mouse-position", Fmouse_position, 0, 1, 0, /*
1756 Return a list (WINDOW X . Y) giving the current mouse window and position.
1757 The position is of a character under cursor, where (0, 0) is the upper-left
1758 corner of the window.
1760 When the cursor is not over a character, or not over a window, the return
1761 value is a list (nil nil).
1763 DEVICE specifies the device on which to read the mouse position, and
1764 defaults to the selected device. If the device is a mouseless terminal
1765 or Emacs hasn't been programmed to read its mouse position, it returns
1766 the device's selected window for WINDOW and nil for X and Y.
1770 struct device *d = decode_device (device);
1772 Lisp_Object frame, window = Qnil, lisp_x = Qnil, lisp_y = Qnil;
1773 int x, y, obj_x, obj_y;
1774 Bufpos bufpos, closest;
1775 Charcount modeline_closest;
1776 Lisp_Object obj1, obj2;
1778 if (mouse_pixel_position_1 (d, &frame, &x, &y) > 0)
1780 int res = pixel_to_glyph_translation (XFRAME (frame), x, y, &x, &y,
1781 &obj_x, &obj_y, &w, &bufpos,
1782 &closest, &modeline_closest,
1784 if (res == OVER_TEXT)
1786 lisp_x = make_int (x);
1787 lisp_y = make_int (y);
1788 XSETWINDOW (window, w);
1791 else if (FRAMEP (frame))
1792 window = FRAME_SELECTED_WINDOW (XFRAME (frame));
1794 return Fcons (window, Fcons (lisp_x, lisp_y));
1797 DEFUN ("mouse-position-as-motion-event", Fmouse_position_as_motion_event, 0, 1, 0, /*
1798 Return the current mouse position as a motion event.
1799 This allows you to call the standard event functions such as
1800 `event-over-toolbar-p' to determine where the mouse is.
1802 DEVICE specifies the device on which to read the mouse position, and
1803 defaults to the selected device. If the mouse position can't be determined
1804 \(e.g. DEVICE is a TTY device), nil is returned instead of an event.
1808 struct device *d = decode_device (device);
1812 if (mouse_pixel_position_1 (d, &frame, &intx, &inty))
1814 Lisp_Object event = Fmake_event (Qnil, Qnil);
1815 XEVENT (event)->event_type = pointer_motion_event;
1816 XEVENT (event)->channel = frame;
1817 XEVENT (event)->event.motion.x = intx;
1818 XEVENT (event)->event.motion.y = inty;
1825 DEFUN ("set-mouse-position", Fset_mouse_position, 3, 3, 0, /*
1826 Move the mouse pointer to the center of character cell (X,Y) in WINDOW.
1827 Note, this is a no-op for an X frame that is not visible.
1828 If you have just created a frame, you must wait for it to become visible
1829 before calling this function on it, like this.
1830 (while (not (frame-visible-p frame)) (sleep-for .5))
1831 Note also: Warping the mouse is contrary to the ICCCM, so be very sure
1832 that the behavior won't end up being obnoxious!
1839 CHECK_LIVE_WINDOW (window);
1843 /* Warping the mouse will cause EnterNotify and Focus events under X. */
1844 w = XWINDOW (window);
1845 glyph_to_pixel_translation (w, XINT (x), XINT (y), &pix_x, &pix_y);
1847 MAYBE_FRAMEMETH (XFRAME (w->frame), set_mouse_position, (w, pix_x, pix_y));
1852 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position, 3, 3, 0, /*
1853 Move the mouse pointer to pixel position (X,Y) in WINDOW.
1854 Note, this is a no-op for an X frame that is not visible.
1855 If you have just created a frame, you must wait for it to become visible
1856 before calling this function on it, like this.
1857 (while (not (frame-visible-p frame)) (sleep-for .5))
1863 CHECK_LIVE_WINDOW (window);
1867 /* Warping the mouse will cause EnterNotify and Focus events under X. */
1868 w = XWINDOW (window);
1869 FRAMEMETH (XFRAME (w->frame), set_mouse_position, (w, XINT (x), XINT (y)));
1874 DEFUN ("make-frame-visible", Fmake_frame_visible, 0, 1, 0, /*
1875 Make the frame FRAME visible (assuming it is an X-window).
1876 If omitted, FRAME defaults to the currently selected frame.
1877 Also raises the frame so that nothing obscures it.
1881 struct frame *f = decode_frame (frame);
1883 MAYBE_FRAMEMETH (f, make_frame_visible, (f));
1887 DEFUN ("make-frame-invisible", Fmake_frame_invisible, 0, 2, 0, /*
1888 Unconditionally removes frame from the display (assuming it is an X-window).
1889 If omitted, FRAME defaults to the currently selected frame.
1890 If what you want to do is iconify the frame (if the window manager uses
1891 icons) then you should call `iconify-frame' instead.
1892 Normally you may not make FRAME invisible if all other frames are invisible
1893 and uniconified, but if the second optional argument FORCE is non-nil,
1898 struct frame *f, *sel_frame;
1901 f = decode_frame (frame);
1902 d = XDEVICE (FRAME_DEVICE (f));
1903 sel_frame = XFRAME (DEVICE_SELECTED_FRAME (d));
1905 if (NILP (force) && !other_visible_frames (f))
1906 error ("Attempt to make invisible the sole visible or iconified frame");
1908 /* Don't allow minibuf_window to remain on a deleted frame. */
1909 if (EQ (f->minibuffer_window, minibuf_window))
1911 Fset_window_buffer (sel_frame->minibuffer_window,
1912 XWINDOW (minibuf_window)->buffer, Qt);
1913 minibuf_window = sel_frame->minibuffer_window;
1916 MAYBE_FRAMEMETH (f, make_frame_invisible, (f));
1921 DEFUN ("iconify-frame", Ficonify_frame, 0, 1, "", /*
1922 Make the frame FRAME into an icon, if the window manager supports icons.
1923 If omitted, FRAME defaults to the currently selected frame.
1927 struct frame *f, *sel_frame;
1930 f = decode_frame (frame);
1931 d = XDEVICE (FRAME_DEVICE (f));
1932 sel_frame = XFRAME (DEVICE_SELECTED_FRAME (d));
1934 /* Don't allow minibuf_window to remain on a deleted frame. */
1935 if (EQ (f->minibuffer_window, minibuf_window))
1937 Fset_window_buffer (sel_frame->minibuffer_window,
1938 XWINDOW (minibuf_window)->buffer, Qt);
1939 minibuf_window = sel_frame->minibuffer_window;
1942 MAYBE_FRAMEMETH (f, iconify_frame, (f));
1947 DEFUN ("deiconify-frame", Fdeiconify_frame, 0, 1, 0, /*
1948 Open (de-iconify) the iconified frame FRAME.
1949 Under X, this is currently the same as `make-frame-visible'.
1950 If omitted, FRAME defaults to the currently selected frame.
1951 Also raises the frame so that nothing obscures it.
1955 return Fmake_frame_visible (frame);
1958 /* FSF returns 'icon for iconized frames. What a crock! */
1960 DEFUN ("frame-visible-p", Fframe_visible_p, 0, 1, 0, /*
1961 Return non NIL if FRAME is now "visible" (actually in use for display).
1962 A frame that is not visible is not updated, and, if it works through a
1963 window system, may not show at all.
1964 N.B. Under X "visible" means Mapped. It the window is mapped but not
1965 actually visible on screen then frame_visible returns 'hidden.
1969 struct frame *f = decode_frame (frame);
1970 int visible = FRAMEMETH_OR_GIVEN (f, frame_visible_p, (f), f->visible);
1971 return visible ? ( visible > 0 ? Qt : Qhidden ) : Qnil;
1974 DEFUN ("frame-totally-visible-p", Fframe_totally_visible_p, 0, 1, 0, /*
1975 Return t if frame is not obscured by any other window system windows.
1976 Always returns t for tty frames.
1980 struct frame *f = decode_frame (frame);
1981 return (FRAMEMETH_OR_GIVEN (f, frame_totally_visible_p, (f), f->visible)
1985 DEFUN ("frame-iconified-p", Fframe_iconified_p, 0, 1, 0, /*
1986 Return t if FRAME is iconified.
1987 Not all window managers use icons; some merely unmap the window, so this
1988 function is not the inverse of `frame-visible-p'. It is possible for a
1989 frame to not be visible and not be iconified either. However, if the
1990 frame is iconified, it will not be visible.
1994 struct frame *f = decode_frame (frame);
1997 f->iconified = FRAMEMETH_OR_GIVEN (f, frame_iconified_p, (f), 0);
1998 return f->iconified ? Qt : Qnil;
2001 DEFUN ("visible-frame-list", Fvisible_frame_list, 0, 1, 0, /*
2002 Return a list of all frames now "visible" (being updated).
2003 If DEVICE is specified only frames on that device will be returned.
2004 Note that under virtual window managers not all these frame are necessarily
2009 Lisp_Object devcons, concons;
2015 DEVICE_LOOP_NO_BREAK (devcons, concons)
2017 assert (DEVICEP (XCAR (devcons)));
2019 if (NILP (device) || EQ (device, XCAR (devcons)))
2021 Lisp_Object frmcons;
2023 DEVICE_FRAME_LOOP (frmcons, XDEVICE (XCAR (devcons)))
2025 Lisp_Object frame = XCAR (frmcons);
2027 if (FRAME_VISIBLE_P(f))
2028 value = Fcons (frame, value);
2037 DEFUN ("raise-frame", Fraise_frame, 0, 1, "", /*
2038 Bring FRAME to the front, so it occludes any frames it overlaps.
2039 If omitted, FRAME defaults to the currently selected frame.
2040 If FRAME is invisible, make it visible.
2041 If Emacs is displaying on an ordinary terminal or some other device which
2042 doesn't support multiple overlapping frames, this function does nothing.
2046 struct frame *f = decode_frame (frame);
2048 /* Do like the documentation says. */
2049 Fmake_frame_visible (frame);
2050 MAYBE_FRAMEMETH (f, raise_frame, (f));
2054 DEFUN ("lower-frame", Flower_frame, 0, 1, "", /*
2055 Send FRAME to the back, so it is occluded by any frames that overlap it.
2056 If omitted, FRAME defaults to the currently selected frame.
2057 If Emacs is displaying on an ordinary terminal or some other device which
2058 doesn't support multiple overlapping frames, this function does nothing.
2062 struct frame *f = decode_frame (frame);
2064 MAYBE_FRAMEMETH (f, lower_frame, (f));
2069 DEFUN ("disable-frame", Fdisable_frame, 1, 1, 0, /*
2070 Disable frame FRAME, so that it cannot have the focus or receive user input.
2071 This is normally used during modal dialog boxes.
2072 WARNING: Be very careful not to wedge XEmacs!
2073 Use an `unwind-protect' that re-enables the frame to avoid this.
2077 struct frame *f = decode_frame (frame);
2080 MAYBE_FRAMEMETH (f, disable_frame, (f));
2084 DEFUN ("enable-frame", Fenable_frame, 1, 1, 0, /*
2085 Enable frame FRAME, so that it can have the focus and receive user input.
2086 Frames are normally enabled, unless explicitly disabled using `disable-frame'.
2090 struct frame *f = decode_frame (frame);
2092 MAYBE_FRAMEMETH (f, enable_frame, (f));
2096 /* Ben thinks there is no need for `redirect-frame-focus' or `frame-focus',
2097 crockish FSFmacs functions. See summary on focus in event-stream.c. */
2099 DEFUN ("print-job-page-number", Fprint_job_page_number, 1, 1, 0, /*
2100 Return current page number for the print job FRAME.
2104 CHECK_PRINTER_FRAME (frame);
2105 return make_int (FRAME_PAGENUMBER (XFRAME (frame)));
2108 DEFUN ("print-job-eject-page", Fprint_job_eject_page, 1, 1, 0, /*
2109 Eject page in the print job FRAME.
2115 CHECK_PRINTER_FRAME (frame);
2117 FRAMEMETH (f, eject_page, (f));
2118 FRAME_SET_PAGENUMBER (f, 1 + FRAME_PAGENUMBER (f));
2125 /***************************************************************************/
2126 /* frame properties */
2127 /***************************************************************************/
2129 static void internal_set_frame_size (struct frame *f, int cols, int rows,
2133 store_minibuf_frame_prop (struct frame *f, Lisp_Object val)
2136 XSETFRAME (frame, f);
2140 if (! MINI_WINDOW_P (XWINDOW (val)))
2142 ("Surrogate minibuffer windows must be minibuffer windows",
2145 if (FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2147 ("Can't change the surrogate minibuffer of a frame with its own minibuffer", frame);
2149 /* Install the chosen minibuffer window, with proper buffer. */
2150 f->minibuffer_window = val;
2152 else if (EQ (val, Qt))
2154 if (FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2156 ("Frame already has its own minibuffer", frame);
2159 setup_normal_frame (f);
2160 f->mirror_dirty = 1;
2162 update_frame_window_mirror (f);
2163 internal_set_frame_size (f, f->width, f->height, 1);
2170 /* possible code if you want to have symbols such as `default-background'
2171 map to setting the background of `default', etc. */
2174 dissect_as_face_setting (Lisp_Object sym, Lisp_Object *face_out,
2175 Lisp_Object *face_prop_out)
2177 Lisp_Object list = Vbuilt_in_face_specifiers;
2183 s = symbol_name (XSYMBOL (sym));
2185 while (!NILP (list))
2187 Lisp_Object prop = Fcar (list);
2188 Lisp_String *prop_name;
2190 if (!SYMBOLP (prop))
2192 prop_name = symbol_name (XSYMBOL (prop));
2193 if (string_length (s) > string_length (prop_name) + 1
2194 && !memcmp (string_data (prop_name),
2195 string_data (s) + string_length (s)
2196 - string_length (prop_name),
2197 string_length (prop_name))
2198 && string_data (s)[string_length (s) - string_length (prop_name)
2202 Ffind_face (make_string (string_data (s),
2204 - string_length (prop_name)
2209 *face_prop_out = prop;
2223 get_property_alias (Lisp_Object prop)
2227 Lisp_Object alias = Qnil;
2230 alias = Fget (prop, Qframe_property_alias, Qnil);
2240 /* #### Using this to modify the internal border width has no effect
2241 because the change isn't propagated to the windows. Are there
2242 other properties which this claims to handle, but doesn't?
2244 But of course. This stuff needs more work, but it's a lot closer
2245 to sanity now than before with the horrible frame-params stuff. */
2247 DEFUN ("set-frame-properties", Fset_frame_properties, 2, 2, 0, /*
2248 Change some properties of a frame.
2249 PLIST is a property list.
2250 You can also change frame properties individually using `set-frame-property',
2251 but it may be more efficient to change many properties at once.
2253 Frame properties can be retrieved using `frame-property' or `frame-properties'.
2255 The following symbols etc. have predefined meanings:
2257 name Name of the frame. Used with X resources.
2258 Unchangeable after creation.
2260 height Height of the frame, in lines.
2262 width Width of the frame, in characters.
2264 minibuffer Gives the minibuffer behavior for this frame. Either
2265 t (frame has its own minibuffer), `only' (frame is
2266 a minibuffer-only frame), `none' (frame has no minibuffer)
2267 or a window (frame uses that window, which is on another
2268 frame, as the minibuffer).
2270 unsplittable If non-nil, frame cannot be split by `display-buffer'.
2272 current-display-table, menubar-visible-p, left-margin-width,
2273 right-margin-width, minimum-line-ascent, minimum-line-descent,
2274 use-left-overflow, use-right-overflow, scrollbar-width, scrollbar-height,
2275 default-toolbar, top-toolbar, bottom-toolbar, left-toolbar, right-toolbar,
2276 default-toolbar-height, default-toolbar-width, top-toolbar-height,
2277 bottom-toolbar-height, left-toolbar-width, right-toolbar-width,
2278 default-toolbar-visible-p, top-toolbar-visible-p, bottom-toolbar-visible-p,
2279 left-toolbar-visible-p, right-toolbar-visible-p, toolbar-buttons-captioned-p,
2280 top-toolbar-border-width, bottom-toolbar-border-width,
2281 left-toolbar-border-width, right-toolbar-border-width,
2282 modeline-shadow-thickness, has-modeline-p,
2283 default-gutter, top-gutter, bottom-gutter, left-gutter, right-gutter,
2284 default-gutter-height, default-gutter-width, top-gutter-height,
2285 bottom-gutter-height, left-gutter-width, right-gutter-width,
2286 default-gutter-visible-p, top-gutter-visible-p, bottom-gutter-visible-p,
2287 left-gutter-visible-p, right-gutter-visible-p, top-gutter-border-width,
2288 bottom-gutter-border-width, left-gutter-border-width, right-gutter-border-width,
2289 [Giving the name of any built-in specifier variable is
2290 equivalent to calling `set-specifier' on the specifier,
2291 with a locale of FRAME. Giving the name to `frame-property'
2292 calls `specifier-instance' on the specifier.]
2294 text-pointer-glyph, nontext-pointer-glyph, modeline-pointer-glyph,
2295 selection-pointer-glyph, busy-pointer-glyph, toolbar-pointer-glyph,
2296 menubar-pointer-glyph, scrollbar-pointer-glyph, gc-pointer-glyph,
2297 octal-escape-glyph, control-arrow-glyph, invisible-text-glyph,
2298 hscroll-glyph, truncation-glyph, continuation-glyph
2299 [Giving the name of any glyph variable is equivalent to
2300 calling `set-glyph-image' on the glyph, with a locale
2301 of FRAME. Giving the name to `frame-property' calls
2302 `glyph-image-instance' on the glyph.]
2304 [default foreground], [default background], [default font],
2305 [modeline foreground], [modeline background], [modeline font],
2307 [Giving a vector of a face and a property is equivalent
2308 to calling `set-face-property' on the face and property,
2309 with a locale of FRAME. Giving the vector to
2310 `frame-property' calls `face-property-instance' on the
2313 Finally, if a frame property symbol has the property `frame-property-alias'
2314 on it, then the value will be used in place of that symbol when looking
2315 up and setting frame property values. This allows you to alias one
2316 frame property name to another.
2318 See the variables `default-x-frame-plist', `default-tty-frame-plist'
2319 and `default-mswindows-frame-plist' for a description of the properties
2320 recognized for particular types of frames.
2324 struct frame *f = decode_frame (frame);
2327 struct gcpro gcpro1, gcpro2;
2329 XSETFRAME (frame, f);
2330 GCPRO2 (frame, plist);
2331 Fcheck_valid_plist (plist);
2332 plist = Fcopy_sequence (plist);
2333 Fcanonicalize_lax_plist (plist, Qnil);
2334 for (tail = plist; !NILP (tail); tail = Fcdr (Fcdr (tail)))
2336 Lisp_Object prop = Fcar (tail);
2337 Lisp_Object val = Fcar (Fcdr (tail));
2339 prop = get_property_alias (prop);
2342 /* mly wants this, but it's not reasonable to change the name of a
2343 frame after it has been created, because the old name was used
2344 for resource lookup. */
2345 if (EQ (prop, Qname))
2351 if (EQ (prop, Qminibuffer))
2352 store_minibuf_frame_prop (f, val);
2353 if (EQ (prop, Qunsplittable))
2354 f->no_split = !NILP (val);
2355 if (EQ (prop, Qbuffer_predicate))
2356 f->buffer_predicate = val;
2357 if (SYMBOLP (prop) && EQ (Fbuilt_in_variable_type (prop),
2359 call3 (Qset_specifier, Fsymbol_value (prop), val, frame);
2360 if (SYMBOLP (prop) && !NILP (Fget (prop, Qconst_glyph_variable, Qnil)))
2361 call3 (Qset_glyph_image, Fsymbol_value (prop), val, frame);
2362 if (VECTORP (prop) && XVECTOR_LENGTH (prop) == 2)
2364 Lisp_Object face_prop = XVECTOR_DATA (prop)[1];
2365 CHECK_SYMBOL (face_prop);
2366 call4 (Qset_face_property,
2367 Fget_face (XVECTOR_DATA (prop)[0]),
2368 face_prop, val, frame);
2372 MAYBE_FRAMEMETH (f, set_frame_properties, (f, plist));
2373 for (tailp = &plist; !NILP (*tailp);)
2375 Lisp_Object *next_tailp;
2379 next = Fcdr (*tailp);
2381 next_tailp = &XCDR (next);
2382 prop = Fcar (*tailp);
2384 prop = get_property_alias (prop);
2386 if (EQ (prop, Qminibuffer)
2387 || EQ (prop, Qunsplittable)
2388 || EQ (prop, Qbuffer_predicate)
2389 || EQ (prop, Qheight)
2390 || EQ (prop, Qwidth)
2391 || (SYMBOLP (prop) && EQ (Fbuilt_in_variable_type (prop),
2393 || (SYMBOLP (prop) && !NILP (Fget (prop, Qconst_glyph_variable,
2395 || (VECTORP (prop) && XVECTOR_LENGTH (prop) == 2)
2396 || FRAMEMETH_OR_GIVEN (f, internal_frame_property_p, (f, prop), 0))
2397 *tailp = *next_tailp;
2401 f->plist = nconc2 (plist, f->plist);
2402 Fcanonicalize_lax_plist (f->plist, Qnil);
2407 DEFUN ("frame-property", Fframe_property, 2, 3, 0, /*
2408 Return FRAME's value for property PROPERTY.
2409 Return DEFAULT if there is no such property.
2410 See `set-frame-properties' for the built-in property names.
2412 (frame, property, default_))
2414 struct frame *f = decode_frame (frame);
2417 XSETFRAME (frame, f);
2419 property = get_property_alias (property);
2421 if (EQ (Qname, property)) return f->name;
2423 if (EQ (Qheight, property) || EQ (Qwidth, property))
2425 if (window_system_pixelated_geometry (frame))
2428 pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
2430 return make_int (EQ (Qheight, property) ? height: width);
2433 return make_int (EQ (Qheight, property) ?
2438 /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P.
2439 This is over-the-top bogosity, because it's inconsistent with
2440 the semantics of `minibuffer' when passed to `make-frame'.
2441 Returning Qt makes things consistent. */
2442 if (EQ (Qminibuffer, property))
2443 return (FRAME_MINIBUF_ONLY_P (f) ? Qonly :
2444 FRAME_HAS_MINIBUF_P (f) ? Qt :
2445 FRAME_MINIBUF_WINDOW (f));
2446 if (EQ (Qunsplittable, property))
2447 return FRAME_NO_SPLIT_P (f) ? Qt : Qnil;
2448 if (EQ (Qbuffer_predicate, property))
2449 return f->buffer_predicate;
2451 if (SYMBOLP (property))
2453 if (EQ (Fbuilt_in_variable_type (property), Qconst_specifier))
2454 return Fspecifier_instance (Fsymbol_value (property),
2455 frame, default_, Qnil);
2456 if (!NILP (Fget (property, Qconst_glyph_variable, Qnil)))
2458 Lisp_Object glyph = Fsymbol_value (property);
2459 CHECK_GLYPH (glyph);
2460 return Fspecifier_instance (XGLYPH_IMAGE (glyph),
2461 frame, default_, Qnil);
2465 if (VECTORP (property) && XVECTOR_LENGTH (property) == 2)
2467 Lisp_Object face_prop = XVECTOR_DATA (property)[1];
2468 CHECK_SYMBOL (face_prop);
2469 return call3 (Qface_property_instance,
2470 Fget_face (XVECTOR_DATA (property)[0]),
2474 if (HAS_FRAMEMETH_P (f, frame_property))
2475 if (!UNBOUNDP (value = FRAMEMETH (f, frame_property, (f, property))))
2478 if (!UNBOUNDP (value = external_plist_get (&f->plist, property, 1, ERROR_ME)))
2484 DEFUN ("frame-properties", Fframe_properties, 0, 1, 0, /*
2485 Return a property list of the properties of FRAME.
2486 Do not modify this list; use `set-frame-property' instead.
2490 struct frame *f = decode_frame (frame);
2491 Lisp_Object result = Qnil;
2492 struct gcpro gcpro1;
2496 XSETFRAME (frame, f);
2498 /* #### for the moment (since old code uses `frame-parameters'),
2499 we call `copy-sequence' on f->plist. That allows frame-parameters
2500 to destructively convert the plist into an alist, which is more
2501 efficient than doing it non-destructively. At some point we
2502 should remove the call to copy-sequence. */
2503 result = Fcopy_sequence (f->plist);
2505 /* #### should we be adding all the specifiers and glyphs?
2506 That would entail having a list of them all. */
2507 if (HAS_FRAMEMETH_P (f, frame_properties))
2508 result = nconc2 (FRAMEMETH (f, frame_properties, (f)), result);
2510 if (!NILP (f->buffer_predicate))
2511 result = cons3 (Qbuffer_predicate, f->buffer_predicate, result);
2513 if (FRAME_NO_SPLIT_P (f))
2514 result = cons3 (Qunsplittable, Qt, result);
2516 /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P.
2517 This is over-the-top bogosity, because it's inconsistent with
2518 the semantics of `minibuffer' when passed to `make-frame'.
2519 Returning Qt makes things consistent. */
2520 result = cons3 (Qminibuffer,
2521 (FRAME_MINIBUF_ONLY_P (f) ? Qonly :
2522 FRAME_HAS_MINIBUF_P (f) ? Qt :
2523 FRAME_MINIBUF_WINDOW (f)),
2528 if (window_system_pixelated_geometry (frame))
2530 pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
2535 height = FRAME_HEIGHT (f);
2536 width = FRAME_WIDTH (f);
2538 result = cons3 (Qwidth , make_int (width), result);
2539 result = cons3 (Qheight, make_int (height), result);
2542 result = cons3 (Qname, f->name, result);
2549 DEFUN ("frame-pixel-height", Fframe_pixel_height, 0, 1, 0, /*
2550 Return the height in pixels of FRAME.
2554 return make_int (decode_frame (frame)->pixheight);
2557 DEFUN ("frame-pixel-width", Fframe_pixel_width, 0, 1, 0, /*
2558 Return the width in pixels of FRAME.
2562 return make_int (decode_frame (frame)->pixwidth);
2565 DEFUN ("frame-name", Fframe_name, 0, 1, 0, /*
2566 Return the name of FRAME (defaulting to the selected frame).
2567 This is not the same as the `title' of the frame.
2571 return decode_frame (frame)->name;
2574 DEFUN ("frame-modified-tick", Fframe_modified_tick, 0, 1, 0, /*
2575 Return FRAME's tick counter, incremented for each change to the frame.
2576 Each frame has a tick counter which is incremented each time the frame
2577 is resized, a window is resized, added, or deleted, a face is changed,
2578 `set-window-buffer' or `select-window' is called on a window in the
2579 frame, the window-start of a window in the frame has changed, or
2580 anything else interesting has happened. It wraps around occasionally.
2581 No argument or nil as argument means use selected frame as FRAME.
2585 return make_int (decode_frame (frame)->modiff);
2589 internal_set_frame_size (struct frame *f, int cols, int rows, int pretend)
2591 /* An explicit size change cancels any pending frame size adjustment */
2592 CLEAR_FRAME_SIZE_SLIPPED(f);
2594 if (pretend || !HAS_FRAMEMETH_P (f, set_frame_size))
2595 change_frame_size (f, rows, cols, 0);
2597 FRAMEMETH (f, set_frame_size, (f, cols, rows));
2600 DEFUN ("set-frame-height", Fset_frame_height, 2, 3, 0, /*
2601 Specify that the frame FRAME has LINES lines.
2602 Optional third arg non-nil means that redisplay should use LINES lines
2603 but that the idea of the actual height of the frame should not be changed.
2605 (frame, lines, pretend))
2607 struct frame *f = decode_frame (frame);
2609 XSETFRAME (frame, f);
2612 if (window_system_pixelated_geometry (frame))
2614 char_to_real_pixel_size (f, 0, XINT (lines), 0, &height);
2615 width = FRAME_PIXWIDTH (f);
2619 height = XINT (lines);
2620 width = FRAME_WIDTH (f);
2623 internal_set_frame_size (f, width, height, !NILP (pretend));
2627 DEFUN ("set-frame-width", Fset_frame_width, 2, 3, 0, /*
2628 Specify that the frame FRAME has COLS columns.
2629 Optional third arg non-nil means that redisplay should use COLS columns
2630 but that the idea of the actual width of the frame should not be changed.
2632 (frame, cols, pretend))
2634 struct frame *f = decode_frame (frame);
2636 XSETFRAME (frame, f);
2639 if (window_system_pixelated_geometry (frame))
2641 char_to_real_pixel_size (f, XINT (cols), 0, &width, 0);
2642 height = FRAME_PIXHEIGHT (f);
2646 width = XINT (cols);
2647 height = FRAME_HEIGHT (f);
2650 internal_set_frame_size (f, width, height, !NILP (pretend));
2654 DEFUN ("set-frame-size", Fset_frame_size, 3, 4, 0, /*
2655 Set the size of FRAME to COLS by ROWS, measured in characters.
2656 Optional fourth arg non-nil means that redisplay should use COLS by ROWS
2657 but that the idea of the actual size of the frame should not be changed.
2659 (frame, cols, rows, pretend))
2661 struct frame *f = decode_frame (frame);
2663 XSETFRAME (frame, f);
2667 if (window_system_pixelated_geometry (frame))
2668 char_to_real_pixel_size (f, XINT (cols), XINT (rows), &width, &height);
2671 height = XINT (rows);
2672 width = XINT (cols);
2675 internal_set_frame_size (f, width, height, !NILP (pretend));
2679 DEFUN ("set-frame-position", Fset_frame_position, 3, 3, 0, /*
2680 Set position of FRAME in pixels to XOFFSET by YOFFSET.
2681 This is actually the position of the upper left corner of the frame.
2682 Negative values for XOFFSET or YOFFSET are interpreted relative to
2683 the rightmost or bottommost possible position (that stays within the screen).
2685 (frame, xoffset, yoffset))
2687 struct frame *f = decode_frame (frame);
2688 CHECK_INT (xoffset);
2689 CHECK_INT (yoffset);
2691 MAYBE_FRAMEMETH (f, set_frame_position, (f, XINT (xoffset), XINT (yoffset)));
2698 /* Frame size conversion functions moved here from EmacsFrame.c
2699 because they're generic and really don't belong in that file.
2700 Function get_default_char_pixel_size() removed because it's
2701 exactly the same as default_face_height_and_width(). */
2703 frame_conversion_internal (struct frame *f, int pixel_to_char,
2704 int *pixel_width, int *pixel_height,
2705 int *char_width, int *char_height,
2712 Lisp_Object frame, window;
2714 XSETFRAME (frame, f);
2716 default_face_height_and_width (frame, &cph, &cpw);
2718 default_face_height_and_width_1 (frame, &cph, &cpw);
2720 window = FRAME_SELECTED_WINDOW (f);
2722 egw = max (glyph_width (Vcontinuation_glyph, window),
2723 glyph_width (Vtruncation_glyph, window));
2724 egw = max (egw, cpw);
2725 bdr = 2 * f->internal_border_width;
2726 obw = FRAME_SCROLLBAR_WIDTH (f) + FRAME_THEORETICAL_LEFT_TOOLBAR_WIDTH (f) +
2727 FRAME_THEORETICAL_RIGHT_TOOLBAR_WIDTH (f) +
2728 2 * FRAME_THEORETICAL_LEFT_TOOLBAR_BORDER_WIDTH (f) +
2729 2 * FRAME_THEORETICAL_RIGHT_TOOLBAR_BORDER_WIDTH (f);
2730 obh = FRAME_SCROLLBAR_HEIGHT (f) + FRAME_THEORETICAL_TOP_TOOLBAR_HEIGHT (f) +
2731 FRAME_THEORETICAL_BOTTOM_TOOLBAR_HEIGHT (f) +
2732 2 * FRAME_THEORETICAL_TOP_TOOLBAR_BORDER_WIDTH (f) +
2733 2 * FRAME_THEORETICAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f);
2738 *char_width = 1 + ((*pixel_width - egw) - bdr - obw) / cpw;
2740 *char_height = (*pixel_height - bdr - obh) / cph;
2745 *pixel_width = (*char_width - 1) * cpw + egw + bdr + obw;
2747 *pixel_height = *char_height * cph + bdr + obh;
2751 /* This takes the size in pixels of the text area, and returns the number
2752 of characters that will fit there, taking into account the internal
2753 border width, and the pixel width of the line terminator glyphs (which
2754 always count as one "character" wide, even if they are not the same size
2755 as the default character size of the default font). The frame scrollbar
2756 width and left and right toolbar widths are also subtracted out of the
2757 available width. The frame scrollbar height and top and bottom toolbar
2758 heights are subtracted out of the available height.
2760 Therefore the result is not necessarily a multiple of anything in
2763 pixel_to_char_size (struct frame *f, int pixel_width, int pixel_height,
2764 int *char_width, int *char_height)
2766 frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width,
2770 /* Given a character size, this returns the minimum number of pixels
2771 necessary to display that many characters, taking into account the
2772 internal border width, scrollbar height and width, toolbar heights and
2773 widths and the size of the line terminator glyphs (assuming the line
2774 terminators take up exactly one character position).
2776 Therefore the result is not necessarily a multiple of anything in
2779 char_to_pixel_size (struct frame *f, int char_width, int char_height,
2780 int *pixel_width, int *pixel_height)
2782 frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width,
2786 /* Given a pixel size, rounds DOWN to the smallest size in pixels necessary
2787 to display the same number of characters as are displayable now.
2790 round_size_to_char (struct frame *f, int in_width, int in_height,
2791 int *out_width, int *out_height)
2795 pixel_to_char_size (f, in_width, in_height, &char_width, &char_height);
2796 char_to_pixel_size (f, char_width, char_height, out_width, out_height);
2799 /* Versions of the above which always account for real font metrics.
2802 pixel_to_real_char_size (struct frame *f, int pixel_width, int pixel_height,
2803 int *char_width, int *char_height)
2805 frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width,
2810 char_to_real_pixel_size (struct frame *f, int char_width, int char_height,
2811 int *pixel_width, int *pixel_height)
2813 frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width,
2818 round_size_to_real_char (struct frame *f, int in_width, int in_height,
2819 int *out_width, int *out_height)
2823 pixel_to_real_char_size (f, in_width, in_height, &char_width, &char_height);
2824 char_to_real_pixel_size (f, char_width, char_height, out_width, out_height);
2827 /* Change the frame height and/or width. Values may be given as zero to
2828 indicate no change is to take place. */
2830 change_frame_size_1 (struct frame *f, int newheight, int newwidth)
2833 int new_pixheight, new_pixwidth;
2834 int font_height, real_font_height, font_width;
2836 /* #### Chuck -- shouldn't we be checking to see if the frame
2837 is being "changed" to its existing size, and do nothing if so? */
2838 /* No, because it would hose toolbar updates. The toolbar
2839 update code relies on this function to cause window `top' and
2840 `left' coordinates to be recomputed even though no frame size
2841 change occurs. --kyle */
2845 XSETFRAME (frame, f);
2847 default_face_height_and_width (frame, &real_font_height, 0);
2848 default_face_height_and_width_1 (frame, &font_height, &font_width);
2850 /* This size-change overrides any pending one for this frame. */
2851 FRAME_NEW_HEIGHT (f) = 0;
2852 FRAME_NEW_WIDTH (f) = 0;
2854 new_pixheight = newheight * font_height;
2855 new_pixwidth = (newwidth - 1) * font_width;
2857 /* #### dependency on FRAME_WIN_P should be removed. */
2858 if (FRAME_WIN_P (f))
2860 new_pixheight += FRAME_SCROLLBAR_HEIGHT (f);
2861 new_pixwidth += FRAME_SCROLLBAR_WIDTH (f);
2864 /* when frame_conversion_internal() calculated the number of rows/cols
2865 in the frame, the theoretical toolbar sizes were subtracted out.
2866 The calculations below adjust for real toolbar height/width in
2867 frame, which may be different from frame spec, taking the above
2868 fact into account */
2870 + FRAME_THEORETICAL_TOP_TOOLBAR_HEIGHT (f)
2871 + 2 * FRAME_THEORETICAL_TOP_TOOLBAR_BORDER_WIDTH (f)
2872 - FRAME_REAL_TOP_TOOLBAR_HEIGHT (f)
2873 - 2 * FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f);
2876 + FRAME_THEORETICAL_BOTTOM_TOOLBAR_HEIGHT (f)
2877 + 2 * FRAME_THEORETICAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f)
2878 - FRAME_REAL_BOTTOM_TOOLBAR_HEIGHT (f)
2879 - 2 * FRAME_REAL_BOTTOM_TOOLBAR_BORDER_WIDTH (f);
2882 + FRAME_THEORETICAL_LEFT_TOOLBAR_WIDTH (f)
2883 + 2 * FRAME_THEORETICAL_LEFT_TOOLBAR_BORDER_WIDTH (f)
2884 - FRAME_REAL_LEFT_TOOLBAR_WIDTH (f)
2885 - 2 * FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f);
2888 + FRAME_THEORETICAL_RIGHT_TOOLBAR_WIDTH (f)
2889 + 2 * FRAME_THEORETICAL_RIGHT_TOOLBAR_BORDER_WIDTH (f)
2890 - FRAME_REAL_RIGHT_TOOLBAR_WIDTH (f)
2891 - 2 * FRAME_REAL_RIGHT_TOOLBAR_BORDER_WIDTH (f);
2893 /* Adjust the width for the end glyph which may be a different width
2894 than the default character width. */
2896 int adjustment, trunc_width, cont_width;
2898 trunc_width = glyph_width (Vtruncation_glyph,
2899 FRAME_SELECTED_WINDOW (f));
2900 cont_width = glyph_width (Vcontinuation_glyph,
2901 FRAME_SELECTED_WINDOW (f));
2902 adjustment = max (trunc_width, cont_width);
2903 adjustment = max (adjustment, font_width);
2905 new_pixwidth += adjustment;
2908 /* If we don't have valid values, exit. */
2909 if (!new_pixheight && !new_pixwidth)
2914 /* Adjust for gutters here so that we always get set
2917 (FRAME_TOP_GUTTER_BOUNDS (f)
2918 + FRAME_BOTTOM_GUTTER_BOUNDS (f));
2920 XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top
2921 = FRAME_TOP_BORDER_END (f) + FRAME_TOP_GUTTER_BOUNDS (f);
2923 if (FRAME_HAS_MINIBUF_P (f)
2924 && ! FRAME_MINIBUF_ONLY_P (f))
2925 /* Frame has both root and minibuffer. */
2928 * Leave the minibuffer height the same if the frame has
2929 * been initialized, and the minibuffer height is tall
2930 * enough to display at least one line of text in the default
2931 * font, and the old minibuffer height is a multiple of the
2932 * default font height. This should cause the minibuffer
2933 * height to be recomputed on font changes but not for
2934 * other frame size changes, which seems reasonable.
2936 int old_minibuf_height =
2937 XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
2938 int minibuf_height =
2939 f->init_finished && (old_minibuf_height % real_font_height) == 0 ?
2940 max(old_minibuf_height, real_font_height) :
2942 set_window_pixheight (FRAME_ROOT_WINDOW (f),
2943 /* - font_height for minibuffer */
2944 new_pixheight - minibuf_height, 0);
2946 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top =
2947 FRAME_TOP_BORDER_END (f) +
2948 FRAME_TOP_GUTTER_BOUNDS (f) +
2949 FRAME_BOTTOM_GUTTER_BOUNDS (f) +
2950 new_pixheight - minibuf_height;
2952 set_window_pixheight (FRAME_MINIBUF_WINDOW (f), minibuf_height, 0);
2955 /* Frame has just one top-level window. */
2956 set_window_pixheight (FRAME_ROOT_WINDOW (f), new_pixheight, 0);
2958 FRAME_HEIGHT (f) = newheight;
2959 if (FRAME_TTY_P (f))
2960 f->pixheight = newheight;
2965 /* Adjust for gutters here so that we always get set
2968 (FRAME_LEFT_GUTTER_BOUNDS (f)
2969 + FRAME_RIGHT_GUTTER_BOUNDS (f));
2971 XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left =
2972 FRAME_LEFT_BORDER_END (f) + FRAME_LEFT_GUTTER_BOUNDS (f);
2973 set_window_pixwidth (FRAME_ROOT_WINDOW (f), new_pixwidth, 0);
2975 if (FRAME_HAS_MINIBUF_P (f))
2977 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_left =
2978 FRAME_LEFT_BORDER_END (f) + FRAME_LEFT_GUTTER_BOUNDS (f);
2979 set_window_pixwidth (FRAME_MINIBUF_WINDOW (f), new_pixwidth, 0);
2982 FRAME_WIDTH (f) = newwidth;
2983 if (FRAME_TTY_P (f))
2984 f->pixwidth = newwidth;
2987 if (window_system_pixelated_geometry (frame))
2988 pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
2989 &FRAME_CHARWIDTH (f), &FRAME_CHARHEIGHT (f));
2992 FRAME_CHARWIDTH (f) = FRAME_WIDTH (f);
2993 FRAME_CHARHEIGHT (f) = FRAME_HEIGHT (f);
2996 MARK_FRAME_TOOLBARS_CHANGED (f);
2997 MARK_FRAME_GUTTERS_CHANGED (f);
2998 MARK_FRAME_CHANGED (f);
2999 f->echo_area_garbaged = 1;
3003 change_frame_size (struct frame *f, int newheight, int newwidth, int delay)
3005 /* sometimes we get passed a size that's too small (esp. when a
3006 client widget gets resized, since we have no control over this).
3008 check_frame_size (f, &newheight, &newwidth);
3010 if (delay || in_display || gc_in_progress)
3012 MARK_FRAME_SIZE_CHANGED (f);
3013 f->new_width = newwidth;
3014 f->new_height = newheight;
3018 f->size_change_pending = 0;
3019 /* For TTY frames, it's like one, like all ...
3020 Can't have two TTY frames of different sizes on the same device. */
3021 if (FRAME_TTY_P (f))
3023 Lisp_Object frmcons;
3025 DEVICE_FRAME_LOOP (frmcons, XDEVICE (FRAME_DEVICE (f)))
3026 change_frame_size_1 (XFRAME (XCAR (frmcons)), newheight, newwidth);
3029 change_frame_size_1 (f, newheight, newwidth);
3033 /* The caller is responsible for freeing the returned string. */
3035 generate_title_string (struct window *w, Lisp_Object format_str,
3036 face_index findex, int type)
3038 struct display_line *dl;
3039 struct display_block *db;
3042 dl = &title_string_display_line;
3043 db = get_display_block_from_line (dl, TEXT);
3044 Dynarr_reset (db->runes);
3046 generate_formatted_string_db (format_str, Qnil, w, dl, db, findex, 0,
3049 Dynarr_reset (title_string_charc_dynarr);
3050 while (elt < Dynarr_length (db->runes))
3052 if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR)
3053 Dynarr_add (title_string_charc_dynarr,
3054 Dynarr_atp (db->runes, elt)->object.cglyph);
3059 convert_charc_string_into_malloced_string
3060 (Dynarr_atp (title_string_charc_dynarr, 0),
3061 Dynarr_length (title_string_charc_dynarr), 0);
3065 update_frame_title (struct frame *f)
3067 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
3068 Lisp_Object title_format;
3069 Lisp_Object icon_format;
3072 /* We don't change the title for the minibuffer unless the frame
3073 only has a minibuffer. */
3074 if (MINI_WINDOW_P (w) && !FRAME_MINIBUF_ONLY_P (f))
3077 /* And we don't want dead buffers to blow up on us. */
3078 if (!BUFFER_LIVE_P (XBUFFER (w->buffer)))
3082 title_format = symbol_value_in_buffer (Qframe_title_format, w->buffer);
3083 icon_format = symbol_value_in_buffer (Qframe_icon_title_format, w->buffer);
3085 if (HAS_FRAMEMETH_P (f, set_title_from_bufbyte))
3087 title = generate_title_string (w, title_format,
3088 DEFAULT_INDEX, CURRENT_DISP);
3089 FRAMEMETH (f, set_title_from_bufbyte, (f, title));
3092 if (HAS_FRAMEMETH_P (f, set_icon_name_from_bufbyte))
3094 if (!EQ (icon_format, title_format) || !title)
3099 title = generate_title_string (w, icon_format,
3100 DEFAULT_INDEX, CURRENT_DISP);
3102 FRAMEMETH (f, set_icon_name_from_bufbyte, (f, title));
3110 DEFUN ("set-frame-pointer", Fset_frame_pointer, 2, 2, 0, /*
3111 Set the mouse pointer of FRAME to the given pointer image instance.
3112 You should not call this function directly. Instead, set one of
3113 the variables `text-pointer-glyph', `nontext-pointer-glyph',
3114 `modeline-pointer-glyph', `selection-pointer-glyph',
3115 `busy-pointer-glyph', or `toolbar-pointer-glyph'.
3117 (frame, image_instance))
3119 struct frame *f = decode_frame (frame);
3120 CHECK_POINTER_IMAGE_INSTANCE (image_instance);
3121 if (!EQ (f->pointer, image_instance))
3123 f->pointer = image_instance;
3124 MAYBE_FRAMEMETH (f, set_frame_pointer, (f));
3131 update_frame_icon (struct frame *f)
3133 if (f->icon_changed || f->windows_changed)
3136 Lisp_Object new_icon;
3138 XSETFRAME (frame, f);
3139 new_icon = glyph_image_instance (Vframe_icon_glyph, frame,
3141 if (!EQ (new_icon, f->icon))
3144 MAYBE_FRAMEMETH (f, set_frame_icon, (f));
3148 f->icon_changed = 0;
3152 icon_glyph_changed (Lisp_Object glyph, Lisp_Object property,
3159 /***************************************************************************/
3161 /* initialization */
3163 /***************************************************************************/
3172 title_string_charc_dynarr = Dynarr_new (Charc);
3173 xzero (title_string_display_line);
3178 syms_of_frame (void)
3180 INIT_LRECORD_IMPLEMENTATION (frame);
3182 defsymbol (&Qdelete_frame_hook, "delete-frame-hook");
3183 defsymbol (&Qselect_frame_hook, "select-frame-hook");
3184 defsymbol (&Qdeselect_frame_hook, "deselect-frame-hook");
3185 defsymbol (&Qcreate_frame_hook, "create-frame-hook");
3186 defsymbol (&Qcustom_initialize_frame, "custom-initialize-frame");
3187 defsymbol (&Qmouse_enter_frame_hook, "mouse-enter-frame-hook");
3188 defsymbol (&Qmouse_leave_frame_hook, "mouse-leave-frame-hook");
3189 defsymbol (&Qmap_frame_hook, "map-frame-hook");
3190 defsymbol (&Qunmap_frame_hook, "unmap-frame-hook");
3192 defsymbol (&Qframep, "framep");
3193 defsymbol (&Qframe_live_p, "frame-live-p");
3194 defsymbol (&Qdelete_frame, "delete-frame");
3195 defsymbol (&Qsynchronize_minibuffers, "synchronize-minibuffers");
3196 defsymbol (&Qbuffer_predicate, "buffer-predicate");
3197 defsymbol (&Qframe_being_created, "frame-being-created");
3198 defsymbol (&Qmake_initial_minibuffer_frame, "make-initial-minibuffer-frame");
3200 defsymbol (&Qframe_title_format, "frame-title-format");
3201 defsymbol (&Qframe_icon_title_format, "frame-icon-title-format");
3203 defsymbol (&Qhidden, "hidden");
3204 defsymbol (&Qvisible, "visible");
3205 defsymbol (&Qiconic, "iconic");
3206 defsymbol (&Qinvisible, "invisible");
3207 defsymbol (&Qvisible_iconic, "visible-iconic");
3208 defsymbol (&Qinvisible_iconic, "invisible-iconic");
3209 defsymbol (&Qnomini, "nomini");
3210 defsymbol (&Qvisible_nomini, "visible-nomini");
3211 defsymbol (&Qiconic_nomini, "iconic-nomini");
3212 defsymbol (&Qinvisible_nomini, "invisible-nomini");
3213 defsymbol (&Qvisible_iconic_nomini, "visible-iconic-nomini");
3214 defsymbol (&Qinvisible_iconic_nomini, "invisible-iconic-nomini");
3216 defsymbol (&Qminibuffer, "minibuffer");
3217 defsymbol (&Qunsplittable, "unsplittable");
3218 defsymbol (&Qinternal_border_width, "internal-border-width");
3219 defsymbol (&Qtop_toolbar_shadow_color, "top-toolbar-shadow-color");
3220 defsymbol (&Qbottom_toolbar_shadow_color, "bottom-toolbar-shadow-color");
3221 defsymbol (&Qbackground_toolbar_color, "background-toolbar-color");
3222 defsymbol (&Qtop_toolbar_shadow_pixmap, "top-toolbar-shadow-pixmap");
3223 defsymbol (&Qbottom_toolbar_shadow_pixmap, "bottom-toolbar-shadow-pixmap");
3224 defsymbol (&Qtoolbar_shadow_thickness, "toolbar-shadow-thickness");
3225 defsymbol (&Qscrollbar_placement, "scrollbar-placement");
3226 defsymbol (&Qinter_line_space, "inter-line-space");
3227 /* Qiconic already in this function. */
3228 defsymbol (&Qvisual_bell, "visual-bell");
3229 defsymbol (&Qbell_volume, "bell-volume");
3230 defsymbol (&Qpointer_background, "pointer-background");
3231 defsymbol (&Qpointer_color, "pointer-color");
3232 defsymbol (&Qtext_pointer, "text-pointer");
3233 defsymbol (&Qspace_pointer, "space-pointer");
3234 defsymbol (&Qmodeline_pointer, "modeline-pointer");
3235 defsymbol (&Qgc_pointer, "gc-pointer");
3236 defsymbol (&Qinitially_unmapped, "initially-unmapped");
3237 defsymbol (&Quse_backing_store, "use-backing-store");
3238 defsymbol (&Qborder_color, "border-color");
3239 defsymbol (&Qborder_width, "border-width");
3240 /* Qwidth, Qheight, Qleft, Qtop in general.c */
3241 defsymbol (&Qset_specifier, "set-specifier");
3242 defsymbol (&Qset_face_property, "set-face-property");
3243 defsymbol (&Qface_property_instance, "face-property-instance");
3244 defsymbol (&Qframe_property_alias, "frame-property-alias");
3246 DEFSUBR (Fmake_frame);
3248 DEFSUBR (Fframe_live_p);
3250 DEFSUBR (Fignore_event);
3252 DEFSUBR (Ffocus_frame);
3253 DEFSUBR (Fselect_frame);
3254 DEFSUBR (Fselected_frame);
3255 DEFSUBR (Factive_minibuffer_window);
3256 DEFSUBR (Flast_nonminibuf_frame);
3257 DEFSUBR (Fframe_root_window);
3258 DEFSUBR (Fframe_selected_window);
3259 DEFSUBR (Fset_frame_selected_window);
3260 DEFSUBR (Fframe_device);
3261 DEFSUBR (Fnext_frame);
3262 DEFSUBR (Fprevious_frame);
3263 DEFSUBR (Fdelete_frame);
3264 DEFSUBR (Fmouse_position);
3265 DEFSUBR (Fmouse_pixel_position);
3266 DEFSUBR (Fmouse_position_as_motion_event);
3267 DEFSUBR (Fset_mouse_position);
3268 DEFSUBR (Fset_mouse_pixel_position);
3269 DEFSUBR (Fmake_frame_visible);
3270 DEFSUBR (Fmake_frame_invisible);
3271 DEFSUBR (Ficonify_frame);
3272 DEFSUBR (Fdeiconify_frame);
3273 DEFSUBR (Fframe_visible_p);
3274 DEFSUBR (Fframe_totally_visible_p);
3275 DEFSUBR (Fframe_iconified_p);
3276 DEFSUBR (Fvisible_frame_list);
3277 DEFSUBR (Fraise_frame);
3278 DEFSUBR (Flower_frame);
3279 DEFSUBR (Fdisable_frame);
3280 DEFSUBR (Fenable_frame);
3281 DEFSUBR (Fframe_property);
3282 DEFSUBR (Fframe_properties);
3283 DEFSUBR (Fset_frame_properties);
3284 DEFSUBR (Fframe_pixel_height);
3285 DEFSUBR (Fframe_pixel_width);
3286 DEFSUBR (Fframe_name);
3287 DEFSUBR (Fframe_modified_tick);
3288 DEFSUBR (Fset_frame_height);
3289 DEFSUBR (Fset_frame_width);
3290 DEFSUBR (Fset_frame_size);
3291 DEFSUBR (Fset_frame_position);
3292 DEFSUBR (Fset_frame_pointer);
3293 DEFSUBR (Fprint_job_page_number);
3294 DEFSUBR (Fprint_job_eject_page);
3298 vars_of_frame (void)
3301 Vframe_being_created = Qnil;
3302 staticpro (&Vframe_being_created);
3305 Fprovide (intern ("cde"));
3308 #ifdef HAVE_OFFIX_DND
3309 Fprovide (intern ("offix"));
3312 #if 0 /* FSFmacs stupidity */
3313 xxDEFVAR_LISP ("emacs-iconified", &Vemacs_iconified /*
3314 Non-nil if all of emacs is iconified and frame updates are not needed.
3316 Vemacs_iconified = Qnil;
3319 DEFVAR_LISP ("select-frame-hook", &Vselect_frame_hook /*
3320 Function or functions to run just after a new frame is given the focus.
3321 Note that calling `select-frame' does not necessarily set the focus:
3322 The actual window-system focus will not be changed until the next time
3323 that XEmacs is waiting for an event, and even then, the window manager
3324 may refuse the focus-change request.
3326 Vselect_frame_hook = Qnil;
3328 DEFVAR_LISP ("deselect-frame-hook", &Vdeselect_frame_hook /*
3329 Function or functions to run just before a frame loses the focus.
3330 See `select-frame-hook'.
3332 Vdeselect_frame_hook = Qnil;
3334 DEFVAR_LISP ("delete-frame-hook", &Vdelete_frame_hook /*
3335 Function or functions to call when a frame is deleted.
3336 One argument, the about-to-be-deleted frame.
3338 Vdelete_frame_hook = Qnil;
3340 DEFVAR_LISP ("create-frame-hook", &Vcreate_frame_hook /*
3341 Function or functions to call when a frame is created.
3342 One argument, the newly-created frame.
3344 Vcreate_frame_hook = Qnil;
3346 DEFVAR_LISP ("mouse-enter-frame-hook", &Vmouse_enter_frame_hook /*
3347 Function or functions to call when the mouse enters a frame.
3348 One argument, the frame.
3349 Be careful not to make assumptions about the window manager's focus model.
3350 In most cases, the `deselect-frame-hook' is more appropriate.
3352 Vmouse_enter_frame_hook = Qnil;
3354 DEFVAR_LISP ("mouse-leave-frame-hook", &Vmouse_leave_frame_hook /*
3355 Function or functions to call when the mouse leaves a frame.
3356 One argument, the frame.
3357 Be careful not to make assumptions about the window manager's focus model.
3358 In most cases, the `select-frame-hook' is more appropriate.
3360 Vmouse_leave_frame_hook = Qnil;
3362 DEFVAR_LISP ("map-frame-hook", &Vmap_frame_hook /*
3363 Function or functions to call when a frame is mapped.
3364 One argument, the frame.
3366 Vmap_frame_hook = Qnil;
3368 DEFVAR_LISP ("unmap-frame-hook", &Vunmap_frame_hook /*
3369 Function or functions to call when a frame is unmapped.
3370 One argument, the frame.
3372 Vunmap_frame_hook = Qnil;
3374 DEFVAR_BOOL ("allow-deletion-of-last-visible-frame",
3375 &allow_deletion_of_last_visible_frame /*
3376 *Non-nil means to assume the force option to delete-frame.
3378 allow_deletion_of_last_visible_frame = 0;
3380 DEFVAR_LISP ("adjust-frame-function", &Vadjust_frame_function /*
3381 Function or constant controlling adjustment of frame.
3382 When scrollbars, toolbars, default font etc. change in frame, the frame
3383 needs to be adjusted. The adjustment is controlled by this variable.
3385 nil to keep character frame size unchanged when possible (resize)
3386 t to keep pixel size unchanged (never resize)
3387 function symbol or lambda form. This function must return boolean
3388 value which is treated as above. Function is passed one parameter,
3389 the frame being adjusted. It function should not modify or delete
3392 Vadjust_frame_function = Qnil;
3394 DEFVAR_LISP ("mouse-motion-handler", &Vmouse_motion_handler /*
3395 Handler for motion events. One arg, the event.
3396 For most applications, you should use `mode-motion-hook' instead of this.
3398 Vmouse_motion_handler = Qnil;
3400 DEFVAR_LISP ("synchronize-minibuffers",&Vsynchronize_minibuffers /*
3401 Set to t if all minibuffer windows are to be synchronized.
3402 This will cause echo area messages to appear in the minibuffers of all
3405 Vsynchronize_minibuffers = Qnil;
3407 DEFVAR_LISP ("frame-title-format", &Vframe_title_format /*
3408 Controls the title of the window-system window of the selected frame.
3409 This is the same format as `modeline-format' with the exception that
3412 /* #### I would change this unilaterally but for the wrath of the Kyles
3415 Vframe_title_format = build_string ("%b - XEmacs");
3417 Vframe_title_format = build_string ("%S: %b");
3420 DEFVAR_LISP ("frame-icon-title-format", &Vframe_icon_title_format /*
3421 Controls the title of the icon corresponding to the selected frame.
3422 See also the variable `frame-title-format'.
3424 Vframe_icon_title_format = build_string ("%b");
3426 DEFVAR_LISP ("default-frame-name", &Vdefault_frame_name /*
3427 The default name to assign to newly-created frames.
3428 This can be overridden by arguments to `make-frame'. This must be a string.
3429 This is used primarily for picking up X resources, and is *not* the title
3430 of the frame. (See `frame-title-format'.)
3433 Vdefault_frame_name = build_string ("emacs");
3435 Vdefault_frame_name = build_string ("InfoDock");
3438 DEFVAR_LISP ("default-frame-plist", &Vdefault_frame_plist /*
3439 Plist of default values for frame creation, other than the first one.
3440 These may be set in your init file, like this:
3442 \(setq default-frame-plist '(width 80 height 55))
3444 The properties may be in alist format for backward compatibility
3445 but you should not rely on this behavior.
3447 These override values given in window system configuration data,
3448 including X Windows' defaults database.
3450 Since the first X frame is created before loading your .emacs file,
3451 you must use the X resource database for that.
3453 For values specific to the first Emacs frame, see `initial-frame-plist'.
3454 For values specific to the separate minibuffer frame, see
3455 `minibuffer-frame-plist'.
3457 See also the variables `default-x-frame-plist' and
3458 `default-tty-frame-plist', which are like `default-frame-plist'
3459 except that they apply only to X or tty frames, respectively
3460 \(whereas `default-frame-plist' applies to all types of frames).
3462 Vdefault_frame_plist = Qnil;
3464 DEFVAR_LISP ("frame-icon-glyph", &Vframe_icon_glyph /*
3465 Icon glyph used to iconify a frame.
3470 complex_vars_of_frame (void)
3472 Vframe_icon_glyph = allocate_glyph (GLYPH_ICON, icon_glyph_changed);