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