Revert the change of 2003-07-29 as GTK+ 2.2 is not required anymore.
[emacs.git] / src / frame.c
blob98b3e7067bda3a7def1525a43cf4288d3791dec4
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2003
3 Free Software Foundation.
5 This file is part of GNU Emacs.
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.
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.
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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include <config.h>
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 "termhooks.h"
46 #include "dispextern.h"
47 #include "window.h"
48 #ifdef MSDOS
49 #include "msdos.h"
50 #include "dosfns.h"
51 #endif
54 #ifdef HAVE_WINDOW_SYSTEM
56 /* The name we're using in resource queries. Most often "emacs". */
58 Lisp_Object Vx_resource_name;
60 /* The application class we're using in resource queries.
61 Normally "Emacs". */
63 Lisp_Object Vx_resource_class;
65 #endif
67 Lisp_Object Qframep, Qframe_live_p;
68 Lisp_Object Qicon, Qmodeline;
69 Lisp_Object Qonly;
70 Lisp_Object Qx, Qw32, Qmac, Qpc;
71 Lisp_Object Qvisible;
72 Lisp_Object Qdisplay_type;
73 Lisp_Object Qbackground_mode;
74 Lisp_Object Qinhibit_default_face_x_resources;
76 Lisp_Object Qx_frame_parameter;
77 Lisp_Object Qx_resource_name;
79 /* Frame parameters (set or reported). */
81 Lisp_Object Qauto_raise, Qauto_lower;
82 Lisp_Object Qborder_color, Qborder_width;
83 Lisp_Object Qcursor_color, Qcursor_type;
84 Lisp_Object Qgeometry; /* Not used */
85 Lisp_Object Qheight, Qwidth;
86 Lisp_Object Qleft, Qright;
87 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
88 Lisp_Object Qinternal_border_width;
89 Lisp_Object Qmouse_color;
90 Lisp_Object Qminibuffer;
91 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
92 Lisp_Object Qvisibility;
93 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
94 Lisp_Object Qscreen_gamma;
95 Lisp_Object Qline_spacing;
96 Lisp_Object Quser_position, Quser_size;
97 Lisp_Object Qwait_for_wm;
98 Lisp_Object Qwindow_id;
99 #ifdef HAVE_X_WINDOWS
100 Lisp_Object Qouter_window_id;
101 #endif
102 Lisp_Object Qparent_id;
103 Lisp_Object Qtitle, Qname;
104 Lisp_Object Qunsplittable;
105 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
106 Lisp_Object Qleft_fringe, Qright_fringe;
107 Lisp_Object Qbuffer_predicate, Qbuffer_list;
108 Lisp_Object Qtty_color_mode;
110 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
112 Lisp_Object Qface_set_after_frame_default;
115 Lisp_Object Vterminal_frame;
116 Lisp_Object Vdefault_frame_alist;
117 Lisp_Object Vmouse_position_function;
118 Lisp_Object Vmouse_highlight;
119 Lisp_Object Vdelete_frame_functions;
121 static void
122 set_menu_bar_lines_1 (window, n)
123 Lisp_Object window;
124 int n;
126 struct window *w = XWINDOW (window);
128 XSETFASTINT (w->last_modified, 0);
129 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
130 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
132 if (INTEGERP (w->orig_top_line))
133 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
134 if (INTEGERP (w->orig_total_lines))
135 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
137 /* Handle just the top child in a vertical split. */
138 if (!NILP (w->vchild))
139 set_menu_bar_lines_1 (w->vchild, n);
141 /* Adjust all children in a horizontal split. */
142 for (window = w->hchild; !NILP (window); window = w->next)
144 w = XWINDOW (window);
145 set_menu_bar_lines_1 (window, n);
149 void
150 set_menu_bar_lines (f, value, oldval)
151 struct frame *f;
152 Lisp_Object value, oldval;
154 int nlines;
155 int olines = FRAME_MENU_BAR_LINES (f);
157 /* Right now, menu bars don't work properly in minibuf-only frames;
158 most of the commands try to apply themselves to the minibuffer
159 frame itself, and get an error because you can't switch buffers
160 in or split the minibuffer window. */
161 if (FRAME_MINIBUF_ONLY_P (f))
162 return;
164 if (INTEGERP (value))
165 nlines = XINT (value);
166 else
167 nlines = 0;
169 if (nlines != olines)
171 windows_or_buffers_changed++;
172 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
173 FRAME_MENU_BAR_LINES (f) = nlines;
174 set_menu_bar_lines_1 (f->root_window, nlines - olines);
175 adjust_glyphs (f);
179 Lisp_Object Vemacs_iconified;
180 Lisp_Object Vframe_list;
182 struct x_output tty_display;
184 extern Lisp_Object Vminibuffer_list;
185 extern Lisp_Object get_minibuffer ();
186 extern Lisp_Object Fhandle_switch_frame ();
187 extern Lisp_Object Fredirect_frame_focus ();
188 extern Lisp_Object x_get_focus_frame ();
190 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
191 doc: /* Return non-nil if OBJECT is a frame.
192 Value is t for a termcap frame (a character-only terminal),
193 `x' for an Emacs frame that is really an X window,
194 `w32' for an Emacs frame that is a window on MS-Windows display,
195 `mac' for an Emacs frame on a Macintosh display,
196 `pc' for a direct-write MS-DOS frame.
197 See also `frame-live-p'. */)
198 (object)
199 Lisp_Object object;
201 if (!FRAMEP (object))
202 return Qnil;
203 switch (XFRAME (object)->output_method)
205 case output_termcap:
206 return Qt;
207 case output_x_window:
208 return Qx;
209 case output_w32:
210 return Qw32;
211 case output_msdos_raw:
212 return Qpc;
213 case output_mac:
214 return Qmac;
215 default:
216 abort ();
220 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
221 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
222 Value is nil if OBJECT is not a live frame. If object is a live
223 frame, the return value indicates what sort of output device it is
224 displayed on. See the documentation of `framep' for possible
225 return values. */)
226 (object)
227 Lisp_Object object;
229 return ((FRAMEP (object)
230 && FRAME_LIVE_P (XFRAME (object)))
231 ? Fframep (object)
232 : Qnil);
235 struct frame *
236 make_frame (mini_p)
237 int mini_p;
239 Lisp_Object frame;
240 register struct frame *f;
241 register Lisp_Object root_window;
242 register Lisp_Object mini_window;
244 f = allocate_frame ();
245 XSETFRAME (frame, f);
247 f->desired_matrix = 0;
248 f->current_matrix = 0;
249 f->desired_pool = 0;
250 f->current_pool = 0;
251 f->glyphs_initialized_p = 0;
252 f->decode_mode_spec_buffer = 0;
253 f->visible = 0;
254 f->async_visible = 0;
255 f->output_data.nothing = 0;
256 f->iconified = 0;
257 f->async_iconified = 0;
258 f->wants_modeline = 1;
259 f->auto_raise = 0;
260 f->auto_lower = 0;
261 f->no_split = 0;
262 f->garbaged = 1;
263 f->has_minibuffer = mini_p;
264 f->focus_frame = Qnil;
265 f->explicit_name = 0;
266 f->can_have_scroll_bars = 0;
267 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
268 f->param_alist = Qnil;
269 f->scroll_bars = Qnil;
270 f->condemned_scroll_bars = Qnil;
271 f->face_alist = Qnil;
272 f->face_cache = NULL;
273 f->menu_bar_items = Qnil;
274 f->menu_bar_vector = Qnil;
275 f->menu_bar_items_used = 0;
276 f->buffer_predicate = Qnil;
277 f->buffer_list = Qnil;
278 #ifdef MULTI_KBOARD
279 f->kboard = initial_kboard;
280 #endif
281 f->namebuf = 0;
282 f->title = Qnil;
283 f->menu_bar_window = Qnil;
284 f->tool_bar_window = Qnil;
285 f->tool_bar_items = Qnil;
286 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
287 f->n_tool_bar_items = 0;
288 f->left_fringe_width = f->right_fringe_width = 0;
289 f->fringe_cols = 0;
290 f->scroll_bar_actual_width = 0;
291 f->border_width = 0;
292 f->internal_border_width = 0;
293 f->column_width = 1; /* !FRAME_WINDOW_P value */
294 f->line_height = 1; /* !FRAME_WINDOW_P value */
295 f->x_pixels_diff = f->y_pixels_diff = 0;
296 #ifdef HAVE_WINDOW_SYSTEM
297 f->want_fullscreen = FULLSCREEN_NONE;
298 #endif
299 f->size_hint_flags = 0;
300 f->win_gravity = 0;
302 root_window = make_window ();
303 if (mini_p)
305 mini_window = make_window ();
306 XWINDOW (root_window)->next = mini_window;
307 XWINDOW (mini_window)->prev = root_window;
308 XWINDOW (mini_window)->mini_p = Qt;
309 XWINDOW (mini_window)->frame = frame;
310 f->minibuffer_window = mini_window;
312 else
314 mini_window = Qnil;
315 XWINDOW (root_window)->next = Qnil;
316 f->minibuffer_window = Qnil;
319 XWINDOW (root_window)->frame = frame;
321 /* 10 is arbitrary,
322 just so that there is "something there."
323 Correct size will be set up later with change_frame_size. */
325 SET_FRAME_COLS (f, 10);
326 FRAME_LINES (f) = 10;
328 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
329 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
331 if (mini_p)
333 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
334 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
335 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
338 /* Choose a buffer for the frame's root window. */
340 Lisp_Object buf;
342 XWINDOW (root_window)->buffer = Qt;
343 buf = Fcurrent_buffer ();
344 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
345 a space), try to find another one. */
346 if (SREF (Fbuffer_name (buf), 0) == ' ')
347 buf = Fother_buffer (buf, Qnil, Qnil);
349 /* Use set_window_buffer, not Fset_window_buffer, and don't let
350 hooks be run by it. The reason is that the whole frame/window
351 arrangement is not yet fully intialized at this point. Windows
352 don't have the right size, glyph matrices aren't initialized
353 etc. Running Lisp functions at this point surely ends in a
354 SEGV. */
355 set_window_buffer (root_window, buf, 0, 0);
356 f->buffer_list = Fcons (buf, Qnil);
359 if (mini_p)
361 XWINDOW (mini_window)->buffer = Qt;
362 set_window_buffer (mini_window,
363 (NILP (Vminibuffer_list)
364 ? get_minibuffer (0)
365 : Fcar (Vminibuffer_list)),
366 0, 0);
369 f->root_window = root_window;
370 f->selected_window = root_window;
371 /* Make sure this window seems more recently used than
372 a newly-created, never-selected window. */
373 XSETFASTINT (XWINDOW (f->selected_window)->use_time, ++window_select_count);
375 f->default_face_done_p = 0;
377 return f;
380 #ifdef HAVE_WINDOW_SYSTEM
381 /* Make a frame using a separate minibuffer window on another frame.
382 MINI_WINDOW is the minibuffer window to use. nil means use the
383 default (the global minibuffer). */
385 struct frame *
386 make_frame_without_minibuffer (mini_window, kb, display)
387 register Lisp_Object mini_window;
388 KBOARD *kb;
389 Lisp_Object display;
391 register struct frame *f;
392 struct gcpro gcpro1;
394 if (!NILP (mini_window))
395 CHECK_LIVE_WINDOW (mini_window);
397 #ifdef MULTI_KBOARD
398 if (!NILP (mini_window)
399 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb)
400 error ("frame and minibuffer must be on the same display");
401 #endif
403 /* Make a frame containing just a root window. */
404 f = make_frame (0);
406 if (NILP (mini_window))
408 /* Use default-minibuffer-frame if possible. */
409 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
410 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
412 Lisp_Object frame_dummy;
414 XSETFRAME (frame_dummy, f);
415 GCPRO1 (frame_dummy);
416 /* If there's no minibuffer frame to use, create one. */
417 kb->Vdefault_minibuffer_frame =
418 call1 (intern ("make-initial-minibuffer-frame"), display);
419 UNGCPRO;
422 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
425 f->minibuffer_window = mini_window;
427 /* Make the chosen minibuffer window display the proper minibuffer,
428 unless it is already showing a minibuffer. */
429 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
430 Fset_window_buffer (mini_window,
431 (NILP (Vminibuffer_list)
432 ? get_minibuffer (0)
433 : Fcar (Vminibuffer_list)), Qnil);
434 return f;
437 /* Make a frame containing only a minibuffer window. */
439 struct frame *
440 make_minibuffer_frame ()
442 /* First make a frame containing just a root window, no minibuffer. */
444 register struct frame *f = make_frame (0);
445 register Lisp_Object mini_window;
446 register Lisp_Object frame;
448 XSETFRAME (frame, f);
450 f->auto_raise = 0;
451 f->auto_lower = 0;
452 f->no_split = 1;
453 f->wants_modeline = 0;
454 f->has_minibuffer = 1;
456 /* Now label the root window as also being the minibuffer.
457 Avoid infinite looping on the window chain by marking next pointer
458 as nil. */
460 mini_window = f->minibuffer_window = f->root_window;
461 XWINDOW (mini_window)->mini_p = Qt;
462 XWINDOW (mini_window)->next = Qnil;
463 XWINDOW (mini_window)->prev = Qnil;
464 XWINDOW (mini_window)->frame = frame;
466 /* Put the proper buffer in that window. */
468 Fset_window_buffer (mini_window,
469 (NILP (Vminibuffer_list)
470 ? get_minibuffer (0)
471 : Fcar (Vminibuffer_list)), Qnil);
472 return f;
474 #endif /* HAVE_WINDOW_SYSTEM */
476 /* Construct a frame that refers to the terminal (stdin and stdout). */
478 static int terminal_frame_count;
480 struct frame *
481 make_terminal_frame ()
483 register struct frame *f;
484 Lisp_Object frame;
485 char name[20];
487 #ifdef MULTI_KBOARD
488 if (!initial_kboard)
490 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
491 init_kboard (initial_kboard);
492 initial_kboard->next_kboard = all_kboards;
493 all_kboards = initial_kboard;
495 #endif
497 /* The first call must initialize Vframe_list. */
498 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
499 Vframe_list = Qnil;
501 f = make_frame (1);
503 XSETFRAME (frame, f);
504 Vframe_list = Fcons (frame, Vframe_list);
506 terminal_frame_count++;
507 sprintf (name, "F%d", terminal_frame_count);
508 f->name = build_string (name);
510 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
511 f->async_visible = 1; /* Don't let visible be cleared later. */
512 #ifdef MSDOS
513 f->output_data.x = &the_only_x_display;
514 if (!inhibit_window_system
515 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
516 || XFRAME (selected_frame)->output_method == output_msdos_raw))
518 f->output_method = output_msdos_raw;
519 /* This initialization of foreground and background pixels is
520 only important for the initial frame created in temacs. If
521 we don't do that, we get black background and foreground in
522 the dumped Emacs because the_only_x_display is a static
523 variable, hence it is born all-zeroes, and zero is the code
524 for the black color. Other frames all inherit their pixels
525 from what's already in the_only_x_display. */
526 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
527 && f->output_data.x->background_pixel == 0
528 && f->output_data.x->foreground_pixel == 0)
530 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
531 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
534 else
535 f->output_method = output_termcap;
536 #else
537 #ifdef WINDOWSNT
538 f->output_method = output_termcap;
539 f->output_data.x = &tty_display;
540 #else
541 #ifdef MAC_OS8
542 make_mac_terminal_frame (f);
543 #else
544 f->output_data.x = &tty_display;
545 #ifdef CANNOT_DUMP
546 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
547 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
548 #endif
549 #endif /* MAC_OS8 */
550 #endif /* WINDOWSNT */
551 #endif /* MSDOS */
553 if (!noninteractive)
554 init_frame_faces (f);
556 return f;
559 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
560 1, 1, 0,
561 doc: /* Create an additional terminal frame.
562 You can create multiple frames on a text-only terminal in this way.
563 Only the selected terminal frame is actually displayed.
564 This function takes one argument, an alist specifying frame parameters.
565 In practice, generally you don't need to specify any parameters.
566 Note that changing the size of one terminal frame automatically affects all. */)
567 (parms)
568 Lisp_Object parms;
570 struct frame *f;
571 Lisp_Object frame, tem;
572 struct frame *sf = SELECTED_FRAME ();
574 #ifdef MSDOS
575 if (sf->output_method != output_msdos_raw
576 && sf->output_method != output_termcap)
577 abort ();
578 #else /* not MSDOS */
580 #ifdef MAC_OS
581 if (sf->output_method != output_mac)
582 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
583 #else
584 if (sf->output_method != output_termcap)
585 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
586 #endif
587 #endif /* not MSDOS */
589 f = make_terminal_frame ();
591 change_frame_size (f, FRAME_LINES (sf),
592 FRAME_COLS (sf), 0, 0, 0);
593 adjust_glyphs (f);
594 calculate_costs (f);
595 XSETFRAME (frame, f);
596 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
597 Fmodify_frame_parameters (frame, parms);
599 /* Make the frame face alist be frame-specific, so that each
600 frame could change its face definitions independently. */
601 f->face_alist = Fcopy_alist (sf->face_alist);
602 /* Simple Fcopy_alist isn't enough, because we need the contents of
603 the vectors which are the CDRs of associations in face_alist to
604 be copied as well. */
605 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
606 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
607 return frame;
611 /* Perform the switch to frame FRAME.
613 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
614 FRAME1 as frame.
616 If TRACK is non-zero and the frame that currently has the focus
617 redirects its focus to the selected frame, redirect that focused
618 frame's focus to FRAME instead.
620 FOR_DELETION non-zero means that the selected frame is being
621 deleted, which includes the possibility that the frame's display
622 is dead. */
624 Lisp_Object
625 do_switch_frame (frame, track, for_deletion)
626 Lisp_Object frame;
627 int track, for_deletion;
629 struct frame *sf = SELECTED_FRAME ();
631 /* If FRAME is a switch-frame event, extract the frame we should
632 switch to. */
633 if (CONSP (frame)
634 && EQ (XCAR (frame), Qswitch_frame)
635 && CONSP (XCDR (frame)))
636 frame = XCAR (XCDR (frame));
638 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
639 a switch-frame event to arrive after a frame is no longer live,
640 especially when deleting the initial frame during startup. */
641 CHECK_FRAME (frame);
642 if (! FRAME_LIVE_P (XFRAME (frame)))
643 return Qnil;
645 if (sf == XFRAME (frame))
646 return frame;
648 /* This is too greedy; it causes inappropriate focus redirection
649 that's hard to get rid of. */
650 #if 0
651 /* If a frame's focus has been redirected toward the currently
652 selected frame, we should change the redirection to point to the
653 newly selected frame. This means that if the focus is redirected
654 from a minibufferless frame to a surrogate minibuffer frame, we
655 can use `other-window' to switch between all the frames using
656 that minibuffer frame, and the focus redirection will follow us
657 around. */
658 if (track)
660 Lisp_Object tail;
662 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
664 Lisp_Object focus;
666 if (!FRAMEP (XCAR (tail)))
667 abort ();
669 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
671 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
672 Fredirect_frame_focus (XCAR (tail), frame);
675 #else /* ! 0 */
676 /* Instead, apply it only to the frame we're pointing to. */
677 #ifdef HAVE_WINDOW_SYSTEM
678 if (track && FRAME_WINDOW_P (XFRAME (frame)))
680 Lisp_Object focus, xfocus;
682 xfocus = x_get_focus_frame (XFRAME (frame));
683 if (FRAMEP (xfocus))
685 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
686 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
687 Fredirect_frame_focus (xfocus, frame);
690 #endif /* HAVE_X_WINDOWS */
691 #endif /* ! 0 */
693 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
694 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
696 selected_frame = frame;
697 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
698 last_nonminibuf_frame = XFRAME (selected_frame);
700 Fselect_window (XFRAME (frame)->selected_window, Qnil);
702 #ifndef WINDOWSNT
703 /* Make sure to switch the tty color mode to that of the newly
704 selected frame. */
705 sf = SELECTED_FRAME ();
706 if (FRAME_TERMCAP_P (sf))
708 Lisp_Object color_mode_spec, color_mode;
710 color_mode_spec = assq_no_quit (Qtty_color_mode, sf->param_alist);
711 if (CONSP (color_mode_spec))
712 color_mode = XCDR (color_mode_spec);
713 else
714 color_mode = make_number (0);
715 set_tty_color_mode (sf, color_mode);
717 #endif /* !WINDOWSNT */
719 /* We want to make sure that the next event generates a frame-switch
720 event to the appropriate frame. This seems kludgy to me, but
721 before you take it out, make sure that evaluating something like
722 (select-window (frame-root-window (new-frame))) doesn't end up
723 with your typing being interpreted in the new frame instead of
724 the one you're actually typing in. */
725 internal_last_event_frame = Qnil;
727 return frame;
730 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
731 doc: /* Select the frame FRAME.
732 Subsequent editing commands apply to its selected window.
733 The selection of FRAME lasts until the next time the user does
734 something to select a different frame, or until the next time this
735 function is called. */)
736 (frame, no_enter)
737 Lisp_Object frame, no_enter;
739 return do_switch_frame (frame, 1, 0);
743 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 2, "e",
744 doc: /* Handle a switch-frame event EVENT.
745 Switch-frame events are usually bound to this function.
746 A switch-frame event tells Emacs that the window manager has requested
747 that the user's events be directed to the frame mentioned in the event.
748 This function selects the selected window of the frame of EVENT.
750 If EVENT is frame object, handle it as if it were a switch-frame event
751 to that frame. */)
752 (event, no_enter)
753 Lisp_Object event, no_enter;
755 /* Preserve prefix arg that the command loop just cleared. */
756 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
757 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
758 return do_switch_frame (event, 0, 0);
761 DEFUN ("ignore-event", Fignore_event, Signore_event, 0, 0, "",
762 doc: /* Do nothing, but preserve any prefix argument already specified.
763 This is a suitable binding for `iconify-frame' and `make-frame-visible'. */)
766 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
767 return Qnil;
770 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
771 doc: /* Return the frame that is now selected. */)
774 return selected_frame;
777 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
778 doc: /* Return the frame object that window WINDOW is on. */)
779 (window)
780 Lisp_Object window;
782 CHECK_LIVE_WINDOW (window);
783 return XWINDOW (window)->frame;
786 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
787 doc: /* Returns the topmost, leftmost window of FRAME.
788 If omitted, FRAME defaults to the currently selected frame. */)
789 (frame)
790 Lisp_Object frame;
792 Lisp_Object w;
794 if (NILP (frame))
795 w = SELECTED_FRAME ()->root_window;
796 else
798 CHECK_LIVE_FRAME (frame);
799 w = XFRAME (frame)->root_window;
801 while (NILP (XWINDOW (w)->buffer))
803 if (! NILP (XWINDOW (w)->hchild))
804 w = XWINDOW (w)->hchild;
805 else if (! NILP (XWINDOW (w)->vchild))
806 w = XWINDOW (w)->vchild;
807 else
808 abort ();
810 return w;
813 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
814 Sactive_minibuffer_window, 0, 0, 0,
815 doc: /* Return the currently active minibuffer window, or nil if none. */)
818 return minibuf_level ? minibuf_window : Qnil;
821 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
822 doc: /* Returns the root-window of FRAME.
823 If omitted, FRAME defaults to the currently selected frame. */)
824 (frame)
825 Lisp_Object frame;
827 Lisp_Object window;
829 if (NILP (frame))
830 window = SELECTED_FRAME ()->root_window;
831 else
833 CHECK_LIVE_FRAME (frame);
834 window = XFRAME (frame)->root_window;
837 return window;
840 DEFUN ("frame-selected-window", Fframe_selected_window,
841 Sframe_selected_window, 0, 1, 0,
842 doc: /* Return the selected window of frame object FRAME.
843 If omitted, FRAME defaults to the currently selected frame. */)
844 (frame)
845 Lisp_Object frame;
847 Lisp_Object window;
849 if (NILP (frame))
850 window = SELECTED_FRAME ()->selected_window;
851 else
853 CHECK_LIVE_FRAME (frame);
854 window = XFRAME (frame)->selected_window;
857 return window;
860 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
861 Sset_frame_selected_window, 2, 2, 0,
862 doc: /* Set the selected window of frame object FRAME to WINDOW.
863 If FRAME is nil, the selected frame is used.
864 If FRAME is the selected frame, this makes WINDOW the selected window. */)
865 (frame, window)
866 Lisp_Object frame, window;
868 if (NILP (frame))
869 frame = selected_frame;
871 CHECK_LIVE_FRAME (frame);
872 CHECK_LIVE_WINDOW (window);
874 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
875 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
877 if (EQ (frame, selected_frame))
878 return Fselect_window (window, Qnil);
880 return XFRAME (frame)->selected_window = window;
883 DEFUN ("frame-list", Fframe_list, Sframe_list,
884 0, 0, 0,
885 doc: /* Return a list of all frames. */)
888 Lisp_Object frames;
889 frames = Fcopy_sequence (Vframe_list);
890 #ifdef HAVE_WINDOW_SYSTEM
891 if (FRAMEP (tip_frame))
892 frames = Fdelq (tip_frame, frames);
893 #endif
894 return frames;
897 /* Return the next frame in the frame list after FRAME.
898 If MINIBUF is nil, exclude minibuffer-only frames.
899 If MINIBUF is a window, include only its own frame
900 and any frame now using that window as the minibuffer.
901 If MINIBUF is `visible', include all visible frames.
902 If MINIBUF is 0, include all visible and iconified frames.
903 Otherwise, include all frames. */
905 Lisp_Object
906 next_frame (frame, minibuf)
907 Lisp_Object frame;
908 Lisp_Object minibuf;
910 Lisp_Object tail;
911 int passed = 0;
913 /* There must always be at least one frame in Vframe_list. */
914 if (! CONSP (Vframe_list))
915 abort ();
917 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
918 forever. Forestall that. */
919 CHECK_LIVE_FRAME (frame);
921 while (1)
922 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
924 Lisp_Object f;
926 f = XCAR (tail);
928 if (passed
929 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
931 /* Decide whether this frame is eligible to be returned. */
933 /* If we've looped all the way around without finding any
934 eligible frames, return the original frame. */
935 if (EQ (f, frame))
936 return f;
938 /* Let minibuf decide if this frame is acceptable. */
939 if (NILP (minibuf))
941 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
942 return f;
944 else if (EQ (minibuf, Qvisible))
946 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
947 if (FRAME_VISIBLE_P (XFRAME (f)))
948 return f;
950 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
952 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
953 if (FRAME_VISIBLE_P (XFRAME (f))
954 || FRAME_ICONIFIED_P (XFRAME (f)))
955 return f;
957 else if (WINDOWP (minibuf))
959 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
960 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
961 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
962 FRAME_FOCUS_FRAME (XFRAME (f))))
963 return f;
965 else
966 return f;
969 if (EQ (frame, f))
970 passed++;
974 /* Return the previous frame in the frame list before FRAME.
975 If MINIBUF is nil, exclude minibuffer-only frames.
976 If MINIBUF is a window, include only its own frame
977 and any frame now using that window as the minibuffer.
978 If MINIBUF is `visible', include all visible frames.
979 If MINIBUF is 0, include all visible and iconified frames.
980 Otherwise, include all frames. */
982 Lisp_Object
983 prev_frame (frame, minibuf)
984 Lisp_Object frame;
985 Lisp_Object minibuf;
987 Lisp_Object tail;
988 Lisp_Object prev;
990 /* There must always be at least one frame in Vframe_list. */
991 if (! CONSP (Vframe_list))
992 abort ();
994 prev = Qnil;
995 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
997 Lisp_Object f;
999 f = XCAR (tail);
1000 if (!FRAMEP (f))
1001 abort ();
1003 if (EQ (frame, f) && !NILP (prev))
1004 return prev;
1006 if (FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1008 /* Decide whether this frame is eligible to be returned,
1009 according to minibuf. */
1010 if (NILP (minibuf))
1012 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1013 prev = f;
1015 else if (WINDOWP (minibuf))
1017 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1018 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1019 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1020 FRAME_FOCUS_FRAME (XFRAME (f))))
1021 prev = f;
1023 else if (EQ (minibuf, Qvisible))
1025 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1026 if (FRAME_VISIBLE_P (XFRAME (f)))
1027 prev = f;
1029 else if (XFASTINT (minibuf) == 0)
1031 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1032 if (FRAME_VISIBLE_P (XFRAME (f))
1033 || FRAME_ICONIFIED_P (XFRAME (f)))
1034 prev = f;
1036 else
1037 prev = f;
1041 /* We've scanned the entire list. */
1042 if (NILP (prev))
1043 /* We went through the whole frame list without finding a single
1044 acceptable frame. Return the original frame. */
1045 return frame;
1046 else
1047 /* There were no acceptable frames in the list before FRAME; otherwise,
1048 we would have returned directly from the loop. Since PREV is the last
1049 acceptable frame in the list, return it. */
1050 return prev;
1054 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1055 doc: /* Return the next frame in the frame list after FRAME.
1056 It considers only frames on the same terminal as FRAME.
1057 By default, skip minibuffer-only frames.
1058 If omitted, FRAME defaults to the selected frame.
1059 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1060 If MINIFRAME is a window, include only its own frame
1061 and any frame now using that window as the minibuffer.
1062 If MINIFRAME is `visible', include all visible frames.
1063 If MINIFRAME is 0, include all visible and iconified frames.
1064 Otherwise, include all frames. */)
1065 (frame, miniframe)
1066 Lisp_Object frame, miniframe;
1068 if (NILP (frame))
1069 frame = selected_frame;
1071 CHECK_LIVE_FRAME (frame);
1072 return next_frame (frame, miniframe);
1075 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1076 doc: /* Return the previous frame in the frame list before FRAME.
1077 It considers only frames on the same terminal as FRAME.
1078 By default, skip minibuffer-only frames.
1079 If omitted, FRAME defaults to the selected frame.
1080 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1081 If MINIFRAME is a window, include only its own frame
1082 and any frame now using that window as the minibuffer.
1083 If MINIFRAME is `visible', include all visible frames.
1084 If MINIFRAME is 0, include all visible and iconified frames.
1085 Otherwise, include all frames. */)
1086 (frame, miniframe)
1087 Lisp_Object frame, miniframe;
1089 if (NILP (frame))
1090 frame = selected_frame;
1091 CHECK_LIVE_FRAME (frame);
1092 return prev_frame (frame, miniframe);
1095 /* Return 1 if it is ok to delete frame F;
1096 0 if all frames aside from F are invisible.
1097 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1100 other_visible_frames (f)
1101 FRAME_PTR f;
1103 /* We know the selected frame is visible,
1104 so if F is some other frame, it can't be the sole visible one. */
1105 if (f == SELECTED_FRAME ())
1107 Lisp_Object frames;
1108 int count = 0;
1110 for (frames = Vframe_list;
1111 CONSP (frames);
1112 frames = XCDR (frames))
1114 Lisp_Object this;
1116 this = XCAR (frames);
1117 /* Verify that the frame's window still exists
1118 and we can still talk to it. And note any recent change
1119 in visibility. */
1120 #ifdef HAVE_WINDOW_SYSTEM
1121 if (FRAME_WINDOW_P (XFRAME (this)))
1123 x_sync (XFRAME (this));
1124 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1126 #endif
1128 if (FRAME_VISIBLE_P (XFRAME (this))
1129 || FRAME_ICONIFIED_P (XFRAME (this))
1130 /* Allow deleting the terminal frame when at least
1131 one X frame exists! */
1132 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1133 count++;
1135 return count > 1;
1137 return 1;
1140 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1141 doc: /* Delete FRAME, permanently eliminating it from use.
1142 If omitted, FRAME defaults to the selected frame.
1143 A frame may not be deleted if its minibuffer is used by other frames.
1144 Normally, you may not delete a frame if all other frames are invisible,
1145 but if the second optional argument FORCE is non-nil, you may do so.
1147 This function runs `delete-frame-functions' before actually deleting the
1148 frame, unless the frame is a tooltip.
1149 The functions are run with one arg, the frame to be deleted. */)
1150 (frame, force)
1151 Lisp_Object frame, force;
1153 struct frame *f;
1154 struct frame *sf = SELECTED_FRAME ();
1155 int minibuffer_selected;
1157 if (EQ (frame, Qnil))
1159 f = sf;
1160 XSETFRAME (frame, f);
1162 else
1164 CHECK_FRAME (frame);
1165 f = XFRAME (frame);
1168 if (! FRAME_LIVE_P (f))
1169 return Qnil;
1171 if (NILP (force) && !other_visible_frames (f)
1172 #ifdef MAC_OS8
1173 /* Terminal frame deleted before any other visible frames are
1174 created. */
1175 && strcmp (SDATA (f->name), "F1") != 0
1176 #endif
1178 error ("Attempt to delete the sole visible or iconified frame");
1180 #if 0
1181 /* This is a nice idea, but x_connection_closed needs to be able
1182 to delete the last frame, if it is gone. */
1183 if (NILP (XCDR (Vframe_list)))
1184 error ("Attempt to delete the only frame");
1185 #endif
1187 /* Does this frame have a minibuffer, and is it the surrogate
1188 minibuffer for any other frame? */
1189 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1191 Lisp_Object frames;
1193 for (frames = Vframe_list;
1194 CONSP (frames);
1195 frames = XCDR (frames))
1197 Lisp_Object this;
1198 this = XCAR (frames);
1200 if (! EQ (this, frame)
1201 && EQ (frame,
1202 WINDOW_FRAME (XWINDOW
1203 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1204 error ("Attempt to delete a surrogate minibuffer frame");
1208 /* Run `delete-frame-functions' unless frame is a tooltip. */
1209 if (!NILP (Vrun_hooks)
1210 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1212 Lisp_Object args[2];
1213 args[0] = intern ("delete-frame-functions");
1214 args[1] = frame;
1215 Frun_hook_with_args (2, args);
1218 minibuffer_selected = EQ (minibuf_window, selected_window);
1220 /* Don't let the frame remain selected. */
1221 if (f == sf)
1223 Lisp_Object tail, frame1;
1225 /* Look for another visible frame on the same terminal. */
1226 frame1 = next_frame (frame, Qvisible);
1228 /* If there is none, find *some* other frame. */
1229 if (NILP (frame1) || EQ (frame1, frame))
1231 FOR_EACH_FRAME (tail, frame1)
1233 if (! EQ (frame, frame1))
1234 break;
1238 do_switch_frame (frame1, 0, 1);
1239 sf = SELECTED_FRAME ();
1242 /* Don't allow minibuf_window to remain on a deleted frame. */
1243 if (EQ (f->minibuffer_window, minibuf_window))
1245 Fset_window_buffer (sf->minibuffer_window,
1246 XWINDOW (minibuf_window)->buffer, Qnil);
1247 minibuf_window = sf->minibuffer_window;
1249 /* If the dying minibuffer window was selected,
1250 select the new one. */
1251 if (minibuffer_selected)
1252 Fselect_window (minibuf_window, Qnil);
1255 /* Don't let echo_area_window to remain on a deleted frame. */
1256 if (EQ (f->minibuffer_window, echo_area_window))
1257 echo_area_window = sf->minibuffer_window;
1259 /* Clear any X selections for this frame. */
1260 #ifdef HAVE_X_WINDOWS
1261 if (FRAME_X_P (f))
1262 x_clear_frame_selections (f);
1263 #endif
1265 /* Free glyphs.
1266 This function must be called before the window tree of the
1267 frame is deleted because windows contain dynamically allocated
1268 memory. */
1269 free_glyphs (f);
1271 /* Mark all the windows that used to be on FRAME as deleted, and then
1272 remove the reference to them. */
1273 delete_all_subwindows (XWINDOW (f->root_window));
1274 f->root_window = Qnil;
1276 Vframe_list = Fdelq (frame, Vframe_list);
1277 FRAME_SET_VISIBLE (f, 0);
1279 if (f->namebuf)
1280 xfree (f->namebuf);
1281 if (FRAME_INSERT_COST (f))
1282 xfree (FRAME_INSERT_COST (f));
1283 if (FRAME_DELETEN_COST (f))
1284 xfree (FRAME_DELETEN_COST (f));
1285 if (FRAME_INSERTN_COST (f))
1286 xfree (FRAME_INSERTN_COST (f));
1287 if (FRAME_DELETE_COST (f))
1288 xfree (FRAME_DELETE_COST (f));
1289 if (FRAME_MESSAGE_BUF (f))
1290 xfree (FRAME_MESSAGE_BUF (f));
1292 /* Since some events are handled at the interrupt level, we may get
1293 an event for f at any time; if we zero out the frame's display
1294 now, then we may trip up the event-handling code. Instead, we'll
1295 promise that the display of the frame must be valid until we have
1296 called the window-system-dependent frame destruction routine. */
1298 /* I think this should be done with a hook. */
1299 #ifdef HAVE_WINDOW_SYSTEM
1300 if (FRAME_WINDOW_P (f))
1301 x_destroy_window (f);
1302 #endif
1304 f->output_data.nothing = 0;
1306 /* If we've deleted the last_nonminibuf_frame, then try to find
1307 another one. */
1308 if (f == last_nonminibuf_frame)
1310 Lisp_Object frames;
1312 last_nonminibuf_frame = 0;
1314 for (frames = Vframe_list;
1315 CONSP (frames);
1316 frames = XCDR (frames))
1318 f = XFRAME (XCAR (frames));
1319 if (!FRAME_MINIBUF_ONLY_P (f))
1321 last_nonminibuf_frame = f;
1322 break;
1327 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1328 find another one. Prefer minibuffer-only frames, but also notice
1329 frames with other windows. */
1330 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame))
1332 Lisp_Object frames;
1334 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1335 Lisp_Object frame_with_minibuf;
1336 /* Some frame we found on the same kboard, or nil if there are none. */
1337 Lisp_Object frame_on_same_kboard;
1339 frame_on_same_kboard = Qnil;
1340 frame_with_minibuf = Qnil;
1342 for (frames = Vframe_list;
1343 CONSP (frames);
1344 frames = XCDR (frames))
1346 Lisp_Object this;
1347 struct frame *f1;
1349 this = XCAR (frames);
1350 if (!FRAMEP (this))
1351 abort ();
1352 f1 = XFRAME (this);
1354 /* Consider only frames on the same kboard
1355 and only those with minibuffers. */
1356 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)
1357 && FRAME_HAS_MINIBUF_P (f1))
1359 frame_with_minibuf = this;
1360 if (FRAME_MINIBUF_ONLY_P (f1))
1361 break;
1364 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1365 frame_on_same_kboard = this;
1368 if (!NILP (frame_on_same_kboard))
1370 /* We know that there must be some frame with a minibuffer out
1371 there. If this were not true, all of the frames present
1372 would have to be minibufferless, which implies that at some
1373 point their minibuffer frames must have been deleted, but
1374 that is prohibited at the top; you can't delete surrogate
1375 minibuffer frames. */
1376 if (NILP (frame_with_minibuf))
1377 abort ();
1379 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf;
1381 else
1382 /* No frames left on this kboard--say no minibuffer either. */
1383 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil;
1386 /* Cause frame titles to update--necessary if we now have just one frame. */
1387 update_mode_lines = 1;
1389 return Qnil;
1392 /* Return mouse position in character cell units. */
1394 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1395 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1396 The position is given in character cells, where (0, 0) is the
1397 upper-left corner.
1398 If Emacs is running on a mouseless terminal or hasn't been programmed
1399 to read the mouse position, it returns the selected frame for FRAME
1400 and nil for X and Y.
1401 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1402 passing the normal return value to that function as an argument,
1403 and returns whatever that function returns. */)
1406 FRAME_PTR f;
1407 Lisp_Object lispy_dummy;
1408 enum scroll_bar_part party_dummy;
1409 Lisp_Object x, y, retval;
1410 int col, row;
1411 unsigned long long_dummy;
1412 struct gcpro gcpro1;
1414 f = SELECTED_FRAME ();
1415 x = y = Qnil;
1417 #ifdef HAVE_MOUSE
1418 /* It's okay for the hook to refrain from storing anything. */
1419 if (mouse_position_hook)
1420 (*mouse_position_hook) (&f, -1,
1421 &lispy_dummy, &party_dummy,
1422 &x, &y,
1423 &long_dummy);
1424 if (! NILP (x))
1426 col = XINT (x);
1427 row = XINT (y);
1428 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1429 XSETINT (x, col);
1430 XSETINT (y, row);
1432 #endif
1433 XSETFRAME (lispy_dummy, f);
1434 retval = Fcons (lispy_dummy, Fcons (x, y));
1435 GCPRO1 (retval);
1436 if (!NILP (Vmouse_position_function))
1437 retval = call1 (Vmouse_position_function, retval);
1438 RETURN_UNGCPRO (retval);
1441 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1442 Smouse_pixel_position, 0, 0, 0,
1443 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1444 The position is given in pixel units, where (0, 0) is the
1445 upper-left corner.
1446 If Emacs is running on a mouseless terminal or hasn't been programmed
1447 to read the mouse position, it returns the selected frame for FRAME
1448 and nil for X and Y. */)
1451 FRAME_PTR f;
1452 Lisp_Object lispy_dummy;
1453 enum scroll_bar_part party_dummy;
1454 Lisp_Object x, y;
1455 unsigned long long_dummy;
1457 f = SELECTED_FRAME ();
1458 x = y = Qnil;
1460 #ifdef HAVE_MOUSE
1461 /* It's okay for the hook to refrain from storing anything. */
1462 if (mouse_position_hook)
1463 (*mouse_position_hook) (&f, -1,
1464 &lispy_dummy, &party_dummy,
1465 &x, &y,
1466 &long_dummy);
1467 #endif
1468 XSETFRAME (lispy_dummy, f);
1469 return Fcons (lispy_dummy, Fcons (x, y));
1472 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1473 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1474 Coordinates are relative to the frame, not a window,
1475 so the coordinates of the top left character in the frame
1476 may be nonzero due to left-hand scroll bars or the menu bar.
1478 This function is a no-op for an X frame that is not visible.
1479 If you have just created a frame, you must wait for it to become visible
1480 before calling this function on it, like this.
1481 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1482 (frame, x, y)
1483 Lisp_Object frame, x, y;
1485 CHECK_LIVE_FRAME (frame);
1486 CHECK_NUMBER (x);
1487 CHECK_NUMBER (y);
1489 /* I think this should be done with a hook. */
1490 #ifdef HAVE_WINDOW_SYSTEM
1491 if (FRAME_WINDOW_P (XFRAME (frame)))
1492 /* Warping the mouse will cause enternotify and focus events. */
1493 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1494 #else
1495 #if defined (MSDOS) && defined (HAVE_MOUSE)
1496 if (FRAME_MSDOS_P (XFRAME (frame)))
1498 Fselect_frame (frame, Qnil);
1499 mouse_moveto (XINT (x), XINT (y));
1501 #endif
1502 #endif
1504 return Qnil;
1507 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1508 Sset_mouse_pixel_position, 3, 3, 0,
1509 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1510 Note, this is a no-op for an X frame that is not visible.
1511 If you have just created a frame, you must wait for it to become visible
1512 before calling this function on it, like this.
1513 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1514 (frame, x, y)
1515 Lisp_Object frame, x, y;
1517 CHECK_LIVE_FRAME (frame);
1518 CHECK_NUMBER (x);
1519 CHECK_NUMBER (y);
1521 /* I think this should be done with a hook. */
1522 #ifdef HAVE_WINDOW_SYSTEM
1523 if (FRAME_WINDOW_P (XFRAME (frame)))
1524 /* Warping the mouse will cause enternotify and focus events. */
1525 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1526 #else
1527 #if defined (MSDOS) && defined (HAVE_MOUSE)
1528 if (FRAME_MSDOS_P (XFRAME (frame)))
1530 Fselect_frame (frame, Qnil);
1531 mouse_moveto (XINT (x), XINT (y));
1533 #endif
1534 #endif
1536 return Qnil;
1539 static void make_frame_visible_1 P_ ((Lisp_Object));
1541 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1542 0, 1, "",
1543 doc: /* Make the frame FRAME visible (assuming it is an X window).
1544 If omitted, FRAME defaults to the currently selected frame. */)
1545 (frame)
1546 Lisp_Object frame;
1548 if (NILP (frame))
1549 frame = selected_frame;
1551 CHECK_LIVE_FRAME (frame);
1553 /* I think this should be done with a hook. */
1554 #ifdef HAVE_WINDOW_SYSTEM
1555 if (FRAME_WINDOW_P (XFRAME (frame)))
1557 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1558 x_make_frame_visible (XFRAME (frame));
1560 #endif
1562 make_frame_visible_1 (XFRAME (frame)->root_window);
1564 /* Make menu bar update for the Buffers and Frames menus. */
1565 windows_or_buffers_changed++;
1567 return frame;
1570 /* Update the display_time slot of the buffers shown in WINDOW
1571 and all its descendents. */
1573 static void
1574 make_frame_visible_1 (window)
1575 Lisp_Object window;
1577 struct window *w;
1579 for (;!NILP (window); window = w->next)
1581 w = XWINDOW (window);
1583 if (!NILP (w->buffer))
1584 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1586 if (!NILP (w->vchild))
1587 make_frame_visible_1 (w->vchild);
1588 if (!NILP (w->hchild))
1589 make_frame_visible_1 (w->hchild);
1593 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1594 0, 2, "",
1595 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1596 If omitted, FRAME defaults to the currently selected frame.
1597 Normally you may not make FRAME invisible if all other frames are invisible,
1598 but if the second optional argument FORCE is non-nil, you may do so. */)
1599 (frame, force)
1600 Lisp_Object frame, force;
1602 if (NILP (frame))
1603 frame = selected_frame;
1605 CHECK_LIVE_FRAME (frame);
1607 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1608 error ("Attempt to make invisible the sole visible or iconified frame");
1610 #if 0 /* This isn't logically necessary, and it can do GC. */
1611 /* Don't let the frame remain selected. */
1612 if (EQ (frame, selected_frame))
1613 do_switch_frame (next_frame (frame, Qt), 0, 0)
1614 #endif
1616 /* Don't allow minibuf_window to remain on a deleted frame. */
1617 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1619 struct frame *sf = XFRAME (selected_frame);
1620 Fset_window_buffer (sf->minibuffer_window,
1621 XWINDOW (minibuf_window)->buffer, Qnil);
1622 minibuf_window = sf->minibuffer_window;
1625 /* I think this should be done with a hook. */
1626 #ifdef HAVE_WINDOW_SYSTEM
1627 if (FRAME_WINDOW_P (XFRAME (frame)))
1628 x_make_frame_invisible (XFRAME (frame));
1629 #endif
1631 /* Make menu bar update for the Buffers and Frames menus. */
1632 windows_or_buffers_changed++;
1634 return Qnil;
1637 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1638 0, 1, "",
1639 doc: /* Make the frame FRAME into an icon.
1640 If omitted, FRAME defaults to the currently selected frame. */)
1641 (frame)
1642 Lisp_Object frame;
1644 if (NILP (frame))
1645 frame = selected_frame;
1647 CHECK_LIVE_FRAME (frame);
1649 #if 0 /* This isn't logically necessary, and it can do GC. */
1650 /* Don't let the frame remain selected. */
1651 if (EQ (frame, selected_frame))
1652 Fhandle_switch_frame (next_frame (frame, Qt), Qnil);
1653 #endif
1655 /* Don't allow minibuf_window to remain on a deleted frame. */
1656 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1658 struct frame *sf = XFRAME (selected_frame);
1659 Fset_window_buffer (sf->minibuffer_window,
1660 XWINDOW (minibuf_window)->buffer, Qnil);
1661 minibuf_window = sf->minibuffer_window;
1664 /* I think this should be done with a hook. */
1665 #ifdef HAVE_WINDOW_SYSTEM
1666 if (FRAME_WINDOW_P (XFRAME (frame)))
1667 x_iconify_frame (XFRAME (frame));
1668 #endif
1670 /* Make menu bar update for the Buffers and Frames menus. */
1671 windows_or_buffers_changed++;
1673 return Qnil;
1676 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1677 1, 1, 0,
1678 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1679 A frame that is not \"visible\" is not updated and, if it works through
1680 a window system, it may not show at all.
1681 Return the symbol `icon' if frame is visible only as an icon. */)
1682 (frame)
1683 Lisp_Object frame;
1685 CHECK_LIVE_FRAME (frame);
1687 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1689 if (FRAME_VISIBLE_P (XFRAME (frame)))
1690 return Qt;
1691 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1692 return Qicon;
1693 return Qnil;
1696 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1697 0, 0, 0,
1698 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1701 Lisp_Object tail, frame;
1702 struct frame *f;
1703 Lisp_Object value;
1705 value = Qnil;
1706 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1708 frame = XCAR (tail);
1709 if (!FRAMEP (frame))
1710 continue;
1711 f = XFRAME (frame);
1712 if (FRAME_VISIBLE_P (f))
1713 value = Fcons (frame, value);
1715 return value;
1719 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1720 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1721 If FRAME is invisible, make it visible.
1722 If you don't specify a frame, the selected frame is used.
1723 If Emacs is displaying on an ordinary terminal or some other device which
1724 doesn't support multiple overlapping frames, this function does nothing. */)
1725 (frame)
1726 Lisp_Object frame;
1728 if (NILP (frame))
1729 frame = selected_frame;
1731 CHECK_LIVE_FRAME (frame);
1733 /* Do like the documentation says. */
1734 Fmake_frame_visible (frame);
1736 if (frame_raise_lower_hook)
1737 (*frame_raise_lower_hook) (XFRAME (frame), 1);
1739 return Qnil;
1742 /* Should we have a corresponding function called Flower_Power? */
1743 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1744 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1745 If you don't specify a frame, the selected frame is used.
1746 If Emacs is displaying on an ordinary terminal or some other device which
1747 doesn't support multiple overlapping frames, this function does nothing. */)
1748 (frame)
1749 Lisp_Object frame;
1751 if (NILP (frame))
1752 frame = selected_frame;
1754 CHECK_LIVE_FRAME (frame);
1756 if (frame_raise_lower_hook)
1757 (*frame_raise_lower_hook) (XFRAME (frame), 0);
1759 return Qnil;
1763 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1764 1, 2, 0,
1765 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1766 In other words, switch-frame events caused by events in FRAME will
1767 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1768 FOCUS-FRAME after reading an event typed at FRAME.
1770 If FOCUS-FRAME is omitted or nil, any existing redirection is
1771 cancelled, and the frame again receives its own keystrokes.
1773 Focus redirection is useful for temporarily redirecting keystrokes to
1774 a surrogate minibuffer frame when a frame doesn't have its own
1775 minibuffer window.
1777 A frame's focus redirection can be changed by select-frame. If frame
1778 FOO is selected, and then a different frame BAR is selected, any
1779 frames redirecting their focus to FOO are shifted to redirect their
1780 focus to BAR. This allows focus redirection to work properly when the
1781 user switches from one frame to another using `select-window'.
1783 This means that a frame whose focus is redirected to itself is treated
1784 differently from a frame whose focus is redirected to nil; the former
1785 is affected by select-frame, while the latter is not.
1787 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1788 (frame, focus_frame)
1789 Lisp_Object frame, focus_frame;
1791 /* Note that we don't check for a live frame here. It's reasonable
1792 to redirect the focus of a frame you're about to delete, if you
1793 know what other frame should receive those keystrokes. */
1794 CHECK_FRAME (frame);
1796 if (! NILP (focus_frame))
1797 CHECK_LIVE_FRAME (focus_frame);
1799 XFRAME (frame)->focus_frame = focus_frame;
1801 if (frame_rehighlight_hook)
1802 (*frame_rehighlight_hook) (XFRAME (frame));
1804 return Qnil;
1808 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1809 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1810 This returns nil if FRAME's focus is not redirected.
1811 See `redirect-frame-focus'. */)
1812 (frame)
1813 Lisp_Object frame;
1815 CHECK_LIVE_FRAME (frame);
1817 return FRAME_FOCUS_FRAME (XFRAME (frame));
1822 /* Return the value of frame parameter PROP in frame FRAME. */
1824 Lisp_Object
1825 get_frame_param (frame, prop)
1826 register struct frame *frame;
1827 Lisp_Object prop;
1829 register Lisp_Object tem;
1831 tem = Fassq (prop, frame->param_alist);
1832 if (EQ (tem, Qnil))
1833 return tem;
1834 return Fcdr (tem);
1837 /* Return the buffer-predicate of the selected frame. */
1839 Lisp_Object
1840 frame_buffer_predicate (frame)
1841 Lisp_Object frame;
1843 return XFRAME (frame)->buffer_predicate;
1846 /* Return the buffer-list of the selected frame. */
1848 Lisp_Object
1849 frame_buffer_list (frame)
1850 Lisp_Object frame;
1852 return XFRAME (frame)->buffer_list;
1855 /* Set the buffer-list of the selected frame. */
1857 void
1858 set_frame_buffer_list (frame, list)
1859 Lisp_Object frame, list;
1861 XFRAME (frame)->buffer_list = list;
1864 /* Discard BUFFER from the buffer-list of each frame. */
1866 void
1867 frames_discard_buffer (buffer)
1868 Lisp_Object buffer;
1870 Lisp_Object frame, tail;
1872 FOR_EACH_FRAME (tail, frame)
1874 XFRAME (frame)->buffer_list
1875 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1879 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1880 If the alist already has an element for PROP, we change it. */
1882 void
1883 store_in_alist (alistptr, prop, val)
1884 Lisp_Object *alistptr, val;
1885 Lisp_Object prop;
1887 register Lisp_Object tem;
1889 tem = Fassq (prop, *alistptr);
1890 if (EQ (tem, Qnil))
1891 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1892 else
1893 Fsetcdr (tem, val);
1896 static int
1897 frame_name_fnn_p (str, len)
1898 char *str;
1899 int len;
1901 if (len > 1 && str[0] == 'F')
1903 char *end_ptr;
1905 strtol (str + 1, &end_ptr, 10);
1907 if (end_ptr == str + len)
1908 return 1;
1910 return 0;
1913 /* Set the name of the terminal frame. Also used by MSDOS frames.
1914 Modeled after x_set_name which is used for WINDOW frames. */
1916 void
1917 set_term_frame_name (f, name)
1918 struct frame *f;
1919 Lisp_Object name;
1921 f->explicit_name = ! NILP (name);
1923 /* If NAME is nil, set the name to F<num>. */
1924 if (NILP (name))
1926 char namebuf[20];
1928 /* Check for no change needed in this very common case
1929 before we do any consing. */
1930 if (frame_name_fnn_p (SDATA (f->name),
1931 SBYTES (f->name)))
1932 return;
1934 terminal_frame_count++;
1935 sprintf (namebuf, "F%d", terminal_frame_count);
1936 name = build_string (namebuf);
1938 else
1940 CHECK_STRING (name);
1942 /* Don't change the name if it's already NAME. */
1943 if (! NILP (Fstring_equal (name, f->name)))
1944 return;
1946 /* Don't allow the user to set the frame name to F<num>, so it
1947 doesn't clash with the names we generate for terminal frames. */
1948 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
1949 error ("Frame names of the form F<num> are usurped by Emacs");
1952 f->name = name;
1953 update_mode_lines = 1;
1956 void
1957 store_frame_param (f, prop, val)
1958 struct frame *f;
1959 Lisp_Object prop, val;
1961 register Lisp_Object old_alist_elt;
1963 /* The buffer-alist parameter is stored in a special place and is
1964 not in the alist. */
1965 if (EQ (prop, Qbuffer_list))
1967 f->buffer_list = val;
1968 return;
1971 /* If PROP is a symbol which is supposed to have frame-local values,
1972 and it is set up based on this frame, switch to the global
1973 binding. That way, we can create or alter the frame-local binding
1974 without messing up the symbol's status. */
1975 if (SYMBOLP (prop))
1977 Lisp_Object valcontents;
1978 valcontents = SYMBOL_VALUE (prop);
1979 if ((BUFFER_LOCAL_VALUEP (valcontents)
1980 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1981 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1982 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
1983 swap_in_global_binding (prop);
1986 #ifndef WINDOWSNT
1987 /* The tty color mode needs to be set before the frame's parameter
1988 alist is updated with the new value, because set_tty_color_mode
1989 wants to look at the old mode. */
1990 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
1991 set_tty_color_mode (f, val);
1992 #endif
1994 /* Update the frame parameter alist. */
1995 old_alist_elt = Fassq (prop, f->param_alist);
1996 if (EQ (old_alist_elt, Qnil))
1997 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
1998 else
1999 Fsetcdr (old_alist_elt, val);
2001 /* Update some other special parameters in their special places
2002 in addition to the alist. */
2004 if (EQ (prop, Qbuffer_predicate))
2005 f->buffer_predicate = val;
2007 if (! FRAME_WINDOW_P (f))
2009 if (EQ (prop, Qmenu_bar_lines))
2010 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2011 else if (EQ (prop, Qname))
2012 set_term_frame_name (f, val);
2015 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2017 if (! MINI_WINDOW_P (XWINDOW (val)))
2018 error ("Surrogate minibuffer windows must be minibuffer windows.");
2020 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2021 && !EQ (val, f->minibuffer_window))
2022 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2024 /* Install the chosen minibuffer window, with proper buffer. */
2025 f->minibuffer_window = val;
2029 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2030 doc: /* Return the parameters-alist of frame FRAME.
2031 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2032 The meaningful PARMs depend on the kind of frame.
2033 If FRAME is omitted, return information on the currently selected frame. */)
2034 (frame)
2035 Lisp_Object frame;
2037 Lisp_Object alist;
2038 FRAME_PTR f;
2039 int height, width;
2040 struct gcpro gcpro1;
2042 if (NILP (frame))
2043 frame = selected_frame;
2045 CHECK_FRAME (frame);
2046 f = XFRAME (frame);
2048 if (!FRAME_LIVE_P (f))
2049 return Qnil;
2051 alist = Fcopy_alist (f->param_alist);
2052 GCPRO1 (alist);
2054 if (!FRAME_WINDOW_P (f))
2056 int fg = FRAME_FOREGROUND_PIXEL (f);
2057 int bg = FRAME_BACKGROUND_PIXEL (f);
2058 Lisp_Object elt;
2060 /* If the frame's parameter alist says the colors are
2061 unspecified and reversed, take the frame's background pixel
2062 for foreground and vice versa. */
2063 elt = Fassq (Qforeground_color, alist);
2064 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2066 if (strncmp (SDATA (XCDR (elt)),
2067 unspecified_bg,
2068 SCHARS (XCDR (elt))) == 0)
2069 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2070 else if (strncmp (SDATA (XCDR (elt)),
2071 unspecified_fg,
2072 SCHARS (XCDR (elt))) == 0)
2073 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2075 else
2076 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2077 elt = Fassq (Qbackground_color, alist);
2078 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2080 if (strncmp (SDATA (XCDR (elt)),
2081 unspecified_fg,
2082 SCHARS (XCDR (elt))) == 0)
2083 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2084 else if (strncmp (SDATA (XCDR (elt)),
2085 unspecified_bg,
2086 SCHARS (XCDR (elt))) == 0)
2087 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2089 else
2090 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2091 store_in_alist (&alist, intern ("font"),
2092 build_string (FRAME_MSDOS_P (f)
2093 ? "ms-dos"
2094 : FRAME_W32_P (f) ? "w32term"
2095 :"tty"));
2097 store_in_alist (&alist, Qname, f->name);
2098 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2099 store_in_alist (&alist, Qheight, make_number (height));
2100 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2101 store_in_alist (&alist, Qwidth, make_number (width));
2102 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2103 store_in_alist (&alist, Qminibuffer,
2104 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2105 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2106 : FRAME_MINIBUF_WINDOW (f)));
2107 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2108 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2110 /* I think this should be done with a hook. */
2111 #ifdef HAVE_WINDOW_SYSTEM
2112 if (FRAME_WINDOW_P (f))
2113 x_report_frame_params (f, &alist);
2114 else
2115 #endif
2117 /* This ought to be correct in f->param_alist for an X frame. */
2118 Lisp_Object lines;
2119 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2120 store_in_alist (&alist, Qmenu_bar_lines, lines);
2123 UNGCPRO;
2124 return alist;
2128 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2129 doc: /* Return FRAME's value for parameter PARAMETER.
2130 If FRAME is nil, describe the currently selected frame. */)
2131 (frame, parameter)
2132 Lisp_Object frame, parameter;
2134 struct frame *f;
2135 Lisp_Object value;
2137 if (NILP (frame))
2138 frame = selected_frame;
2139 else
2140 CHECK_FRAME (frame);
2141 CHECK_SYMBOL (parameter);
2143 f = XFRAME (frame);
2144 value = Qnil;
2146 if (FRAME_LIVE_P (f))
2148 /* Avoid consing in frequent cases. */
2149 if (EQ (parameter, Qname))
2150 value = f->name;
2151 #ifdef HAVE_X_WINDOWS
2152 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2153 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2154 #endif /* HAVE_X_WINDOWS */
2155 else if (EQ (parameter, Qbackground_color)
2156 || EQ (parameter, Qforeground_color))
2158 value = Fassq (parameter, f->param_alist);
2159 if (CONSP (value))
2161 value = XCDR (value);
2162 /* Fframe_parameters puts the actual fg/bg color names,
2163 even if f->param_alist says otherwise. This is
2164 important when param_alist's notion of colors is
2165 "unspecified". We need to do the same here. */
2166 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2168 const char *color_name;
2169 EMACS_INT csz;
2171 if (EQ (parameter, Qbackground_color))
2173 color_name = SDATA (value);
2174 csz = SCHARS (value);
2175 if (strncmp (color_name, unspecified_bg, csz) == 0)
2176 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2177 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2178 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2180 else if (EQ (parameter, Qforeground_color))
2182 color_name = SDATA (value);
2183 csz = SCHARS (value);
2184 if (strncmp (color_name, unspecified_fg, csz) == 0)
2185 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2186 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2187 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2191 else
2192 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2194 else if (EQ (parameter, Qdisplay_type)
2195 || EQ (parameter, Qbackground_mode))
2196 value = Fcdr (Fassq (parameter, f->param_alist));
2197 else
2198 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2201 return value;
2205 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2206 Smodify_frame_parameters, 2, 2, 0,
2207 doc: /* Modify the parameters of frame FRAME according to ALIST.
2208 If FRAME is nil, it defaults to the selected frame.
2209 ALIST is an alist of parameters to change and their new values.
2210 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2211 The meaningful PARMs depend on the kind of frame.
2212 Undefined PARMs are ignored, but stored in the frame's parameter list
2213 so that `frame-parameters' will return them.
2215 The value of frame parameter FOO can also be accessed
2216 as a frame-local binding for the variable FOO, if you have
2217 enabled such bindings for that variable with `make-variable-frame-local'. */)
2218 (frame, alist)
2219 Lisp_Object frame, alist;
2221 FRAME_PTR f;
2222 register Lisp_Object tail, prop, val;
2223 int count = SPECPDL_INDEX ();
2225 /* Bind this to t to inhibit initialization of the default face from
2226 X resources in face-set-after-frame-default. If we don't inhibit
2227 this, modifying the `font' frame parameter, for example, while
2228 there is a `default.attributeFont' X resource, won't work,
2229 because `default's font is reset to the value of the X resource
2230 and that resets the `font' frame parameter. */
2231 specbind (Qinhibit_default_face_x_resources, Qt);
2233 if (EQ (frame, Qnil))
2234 frame = selected_frame;
2235 CHECK_LIVE_FRAME (frame);
2236 f = XFRAME (frame);
2238 /* I think this should be done with a hook. */
2239 #ifdef HAVE_WINDOW_SYSTEM
2240 if (FRAME_WINDOW_P (f))
2241 x_set_frame_parameters (f, alist);
2242 else
2243 #endif
2244 #ifdef MSDOS
2245 if (FRAME_MSDOS_P (f))
2246 IT_set_frame_parameters (f, alist);
2247 else
2248 #endif
2251 int length = XINT (Flength (alist));
2252 int i;
2253 Lisp_Object *parms
2254 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2255 Lisp_Object *values
2256 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2258 /* Extract parm names and values into those vectors. */
2260 i = 0;
2261 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2263 Lisp_Object elt;
2265 elt = Fcar (tail);
2266 parms[i] = Fcar (elt);
2267 values[i] = Fcdr (elt);
2268 i++;
2271 /* Now process them in reverse of specified order. */
2272 for (i--; i >= 0; i--)
2274 prop = parms[i];
2275 val = values[i];
2276 store_frame_param (f, prop, val);
2280 return unbind_to (count, Qnil);
2283 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2284 0, 1, 0,
2285 doc: /* Height in pixels of a line in the font in frame FRAME.
2286 If FRAME is omitted, the selected frame is used.
2287 For a terminal frame, the value is always 1. */)
2288 (frame)
2289 Lisp_Object frame;
2291 struct frame *f;
2293 if (NILP (frame))
2294 frame = selected_frame;
2295 CHECK_FRAME (frame);
2296 f = XFRAME (frame);
2298 #ifdef HAVE_WINDOW_SYSTEM
2299 if (FRAME_WINDOW_P (f))
2300 return make_number (x_char_height (f));
2301 else
2302 #endif
2303 return make_number (1);
2307 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2308 0, 1, 0,
2309 doc: /* Width in pixels of characters in the font in frame FRAME.
2310 If FRAME is omitted, the selected frame is used.
2311 The width is the same for all characters, because
2312 currently Emacs supports only fixed-width fonts.
2313 For a terminal screen, the value is always 1. */)
2314 (frame)
2315 Lisp_Object frame;
2317 struct frame *f;
2319 if (NILP (frame))
2320 frame = selected_frame;
2321 CHECK_FRAME (frame);
2322 f = XFRAME (frame);
2324 #ifdef HAVE_WINDOW_SYSTEM
2325 if (FRAME_WINDOW_P (f))
2326 return make_number (x_char_width (f));
2327 else
2328 #endif
2329 return make_number (1);
2332 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2333 Sframe_pixel_height, 0, 1, 0,
2334 doc: /* Return a FRAME's height in pixels.
2335 This counts only the height available for text lines,
2336 not menu bars on window-system Emacs frames.
2337 For a terminal frame, the result really gives the height in characters.
2338 If FRAME is omitted, the selected frame is used. */)
2339 (frame)
2340 Lisp_Object frame;
2342 struct frame *f;
2344 if (NILP (frame))
2345 frame = selected_frame;
2346 CHECK_FRAME (frame);
2347 f = XFRAME (frame);
2349 #ifdef HAVE_WINDOW_SYSTEM
2350 if (FRAME_WINDOW_P (f))
2351 return make_number (x_pixel_height (f));
2352 else
2353 #endif
2354 return make_number (FRAME_LINES (f));
2357 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2358 Sframe_pixel_width, 0, 1, 0,
2359 doc: /* Return FRAME's width in pixels.
2360 For a terminal frame, the result really gives the width in characters.
2361 If FRAME is omitted, the selected frame is used. */)
2362 (frame)
2363 Lisp_Object frame;
2365 struct frame *f;
2367 if (NILP (frame))
2368 frame = selected_frame;
2369 CHECK_FRAME (frame);
2370 f = XFRAME (frame);
2372 #ifdef HAVE_WINDOW_SYSTEM
2373 if (FRAME_WINDOW_P (f))
2374 return make_number (x_pixel_width (f));
2375 else
2376 #endif
2377 return make_number (FRAME_COLS (f));
2380 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2381 doc: /* Specify that the frame FRAME has LINES lines.
2382 Optional third arg non-nil means that redisplay should use LINES lines
2383 but that the idea of the actual height of the frame should not be changed. */)
2384 (frame, lines, pretend)
2385 Lisp_Object frame, lines, pretend;
2387 register struct frame *f;
2389 CHECK_NUMBER (lines);
2390 if (NILP (frame))
2391 frame = selected_frame;
2392 CHECK_LIVE_FRAME (frame);
2393 f = XFRAME (frame);
2395 /* I think this should be done with a hook. */
2396 #ifdef HAVE_WINDOW_SYSTEM
2397 if (FRAME_WINDOW_P (f))
2399 if (XINT (lines) != FRAME_LINES (f))
2400 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2401 do_pending_window_change (0);
2403 else
2404 #endif
2405 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2406 return Qnil;
2409 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2410 doc: /* Specify that the frame FRAME has COLS columns.
2411 Optional third arg non-nil means that redisplay should use COLS columns
2412 but that the idea of the actual width of the frame should not be changed. */)
2413 (frame, cols, pretend)
2414 Lisp_Object frame, cols, pretend;
2416 register struct frame *f;
2417 CHECK_NUMBER (cols);
2418 if (NILP (frame))
2419 frame = selected_frame;
2420 CHECK_LIVE_FRAME (frame);
2421 f = XFRAME (frame);
2423 /* I think this should be done with a hook. */
2424 #ifdef HAVE_WINDOW_SYSTEM
2425 if (FRAME_WINDOW_P (f))
2427 if (XINT (cols) != FRAME_COLS (f))
2428 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2429 do_pending_window_change (0);
2431 else
2432 #endif
2433 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2434 return Qnil;
2437 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2438 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2439 (frame, cols, rows)
2440 Lisp_Object frame, cols, rows;
2442 register struct frame *f;
2444 CHECK_LIVE_FRAME (frame);
2445 CHECK_NUMBER (cols);
2446 CHECK_NUMBER (rows);
2447 f = XFRAME (frame);
2449 /* I think this should be done with a hook. */
2450 #ifdef HAVE_WINDOW_SYSTEM
2451 if (FRAME_WINDOW_P (f))
2453 if (XINT (rows) != FRAME_LINES (f)
2454 || XINT (cols) != FRAME_COLS (f)
2455 || f->new_text_lines || f->new_text_cols)
2456 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2457 do_pending_window_change (0);
2459 else
2460 #endif
2461 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2463 return Qnil;
2466 DEFUN ("set-frame-position", Fset_frame_position,
2467 Sset_frame_position, 3, 3, 0,
2468 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2469 This is actually the position of the upper left corner of the frame.
2470 Negative values for XOFFSET or YOFFSET are interpreted relative to
2471 the rightmost or bottommost possible position (that stays within the screen). */)
2472 (frame, xoffset, yoffset)
2473 Lisp_Object frame, xoffset, yoffset;
2475 register struct frame *f;
2477 CHECK_LIVE_FRAME (frame);
2478 CHECK_NUMBER (xoffset);
2479 CHECK_NUMBER (yoffset);
2480 f = XFRAME (frame);
2482 /* I think this should be done with a hook. */
2483 #ifdef HAVE_WINDOW_SYSTEM
2484 if (FRAME_WINDOW_P (f))
2485 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2486 #endif
2488 return Qt;
2492 /***********************************************************************
2493 Frame Parameters
2494 ***********************************************************************/
2496 /* Connect the frame-parameter names for X frames
2497 to the ways of passing the parameter values to the window system.
2499 The name of a parameter, as a Lisp symbol,
2500 has an `x-frame-parameter' property which is an integer in Lisp
2501 that is an index in this table. */
2503 struct frame_parm_table {
2504 char *name;
2505 Lisp_Object *variable;
2508 static struct frame_parm_table frame_parms[] =
2510 {"auto-raise", &Qauto_raise},
2511 {"auto-lower", &Qauto_lower},
2512 {"background-color", 0},
2513 {"border-color", &Qborder_color},
2514 {"border-width", &Qborder_width},
2515 {"cursor-color", &Qcursor_color},
2516 {"cursor-type", &Qcursor_type},
2517 {"font", 0},
2518 {"foreground-color", 0},
2519 {"icon-name", &Qicon_name},
2520 {"icon-type", &Qicon_type},
2521 {"internal-border-width", &Qinternal_border_width},
2522 {"menu-bar-lines", &Qmenu_bar_lines},
2523 {"mouse-color", &Qmouse_color},
2524 {"name", &Qname},
2525 {"scroll-bar-width", &Qscroll_bar_width},
2526 {"title", &Qtitle},
2527 {"unsplittable", &Qunsplittable},
2528 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2529 {"visibility", &Qvisibility},
2530 {"tool-bar-lines", &Qtool_bar_lines},
2531 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2532 {"scroll-bar-background", &Qscroll_bar_background},
2533 {"screen-gamma", &Qscreen_gamma},
2534 {"line-spacing", &Qline_spacing},
2535 {"left-fringe", &Qleft_fringe},
2536 {"right-fringe", &Qright_fringe},
2537 {"wait-for-wm", &Qwait_for_wm},
2538 {"fullscreen", &Qfullscreen},
2541 #ifdef HAVE_WINDOW_SYSTEM
2543 extern Lisp_Object Qbox;
2544 extern Lisp_Object Qtop;
2546 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2547 wanted positions of the WM window (not emacs window).
2548 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2549 window (FRAME_X_WINDOW).
2552 void
2553 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2554 struct frame *f;
2555 int *width;
2556 int *height;
2557 int *top_pos;
2558 int *left_pos;
2560 int newwidth = FRAME_COLS (f);
2561 int newheight = FRAME_LINES (f);
2563 *top_pos = f->top_pos;
2564 *left_pos = f->left_pos;
2566 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2568 int ph;
2570 ph = FRAME_X_DISPLAY_INFO (f)->height;
2571 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2572 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2573 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2574 *top_pos = 0;
2577 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2579 int pw;
2581 pw = FRAME_X_DISPLAY_INFO (f)->width;
2582 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2583 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2584 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2585 *left_pos = 0;
2588 *width = newwidth;
2589 *height = newheight;
2593 /* Really try to move where we want to be in case of fullscreen. Some WMs
2594 moves the window where we tell them. Some (mwm, twm) moves the outer
2595 window manager window there instead.
2596 Try to compensate for those WM here. */
2598 static void
2599 x_fullscreen_move (f, new_top, new_left)
2600 struct frame *f;
2601 int new_top;
2602 int new_left;
2604 if (new_top != f->top_pos || new_left != f->left_pos)
2606 int move_x = new_left;
2607 int move_y = new_top;
2609 #ifdef HAVE_X_WINDOWS
2610 move_x += FRAME_X_OUTPUT (f)->x_pixels_outer_diff;
2611 move_y += FRAME_X_OUTPUT (f)->y_pixels_outer_diff;
2612 #endif
2614 f->want_fullscreen |= FULLSCREEN_MOVE_WAIT;
2615 x_set_offset (f, move_x, move_y, 1);
2619 /* Change the parameters of frame F as specified by ALIST.
2620 If a parameter is not specially recognized, do nothing special;
2621 otherwise call the `x_set_...' function for that parameter.
2622 Except for certain geometry properties, always call store_frame_param
2623 to store the new value in the parameter alist. */
2625 void
2626 x_set_frame_parameters (f, alist)
2627 FRAME_PTR f;
2628 Lisp_Object alist;
2630 Lisp_Object tail;
2632 /* If both of these parameters are present, it's more efficient to
2633 set them both at once. So we wait until we've looked at the
2634 entire list before we set them. */
2635 int width, height;
2637 /* Same here. */
2638 Lisp_Object left, top;
2640 /* Same with these. */
2641 Lisp_Object icon_left, icon_top;
2643 /* Record in these vectors all the parms specified. */
2644 Lisp_Object *parms;
2645 Lisp_Object *values;
2646 int i, p;
2647 int left_no_change = 0, top_no_change = 0;
2648 int icon_left_no_change = 0, icon_top_no_change = 0;
2649 int fullscreen_is_being_set = 0;
2651 struct gcpro gcpro1, gcpro2;
2653 i = 0;
2654 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2655 i++;
2657 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2658 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2660 /* Extract parm names and values into those vectors. */
2662 i = 0;
2663 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2665 Lisp_Object elt;
2667 elt = Fcar (tail);
2668 parms[i] = Fcar (elt);
2669 values[i] = Fcdr (elt);
2670 i++;
2672 /* TAIL and ALIST are not used again below here. */
2673 alist = tail = Qnil;
2675 GCPRO2 (*parms, *values);
2676 gcpro1.nvars = i;
2677 gcpro2.nvars = i;
2679 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2680 because their values appear in VALUES and strings are not valid. */
2681 top = left = Qunbound;
2682 icon_left = icon_top = Qunbound;
2684 /* Provide default values for HEIGHT and WIDTH. */
2685 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2686 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2688 /* Process foreground_color and background_color before anything else.
2689 They are independent of other properties, but other properties (e.g.,
2690 cursor_color) are dependent upon them. */
2691 /* Process default font as well, since fringe widths depends on it. */
2692 /* Also, process fullscreen, width and height depend upon that */
2693 for (p = 0; p < i; p++)
2695 Lisp_Object prop, val;
2697 prop = parms[p];
2698 val = values[p];
2699 if (EQ (prop, Qforeground_color)
2700 || EQ (prop, Qbackground_color)
2701 || EQ (prop, Qfont)
2702 || EQ (prop, Qfullscreen))
2704 register Lisp_Object param_index, old_value;
2706 old_value = get_frame_param (f, prop);
2707 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2709 if (NILP (Fequal (val, old_value)))
2711 store_frame_param (f, prop, val);
2713 param_index = Fget (prop, Qx_frame_parameter);
2714 if (NATNUMP (param_index)
2715 && (XFASTINT (param_index)
2716 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2717 && rif->frame_parm_handlers[XINT (param_index)])
2718 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2723 /* Now process them in reverse of specified order. */
2724 for (i--; i >= 0; i--)
2726 Lisp_Object prop, val;
2728 prop = parms[i];
2729 val = values[i];
2731 if (EQ (prop, Qwidth) && NUMBERP (val))
2732 width = XFASTINT (val);
2733 else if (EQ (prop, Qheight) && NUMBERP (val))
2734 height = XFASTINT (val);
2735 else if (EQ (prop, Qtop))
2736 top = val;
2737 else if (EQ (prop, Qleft))
2738 left = val;
2739 else if (EQ (prop, Qicon_top))
2740 icon_top = val;
2741 else if (EQ (prop, Qicon_left))
2742 icon_left = val;
2743 else if (EQ (prop, Qforeground_color)
2744 || EQ (prop, Qbackground_color)
2745 || EQ (prop, Qfont)
2746 || EQ (prop, Qfullscreen))
2747 /* Processed above. */
2748 continue;
2749 else
2751 register Lisp_Object param_index, old_value;
2753 old_value = get_frame_param (f, prop);
2755 store_frame_param (f, prop, val);
2757 param_index = Fget (prop, Qx_frame_parameter);
2758 if (NATNUMP (param_index)
2759 && (XFASTINT (param_index)
2760 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2761 && rif->frame_parm_handlers[XINT (param_index)])
2762 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2766 /* Don't die if just one of these was set. */
2767 if (EQ (left, Qunbound))
2769 left_no_change = 1;
2770 if (f->left_pos < 0)
2771 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2772 else
2773 XSETINT (left, f->left_pos);
2775 if (EQ (top, Qunbound))
2777 top_no_change = 1;
2778 if (f->top_pos < 0)
2779 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2780 else
2781 XSETINT (top, f->top_pos);
2784 /* If one of the icon positions was not set, preserve or default it. */
2785 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
2787 icon_left_no_change = 1;
2788 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2789 if (NILP (icon_left))
2790 XSETINT (icon_left, 0);
2792 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
2794 icon_top_no_change = 1;
2795 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2796 if (NILP (icon_top))
2797 XSETINT (icon_top, 0);
2800 #ifndef HAVE_CARBON
2801 /* MAC_TODO: fullscreen */
2802 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
2804 /* If the frame is visible already and the fullscreen parameter is
2805 being set, it is too late to set WM manager hints to specify
2806 size and position.
2807 Here we first get the width, height and position that applies to
2808 fullscreen. We then move the frame to the appropriate
2809 position. Resize of the frame is taken care of in the code after
2810 this if-statement. */
2811 int new_left, new_top;
2813 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
2814 x_fullscreen_move (f, new_top, new_left);
2816 #endif
2818 /* Don't set these parameters unless they've been explicitly
2819 specified. The window might be mapped or resized while we're in
2820 this function, and we don't want to override that unless the lisp
2821 code has asked for it.
2823 Don't set these parameters unless they actually differ from the
2824 window's current parameters; the window may not actually exist
2825 yet. */
2827 Lisp_Object frame;
2829 check_frame_size (f, &height, &width);
2831 XSETFRAME (frame, f);
2833 if (width != FRAME_COLS (f)
2834 || height != FRAME_LINES (f)
2835 || f->new_text_lines || f->new_text_cols)
2836 Fset_frame_size (frame, make_number (width), make_number (height));
2838 if ((!NILP (left) || !NILP (top))
2839 && ! (left_no_change && top_no_change)
2840 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2841 && NUMBERP (top) && XINT (top) == f->top_pos))
2843 int leftpos = 0;
2844 int toppos = 0;
2846 /* Record the signs. */
2847 f->size_hint_flags &= ~ (XNegative | YNegative);
2848 if (EQ (left, Qminus))
2849 f->size_hint_flags |= XNegative;
2850 else if (INTEGERP (left))
2852 leftpos = XINT (left);
2853 if (leftpos < 0)
2854 f->size_hint_flags |= XNegative;
2856 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2857 && CONSP (XCDR (left))
2858 && INTEGERP (XCAR (XCDR (left))))
2860 leftpos = - XINT (XCAR (XCDR (left)));
2861 f->size_hint_flags |= XNegative;
2863 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2864 && CONSP (XCDR (left))
2865 && INTEGERP (XCAR (XCDR (left))))
2867 leftpos = XINT (XCAR (XCDR (left)));
2870 if (EQ (top, Qminus))
2871 f->size_hint_flags |= YNegative;
2872 else if (INTEGERP (top))
2874 toppos = XINT (top);
2875 if (toppos < 0)
2876 f->size_hint_flags |= YNegative;
2878 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2879 && CONSP (XCDR (top))
2880 && INTEGERP (XCAR (XCDR (top))))
2882 toppos = - XINT (XCAR (XCDR (top)));
2883 f->size_hint_flags |= YNegative;
2885 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2886 && CONSP (XCDR (top))
2887 && INTEGERP (XCAR (XCDR (top))))
2889 toppos = XINT (XCAR (XCDR (top)));
2893 /* Store the numeric value of the position. */
2894 f->top_pos = toppos;
2895 f->left_pos = leftpos;
2897 f->win_gravity = NorthWestGravity;
2899 /* Actually set that position, and convert to absolute. */
2900 x_set_offset (f, leftpos, toppos, -1);
2903 if ((!NILP (icon_left) || !NILP (icon_top))
2904 && ! (icon_left_no_change && icon_top_no_change))
2905 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2908 UNGCPRO;
2912 /* Insert a description of internally-recorded parameters of frame X
2913 into the parameter alist *ALISTPTR that is to be given to the user.
2914 Only parameters that are specific to the X window system
2915 and whose values are not correctly recorded in the frame's
2916 param_alist need to be considered here. */
2918 void
2919 x_report_frame_params (f, alistptr)
2920 struct frame *f;
2921 Lisp_Object *alistptr;
2923 char buf[16];
2924 Lisp_Object tem;
2926 /* Represent negative positions (off the top or left screen edge)
2927 in a way that Fmodify_frame_parameters will understand correctly. */
2928 XSETINT (tem, f->left_pos);
2929 if (f->left_pos >= 0)
2930 store_in_alist (alistptr, Qleft, tem);
2931 else
2932 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
2934 XSETINT (tem, f->top_pos);
2935 if (f->top_pos >= 0)
2936 store_in_alist (alistptr, Qtop, tem);
2937 else
2938 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
2940 store_in_alist (alistptr, Qborder_width,
2941 make_number (f->border_width));
2942 store_in_alist (alistptr, Qinternal_border_width,
2943 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
2944 store_in_alist (alistptr, Qleft_fringe,
2945 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
2946 store_in_alist (alistptr, Qright_fringe,
2947 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
2948 store_in_alist (alistptr, Qscroll_bar_width,
2949 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2950 ? make_number (0)
2951 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
2952 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
2953 /* nil means "use default width"
2954 for non-toolkit scroll bar.
2955 ruler-mode.el depends on this. */
2956 : Qnil));
2957 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
2958 store_in_alist (alistptr, Qwindow_id,
2959 build_string (buf));
2960 #ifdef HAVE_X_WINDOWS
2961 #ifdef USE_X_TOOLKIT
2962 /* Tooltip frame may not have this widget. */
2963 if (FRAME_X_OUTPUT (f)->widget)
2964 #endif
2965 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
2966 store_in_alist (alistptr, Qouter_window_id,
2967 build_string (buf));
2968 #endif
2969 store_in_alist (alistptr, Qicon_name, f->icon_name);
2970 FRAME_SAMPLE_VISIBILITY (f);
2971 store_in_alist (alistptr, Qvisibility,
2972 (FRAME_VISIBLE_P (f) ? Qt
2973 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
2974 store_in_alist (alistptr, Qdisplay,
2975 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
2977 #ifndef HAVE_CARBON
2978 /* A Mac Window is identified by a struct, not an integer. */
2979 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
2980 tem = Qnil;
2981 else
2982 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
2983 store_in_alist (alistptr, Qparent_id, tem);
2984 #endif
2988 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
2989 the previous value of that parameter, NEW_VALUE is the new value. */
2991 void
2992 x_set_fullscreen (f, new_value, old_value)
2993 struct frame *f;
2994 Lisp_Object new_value, old_value;
2996 #ifndef HAVE_CARBON
2997 if (NILP (new_value))
2998 f->want_fullscreen = FULLSCREEN_NONE;
2999 else if (EQ (new_value, Qfullboth))
3000 f->want_fullscreen = FULLSCREEN_BOTH;
3001 else if (EQ (new_value, Qfullwidth))
3002 f->want_fullscreen = FULLSCREEN_WIDTH;
3003 else if (EQ (new_value, Qfullheight))
3004 f->want_fullscreen = FULLSCREEN_HEIGHT;
3005 #endif
3009 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3010 the previous value of that parameter, NEW_VALUE is the new value. */
3012 void
3013 x_set_line_spacing (f, new_value, old_value)
3014 struct frame *f;
3015 Lisp_Object new_value, old_value;
3017 if (NILP (new_value))
3018 f->extra_line_spacing = 0;
3019 else if (NATNUMP (new_value))
3020 f->extra_line_spacing = XFASTINT (new_value);
3021 else
3022 Fsignal (Qerror, Fcons (build_string ("Invalid line-spacing"),
3023 Fcons (new_value, Qnil)));
3024 if (FRAME_VISIBLE_P (f))
3025 redraw_frame (f);
3029 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3030 the previous value of that parameter, NEW_VALUE is the new value. */
3032 void
3033 x_set_screen_gamma (f, new_value, old_value)
3034 struct frame *f;
3035 Lisp_Object new_value, old_value;
3037 if (NILP (new_value))
3038 f->gamma = 0;
3039 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3040 /* The value 0.4545 is the normal viewing gamma. */
3041 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3042 else
3043 Fsignal (Qerror, Fcons (build_string ("Invalid screen-gamma"),
3044 Fcons (new_value, Qnil)));
3046 clear_face_cache (0);
3050 void
3051 x_set_font (f, arg, oldval)
3052 struct frame *f;
3053 Lisp_Object arg, oldval;
3055 Lisp_Object result;
3056 Lisp_Object fontset_name;
3057 Lisp_Object frame;
3058 int old_fontset = FRAME_FONTSET(f);
3060 CHECK_STRING (arg);
3062 fontset_name = Fquery_fontset (arg, Qnil);
3064 BLOCK_INPUT;
3065 result = (STRINGP (fontset_name)
3066 ? x_new_fontset (f, SDATA (fontset_name))
3067 : x_new_font (f, SDATA (arg)));
3068 UNBLOCK_INPUT;
3070 if (EQ (result, Qnil))
3071 error ("Font `%s' is not defined", SDATA (arg));
3072 else if (EQ (result, Qt))
3073 error ("The characters of the given font have varying widths");
3074 else if (STRINGP (result))
3076 if (STRINGP (fontset_name))
3078 /* Fontset names are built from ASCII font names, so the
3079 names may be equal despite there was a change. */
3080 if (old_fontset == FRAME_FONTSET (f))
3081 return;
3083 else if (!NILP (Fequal (result, oldval)))
3084 return;
3086 store_frame_param (f, Qfont, result);
3087 recompute_basic_faces (f);
3089 else
3090 abort ();
3092 do_pending_window_change (0);
3094 /* Don't call `face-set-after-frame-default' when faces haven't been
3095 initialized yet. This is the case when called from
3096 Fx_create_frame. In that case, the X widget or window doesn't
3097 exist either, and we can end up in x_report_frame_params with a
3098 null widget which gives a segfault. */
3099 if (FRAME_FACE_CACHE (f))
3101 XSETFRAME (frame, f);
3102 call1 (Qface_set_after_frame_default, frame);
3107 void
3108 x_set_fringe_width (f, new_value, old_value)
3109 struct frame *f;
3110 Lisp_Object new_value, old_value;
3112 compute_fringe_widths (f, 1);
3115 void
3116 x_set_border_width (f, arg, oldval)
3117 struct frame *f;
3118 Lisp_Object arg, oldval;
3120 CHECK_NUMBER (arg);
3122 if (XINT (arg) == f->border_width)
3123 return;
3125 #ifndef HAVE_CARBON
3126 if (FRAME_X_WINDOW (f) != 0)
3127 error ("Cannot change the border width of a window");
3128 #endif /* MAC_TODO */
3130 f->border_width = XINT (arg);
3133 void
3134 x_set_internal_border_width (f, arg, oldval)
3135 struct frame *f;
3136 Lisp_Object arg, oldval;
3138 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3140 CHECK_NUMBER (arg);
3141 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3142 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3143 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3145 #ifdef USE_X_TOOLKIT
3146 if (FRAME_X_OUTPUT (f)->edit_widget)
3147 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3148 #endif
3150 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3151 return;
3153 if (FRAME_X_WINDOW (f) != 0)
3155 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3156 SET_FRAME_GARBAGED (f);
3157 do_pending_window_change (0);
3159 else
3160 SET_FRAME_GARBAGED (f);
3163 void
3164 x_set_visibility (f, value, oldval)
3165 struct frame *f;
3166 Lisp_Object value, oldval;
3168 Lisp_Object frame;
3169 XSETFRAME (frame, f);
3171 if (NILP (value))
3172 Fmake_frame_invisible (frame, Qt);
3173 else if (EQ (value, Qicon))
3174 Ficonify_frame (frame);
3175 else
3176 Fmake_frame_visible (frame);
3179 void
3180 x_set_autoraise (f, arg, oldval)
3181 struct frame *f;
3182 Lisp_Object arg, oldval;
3184 f->auto_raise = !EQ (Qnil, arg);
3187 void
3188 x_set_autolower (f, arg, oldval)
3189 struct frame *f;
3190 Lisp_Object arg, oldval;
3192 f->auto_lower = !EQ (Qnil, arg);
3195 void
3196 x_set_unsplittable (f, arg, oldval)
3197 struct frame *f;
3198 Lisp_Object arg, oldval;
3200 f->no_split = !NILP (arg);
3203 void
3204 x_set_vertical_scroll_bars (f, arg, oldval)
3205 struct frame *f;
3206 Lisp_Object arg, oldval;
3208 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3209 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3210 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3211 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3213 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3214 = (NILP (arg)
3215 ? vertical_scroll_bar_none
3216 : EQ (Qleft, arg)
3217 ? vertical_scroll_bar_left
3218 : EQ (Qright, arg)
3219 ? vertical_scroll_bar_right
3220 #ifdef HAVE_NTGUI
3221 /* MS-Windows has scroll bars on the right by default. */
3222 : vertical_scroll_bar_right
3223 #else
3224 : vertical_scroll_bar_left
3225 #endif
3228 /* We set this parameter before creating the X window for the
3229 frame, so we can get the geometry right from the start.
3230 However, if the window hasn't been created yet, we shouldn't
3231 call x_set_window_size. */
3232 if (FRAME_X_WINDOW (f))
3233 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3234 do_pending_window_change (0);
3238 void
3239 x_set_scroll_bar_width (f, arg, oldval)
3240 struct frame *f;
3241 Lisp_Object arg, oldval;
3243 int wid = FRAME_COLUMN_WIDTH (f);
3245 if (NILP (arg))
3247 x_set_scroll_bar_default_width (f);
3249 if (FRAME_X_WINDOW (f))
3250 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3251 do_pending_window_change (0);
3253 else if (INTEGERP (arg) && XINT (arg) > 0
3254 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3256 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3257 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3259 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3260 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3261 if (FRAME_X_WINDOW (f))
3262 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3263 do_pending_window_change (0);
3266 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3267 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3268 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3273 /* Return non-nil if frame F wants a bitmap icon. */
3275 Lisp_Object
3276 x_icon_type (f)
3277 FRAME_PTR f;
3279 Lisp_Object tem;
3281 tem = assq_no_quit (Qicon_type, f->param_alist);
3282 if (CONSP (tem))
3283 return XCDR (tem);
3284 else
3285 return Qnil;
3289 /* Subroutines of creating an X frame. */
3291 /* Make sure that Vx_resource_name is set to a reasonable value.
3292 Fix it up, or set it to `emacs' if it is too hopeless. */
3294 void
3295 validate_x_resource_name ()
3297 int len = 0;
3298 /* Number of valid characters in the resource name. */
3299 int good_count = 0;
3300 /* Number of invalid characters in the resource name. */
3301 int bad_count = 0;
3302 Lisp_Object new;
3303 int i;
3305 if (!STRINGP (Vx_resource_class))
3306 Vx_resource_class = build_string (EMACS_CLASS);
3308 if (STRINGP (Vx_resource_name))
3310 unsigned char *p = SDATA (Vx_resource_name);
3311 int i;
3313 len = SBYTES (Vx_resource_name);
3315 /* Only letters, digits, - and _ are valid in resource names.
3316 Count the valid characters and count the invalid ones. */
3317 for (i = 0; i < len; i++)
3319 int c = p[i];
3320 if (! ((c >= 'a' && c <= 'z')
3321 || (c >= 'A' && c <= 'Z')
3322 || (c >= '0' && c <= '9')
3323 || c == '-' || c == '_'))
3324 bad_count++;
3325 else
3326 good_count++;
3329 else
3330 /* Not a string => completely invalid. */
3331 bad_count = 5, good_count = 0;
3333 /* If name is valid already, return. */
3334 if (bad_count == 0)
3335 return;
3337 /* If name is entirely invalid, or nearly so, use `emacs'. */
3338 if (good_count == 0
3339 || (good_count == 1 && bad_count > 0))
3341 Vx_resource_name = build_string ("emacs");
3342 return;
3345 /* Name is partly valid. Copy it and replace the invalid characters
3346 with underscores. */
3348 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3350 for (i = 0; i < len; i++)
3352 int c = SREF (new, i);
3353 if (! ((c >= 'a' && c <= 'z')
3354 || (c >= 'A' && c <= 'Z')
3355 || (c >= '0' && c <= '9')
3356 || c == '-' || c == '_'))
3357 SSET (new, i, '_');
3362 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3363 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3366 /* Get specified attribute from resource database RDB.
3367 See Fx_get_resource below for other parameters. */
3369 static Lisp_Object
3370 xrdb_get_resource (rdb, attribute, class, component, subclass)
3371 XrmDatabase rdb;
3372 Lisp_Object attribute, class, component, subclass;
3374 register char *value;
3375 char *name_key;
3376 char *class_key;
3378 CHECK_STRING (attribute);
3379 CHECK_STRING (class);
3381 if (!NILP (component))
3382 CHECK_STRING (component);
3383 if (!NILP (subclass))
3384 CHECK_STRING (subclass);
3385 if (NILP (component) != NILP (subclass))
3386 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3388 validate_x_resource_name ();
3390 /* Allocate space for the components, the dots which separate them,
3391 and the final '\0'. Make them big enough for the worst case. */
3392 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3393 + (STRINGP (component)
3394 ? SBYTES (component) : 0)
3395 + SBYTES (attribute)
3396 + 3);
3398 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3399 + SBYTES (class)
3400 + (STRINGP (subclass)
3401 ? SBYTES (subclass) : 0)
3402 + 3);
3404 /* Start with emacs.FRAMENAME for the name (the specific one)
3405 and with `Emacs' for the class key (the general one). */
3406 strcpy (name_key, SDATA (Vx_resource_name));
3407 strcpy (class_key, SDATA (Vx_resource_class));
3409 strcat (class_key, ".");
3410 strcat (class_key, SDATA (class));
3412 if (!NILP (component))
3414 strcat (class_key, ".");
3415 strcat (class_key, SDATA (subclass));
3417 strcat (name_key, ".");
3418 strcat (name_key, SDATA (component));
3421 strcat (name_key, ".");
3422 strcat (name_key, SDATA (attribute));
3424 value = x_get_string_resource (rdb, name_key, class_key);
3426 if (value != (char *) 0)
3427 return build_string (value);
3428 else
3429 return Qnil;
3433 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3434 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3435 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3436 class, where INSTANCE is the name under which Emacs was invoked, or
3437 the name specified by the `-name' or `-rn' command-line arguments.
3439 The optional arguments COMPONENT and SUBCLASS add to the key and the
3440 class, respectively. You must specify both of them or neither.
3441 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3442 and the class is `Emacs.CLASS.SUBCLASS'. */)
3443 (attribute, class, component, subclass)
3444 Lisp_Object attribute, class, component, subclass;
3446 #ifdef HAVE_X_WINDOWS
3447 check_x ();
3448 #endif
3450 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3451 attribute, class, component, subclass);
3454 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3456 Lisp_Object
3457 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3458 Display_Info *dpyinfo;
3459 Lisp_Object attribute, class, component, subclass;
3461 return xrdb_get_resource (dpyinfo->xrdb,
3462 attribute, class, component, subclass);
3465 /* Used when C code wants a resource value. */
3467 char *
3468 x_get_resource_string (attribute, class)
3469 char *attribute, *class;
3471 char *name_key;
3472 char *class_key;
3473 struct frame *sf = SELECTED_FRAME ();
3475 /* Allocate space for the components, the dots which separate them,
3476 and the final '\0'. */
3477 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3478 + strlen (attribute) + 2);
3479 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3480 + strlen (class) + 2);
3482 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3483 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3485 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3486 name_key, class_key);
3490 /* Return the value of parameter PARAM.
3492 First search ALIST, then Vdefault_frame_alist, then the X defaults
3493 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3495 Convert the resource to the type specified by desired_type.
3497 If no default is specified, return Qunbound. If you call
3498 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3499 and don't let it get stored in any Lisp-visible variables! */
3501 Lisp_Object
3502 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3503 Display_Info *dpyinfo;
3504 Lisp_Object alist, param;
3505 char *attribute;
3506 char *class;
3507 enum resource_types type;
3509 register Lisp_Object tem;
3511 tem = Fassq (param, alist);
3512 if (EQ (tem, Qnil))
3513 tem = Fassq (param, Vdefault_frame_alist);
3514 if (EQ (tem, Qnil))
3516 if (attribute)
3518 tem = display_x_get_resource (dpyinfo,
3519 build_string (attribute),
3520 build_string (class),
3521 Qnil, Qnil);
3523 if (NILP (tem))
3524 return Qunbound;
3526 switch (type)
3528 case RES_TYPE_NUMBER:
3529 return make_number (atoi (SDATA (tem)));
3531 case RES_TYPE_FLOAT:
3532 return make_float (atof (SDATA (tem)));
3534 case RES_TYPE_BOOLEAN:
3535 tem = Fdowncase (tem);
3536 if (!strcmp (SDATA (tem), "on")
3537 || !strcmp (SDATA (tem), "true"))
3538 return Qt;
3539 else
3540 return Qnil;
3542 case RES_TYPE_STRING:
3543 return tem;
3545 case RES_TYPE_SYMBOL:
3546 /* As a special case, we map the values `true' and `on'
3547 to Qt, and `false' and `off' to Qnil. */
3549 Lisp_Object lower;
3550 lower = Fdowncase (tem);
3551 if (!strcmp (SDATA (lower), "on")
3552 || !strcmp (SDATA (lower), "true"))
3553 return Qt;
3554 else if (!strcmp (SDATA (lower), "off")
3555 || !strcmp (SDATA (lower), "false"))
3556 return Qnil;
3557 else
3558 return Fintern (tem, Qnil);
3561 default:
3562 abort ();
3565 else
3566 return Qunbound;
3568 return Fcdr (tem);
3571 Lisp_Object
3572 x_frame_get_arg (f, alist, param, attribute, class, type)
3573 struct frame *f;
3574 Lisp_Object alist, param;
3575 char *attribute;
3576 char *class;
3577 enum resource_types type;
3579 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3580 alist, param, attribute, class, type);
3583 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3585 Lisp_Object
3586 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3587 struct frame *f;
3588 Lisp_Object alist, param;
3589 char *attribute;
3590 char *class;
3591 enum resource_types type;
3593 Lisp_Object value;
3595 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3596 attribute, class, type);
3597 if (! NILP (value))
3598 store_frame_param (f, param, value);
3600 return value;
3604 /* Record in frame F the specified or default value according to ALIST
3605 of the parameter named PROP (a Lisp symbol).
3606 If no value is specified for PROP, look for an X default for XPROP
3607 on the frame named NAME.
3608 If that is not found either, use the value DEFLT. */
3610 Lisp_Object
3611 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3612 struct frame *f;
3613 Lisp_Object alist;
3614 Lisp_Object prop;
3615 Lisp_Object deflt;
3616 char *xprop;
3617 char *xclass;
3618 enum resource_types type;
3620 Lisp_Object tem;
3622 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3623 if (EQ (tem, Qunbound))
3624 tem = deflt;
3625 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3626 return tem;
3632 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3633 doc: /* Parse an X-style geometry string STRING.
3634 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3635 The properties returned may include `top', `left', `height', and `width'.
3636 The value of `left' or `top' may be an integer,
3637 or a list (+ N) meaning N pixels relative to top/left corner,
3638 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3639 (string)
3640 Lisp_Object string;
3642 int geometry, x, y;
3643 unsigned int width, height;
3644 Lisp_Object result;
3646 CHECK_STRING (string);
3648 geometry = XParseGeometry ((char *) SDATA (string),
3649 &x, &y, &width, &height);
3651 #if 0
3652 if (!!(geometry & XValue) != !!(geometry & YValue))
3653 error ("Must specify both x and y position, or neither");
3654 #endif
3656 result = Qnil;
3657 if (geometry & XValue)
3659 Lisp_Object element;
3661 if (x >= 0 && (geometry & XNegative))
3662 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3663 else if (x < 0 && ! (geometry & XNegative))
3664 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3665 else
3666 element = Fcons (Qleft, make_number (x));
3667 result = Fcons (element, result);
3670 if (geometry & YValue)
3672 Lisp_Object element;
3674 if (y >= 0 && (geometry & YNegative))
3675 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3676 else if (y < 0 && ! (geometry & YNegative))
3677 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3678 else
3679 element = Fcons (Qtop, make_number (y));
3680 result = Fcons (element, result);
3683 if (geometry & WidthValue)
3684 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3685 if (geometry & HeightValue)
3686 result = Fcons (Fcons (Qheight, make_number (height)), result);
3688 return result;
3691 /* Calculate the desired size and position of frame F.
3692 Return the flags saying which aspects were specified.
3694 Also set the win_gravity and size_hint_flags of F.
3696 Adjust height for toolbar if TOOLBAR_P is 1.
3698 This function does not make the coordinates positive. */
3700 #define DEFAULT_ROWS 40
3701 #define DEFAULT_COLS 80
3704 x_figure_window_size (f, parms, toolbar_p)
3705 struct frame *f;
3706 Lisp_Object parms;
3707 int toolbar_p;
3709 register Lisp_Object tem0, tem1, tem2;
3710 long window_prompting = 0;
3711 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3713 /* Default values if we fall through.
3714 Actually, if that happens we should get
3715 window manager prompting. */
3716 SET_FRAME_COLS (f, DEFAULT_COLS);
3717 FRAME_LINES (f) = DEFAULT_ROWS;
3718 /* Window managers expect that if program-specified
3719 positions are not (0,0), they're intentional, not defaults. */
3720 f->top_pos = 0;
3721 f->left_pos = 0;
3723 /* Ensure that old new_text_cols and new_text_lines will not override the
3724 values set here. */
3725 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3726 f->new_text_cols = f->new_text_lines = 0;
3728 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3729 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3730 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3731 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3733 if (!EQ (tem0, Qunbound))
3735 CHECK_NUMBER (tem0);
3736 FRAME_LINES (f) = XINT (tem0);
3738 if (!EQ (tem1, Qunbound))
3740 CHECK_NUMBER (tem1);
3741 SET_FRAME_COLS (f, XINT (tem1));
3743 if (!NILP (tem2) && !EQ (tem2, Qunbound))
3744 window_prompting |= USSize;
3745 else
3746 window_prompting |= PSize;
3749 f->scroll_bar_actual_width
3750 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
3752 /* This used to be done _before_ calling x_figure_window_size, but
3753 since the height is reset here, this was really a no-op. I
3754 assume that moving it here does what Gerd intended (although he
3755 no longer can remember what that was... ++KFS, 2003-03-25. */
3757 /* Add the tool-bar height to the initial frame height so that the
3758 user gets a text display area of the size he specified with -g or
3759 via .Xdefaults. Later changes of the tool-bar height don't
3760 change the frame size. This is done so that users can create
3761 tall Emacs frames without having to guess how tall the tool-bar
3762 will get. */
3763 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
3765 int margin, relief, bar_height;
3767 relief = (tool_bar_button_relief >= 0
3768 ? tool_bar_button_relief
3769 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
3771 if (INTEGERP (Vtool_bar_button_margin)
3772 && XINT (Vtool_bar_button_margin) > 0)
3773 margin = XFASTINT (Vtool_bar_button_margin);
3774 else if (CONSP (Vtool_bar_button_margin)
3775 && INTEGERP (XCDR (Vtool_bar_button_margin))
3776 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
3777 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
3778 else
3779 margin = 0;
3781 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
3782 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
3785 compute_fringe_widths (f, 0);
3787 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
3788 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
3790 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
3791 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
3792 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
3793 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3795 if (EQ (tem0, Qminus))
3797 f->top_pos = 0;
3798 window_prompting |= YNegative;
3800 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
3801 && CONSP (XCDR (tem0))
3802 && INTEGERP (XCAR (XCDR (tem0))))
3804 f->top_pos = - XINT (XCAR (XCDR (tem0)));
3805 window_prompting |= YNegative;
3807 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
3808 && CONSP (XCDR (tem0))
3809 && INTEGERP (XCAR (XCDR (tem0))))
3811 f->top_pos = XINT (XCAR (XCDR (tem0)));
3813 else if (EQ (tem0, Qunbound))
3814 f->top_pos = 0;
3815 else
3817 CHECK_NUMBER (tem0);
3818 f->top_pos = XINT (tem0);
3819 if (f->top_pos < 0)
3820 window_prompting |= YNegative;
3823 if (EQ (tem1, Qminus))
3825 f->left_pos = 0;
3826 window_prompting |= XNegative;
3828 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
3829 && CONSP (XCDR (tem1))
3830 && INTEGERP (XCAR (XCDR (tem1))))
3832 f->left_pos = - XINT (XCAR (XCDR (tem1)));
3833 window_prompting |= XNegative;
3835 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
3836 && CONSP (XCDR (tem1))
3837 && INTEGERP (XCAR (XCDR (tem1))))
3839 f->left_pos = XINT (XCAR (XCDR (tem1)));
3841 else if (EQ (tem1, Qunbound))
3842 f->left_pos = 0;
3843 else
3845 CHECK_NUMBER (tem1);
3846 f->left_pos = XINT (tem1);
3847 if (f->left_pos < 0)
3848 window_prompting |= XNegative;
3851 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
3852 window_prompting |= USPosition;
3853 else
3854 window_prompting |= PPosition;
3857 if (f->want_fullscreen != FULLSCREEN_NONE)
3859 int left, top;
3860 int width, height;
3862 /* It takes both for some WM:s to place it where we want */
3863 window_prompting = USPosition | PPosition;
3864 x_fullscreen_adjust (f, &width, &height, &top, &left);
3865 FRAME_COLS (f) = width;
3866 FRAME_LINES (f) = height;
3867 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
3868 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
3869 f->left_pos = left;
3870 f->top_pos = top;
3873 if (window_prompting & XNegative)
3875 if (window_prompting & YNegative)
3876 f->win_gravity = SouthEastGravity;
3877 else
3878 f->win_gravity = NorthEastGravity;
3880 else
3882 if (window_prompting & YNegative)
3883 f->win_gravity = SouthWestGravity;
3884 else
3885 f->win_gravity = NorthWestGravity;
3888 f->size_hint_flags = window_prompting;
3890 return window_prompting;
3895 #endif /* HAVE_WINDOW_SYSTEM */
3899 /***********************************************************************
3900 Initialization
3901 ***********************************************************************/
3903 void
3904 syms_of_frame ()
3906 Qframep = intern ("framep");
3907 staticpro (&Qframep);
3908 Qframe_live_p = intern ("frame-live-p");
3909 staticpro (&Qframe_live_p);
3910 Qheight = intern ("height");
3911 staticpro (&Qheight);
3912 Qicon = intern ("icon");
3913 staticpro (&Qicon);
3914 Qminibuffer = intern ("minibuffer");
3915 staticpro (&Qminibuffer);
3916 Qmodeline = intern ("modeline");
3917 staticpro (&Qmodeline);
3918 Qonly = intern ("only");
3919 staticpro (&Qonly);
3920 Qwidth = intern ("width");
3921 staticpro (&Qwidth);
3922 Qgeometry = intern ("geometry");
3923 staticpro (&Qgeometry);
3924 Qicon_left = intern ("icon-left");
3925 staticpro (&Qicon_left);
3926 Qicon_top = intern ("icon-top");
3927 staticpro (&Qicon_top);
3928 Qleft = intern ("left");
3929 staticpro (&Qleft);
3930 Qright = intern ("right");
3931 staticpro (&Qright);
3932 Quser_position = intern ("user-position");
3933 staticpro (&Quser_position);
3934 Quser_size = intern ("user-size");
3935 staticpro (&Quser_size);
3936 Qwindow_id = intern ("window-id");
3937 staticpro (&Qwindow_id);
3938 #ifdef HAVE_X_WINDOWS
3939 Qouter_window_id = intern ("outer-window-id");
3940 staticpro (&Qouter_window_id);
3941 #endif
3942 Qparent_id = intern ("parent-id");
3943 staticpro (&Qparent_id);
3944 Qx = intern ("x");
3945 staticpro (&Qx);
3946 Qw32 = intern ("w32");
3947 staticpro (&Qw32);
3948 Qpc = intern ("pc");
3949 staticpro (&Qpc);
3950 Qmac = intern ("mac");
3951 staticpro (&Qmac);
3952 Qvisible = intern ("visible");
3953 staticpro (&Qvisible);
3954 Qbuffer_predicate = intern ("buffer-predicate");
3955 staticpro (&Qbuffer_predicate);
3956 Qbuffer_list = intern ("buffer-list");
3957 staticpro (&Qbuffer_list);
3958 Qdisplay_type = intern ("display-type");
3959 staticpro (&Qdisplay_type);
3960 Qbackground_mode = intern ("background-mode");
3961 staticpro (&Qbackground_mode);
3962 Qtty_color_mode = intern ("tty-color-mode");
3963 staticpro (&Qtty_color_mode);
3965 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
3966 staticpro (&Qface_set_after_frame_default);
3968 Qfullwidth = intern ("fullwidth");
3969 staticpro (&Qfullwidth);
3970 Qfullheight = intern ("fullheight");
3971 staticpro (&Qfullheight);
3972 Qfullboth = intern ("fullboth");
3973 staticpro (&Qfullboth);
3974 Qx_resource_name = intern ("x-resource-name");
3975 staticpro (&Qx_resource_name);
3977 Qx_frame_parameter = intern ("x-frame-parameter");
3978 staticpro (&Qx_frame_parameter);
3981 int i;
3983 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
3985 Lisp_Object v = intern (frame_parms[i].name);
3986 if (frame_parms[i].variable)
3988 *frame_parms[i].variable = v;
3989 staticpro (frame_parms[i].variable);
3991 Fput (v, Qx_frame_parameter, make_number (i));
3995 #ifdef HAVE_WINDOW_SYSTEM
3996 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
3997 doc: /* The name Emacs uses to look up X resources.
3998 `x-get-resource' uses this as the first component of the instance name
3999 when requesting resource values.
4000 Emacs initially sets `x-resource-name' to the name under which Emacs
4001 was invoked, or to the value specified with the `-name' or `-rn'
4002 switches, if present.
4004 It may be useful to bind this variable locally around a call
4005 to `x-get-resource'. See also the variable `x-resource-class'. */);
4006 Vx_resource_name = Qnil;
4008 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4009 doc: /* The class Emacs uses to look up X resources.
4010 `x-get-resource' uses this as the first component of the instance class
4011 when requesting resource values.
4013 Emacs initially sets `x-resource-class' to "Emacs".
4015 Setting this variable permanently is not a reasonable thing to do,
4016 but binding this variable locally around a call to `x-get-resource'
4017 is a reasonable practice. See also the variable `x-resource-name'. */);
4018 Vx_resource_class = build_string (EMACS_CLASS);
4019 #endif
4021 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4022 doc: /* Alist of default values for frame creation.
4023 These may be set in your init file, like this:
4024 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1))
4025 These override values given in window system configuration data,
4026 including X Windows' defaults database.
4027 For values specific to the first Emacs frame, see `initial-frame-alist'.
4028 For values specific to the separate minibuffer frame, see
4029 `minibuffer-frame-alist'.
4030 The `menu-bar-lines' element of the list controls whether new frames
4031 have menu bars; `menu-bar-mode' works by altering this element.
4032 Setting this variable does not affect existing frames, only new ones. */);
4033 Vdefault_frame_alist = Qnil;
4035 Qinhibit_default_face_x_resources
4036 = intern ("inhibit-default-face-x-resources");
4037 staticpro (&Qinhibit_default_face_x_resources);
4039 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4040 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4042 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4043 doc: /* Non-nil if all of emacs is iconified and frame updates are not needed. */);
4044 Vemacs_iconified = Qnil;
4046 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4047 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4048 `mouse-position' calls this function, passing its usual return value as
4049 argument, and returns whatever this function returns.
4050 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4051 which need to do mouse handling at the Lisp level. */);
4052 Vmouse_position_function = Qnil;
4054 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4055 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4056 If the value is an integer, highlighting is only shown after moving the
4057 mouse, while keyboard input turns off the highlight even when the mouse
4058 is over the clickable text. However, the mouse shape still indicates
4059 when the mouse is over clickable text. */);
4060 Vmouse_highlight = Qt;
4062 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4063 doc: /* Functions to be run before deleting a frame.
4064 The functions are run with one arg, the frame to be deleted.
4065 See `delete-frame'. */);
4066 Vdelete_frame_functions = Qnil;
4068 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4069 doc: /* Minibufferless frames use this frame's minibuffer.
4071 Emacs cannot create minibufferless frames unless this is set to an
4072 appropriate surrogate.
4074 Emacs consults this variable only when creating minibufferless
4075 frames; once the frame is created, it sticks with its assigned
4076 minibuffer, no matter what this variable is set to. This means that
4077 this variable doesn't necessarily say anything meaningful about the
4078 current set of frames, or where the minibuffer is currently being
4079 displayed.
4081 This variable is local to the current terminal and cannot be buffer-local. */);
4083 staticpro (&Vframe_list);
4085 defsubr (&Sactive_minibuffer_window);
4086 defsubr (&Sframep);
4087 defsubr (&Sframe_live_p);
4088 defsubr (&Smake_terminal_frame);
4089 defsubr (&Shandle_switch_frame);
4090 defsubr (&Signore_event);
4091 defsubr (&Sselect_frame);
4092 defsubr (&Sselected_frame);
4093 defsubr (&Swindow_frame);
4094 defsubr (&Sframe_root_window);
4095 defsubr (&Sframe_first_window);
4096 defsubr (&Sframe_selected_window);
4097 defsubr (&Sset_frame_selected_window);
4098 defsubr (&Sframe_list);
4099 defsubr (&Snext_frame);
4100 defsubr (&Sprevious_frame);
4101 defsubr (&Sdelete_frame);
4102 defsubr (&Smouse_position);
4103 defsubr (&Smouse_pixel_position);
4104 defsubr (&Sset_mouse_position);
4105 defsubr (&Sset_mouse_pixel_position);
4106 #if 0
4107 defsubr (&Sframe_configuration);
4108 defsubr (&Srestore_frame_configuration);
4109 #endif
4110 defsubr (&Smake_frame_visible);
4111 defsubr (&Smake_frame_invisible);
4112 defsubr (&Siconify_frame);
4113 defsubr (&Sframe_visible_p);
4114 defsubr (&Svisible_frame_list);
4115 defsubr (&Sraise_frame);
4116 defsubr (&Slower_frame);
4117 defsubr (&Sredirect_frame_focus);
4118 defsubr (&Sframe_focus);
4119 defsubr (&Sframe_parameters);
4120 defsubr (&Sframe_parameter);
4121 defsubr (&Smodify_frame_parameters);
4122 defsubr (&Sframe_char_height);
4123 defsubr (&Sframe_char_width);
4124 defsubr (&Sframe_pixel_height);
4125 defsubr (&Sframe_pixel_width);
4126 defsubr (&Sset_frame_height);
4127 defsubr (&Sset_frame_width);
4128 defsubr (&Sset_frame_size);
4129 defsubr (&Sset_frame_position);
4131 #ifdef HAVE_WINDOW_SYSTEM
4132 defsubr (&Sx_get_resource);
4133 defsubr (&Sx_parse_geometry);
4134 #endif