]> code.delx.au - gnu-emacs/blob - src/frame.c
Merged in changes from CVS trunk. Plus added lisp/term tweaks.
[gnu-emacs] / src / frame.c
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 #include <config.h>
23
24 #include <stdio.h>
25 #include "lisp.h"
26 #include "charset.h"
27 #ifdef HAVE_X_WINDOWS
28 #include "xterm.h"
29 #endif
30 #ifdef WINDOWSNT
31 #include "w32term.h"
32 #endif
33 #ifdef MAC_OS
34 #include "macterm.h"
35 #endif
36 #include "buffer.h"
37 /* These help us bind and responding to switch-frame events. */
38 #include "commands.h"
39 #include "keyboard.h"
40 #include "frame.h"
41 #ifdef HAVE_WINDOW_SYSTEM
42 #include "fontset.h"
43 #endif
44 #include "blockinput.h"
45 #include "termchar.h"
46 #include "termhooks.h"
47 #include "dispextern.h"
48 #include "window.h"
49 #ifdef MSDOS
50 #include "msdos.h"
51 #include "dosfns.h"
52 #endif
53
54
55 #ifdef HAVE_WINDOW_SYSTEM
56
57 /* The name we're using in resource queries. Most often "emacs". */
58
59 Lisp_Object Vx_resource_name;
60
61 /* The application class we're using in resource queries.
62 Normally "Emacs". */
63
64 Lisp_Object Vx_resource_class;
65
66 #endif
67
68 Lisp_Object Qframep, Qframe_live_p;
69 Lisp_Object Qicon, Qmodeline;
70 Lisp_Object Qonly;
71 Lisp_Object Qx, Qw32, Qmac, Qpc;
72 Lisp_Object Qvisible;
73 Lisp_Object Qdisplay_type;
74 Lisp_Object Qbackground_mode;
75 Lisp_Object Qinhibit_default_face_x_resources;
76
77 Lisp_Object Qx_frame_parameter;
78 Lisp_Object Qx_resource_name;
79 Lisp_Object Qdevice;
80 Lisp_Object Qdisplay_live_p;
81
82 /* Frame parameters (set or reported). */
83
84 Lisp_Object Qauto_raise, Qauto_lower;
85 Lisp_Object Qborder_color, Qborder_width;
86 Lisp_Object Qcursor_color, Qcursor_type;
87 Lisp_Object Qgeometry; /* Not used */
88 Lisp_Object Qheight, Qwidth;
89 Lisp_Object Qleft, Qright;
90 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
91 Lisp_Object Qinternal_border_width;
92 Lisp_Object Qmouse_color;
93 Lisp_Object Qminibuffer;
94 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
95 Lisp_Object Qvisibility;
96 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
97 Lisp_Object Qscreen_gamma;
98 Lisp_Object Qline_spacing;
99 Lisp_Object Quser_position, Quser_size;
100 Lisp_Object Qwait_for_wm;
101 Lisp_Object Qwindow_id;
102 #ifdef HAVE_X_WINDOWS
103 Lisp_Object Qouter_window_id;
104 #endif
105 Lisp_Object Qparent_id;
106 Lisp_Object Qtitle, Qname;
107 Lisp_Object Qunsplittable;
108 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
109 Lisp_Object Qleft_fringe, Qright_fringe;
110 Lisp_Object Qbuffer_predicate, Qbuffer_list;
111 Lisp_Object Qtty_color_mode;
112 Lisp_Object Qtty, Qtty_type;
113 Lisp_Object Qwindow_system;
114
115 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
116
117 Lisp_Object Qface_set_after_frame_default;
118
119 Lisp_Object Vterminal_frame;
120 Lisp_Object Vdefault_frame_alist;
121 Lisp_Object Vdefault_frame_scroll_bars;
122 Lisp_Object Vmouse_position_function;
123 Lisp_Object Vmouse_highlight;
124 Lisp_Object Vdelete_frame_functions;
125 \f
126 static void
127 set_menu_bar_lines_1 (window, n)
128 Lisp_Object window;
129 int n;
130 {
131 struct window *w = XWINDOW (window);
132
133 XSETFASTINT (w->last_modified, 0);
134 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
135 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
136
137 if (INTEGERP (w->orig_top_line))
138 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
139 if (INTEGERP (w->orig_total_lines))
140 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
141
142 /* Handle just the top child in a vertical split. */
143 if (!NILP (w->vchild))
144 set_menu_bar_lines_1 (w->vchild, n);
145
146 /* Adjust all children in a horizontal split. */
147 for (window = w->hchild; !NILP (window); window = w->next)
148 {
149 w = XWINDOW (window);
150 set_menu_bar_lines_1 (window, n);
151 }
152 }
153
154 void
155 set_menu_bar_lines (f, value, oldval)
156 struct frame *f;
157 Lisp_Object value, oldval;
158 {
159 int nlines;
160 int olines = FRAME_MENU_BAR_LINES (f);
161
162 /* Right now, menu bars don't work properly in minibuf-only frames;
163 most of the commands try to apply themselves to the minibuffer
164 frame itself, and get an error because you can't switch buffers
165 in or split the minibuffer window. */
166 if (FRAME_MINIBUF_ONLY_P (f))
167 return;
168
169 if (INTEGERP (value))
170 nlines = XINT (value);
171 else
172 nlines = 0;
173
174 if (nlines != olines)
175 {
176 windows_or_buffers_changed++;
177 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
178 FRAME_MENU_BAR_LINES (f) = nlines;
179 set_menu_bar_lines_1 (f->root_window, nlines - olines);
180 adjust_glyphs (f);
181 }
182 }
183 \f
184 Lisp_Object Vemacs_iconified;
185 Lisp_Object Vframe_list;
186
187 extern Lisp_Object Vminibuffer_list;
188 extern Lisp_Object get_minibuffer ();
189 extern Lisp_Object Fhandle_switch_frame ();
190 extern Lisp_Object Fredirect_frame_focus ();
191 extern Lisp_Object x_get_focus_frame ();
192 \f
193 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
194 doc: /* Return non-nil if OBJECT is a frame.
195 Value is t for a termcap frame (a character-only terminal),
196 `x' for an Emacs frame that is really an X window,
197 `w32' for an Emacs frame that is a window on MS-Windows display,
198 `mac' for an Emacs frame on a Macintosh display,
199 `pc' for a direct-write MS-DOS frame.
200 See also `frame-live-p'. */)
201 (object)
202 Lisp_Object object;
203 {
204 if (!FRAMEP (object))
205 return Qnil;
206 switch (XFRAME (object)->output_method)
207 {
208 case output_initial: /* The initial frame is like a termcap frame. */
209 case output_termcap:
210 return Qt;
211 case output_x_window:
212 return Qx;
213 case output_w32:
214 return Qw32;
215 case output_msdos_raw:
216 return Qpc;
217 case output_mac:
218 return Qmac;
219 default:
220 abort ();
221 }
222 }
223
224 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
225 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
226 Value is nil if OBJECT is not a live frame. If object is a live
227 frame, the return value indicates what sort of output device it is
228 displayed on. See the documentation of `framep' for possible
229 return values. */)
230 (object)
231 Lisp_Object object;
232 {
233 return ((FRAMEP (object)
234 && FRAME_LIVE_P (XFRAME (object)))
235 ? Fframep (object)
236 : Qnil);
237 }
238
239 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
240 doc: /* The name of the window system that FRAME is displaying through.
241 The value is a symbol---for instance, 'x' for X windows.
242 The value is nil if Emacs is using a text-only terminal.
243
244 FRAME defaults to the currently selected frame. */)
245 (frame)
246 Lisp_Object frame;
247 {
248 Lisp_Object type;
249 if (NILP (frame))
250 frame = selected_frame;
251
252 type = Fframep (frame);
253
254 if (NILP (type))
255 wrong_type_argument (Qframep, frame);
256
257 if (EQ (type, Qt))
258 return Qnil;
259 else
260 return type;
261 }
262
263 struct frame *
264 make_frame (mini_p)
265 int mini_p;
266 {
267 Lisp_Object frame;
268 register struct frame *f;
269 register Lisp_Object root_window;
270 register Lisp_Object mini_window;
271
272 f = allocate_frame ();
273 XSETFRAME (frame, f);
274
275 f->desired_matrix = 0;
276 f->current_matrix = 0;
277 f->desired_pool = 0;
278 f->current_pool = 0;
279 f->glyphs_initialized_p = 0;
280 f->decode_mode_spec_buffer = 0;
281 f->visible = 0;
282 f->async_visible = 0;
283 f->output_data.nothing = 0;
284 f->iconified = 0;
285 f->async_iconified = 0;
286 f->wants_modeline = 1;
287 f->auto_raise = 0;
288 f->auto_lower = 0;
289 f->no_split = 0;
290 f->garbaged = 1;
291 f->has_minibuffer = mini_p;
292 f->focus_frame = Qnil;
293 f->explicit_name = 0;
294 f->can_have_scroll_bars = 0;
295 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
296 f->param_alist = Qnil;
297 f->scroll_bars = Qnil;
298 f->condemned_scroll_bars = Qnil;
299 f->face_alist = Qnil;
300 f->face_cache = NULL;
301 f->menu_bar_items = Qnil;
302 f->menu_bar_vector = Qnil;
303 f->menu_bar_items_used = 0;
304 f->buffer_predicate = Qnil;
305 f->buffer_list = Qnil;
306 f->namebuf = 0;
307 f->title = Qnil;
308 f->menu_bar_window = Qnil;
309 f->tool_bar_window = Qnil;
310 f->tool_bar_items = Qnil;
311 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
312 f->n_tool_bar_items = 0;
313 f->left_fringe_width = f->right_fringe_width = 0;
314 f->fringe_cols = 0;
315 f->scroll_bar_actual_width = 0;
316 f->border_width = 0;
317 f->internal_border_width = 0;
318 f->column_width = 1; /* !FRAME_WINDOW_P value */
319 f->line_height = 1; /* !FRAME_WINDOW_P value */
320 f->x_pixels_diff = f->y_pixels_diff = 0;
321 #ifdef HAVE_WINDOW_SYSTEM
322 f->want_fullscreen = FULLSCREEN_NONE;
323 #endif
324 f->size_hint_flags = 0;
325 f->win_gravity = 0;
326
327 root_window = make_window ();
328 if (mini_p)
329 {
330 mini_window = make_window ();
331 XWINDOW (root_window)->next = mini_window;
332 XWINDOW (mini_window)->prev = root_window;
333 XWINDOW (mini_window)->mini_p = Qt;
334 XWINDOW (mini_window)->frame = frame;
335 f->minibuffer_window = mini_window;
336 }
337 else
338 {
339 mini_window = Qnil;
340 XWINDOW (root_window)->next = Qnil;
341 f->minibuffer_window = Qnil;
342 }
343
344 XWINDOW (root_window)->frame = frame;
345
346 /* 10 is arbitrary,
347 just so that there is "something there."
348 Correct size will be set up later with change_frame_size. */
349
350 SET_FRAME_COLS (f, 10);
351 FRAME_LINES (f) = 10;
352
353 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
354 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
355
356 if (mini_p)
357 {
358 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
359 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
360 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
361 }
362
363 /* Choose a buffer for the frame's root window. */
364 {
365 Lisp_Object buf;
366
367 XWINDOW (root_window)->buffer = Qt;
368 buf = Fcurrent_buffer ();
369 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
370 a space), try to find another one. */
371 if (SREF (Fbuffer_name (buf), 0) == ' ')
372 buf = Fother_buffer (buf, Qnil, Qnil);
373
374 /* Use set_window_buffer, not Fset_window_buffer, and don't let
375 hooks be run by it. The reason is that the whole frame/window
376 arrangement is not yet fully intialized at this point. Windows
377 don't have the right size, glyph matrices aren't initialized
378 etc. Running Lisp functions at this point surely ends in a
379 SEGV. */
380 set_window_buffer (root_window, buf, 0, 0);
381 f->buffer_list = Fcons (buf, Qnil);
382 }
383
384 if (mini_p)
385 {
386 XWINDOW (mini_window)->buffer = Qt;
387 set_window_buffer (mini_window,
388 (NILP (Vminibuffer_list)
389 ? get_minibuffer (0)
390 : Fcar (Vminibuffer_list)),
391 0, 0);
392 }
393
394 f->root_window = root_window;
395 f->selected_window = root_window;
396 /* Make sure this window seems more recently used than
397 a newly-created, never-selected window. */
398 ++window_select_count;
399 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
400
401 f->default_face_done_p = 0;
402
403 return f;
404 }
405 \f
406 #ifdef HAVE_WINDOW_SYSTEM
407 /* Make a frame using a separate minibuffer window on another frame.
408 MINI_WINDOW is the minibuffer window to use. nil means use the
409 default (the global minibuffer). */
410
411 struct frame *
412 make_frame_without_minibuffer (mini_window, kb, display)
413 register Lisp_Object mini_window;
414 KBOARD *kb;
415 Lisp_Object display;
416 {
417 register struct frame *f;
418 struct gcpro gcpro1;
419
420 if (!NILP (mini_window))
421 CHECK_LIVE_WINDOW (mini_window);
422
423 #ifdef MULTI_KBOARD
424 if (!NILP (mini_window)
425 && XFRAME (XWINDOW (mini_window)->frame)->device->kboard != kb)
426 error ("Frame and minibuffer must be on the same display");
427 #endif
428
429 /* Make a frame containing just a root window. */
430 f = make_frame (0);
431
432 if (NILP (mini_window))
433 {
434 /* Use default-minibuffer-frame if possible. */
435 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
436 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
437 {
438 Lisp_Object frame_dummy;
439
440 XSETFRAME (frame_dummy, f);
441 GCPRO1 (frame_dummy);
442 /* If there's no minibuffer frame to use, create one. */
443 kb->Vdefault_minibuffer_frame =
444 call1 (intern ("make-initial-minibuffer-frame"), display);
445 UNGCPRO;
446 }
447
448 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
449 }
450
451 f->minibuffer_window = mini_window;
452
453 /* Make the chosen minibuffer window display the proper minibuffer,
454 unless it is already showing a minibuffer. */
455 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
456 Fset_window_buffer (mini_window,
457 (NILP (Vminibuffer_list)
458 ? get_minibuffer (0)
459 : Fcar (Vminibuffer_list)), Qnil);
460 return f;
461 }
462
463 /* Make a frame containing only a minibuffer window. */
464
465 struct frame *
466 make_minibuffer_frame ()
467 {
468 /* First make a frame containing just a root window, no minibuffer. */
469
470 register struct frame *f = make_frame (0);
471 register Lisp_Object mini_window;
472 register Lisp_Object frame;
473
474 XSETFRAME (frame, f);
475
476 f->auto_raise = 0;
477 f->auto_lower = 0;
478 f->no_split = 1;
479 f->wants_modeline = 0;
480 f->has_minibuffer = 1;
481
482 /* Now label the root window as also being the minibuffer.
483 Avoid infinite looping on the window chain by marking next pointer
484 as nil. */
485
486 mini_window = f->minibuffer_window = f->root_window;
487 XWINDOW (mini_window)->mini_p = Qt;
488 XWINDOW (mini_window)->next = Qnil;
489 XWINDOW (mini_window)->prev = Qnil;
490 XWINDOW (mini_window)->frame = frame;
491
492 /* Put the proper buffer in that window. */
493
494 Fset_window_buffer (mini_window,
495 (NILP (Vminibuffer_list)
496 ? get_minibuffer (0)
497 : Fcar (Vminibuffer_list)), Qnil);
498 return f;
499 }
500 #endif /* HAVE_WINDOW_SYSTEM */
501 \f
502 /* Construct a frame that refers to a terminal. */
503
504 static int terminal_frame_count;
505
506 struct frame *
507 make_initial_frame (void)
508 {
509 struct frame *f;
510 struct device *device;
511 Lisp_Object frame;
512
513 #ifdef MULTI_KBOARD
514 /* Create the initial keyboard. */
515 if (!initial_kboard)
516 {
517 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
518 init_kboard (initial_kboard);
519 initial_kboard->next_kboard = all_kboards;
520 all_kboards = initial_kboard;
521 }
522 #endif
523
524 /* The first call must initialize Vframe_list. */
525 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
526 Vframe_list = Qnil;
527
528 device = init_initial_device ();
529
530 f = make_frame (1);
531 XSETFRAME (frame, f);
532
533 Vframe_list = Fcons (frame, Vframe_list);
534
535 terminal_frame_count = 1;
536 f->name = build_string ("F1");
537
538 f->visible = 1;
539 f->async_visible = 1;
540
541 f->output_method = device->type;
542 f->device = device;
543 f->device->reference_count++;
544 f->output_data.nothing = 0;
545
546 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
547 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
548
549 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
550 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
551
552 return f;
553 }
554
555
556 struct frame *
557 make_terminal_frame (struct device *device)
558 {
559 register struct frame *f;
560 Lisp_Object frame;
561 char name[20];
562
563 f = make_frame (1);
564
565 XSETFRAME (frame, f);
566 Vframe_list = Fcons (frame, Vframe_list);
567
568 terminal_frame_count++;
569 sprintf (name, "F%d", terminal_frame_count);
570 f->name = build_string (name);
571
572 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
573 f->async_visible = 1; /* Don't let visible be cleared later. */
574 #ifdef MSDOS
575 f->output_data.x = &the_only_x_display;
576 if (!inhibit_window_system
577 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
578 || XFRAME (selected_frame)->output_method == output_msdos_raw))
579 {
580 f->output_method = output_msdos_raw;
581 /* This initialization of foreground and background pixels is
582 only important for the initial frame created in temacs. If
583 we don't do that, we get black background and foreground in
584 the dumped Emacs because the_only_x_display is a static
585 variable, hence it is born all-zeroes, and zero is the code
586 for the black color. Other frames all inherit their pixels
587 from what's already in the_only_x_display. */
588 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
589 && f->output_data.x->background_pixel == 0
590 && f->output_data.x->foreground_pixel == 0)
591 {
592 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
593 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
594 }
595 }
596 else
597 f->output_method = output_termcap;
598 #else
599 #ifdef WINDOWSNT
600 f->output_method = output_termcap;
601 f->output_data.x = &tty_display; /* XXX ??? */
602 #else
603 #ifdef MAC_OS8
604 make_mac_terminal_frame (f);
605 #else
606 {
607 f->output_method = output_termcap;
608 f->device = device;
609 f->device->reference_count++;
610 create_tty_output (f);
611
612 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
613 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
614
615 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
616 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
617
618 /* Set the top frame to the newly created frame. */
619 if (FRAME_TTY (f)->top_frame
620 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
621 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
622
623 FRAME_TTY (f)->top_frame = frame;
624 }
625
626 #ifdef CANNOT_DUMP
627 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
628 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
629 #endif
630 #endif /* MAC_OS8 */
631 #endif /* WINDOWSNT */
632 #endif /* MSDOS */
633
634 if (!noninteractive)
635 init_frame_faces (f);
636
637 return f;
638 }
639
640 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
641 1, 1, 0,
642 doc: /* Create an additional terminal frame, possibly on another terminal.
643 This function takes one argument, an alist specifying frame parameters.
644
645 You can create multiple frames on a single text-only terminal, but
646 only one of them (the selected terminal frame) is actually displayed.
647
648 In practice, generally you don't need to specify any parameters,
649 except when you want to create a new frame on another terminal.
650 In that case, the `tty' parameter specifies the device file to open,
651 and the `tty-type' parameter specifies the terminal type. Example:
652
653 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
654
655 Note that changing the size of one terminal frame automatically
656 affects all frames on the same terminal device. */)
657 (parms)
658 Lisp_Object parms;
659 {
660 struct frame *f;
661 struct device *d = NULL;
662 Lisp_Object frame, tem;
663 struct frame *sf = SELECTED_FRAME ();
664
665 #ifdef MSDOS
666 if (sf->output_method != output_msdos_raw
667 && sf->output_method != output_termcap)
668 abort ();
669 #else /* not MSDOS */
670
671 #ifdef MAC_OS
672 if (sf->output_method != output_mac)
673 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
674 #else
675 #if 0 /* This should work now! */
676 if (sf->output_method != output_termcap)
677 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
678 #endif
679 #endif
680 #endif /* not MSDOS */
681
682 {
683 Lisp_Object display_device;
684
685 display_device = Fassq (Qdevice, parms);
686 if (!NILP (display_device))
687 {
688 display_device = XCDR (display_device);
689 CHECK_NUMBER (display_device);
690 d = get_device (XINT (display_device), 1);
691 }
692 }
693
694 if (!d)
695 {
696 Lisp_Object tty, tty_type;
697 char *name = 0, *type = 0;
698
699 tty = Fassq (Qtty, parms);
700 if (EQ (tty, Qnil))
701 tty = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
702 if (EQ (tty, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
703 && FRAME_TTY (XFRAME (selected_frame))->name)
704 tty = build_string (FRAME_TTY (XFRAME (selected_frame))->name);
705 if (EQ (tty, Qnil))
706 tty = Fassq (Qtty, Vdefault_frame_alist);
707 if (! EQ (tty, Qnil) && ! STRINGP (tty))
708 tty = XCDR (tty);
709 if (EQ (tty, Qnil) || !STRINGP (tty))
710 tty = Qnil;
711
712 tty_type = Fassq (Qtty_type, parms);
713 if (EQ (tty_type, Qnil))
714 tty_type = Fassq (Qtty, XFRAME (selected_frame)->param_alist);
715 if (EQ (tty_type, Qnil) && FRAME_TERMCAP_P (XFRAME (selected_frame))
716 && FRAME_TTY (XFRAME (selected_frame))->type)
717 tty_type = build_string (FRAME_TTY (XFRAME (selected_frame))->type);
718 if (EQ (tty_type, Qnil))
719 tty_type = Fassq (Qtty_type, Vdefault_frame_alist);
720 if (! EQ (tty_type, Qnil) && ! STRINGP (tty_type))
721 tty_type = XCDR (tty_type);
722 if (EQ (tty_type, Qnil) || !STRINGP (tty_type))
723 tty_type = Qnil;
724
725 if (! EQ (tty, Qnil))
726 {
727 name = (char *) alloca (SBYTES (tty) + 1);
728 strncpy (name, SDATA (tty), SBYTES (tty));
729 name[SBYTES (tty)] = 0;
730 }
731
732 if (! EQ (tty_type, Qnil))
733 {
734 type = (char *) alloca (SBYTES (tty_type) + 1);
735 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
736 type[SBYTES (tty_type)] = 0;
737 }
738
739 d = init_tty (name, type, 0); /* Errors are not fatal. */
740 }
741
742 f = make_terminal_frame (d);
743
744 {
745 int width, height;
746 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
747 change_frame_size (f, height, width, 0, 0, 0);
748 }
749
750 adjust_glyphs (f);
751 calculate_costs (f);
752 XSETFRAME (frame, f);
753 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
754 Fmodify_frame_parameters (frame, parms);
755 Fmodify_frame_parameters (frame, Fcons (Fcons (Qwindow_system, Qnil), Qnil));
756
757 /* Make the frame face alist be frame-specific, so that each
758 frame could change its face definitions independently. */
759 f->face_alist = Fcopy_alist (sf->face_alist);
760 /* Simple Fcopy_alist isn't enough, because we need the contents of
761 the vectors which are the CDRs of associations in face_alist to
762 be copied as well. */
763 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
764 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
765 return frame;
766 }
767
768 \f
769 /* Perform the switch to frame FRAME.
770
771 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
772 FRAME1 as frame.
773
774 If TRACK is non-zero and the frame that currently has the focus
775 redirects its focus to the selected frame, redirect that focused
776 frame's focus to FRAME instead.
777
778 FOR_DELETION non-zero means that the selected frame is being
779 deleted, which includes the possibility that the frame's display
780 is dead. */
781
782 Lisp_Object
783 do_switch_frame (frame, track, for_deletion)
784 Lisp_Object frame;
785 int track, for_deletion;
786 {
787 struct frame *sf = SELECTED_FRAME ();
788
789 /* If FRAME is a switch-frame event, extract the frame we should
790 switch to. */
791 if (CONSP (frame)
792 && EQ (XCAR (frame), Qswitch_frame)
793 && CONSP (XCDR (frame)))
794 frame = XCAR (XCDR (frame));
795
796 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
797 a switch-frame event to arrive after a frame is no longer live,
798 especially when deleting the initial frame during startup. */
799 CHECK_FRAME (frame);
800 if (! FRAME_LIVE_P (XFRAME (frame)))
801 return Qnil;
802
803 if (sf == XFRAME (frame))
804 return frame;
805
806 /* This is too greedy; it causes inappropriate focus redirection
807 that's hard to get rid of. */
808 #if 0
809 /* If a frame's focus has been redirected toward the currently
810 selected frame, we should change the redirection to point to the
811 newly selected frame. This means that if the focus is redirected
812 from a minibufferless frame to a surrogate minibuffer frame, we
813 can use `other-window' to switch between all the frames using
814 that minibuffer frame, and the focus redirection will follow us
815 around. */
816 if (track)
817 {
818 Lisp_Object tail;
819
820 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
821 {
822 Lisp_Object focus;
823
824 if (!FRAMEP (XCAR (tail)))
825 abort ();
826
827 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
828
829 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
830 Fredirect_frame_focus (XCAR (tail), frame);
831 }
832 }
833 #else /* ! 0 */
834 /* Instead, apply it only to the frame we're pointing to. */
835 #ifdef HAVE_WINDOW_SYSTEM
836 if (track && FRAME_WINDOW_P (XFRAME (frame)))
837 {
838 Lisp_Object focus, xfocus;
839
840 xfocus = x_get_focus_frame (XFRAME (frame));
841 if (FRAMEP (xfocus))
842 {
843 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
844 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
845 Fredirect_frame_focus (xfocus, frame);
846 }
847 }
848 #endif /* HAVE_X_WINDOWS */
849 #endif /* ! 0 */
850
851 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
852 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
853
854 if (FRAME_TERMCAP_P (XFRAME (selected_frame))
855 && FRAME_TERMCAP_P (XFRAME (frame))
856 && FRAME_TTY (XFRAME (selected_frame)) == FRAME_TTY (XFRAME (frame)))
857 {
858 XFRAME (selected_frame)->async_visible = 2; /* obscured */
859 XFRAME (frame)->async_visible = 1;
860 FRAME_TTY (XFRAME (frame))->top_frame = frame;
861 }
862
863 selected_frame = frame;
864 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
865 last_nonminibuf_frame = XFRAME (selected_frame);
866
867 Fselect_window (XFRAME (frame)->selected_window, Qnil);
868
869 #ifndef WINDOWSNT
870 /* Make sure to switch the tty color mode to that of the newly
871 selected frame. */
872 sf = SELECTED_FRAME ();
873 if (FRAME_TERMCAP_P (sf))
874 {
875 Lisp_Object color_mode_spec, color_mode;
876
877 color_mode_spec = assq_no_quit (Qtty_color_mode, sf->param_alist);
878 if (CONSP (color_mode_spec))
879 color_mode = XCDR (color_mode_spec);
880 else
881 color_mode = make_number (0);
882 set_tty_color_mode (sf, color_mode);
883 }
884 #endif /* !WINDOWSNT */
885
886 /* We want to make sure that the next event generates a frame-switch
887 event to the appropriate frame. This seems kludgy to me, but
888 before you take it out, make sure that evaluating something like
889 (select-window (frame-root-window (new-frame))) doesn't end up
890 with your typing being interpreted in the new frame instead of
891 the one you're actually typing in. */
892 internal_last_event_frame = Qnil;
893
894 return frame;
895 }
896
897 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
898 doc: /* Select the frame FRAME.
899 Subsequent editing commands apply to its selected window.
900 The selection of FRAME lasts until the next time the user does
901 something to select a different frame, or until the next time this
902 function is called. If you are using a window system, the previously
903 selected frame may be restored as the selected frame after return to
904 the command loop, because it still may have the window system's input
905 focus. On a text-only terminal, the next redisplay will display FRAME.
906
907 This function returns FRAME, or nil if FRAME has been deleted. */)
908 (frame)
909 Lisp_Object frame;
910 {
911 return do_switch_frame (frame, 1, 0);
912 }
913
914
915 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
916 doc: /* Handle a switch-frame event EVENT.
917 Switch-frame events are usually bound to this function.
918 A switch-frame event tells Emacs that the window manager has requested
919 that the user's events be directed to the frame mentioned in the event.
920 This function selects the selected window of the frame of EVENT.
921
922 If EVENT is frame object, handle it as if it were a switch-frame event
923 to that frame. */)
924 (event)
925 Lisp_Object event;
926 {
927 /* Preserve prefix arg that the command loop just cleared. */
928 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
929 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
930 return do_switch_frame (event, 0, 0);
931 }
932
933 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
934 doc: /* Return the frame that is now selected. */)
935 ()
936 {
937 return selected_frame;
938 }
939 \f
940 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
941 doc: /* Return the frame object that window WINDOW is on. */)
942 (window)
943 Lisp_Object window;
944 {
945 CHECK_LIVE_WINDOW (window);
946 return XWINDOW (window)->frame;
947 }
948
949 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
950 doc: /* Returns the topmost, leftmost window of FRAME.
951 If omitted, FRAME defaults to the currently selected frame. */)
952 (frame)
953 Lisp_Object frame;
954 {
955 Lisp_Object w;
956
957 if (NILP (frame))
958 w = SELECTED_FRAME ()->root_window;
959 else
960 {
961 CHECK_LIVE_FRAME (frame);
962 w = XFRAME (frame)->root_window;
963 }
964 while (NILP (XWINDOW (w)->buffer))
965 {
966 if (! NILP (XWINDOW (w)->hchild))
967 w = XWINDOW (w)->hchild;
968 else if (! NILP (XWINDOW (w)->vchild))
969 w = XWINDOW (w)->vchild;
970 else
971 abort ();
972 }
973 return w;
974 }
975
976 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
977 Sactive_minibuffer_window, 0, 0, 0,
978 doc: /* Return the currently active minibuffer window, or nil if none. */)
979 ()
980 {
981 return minibuf_level ? minibuf_window : Qnil;
982 }
983
984 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
985 doc: /* Returns the root-window of FRAME.
986 If omitted, FRAME defaults to the currently selected frame. */)
987 (frame)
988 Lisp_Object frame;
989 {
990 Lisp_Object window;
991
992 if (NILP (frame))
993 window = SELECTED_FRAME ()->root_window;
994 else
995 {
996 CHECK_LIVE_FRAME (frame);
997 window = XFRAME (frame)->root_window;
998 }
999
1000 return window;
1001 }
1002
1003 DEFUN ("frame-selected-window", Fframe_selected_window,
1004 Sframe_selected_window, 0, 1, 0,
1005 doc: /* Return the selected window of frame object FRAME.
1006 If omitted, FRAME defaults to the currently selected frame. */)
1007 (frame)
1008 Lisp_Object frame;
1009 {
1010 Lisp_Object window;
1011
1012 if (NILP (frame))
1013 window = SELECTED_FRAME ()->selected_window;
1014 else
1015 {
1016 CHECK_LIVE_FRAME (frame);
1017 window = XFRAME (frame)->selected_window;
1018 }
1019
1020 return window;
1021 }
1022
1023 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1024 Sset_frame_selected_window, 2, 2, 0,
1025 doc: /* Set the selected window of frame object FRAME to WINDOW.
1026 Return WINDOW.
1027 If FRAME is nil, the selected frame is used.
1028 If FRAME is the selected frame, this makes WINDOW the selected window. */)
1029 (frame, window)
1030 Lisp_Object frame, window;
1031 {
1032 if (NILP (frame))
1033 frame = selected_frame;
1034
1035 CHECK_LIVE_FRAME (frame);
1036 CHECK_LIVE_WINDOW (window);
1037
1038 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1039 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1040
1041 if (EQ (frame, selected_frame))
1042 return Fselect_window (window, Qnil);
1043
1044 return XFRAME (frame)->selected_window = window;
1045 }
1046 \f
1047
1048 DEFUN ("frame-display", Fframe_display, Sframe_display, 0, 1, 0,
1049 doc: /* Return the display device that FRAME is displayed on.
1050 If FRAME is nil, the selected frame is used.
1051
1052 The display device is represented by its integer identifier. */)
1053 (frame)
1054 Lisp_Object frame;
1055 {
1056 struct device *d;
1057
1058 if (NILP (frame))
1059 frame = selected_frame;
1060
1061 CHECK_LIVE_FRAME (frame);
1062
1063 d = get_device (frame, 0);
1064
1065 if (!d)
1066 return Qnil;
1067 else
1068 return make_number (d->id);
1069 }
1070
1071 \f
1072 DEFUN ("frame-list", Fframe_list, Sframe_list,
1073 0, 0, 0,
1074 doc: /* Return a list of all frames. */)
1075 ()
1076 {
1077 Lisp_Object frames;
1078 frames = Fcopy_sequence (Vframe_list);
1079 #ifdef HAVE_WINDOW_SYSTEM
1080 if (FRAMEP (tip_frame))
1081 frames = Fdelq (tip_frame, frames);
1082 #endif
1083 return frames;
1084 }
1085
1086 /* Return the next frame in the frame list after FRAME.
1087 If MINIBUF is nil, exclude minibuffer-only frames.
1088 If MINIBUF is a window, include only its own frame
1089 and any frame now using that window as the minibuffer.
1090 If MINIBUF is `visible', include all visible frames.
1091 If MINIBUF is 0, include all visible and iconified frames.
1092 Otherwise, include all frames. */
1093
1094 Lisp_Object
1095 next_frame (frame, minibuf)
1096 Lisp_Object frame;
1097 Lisp_Object minibuf;
1098 {
1099 Lisp_Object tail;
1100 int passed = 0;
1101
1102 /* There must always be at least one frame in Vframe_list. */
1103 if (! CONSP (Vframe_list))
1104 abort ();
1105
1106 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1107 forever. Forestall that. */
1108 CHECK_LIVE_FRAME (frame);
1109
1110 while (1)
1111 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1112 {
1113 Lisp_Object f;
1114
1115 f = XCAR (tail);
1116
1117 if (passed
1118 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1119 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1120 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1121 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1122 {
1123 /* Decide whether this frame is eligible to be returned. */
1124
1125 /* If we've looped all the way around without finding any
1126 eligible frames, return the original frame. */
1127 if (EQ (f, frame))
1128 return f;
1129
1130 /* Let minibuf decide if this frame is acceptable. */
1131 if (NILP (minibuf))
1132 {
1133 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1134 return f;
1135 }
1136 else if (EQ (minibuf, Qvisible))
1137 {
1138 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1139 if (FRAME_VISIBLE_P (XFRAME (f)))
1140 return f;
1141 }
1142 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1143 {
1144 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1145 if (FRAME_VISIBLE_P (XFRAME (f))
1146 || FRAME_ICONIFIED_P (XFRAME (f)))
1147 return f;
1148 }
1149 else if (WINDOWP (minibuf))
1150 {
1151 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1152 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1153 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1154 FRAME_FOCUS_FRAME (XFRAME (f))))
1155 return f;
1156 }
1157 else
1158 return f;
1159 }
1160
1161 if (EQ (frame, f))
1162 passed++;
1163 }
1164 }
1165
1166 /* Return the previous frame in the frame list before FRAME.
1167 If MINIBUF is nil, exclude minibuffer-only frames.
1168 If MINIBUF is a window, include only its own frame
1169 and any frame now using that window as the minibuffer.
1170 If MINIBUF is `visible', include all visible frames.
1171 If MINIBUF is 0, include all visible and iconified frames.
1172 Otherwise, include all frames. */
1173
1174 Lisp_Object
1175 prev_frame (frame, minibuf)
1176 Lisp_Object frame;
1177 Lisp_Object minibuf;
1178 {
1179 Lisp_Object tail;
1180 Lisp_Object prev;
1181
1182 /* There must always be at least one frame in Vframe_list. */
1183 if (! CONSP (Vframe_list))
1184 abort ();
1185
1186 prev = Qnil;
1187 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1188 {
1189 Lisp_Object f;
1190
1191 f = XCAR (tail);
1192 if (!FRAMEP (f))
1193 abort ();
1194
1195 if (EQ (frame, f) && !NILP (prev))
1196 return prev;
1197
1198 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1199 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1200 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1201 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1202 {
1203 /* Decide whether this frame is eligible to be returned,
1204 according to minibuf. */
1205 if (NILP (minibuf))
1206 {
1207 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1208 prev = f;
1209 }
1210 else if (WINDOWP (minibuf))
1211 {
1212 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1213 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1214 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1215 FRAME_FOCUS_FRAME (XFRAME (f))))
1216 prev = f;
1217 }
1218 else if (EQ (minibuf, Qvisible))
1219 {
1220 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1221 if (FRAME_VISIBLE_P (XFRAME (f)))
1222 prev = f;
1223 }
1224 else if (XFASTINT (minibuf) == 0)
1225 {
1226 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1227 if (FRAME_VISIBLE_P (XFRAME (f))
1228 || FRAME_ICONIFIED_P (XFRAME (f)))
1229 prev = f;
1230 }
1231 else
1232 prev = f;
1233 }
1234 }
1235
1236 /* We've scanned the entire list. */
1237 if (NILP (prev))
1238 /* We went through the whole frame list without finding a single
1239 acceptable frame. Return the original frame. */
1240 return frame;
1241 else
1242 /* There were no acceptable frames in the list before FRAME; otherwise,
1243 we would have returned directly from the loop. Since PREV is the last
1244 acceptable frame in the list, return it. */
1245 return prev;
1246 }
1247
1248
1249 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1250 doc: /* Return the next frame in the frame list after FRAME.
1251 It considers only frames on the same terminal as FRAME.
1252 By default, skip minibuffer-only frames.
1253 If omitted, FRAME defaults to the selected frame.
1254 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1255 If MINIFRAME is a window, include only its own frame
1256 and any frame now using that window as the minibuffer.
1257 If MINIFRAME is `visible', include all visible frames.
1258 If MINIFRAME is 0, include all visible and iconified frames.
1259 Otherwise, include all frames. */)
1260 (frame, miniframe)
1261 Lisp_Object frame, miniframe;
1262 {
1263 if (NILP (frame))
1264 frame = selected_frame;
1265
1266 CHECK_LIVE_FRAME (frame);
1267 return next_frame (frame, miniframe);
1268 }
1269
1270 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1271 doc: /* Return the previous frame in the frame list before FRAME.
1272 It considers only frames on the same terminal as FRAME.
1273 By default, skip minibuffer-only frames.
1274 If omitted, FRAME defaults to the selected frame.
1275 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1276 If MINIFRAME is a window, include only its own frame
1277 and any frame now using that window as the minibuffer.
1278 If MINIFRAME is `visible', include all visible frames.
1279 If MINIFRAME is 0, include all visible and iconified frames.
1280 Otherwise, include all frames. */)
1281 (frame, miniframe)
1282 Lisp_Object frame, miniframe;
1283 {
1284 if (NILP (frame))
1285 frame = selected_frame;
1286 CHECK_LIVE_FRAME (frame);
1287 return prev_frame (frame, miniframe);
1288 }
1289 \f
1290 /* Return 1 if it is ok to delete frame F;
1291 0 if all frames aside from F are invisible.
1292 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1293
1294 int
1295 other_visible_frames (f)
1296 FRAME_PTR f;
1297 {
1298 /* We know the selected frame is visible,
1299 so if F is some other frame, it can't be the sole visible one. */
1300 if (f == SELECTED_FRAME ())
1301 {
1302 Lisp_Object frames;
1303 int count = 0;
1304
1305 for (frames = Vframe_list;
1306 CONSP (frames);
1307 frames = XCDR (frames))
1308 {
1309 Lisp_Object this;
1310
1311 this = XCAR (frames);
1312 /* Verify that the frame's window still exists
1313 and we can still talk to it. And note any recent change
1314 in visibility. */
1315 #ifdef HAVE_WINDOW_SYSTEM
1316 if (FRAME_WINDOW_P (XFRAME (this)))
1317 {
1318 x_sync (XFRAME (this));
1319 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1320 }
1321 #endif
1322
1323 if (FRAME_VISIBLE_P (XFRAME (this))
1324 || FRAME_ICONIFIED_P (XFRAME (this))
1325 /* Allow deleting the terminal frame when at least
1326 one X frame exists! */
1327 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1328 count++;
1329 }
1330 return count > 1;
1331 }
1332 return 1;
1333 }
1334
1335 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1336 doc: /* Delete FRAME, permanently eliminating it from use.
1337 If omitted, FRAME defaults to the selected frame.
1338 A frame may not be deleted if its minibuffer is used by other frames.
1339 Normally, you may not delete a frame if all other frames are invisible,
1340 but if the second optional argument FORCE is non-nil, you may do so.
1341
1342 This function runs `delete-frame-functions' before actually deleting the
1343 frame, unless the frame is a tooltip.
1344 The functions are run with one arg, the frame to be deleted. */)
1345 (frame, force)
1346 Lisp_Object frame, force;
1347 {
1348 struct frame *f;
1349 struct frame *sf = SELECTED_FRAME ();
1350 struct kboard *kb;
1351
1352 int minibuffer_selected;
1353
1354 if (EQ (frame, Qnil))
1355 {
1356 f = sf;
1357 XSETFRAME (frame, f);
1358 }
1359 else
1360 {
1361 CHECK_FRAME (frame);
1362 f = XFRAME (frame);
1363 }
1364
1365 if (! FRAME_LIVE_P (f))
1366 return Qnil;
1367
1368 if (NILP (force) && !other_visible_frames (f)
1369 #ifdef MAC_OS8
1370 /* Terminal frame deleted before any other visible frames are
1371 created. */
1372 && strcmp (SDATA (f->name), "F1") != 0
1373 #endif
1374 )
1375 error ("Attempt to delete the sole visible or iconified frame");
1376
1377 #if 0
1378 /* This is a nice idea, but x_connection_closed needs to be able
1379 to delete the last frame, if it is gone. */
1380 if (NILP (XCDR (Vframe_list)))
1381 error ("Attempt to delete the only frame");
1382 #endif
1383
1384 /* Does this frame have a minibuffer, and is it the surrogate
1385 minibuffer for any other frame? */
1386 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1387 {
1388 Lisp_Object frames;
1389
1390 for (frames = Vframe_list;
1391 CONSP (frames);
1392 frames = XCDR (frames))
1393 {
1394 Lisp_Object this;
1395 this = XCAR (frames);
1396
1397 if (! EQ (this, frame)
1398 && EQ (frame,
1399 WINDOW_FRAME (XWINDOW
1400 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1401 error ("Attempt to delete a surrogate minibuffer frame");
1402 }
1403 }
1404
1405 /* Run `delete-frame-functions' unless frame is a tooltip. */
1406 if (!NILP (Vrun_hooks)
1407 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1408 {
1409 Lisp_Object args[2];
1410 args[0] = intern ("delete-frame-functions");
1411 args[1] = frame;
1412 Frun_hook_with_args (2, args);
1413 }
1414
1415 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1416 if (! FRAME_LIVE_P (f))
1417 return Qnil;
1418
1419 minibuffer_selected = EQ (minibuf_window, selected_window);
1420
1421 /* Don't let the frame remain selected. */
1422 if (f == sf)
1423 {
1424 Lisp_Object tail, frame1;
1425
1426 /* Look for another visible frame on the same terminal. */
1427 frame1 = next_frame (frame, Qvisible);
1428
1429 /* If there is none, find *some* other frame. */
1430 if (NILP (frame1) || EQ (frame1, frame))
1431 {
1432 FOR_EACH_FRAME (tail, frame1)
1433 {
1434 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1435 break;
1436 }
1437 }
1438
1439 do_switch_frame (frame1, 0, 1);
1440 sf = SELECTED_FRAME ();
1441 }
1442
1443 /* Don't allow minibuf_window to remain on a deleted frame. */
1444 if (EQ (f->minibuffer_window, minibuf_window))
1445 {
1446 Fset_window_buffer (sf->minibuffer_window,
1447 XWINDOW (minibuf_window)->buffer, Qnil);
1448 minibuf_window = sf->minibuffer_window;
1449
1450 /* If the dying minibuffer window was selected,
1451 select the new one. */
1452 if (minibuffer_selected)
1453 Fselect_window (minibuf_window, Qnil);
1454 }
1455
1456 /* Don't let echo_area_window to remain on a deleted frame. */
1457 if (EQ (f->minibuffer_window, echo_area_window))
1458 echo_area_window = sf->minibuffer_window;
1459
1460 /* Clear any X selections for this frame. */
1461 #ifdef HAVE_X_WINDOWS
1462 if (FRAME_X_P (f))
1463 x_clear_frame_selections (f);
1464 #endif
1465 #ifdef MAC_OS
1466 if (FRAME_MAC_P (f))
1467 x_clear_frame_selections (f);
1468 #endif
1469
1470 /* Free glyphs.
1471 This function must be called before the window tree of the
1472 frame is deleted because windows contain dynamically allocated
1473 memory. */
1474 free_glyphs (f);
1475
1476 /* Mark all the windows that used to be on FRAME as deleted, and then
1477 remove the reference to them. */
1478 delete_all_subwindows (XWINDOW (f->root_window));
1479 f->root_window = Qnil;
1480
1481 Vframe_list = Fdelq (frame, Vframe_list);
1482 FRAME_SET_VISIBLE (f, 0);
1483
1484 if (f->namebuf)
1485 xfree (f->namebuf);
1486 if (f->decode_mode_spec_buffer)
1487 xfree (f->decode_mode_spec_buffer);
1488 if (FRAME_INSERT_COST (f))
1489 xfree (FRAME_INSERT_COST (f));
1490 if (FRAME_DELETEN_COST (f))
1491 xfree (FRAME_DELETEN_COST (f));
1492 if (FRAME_INSERTN_COST (f))
1493 xfree (FRAME_INSERTN_COST (f));
1494 if (FRAME_DELETE_COST (f))
1495 xfree (FRAME_DELETE_COST (f));
1496 if (FRAME_MESSAGE_BUF (f))
1497 xfree (FRAME_MESSAGE_BUF (f));
1498
1499 /* Since some events are handled at the interrupt level, we may get
1500 an event for f at any time; if we zero out the frame's display
1501 now, then we may trip up the event-handling code. Instead, we'll
1502 promise that the display of the frame must be valid until we have
1503 called the window-system-dependent frame destruction routine. */
1504
1505 if (FRAME_DEVICE (f)->delete_frame_hook)
1506 (*FRAME_DEVICE (f)->delete_frame_hook) (f);
1507
1508 {
1509 struct device *device = FRAME_DEVICE (f);
1510 f->output_data.nothing = 0;
1511 f->device = 0; /* Now the frame is dead. */
1512
1513 /* If needed, delete the device that this frame was on.
1514 (This must be done after the frame is killed.) */
1515 device->reference_count--;
1516 if (device->reference_count == 0)
1517 {
1518 kb = NULL;
1519 if (device->delete_device_hook)
1520 (*device->delete_device_hook) (device);
1521 else
1522 delete_device (device);
1523 }
1524 else
1525 kb = device->kboard;
1526 }
1527
1528 /* If we've deleted the last_nonminibuf_frame, then try to find
1529 another one. */
1530 if (f == last_nonminibuf_frame)
1531 {
1532 Lisp_Object frames;
1533
1534 last_nonminibuf_frame = 0;
1535
1536 for (frames = Vframe_list;
1537 CONSP (frames);
1538 frames = XCDR (frames))
1539 {
1540 f = XFRAME (XCAR (frames));
1541 if (!FRAME_MINIBUF_ONLY_P (f))
1542 {
1543 last_nonminibuf_frame = f;
1544 break;
1545 }
1546 }
1547 }
1548
1549 /* If there's no other frame on the same kboard, get out of
1550 single-kboard state if we're in it for this kboard. */
1551 if (kb != NULL)
1552 {
1553 Lisp_Object frames;
1554 /* Some frame we found on the same kboard, or nil if there are none. */
1555 Lisp_Object frame_on_same_kboard;
1556
1557 frame_on_same_kboard = Qnil;
1558
1559 for (frames = Vframe_list;
1560 CONSP (frames);
1561 frames = XCDR (frames))
1562 {
1563 Lisp_Object this;
1564 struct frame *f1;
1565
1566 this = XCAR (frames);
1567 if (!FRAMEP (this))
1568 abort ();
1569 f1 = XFRAME (this);
1570
1571 if (kb == FRAME_KBOARD (f1))
1572 frame_on_same_kboard = this;
1573 }
1574
1575 if (NILP (frame_on_same_kboard))
1576 not_single_kboard_state (kb);
1577 }
1578
1579
1580 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1581 find another one. Prefer minibuffer-only frames, but also notice
1582 frames with other windows. */
1583 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1584 {
1585 Lisp_Object frames;
1586
1587 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1588 Lisp_Object frame_with_minibuf;
1589 /* Some frame we found on the same kboard, or nil if there are none. */
1590 Lisp_Object frame_on_same_kboard;
1591
1592 frame_on_same_kboard = Qnil;
1593 frame_with_minibuf = Qnil;
1594
1595 for (frames = Vframe_list;
1596 CONSP (frames);
1597 frames = XCDR (frames))
1598 {
1599 Lisp_Object this;
1600 struct frame *f1;
1601
1602 this = XCAR (frames);
1603 if (!FRAMEP (this))
1604 abort ();
1605 f1 = XFRAME (this);
1606
1607 /* Consider only frames on the same kboard
1608 and only those with minibuffers. */
1609 if (kb == FRAME_KBOARD (f1)
1610 && FRAME_HAS_MINIBUF_P (f1))
1611 {
1612 frame_with_minibuf = this;
1613 if (FRAME_MINIBUF_ONLY_P (f1))
1614 break;
1615 }
1616
1617 if (kb == FRAME_KBOARD (f1))
1618 frame_on_same_kboard = this;
1619 }
1620
1621 if (!NILP (frame_on_same_kboard))
1622 {
1623 /* We know that there must be some frame with a minibuffer out
1624 there. If this were not true, all of the frames present
1625 would have to be minibufferless, which implies that at some
1626 point their minibuffer frames must have been deleted, but
1627 that is prohibited at the top; you can't delete surrogate
1628 minibuffer frames. */
1629 if (NILP (frame_with_minibuf))
1630 abort ();
1631
1632 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1633 }
1634 else
1635 /* No frames left on this kboard--say no minibuffer either. */
1636 kb->Vdefault_minibuffer_frame = Qnil;
1637 }
1638
1639 /* Cause frame titles to update--necessary if we now have just one frame. */
1640 update_mode_lines = 1;
1641
1642 return Qnil;
1643 }
1644 \f
1645 /* Return mouse position in character cell units. */
1646
1647 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1648 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1649 The position is given in character cells, where (0, 0) is the
1650 upper-left corner.
1651 If Emacs is running on a mouseless terminal or hasn't been programmed
1652 to read the mouse position, it returns the selected frame for FRAME
1653 and nil for X and Y.
1654 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1655 passing the normal return value to that function as an argument,
1656 and returns whatever that function returns. */)
1657 ()
1658 {
1659 FRAME_PTR f;
1660 Lisp_Object lispy_dummy;
1661 enum scroll_bar_part party_dummy;
1662 Lisp_Object x, y, retval;
1663 int col, row;
1664 unsigned long long_dummy;
1665 struct gcpro gcpro1;
1666
1667 f = SELECTED_FRAME ();
1668 x = y = Qnil;
1669
1670 #ifdef HAVE_MOUSE
1671 /* It's okay for the hook to refrain from storing anything. */
1672 if (FRAME_DEVICE (f)->mouse_position_hook)
1673 (*FRAME_DEVICE (f)->mouse_position_hook) (&f, -1,
1674 &lispy_dummy, &party_dummy,
1675 &x, &y,
1676 &long_dummy);
1677 if (! NILP (x))
1678 {
1679 col = XINT (x);
1680 row = XINT (y);
1681 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1682 XSETINT (x, col);
1683 XSETINT (y, row);
1684 }
1685 #endif
1686 XSETFRAME (lispy_dummy, f);
1687 retval = Fcons (lispy_dummy, Fcons (x, y));
1688 GCPRO1 (retval);
1689 if (!NILP (Vmouse_position_function))
1690 retval = call1 (Vmouse_position_function, retval);
1691 RETURN_UNGCPRO (retval);
1692 }
1693
1694 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1695 Smouse_pixel_position, 0, 0, 0,
1696 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1697 The position is given in pixel units, where (0, 0) is the
1698 upper-left corner.
1699 If Emacs is running on a mouseless terminal or hasn't been programmed
1700 to read the mouse position, it returns the selected frame for FRAME
1701 and nil for X and Y. */)
1702 ()
1703 {
1704 FRAME_PTR f;
1705 Lisp_Object lispy_dummy;
1706 enum scroll_bar_part party_dummy;
1707 Lisp_Object x, y;
1708 unsigned long long_dummy;
1709
1710 f = SELECTED_FRAME ();
1711 x = y = Qnil;
1712
1713 #ifdef HAVE_MOUSE
1714 /* It's okay for the hook to refrain from storing anything. */
1715 if (FRAME_DEVICE (f)->mouse_position_hook)
1716 (*FRAME_DEVICE (f)->mouse_position_hook) (&f, -1,
1717 &lispy_dummy, &party_dummy,
1718 &x, &y,
1719 &long_dummy);
1720 #endif
1721 XSETFRAME (lispy_dummy, f);
1722 return Fcons (lispy_dummy, Fcons (x, y));
1723 }
1724
1725 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1726 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1727 Coordinates are relative to the frame, not a window,
1728 so the coordinates of the top left character in the frame
1729 may be nonzero due to left-hand scroll bars or the menu bar.
1730
1731 This function is a no-op for an X frame that is not visible.
1732 If you have just created a frame, you must wait for it to become visible
1733 before calling this function on it, like this.
1734 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1735 (frame, x, y)
1736 Lisp_Object frame, x, y;
1737 {
1738 CHECK_LIVE_FRAME (frame);
1739 CHECK_NUMBER (x);
1740 CHECK_NUMBER (y);
1741
1742 /* I think this should be done with a hook. */
1743 #ifdef HAVE_WINDOW_SYSTEM
1744 if (FRAME_WINDOW_P (XFRAME (frame)))
1745 /* Warping the mouse will cause enternotify and focus events. */
1746 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1747 #else
1748 #if defined (MSDOS) && defined (HAVE_MOUSE)
1749 if (FRAME_MSDOS_P (XFRAME (frame)))
1750 {
1751 Fselect_frame (frame);
1752 mouse_moveto (XINT (x), XINT (y));
1753 }
1754 #endif
1755 #endif
1756
1757 return Qnil;
1758 }
1759
1760 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1761 Sset_mouse_pixel_position, 3, 3, 0,
1762 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1763 Note, this is a no-op for an X frame that is not visible.
1764 If you have just created a frame, you must wait for it to become visible
1765 before calling this function on it, like this.
1766 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1767 (frame, x, y)
1768 Lisp_Object frame, x, y;
1769 {
1770 CHECK_LIVE_FRAME (frame);
1771 CHECK_NUMBER (x);
1772 CHECK_NUMBER (y);
1773
1774 /* I think this should be done with a hook. */
1775 #ifdef HAVE_WINDOW_SYSTEM
1776 if (FRAME_WINDOW_P (XFRAME (frame)))
1777 /* Warping the mouse will cause enternotify and focus events. */
1778 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1779 #else
1780 #if defined (MSDOS) && defined (HAVE_MOUSE)
1781 if (FRAME_MSDOS_P (XFRAME (frame)))
1782 {
1783 Fselect_frame (frame);
1784 mouse_moveto (XINT (x), XINT (y));
1785 }
1786 #endif
1787 #endif
1788
1789 return Qnil;
1790 }
1791 \f
1792 static void make_frame_visible_1 P_ ((Lisp_Object));
1793
1794 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1795 0, 1, "",
1796 doc: /* Make the frame FRAME visible (assuming it is an X window).
1797 If omitted, FRAME defaults to the currently selected frame. */)
1798 (frame)
1799 Lisp_Object frame;
1800 {
1801 if (NILP (frame))
1802 frame = selected_frame;
1803
1804 CHECK_LIVE_FRAME (frame);
1805
1806 /* I think this should be done with a hook. */
1807 #ifdef HAVE_WINDOW_SYSTEM
1808 if (FRAME_WINDOW_P (XFRAME (frame)))
1809 {
1810 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1811 x_make_frame_visible (XFRAME (frame));
1812 }
1813 #endif
1814
1815 make_frame_visible_1 (XFRAME (frame)->root_window);
1816
1817 /* Make menu bar update for the Buffers and Frames menus. */
1818 windows_or_buffers_changed++;
1819
1820 return frame;
1821 }
1822
1823 /* Update the display_time slot of the buffers shown in WINDOW
1824 and all its descendents. */
1825
1826 static void
1827 make_frame_visible_1 (window)
1828 Lisp_Object window;
1829 {
1830 struct window *w;
1831
1832 for (;!NILP (window); window = w->next)
1833 {
1834 w = XWINDOW (window);
1835
1836 if (!NILP (w->buffer))
1837 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1838
1839 if (!NILP (w->vchild))
1840 make_frame_visible_1 (w->vchild);
1841 if (!NILP (w->hchild))
1842 make_frame_visible_1 (w->hchild);
1843 }
1844 }
1845
1846 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1847 0, 2, "",
1848 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1849 If omitted, FRAME defaults to the currently selected frame.
1850 Normally you may not make FRAME invisible if all other frames are invisible,
1851 but if the second optional argument FORCE is non-nil, you may do so. */)
1852 (frame, force)
1853 Lisp_Object frame, force;
1854 {
1855 if (NILP (frame))
1856 frame = selected_frame;
1857
1858 CHECK_LIVE_FRAME (frame);
1859
1860 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1861 error ("Attempt to make invisible the sole visible or iconified frame");
1862
1863 #if 0 /* This isn't logically necessary, and it can do GC. */
1864 /* Don't let the frame remain selected. */
1865 if (EQ (frame, selected_frame))
1866 do_switch_frame (next_frame (frame, Qt), 0, 0)
1867 #endif
1868
1869 /* Don't allow minibuf_window to remain on a deleted frame. */
1870 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1871 {
1872 struct frame *sf = XFRAME (selected_frame);
1873 Fset_window_buffer (sf->minibuffer_window,
1874 XWINDOW (minibuf_window)->buffer, Qnil);
1875 minibuf_window = sf->minibuffer_window;
1876 }
1877
1878 /* I think this should be done with a hook. */
1879 #ifdef HAVE_WINDOW_SYSTEM
1880 if (FRAME_WINDOW_P (XFRAME (frame)))
1881 x_make_frame_invisible (XFRAME (frame));
1882 #endif
1883
1884 /* Make menu bar update for the Buffers and Frames menus. */
1885 windows_or_buffers_changed++;
1886
1887 return Qnil;
1888 }
1889
1890 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1891 0, 1, "",
1892 doc: /* Make the frame FRAME into an icon.
1893 If omitted, FRAME defaults to the currently selected frame. */)
1894 (frame)
1895 Lisp_Object frame;
1896 {
1897 if (NILP (frame))
1898 frame = selected_frame;
1899
1900 CHECK_LIVE_FRAME (frame);
1901
1902 #if 0 /* This isn't logically necessary, and it can do GC. */
1903 /* Don't let the frame remain selected. */
1904 if (EQ (frame, selected_frame))
1905 Fhandle_switch_frame (next_frame (frame, Qt));
1906 #endif
1907
1908 /* Don't allow minibuf_window to remain on a deleted frame. */
1909 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1910 {
1911 struct frame *sf = XFRAME (selected_frame);
1912 Fset_window_buffer (sf->minibuffer_window,
1913 XWINDOW (minibuf_window)->buffer, Qnil);
1914 minibuf_window = sf->minibuffer_window;
1915 }
1916
1917 /* I think this should be done with a hook. */
1918 #ifdef HAVE_WINDOW_SYSTEM
1919 if (FRAME_WINDOW_P (XFRAME (frame)))
1920 x_iconify_frame (XFRAME (frame));
1921 #endif
1922
1923 /* Make menu bar update for the Buffers and Frames menus. */
1924 windows_or_buffers_changed++;
1925
1926 return Qnil;
1927 }
1928
1929 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1930 1, 1, 0,
1931 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1932 A frame that is not \"visible\" is not updated and, if it works through
1933 a window system, it may not show at all.
1934 Return the symbol `icon' if frame is visible only as an icon.
1935
1936 On a text-only terminal, all frames are considered visible, whether
1937 they are currently being displayed or not, and this function returns t
1938 for all frames. */)
1939 (frame)
1940 Lisp_Object frame;
1941 {
1942 CHECK_LIVE_FRAME (frame);
1943
1944 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1945
1946 if (FRAME_VISIBLE_P (XFRAME (frame)))
1947 return Qt;
1948 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1949 return Qicon;
1950 return Qnil;
1951 }
1952
1953 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1954 0, 0, 0,
1955 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1956 ()
1957 {
1958 Lisp_Object tail, frame;
1959 struct frame *f;
1960 Lisp_Object value;
1961
1962 value = Qnil;
1963 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1964 {
1965 frame = XCAR (tail);
1966 if (!FRAMEP (frame))
1967 continue;
1968 f = XFRAME (frame);
1969 if (FRAME_VISIBLE_P (f))
1970 value = Fcons (frame, value);
1971 }
1972 return value;
1973 }
1974
1975
1976 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1977 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1978 If FRAME is invisible or iconified, make it visible.
1979 If you don't specify a frame, the selected frame is used.
1980 If Emacs is displaying on an ordinary terminal or some other device which
1981 doesn't support multiple overlapping frames, this function does nothing. */)
1982 (frame)
1983 Lisp_Object frame;
1984 {
1985 struct frame *f;
1986 if (NILP (frame))
1987 frame = selected_frame;
1988
1989 CHECK_LIVE_FRAME (frame);
1990
1991 f = XFRAME (frame);
1992
1993 /* Do like the documentation says. */
1994 Fmake_frame_visible (frame);
1995
1996 if (FRAME_DEVICE (f)->frame_raise_lower_hook)
1997 (*FRAME_DEVICE (f)->frame_raise_lower_hook) (f, 1);
1998
1999 return Qnil;
2000 }
2001
2002 /* Should we have a corresponding function called Flower_Power? */
2003 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2004 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2005 If you don't specify a frame, the selected frame is used.
2006 If Emacs is displaying on an ordinary terminal or some other device which
2007 doesn't support multiple overlapping frames, this function does nothing. */)
2008 (frame)
2009 Lisp_Object frame;
2010 {
2011 struct frame *f;
2012
2013 if (NILP (frame))
2014 frame = selected_frame;
2015
2016 CHECK_LIVE_FRAME (frame);
2017
2018 f = XFRAME (frame);
2019
2020 if (FRAME_DEVICE (f)->frame_raise_lower_hook)
2021 (*FRAME_DEVICE (f)->frame_raise_lower_hook) (f, 0);
2022
2023 return Qnil;
2024 }
2025
2026 \f
2027 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2028 1, 2, 0,
2029 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2030 In other words, switch-frame events caused by events in FRAME will
2031 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2032 FOCUS-FRAME after reading an event typed at FRAME.
2033
2034 If FOCUS-FRAME is omitted or nil, any existing redirection is
2035 cancelled, and the frame again receives its own keystrokes.
2036
2037 Focus redirection is useful for temporarily redirecting keystrokes to
2038 a surrogate minibuffer frame when a frame doesn't have its own
2039 minibuffer window.
2040
2041 A frame's focus redirection can be changed by select-frame. If frame
2042 FOO is selected, and then a different frame BAR is selected, any
2043 frames redirecting their focus to FOO are shifted to redirect their
2044 focus to BAR. This allows focus redirection to work properly when the
2045 user switches from one frame to another using `select-window'.
2046
2047 This means that a frame whose focus is redirected to itself is treated
2048 differently from a frame whose focus is redirected to nil; the former
2049 is affected by select-frame, while the latter is not.
2050
2051 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2052 (frame, focus_frame)
2053 Lisp_Object frame, focus_frame;
2054 {
2055 struct frame *f;
2056
2057 /* Note that we don't check for a live frame here. It's reasonable
2058 to redirect the focus of a frame you're about to delete, if you
2059 know what other frame should receive those keystrokes. */
2060 CHECK_FRAME (frame);
2061
2062 if (! NILP (focus_frame))
2063 CHECK_LIVE_FRAME (focus_frame);
2064
2065 f = XFRAME (frame);
2066
2067 f->focus_frame = focus_frame;
2068
2069 if (FRAME_DEVICE (f)->frame_rehighlight_hook)
2070 (*FRAME_DEVICE (f)->frame_rehighlight_hook) (f);
2071
2072 return Qnil;
2073 }
2074
2075
2076 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2077 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2078 This returns nil if FRAME's focus is not redirected.
2079 See `redirect-frame-focus'. */)
2080 (frame)
2081 Lisp_Object frame;
2082 {
2083 CHECK_LIVE_FRAME (frame);
2084
2085 return FRAME_FOCUS_FRAME (XFRAME (frame));
2086 }
2087
2088
2089 \f
2090 /* Return the value of frame parameter PROP in frame FRAME. */
2091
2092 Lisp_Object
2093 get_frame_param (frame, prop)
2094 register struct frame *frame;
2095 Lisp_Object prop;
2096 {
2097 register Lisp_Object tem;
2098
2099 tem = Fassq (prop, frame->param_alist);
2100 if (EQ (tem, Qnil))
2101 return tem;
2102 return Fcdr (tem);
2103 }
2104
2105 /* Return the buffer-predicate of the selected frame. */
2106
2107 Lisp_Object
2108 frame_buffer_predicate (frame)
2109 Lisp_Object frame;
2110 {
2111 return XFRAME (frame)->buffer_predicate;
2112 }
2113
2114 /* Return the buffer-list of the selected frame. */
2115
2116 Lisp_Object
2117 frame_buffer_list (frame)
2118 Lisp_Object frame;
2119 {
2120 return XFRAME (frame)->buffer_list;
2121 }
2122
2123 /* Set the buffer-list of the selected frame. */
2124
2125 void
2126 set_frame_buffer_list (frame, list)
2127 Lisp_Object frame, list;
2128 {
2129 XFRAME (frame)->buffer_list = list;
2130 }
2131
2132 /* Discard BUFFER from the buffer-list of each frame. */
2133
2134 void
2135 frames_discard_buffer (buffer)
2136 Lisp_Object buffer;
2137 {
2138 Lisp_Object frame, tail;
2139
2140 FOR_EACH_FRAME (tail, frame)
2141 {
2142 XFRAME (frame)->buffer_list
2143 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2144 }
2145 }
2146
2147 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2148 If the alist already has an element for PROP, we change it. */
2149
2150 void
2151 store_in_alist (alistptr, prop, val)
2152 Lisp_Object *alistptr, val;
2153 Lisp_Object prop;
2154 {
2155 register Lisp_Object tem;
2156
2157 tem = Fassq (prop, *alistptr);
2158 if (EQ (tem, Qnil))
2159 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2160 else
2161 Fsetcdr (tem, val);
2162 }
2163
2164 static int
2165 frame_name_fnn_p (str, len)
2166 char *str;
2167 int len;
2168 {
2169 if (len > 1 && str[0] == 'F')
2170 {
2171 char *end_ptr;
2172
2173 strtol (str + 1, &end_ptr, 10);
2174
2175 if (end_ptr == str + len)
2176 return 1;
2177 }
2178 return 0;
2179 }
2180
2181 /* Set the name of the terminal frame. Also used by MSDOS frames.
2182 Modeled after x_set_name which is used for WINDOW frames. */
2183
2184 void
2185 set_term_frame_name (f, name)
2186 struct frame *f;
2187 Lisp_Object name;
2188 {
2189 f->explicit_name = ! NILP (name);
2190
2191 /* If NAME is nil, set the name to F<num>. */
2192 if (NILP (name))
2193 {
2194 char namebuf[20];
2195
2196 /* Check for no change needed in this very common case
2197 before we do any consing. */
2198 if (frame_name_fnn_p (SDATA (f->name),
2199 SBYTES (f->name)))
2200 return;
2201
2202 terminal_frame_count++;
2203 sprintf (namebuf, "F%d", terminal_frame_count);
2204 name = build_string (namebuf);
2205 }
2206 else
2207 {
2208 CHECK_STRING (name);
2209
2210 /* Don't change the name if it's already NAME. */
2211 if (! NILP (Fstring_equal (name, f->name)))
2212 return;
2213
2214 /* Don't allow the user to set the frame name to F<num>, so it
2215 doesn't clash with the names we generate for terminal frames. */
2216 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2217 error ("Frame names of the form F<num> are usurped by Emacs");
2218 }
2219
2220 f->name = name;
2221 update_mode_lines = 1;
2222 }
2223
2224 void
2225 store_frame_param (f, prop, val)
2226 struct frame *f;
2227 Lisp_Object prop, val;
2228 {
2229 register Lisp_Object old_alist_elt;
2230
2231 /* The buffer-alist parameter is stored in a special place and is
2232 not in the alist. */
2233 if (EQ (prop, Qbuffer_list))
2234 {
2235 f->buffer_list = val;
2236 return;
2237 }
2238
2239 /* If PROP is a symbol which is supposed to have frame-local values,
2240 and it is set up based on this frame, switch to the global
2241 binding. That way, we can create or alter the frame-local binding
2242 without messing up the symbol's status. */
2243 if (SYMBOLP (prop))
2244 {
2245 Lisp_Object valcontents;
2246 valcontents = SYMBOL_VALUE (prop);
2247 if ((BUFFER_LOCAL_VALUEP (valcontents)
2248 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2249 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2250 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2251 swap_in_global_binding (prop);
2252 }
2253
2254 #ifndef WINDOWSNT
2255 /* The tty color mode needs to be set before the frame's parameter
2256 alist is updated with the new value, because set_tty_color_mode
2257 wants to look at the old mode. */
2258 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2259 set_tty_color_mode (f, val);
2260 #endif
2261
2262 /* Update the frame parameter alist. */
2263 old_alist_elt = Fassq (prop, f->param_alist);
2264 if (EQ (old_alist_elt, Qnil))
2265 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2266 else
2267 Fsetcdr (old_alist_elt, val);
2268
2269 /* Update some other special parameters in their special places
2270 in addition to the alist. */
2271
2272 if (EQ (prop, Qbuffer_predicate))
2273 f->buffer_predicate = val;
2274
2275 if (! FRAME_WINDOW_P (f))
2276 {
2277 if (EQ (prop, Qmenu_bar_lines))
2278 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2279 else if (EQ (prop, Qname))
2280 set_term_frame_name (f, val);
2281 }
2282
2283 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2284 {
2285 if (! MINI_WINDOW_P (XWINDOW (val)))
2286 error ("Surrogate minibuffer windows must be minibuffer windows");
2287
2288 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2289 && !EQ (val, f->minibuffer_window))
2290 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2291
2292 /* Install the chosen minibuffer window, with proper buffer. */
2293 f->minibuffer_window = val;
2294 }
2295 }
2296
2297 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2298 doc: /* Return the parameters-alist of frame FRAME.
2299 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2300 The meaningful PARMs depend on the kind of frame.
2301 If FRAME is omitted, return information on the currently selected frame. */)
2302 (frame)
2303 Lisp_Object frame;
2304 {
2305 Lisp_Object alist;
2306 FRAME_PTR f;
2307 int height, width;
2308 struct gcpro gcpro1;
2309
2310 if (NILP (frame))
2311 frame = selected_frame;
2312
2313 CHECK_FRAME (frame);
2314 f = XFRAME (frame);
2315
2316 if (!FRAME_LIVE_P (f))
2317 return Qnil;
2318
2319 alist = Fcopy_alist (f->param_alist);
2320 GCPRO1 (alist);
2321
2322 if (!FRAME_WINDOW_P (f))
2323 {
2324 int fg = FRAME_FOREGROUND_PIXEL (f);
2325 int bg = FRAME_BACKGROUND_PIXEL (f);
2326 Lisp_Object elt;
2327
2328 /* If the frame's parameter alist says the colors are
2329 unspecified and reversed, take the frame's background pixel
2330 for foreground and vice versa. */
2331 elt = Fassq (Qforeground_color, alist);
2332 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2333 {
2334 if (strncmp (SDATA (XCDR (elt)),
2335 unspecified_bg,
2336 SCHARS (XCDR (elt))) == 0)
2337 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2338 else if (strncmp (SDATA (XCDR (elt)),
2339 unspecified_fg,
2340 SCHARS (XCDR (elt))) == 0)
2341 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2342 }
2343 else
2344 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2345 elt = Fassq (Qbackground_color, alist);
2346 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2347 {
2348 if (strncmp (SDATA (XCDR (elt)),
2349 unspecified_fg,
2350 SCHARS (XCDR (elt))) == 0)
2351 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2352 else if (strncmp (SDATA (XCDR (elt)),
2353 unspecified_bg,
2354 SCHARS (XCDR (elt))) == 0)
2355 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2356 }
2357 else
2358 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2359 store_in_alist (&alist, intern ("font"),
2360 build_string (FRAME_MSDOS_P (f)
2361 ? "ms-dos"
2362 : FRAME_W32_P (f) ? "w32term"
2363 :"tty"));
2364 }
2365 store_in_alist (&alist, Qname, f->name);
2366 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2367 store_in_alist (&alist, Qheight, make_number (height));
2368 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2369 store_in_alist (&alist, Qwidth, make_number (width));
2370 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2371 store_in_alist (&alist, Qminibuffer,
2372 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2373 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2374 : FRAME_MINIBUF_WINDOW (f)));
2375 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2376 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2377
2378 /* I think this should be done with a hook. */
2379 #ifdef HAVE_WINDOW_SYSTEM
2380 if (FRAME_WINDOW_P (f))
2381 x_report_frame_params (f, &alist);
2382 else
2383 #endif
2384 {
2385 /* This ought to be correct in f->param_alist for an X frame. */
2386 Lisp_Object lines;
2387 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2388 store_in_alist (&alist, Qmenu_bar_lines, lines);
2389 }
2390
2391 UNGCPRO;
2392 return alist;
2393 }
2394
2395
2396 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2397 doc: /* Return FRAME's value for parameter PARAMETER.
2398 If FRAME is nil, describe the currently selected frame. */)
2399 (frame, parameter)
2400 Lisp_Object frame, parameter;
2401 {
2402 struct frame *f;
2403 Lisp_Object value;
2404
2405 if (NILP (frame))
2406 frame = selected_frame;
2407 else
2408 CHECK_FRAME (frame);
2409 CHECK_SYMBOL (parameter);
2410
2411 f = XFRAME (frame);
2412 value = Qnil;
2413
2414 if (FRAME_LIVE_P (f))
2415 {
2416 /* Avoid consing in frequent cases. */
2417 if (EQ (parameter, Qname))
2418 value = f->name;
2419 #ifdef HAVE_X_WINDOWS
2420 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2421 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2422 #endif /* HAVE_X_WINDOWS */
2423 else if (EQ (parameter, Qbackground_color)
2424 || EQ (parameter, Qforeground_color))
2425 {
2426 value = Fassq (parameter, f->param_alist);
2427 if (CONSP (value))
2428 {
2429 value = XCDR (value);
2430 /* Fframe_parameters puts the actual fg/bg color names,
2431 even if f->param_alist says otherwise. This is
2432 important when param_alist's notion of colors is
2433 "unspecified". We need to do the same here. */
2434 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2435 {
2436 const char *color_name;
2437 EMACS_INT csz;
2438
2439 if (EQ (parameter, Qbackground_color))
2440 {
2441 color_name = SDATA (value);
2442 csz = SCHARS (value);
2443 if (strncmp (color_name, unspecified_bg, csz) == 0)
2444 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2445 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2446 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2447 }
2448 else if (EQ (parameter, Qforeground_color))
2449 {
2450 color_name = SDATA (value);
2451 csz = SCHARS (value);
2452 if (strncmp (color_name, unspecified_fg, csz) == 0)
2453 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2454 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2455 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2456 }
2457 }
2458 }
2459 else
2460 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2461 }
2462 else if (EQ (parameter, Qdisplay_type)
2463 || EQ (parameter, Qbackground_mode))
2464 value = Fcdr (Fassq (parameter, f->param_alist));
2465 else
2466 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2467 }
2468
2469 return value;
2470 }
2471
2472
2473 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2474 Smodify_frame_parameters, 2, 2, 0,
2475 doc: /* Modify the parameters of frame FRAME according to ALIST.
2476 If FRAME is nil, it defaults to the selected frame.
2477 ALIST is an alist of parameters to change and their new values.
2478 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2479 The meaningful PARMs depend on the kind of frame.
2480 Undefined PARMs are ignored, but stored in the frame's parameter list
2481 so that `frame-parameters' will return them.
2482
2483 The value of frame parameter FOO can also be accessed
2484 as a frame-local binding for the variable FOO, if you have
2485 enabled such bindings for that variable with `make-variable-frame-local'. */)
2486 (frame, alist)
2487 Lisp_Object frame, alist;
2488 {
2489 FRAME_PTR f;
2490 register Lisp_Object tail, prop, val;
2491 int count = SPECPDL_INDEX ();
2492
2493 /* Bind this to t to inhibit initialization of the default face from
2494 X resources in face-set-after-frame-default. If we don't inhibit
2495 this, modifying the `font' frame parameter, for example, while
2496 there is a `default.attributeFont' X resource, won't work,
2497 because `default's font is reset to the value of the X resource
2498 and that resets the `font' frame parameter. */
2499 specbind (Qinhibit_default_face_x_resources, Qt);
2500
2501 if (EQ (frame, Qnil))
2502 frame = selected_frame;
2503 CHECK_LIVE_FRAME (frame);
2504 f = XFRAME (frame);
2505
2506 /* I think this should be done with a hook. */
2507 #ifdef HAVE_WINDOW_SYSTEM
2508 if (FRAME_WINDOW_P (f))
2509 x_set_frame_parameters (f, alist);
2510 else
2511 #endif
2512 #ifdef MSDOS
2513 if (FRAME_MSDOS_P (f))
2514 IT_set_frame_parameters (f, alist);
2515 else
2516 #endif
2517
2518 {
2519 int length = XINT (Flength (alist));
2520 int i;
2521 Lisp_Object *parms
2522 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2523 Lisp_Object *values
2524 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2525
2526 /* Extract parm names and values into those vectors. */
2527
2528 i = 0;
2529 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2530 {
2531 Lisp_Object elt;
2532
2533 elt = Fcar (tail);
2534 parms[i] = Fcar (elt);
2535 values[i] = Fcdr (elt);
2536 i++;
2537 }
2538
2539 /* Now process them in reverse of specified order. */
2540 for (i--; i >= 0; i--)
2541 {
2542 prop = parms[i];
2543 val = values[i];
2544 store_frame_param (f, prop, val);
2545
2546 /* Changing the background color might change the background
2547 mode, so that we have to load new defface specs.
2548 Call frame-set-background-mode to do that. */
2549 if (EQ (prop, Qbackground_color))
2550 call1 (Qframe_set_background_mode, frame);
2551 }
2552 }
2553
2554 return unbind_to (count, Qnil);
2555 }
2556 \f
2557 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2558 0, 1, 0,
2559 doc: /* Height in pixels of a line in the font in frame FRAME.
2560 If FRAME is omitted, the selected frame is used.
2561 For a terminal frame, the value is always 1. */)
2562 (frame)
2563 Lisp_Object frame;
2564 {
2565 struct frame *f;
2566
2567 if (NILP (frame))
2568 frame = selected_frame;
2569 CHECK_FRAME (frame);
2570 f = XFRAME (frame);
2571
2572 #ifdef HAVE_WINDOW_SYSTEM
2573 if (FRAME_WINDOW_P (f))
2574 return make_number (x_char_height (f));
2575 else
2576 #endif
2577 return make_number (1);
2578 }
2579
2580
2581 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2582 0, 1, 0,
2583 doc: /* Width in pixels of characters in the font in frame FRAME.
2584 If FRAME is omitted, the selected frame is used.
2585 On a graphical screen, the width is the standard width of the default font.
2586 For a terminal screen, the value is always 1. */)
2587 (frame)
2588 Lisp_Object frame;
2589 {
2590 struct frame *f;
2591
2592 if (NILP (frame))
2593 frame = selected_frame;
2594 CHECK_FRAME (frame);
2595 f = XFRAME (frame);
2596
2597 #ifdef HAVE_WINDOW_SYSTEM
2598 if (FRAME_WINDOW_P (f))
2599 return make_number (x_char_width (f));
2600 else
2601 #endif
2602 return make_number (1);
2603 }
2604
2605 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2606 Sframe_pixel_height, 0, 1, 0,
2607 doc: /* Return a FRAME's height in pixels.
2608 This counts only the height available for text lines,
2609 not menu bars on window-system Emacs frames.
2610 For a terminal frame, the result really gives the height in characters.
2611 If FRAME is omitted, the selected frame is used. */)
2612 (frame)
2613 Lisp_Object frame;
2614 {
2615 struct frame *f;
2616
2617 if (NILP (frame))
2618 frame = selected_frame;
2619 CHECK_FRAME (frame);
2620 f = XFRAME (frame);
2621
2622 #ifdef HAVE_WINDOW_SYSTEM
2623 if (FRAME_WINDOW_P (f))
2624 return make_number (x_pixel_height (f));
2625 else
2626 #endif
2627 return make_number (FRAME_LINES (f));
2628 }
2629
2630 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2631 Sframe_pixel_width, 0, 1, 0,
2632 doc: /* Return FRAME's width in pixels.
2633 For a terminal frame, the result really gives the width in characters.
2634 If FRAME is omitted, the selected frame is used. */)
2635 (frame)
2636 Lisp_Object frame;
2637 {
2638 struct frame *f;
2639
2640 if (NILP (frame))
2641 frame = selected_frame;
2642 CHECK_FRAME (frame);
2643 f = XFRAME (frame);
2644
2645 #ifdef HAVE_WINDOW_SYSTEM
2646 if (FRAME_WINDOW_P (f))
2647 return make_number (x_pixel_width (f));
2648 else
2649 #endif
2650 return make_number (FRAME_COLS (f));
2651 }
2652 \f
2653 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2654 doc: /* Specify that the frame FRAME has LINES lines.
2655 Optional third arg non-nil means that redisplay should use LINES lines
2656 but that the idea of the actual height of the frame should not be changed. */)
2657 (frame, lines, pretend)
2658 Lisp_Object frame, lines, pretend;
2659 {
2660 register struct frame *f;
2661
2662 CHECK_NUMBER (lines);
2663 if (NILP (frame))
2664 frame = selected_frame;
2665 CHECK_LIVE_FRAME (frame);
2666 f = XFRAME (frame);
2667
2668 /* I think this should be done with a hook. */
2669 #ifdef HAVE_WINDOW_SYSTEM
2670 if (FRAME_WINDOW_P (f))
2671 {
2672 if (XINT (lines) != FRAME_LINES (f))
2673 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2674 do_pending_window_change (0);
2675 }
2676 else
2677 #endif
2678 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2679 return Qnil;
2680 }
2681
2682 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2683 doc: /* Specify that the frame FRAME has COLS columns.
2684 Optional third arg non-nil means that redisplay should use COLS columns
2685 but that the idea of the actual width of the frame should not be changed. */)
2686 (frame, cols, pretend)
2687 Lisp_Object frame, cols, pretend;
2688 {
2689 register struct frame *f;
2690 CHECK_NUMBER (cols);
2691 if (NILP (frame))
2692 frame = selected_frame;
2693 CHECK_LIVE_FRAME (frame);
2694 f = XFRAME (frame);
2695
2696 /* I think this should be done with a hook. */
2697 #ifdef HAVE_WINDOW_SYSTEM
2698 if (FRAME_WINDOW_P (f))
2699 {
2700 if (XINT (cols) != FRAME_COLS (f))
2701 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2702 do_pending_window_change (0);
2703 }
2704 else
2705 #endif
2706 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2707 return Qnil;
2708 }
2709
2710 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2711 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2712 (frame, cols, rows)
2713 Lisp_Object frame, cols, rows;
2714 {
2715 register struct frame *f;
2716
2717 CHECK_LIVE_FRAME (frame);
2718 CHECK_NUMBER (cols);
2719 CHECK_NUMBER (rows);
2720 f = XFRAME (frame);
2721
2722 /* I think this should be done with a hook. */
2723 #ifdef HAVE_WINDOW_SYSTEM
2724 if (FRAME_WINDOW_P (f))
2725 {
2726 if (XINT (rows) != FRAME_LINES (f)
2727 || XINT (cols) != FRAME_COLS (f)
2728 || f->new_text_lines || f->new_text_cols)
2729 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2730 do_pending_window_change (0);
2731 }
2732 else
2733 #endif
2734 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2735
2736 return Qnil;
2737 }
2738
2739 DEFUN ("set-frame-position", Fset_frame_position,
2740 Sset_frame_position, 3, 3, 0,
2741 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2742 This is actually the position of the upper left corner of the frame.
2743 Negative values for XOFFSET or YOFFSET are interpreted relative to
2744 the rightmost or bottommost possible position (that stays within the screen). */)
2745 (frame, xoffset, yoffset)
2746 Lisp_Object frame, xoffset, yoffset;
2747 {
2748 register struct frame *f;
2749
2750 CHECK_LIVE_FRAME (frame);
2751 CHECK_NUMBER (xoffset);
2752 CHECK_NUMBER (yoffset);
2753 f = XFRAME (frame);
2754
2755 /* I think this should be done with a hook. */
2756 #ifdef HAVE_WINDOW_SYSTEM
2757 if (FRAME_WINDOW_P (f))
2758 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2759 #endif
2760
2761 return Qt;
2762 }
2763
2764 \f
2765 /***********************************************************************
2766 Frame Parameters
2767 ***********************************************************************/
2768
2769 /* Connect the frame-parameter names for X frames
2770 to the ways of passing the parameter values to the window system.
2771
2772 The name of a parameter, as a Lisp symbol,
2773 has an `x-frame-parameter' property which is an integer in Lisp
2774 that is an index in this table. */
2775
2776 struct frame_parm_table {
2777 char *name;
2778 Lisp_Object *variable;
2779 };
2780
2781 static struct frame_parm_table frame_parms[] =
2782 {
2783 {"auto-raise", &Qauto_raise},
2784 {"auto-lower", &Qauto_lower},
2785 {"background-color", 0},
2786 {"border-color", &Qborder_color},
2787 {"border-width", &Qborder_width},
2788 {"cursor-color", &Qcursor_color},
2789 {"cursor-type", &Qcursor_type},
2790 {"font", 0},
2791 {"foreground-color", 0},
2792 {"icon-name", &Qicon_name},
2793 {"icon-type", &Qicon_type},
2794 {"internal-border-width", &Qinternal_border_width},
2795 {"menu-bar-lines", &Qmenu_bar_lines},
2796 {"mouse-color", &Qmouse_color},
2797 {"name", &Qname},
2798 {"scroll-bar-width", &Qscroll_bar_width},
2799 {"title", &Qtitle},
2800 {"unsplittable", &Qunsplittable},
2801 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2802 {"visibility", &Qvisibility},
2803 {"tool-bar-lines", &Qtool_bar_lines},
2804 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2805 {"scroll-bar-background", &Qscroll_bar_background},
2806 {"screen-gamma", &Qscreen_gamma},
2807 {"line-spacing", &Qline_spacing},
2808 {"left-fringe", &Qleft_fringe},
2809 {"right-fringe", &Qright_fringe},
2810 {"wait-for-wm", &Qwait_for_wm},
2811 {"fullscreen", &Qfullscreen},
2812 };
2813
2814 #ifdef HAVE_WINDOW_SYSTEM
2815
2816 extern Lisp_Object Qbox;
2817 extern Lisp_Object Qtop;
2818
2819 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2820 wanted positions of the WM window (not emacs window).
2821 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2822 window (FRAME_X_WINDOW).
2823 */
2824
2825 void
2826 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2827 struct frame *f;
2828 int *width;
2829 int *height;
2830 int *top_pos;
2831 int *left_pos;
2832 {
2833 int newwidth = FRAME_COLS (f);
2834 int newheight = FRAME_LINES (f);
2835
2836 *top_pos = f->top_pos;
2837 *left_pos = f->left_pos;
2838
2839 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2840 {
2841 int ph;
2842
2843 ph = FRAME_X_DISPLAY_INFO (f)->height;
2844 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2845 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2846 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2847 *top_pos = 0;
2848 }
2849
2850 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2851 {
2852 int pw;
2853
2854 pw = FRAME_X_DISPLAY_INFO (f)->width;
2855 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2856 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2857 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2858 *left_pos = 0;
2859 }
2860
2861 *width = newwidth;
2862 *height = newheight;
2863 }
2864
2865
2866 /* Change the parameters of frame F as specified by ALIST.
2867 If a parameter is not specially recognized, do nothing special;
2868 otherwise call the `x_set_...' function for that parameter.
2869 Except for certain geometry properties, always call store_frame_param
2870 to store the new value in the parameter alist. */
2871
2872 void
2873 x_set_frame_parameters (f, alist)
2874 FRAME_PTR f;
2875 Lisp_Object alist;
2876 {
2877 Lisp_Object tail;
2878
2879 /* If both of these parameters are present, it's more efficient to
2880 set them both at once. So we wait until we've looked at the
2881 entire list before we set them. */
2882 int width, height;
2883
2884 /* Same here. */
2885 Lisp_Object left, top;
2886
2887 /* Same with these. */
2888 Lisp_Object icon_left, icon_top;
2889
2890 /* Record in these vectors all the parms specified. */
2891 Lisp_Object *parms;
2892 Lisp_Object *values;
2893 int i, p;
2894 int left_no_change = 0, top_no_change = 0;
2895 int icon_left_no_change = 0, icon_top_no_change = 0;
2896 int fullscreen_is_being_set = 0;
2897
2898 struct gcpro gcpro1, gcpro2;
2899
2900 i = 0;
2901 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2902 i++;
2903
2904 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2905 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2906
2907 /* Extract parm names and values into those vectors. */
2908
2909 i = 0;
2910 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2911 {
2912 Lisp_Object elt;
2913
2914 elt = Fcar (tail);
2915 parms[i] = Fcar (elt);
2916 values[i] = Fcdr (elt);
2917 i++;
2918 }
2919 /* TAIL and ALIST are not used again below here. */
2920 alist = tail = Qnil;
2921
2922 GCPRO2 (*parms, *values);
2923 gcpro1.nvars = i;
2924 gcpro2.nvars = i;
2925
2926 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2927 because their values appear in VALUES and strings are not valid. */
2928 top = left = Qunbound;
2929 icon_left = icon_top = Qunbound;
2930
2931 /* Provide default values for HEIGHT and WIDTH. */
2932 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2933 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2934
2935 /* Process foreground_color and background_color before anything else.
2936 They are independent of other properties, but other properties (e.g.,
2937 cursor_color) are dependent upon them. */
2938 /* Process default font as well, since fringe widths depends on it. */
2939 /* Also, process fullscreen, width and height depend upon that */
2940 for (p = 0; p < i; p++)
2941 {
2942 Lisp_Object prop, val;
2943
2944 prop = parms[p];
2945 val = values[p];
2946 if (EQ (prop, Qforeground_color)
2947 || EQ (prop, Qbackground_color)
2948 || EQ (prop, Qfont)
2949 || EQ (prop, Qfullscreen))
2950 {
2951 register Lisp_Object param_index, old_value;
2952
2953 old_value = get_frame_param (f, prop);
2954 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2955
2956 if (NILP (Fequal (val, old_value)))
2957 {
2958 store_frame_param (f, prop, val);
2959
2960 param_index = Fget (prop, Qx_frame_parameter);
2961 if (NATNUMP (param_index)
2962 && (XFASTINT (param_index)
2963 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2964 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2965 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2966 }
2967 }
2968 }
2969
2970 /* Now process them in reverse of specified order. */
2971 for (i--; i >= 0; i--)
2972 {
2973 Lisp_Object prop, val;
2974
2975 prop = parms[i];
2976 val = values[i];
2977
2978 if (EQ (prop, Qwidth) && NUMBERP (val))
2979 width = XFASTINT (val);
2980 else if (EQ (prop, Qheight) && NUMBERP (val))
2981 height = XFASTINT (val);
2982 else if (EQ (prop, Qtop))
2983 top = val;
2984 else if (EQ (prop, Qleft))
2985 left = val;
2986 else if (EQ (prop, Qicon_top))
2987 icon_top = val;
2988 else if (EQ (prop, Qicon_left))
2989 icon_left = val;
2990 else if (EQ (prop, Qforeground_color)
2991 || EQ (prop, Qbackground_color)
2992 || EQ (prop, Qfont)
2993 || EQ (prop, Qfullscreen))
2994 /* Processed above. */
2995 continue;
2996 else
2997 {
2998 register Lisp_Object param_index, old_value;
2999
3000 old_value = get_frame_param (f, prop);
3001
3002 store_frame_param (f, prop, val);
3003
3004 param_index = Fget (prop, Qx_frame_parameter);
3005 if (NATNUMP (param_index)
3006 && (XFASTINT (param_index)
3007 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3008 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3009 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3010 }
3011 }
3012
3013 /* Don't die if just one of these was set. */
3014 if (EQ (left, Qunbound))
3015 {
3016 left_no_change = 1;
3017 if (f->left_pos < 0)
3018 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3019 else
3020 XSETINT (left, f->left_pos);
3021 }
3022 if (EQ (top, Qunbound))
3023 {
3024 top_no_change = 1;
3025 if (f->top_pos < 0)
3026 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3027 else
3028 XSETINT (top, f->top_pos);
3029 }
3030
3031 /* If one of the icon positions was not set, preserve or default it. */
3032 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3033 {
3034 icon_left_no_change = 1;
3035 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3036 if (NILP (icon_left))
3037 XSETINT (icon_left, 0);
3038 }
3039 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3040 {
3041 icon_top_no_change = 1;
3042 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3043 if (NILP (icon_top))
3044 XSETINT (icon_top, 0);
3045 }
3046
3047 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
3048 {
3049 /* If the frame is visible already and the fullscreen parameter is
3050 being set, it is too late to set WM manager hints to specify
3051 size and position.
3052 Here we first get the width, height and position that applies to
3053 fullscreen. We then move the frame to the appropriate
3054 position. Resize of the frame is taken care of in the code after
3055 this if-statement. */
3056 int new_left, new_top;
3057
3058 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
3059 if (new_top != f->top_pos || new_left != f->left_pos)
3060 x_set_offset (f, new_left, new_top, 1);
3061 }
3062
3063 /* Don't set these parameters unless they've been explicitly
3064 specified. The window might be mapped or resized while we're in
3065 this function, and we don't want to override that unless the lisp
3066 code has asked for it.
3067
3068 Don't set these parameters unless they actually differ from the
3069 window's current parameters; the window may not actually exist
3070 yet. */
3071 {
3072 Lisp_Object frame;
3073
3074 check_frame_size (f, &height, &width);
3075
3076 XSETFRAME (frame, f);
3077
3078 if (width != FRAME_COLS (f)
3079 || height != FRAME_LINES (f)
3080 || f->new_text_lines || f->new_text_cols)
3081 Fset_frame_size (frame, make_number (width), make_number (height));
3082
3083 if ((!NILP (left) || !NILP (top))
3084 && ! (left_no_change && top_no_change)
3085 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3086 && NUMBERP (top) && XINT (top) == f->top_pos))
3087 {
3088 int leftpos = 0;
3089 int toppos = 0;
3090
3091 /* Record the signs. */
3092 f->size_hint_flags &= ~ (XNegative | YNegative);
3093 if (EQ (left, Qminus))
3094 f->size_hint_flags |= XNegative;
3095 else if (INTEGERP (left))
3096 {
3097 leftpos = XINT (left);
3098 if (leftpos < 0)
3099 f->size_hint_flags |= XNegative;
3100 }
3101 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3102 && CONSP (XCDR (left))
3103 && INTEGERP (XCAR (XCDR (left))))
3104 {
3105 leftpos = - XINT (XCAR (XCDR (left)));
3106 f->size_hint_flags |= XNegative;
3107 }
3108 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3109 && CONSP (XCDR (left))
3110 && INTEGERP (XCAR (XCDR (left))))
3111 {
3112 leftpos = XINT (XCAR (XCDR (left)));
3113 }
3114
3115 if (EQ (top, Qminus))
3116 f->size_hint_flags |= YNegative;
3117 else if (INTEGERP (top))
3118 {
3119 toppos = XINT (top);
3120 if (toppos < 0)
3121 f->size_hint_flags |= YNegative;
3122 }
3123 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3124 && CONSP (XCDR (top))
3125 && INTEGERP (XCAR (XCDR (top))))
3126 {
3127 toppos = - XINT (XCAR (XCDR (top)));
3128 f->size_hint_flags |= YNegative;
3129 }
3130 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3131 && CONSP (XCDR (top))
3132 && INTEGERP (XCAR (XCDR (top))))
3133 {
3134 toppos = XINT (XCAR (XCDR (top)));
3135 }
3136
3137
3138 /* Store the numeric value of the position. */
3139 f->top_pos = toppos;
3140 f->left_pos = leftpos;
3141
3142 f->win_gravity = NorthWestGravity;
3143
3144 /* Actually set that position, and convert to absolute. */
3145 x_set_offset (f, leftpos, toppos, -1);
3146 }
3147
3148 if ((!NILP (icon_left) || !NILP (icon_top))
3149 && ! (icon_left_no_change && icon_top_no_change))
3150 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3151 }
3152
3153 UNGCPRO;
3154 }
3155
3156
3157 /* Insert a description of internally-recorded parameters of frame X
3158 into the parameter alist *ALISTPTR that is to be given to the user.
3159 Only parameters that are specific to the X window system
3160 and whose values are not correctly recorded in the frame's
3161 param_alist need to be considered here. */
3162
3163 void
3164 x_report_frame_params (f, alistptr)
3165 struct frame *f;
3166 Lisp_Object *alistptr;
3167 {
3168 char buf[16];
3169 Lisp_Object tem;
3170
3171 /* Represent negative positions (off the top or left screen edge)
3172 in a way that Fmodify_frame_parameters will understand correctly. */
3173 XSETINT (tem, f->left_pos);
3174 if (f->left_pos >= 0)
3175 store_in_alist (alistptr, Qleft, tem);
3176 else
3177 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3178
3179 XSETINT (tem, f->top_pos);
3180 if (f->top_pos >= 0)
3181 store_in_alist (alistptr, Qtop, tem);
3182 else
3183 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3184
3185 store_in_alist (alistptr, Qborder_width,
3186 make_number (f->border_width));
3187 store_in_alist (alistptr, Qinternal_border_width,
3188 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3189 store_in_alist (alistptr, Qleft_fringe,
3190 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3191 store_in_alist (alistptr, Qright_fringe,
3192 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3193 store_in_alist (alistptr, Qscroll_bar_width,
3194 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3195 ? make_number (0)
3196 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3197 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3198 /* nil means "use default width"
3199 for non-toolkit scroll bar.
3200 ruler-mode.el depends on this. */
3201 : Qnil));
3202 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3203 store_in_alist (alistptr, Qwindow_id,
3204 build_string (buf));
3205 #ifdef HAVE_X_WINDOWS
3206 #ifdef USE_X_TOOLKIT
3207 /* Tooltip frame may not have this widget. */
3208 if (FRAME_X_OUTPUT (f)->widget)
3209 #endif
3210 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3211 store_in_alist (alistptr, Qouter_window_id,
3212 build_string (buf));
3213 #endif
3214 store_in_alist (alistptr, Qicon_name, f->icon_name);
3215 FRAME_SAMPLE_VISIBILITY (f);
3216 store_in_alist (alistptr, Qvisibility,
3217 (FRAME_VISIBLE_P (f) ? Qt
3218 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3219 store_in_alist (alistptr, Qdisplay,
3220 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3221
3222 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3223 tem = Qnil;
3224 else
3225 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3226 store_in_alist (alistptr, Qparent_id, tem);
3227 }
3228
3229
3230 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3231 the previous value of that parameter, NEW_VALUE is the new value. */
3232
3233 void
3234 x_set_fullscreen (f, new_value, old_value)
3235 struct frame *f;
3236 Lisp_Object new_value, old_value;
3237 {
3238 if (NILP (new_value))
3239 f->want_fullscreen = FULLSCREEN_NONE;
3240 else if (EQ (new_value, Qfullboth))
3241 f->want_fullscreen = FULLSCREEN_BOTH;
3242 else if (EQ (new_value, Qfullwidth))
3243 f->want_fullscreen = FULLSCREEN_WIDTH;
3244 else if (EQ (new_value, Qfullheight))
3245 f->want_fullscreen = FULLSCREEN_HEIGHT;
3246 }
3247
3248
3249 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3250 the previous value of that parameter, NEW_VALUE is the new value. */
3251
3252 void
3253 x_set_line_spacing (f, new_value, old_value)
3254 struct frame *f;
3255 Lisp_Object new_value, old_value;
3256 {
3257 if (NILP (new_value))
3258 f->extra_line_spacing = 0;
3259 else if (NATNUMP (new_value))
3260 f->extra_line_spacing = XFASTINT (new_value);
3261 else
3262 Fsignal (Qerror, Fcons (build_string ("Invalid line-spacing"),
3263 Fcons (new_value, Qnil)));
3264 if (FRAME_VISIBLE_P (f))
3265 redraw_frame (f);
3266 }
3267
3268
3269 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3270 the previous value of that parameter, NEW_VALUE is the new value. */
3271
3272 void
3273 x_set_screen_gamma (f, new_value, old_value)
3274 struct frame *f;
3275 Lisp_Object new_value, old_value;
3276 {
3277 if (NILP (new_value))
3278 f->gamma = 0;
3279 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3280 /* The value 0.4545 is the normal viewing gamma. */
3281 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3282 else
3283 Fsignal (Qerror, Fcons (build_string ("Invalid screen-gamma"),
3284 Fcons (new_value, Qnil)));
3285
3286 clear_face_cache (0);
3287 }
3288
3289
3290 void
3291 x_set_font (f, arg, oldval)
3292 struct frame *f;
3293 Lisp_Object arg, oldval;
3294 {
3295 Lisp_Object result;
3296 Lisp_Object fontset_name;
3297 Lisp_Object frame;
3298 int old_fontset = FRAME_FONTSET(f);
3299
3300 CHECK_STRING (arg);
3301
3302 fontset_name = Fquery_fontset (arg, Qnil);
3303
3304 BLOCK_INPUT;
3305 result = (STRINGP (fontset_name)
3306 ? x_new_fontset (f, SDATA (fontset_name))
3307 : x_new_font (f, SDATA (arg)));
3308 UNBLOCK_INPUT;
3309
3310 if (EQ (result, Qnil))
3311 error ("Font `%s' is not defined", SDATA (arg));
3312 else if (EQ (result, Qt))
3313 error ("The characters of the given font have varying widths");
3314 else if (STRINGP (result))
3315 {
3316 set_default_ascii_font (result);
3317 if (STRINGP (fontset_name))
3318 {
3319 /* Fontset names are built from ASCII font names, so the
3320 names may be equal despite there was a change. */
3321 if (old_fontset == FRAME_FONTSET (f))
3322 return;
3323 }
3324 else if (!NILP (Fequal (result, oldval)))
3325 return;
3326
3327 store_frame_param (f, Qfont, result);
3328 recompute_basic_faces (f);
3329 }
3330 else
3331 abort ();
3332
3333 do_pending_window_change (0);
3334
3335 /* Don't call `face-set-after-frame-default' when faces haven't been
3336 initialized yet. This is the case when called from
3337 Fx_create_frame. In that case, the X widget or window doesn't
3338 exist either, and we can end up in x_report_frame_params with a
3339 null widget which gives a segfault. */
3340 if (FRAME_FACE_CACHE (f))
3341 {
3342 XSETFRAME (frame, f);
3343 call1 (Qface_set_after_frame_default, frame);
3344 }
3345 }
3346
3347
3348 void
3349 x_set_fringe_width (f, new_value, old_value)
3350 struct frame *f;
3351 Lisp_Object new_value, old_value;
3352 {
3353 compute_fringe_widths (f, 1);
3354 }
3355
3356 void
3357 x_set_border_width (f, arg, oldval)
3358 struct frame *f;
3359 Lisp_Object arg, oldval;
3360 {
3361 CHECK_NUMBER (arg);
3362
3363 if (XINT (arg) == f->border_width)
3364 return;
3365
3366 #ifndef MAC_OS
3367 if (FRAME_X_WINDOW (f) != 0)
3368 error ("Cannot change the border width of a window");
3369 #endif /* MAC_TODO */
3370
3371 f->border_width = XINT (arg);
3372 }
3373
3374 void
3375 x_set_internal_border_width (f, arg, oldval)
3376 struct frame *f;
3377 Lisp_Object arg, oldval;
3378 {
3379 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3380
3381 CHECK_NUMBER (arg);
3382 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3383 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3384 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3385
3386 #ifdef USE_X_TOOLKIT
3387 if (FRAME_X_OUTPUT (f)->edit_widget)
3388 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3389 #endif
3390
3391 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3392 return;
3393
3394 if (FRAME_X_WINDOW (f) != 0)
3395 {
3396 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3397 SET_FRAME_GARBAGED (f);
3398 do_pending_window_change (0);
3399 }
3400 else
3401 SET_FRAME_GARBAGED (f);
3402 }
3403
3404 void
3405 x_set_visibility (f, value, oldval)
3406 struct frame *f;
3407 Lisp_Object value, oldval;
3408 {
3409 Lisp_Object frame;
3410 XSETFRAME (frame, f);
3411
3412 if (NILP (value))
3413 Fmake_frame_invisible (frame, Qt);
3414 else if (EQ (value, Qicon))
3415 Ficonify_frame (frame);
3416 else
3417 Fmake_frame_visible (frame);
3418 }
3419
3420 void
3421 x_set_autoraise (f, arg, oldval)
3422 struct frame *f;
3423 Lisp_Object arg, oldval;
3424 {
3425 f->auto_raise = !EQ (Qnil, arg);
3426 }
3427
3428 void
3429 x_set_autolower (f, arg, oldval)
3430 struct frame *f;
3431 Lisp_Object arg, oldval;
3432 {
3433 f->auto_lower = !EQ (Qnil, arg);
3434 }
3435
3436 void
3437 x_set_unsplittable (f, arg, oldval)
3438 struct frame *f;
3439 Lisp_Object arg, oldval;
3440 {
3441 f->no_split = !NILP (arg);
3442 }
3443
3444 void
3445 x_set_vertical_scroll_bars (f, arg, oldval)
3446 struct frame *f;
3447 Lisp_Object arg, oldval;
3448 {
3449 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3450 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3451 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3452 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3453 {
3454 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3455 = (NILP (arg)
3456 ? vertical_scroll_bar_none
3457 : EQ (Qleft, arg)
3458 ? vertical_scroll_bar_left
3459 : EQ (Qright, arg)
3460 ? vertical_scroll_bar_right
3461 : EQ (Qleft, Vdefault_frame_scroll_bars)
3462 ? vertical_scroll_bar_left
3463 : EQ (Qright, Vdefault_frame_scroll_bars)
3464 ? vertical_scroll_bar_right
3465 : vertical_scroll_bar_none);
3466
3467 /* We set this parameter before creating the X window for the
3468 frame, so we can get the geometry right from the start.
3469 However, if the window hasn't been created yet, we shouldn't
3470 call x_set_window_size. */
3471 if (FRAME_X_WINDOW (f))
3472 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3473 do_pending_window_change (0);
3474 }
3475 }
3476
3477 void
3478 x_set_scroll_bar_width (f, arg, oldval)
3479 struct frame *f;
3480 Lisp_Object arg, oldval;
3481 {
3482 int wid = FRAME_COLUMN_WIDTH (f);
3483
3484 if (NILP (arg))
3485 {
3486 x_set_scroll_bar_default_width (f);
3487
3488 if (FRAME_X_WINDOW (f))
3489 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3490 do_pending_window_change (0);
3491 }
3492 else if (INTEGERP (arg) && XINT (arg) > 0
3493 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3494 {
3495 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3496 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3497
3498 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3499 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3500 if (FRAME_X_WINDOW (f))
3501 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3502 do_pending_window_change (0);
3503 }
3504
3505 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3506 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3507 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3508 }
3509
3510
3511
3512 /* Return non-nil if frame F wants a bitmap icon. */
3513
3514 Lisp_Object
3515 x_icon_type (f)
3516 FRAME_PTR f;
3517 {
3518 Lisp_Object tem;
3519
3520 tem = assq_no_quit (Qicon_type, f->param_alist);
3521 if (CONSP (tem))
3522 return XCDR (tem);
3523 else
3524 return Qnil;
3525 }
3526
3527 \f
3528 /* Subroutines of creating an X frame. */
3529
3530 /* Make sure that Vx_resource_name is set to a reasonable value.
3531 Fix it up, or set it to `emacs' if it is too hopeless. */
3532
3533 void
3534 validate_x_resource_name ()
3535 {
3536 int len = 0;
3537 /* Number of valid characters in the resource name. */
3538 int good_count = 0;
3539 /* Number of invalid characters in the resource name. */
3540 int bad_count = 0;
3541 Lisp_Object new;
3542 int i;
3543
3544 if (!STRINGP (Vx_resource_class))
3545 Vx_resource_class = build_string (EMACS_CLASS);
3546
3547 if (STRINGP (Vx_resource_name))
3548 {
3549 unsigned char *p = SDATA (Vx_resource_name);
3550 int i;
3551
3552 len = SBYTES (Vx_resource_name);
3553
3554 /* Only letters, digits, - and _ are valid in resource names.
3555 Count the valid characters and count the invalid ones. */
3556 for (i = 0; i < len; i++)
3557 {
3558 int c = p[i];
3559 if (! ((c >= 'a' && c <= 'z')
3560 || (c >= 'A' && c <= 'Z')
3561 || (c >= '0' && c <= '9')
3562 || c == '-' || c == '_'))
3563 bad_count++;
3564 else
3565 good_count++;
3566 }
3567 }
3568 else
3569 /* Not a string => completely invalid. */
3570 bad_count = 5, good_count = 0;
3571
3572 /* If name is valid already, return. */
3573 if (bad_count == 0)
3574 return;
3575
3576 /* If name is entirely invalid, or nearly so, use `emacs'. */
3577 if (good_count == 0
3578 || (good_count == 1 && bad_count > 0))
3579 {
3580 Vx_resource_name = build_string ("emacs");
3581 return;
3582 }
3583
3584 /* Name is partly valid. Copy it and replace the invalid characters
3585 with underscores. */
3586
3587 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3588
3589 for (i = 0; i < len; i++)
3590 {
3591 int c = SREF (new, i);
3592 if (! ((c >= 'a' && c <= 'z')
3593 || (c >= 'A' && c <= 'Z')
3594 || (c >= '0' && c <= '9')
3595 || c == '-' || c == '_'))
3596 SSET (new, i, '_');
3597 }
3598 }
3599
3600
3601 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3602 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3603
3604
3605 /* Get specified attribute from resource database RDB.
3606 See Fx_get_resource below for other parameters. */
3607
3608 static Lisp_Object
3609 xrdb_get_resource (rdb, attribute, class, component, subclass)
3610 XrmDatabase rdb;
3611 Lisp_Object attribute, class, component, subclass;
3612 {
3613 register char *value;
3614 char *name_key;
3615 char *class_key;
3616
3617 CHECK_STRING (attribute);
3618 CHECK_STRING (class);
3619
3620 if (!NILP (component))
3621 CHECK_STRING (component);
3622 if (!NILP (subclass))
3623 CHECK_STRING (subclass);
3624 if (NILP (component) != NILP (subclass))
3625 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3626
3627 validate_x_resource_name ();
3628
3629 /* Allocate space for the components, the dots which separate them,
3630 and the final '\0'. Make them big enough for the worst case. */
3631 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3632 + (STRINGP (component)
3633 ? SBYTES (component) : 0)
3634 + SBYTES (attribute)
3635 + 3);
3636
3637 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3638 + SBYTES (class)
3639 + (STRINGP (subclass)
3640 ? SBYTES (subclass) : 0)
3641 + 3);
3642
3643 /* Start with emacs.FRAMENAME for the name (the specific one)
3644 and with `Emacs' for the class key (the general one). */
3645 strcpy (name_key, SDATA (Vx_resource_name));
3646 strcpy (class_key, SDATA (Vx_resource_class));
3647
3648 strcat (class_key, ".");
3649 strcat (class_key, SDATA (class));
3650
3651 if (!NILP (component))
3652 {
3653 strcat (class_key, ".");
3654 strcat (class_key, SDATA (subclass));
3655
3656 strcat (name_key, ".");
3657 strcat (name_key, SDATA (component));
3658 }
3659
3660 strcat (name_key, ".");
3661 strcat (name_key, SDATA (attribute));
3662
3663 value = x_get_string_resource (rdb, name_key, class_key);
3664
3665 if (value != (char *) 0)
3666 return build_string (value);
3667 else
3668 return Qnil;
3669 }
3670
3671
3672 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3673 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3674 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3675 class, where INSTANCE is the name under which Emacs was invoked, or
3676 the name specified by the `-name' or `-rn' command-line arguments.
3677
3678 The optional arguments COMPONENT and SUBCLASS add to the key and the
3679 class, respectively. You must specify both of them or neither.
3680 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3681 and the class is `Emacs.CLASS.SUBCLASS'. */)
3682 (attribute, class, component, subclass)
3683 Lisp_Object attribute, class, component, subclass;
3684 {
3685 #ifdef HAVE_X_WINDOWS
3686 check_x ();
3687 #endif
3688
3689 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3690 attribute, class, component, subclass);
3691 }
3692
3693 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3694
3695 Lisp_Object
3696 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3697 Display_Info *dpyinfo;
3698 Lisp_Object attribute, class, component, subclass;
3699 {
3700 return xrdb_get_resource (dpyinfo->xrdb,
3701 attribute, class, component, subclass);
3702 }
3703
3704 /* Used when C code wants a resource value. */
3705
3706 char *
3707 x_get_resource_string (attribute, class)
3708 char *attribute, *class;
3709 {
3710 char *name_key;
3711 char *class_key;
3712 struct frame *sf = SELECTED_FRAME ();
3713
3714 /* Allocate space for the components, the dots which separate them,
3715 and the final '\0'. */
3716 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3717 + strlen (attribute) + 2);
3718 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3719 + strlen (class) + 2);
3720
3721 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3722 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3723
3724 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3725 name_key, class_key);
3726 }
3727
3728
3729 /* Return the value of parameter PARAM.
3730
3731 First search ALIST, then Vdefault_frame_alist, then the X defaults
3732 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3733
3734 Convert the resource to the type specified by desired_type.
3735
3736 If no default is specified, return Qunbound. If you call
3737 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3738 and don't let it get stored in any Lisp-visible variables! */
3739
3740 Lisp_Object
3741 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3742 Display_Info *dpyinfo;
3743 Lisp_Object alist, param;
3744 char *attribute;
3745 char *class;
3746 enum resource_types type;
3747 {
3748 register Lisp_Object tem;
3749
3750 tem = Fassq (param, alist);
3751 if (EQ (tem, Qnil))
3752 tem = Fassq (param, Vdefault_frame_alist);
3753 if (EQ (tem, Qnil))
3754 {
3755 if (attribute)
3756 {
3757 tem = display_x_get_resource (dpyinfo,
3758 build_string (attribute),
3759 build_string (class),
3760 Qnil, Qnil);
3761
3762 if (NILP (tem))
3763 return Qunbound;
3764
3765 switch (type)
3766 {
3767 case RES_TYPE_NUMBER:
3768 return make_number (atoi (SDATA (tem)));
3769
3770 case RES_TYPE_FLOAT:
3771 return make_float (atof (SDATA (tem)));
3772
3773 case RES_TYPE_BOOLEAN:
3774 tem = Fdowncase (tem);
3775 if (!strcmp (SDATA (tem), "on")
3776 || !strcmp (SDATA (tem), "true"))
3777 return Qt;
3778 else
3779 return Qnil;
3780
3781 case RES_TYPE_STRING:
3782 return tem;
3783
3784 case RES_TYPE_SYMBOL:
3785 /* As a special case, we map the values `true' and `on'
3786 to Qt, and `false' and `off' to Qnil. */
3787 {
3788 Lisp_Object lower;
3789 lower = Fdowncase (tem);
3790 if (!strcmp (SDATA (lower), "on")
3791 || !strcmp (SDATA (lower), "true"))
3792 return Qt;
3793 else if (!strcmp (SDATA (lower), "off")
3794 || !strcmp (SDATA (lower), "false"))
3795 return Qnil;
3796 else
3797 return Fintern (tem, Qnil);
3798 }
3799
3800 default:
3801 abort ();
3802 }
3803 }
3804 else
3805 return Qunbound;
3806 }
3807 return Fcdr (tem);
3808 }
3809
3810 Lisp_Object
3811 x_frame_get_arg (f, alist, param, attribute, class, type)
3812 struct frame *f;
3813 Lisp_Object alist, param;
3814 char *attribute;
3815 char *class;
3816 enum resource_types type;
3817 {
3818 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3819 alist, param, attribute, class, type);
3820 }
3821
3822 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3823
3824 Lisp_Object
3825 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3826 struct frame *f;
3827 Lisp_Object alist, param;
3828 char *attribute;
3829 char *class;
3830 enum resource_types type;
3831 {
3832 Lisp_Object value;
3833
3834 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3835 attribute, class, type);
3836 if (! NILP (value))
3837 store_frame_param (f, param, value);
3838
3839 return value;
3840 }
3841
3842
3843 /* Record in frame F the specified or default value according to ALIST
3844 of the parameter named PROP (a Lisp symbol).
3845 If no value is specified for PROP, look for an X default for XPROP
3846 on the frame named NAME.
3847 If that is not found either, use the value DEFLT. */
3848
3849 Lisp_Object
3850 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3851 struct frame *f;
3852 Lisp_Object alist;
3853 Lisp_Object prop;
3854 Lisp_Object deflt;
3855 char *xprop;
3856 char *xclass;
3857 enum resource_types type;
3858 {
3859 Lisp_Object tem;
3860
3861 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3862 if (EQ (tem, Qunbound))
3863 tem = deflt;
3864 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3865 return tem;
3866 }
3867
3868
3869
3870 \f
3871 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3872 doc: /* Parse an X-style geometry string STRING.
3873 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3874 The properties returned may include `top', `left', `height', and `width'.
3875 The value of `left' or `top' may be an integer,
3876 or a list (+ N) meaning N pixels relative to top/left corner,
3877 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3878 (string)
3879 Lisp_Object string;
3880 {
3881 int geometry, x, y;
3882 unsigned int width, height;
3883 Lisp_Object result;
3884
3885 CHECK_STRING (string);
3886
3887 geometry = XParseGeometry ((char *) SDATA (string),
3888 &x, &y, &width, &height);
3889
3890 #if 0
3891 if (!!(geometry & XValue) != !!(geometry & YValue))
3892 error ("Must specify both x and y position, or neither");
3893 #endif
3894
3895 result = Qnil;
3896 if (geometry & XValue)
3897 {
3898 Lisp_Object element;
3899
3900 if (x >= 0 && (geometry & XNegative))
3901 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3902 else if (x < 0 && ! (geometry & XNegative))
3903 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3904 else
3905 element = Fcons (Qleft, make_number (x));
3906 result = Fcons (element, result);
3907 }
3908
3909 if (geometry & YValue)
3910 {
3911 Lisp_Object element;
3912
3913 if (y >= 0 && (geometry & YNegative))
3914 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3915 else if (y < 0 && ! (geometry & YNegative))
3916 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3917 else
3918 element = Fcons (Qtop, make_number (y));
3919 result = Fcons (element, result);
3920 }
3921
3922 if (geometry & WidthValue)
3923 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3924 if (geometry & HeightValue)
3925 result = Fcons (Fcons (Qheight, make_number (height)), result);
3926
3927 return result;
3928 }
3929
3930 /* Calculate the desired size and position of frame F.
3931 Return the flags saying which aspects were specified.
3932
3933 Also set the win_gravity and size_hint_flags of F.
3934
3935 Adjust height for toolbar if TOOLBAR_P is 1.
3936
3937 This function does not make the coordinates positive. */
3938
3939 #define DEFAULT_ROWS 40
3940 #define DEFAULT_COLS 80
3941
3942 int
3943 x_figure_window_size (f, parms, toolbar_p)
3944 struct frame *f;
3945 Lisp_Object parms;
3946 int toolbar_p;
3947 {
3948 register Lisp_Object tem0, tem1, tem2;
3949 long window_prompting = 0;
3950 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3951
3952 /* Default values if we fall through.
3953 Actually, if that happens we should get
3954 window manager prompting. */
3955 SET_FRAME_COLS (f, DEFAULT_COLS);
3956 FRAME_LINES (f) = DEFAULT_ROWS;
3957 /* Window managers expect that if program-specified
3958 positions are not (0,0), they're intentional, not defaults. */
3959 f->top_pos = 0;
3960 f->left_pos = 0;
3961
3962 /* Ensure that old new_text_cols and new_text_lines will not override the
3963 values set here. */
3964 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3965 f->new_text_cols = f->new_text_lines = 0;
3966
3967 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3968 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3969 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3970 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3971 {
3972 if (!EQ (tem0, Qunbound))
3973 {
3974 CHECK_NUMBER (tem0);
3975 FRAME_LINES (f) = XINT (tem0);
3976 }
3977 if (!EQ (tem1, Qunbound))
3978 {
3979 CHECK_NUMBER (tem1);
3980 SET_FRAME_COLS (f, XINT (tem1));
3981 }
3982 if (!NILP (tem2) && !EQ (tem2, Qunbound))
3983 window_prompting |= USSize;
3984 else
3985 window_prompting |= PSize;
3986 }
3987
3988 f->scroll_bar_actual_width
3989 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
3990
3991 /* This used to be done _before_ calling x_figure_window_size, but
3992 since the height is reset here, this was really a no-op. I
3993 assume that moving it here does what Gerd intended (although he
3994 no longer can remember what that was... ++KFS, 2003-03-25. */
3995
3996 /* Add the tool-bar height to the initial frame height so that the
3997 user gets a text display area of the size he specified with -g or
3998 via .Xdefaults. Later changes of the tool-bar height don't
3999 change the frame size. This is done so that users can create
4000 tall Emacs frames without having to guess how tall the tool-bar
4001 will get. */
4002 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4003 {
4004 int margin, relief, bar_height;
4005
4006 relief = (tool_bar_button_relief >= 0
4007 ? tool_bar_button_relief
4008 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4009
4010 if (INTEGERP (Vtool_bar_button_margin)
4011 && XINT (Vtool_bar_button_margin) > 0)
4012 margin = XFASTINT (Vtool_bar_button_margin);
4013 else if (CONSP (Vtool_bar_button_margin)
4014 && INTEGERP (XCDR (Vtool_bar_button_margin))
4015 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4016 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4017 else
4018 margin = 0;
4019
4020 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4021 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4022 }
4023
4024 compute_fringe_widths (f, 0);
4025
4026 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4027 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4028
4029 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4030 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4031 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4032 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4033 {
4034 if (EQ (tem0, Qminus))
4035 {
4036 f->top_pos = 0;
4037 window_prompting |= YNegative;
4038 }
4039 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4040 && CONSP (XCDR (tem0))
4041 && INTEGERP (XCAR (XCDR (tem0))))
4042 {
4043 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4044 window_prompting |= YNegative;
4045 }
4046 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4047 && CONSP (XCDR (tem0))
4048 && INTEGERP (XCAR (XCDR (tem0))))
4049 {
4050 f->top_pos = XINT (XCAR (XCDR (tem0)));
4051 }
4052 else if (EQ (tem0, Qunbound))
4053 f->top_pos = 0;
4054 else
4055 {
4056 CHECK_NUMBER (tem0);
4057 f->top_pos = XINT (tem0);
4058 if (f->top_pos < 0)
4059 window_prompting |= YNegative;
4060 }
4061
4062 if (EQ (tem1, Qminus))
4063 {
4064 f->left_pos = 0;
4065 window_prompting |= XNegative;
4066 }
4067 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4068 && CONSP (XCDR (tem1))
4069 && INTEGERP (XCAR (XCDR (tem1))))
4070 {
4071 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4072 window_prompting |= XNegative;
4073 }
4074 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4075 && CONSP (XCDR (tem1))
4076 && INTEGERP (XCAR (XCDR (tem1))))
4077 {
4078 f->left_pos = XINT (XCAR (XCDR (tem1)));
4079 }
4080 else if (EQ (tem1, Qunbound))
4081 f->left_pos = 0;
4082 else
4083 {
4084 CHECK_NUMBER (tem1);
4085 f->left_pos = XINT (tem1);
4086 if (f->left_pos < 0)
4087 window_prompting |= XNegative;
4088 }
4089
4090 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4091 window_prompting |= USPosition;
4092 else
4093 window_prompting |= PPosition;
4094 }
4095
4096 if (f->want_fullscreen != FULLSCREEN_NONE)
4097 {
4098 int left, top;
4099 int width, height;
4100
4101 /* It takes both for some WM:s to place it where we want */
4102 window_prompting = USPosition | PPosition;
4103 x_fullscreen_adjust (f, &width, &height, &top, &left);
4104 FRAME_COLS (f) = width;
4105 FRAME_LINES (f) = height;
4106 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
4107 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
4108 f->left_pos = left;
4109 f->top_pos = top;
4110 }
4111
4112 if (window_prompting & XNegative)
4113 {
4114 if (window_prompting & YNegative)
4115 f->win_gravity = SouthEastGravity;
4116 else
4117 f->win_gravity = NorthEastGravity;
4118 }
4119 else
4120 {
4121 if (window_prompting & YNegative)
4122 f->win_gravity = SouthWestGravity;
4123 else
4124 f->win_gravity = NorthWestGravity;
4125 }
4126
4127 f->size_hint_flags = window_prompting;
4128
4129 return window_prompting;
4130 }
4131
4132
4133
4134 #endif /* HAVE_WINDOW_SYSTEM */
4135
4136
4137 \f
4138 /***********************************************************************
4139 Initialization
4140 ***********************************************************************/
4141
4142 void
4143 syms_of_frame ()
4144 {
4145 Qframep = intern ("framep");
4146 staticpro (&Qframep);
4147 Qframe_live_p = intern ("frame-live-p");
4148 staticpro (&Qframe_live_p);
4149 Qheight = intern ("height");
4150 staticpro (&Qheight);
4151 Qicon = intern ("icon");
4152 staticpro (&Qicon);
4153 Qminibuffer = intern ("minibuffer");
4154 staticpro (&Qminibuffer);
4155 Qmodeline = intern ("modeline");
4156 staticpro (&Qmodeline);
4157 Qonly = intern ("only");
4158 staticpro (&Qonly);
4159 Qwidth = intern ("width");
4160 staticpro (&Qwidth);
4161 Qgeometry = intern ("geometry");
4162 staticpro (&Qgeometry);
4163 Qicon_left = intern ("icon-left");
4164 staticpro (&Qicon_left);
4165 Qicon_top = intern ("icon-top");
4166 staticpro (&Qicon_top);
4167 Qleft = intern ("left");
4168 staticpro (&Qleft);
4169 Qright = intern ("right");
4170 staticpro (&Qright);
4171 Quser_position = intern ("user-position");
4172 staticpro (&Quser_position);
4173 Quser_size = intern ("user-size");
4174 staticpro (&Quser_size);
4175 Qwindow_id = intern ("window-id");
4176 staticpro (&Qwindow_id);
4177 #ifdef HAVE_X_WINDOWS
4178 Qouter_window_id = intern ("outer-window-id");
4179 staticpro (&Qouter_window_id);
4180 #endif
4181 Qparent_id = intern ("parent-id");
4182 staticpro (&Qparent_id);
4183 Qx = intern ("x");
4184 staticpro (&Qx);
4185 Qw32 = intern ("w32");
4186 staticpro (&Qw32);
4187 Qpc = intern ("pc");
4188 staticpro (&Qpc);
4189 Qmac = intern ("mac");
4190 staticpro (&Qmac);
4191 Qvisible = intern ("visible");
4192 staticpro (&Qvisible);
4193 Qbuffer_predicate = intern ("buffer-predicate");
4194 staticpro (&Qbuffer_predicate);
4195 Qbuffer_list = intern ("buffer-list");
4196 staticpro (&Qbuffer_list);
4197 Qdisplay_type = intern ("display-type");
4198 staticpro (&Qdisplay_type);
4199 Qbackground_mode = intern ("background-mode");
4200 staticpro (&Qbackground_mode);
4201 Qtty_color_mode = intern ("tty-color-mode");
4202 staticpro (&Qtty_color_mode);
4203 Qtty = intern ("tty");
4204 staticpro (&Qtty);
4205 Qtty_type = intern ("tty-type");
4206 staticpro (&Qtty_type);
4207 Qwindow_system = intern ("window-system");
4208 staticpro (&Qwindow_system);
4209
4210 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4211 staticpro (&Qface_set_after_frame_default);
4212
4213 Qfullwidth = intern ("fullwidth");
4214 staticpro (&Qfullwidth);
4215 Qfullheight = intern ("fullheight");
4216 staticpro (&Qfullheight);
4217 Qfullboth = intern ("fullboth");
4218 staticpro (&Qfullboth);
4219 Qx_resource_name = intern ("x-resource-name");
4220 staticpro (&Qx_resource_name);
4221
4222 Qx_frame_parameter = intern ("x-frame-parameter");
4223 staticpro (&Qx_frame_parameter);
4224
4225 Qdevice = intern ("device");
4226 staticpro (&Qdevice);
4227 Qdisplay_live_p = intern ("display-live-p");
4228 staticpro (&Qdisplay_live_p);
4229
4230 {
4231 int i;
4232
4233 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4234 {
4235 Lisp_Object v = intern (frame_parms[i].name);
4236 if (frame_parms[i].variable)
4237 {
4238 *frame_parms[i].variable = v;
4239 staticpro (frame_parms[i].variable);
4240 }
4241 Fput (v, Qx_frame_parameter, make_number (i));
4242 }
4243 }
4244
4245 #ifdef HAVE_WINDOW_SYSTEM
4246 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4247 doc: /* The name Emacs uses to look up X resources.
4248 `x-get-resource' uses this as the first component of the instance name
4249 when requesting resource values.
4250 Emacs initially sets `x-resource-name' to the name under which Emacs
4251 was invoked, or to the value specified with the `-name' or `-rn'
4252 switches, if present.
4253
4254 It may be useful to bind this variable locally around a call
4255 to `x-get-resource'. See also the variable `x-resource-class'. */);
4256 Vx_resource_name = Qnil;
4257
4258 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4259 doc: /* The class Emacs uses to look up X resources.
4260 `x-get-resource' uses this as the first component of the instance class
4261 when requesting resource values.
4262
4263 Emacs initially sets `x-resource-class' to "Emacs".
4264
4265 Setting this variable permanently is not a reasonable thing to do,
4266 but binding this variable locally around a call to `x-get-resource'
4267 is a reasonable practice. See also the variable `x-resource-name'. */);
4268 Vx_resource_class = build_string (EMACS_CLASS);
4269 #endif
4270
4271 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4272 doc: /* Alist of default values for frame creation.
4273 These may be set in your init file, like this:
4274 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4275 These override values given in window system configuration data,
4276 including X Windows' defaults database.
4277 For values specific to the first Emacs frame, see `initial-frame-alist'.
4278 For values specific to the separate minibuffer frame, see
4279 `minibuffer-frame-alist'.
4280 The `menu-bar-lines' element of the list controls whether new frames
4281 have menu bars; `menu-bar-mode' works by altering this element.
4282 Setting this variable does not affect existing frames, only new ones. */);
4283 Vdefault_frame_alist = Qnil;
4284
4285 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4286 doc: /* Default position of scroll bars on this window-system. */);
4287 #ifdef HAVE_WINDOW_SYSTEM
4288 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4289 /* MS-Windows has scroll bars on the right by default. */
4290 Vdefault_frame_scroll_bars = Qright;
4291 #else
4292 Vdefault_frame_scroll_bars = Qleft;
4293 #endif
4294 #else
4295 Vdefault_frame_scroll_bars = Qnil;
4296 #endif
4297
4298 Qinhibit_default_face_x_resources
4299 = intern ("inhibit-default-face-x-resources");
4300 staticpro (&Qinhibit_default_face_x_resources);
4301
4302 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4303 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4304
4305 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4306 doc: /* Non-nil if all of emacs is iconified and frame updates are not needed. */);
4307 Vemacs_iconified = Qnil;
4308
4309 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4310 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4311 `mouse-position' calls this function, passing its usual return value as
4312 argument, and returns whatever this function returns.
4313 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4314 which need to do mouse handling at the Lisp level. */);
4315 Vmouse_position_function = Qnil;
4316
4317 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4318 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4319 If the value is an integer, highlighting is only shown after moving the
4320 mouse, while keyboard input turns off the highlight even when the mouse
4321 is over the clickable text. However, the mouse shape still indicates
4322 when the mouse is over clickable text. */);
4323 Vmouse_highlight = Qt;
4324
4325 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4326 doc: /* Functions to be run before deleting a frame.
4327 The functions are run with one arg, the frame to be deleted.
4328 See `delete-frame'.
4329
4330 Note that functions in this list may be called twice on the same
4331 frame. In the second invocation, the frame is already deleted, and
4332 the function should do nothing. (You can use `frame-live-p' to check
4333 for this.) This wrinkle happens when an earlier function in
4334 `delete-frame-functions' (indirectly) calls delete-frame
4335 recursively. */);
4336 Vdelete_frame_functions = Qnil;
4337
4338 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4339 doc: /* Minibufferless frames use this frame's minibuffer.
4340
4341 Emacs cannot create minibufferless frames unless this is set to an
4342 appropriate surrogate.
4343
4344 Emacs consults this variable only when creating minibufferless
4345 frames; once the frame is created, it sticks with its assigned
4346 minibuffer, no matter what this variable is set to. This means that
4347 this variable doesn't necessarily say anything meaningful about the
4348 current set of frames, or where the minibuffer is currently being
4349 displayed.
4350
4351 This variable is local to the current terminal and cannot be buffer-local. */);
4352
4353 staticpro (&Vframe_list);
4354
4355 defsubr (&Sactive_minibuffer_window);
4356 defsubr (&Sframep);
4357 defsubr (&Sframe_live_p);
4358 defsubr (&Swindow_system);
4359 defsubr (&Smake_terminal_frame);
4360 defsubr (&Shandle_switch_frame);
4361 defsubr (&Sselect_frame);
4362 defsubr (&Sselected_frame);
4363 defsubr (&Swindow_frame);
4364 defsubr (&Sframe_root_window);
4365 defsubr (&Sframe_first_window);
4366 defsubr (&Sframe_selected_window);
4367 defsubr (&Sset_frame_selected_window);
4368 defsubr (&Sframe_display);
4369 defsubr (&Sframe_list);
4370 defsubr (&Snext_frame);
4371 defsubr (&Sprevious_frame);
4372 defsubr (&Sdelete_frame);
4373 defsubr (&Smouse_position);
4374 defsubr (&Smouse_pixel_position);
4375 defsubr (&Sset_mouse_position);
4376 defsubr (&Sset_mouse_pixel_position);
4377 #if 0
4378 defsubr (&Sframe_configuration);
4379 defsubr (&Srestore_frame_configuration);
4380 #endif
4381 defsubr (&Smake_frame_visible);
4382 defsubr (&Smake_frame_invisible);
4383 defsubr (&Siconify_frame);
4384 defsubr (&Sframe_visible_p);
4385 defsubr (&Svisible_frame_list);
4386 defsubr (&Sraise_frame);
4387 defsubr (&Slower_frame);
4388 defsubr (&Sredirect_frame_focus);
4389 defsubr (&Sframe_focus);
4390 defsubr (&Sframe_parameters);
4391 defsubr (&Sframe_parameter);
4392 defsubr (&Smodify_frame_parameters);
4393 defsubr (&Sframe_char_height);
4394 defsubr (&Sframe_char_width);
4395 defsubr (&Sframe_pixel_height);
4396 defsubr (&Sframe_pixel_width);
4397 defsubr (&Sset_frame_height);
4398 defsubr (&Sset_frame_width);
4399 defsubr (&Sset_frame_size);
4400 defsubr (&Sset_frame_position);
4401
4402 #ifdef HAVE_WINDOW_SYSTEM
4403 defsubr (&Sx_get_resource);
4404 defsubr (&Sx_parse_geometry);
4405 #endif
4406
4407 }
4408
4409 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4410 (do not change this comment) */