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