comparison src/window.c @ 343:8bec6624d99b r21-1-1

Import from CVS: tag r21-1-1
author cvs
date Mon, 13 Aug 2007 10:52:53 +0200
parents 19dcec799385
children 7c94d56991e1
comparison
equal deleted inserted replaced
342:b036ce23deaa 343:8bec6624d99b
4619 /* If you add anything to this structure make sure window_config_equal 4619 /* If you add anything to this structure make sure window_config_equal
4620 knows about it. */ 4620 knows about it. */
4621 struct window_config 4621 struct window_config
4622 { 4622 {
4623 struct lcrecord_header header; 4623 struct lcrecord_header header;
4624 int frame_width; 4624 /* int frame_width; No longer needed, JV
4625 int frame_height; 4625 int frame_height; */
4626 #if 0 /* FSFmacs */ 4626 #if 0 /* FSFmacs */
4627 Lisp_Object selected_frame; 4627 Lisp_Object selected_frame;
4628 #endif 4628 #endif
4629 Lisp_Object current_window; 4629 Lisp_Object current_window;
4630 Lisp_Object current_buffer; 4630 Lisp_Object current_buffer;
4631 Lisp_Object minibuffer_scroll_window; 4631 Lisp_Object minibuffer_scroll_window;
4632 Lisp_Object root_window; 4632 Lisp_Object root_window;
4633 int minibuf_height; /* 0 = no minibuffer, <0, size in lines, >0 in pixels */
4633 /* Record the values of window-min-width and window-min-height 4634 /* Record the values of window-min-width and window-min-height
4634 so that window sizes remain consistent with them. */ 4635 so that window sizes remain consistent with them. */
4635 int min_width, min_height; 4636 int min_width, min_height;
4636 int saved_windows_count; 4637 int saved_windows_count;
4637 /* Zero-sized arrays aren't ANSI C */ 4638 /* Zero-sized arrays aren't ANSI C */
4759 4760
4760 if (!((fig1->saved_windows_count == fig2->saved_windows_count) && 4761 if (!((fig1->saved_windows_count == fig2->saved_windows_count) &&
4761 EQ (fig1->current_window, fig2->current_window) && 4762 EQ (fig1->current_window, fig2->current_window) &&
4762 EQ (fig1->current_buffer, fig2->current_buffer) && 4763 EQ (fig1->current_buffer, fig2->current_buffer) &&
4763 EQ (fig1->root_window, fig2->root_window) && 4764 EQ (fig1->root_window, fig2->root_window) &&
4764 EQ (fig1->minibuffer_scroll_window, fig2->minibuffer_scroll_window) && 4765 EQ (fig1->minibuffer_scroll_window, fig2->minibuffer_scroll_window)))
4766 /* &&
4765 fig1->frame_width == fig2->frame_width && 4767 fig1->frame_width == fig2->frame_width &&
4766 fig1->frame_height == fig2->frame_height)) 4768 fig1->frame_height == fig2->frame_height)) */
4767 return 0; 4769 return 0;
4768 4770
4769 for (i = 0; i < fig1->saved_windows_count; i++) 4771 for (i = 0; i < fig1->saved_windows_count; i++)
4770 { 4772 {
4771 if (!saved_window_equal (SAVED_WINDOW_N (fig1, i), 4773 if (!saved_window_equal (SAVED_WINDOW_N (fig1, i),
4857 int k; 4859 int k;
4858 Lisp_Object frame; 4860 Lisp_Object frame;
4859 struct frame *f; 4861 struct frame *f;
4860 struct gcpro gcpro1; 4862 struct gcpro gcpro1;
4861 Lisp_Object old_window_config; 4863 Lisp_Object old_window_config;
4862 int previous_frame_height; 4864 /* int previous_frame_height;
4863 int previous_frame_width; 4865 int previous_frame_width;*/
4866 int previous_pixel_top;
4867 int previous_pixel_height;
4868 int previous_pixel_left;
4869 int previous_pixel_width;
4870 int previous_minibuf_height, previous_minibuf_top,previous_minibuf_width;
4871 int real_font_height;
4872 int converted_minibuf_height,target_minibuf_height;
4864 int specpdl_count = specpdl_depth (); 4873 int specpdl_count = specpdl_depth ();
4865 4874
4866 GCPRO1 (configuration); 4875 GCPRO1 (configuration);
4867 4876
4868 CHECK_WINDOW_CONFIGURATION (configuration); 4877 CHECK_WINDOW_CONFIGURATION (configuration);
4923 begin_dont_check_for_quit (); 4932 begin_dont_check_for_quit ();
4924 record_unwind_protect (free_window_configuration, old_window_config); 4933 record_unwind_protect (free_window_configuration, old_window_config);
4925 4934
4926 mark_windows_in_use (f, 1); 4935 mark_windows_in_use (f, 1);
4927 4936
4937 #if 0
4938 /* JV: This is bogus,
4939 First of all, the units are inconsistent. The frame sizes are measured
4940 in characters but the window sizes are stored in pixels. So if a
4941 font size change happened between saving and restoring, the
4942 frame "sizes" maybe equal but the windows still should be
4943 resized. This is tickled alot by the new "character size
4944 stays constant" policy in 21.0. It leads to very wierd
4945 glitches (and possibly craches when asserts are tickled).
4946
4947 Just changing the units doens't help because changing the
4948 toolbar configuration can also change the pixel positions.
4949 Luckily there is a much simpler way of doing this, see below.
4950 */
4928 previous_frame_width = FRAME_WIDTH (f); 4951 previous_frame_width = FRAME_WIDTH (f);
4929 previous_frame_height = FRAME_HEIGHT (f); 4952 previous_frame_height = FRAME_HEIGHT (f);
4930 /* If the frame has been resized since this window configuration was 4953 /* If the frame has been resized since this window configuration was
4931 made, we change the frame to the size specified in the 4954 made, we change the frame to the size specified in the
4932 configuration, restore the configuration, and then resize it 4955 configuration, restore the configuration, and then resize it
4933 back. We keep track of the prevailing height in these variables. */ 4956 back. We keep track of the prevailing height in these variables. */
4934 if (config->frame_height != FRAME_HEIGHT (f) 4957 if (config->frame_height != FRAME_HEIGHT (f)
4935 || config->frame_width != FRAME_WIDTH (f)) 4958 || config->frame_width != FRAME_WIDTH (f))
4936 change_frame_size (f, config->frame_height, config->frame_width, 0); 4959 change_frame_size (f, config->frame_height, config->frame_width, 0);
4937 4960 #endif
4961
4962 previous_pixel_top = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top;
4963 previous_pixel_height = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_height;
4964 previous_pixel_left = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left;
4965 previous_pixel_width = XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_width;
4966
4967 /* remember some properties of the minibuffer */
4968
4969 default_face_height_and_width (frame, &real_font_height, 0);
4970 assert(real_font_height > 0);
4971
4972 if (FRAME_HAS_MINIBUF_P (f) && ! FRAME_MINIBUF_ONLY_P (f))
4973 {
4974 previous_minibuf_height
4975 = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
4976 previous_minibuf_top
4977 = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_top;
4978 previous_minibuf_width
4979 = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_width;
4980 }
4981 else
4982 {
4983 previous_minibuf_height = 0;
4984 previous_minibuf_width = 0;
4985 }
4986 converted_minibuf_height =
4987 (previous_minibuf_height % real_font_height) == 0 ?
4988 - (previous_minibuf_height / real_font_height ) : /* lines */
4989 previous_minibuf_height; /* pixels */
4990
4938 /* Temporarily avoid any problems with windows that are smaller 4991 /* Temporarily avoid any problems with windows that are smaller
4939 than they are supposed to be. */ 4992 than they are supposed to be. */
4940 window_min_height = 1; 4993 window_min_height = 1;
4941 window_min_width = 1; 4994 window_min_width = 1;
4942 4995
5098 Instead, we don't ever change the selected frame, and either 5151 Instead, we don't ever change the selected frame, and either
5099 call Fselect_window() below if the window config's frame is 5152 call Fselect_window() below if the window config's frame is
5100 currently selected, or just set the selected window of the 5153 currently selected, or just set the selected window of the
5101 window config's frame. */ 5154 window config's frame. */
5102 5155
5156 #if 0
5103 /* Set the frame height to the value it had before this function. */ 5157 /* Set the frame height to the value it had before this function. */
5104 if (previous_frame_height != FRAME_HEIGHT (f) 5158 if (previous_frame_height != FRAME_HEIGHT (f)
5105 || previous_frame_width != FRAME_WIDTH (f)) 5159 || previous_frame_width != FRAME_WIDTH (f))
5106 change_frame_size (f, previous_frame_height, previous_frame_width, 0); 5160 change_frame_size (f, previous_frame_height, previous_frame_width, 0);
5107 5161 #endif
5162 /* We just reset the size and position of the minibuffer, to its old
5163 value, which needn't be valid. So we do some magic to see which value
5164 to actually take. Then we set it.
5165
5166 The magic:
5167 We take the old value if is in the same units but differs from the
5168 current value.
5169
5170 #### Now we get more cases correct then ever before, but
5171 are we treating all? For instance what if the frames minibuf window
5172 is no longer the same one?
5173 */
5174 target_minibuf_height = previous_minibuf_height;
5175 if (converted_minibuf_height &&
5176 (converted_minibuf_height * config->minibuf_height) > 0 &&
5177 (converted_minibuf_height != config->minibuf_height))
5178 {
5179 target_minibuf_height = config->minibuf_height < 0 ?
5180 - (config->minibuf_height * real_font_height) :
5181 config->minibuf_height;
5182 target_minibuf_height =
5183 max(target_minibuf_height,real_font_height);
5184 }
5185 if (previous_minibuf_height)
5186 {
5187 XWINDOW (FRAME_MINIBUF_WINDOW (f))->pixel_top
5188 = previous_minibuf_top -
5189 (target_minibuf_height - previous_minibuf_height);
5190 set_window_pixheight (FRAME_MINIBUF_WINDOW (f),
5191 target_minibuf_height, 0);
5192 set_window_pixwidth (FRAME_MINIBUF_WINDOW (f),
5193 previous_minibuf_width, 0);
5194 }
5195
5196 /* This is a better way to deal with frame resizing, etc.
5197 What we _actually_ want is for the old (just restored)
5198 root window to fit
5199 into the place of the new one. So we just do that. Simple! */
5200 XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_top = previous_pixel_top;
5201 /* Note that this function also updates the subwindow
5202 "pixel_top"s */
5203 set_window_pixheight (FRAME_ROOT_WINDOW (f),
5204 previous_pixel_height -
5205 (target_minibuf_height - previous_minibuf_height), 0);
5206 XWINDOW (FRAME_ROOT_WINDOW (f))->pixel_left = previous_pixel_left;
5207 /* Note that this function also updates the subwindow
5208 "pixel_left"s */
5209 set_window_pixwidth (FRAME_ROOT_WINDOW (f), previous_pixel_width, 0);
5210
5108 /* If restoring in the current frame make the window current, 5211 /* If restoring in the current frame make the window current,
5109 otherwise just update the frame selected_window slot to be 5212 otherwise just update the frame selected_window slot to be
5110 the restored current_window. */ 5213 the restored current_window. */
5111 if (f == selected_frame ()) 5214 if (f == selected_frame ())
5112 { 5215 {
5317 { 5420 {
5318 Lisp_Object result; 5421 Lisp_Object result;
5319 struct frame *f = decode_frame (frame); 5422 struct frame *f = decode_frame (frame);
5320 struct window_config *config; 5423 struct window_config *config;
5321 int n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f))); 5424 int n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5425 int minibuf_height;
5426 int real_font_height;
5322 5427
5323 if (n_windows <= countof (Vwindow_configuration_free_list)) 5428 if (n_windows <= countof (Vwindow_configuration_free_list))
5324 config = XWINDOW_CONFIGURATION (allocate_managed_lcrecord 5429 config = XWINDOW_CONFIGURATION (allocate_managed_lcrecord
5325 (Vwindow_configuration_free_list 5430 (Vwindow_configuration_free_list
5326 [n_windows - 1])); 5431 [n_windows - 1]));
5328 /* More than ten windows; just allocate directly */ 5433 /* More than ten windows; just allocate directly */
5329 config = (struct window_config *) 5434 config = (struct window_config *)
5330 alloc_lcrecord (sizeof_window_config_for_n_windows (n_windows), 5435 alloc_lcrecord (sizeof_window_config_for_n_windows (n_windows),
5331 lrecord_window_configuration); 5436 lrecord_window_configuration);
5332 XSETWINDOW_CONFIGURATION (result, config); 5437 XSETWINDOW_CONFIGURATION (result, config);
5333 5438 /*
5334 config->frame_width = FRAME_WIDTH (f); 5439 config->frame_width = FRAME_WIDTH (f);
5335 config->frame_height = FRAME_HEIGHT (f); 5440 config->frame_height = FRAME_HEIGHT (f); */
5336 config->current_window = FRAME_SELECTED_WINDOW (f); 5441 config->current_window = FRAME_SELECTED_WINDOW (f);
5337 XSETBUFFER (config->current_buffer, current_buffer); 5442 XSETBUFFER (config->current_buffer, current_buffer);
5338 config->minibuffer_scroll_window = Vminibuffer_scroll_window; 5443 config->minibuffer_scroll_window = Vminibuffer_scroll_window;
5339 config->root_window = FRAME_ROOT_WINDOW (f); 5444 config->root_window = FRAME_ROOT_WINDOW (f);
5340 config->min_height = window_min_height; 5445 config->min_height = window_min_height;
5341 config->min_width = window_min_width; 5446 config->min_width = window_min_width;
5342 config->saved_windows_count = n_windows; 5447 config->saved_windows_count = n_windows;
5343 save_window_save (FRAME_ROOT_WINDOW (f), config, 0); 5448 save_window_save (FRAME_ROOT_WINDOW (f), config, 0);
5449
5450 /* save the minibuffer height using the heuristics from
5451 change_frame_size_1 */
5452
5453 XSETFRAME (frame, f); /* frame could have been nil ! */
5454 default_face_height_and_width (frame, &real_font_height, 0);
5455 assert(real_font_height > 0);
5456
5457 if (FRAME_HAS_MINIBUF_P (f) && ! FRAME_MINIBUF_ONLY_P (f))
5458 minibuf_height = XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
5459 else
5460 minibuf_height = 0;
5461 config->minibuf_height = (minibuf_height % real_font_height) == 0 ?
5462 - (minibuf_height / real_font_height ) : /* lines */
5463 minibuf_height; /* pixels */
5464
5344 return result; 5465 return result;
5345 } 5466 }
5346 5467
5347 Lisp_Object 5468 Lisp_Object
5348 save_window_excursion_unwind (Lisp_Object window_config) 5469 save_window_excursion_unwind (Lisp_Object window_config)