aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnders Lindgren2015-10-23 07:58:02 +0200
committerAnders Lindgren2015-10-23 07:58:02 +0200
commitba24d35a3e82cdeba4be5bd794f7f48bbfa5498e (patch)
treeafd99e3b51d9773d178bdc1b972ddd6a367385e3 /src
parent3768304c6a501fb5bc90ed9e21a63aebd314a44e (diff)
downloademacs-ba24d35a3e82cdeba4be5bd794f7f48bbfa5498e.tar.gz
emacs-ba24d35a3e82cdeba4be5bd794f7f48bbfa5498e.zip
NextSten maximization and NSTRACE rewrite.
Full-height, full-width, and maximized windows now cover the entire screen (except the menu bar), including the part where the system dock is placed. The system zoom animation is no longer used. Made NonMaximized->FullWidth->FullHeight->NonMaximized restore the original size. * nsterm.m (ns_menu_bar_height): New function, return height of the menu bar, or 0 when it's hidden. * nsterm.m (constrain_frame_rect): New function for constraining a frame. * nsterm.m (ns_constrain_all_frames): Set frame size explicitly rather than relying on the system doing it for us by writing back the current frame size. * nsterm.m (windowWillUseStandardFrame): Register non-maximized width or height as new user size. When entering full width or height, the other size component is taken from the user size. * nsterm.m (fullscreenState): New method for accessing the fullscreen state. * nsterm.m (constrainFrameRect): Restrict frame to be placed under the menu bar, if present. The old version, sometimes, restricted the height of a frame to the screen, this version never does this. * nsterm.m (zoom): Perform zoom by setting the frame to the full size of the screen (minus the menu bar). The default system function, with the zoom animation, is no longer used, as the final frame size doesn't cover the entire screen. Rework how to constrain resizing to the character grid. The old system used "resizeIncrements" in NSWindows. However, once a frame was resized so that it was not aligned to the text grid, it remained unaligned even after a resize. In addition, it conflicted when resizing a fullheight window. * nsterm.m (windowWillResize): Restrict frame size to text grid, unless when pixelwise frame resizing is enabled. * nsterm.m (updateFrameSize, initFrameFromEmacs) (toggleFullScreen, handleFS): Don't set resizeIncrements. Redesign the NS trace system. The call structure is represented using indentations and vertical lines. The NSTRACE macro accepts printf-style arguments. New macros for printing various information. * nsterm.h (NSTRACE_ENABLED): Macro to enable trace system. * nsterm.h (NSTRACE, NSTRACE_WHEN, NSTRACE_UNLESS): Macros to start a new block (typically a function), accept printf-style arguments. * nsterm.h (NSTRACE_MSG): Macro for extra information, accepts printf-style arguments. * nsterm.h (NSTRACE_what): Macros for printing various types. * nsterm.h (NSTRACE_FMT_what): Macro with printf format string snippets. * nsterm.h (NSTRACE_ARG_what): Macros for passing printf-style arguments, corresponds to NSTRACE_FMT_what. * nsterm.h (NSTRACE_RETURN): Macro to print return value, accept printf-style arguments. * nsterm.h (NSTRACE_RETURN_what): Macros to print return value for various types. * nsterm.m: Remove old NSTRACE macro. * nsterm.m (nstrace_num): Trace counter. * nsterm.m (nstrace_depth): Current call depth. * nsterm.m (nstrace_leave): NSTRACE support function, called when the local variable "nstrace_enabled" goes out of scope using the "cleanup" extension. * nsterm.m (ns_print_fullscreen_type_name): NSTRACE_FSTYPE support function. * nsterm.m (constrain_frame_rect, ns_constrain_all_frames) (ns_update_auto_hide_menu_bar, ns_update_begin) (ns_update_window_begin, update_window_end, ns_update_end) (ns_focus, ns_unfocus, ns_ring_bell, ns_frame_raise_lower) (ns_frame_rehighlight, x_make_frame_visible) (x_make_frame_invisible, x_iconify_frame, x_free_frame_resources) (x_destroy_window, x_set_offset, x_set_window_size) (ns_fullscreen_hook, ns_lisp_to_color, ns_color_to_lisp) (ns_defined_color, frame_set_mouse_pixel_position) (note_mouse_movement, ns_mouse_position, ns_frame_up_to_date) (ns_define_frame_cursor, x_get_keysym_name, ns_redraw_scroll_bars) (ns_clear_frame, ns_clear_frame_area, ns_scroll_run) (ns_after_update_window_line, ns_shift_glyphs_for_insert) (dumpcursor, ns_draw_vertical_window_border) (ns_draw_window_divider, ns_draw_relief) (ns_dumpglyphs_box_or_relief, ns_maybe_dumpglyphs_background) (ns_dumpglyphs_image, ns_draw_glyph_string, ns_send_appdefined) (ns_read_socket, ns_select, ns_set_vertical_scroll_bar) (ns_set_horizontal_scroll_bar, ns_condemn_scroll_bars) (ns_redeem_scroll_bar, ns_judge_scroll_bars, ns_delete_terminal) (ns_create_terminal, ns_term_init, sendEvent) (applicationDidFinishLaunching, applicationDidBecomeActive) (timeout_handler, fd_handler, EmacsView_dealloc, changeFont) (acceptsFirstResponder, resetCursorRects, keyDown, mouseDown) (deltaIsZero, rightMouseDown, otherMouseDown, mouseUp) (rightMouseUp, otherMouseUp, scrollWheel, mouseMoved) (mouse_autoselect_window, in_window, mouseDragged) (rightMouseDragged, otherMouseDragged, windowShouldClose) (updateFrameSize, windowWillResize, windowDidResize) (windowDidBecomeKey, windowDidResignKey, windowWillMiniaturize) (initFrameFromEmacs, windowDidMove, windowDidDeminiaturize) (windowDidExpose, windowDidMiniaturize, windowWillEnterFullScreen) (windowDidEnterFullScreen, windowWillExitFullScreen) (windowDidExitFullScreen, toggleFullScreen, handleFS, setFSValue) (mouseEntered, mouseExited, menuDown, toolbarClicked, drawRect) (draggingEntered, performDragOperation, validRequestorForSendType) (setMiniwindowImage, constrainFrameRect, performZoom, zoom) (EmacsScroller_initFrame, EmacsScroller_setFrame) (EmacsScroller_dealloc, condemn, reprieve, judge) (resetCursorRects, setPosition, EmacsScroller_mouseDown) (EmacsScroller_mouseDragged, syms_of_nsterm): Use new trace system. * nsfns.m: Remove old NSTRACE macro. * nsfns.m (x_set_icon_name, ns_set_name, x_explicitly_set_name) (x_implicitly_set_name, x_set_title, ns_set_name_as_filename) (ns_implicitly_set_icon_type, x_set_icon_type): Use new trace system. * nsimage.m: Remove old NSTRACE macro. * nsimage.m (ns_image_from_XBM, ns_image_for_XPM) (ns_image_from_bitmap_file, ns_load_image): Use new trace system. * nsmenu.m: Remove old NSTRACE macro. * nsmenu.m (ns_update_menubar, ns_menu_show, ns_popup_dialog): Use new trace system.
Diffstat (limited to 'src')
-rw-r--r--src/nsfns.m23
-rw-r--r--src/nsimage.m16
-rw-r--r--src/nsmenu.m13
-rw-r--r--src/nsterm.h235
-rw-r--r--src/nsterm.m909
5 files changed, 873 insertions, 323 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 43002ca6fef..1ed3e23cba5 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -49,13 +49,6 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
49#include "macfont.h" 49#include "macfont.h"
50#endif 50#endif
51 51
52#if 0
53int fns_trace_num = 1;
54#define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \
55 __FILE__, __LINE__, ++fns_trace_num)
56#else
57#define NSTRACE(x)
58#endif
59 52
60#ifdef HAVE_NS 53#ifdef HAVE_NS
61 54
@@ -364,7 +357,7 @@ static void
364x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 357x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
365{ 358{
366 NSView *view = FRAME_NS_VIEW (f); 359 NSView *view = FRAME_NS_VIEW (f);
367 NSTRACE (x_set_icon_name); 360 NSTRACE ("x_set_icon_name");
368 361
369 /* see if it's changed */ 362 /* see if it's changed */
370 if (STRINGP (arg)) 363 if (STRINGP (arg))
@@ -436,7 +429,7 @@ ns_set_name_internal (struct frame *f, Lisp_Object name)
436static void 429static void
437ns_set_name (struct frame *f, Lisp_Object name, int explicit) 430ns_set_name (struct frame *f, Lisp_Object name, int explicit)
438{ 431{
439 NSTRACE (ns_set_name); 432 NSTRACE ("ns_set_name");
440 433
441 /* Make sure that requests from lisp code override requests from 434 /* Make sure that requests from lisp code override requests from
442 Emacs redisplay code. */ 435 Emacs redisplay code. */
@@ -477,7 +470,7 @@ ns_set_name (struct frame *f, Lisp_Object name, int explicit)
477static void 470static void
478x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 471x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
479{ 472{
480 NSTRACE (x_explicitly_set_name); 473 NSTRACE ("x_explicitly_set_name");
481 ns_set_name (f, arg, 1); 474 ns_set_name (f, arg, 1);
482} 475}
483 476
@@ -488,7 +481,7 @@ x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
488void 481void
489x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 482x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
490{ 483{
491 NSTRACE (x_implicitly_set_name); 484 NSTRACE ("x_implicitly_set_name");
492 485
493 /* Deal with NS specific format t. */ 486 /* Deal with NS specific format t. */
494 if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (Vicon_title_format, Qt)) 487 if (FRAME_NS_P (f) && ((FRAME_ICONIFIED_P (f) && EQ (Vicon_title_format, Qt))
@@ -505,7 +498,7 @@ x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
505static void 498static void
506x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name) 499x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
507{ 500{
508 NSTRACE (x_set_title); 501 NSTRACE ("x_set_title");
509 /* Don't change the title if it's already NAME. */ 502 /* Don't change the title if it's already NAME. */
510 if (EQ (name, f->title)) 503 if (EQ (name, f->title))
511 return; 504 return;
@@ -533,7 +526,7 @@ ns_set_name_as_filename (struct frame *f)
533 NSAutoreleasePool *pool; 526 NSAutoreleasePool *pool;
534 Lisp_Object encoded_name, encoded_filename; 527 Lisp_Object encoded_name, encoded_filename;
535 NSString *str; 528 NSString *str;
536 NSTRACE (ns_set_name_as_filename); 529 NSTRACE ("ns_set_name_as_filename");
537 530
538 if (f->explicit_name || ! NILP (f->title)) 531 if (f->explicit_name || ! NILP (f->title))
539 return; 532 return;
@@ -729,7 +722,7 @@ ns_implicitly_set_icon_type (struct frame *f)
729 NSAutoreleasePool *pool; 722 NSAutoreleasePool *pool;
730 BOOL setMini = YES; 723 BOOL setMini = YES;
731 724
732 NSTRACE (ns_implicitly_set_icon_type); 725 NSTRACE ("ns_implicitly_set_icon_type");
733 726
734 block_input (); 727 block_input ();
735 pool = [[NSAutoreleasePool alloc] init]; 728 pool = [[NSAutoreleasePool alloc] init];
@@ -797,7 +790,7 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
797 id image = nil; 790 id image = nil;
798 BOOL setMini = YES; 791 BOOL setMini = YES;
799 792
800 NSTRACE (x_set_icon_type); 793 NSTRACE ("x_set_icon_type");
801 794
802 if (!NILP (arg) && SYMBOLP (arg)) 795 if (!NILP (arg) && SYMBOLP (arg))
803 { 796 {
diff --git a/src/nsimage.m b/src/nsimage.m
index 9eaeefebcd8..e76a7db8ef3 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -35,14 +35,6 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
35#include "frame.h" 35#include "frame.h"
36#include "coding.h" 36#include "coding.h"
37 37
38/* call tracing */
39#if 0
40int image_trace_num = 0;
41#define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \
42 __FILE__, __LINE__, ++image_trace_num)
43#else
44#define NSTRACE(x)
45#endif
46 38
47 39
48/* ========================================================================== 40/* ==========================================================================
@@ -57,7 +49,7 @@ void *
57ns_image_from_XBM (unsigned char *bits, int width, int height, 49ns_image_from_XBM (unsigned char *bits, int width, int height,
58 unsigned long fg, unsigned long bg) 50 unsigned long fg, unsigned long bg)
59{ 51{
60 NSTRACE (ns_image_from_XBM); 52 NSTRACE ("ns_image_from_XBM");
61 return [[EmacsImage alloc] initFromXBM: bits 53 return [[EmacsImage alloc] initFromXBM: bits
62 width: width height: height 54 width: width height: height
63 fg: fg bg: bg]; 55 fg: fg bg: bg];
@@ -66,7 +58,7 @@ ns_image_from_XBM (unsigned char *bits, int width, int height,
66void * 58void *
67ns_image_for_XPM (int width, int height, int depth) 59ns_image_for_XPM (int width, int height, int depth)
68{ 60{
69 NSTRACE (ns_image_for_XPM); 61 NSTRACE ("ns_image_for_XPM");
70 return [[EmacsImage alloc] initForXPMWithDepth: depth 62 return [[EmacsImage alloc] initForXPMWithDepth: depth
71 width: width height: height]; 63 width: width height: height];
72} 64}
@@ -74,7 +66,7 @@ ns_image_for_XPM (int width, int height, int depth)
74void * 66void *
75ns_image_from_file (Lisp_Object file) 67ns_image_from_file (Lisp_Object file)
76{ 68{
77 NSTRACE (ns_image_from_bitmap_file); 69 NSTRACE ("ns_image_from_bitmap_file");
78 return [EmacsImage allocInitFromFile: file]; 70 return [EmacsImage allocInitFromFile: file];
79} 71}
80 72
@@ -85,7 +77,7 @@ ns_load_image (struct frame *f, struct image *img,
85 EmacsImage *eImg = nil; 77 EmacsImage *eImg = nil;
86 NSSize size; 78 NSSize size;
87 79
88 NSTRACE (ns_load_image); 80 NSTRACE ("ns_load_image");
89 81
90 if (STRINGP (spec_file)) 82 if (STRINGP (spec_file))
91 { 83 {
diff --git a/src/nsmenu.m b/src/nsmenu.m
index b5cb64d68e5..2ef12234960 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -45,13 +45,6 @@ Carbon version by Yamamoto Mitsuharu. */
45#include <sys/types.h> 45#include <sys/types.h>
46#endif 46#endif
47 47
48#if 0
49int menu_trace_num = 0;
50#define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \
51 __FILE__, __LINE__, ++menu_trace_num)
52#else
53#define NSTRACE(x)
54#endif
55 48
56#if 0 49#if 0
57/* Include lisp -> C common menu parsing code */ 50/* Include lisp -> C common menu parsing code */
@@ -121,7 +114,7 @@ ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu)
121 long t; 114 long t;
122#endif 115#endif
123 116
124 NSTRACE (ns_update_menubar); 117 NSTRACE ("ns_update_menubar");
125 118
126 if (f != SELECTED_FRAME ()) 119 if (f != SELECTED_FRAME ())
127 return; 120 return;
@@ -801,6 +794,8 @@ ns_menu_show (struct frame *f, int x, int y, int menuflags,
801 widget_value *wv, *first_wv = 0; 794 widget_value *wv, *first_wv = 0;
802 bool keymaps = (menuflags & MENU_KEYMAPS); 795 bool keymaps = (menuflags & MENU_KEYMAPS);
803 796
797 NSTRACE ("ns_menu_show");
798
804 block_input (); 799 block_input ();
805 800
806 p.x = x; p.y = y; 801 p.x = x; p.y = y;
@@ -1423,7 +1418,7 @@ ns_popup_dialog (struct frame *f, Lisp_Object header, Lisp_Object contents)
1423 BOOL isQ; 1418 BOOL isQ;
1424 NSAutoreleasePool *pool; 1419 NSAutoreleasePool *pool;
1425 1420
1426 NSTRACE (x-popup-dialog); 1421 NSTRACE ("ns_popup_dialog");
1427 1422
1428 isQ = NILP (header); 1423 isQ = NILP (header);
1429 1424
diff --git a/src/nsterm.h b/src/nsterm.h
index c06b7c49a6d..8d52dc642ed 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -61,6 +61,240 @@ typedef float EmacsCGFloat;
61 61
62/* ========================================================================== 62/* ==========================================================================
63 63
64 Trace support
65
66 ========================================================================== */
67
68/* Uncomment the following line to enable trace. */
69
70/* #define NSTRACE_ENABLED 1 */
71
72
73/* Print a call tree containing all annotated functions.
74
75 The call structure of the functions is represented using
76 indentation and vertical lines. Extra information is printed using
77 horizontal lines that connect to the vertical line.
78
79 The return value is represented using the arrow "->>". For simple
80 functions, the arrow can be printed on the same line as the
81 function name. If more output is printed, it is connected to the
82 vertical line of the function.
83
84 The first column contains the file name, the second the line
85 number, and the third a number increasing for each trace line.
86
87 Note that the trace system, when enabled, use the GCC/Clang
88 "cleanup" extension.
89
90 For example (long lines manually split to reduce width):
91
92nsterm.m : 1600: [ 4428] ns_fullscreen_hook
93nsterm.m : 7006: [ 4429] | handleFS
94nsterm.m : 7035: [ 4430] | +--- FULLSCREEN_MAXIMIZED
95nsterm.m : 7627: [ 4431] | | performZoom
96nsterm.m : 7636: [ 4432] | | | zoom
97nsterm.m : 874: [ 4433] | | | | ns_update_auto_hide_menu_bar
98nsterm.m : 6615: [ 4434] | | | | [windowWillUseStandardFrame:
99 defaultFrame:(X:0 Y:0)/(W:1600 H:1177)]
100nsterm.m : 99: [ 4435] | | | | +--- fs_state: FULLSCREEN_NONE
101nsterm.m : 119: [ 4436] | | | | +--- fs_before_fs: -1
102nsterm.m : 115: [ 4437] | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED
103nsterm.m : 6619: [ 4438] | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0)
104nsterm.m : 6620: [ 4439] | | | | +--- [sender frame]:
105 (X:0 Y:626)/(W:595 H:551)
106nsterm.m : 6644: [ 4440] | | | | +--- ns_userRect (2):
107 (X:0 Y:626)/(W:595 H:551)
108nsterm.m : 6684: [ 4441] | | | | +--- FULLSCREEN_MAXIMIZED
109nsterm.m : 7057: [ 4442] | | | | | setFSValue
110nsterm.m : 115: [ 4443] | | | | | +--- value: FULLSCREEN_MAXIMIZED
111nsterm.m : 6711: [ 4444] | | | | +--- Final ns_userRect:
112 (X:0 Y:626)/(W:595 H:551)
113nsterm.m : 6712: [ 4445] | | | | +--- Final maximized_width: 1600
114nsterm.m : 6713: [ 4446] | | | | +--- Final maximized_height: 1177
115nsterm.m : 119: [ 4447] | | | | +--- Final next_maximized: -1
116nsterm.m : 6209: [ 4448] | | | | | windowWillResize: toSize: (W:1600 H:1177)
117nsterm.m : 6210: [ 4449] | | | | | +--- [sender frame]:
118 (X:0 Y:626)/(W:595 H:551)
119nsterm.m : 115: [ 4450] | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED
120nsterm.m : 6274: [ 4451] | | | | | +--- cols: 223 rows: 79
121nsterm.m : 6299: [ 4452] | | | | | +->> (W:1596 H:1167)
122nsterm.m : 6718: [ 4453] | | | | +->> (X:0 Y:0)/(W:1600 H:1177)
123
124 Here, "ns_fullscreen_hook" calls "handleFS", which is turn calls
125 "performZoom". This function calls "[super performZoom]", which
126 isn't annoted (so it doesn't show up in the trace). However, it
127 calls "zoom" which is annotated so it is part of the call trace.
128 Later, the method "windowWillUseStandardFrame" and the function
129 "setFSValue" are called. The lines with "+---" contain extra
130 information and lines containing "->>" represent return values. */
131
132#ifndef NSTRACE_ENABLED
133#define NSTRACE_ENABLED 0
134#endif
135
136#if NSTRACE_ENABLED
137extern int nstrace_num;
138extern int nstrace_depth;
139
140void nstrace_leave(int *);
141
142/* printf-style trace output. Output is aligned with contained heading. */
143#define NSTRACE_MSG_NO_DASHES(...) \
144 do \
145 { \
146 if (nstrace_enabled) \
147 { \
148 fprintf (stderr, "%-10s:%5d: [%5d]%.*s", \
149 __FILE__, __LINE__, ++nstrace_num, \
150 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \
151 fprintf (stderr, __VA_ARGS__); \
152 fprintf (stderr, "\n"); \
153 } \
154 } \
155 while(0)
156
157#define NSTRACE_MSG(...) NSTRACE_MSG_NO_DASHES("+--- " __VA_ARGS__)
158
159
160
161/* Macros for printing complex types.
162
163 NSTRACE_FMT_what -- Printf format string for "what".
164 NSTRACE_ARG_what(x) -- Printf argument for "what". */
165
166#define NSTRACE_FMT_SIZE "(W:%.0f H:%.0f)"
167#define NSTRACE_ARG_SIZE(elt) (elt).width, (elt).height
168
169#define NSTRACE_FMT_POINT "(X:%.0f Y:%.0f)"
170#define NSTRACE_ARG_POINT(elt) (elt).x, (elt).y
171
172#define NSTRACE_FMT_RECT NSTRACE_FMT_POINT "/" NSTRACE_FMT_SIZE
173#define NSTRACE_ARG_RECT(elt) \
174 NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size)
175
176
177/* Macros for printing complex types as extra information. */
178
179#define NSTRACE_SIZE(str,size) \
180 NSTRACE_MSG (str ": " NSTRACE_FMT_SIZE, \
181 NSTRACE_ARG_SIZE (size));
182
183#define NSTRACE_POINT(str,point) \
184 NSTRACE_MSG (str ": " NSTRACE_FMT_POINT, \
185 NSTRACE_ARG_POINT (point));
186
187#define NSTRACE_RECT(str,rect) \
188 NSTRACE_MSG (str ": " NSTRACE_FMT_RECT, \
189 NSTRACE_ARG_RECT (rect));
190
191#define NSTRACE_FSTYPE(str,fs_type) \
192 do \
193 { \
194 if (nstrace_enabled) \
195 { \
196 ns_print_fullscreen_type_name(str, fs_type); \
197 } \
198 } \
199 while(0)
200
201
202/* Return value macros.
203
204 NSTRACE_RETURN(fmt, ...) - Print a return value, support printf-style
205 format string and arguments.
206
207 NSTRACE_RETURN_what(obj) - Print a return value of kind WHAT.
208
209 NSTRACE_FMT_RETURN - A string literal representing a returned
210 value. Useful when creating a format string
211 to printf-like constructs like NSTRACE(). */
212
213#define NSTRACE_FMT_RETURN "->>"
214
215#define NSTRACE_RETURN(...) \
216 NSTRACE_MSG_NO_DASHES ("+" NSTRACE_FMT_RETURN " " __VA_ARGS__)
217
218#define NSTRACE_RETURN_SIZE(size) \
219 NSTRACE_RETURN(NSTRACE_FMT_SIZE, NSTRACE_ARG_SIZE(size))
220
221#define NSTRACE_RETURN_POINT(point) \
222 NSTRACE_RETURN(NSTRACE_FMT_POINT, NSTRACE_ARG_POINT(point))
223
224#define NSTRACE_RETURN_RECT(rect) \
225 NSTRACE_RETURN(NSTRACE_FMT_RECT, NSTRACE_ARG_RECT(rect))
226
227
228/* Function enter macros.
229
230 NSTRACE (fmt, ...) -- Enable trace output in curent block
231 (typically a function). Accepts printf-style
232 arguments.
233
234 NSTRACE_WHEN (cond, fmt, ...) -- Enable trace output when COND is true.
235
236 NSTRACE_UNLESS (cond, fmt, ...) -- Enable trace output unless COND is
237 true. */
238
239
240
241#define NSTRACE_WHEN(cond, ...) \
242 __attribute__((cleanup(nstrace_leave))) \
243 int nstrace_enabled = (cond); \
244 if (nstrace_enabled) { ++nstrace_depth; } \
245 NSTRACE_MSG_NO_DASHES(__VA_ARGS__);
246
247#endif /* NSTRACE_ENABLED */
248
249#define NSTRACE(...) NSTRACE_WHEN(1, __VA_ARGS__)
250#define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__)
251
252
253/* Non-trace replacement versions. */
254#ifndef NSTRACE_WHEN
255#define NSTRACE_WHEN(...)
256#endif
257
258#ifndef NSTRACE_MSG
259#define NSTRACE_MSG(...)
260#endif
261
262#ifndef NSTRACE_SIZE
263#define NSTRACE_SIZE(str,size)
264#endif
265
266#ifndef NSTRACE_POINT
267#define NSTRACE_POINT(str,point)
268#endif
269
270#ifndef NSTRACE_RECT
271#define NSTRACE_RECT(str,rect)
272#endif
273
274#ifndef NSTRACE_FSTYPE
275#define NSTRACE_FSTYPE(str,fs_type)
276#endif
277
278#ifndef NSTRACE_RETURN_SIZE
279#define NSTRACE_RETURN_SIZE(size)
280#endif
281
282#ifndef NSTRACE_RETURN_POINT
283#define NSTRACE_RETURN_POINT(point)
284#endif
285
286#ifndef NSTRACE_RETURN_RECT
287#define NSTRACE_RETURN_RECT(rect)
288#endif
289
290#ifndef NSTRACE_RETURN_FSTYPE
291#define NSTRACE_RETURN_FSTYPE(fs_type)
292#endif
293
294
295
296/* ==========================================================================
297
64 NSColor, EmacsColor category. 298 NSColor, EmacsColor category.
65 299
66 ========================================================================== */ 300 ========================================================================== */
@@ -174,6 +408,7 @@ typedef float EmacsCGFloat;
174#ifdef NS_IMPL_GNUSTEP 408#ifdef NS_IMPL_GNUSTEP
175- (void)windowDidMove: (id)sender; 409- (void)windowDidMove: (id)sender;
176#endif 410#endif
411- (int)fullscreenState;
177@end 412@end
178 413
179 414
diff --git a/src/nsterm.m b/src/nsterm.m
index c4bfd7c9914..e5eb8caaef3 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -68,38 +68,60 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
68#include "macfont.h" 68#include "macfont.h"
69#endif 69#endif
70 70
71/* call tracing */
72#if 0
73int term_trace_num = 0;
74#define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \
75 __FILE__, __LINE__, ++term_trace_num)
76#else
77#define NSTRACE(x)
78#endif
79 71
80/* Detailed tracing. "S" means "size" and "LL" stands for "lower left". */ 72extern NSString *NSMenuDidBeginTrackingNotification;
81#if 0 73
82int term_trace_num = 0; 74
83#define NSTRACE_SIZE(str,size) fprintf (stderr, \ 75#if NSTRACE_ENABLED
84 "%s:%d: [%d] " str \ 76int nstrace_num = 0;
85 " (S:%.0f x %.0f)\n", \ 77int nstrace_depth = 0;
86 __FILE__, __LINE__, ++term_trace_num,\ 78
87 size.height, \ 79/* Called when nstrace_enabled goes out of scope. */
88 size.width) 80void nstrace_leave(int * pointer_to_nstrace_enabled)
89#define NSTRACE_RECT(s,r) fprintf (stderr, \ 81{
90 "%s:%d: [%d] " s \ 82 if (*pointer_to_nstrace_enabled)
91 " (LL:%.0f x %.0f -> S:%.0f x %.0f)\n", \ 83 {
92 __FILE__, __LINE__, ++term_trace_num,\ 84 --nstrace_depth;
93 r.origin.x, \ 85 }
94 r.origin.y, \ 86}
95 r.size.height, \ 87
96 r.size.width) 88
97#else 89void ns_print_fullscreen_type_name (char const * s, int fs_type)
98#define NSTRACE_SIZE(str,size) 90{
99#define NSTRACE_RECT(s,r) 91 // This is a support function for the NSTRACE system, don't add a
92 // NSTRACE () here. However, a local `nstrace_enabled' variable is
93 // needed by the NSTRACE_MSG macros.
94 int nstrace_enabled = 1;
95
96 switch (fs_type)
97 {
98 case FULLSCREEN_NONE:
99 NSTRACE_MSG ("%s: FULLSCREEN_NONE", s);
100 break;
101
102 case FULLSCREEN_WIDTH:
103 NSTRACE_MSG ("%s: FULLSCREEN_WIDTH", s);
104 break;
105
106 case FULLSCREEN_HEIGHT:
107 NSTRACE_MSG ("%s: FULLSCREEN_HEIGHT", s);
108 break;
109
110 case FULLSCREEN_BOTH:
111 NSTRACE_MSG ("%s: FULLSCREEN_BOTH", s);
112 break;
113
114 case FULLSCREEN_MAXIMIZED:
115 NSTRACE_MSG ("%s: FULLSCREEN_MAXIMIZED", s);
116 break;
117
118 default:
119 NSTRACE_MSG ("%s: %d", s, fs_type);
120 break;
121 }
122}
100#endif 123#endif
101 124
102extern NSString *NSMenuDidBeginTrackingNotification;
103 125
104/* ========================================================================== 126/* ==========================================================================
105 127
@@ -242,7 +264,7 @@ static struct frame *ns_updating_frame;
242static NSView *focus_view = NULL; 264static NSView *focus_view = NULL;
243static int ns_window_num = 0; 265static int ns_window_num = 0;
244#ifdef NS_IMPL_GNUSTEP 266#ifdef NS_IMPL_GNUSTEP
245static NSRect uRect; 267static NSRect uRect; // TODO: This is dead, remove it?
246#endif 268#endif
247static BOOL gsaved = NO; 269static BOOL gsaved = NO;
248static BOOL ns_fake_keydown = NO; 270static BOOL ns_fake_keydown = NO;
@@ -622,6 +644,46 @@ ns_release_autorelease_pool (void *pool)
622} 644}
623 645
624 646
647/* True, if the menu bar should be hidden. */
648
649static BOOL
650ns_menu_bar_should_be_hidden (void)
651{
652 return !NILP (ns_auto_hide_menu_bar)
653 && [NSApp respondsToSelector:@selector(setPresentationOptions:)];
654}
655
656
657static CGFloat
658ns_menu_bar_height (NSScreen *screen)
659/* The height of the menu bar, if visible. */
660{
661 // NSTRACE ("ns_menu_bar_height");
662
663 CGFloat res;
664
665 if (ns_menu_bar_should_be_hidden())
666 {
667 res = 0;
668 }
669 else
670 {
671 NSRect screenFrame = [screen frame];
672 NSRect screenVisibleFrame = [screen visibleFrame];
673
674 CGFloat frameTop = screenFrame.origin.y + screenFrame.size.height;
675 CGFloat visibleFrameTop = (screenVisibleFrame.origin.y
676 + screenVisibleFrame.size.height);
677
678 res = frameTop - visibleFrameTop;
679
680 }
681
682 // NSTRACE_MSG (NSTRACE_FMT_RETURN "%.0f", res);
683
684 return res;
685}
686
625 687
626/* ========================================================================== 688/* ==========================================================================
627 689
@@ -671,44 +733,140 @@ ns_release_autorelease_pool (void *pool)
671// Result: Menu bar visible, frame placed immediately below the menu. 733// Result: Menu bar visible, frame placed immediately below the menu.
672// 734//
673 735
736static NSRect constrain_frame_rect(NSRect frameRect)
737{
738 NSTRACE ("constrain_frame_rect(" NSTRACE_FMT_RECT ")",
739 NSTRACE_ARG_RECT (frameRect));
740
741 // --------------------
742 // Collect information about the screen the frame is covering.
743 //
744
745 NSArray *screens = [NSScreen screens];
746 NSUInteger nr_screens = [screens count];
747
748 int i;
749
750 // The height of the menu bar, if present in any screen the frame is
751 // displayed in.
752 int menu_bar_height = 0;
753
754 // A rectangle covering all the screen the frame is displayed in.
755 NSRect multiscreenRect = NSMakeRect(0, 0, 0, 0);
756 for (i = 0; i < nr_screens; ++i )
757 {
758 NSScreen *s = [screens objectAtIndex: i];
759 NSRect scrRect = [s frame];
760
761 NSTRACE_MSG ("Screen %d: " NSTRACE_FMT_RECT,
762 i, NSTRACE_ARG_RECT (scrRect));
763
764 if (NSIntersectionRect (frameRect, scrRect).size.height != 0)
765 {
766 multiscreenRect = NSUnionRect (multiscreenRect, scrRect);
767
768 menu_bar_height = max(menu_bar_height, ns_menu_bar_height (s));
769 }
770 }
771
772 NSTRACE_RECT ("multiscreenRect", multiscreenRect);
773
774 NSTRACE_MSG ("menu_bar_height: %d", menu_bar_height);
775
776 if (multiscreenRect.size.width == 0
777 || multiscreenRect.size.height == 0)
778 {
779 // Failed to find any monitor, give up.
780 NSTRACE_MSG ("multiscreenRect empty");
781 NSTRACE_RETURN_RECT (frameRect);
782 return frameRect;
783 }
784
785
786 // --------------------
787 // Find a suitable placement.
788 //
789
790 if (ns_menu_bar_should_be_hidden())
791 {
792 // When the menu bar is hidden, the user may place part of the
793 // frame above the top of the screen, for example to hide the
794 // title bar.
795 //
796 // Hence, keep the original position.
797 }
798 else
799 {
800 // Ensure that the frame is below the menu bar, or below the top
801 // of the screen.
802 //
803 // This assume that the menu bar is placed at the top in the
804 // rectangle that covers the monitors. (It doesn't have to be,
805 // but if it's not it's hard to do anything useful.)
806 CGFloat topOfWorkArea = (multiscreenRect.origin.y
807 + multiscreenRect.size.height
808 - menu_bar_height);
809
810 CGFloat topOfFrame = frameRect.origin.y + frameRect.size.height;
811 if (topOfFrame > topOfWorkArea)
812 {
813 frameRect.origin.y -= topOfFrame - topOfWorkArea;
814 NSTRACE_RECT ("After placement adjust", frameRect);
815 }
816 }
817
818 // Include the following section to restrict frame to the screens.
819 // (If so, update it to allow the frame to stretch down below the
820 // screen.)
821#if 0
822 // --------------------
823 // Ensure frame doesn't stretch below the screens.
824 //
825
826 CGFloat diff = multiscreenRect.origin.y - frameRect.origin.y;
827
828 if (diff > 0)
829 {
830 frameRect.origin.y = multiscreenRect.origin.y;
831 frameRect.size.height -= diff;
832 }
833#endif
834
835 NSTRACE_RETURN_RECT (frameRect);
836 return frameRect;
837}
838
839
674static void 840static void
675ns_constrain_all_frames (void) 841ns_constrain_all_frames (void)
676{ 842{
677 Lisp_Object tail, frame; 843 Lisp_Object tail, frame;
678 844
845 NSTRACE ("ns_constrain_all_frames");
846
679 FOR_EACH_FRAME (tail, frame) 847 FOR_EACH_FRAME (tail, frame)
680 { 848 {
681 struct frame *f = XFRAME (frame); 849 struct frame *f = XFRAME (frame);
682 if (FRAME_NS_P (f)) 850 if (FRAME_NS_P (f))
683 { 851 {
684 NSView *view = FRAME_NS_VIEW (f); 852 NSView *view = FRAME_NS_VIEW (f);
685 /* This no-op will trigger the default window placing 853
686 * constraint system. */ 854 [[view window] setFrame:constrain_frame_rect([[view window] frame])
687 [[view window] setFrameOrigin:[[view window] frame].origin]; 855 display:NO];
688 } 856 }
689 } 857 }
690} 858}
691 859
692 860
693/* True, if the menu bar should be hidden. */
694
695static BOOL
696ns_menu_bar_should_be_hidden (void)
697{
698 return !NILP (ns_auto_hide_menu_bar)
699 && [NSApp respondsToSelector:@selector(setPresentationOptions:)];
700}
701
702
703/* Show or hide the menu bar, based on user setting. */ 861/* Show or hide the menu bar, based on user setting. */
704 862
705static void 863static void
706ns_update_auto_hide_menu_bar (void) 864ns_update_auto_hide_menu_bar (void)
707{ 865{
708#ifdef NS_IMPL_COCOA 866#ifdef NS_IMPL_COCOA
709 block_input (); 867 NSTRACE ("ns_update_auto_hide_menu_bar");
710 868
711 NSTRACE (ns_update_auto_hide_menu_bar); 869 block_input ();
712 870
713 if (NSApp != nil && [NSApp isActive]) 871 if (NSApp != nil && [NSApp isActive])
714 { 872 {
@@ -749,7 +907,7 @@ ns_update_begin (struct frame *f)
749 -------------------------------------------------------------------------- */ 907 -------------------------------------------------------------------------- */
750{ 908{
751 EmacsView *view = FRAME_NS_VIEW (f); 909 EmacsView *view = FRAME_NS_VIEW (f);
752 NSTRACE (ns_update_begin); 910 NSTRACE ("ns_update_begin");
753 911
754 ns_update_auto_hide_menu_bar (); 912 ns_update_auto_hide_menu_bar ();
755 913
@@ -806,7 +964,7 @@ ns_update_window_begin (struct window *w)
806 struct frame *f = XFRAME (WINDOW_FRAME (w)); 964 struct frame *f = XFRAME (WINDOW_FRAME (w));
807 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 965 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
808 966
809 NSTRACE (ns_update_window_begin); 967 NSTRACE ("ns_update_window_begin");
810 w->output_cursor = w->cursor; 968 w->output_cursor = w->cursor;
811 969
812 block_input (); 970 block_input ();
@@ -836,6 +994,8 @@ ns_update_window_end (struct window *w, bool cursor_on_p,
836 external (RIF) call; for one window called before update_end 994 external (RIF) call; for one window called before update_end
837 -------------------------------------------------------------------------- */ 995 -------------------------------------------------------------------------- */
838{ 996{
997 NSTRACE ("update_window_end");
998
839 /* note: this fn is nearly identical in all terms */ 999 /* note: this fn is nearly identical in all terms */
840 if (!w->pseudo_window_p) 1000 if (!w->pseudo_window_p)
841 { 1001 {
@@ -861,8 +1021,6 @@ ns_update_window_end (struct window *w, bool cursor_on_p,
861 frame_up_to_date to redisplay the mouse highlight. */ 1021 frame_up_to_date to redisplay the mouse highlight. */
862 if (mouse_face_overwritten_p) 1022 if (mouse_face_overwritten_p)
863 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w->frame))); 1023 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w->frame)));
864
865 NSTRACE (update_window_end);
866} 1024}
867 1025
868 1026
@@ -875,6 +1033,8 @@ ns_update_end (struct frame *f)
875{ 1033{
876 EmacsView *view = FRAME_NS_VIEW (f); 1034 EmacsView *view = FRAME_NS_VIEW (f);
877 1035
1036 NSTRACE ("ns_update_end");
1037
878/* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */ 1038/* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
879 MOUSE_HL_INFO (f)->mouse_face_defer = 0; 1039 MOUSE_HL_INFO (f)->mouse_face_defer = 0;
880 1040
@@ -885,7 +1045,6 @@ ns_update_end (struct frame *f)
885 1045
886 unblock_input (); 1046 unblock_input ();
887 ns_updating_frame = NULL; 1047 ns_updating_frame = NULL;
888 NSTRACE (ns_update_end);
889} 1048}
890 1049
891static void 1050static void
@@ -899,7 +1058,7 @@ ns_focus (struct frame *f, NSRect *r, int n)
899 the entire window. 1058 the entire window.
900 -------------------------------------------------------------------------- */ 1059 -------------------------------------------------------------------------- */
901{ 1060{
902// NSTRACE (ns_focus); 1061// NSTRACE ("ns_focus");
903/* static int c =0; 1062/* static int c =0;
904 fprintf (stderr, "focus: %d", c++); 1063 fprintf (stderr, "focus: %d", c++);
905 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height); 1064 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
@@ -943,7 +1102,7 @@ ns_unfocus (struct frame *f)
943 Internal: Remove focus on given frame 1102 Internal: Remove focus on given frame
944 -------------------------------------------------------------------------- */ 1103 -------------------------------------------------------------------------- */
945{ 1104{
946// NSTRACE (ns_unfocus); 1105// NSTRACE ("ns_unfocus");
947 1106
948 if (gsaved) 1107 if (gsaved)
949 { 1108 {
@@ -993,7 +1152,7 @@ ns_ring_bell (struct frame *f)
993 "Beep" routine 1152 "Beep" routine
994 -------------------------------------------------------------------------- */ 1153 -------------------------------------------------------------------------- */
995{ 1154{
996 NSTRACE (ns_ring_bell); 1155 NSTRACE ("ns_ring_bell");
997 if (visible_bell) 1156 if (visible_bell)
998 { 1157 {
999 NSAutoreleasePool *pool; 1158 NSAutoreleasePool *pool;
@@ -1079,7 +1238,7 @@ ns_frame_raise_lower (struct frame *f, bool raise)
1079 External (hook) 1238 External (hook)
1080 -------------------------------------------------------------------------- */ 1239 -------------------------------------------------------------------------- */
1081{ 1240{
1082 NSTRACE (ns_frame_raise_lower); 1241 NSTRACE ("ns_frame_raise_lower");
1083 1242
1084 if (raise) 1243 if (raise)
1085 ns_raise_frame (f); 1244 ns_raise_frame (f);
@@ -1097,7 +1256,7 @@ ns_frame_rehighlight (struct frame *frame)
1097 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame); 1256 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
1098 struct frame *old_highlight = dpyinfo->x_highlight_frame; 1257 struct frame *old_highlight = dpyinfo->x_highlight_frame;
1099 1258
1100 NSTRACE (ns_frame_rehighlight); 1259 NSTRACE ("ns_frame_rehighlight");
1101 if (dpyinfo->x_focus_frame) 1260 if (dpyinfo->x_focus_frame)
1102 { 1261 {
1103 dpyinfo->x_highlight_frame 1262 dpyinfo->x_highlight_frame
@@ -1136,7 +1295,7 @@ x_make_frame_visible (struct frame *f)
1136 External: Show the window (X11 semantics) 1295 External: Show the window (X11 semantics)
1137 -------------------------------------------------------------------------- */ 1296 -------------------------------------------------------------------------- */
1138{ 1297{
1139 NSTRACE (x_make_frame_visible); 1298 NSTRACE ("x_make_frame_visible");
1140 /* XXX: at some points in past this was not needed, as the only place that 1299 /* XXX: at some points in past this was not needed, as the only place that
1141 called this (frame.c:Fraise_frame ()) also called raise_lower; 1300 called this (frame.c:Fraise_frame ()) also called raise_lower;
1142 if this ends up the case again, comment this out again. */ 1301 if this ends up the case again, comment this out again. */
@@ -1170,7 +1329,7 @@ x_make_frame_invisible (struct frame *f)
1170 -------------------------------------------------------------------------- */ 1329 -------------------------------------------------------------------------- */
1171{ 1330{
1172 NSView *view; 1331 NSView *view;
1173 NSTRACE (x_make_frame_invisible); 1332 NSTRACE ("x_make_frame_invisible");
1174 check_window_system (f); 1333 check_window_system (f);
1175 view = FRAME_NS_VIEW (f); 1334 view = FRAME_NS_VIEW (f);
1176 [[view window] orderOut: NSApp]; 1335 [[view window] orderOut: NSApp];
@@ -1188,7 +1347,7 @@ x_iconify_frame (struct frame *f)
1188 NSView *view; 1347 NSView *view;
1189 struct ns_display_info *dpyinfo; 1348 struct ns_display_info *dpyinfo;
1190 1349
1191 NSTRACE (x_iconify_frame); 1350 NSTRACE ("x_iconify_frame");
1192 check_window_system (f); 1351 check_window_system (f);
1193 view = FRAME_NS_VIEW (f); 1352 view = FRAME_NS_VIEW (f);
1194 dpyinfo = FRAME_DISPLAY_INFO (f); 1353 dpyinfo = FRAME_DISPLAY_INFO (f);
@@ -1220,7 +1379,7 @@ x_free_frame_resources (struct frame *f)
1220 struct ns_display_info *dpyinfo; 1379 struct ns_display_info *dpyinfo;
1221 Mouse_HLInfo *hlinfo; 1380 Mouse_HLInfo *hlinfo;
1222 1381
1223 NSTRACE (x_free_frame_resources); 1382 NSTRACE ("x_free_frame_resources");
1224 check_window_system (f); 1383 check_window_system (f);
1225 view = FRAME_NS_VIEW (f); 1384 view = FRAME_NS_VIEW (f);
1226 dpyinfo = FRAME_DISPLAY_INFO (f); 1385 dpyinfo = FRAME_DISPLAY_INFO (f);
@@ -1257,7 +1416,7 @@ x_destroy_window (struct frame *f)
1257 External: Delete the window 1416 External: Delete the window
1258 -------------------------------------------------------------------------- */ 1417 -------------------------------------------------------------------------- */
1259{ 1418{
1260 NSTRACE (x_destroy_window); 1419 NSTRACE ("x_destroy_window");
1261 check_window_system (f); 1420 check_window_system (f);
1262 x_free_frame_resources (f); 1421 x_free_frame_resources (f);
1263 ns_window_num--; 1422 ns_window_num--;
@@ -1275,7 +1434,7 @@ x_set_offset (struct frame *f, int xoff, int yoff, int change_grav)
1275 NSScreen *fscreen = [screens objectAtIndex: 0]; 1434 NSScreen *fscreen = [screens objectAtIndex: 0];
1276 NSScreen *screen = [[view window] screen]; 1435 NSScreen *screen = [[view window] screen];
1277 1436
1278 NSTRACE (x_set_offset); 1437 NSTRACE ("x_set_offset");
1279 1438
1280 block_input (); 1439 block_input ();
1281 1440
@@ -1301,10 +1460,11 @@ x_set_offset (struct frame *f, int xoff, int yoff, int change_grav)
1301#endif 1460#endif
1302 /* Constrain the setFrameTopLeftPoint so we don't move behind the 1461 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1303 menu bar. */ 1462 menu bar. */
1304 [[view window] setFrameTopLeftPoint: 1463 NSPoint pt = NSMakePoint (SCREENMAXBOUND (f->left_pos),
1305 NSMakePoint (SCREENMAXBOUND (f->left_pos), 1464 SCREENMAXBOUND ([fscreen frame].size.height
1306 SCREENMAXBOUND ([fscreen frame].size.height 1465 - NS_TOP_POS (f)));
1307 - NS_TOP_POS (f)))]; 1466 NSTRACE_POINT ("setFrameTopLeftPoint", pt);
1467 [[view window] setFrameTopLeftPoint: pt];
1308 f->size_hint_flags &= ~(XNegative|YNegative); 1468 f->size_hint_flags &= ~(XNegative|YNegative);
1309 } 1469 }
1310 1470
@@ -1332,11 +1492,13 @@ x_set_window_size (struct frame *f,
1332 int rows, cols; 1492 int rows, cols;
1333 int orig_height = wr.size.height; 1493 int orig_height = wr.size.height;
1334 1494
1335 NSTRACE (x_set_window_size); 1495 NSTRACE ("x_set_window_size");
1336 1496
1337 if (view == nil) 1497 if (view == nil)
1338 return; 1498 return;
1339 1499
1500 NSTRACE_RECT ("input", wr);
1501
1340/*fprintf (stderr, "\tsetWindowSize: %d x %d, pixelwise %d, font size %d x %d\n", width, height, pixelwise, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f));*/ 1502/*fprintf (stderr, "\tsetWindowSize: %d x %d, pixelwise %d, font size %d x %d\n", width, height, pixelwise, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f));*/
1341 1503
1342 block_input (); 1504 block_input ();
@@ -1398,6 +1560,7 @@ x_set_window_size (struct frame *f,
1398 make_number (FRAME_TOOLBAR_HEIGHT (f)))); 1560 make_number (FRAME_TOOLBAR_HEIGHT (f))));
1399 1561
1400 [view setRows: rows andColumns: cols]; 1562 [view setRows: rows andColumns: cols];
1563 NSTRACE_RECT ("setFrame", wr);
1401 [window setFrame: wr display: YES]; 1564 [window setFrame: wr display: YES];
1402 1565
1403 /* This is a trick to compensate for Emacs' managing the scrollbar area 1566 /* This is a trick to compensate for Emacs' managing the scrollbar area
@@ -1412,6 +1575,7 @@ x_set_window_size (struct frame *f,
1412 ? NSMakePoint (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) 1575 ? NSMakePoint (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f)
1413 - NS_SCROLL_BAR_WIDTH (f), 0) 1576 - NS_SCROLL_BAR_WIDTH (f), 0)
1414 : NSMakePoint (0, 0); 1577 : NSMakePoint (0, 0);
1578 NSTRACE_RECT ("setFrame", wr);
1415 [view setFrame: NSMakeRect (0, 0, pixelwidth, pixelheight)]; 1579 [view setFrame: NSMakeRect (0, 0, pixelwidth, pixelheight)];
1416 [view setBoundsOrigin: origin]; 1580 [view setBoundsOrigin: origin];
1417 } 1581 }
@@ -1426,6 +1590,8 @@ ns_fullscreen_hook (struct frame *f)
1426{ 1590{
1427 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f); 1591 EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
1428 1592
1593 NSTRACE ("ns_fullscreen_hook");
1594
1429 if (!FRAME_VISIBLE_P (f)) 1595 if (!FRAME_VISIBLE_P (f))
1430 return; 1596 return;
1431 1597
@@ -1672,7 +1838,7 @@ ns_lisp_to_color (Lisp_Object color, NSColor **col)
1672 Convert a Lisp string object to a NS color 1838 Convert a Lisp string object to a NS color
1673 -------------------------------------------------------------------------- */ 1839 -------------------------------------------------------------------------- */
1674{ 1840{
1675 NSTRACE (ns_lisp_to_color); 1841 NSTRACE ("ns_lisp_to_color");
1676 if (STRINGP (color)) 1842 if (STRINGP (color))
1677 return ns_get_color (SSDATA (color), col); 1843 return ns_get_color (SSDATA (color), col);
1678 else if (SYMBOLP (color)) 1844 else if (SYMBOLP (color))
@@ -1690,7 +1856,7 @@ ns_color_to_lisp (NSColor *col)
1690 EmacsCGFloat red, green, blue, alpha, gray; 1856 EmacsCGFloat red, green, blue, alpha, gray;
1691 char buf[1024]; 1857 char buf[1024];
1692 const char *str; 1858 const char *str;
1693 NSTRACE (ns_color_to_lisp); 1859 NSTRACE ("ns_color_to_lisp");
1694 1860
1695 block_input (); 1861 block_input ();
1696 if ([[col colorSpaceName] isEqualToString: NSNamedColorSpace]) 1862 if ([[col colorSpaceName] isEqualToString: NSNamedColorSpace])
@@ -1758,7 +1924,7 @@ ns_defined_color (struct frame *f,
1758 -------------------------------------------------------------------------- */ 1924 -------------------------------------------------------------------------- */
1759{ 1925{
1760 NSColor *col; 1926 NSColor *col;
1761 NSTRACE (ns_defined_color); 1927 NSTRACE ("ns_defined_color");
1762 1928
1763 block_input (); 1929 block_input ();
1764 if (ns_get_color (name, &col) != 0) /* Color not found */ 1930 if (ns_get_color (name, &col) != 0) /* Color not found */
@@ -1823,7 +1989,7 @@ frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
1823 Programmatically reposition mouse pointer in pixel coordinates 1989 Programmatically reposition mouse pointer in pixel coordinates
1824 -------------------------------------------------------------------------- */ 1990 -------------------------------------------------------------------------- */
1825{ 1991{
1826 NSTRACE (frame_set_mouse_pixel_position); 1992 NSTRACE ("frame_set_mouse_pixel_position");
1827 ns_raise_frame (f); 1993 ns_raise_frame (f);
1828#if 0 1994#if 0
1829 /* FIXME: this does not work, and what about GNUstep? */ 1995 /* FIXME: this does not work, and what about GNUstep? */
@@ -1846,7 +2012,7 @@ note_mouse_movement (struct frame *frame, CGFloat x, CGFloat y)
1846 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame); 2012 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
1847 NSRect *r; 2013 NSRect *r;
1848 2014
1849// NSTRACE (note_mouse_movement); 2015// NSTRACE ("note_mouse_movement");
1850 2016
1851 dpyinfo->last_mouse_motion_frame = frame; 2017 dpyinfo->last_mouse_motion_frame = frame;
1852 r = &dpyinfo->last_mouse_glyph; 2018 r = &dpyinfo->last_mouse_glyph;
@@ -1887,7 +2053,7 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
1887 struct frame *f; 2053 struct frame *f;
1888 struct ns_display_info *dpyinfo; 2054 struct ns_display_info *dpyinfo;
1889 2055
1890 NSTRACE (ns_mouse_position); 2056 NSTRACE ("ns_mouse_position");
1891 2057
1892 if (*fp == NULL) 2058 if (*fp == NULL)
1893 { 2059 {
@@ -1943,7 +2109,7 @@ ns_frame_up_to_date (struct frame *f)
1943 Can't use FRAME_MOUSE_UPDATE due to ns_frame_begin and ns_frame_end calls. 2109 Can't use FRAME_MOUSE_UPDATE due to ns_frame_begin and ns_frame_end calls.
1944 -------------------------------------------------------------------------- */ 2110 -------------------------------------------------------------------------- */
1945{ 2111{
1946 NSTRACE (ns_frame_up_to_date); 2112 NSTRACE ("ns_frame_up_to_date");
1947 2113
1948 if (FRAME_NS_P (f)) 2114 if (FRAME_NS_P (f))
1949 { 2115 {
@@ -1968,7 +2134,7 @@ ns_define_frame_cursor (struct frame *f, Cursor cursor)
1968 External (RIF): set frame mouse pointer type. 2134 External (RIF): set frame mouse pointer type.
1969 -------------------------------------------------------------------------- */ 2135 -------------------------------------------------------------------------- */
1970{ 2136{
1971 NSTRACE (ns_define_frame_cursor); 2137 NSTRACE ("ns_define_frame_cursor");
1972 if (FRAME_POINTER_TYPE (f) != cursor) 2138 if (FRAME_POINTER_TYPE (f) != cursor)
1973 { 2139 {
1974 EmacsView *view = FRAME_NS_VIEW (f); 2140 EmacsView *view = FRAME_NS_VIEW (f);
@@ -2015,7 +2181,7 @@ x_get_keysym_name (int keysym)
2015 -------------------------------------------------------------------------- */ 2181 -------------------------------------------------------------------------- */
2016{ 2182{
2017 static char value[16]; 2183 static char value[16];
2018 NSTRACE (x_get_keysym_name); 2184 NSTRACE ("x_get_keysym_name");
2019 sprintf (value, "%d", keysym); 2185 sprintf (value, "%d", keysym);
2020 return value; 2186 return value;
2021} 2187}
@@ -2035,7 +2201,7 @@ ns_redraw_scroll_bars (struct frame *f)
2035 int i; 2201 int i;
2036 id view; 2202 id view;
2037 NSArray *subviews = [[FRAME_NS_VIEW (f) superview] subviews]; 2203 NSArray *subviews = [[FRAME_NS_VIEW (f) superview] subviews];
2038 NSTRACE (ns_redraw_scroll_bars); 2204 NSTRACE ("ns_redraw_scroll_bars");
2039 for (i =[subviews count]-1; i >= 0; i--) 2205 for (i =[subviews count]-1; i >= 0; i--)
2040 { 2206 {
2041 view = [subviews objectAtIndex: i]; 2207 view = [subviews objectAtIndex: i];
@@ -2054,7 +2220,7 @@ ns_clear_frame (struct frame *f)
2054 NSView *view = FRAME_NS_VIEW (f); 2220 NSView *view = FRAME_NS_VIEW (f);
2055 NSRect r; 2221 NSRect r;
2056 2222
2057 NSTRACE (ns_clear_frame); 2223 NSTRACE ("ns_clear_frame");
2058 2224
2059 /* comes on initial frame because we have 2225 /* comes on initial frame because we have
2060 after-make-frame-functions = select-frame */ 2226 after-make-frame-functions = select-frame */
@@ -2090,7 +2256,7 @@ ns_clear_frame_area (struct frame *f, int x, int y, int width, int height)
2090 if (!view || !face) 2256 if (!view || !face)
2091 return; 2257 return;
2092 2258
2093 NSTRACE (ns_clear_frame_area); 2259 NSTRACE ("ns_clear_frame_area");
2094 2260
2095 r = NSIntersectionRect (r, [view frame]); 2261 r = NSIntersectionRect (r, [view frame]);
2096 ns_focus (f, &r, 1); 2262 ns_focus (f, &r, 1);
@@ -2124,7 +2290,7 @@ ns_scroll_run (struct window *w, struct run *run)
2124 struct frame *f = XFRAME (w->frame); 2290 struct frame *f = XFRAME (w->frame);
2125 int x, y, width, height, from_y, to_y, bottom_y; 2291 int x, y, width, height, from_y, to_y, bottom_y;
2126 2292
2127 NSTRACE (ns_scroll_run); 2293 NSTRACE ("ns_scroll_run");
2128 2294
2129 /* begin copy from other terms */ 2295 /* begin copy from other terms */
2130 /* Get frame-relative bounding box of the text display area of W, 2296 /* Get frame-relative bounding box of the text display area of W,
@@ -2183,7 +2349,7 @@ ns_after_update_window_line (struct window *w, struct glyph_row *desired_row)
2183 struct frame *f; 2349 struct frame *f;
2184 int width, height; 2350 int width, height;
2185 2351
2186 NSTRACE (ns_after_update_window_line); 2352 NSTRACE ("ns_after_update_window_line");
2187 2353
2188 /* begin copy from other terms */ 2354 /* begin copy from other terms */
2189 eassert (w); 2355 eassert (w);
@@ -2224,7 +2390,7 @@ ns_shift_glyphs_for_insert (struct frame *f,
2224 NSRect srcRect = NSMakeRect (x, y, width, height); 2390 NSRect srcRect = NSMakeRect (x, y, width, height);
2225 NSRect dstRect = NSMakeRect (x+shift_by, y, width, height); 2391 NSRect dstRect = NSMakeRect (x+shift_by, y, width, height);
2226 2392
2227 NSTRACE (ns_shift_glyphs_for_insert); 2393 NSTRACE ("ns_shift_glyphs_for_insert");
2228 2394
2229 ns_copy_bits (f, srcRect, dstRect); 2395 ns_copy_bits (f, srcRect, dstRect);
2230} 2396}
@@ -2394,7 +2560,7 @@ ns_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
2394 in mini-buffer windows when switching between echo area glyphs 2560 in mini-buffer windows when switching between echo area glyphs
2395 and mini-buffer. */ 2561 and mini-buffer. */
2396 2562
2397 NSTRACE (dumpcursor); 2563 NSTRACE ("dumpcursor");
2398 2564
2399 if (!on_p) 2565 if (!on_p)
2400 return; 2566 return;
@@ -2523,7 +2689,7 @@ ns_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
2523 struct face *face; 2689 struct face *face;
2524 NSRect r = NSMakeRect (x, y0, 1, y1-y0); 2690 NSRect r = NSMakeRect (x, y0, 1, y1-y0);
2525 2691
2526 NSTRACE (ns_draw_vertical_window_border); 2692 NSTRACE ("ns_draw_vertical_window_border");
2527 2693
2528 face = FACE_FROM_ID (f, VERTICAL_BORDER_FACE_ID); 2694 face = FACE_FROM_ID (f, VERTICAL_BORDER_FACE_ID);
2529 if (face) 2695 if (face)
@@ -2545,7 +2711,7 @@ ns_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1)
2545 struct face *face; 2711 struct face *face;
2546 NSRect r = NSMakeRect (x0, y0, x1-x0, y1-y0); 2712 NSRect r = NSMakeRect (x0, y0, x1-x0, y1-y0);
2547 2713
2548 NSTRACE (ns_draw_window_divider); 2714 NSTRACE ("ns_draw_window_divider");
2549 2715
2550 face = FACE_FROM_ID (f, WINDOW_DIVIDER_FACE_ID); 2716 face = FACE_FROM_ID (f, WINDOW_DIVIDER_FACE_ID);
2551 if (face) 2717 if (face)
@@ -2802,7 +2968,7 @@ ns_draw_relief (NSRect r, int thickness, char raised_p,
2802 NSColor *newBaseCol = nil; 2968 NSColor *newBaseCol = nil;
2803 NSRect sr = r; 2969 NSRect sr = r;
2804 2970
2805 NSTRACE (ns_draw_relief); 2971 NSTRACE ("ns_draw_relief");
2806 2972
2807 /* set up colors */ 2973 /* set up colors */
2808 2974
@@ -2889,7 +3055,7 @@ ns_dumpglyphs_box_or_relief (struct glyph_string *s)
2889 3055
2890 thickness = face->box_line_width; 3056 thickness = face->box_line_width;
2891 3057
2892 NSTRACE (ns_dumpglyphs_box_or_relief); 3058 NSTRACE ("ns_dumpglyphs_box_or_relief");
2893 3059
2894 last_x = ((s->row->full_width_p && !s->w->pseudo_window_p) 3060 last_x = ((s->row->full_width_p && !s->w->pseudo_window_p)
2895 ? WINDOW_RIGHT_EDGE_X (s->w) 3061 ? WINDOW_RIGHT_EDGE_X (s->w)
@@ -2931,7 +3097,7 @@ ns_maybe_dumpglyphs_background (struct glyph_string *s, char force_p)
2931 certain cases. Others are left to the text rendering routine. 3097 certain cases. Others are left to the text rendering routine.
2932 -------------------------------------------------------------------------- */ 3098 -------------------------------------------------------------------------- */
2933{ 3099{
2934 NSTRACE (ns_maybe_dumpglyphs_background); 3100 NSTRACE ("ns_maybe_dumpglyphs_background");
2935 3101
2936 if (!s->background_filled_p/* || s->hl == DRAW_MOUSE_FACE*/) 3102 if (!s->background_filled_p/* || s->hl == DRAW_MOUSE_FACE*/)
2937 { 3103 {
@@ -2994,7 +3160,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2994 struct face *face; 3160 struct face *face;
2995 NSColor *tdCol; 3161 NSColor *tdCol;
2996 3162
2997 NSTRACE (ns_dumpglyphs_image); 3163 NSTRACE ("ns_dumpglyphs_image");
2998 3164
2999 if (s->face->box != FACE_NO_BOX 3165 if (s->face->box != FACE_NO_BOX
3000 && s->first_glyph->left_box_line_p && s->slice.x == 0) 3166 && s->first_glyph->left_box_line_p && s->slice.x == 0)
@@ -3311,7 +3477,7 @@ ns_draw_glyph_string (struct glyph_string *s)
3311 struct font *font = s->face->font; 3477 struct font *font = s->face->font;
3312 if (! font) font = FRAME_FONT (s->f); 3478 if (! font) font = FRAME_FONT (s->f);
3313 3479
3314 NSTRACE (ns_draw_glyph_string); 3480 NSTRACE ("ns_draw_glyph_string");
3315 3481
3316 if (s->next && s->right_overhang && !s->for_overlaps/*&&s->hl!=DRAW_CURSOR*/) 3482 if (s->next && s->right_overhang && !s->for_overlaps/*&&s->hl!=DRAW_CURSOR*/)
3317 { 3483 {
@@ -3469,7 +3635,7 @@ ns_send_appdefined (int value)
3469 recognize and take as a command to halt the event loop. 3635 recognize and take as a command to halt the event loop.
3470 -------------------------------------------------------------------------- */ 3636 -------------------------------------------------------------------------- */
3471{ 3637{
3472 /*NSTRACE (ns_send_appdefined); */ 3638 /*NSTRACE ("ns_send_appdefined"); */
3473 3639
3474#ifdef NS_IMPL_GNUSTEP 3640#ifdef NS_IMPL_GNUSTEP
3475 // GNUstep needs postEvent to happen on the main thread. 3641 // GNUstep needs postEvent to happen on the main thread.
@@ -3643,7 +3809,7 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
3643 struct input_event ev; 3809 struct input_event ev;
3644 int nevents; 3810 int nevents;
3645 3811
3646/* NSTRACE (ns_read_socket); */ 3812/* NSTRACE ("ns_read_socket"); */
3647 3813
3648#ifdef HAVE_NATIVE_FS 3814#ifdef HAVE_NATIVE_FS
3649 check_native_fs (); 3815 check_native_fs ();
@@ -3727,7 +3893,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
3727 struct input_event event; 3893 struct input_event event;
3728 char c; 3894 char c;
3729 3895
3730/* NSTRACE (ns_select); */ 3896/* NSTRACE ("ns_select"); */
3731 3897
3732#ifdef HAVE_NATIVE_FS 3898#ifdef HAVE_NATIVE_FS
3733 check_native_fs (); 3899 check_native_fs ();
@@ -3903,7 +4069,7 @@ ns_set_vertical_scroll_bar (struct window *window,
3903 } 4069 }
3904 } 4070 }
3905 4071
3906 NSTRACE (ns_set_vertical_scroll_bar); 4072 NSTRACE ("ns_set_vertical_scroll_bar");
3907 4073
3908 /* Get dimensions. */ 4074 /* Get dimensions. */
3909 window_box (window, ANY_AREA, 0, &window_y, 0, &window_height); 4075 window_box (window, ANY_AREA, 0, &window_y, 0, &window_height);
@@ -3997,7 +4163,7 @@ ns_set_horizontal_scroll_bar (struct window *window,
3997 } 4163 }
3998 } 4164 }
3999 4165
4000 NSTRACE (ns_set_horizontal_scroll_bar); 4166 NSTRACE ("ns_set_horizontal_scroll_bar");
4001 4167
4002 /* Get dimensions. */ 4168 /* Get dimensions. */
4003 window_box (window, ANY_AREA, 0, &window_x, &window_width, 0); 4169 window_box (window, ANY_AREA, 0, &window_x, &window_width, 0);
@@ -4069,7 +4235,7 @@ ns_condemn_scroll_bars (struct frame *f)
4069 id view; 4235 id view;
4070 NSArray *subviews = [[FRAME_NS_VIEW (f) superview] subviews]; 4236 NSArray *subviews = [[FRAME_NS_VIEW (f) superview] subviews];
4071 4237
4072 NSTRACE (ns_condemn_scroll_bars); 4238 NSTRACE ("ns_condemn_scroll_bars");
4073 4239
4074 for (i =[subviews count]-1; i >= 0; i--) 4240 for (i =[subviews count]-1; i >= 0; i--)
4075 { 4241 {
@@ -4088,7 +4254,7 @@ ns_redeem_scroll_bar (struct window *window)
4088 -------------------------------------------------------------------------- */ 4254 -------------------------------------------------------------------------- */
4089{ 4255{
4090 id bar; 4256 id bar;
4091 NSTRACE (ns_redeem_scroll_bar); 4257 NSTRACE ("ns_redeem_scroll_bar");
4092 if (!NILP (window->vertical_scroll_bar)) 4258 if (!NILP (window->vertical_scroll_bar))
4093 { 4259 {
4094 bar = XNS_SCROLL_BAR (window->vertical_scroll_bar); 4260 bar = XNS_SCROLL_BAR (window->vertical_scroll_bar);
@@ -4116,7 +4282,7 @@ ns_judge_scroll_bars (struct frame *f)
4116 NSArray *subviews = [[eview superview] subviews]; 4282 NSArray *subviews = [[eview superview] subviews];
4117 BOOL removed = NO; 4283 BOOL removed = NO;
4118 4284
4119 NSTRACE (ns_judge_scroll_bars); 4285 NSTRACE ("ns_judge_scroll_bars");
4120 for (i = [subviews count]-1; i >= 0; --i) 4286 for (i = [subviews count]-1; i >= 0; --i)
4121 { 4287 {
4122 view = [subviews objectAtIndex: i]; 4288 view = [subviews objectAtIndex: i];
@@ -4294,6 +4460,8 @@ ns_delete_terminal (struct terminal *terminal)
4294{ 4460{
4295 struct ns_display_info *dpyinfo = terminal->display_info.ns; 4461 struct ns_display_info *dpyinfo = terminal->display_info.ns;
4296 4462
4463 NSTRACE ("ns_delete_terminal");
4464
4297 /* Protect against recursive calls. delete_frame in 4465 /* Protect against recursive calls. delete_frame in
4298 delete_terminal calls us back when it deletes our last frame. */ 4466 delete_terminal calls us back when it deletes our last frame. */
4299 if (!terminal->name) 4467 if (!terminal->name)
@@ -4315,7 +4483,7 @@ ns_create_terminal (struct ns_display_info *dpyinfo)
4315{ 4483{
4316 struct terminal *terminal; 4484 struct terminal *terminal;
4317 4485
4318 NSTRACE (ns_create_terminal); 4486 NSTRACE ("ns_create_terminal");
4319 4487
4320 terminal = create_terminal (output_ns, &ns_redisplay_interface); 4488 terminal = create_terminal (output_ns, &ns_redisplay_interface);
4321 4489
@@ -4361,7 +4529,7 @@ ns_term_init (Lisp_Object display_name)
4361 if (ns_initialized) return x_display_list; 4529 if (ns_initialized) return x_display_list;
4362 ns_initialized = 1; 4530 ns_initialized = 1;
4363 4531
4364 NSTRACE (ns_term_init); 4532 NSTRACE ("ns_term_init");
4365 4533
4366 [outerpool release]; 4534 [outerpool release];
4367 outerpool = [[NSAutoreleasePool alloc] init]; 4535 outerpool = [[NSAutoreleasePool alloc] init];
@@ -4443,6 +4611,8 @@ ns_term_init (Lisp_Object display_name)
4443 ns_antialias_threshold = NILP (tmp) ? 10.0 : XFLOATINT (tmp); 4611 ns_antialias_threshold = NILP (tmp) ? 10.0 : XFLOATINT (tmp);
4444 } 4612 }
4445 4613
4614 NSTRACE_MSG ("Colors");
4615
4446 { 4616 {
4447 NSColorList *cl = [NSColorList colorListNamed: @"Emacs"]; 4617 NSColorList *cl = [NSColorList colorListNamed: @"Emacs"];
4448 4618
@@ -4476,6 +4646,8 @@ ns_term_init (Lisp_Object display_name)
4476 } 4646 }
4477 } 4647 }
4478 4648
4649 NSTRACE_MSG ("Versions");
4650
4479 { 4651 {
4480#ifdef NS_IMPL_GNUSTEP 4652#ifdef NS_IMPL_GNUSTEP
4481 Vwindow_system_version = build_string (gnustep_base_version); 4653 Vwindow_system_version = build_string (gnustep_base_version);
@@ -4491,7 +4663,10 @@ ns_term_init (Lisp_Object display_name)
4491 4663
4492 ns_app_name = [[NSProcessInfo processInfo] processName]; 4664 ns_app_name = [[NSProcessInfo processInfo] processName];
4493 4665
4494/* Set up OS X app menu */ 4666 /* Set up OS X app menu */
4667
4668 NSTRACE_MSG ("Menu init");
4669
4495#ifdef NS_IMPL_COCOA 4670#ifdef NS_IMPL_COCOA
4496 { 4671 {
4497 NSMenu *appMenu; 4672 NSMenu *appMenu;
@@ -4564,6 +4739,9 @@ ns_term_init (Lisp_Object display_name)
4564 4739
4565 /* Register our external input/output types, used for determining 4740 /* Register our external input/output types, used for determining
4566 applicable services and also drag/drop eligibility. */ 4741 applicable services and also drag/drop eligibility. */
4742
4743 NSTRACE_MSG ("Input/output types");
4744
4567 ns_send_types = [[NSArray arrayWithObjects: NSStringPboardType, nil] retain]; 4745 ns_send_types = [[NSArray arrayWithObjects: NSStringPboardType, nil] retain];
4568 ns_return_types = [[NSArray arrayWithObjects: NSStringPboardType, nil] 4746 ns_return_types = [[NSArray arrayWithObjects: NSStringPboardType, nil]
4569 retain]; 4747 retain];
@@ -4577,6 +4755,8 @@ ns_term_init (Lisp_Object display_name)
4577 right for fullscreen windows, so set this. */ 4755 right for fullscreen windows, so set this. */
4578 [NSApp activateIgnoringOtherApps:YES]; 4756 [NSApp activateIgnoringOtherApps:YES];
4579 4757
4758 NSTRACE_MSG ("Call NSApp run");
4759
4580 [NSApp run]; 4760 [NSApp run];
4581 ns_do_open_file = YES; 4761 ns_do_open_file = YES;
4582 4762
@@ -4585,6 +4765,9 @@ ns_term_init (Lisp_Object display_name)
4585 We must re-catch it so subprocess works. */ 4765 We must re-catch it so subprocess works. */
4586 catch_child_signal (); 4766 catch_child_signal ();
4587#endif 4767#endif
4768
4769 NSTRACE_MSG ("ns_term_init done");
4770
4588 return dpyinfo; 4771 return dpyinfo;
4589} 4772}
4590 4773
@@ -4697,7 +4880,7 @@ ns_term_shutdown (int sig)
4697 int type = [theEvent type]; 4880 int type = [theEvent type];
4698 NSWindow *window = [theEvent window]; 4881 NSWindow *window = [theEvent window];
4699 4882
4700/* NSTRACE (sendEvent); */ 4883/* NSTRACE ("sendEvent"); */
4701/*fprintf (stderr, "received event of type %d\t%d\n", type);*/ 4884/*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4702 4885
4703#ifdef NS_IMPL_GNUSTEP 4886#ifdef NS_IMPL_GNUSTEP
@@ -4847,7 +5030,7 @@ ns_term_shutdown (int sig)
4847 When application is loaded, terminate event loop in ns_term_init 5030 When application is loaded, terminate event loop in ns_term_init
4848 -------------------------------------------------------------------------- */ 5031 -------------------------------------------------------------------------- */
4849{ 5032{
4850 NSTRACE (applicationDidFinishLaunching); 5033 NSTRACE ("applicationDidFinishLaunching");
4851#ifdef NS_IMPL_GNUSTEP 5034#ifdef NS_IMPL_GNUSTEP
4852 ((EmacsApp *)self)->applicationDidFinishLaunchingCalled = YES; 5035 ((EmacsApp *)self)->applicationDidFinishLaunchingCalled = YES;
4853#endif 5036#endif
@@ -5015,7 +5198,7 @@ not_in_argv (NSString *arg)
5015} 5198}
5016- (void)applicationDidBecomeActive: (NSNotification *)notification 5199- (void)applicationDidBecomeActive: (NSNotification *)notification
5017{ 5200{
5018 NSTRACE (applicationDidBecomeActive); 5201 NSTRACE ("applicationDidBecomeActive");
5019 5202
5020#ifdef NS_IMPL_GNUSTEP 5203#ifdef NS_IMPL_GNUSTEP
5021 if (! applicationDidFinishLaunchingCalled) 5204 if (! applicationDidFinishLaunchingCalled)
@@ -5047,7 +5230,7 @@ not_in_argv (NSString *arg)
5047 The timeout specified to ns_select has passed. 5230 The timeout specified to ns_select has passed.
5048 -------------------------------------------------------------------------- */ 5231 -------------------------------------------------------------------------- */
5049{ 5232{
5050 /*NSTRACE (timeout_handler); */ 5233 /*NSTRACE ("timeout_handler"); */
5051 ns_send_appdefined (-2); 5234 ns_send_appdefined (-2);
5052} 5235}
5053 5236
@@ -5071,7 +5254,7 @@ not_in_argv (NSString *arg)
5071 struct timespec timeout, *tmo; 5254 struct timespec timeout, *tmo;
5072 NSAutoreleasePool *pool = nil; 5255 NSAutoreleasePool *pool = nil;
5073 5256
5074 /* NSTRACE (fd_handler); */ 5257 /* NSTRACE ("fd_handler"); */
5075 5258
5076 for (;;) 5259 for (;;)
5077 { 5260 {
@@ -5208,7 +5391,7 @@ not_in_argv (NSString *arg)
5208 5391
5209- (void)dealloc 5392- (void)dealloc
5210{ 5393{
5211 NSTRACE (EmacsView_dealloc); 5394 NSTRACE ("EmacsView_dealloc");
5212 [toolbar release]; 5395 [toolbar release];
5213 if (fs_state == FULLSCREEN_BOTH) 5396 if (fs_state == FULLSCREEN_BOTH)
5214 [nonfs_window release]; 5397 [nonfs_window release];
@@ -5226,7 +5409,7 @@ not_in_argv (NSString *arg)
5226 CGFloat size; 5409 CGFloat size;
5227 NSFont *nsfont; 5410 NSFont *nsfont;
5228 5411
5229 NSTRACE (changeFont); 5412 NSTRACE ("changeFont");
5230 5413
5231 if (!emacs_event) 5414 if (!emacs_event)
5232 return; 5415 return;
@@ -5256,7 +5439,7 @@ not_in_argv (NSString *arg)
5256 5439
5257- (BOOL)acceptsFirstResponder 5440- (BOOL)acceptsFirstResponder
5258{ 5441{
5259 NSTRACE (acceptsFirstResponder); 5442 NSTRACE ("acceptsFirstResponder");
5260 return YES; 5443 return YES;
5261} 5444}
5262 5445
@@ -5265,7 +5448,7 @@ not_in_argv (NSString *arg)
5265{ 5448{
5266 NSRect visible = [self visibleRect]; 5449 NSRect visible = [self visibleRect];
5267 NSCursor *currentCursor = FRAME_POINTER_TYPE (emacsframe); 5450 NSCursor *currentCursor = FRAME_POINTER_TYPE (emacsframe);
5268 NSTRACE (resetCursorRects); 5451 NSTRACE ("resetCursorRects");
5269 5452
5270 if (currentCursor == nil) 5453 if (currentCursor == nil)
5271 currentCursor = [NSCursor arrowCursor]; 5454 currentCursor = [NSCursor arrowCursor];
@@ -5290,7 +5473,7 @@ not_in_argv (NSString *arg)
5290 int left_is_none; 5473 int left_is_none;
5291 unsigned int flags = [theEvent modifierFlags]; 5474 unsigned int flags = [theEvent modifierFlags];
5292 5475
5293 NSTRACE (keyDown); 5476 NSTRACE ("keyDown");
5294 5477
5295 /* Rhapsody and OS X give up and down events for the arrow keys */ 5478 /* Rhapsody and OS X give up and down events for the arrow keys */
5296 if (ns_fake_keydown == YES) 5479 if (ns_fake_keydown == YES)
@@ -5753,7 +5936,7 @@ not_in_argv (NSString *arg)
5753 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); 5936 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe);
5754 NSPoint p = [self convertPoint: [theEvent locationInWindow] fromView: nil]; 5937 NSPoint p = [self convertPoint: [theEvent locationInWindow] fromView: nil];
5755 5938
5756 NSTRACE (mouseDown); 5939 NSTRACE ("mouseDown");
5757 5940
5758 [self deleteWorkingText]; 5941 [self deleteWorkingText];
5759 5942
@@ -5774,7 +5957,7 @@ not_in_argv (NSString *arg)
5774 delta = [theEvent deltaX]; 5957 delta = [theEvent deltaX];
5775 if (delta == 0) 5958 if (delta == 0)
5776 { 5959 {
5777 NSTRACE (deltaIsZero); 5960 NSTRACE ("deltaIsZero");
5778 return; 5961 return;
5779 } 5962 }
5780 emacs_event->kind = HORIZ_WHEEL_EVENT; 5963 emacs_event->kind = HORIZ_WHEEL_EVENT;
@@ -5801,42 +5984,42 @@ not_in_argv (NSString *arg)
5801 5984
5802- (void)rightMouseDown: (NSEvent *)theEvent 5985- (void)rightMouseDown: (NSEvent *)theEvent
5803{ 5986{
5804 NSTRACE (rightMouseDown); 5987 NSTRACE ("rightMouseDown");
5805 [self mouseDown: theEvent]; 5988 [self mouseDown: theEvent];
5806} 5989}
5807 5990
5808 5991
5809- (void)otherMouseDown: (NSEvent *)theEvent 5992- (void)otherMouseDown: (NSEvent *)theEvent
5810{ 5993{
5811 NSTRACE (otherMouseDown); 5994 NSTRACE ("otherMouseDown");
5812 [self mouseDown: theEvent]; 5995 [self mouseDown: theEvent];
5813} 5996}
5814 5997
5815 5998
5816- (void)mouseUp: (NSEvent *)theEvent 5999- (void)mouseUp: (NSEvent *)theEvent
5817{ 6000{
5818 NSTRACE (mouseUp); 6001 NSTRACE ("mouseUp");
5819 [self mouseDown: theEvent]; 6002 [self mouseDown: theEvent];
5820} 6003}
5821 6004
5822 6005
5823- (void)rightMouseUp: (NSEvent *)theEvent 6006- (void)rightMouseUp: (NSEvent *)theEvent
5824{ 6007{
5825 NSTRACE (rightMouseUp); 6008 NSTRACE ("rightMouseUp");
5826 [self mouseDown: theEvent]; 6009 [self mouseDown: theEvent];
5827} 6010}
5828 6011
5829 6012
5830- (void)otherMouseUp: (NSEvent *)theEvent 6013- (void)otherMouseUp: (NSEvent *)theEvent
5831{ 6014{
5832 NSTRACE (otherMouseUp); 6015 NSTRACE ("otherMouseUp");
5833 [self mouseDown: theEvent]; 6016 [self mouseDown: theEvent];
5834} 6017}
5835 6018
5836 6019
5837- (void) scrollWheel: (NSEvent *)theEvent 6020- (void) scrollWheel: (NSEvent *)theEvent
5838{ 6021{
5839 NSTRACE (scrollWheel); 6022 NSTRACE ("scrollWheel");
5840 [self mouseDown: theEvent]; 6023 [self mouseDown: theEvent];
5841} 6024}
5842 6025
@@ -5849,7 +6032,7 @@ not_in_argv (NSString *arg)
5849 Lisp_Object frame; 6032 Lisp_Object frame;
5850 NSPoint pt; 6033 NSPoint pt;
5851 6034
5852// NSTRACE (mouseMoved); 6035// NSTRACE ("mouseMoved");
5853 6036
5854 dpyinfo->last_mouse_movement_time = EV_TIMESTAMP (e); 6037 dpyinfo->last_mouse_movement_time = EV_TIMESTAMP (e);
5855 pt = [self convertPoint: [e locationInWindow] fromView: nil]; 6038 pt = [self convertPoint: [e locationInWindow] fromView: nil];
@@ -5869,7 +6052,7 @@ not_in_argv (NSString *arg)
5869 6052
5870 if (!NILP (Vmouse_autoselect_window)) 6053 if (!NILP (Vmouse_autoselect_window))
5871 { 6054 {
5872 NSTRACE (mouse_autoselect_window); 6055 NSTRACE ("mouse_autoselect_window");
5873 static Lisp_Object last_mouse_window; 6056 static Lisp_Object last_mouse_window;
5874 Lisp_Object window 6057 Lisp_Object window
5875 = window_from_coordinates (emacsframe, pt.x, pt.y, 0, 0); 6058 = window_from_coordinates (emacsframe, pt.x, pt.y, 0, 0);
@@ -5881,7 +6064,7 @@ not_in_argv (NSString *arg)
5881 || (EQ (XWINDOW (window)->frame, 6064 || (EQ (XWINDOW (window)->frame,
5882 XWINDOW (selected_window)->frame)))) 6065 XWINDOW (selected_window)->frame))))
5883 { 6066 {
5884 NSTRACE (in_window); 6067 NSTRACE ("in_window");
5885 emacs_event->kind = SELECT_WINDOW_EVENT; 6068 emacs_event->kind = SELECT_WINDOW_EVENT;
5886 emacs_event->frame_or_window = window; 6069 emacs_event->frame_or_window = window;
5887 EV_TRAILER2 (e); 6070 EV_TRAILER2 (e);
@@ -5911,21 +6094,21 @@ not_in_argv (NSString *arg)
5911 6094
5912- (void)mouseDragged: (NSEvent *)e 6095- (void)mouseDragged: (NSEvent *)e
5913{ 6096{
5914 NSTRACE (mouseDragged); 6097 NSTRACE ("mouseDragged");
5915 [self mouseMoved: e]; 6098 [self mouseMoved: e];
5916} 6099}
5917 6100
5918 6101
5919- (void)rightMouseDragged: (NSEvent *)e 6102- (void)rightMouseDragged: (NSEvent *)e
5920{ 6103{
5921 NSTRACE (rightMouseDragged); 6104 NSTRACE ("rightMouseDragged");
5922 [self mouseMoved: e]; 6105 [self mouseMoved: e];
5923} 6106}
5924 6107
5925 6108
5926- (void)otherMouseDragged: (NSEvent *)e 6109- (void)otherMouseDragged: (NSEvent *)e
5927{ 6110{
5928 NSTRACE (otherMouseDragged); 6111 NSTRACE ("otherMouseDragged");
5929 [self mouseMoved: e]; 6112 [self mouseMoved: e];
5930} 6113}
5931 6114
@@ -5934,7 +6117,7 @@ not_in_argv (NSString *arg)
5934{ 6117{
5935 NSEvent *e =[[self window] currentEvent]; 6118 NSEvent *e =[[self window] currentEvent];
5936 6119
5937 NSTRACE (windowShouldClose); 6120 NSTRACE ("windowShouldClose");
5938 windowClosing = YES; 6121 windowClosing = YES;
5939 if (!emacs_event) 6122 if (!emacs_event)
5940 return NO; 6123 return NO;
@@ -5956,8 +6139,9 @@ not_in_argv (NSString *arg)
5956 int oldh = FRAME_PIXEL_HEIGHT (emacsframe); 6139 int oldh = FRAME_PIXEL_HEIGHT (emacsframe);
5957 int neww, newh; 6140 int neww, newh;
5958 6141
5959 NSTRACE (updateFrameSize); 6142 NSTRACE ("updateFrameSize");
5960 NSTRACE_SIZE ("Original size", NSMakeSize (oldw, oldh)); 6143 NSTRACE_SIZE ("Original size", NSMakeSize (oldw, oldh));
6144 NSTRACE_RECT ("Original frame", wr);
5961 6145
5962 if (! [self isFullscreen]) 6146 if (! [self isFullscreen])
5963 { 6147 {
@@ -5994,7 +6178,6 @@ not_in_argv (NSString *arg)
5994 { 6178 {
5995 NSView *view = FRAME_NS_VIEW (emacsframe); 6179 NSView *view = FRAME_NS_VIEW (emacsframe);
5996 NSWindow *win = [view window]; 6180 NSWindow *win = [view window];
5997 NSSize sz = [win resizeIncrements];
5998 6181
5999 change_frame_size (emacsframe, 6182 change_frame_size (emacsframe,
6000 FRAME_PIXEL_TO_TEXT_WIDTH (emacsframe, neww), 6183 FRAME_PIXEL_TO_TEXT_WIDTH (emacsframe, neww),
@@ -6003,21 +6186,9 @@ not_in_argv (NSString *arg)
6003 SET_FRAME_GARBAGED (emacsframe); 6186 SET_FRAME_GARBAGED (emacsframe);
6004 cancel_mouse_face (emacsframe); 6187 cancel_mouse_face (emacsframe);
6005 6188
6006 // Did resize increments change because of a font change? 6189 wr = NSMakeRect (0, 0, neww, newh);
6007 if (sz.width != FRAME_COLUMN_WIDTH (emacsframe) || 6190 NSTRACE_RECT ("setFrame", wr);
6008 sz.height != FRAME_LINE_HEIGHT (emacsframe) || 6191 [view setFrame: wr];
6009 (frame_resize_pixelwise && sz.width != 1))
6010 {
6011 sz.width = frame_resize_pixelwise
6012 ? 1 : FRAME_COLUMN_WIDTH (emacsframe);
6013 sz.height = frame_resize_pixelwise
6014 ? 1 : FRAME_LINE_HEIGHT (emacsframe);
6015 [win setResizeIncrements: sz];
6016
6017 NSTRACE_SIZE ("New size", NSMakeSize (neww, newh));
6018 }
6019
6020 [view setFrame: NSMakeRect (0, 0, neww, newh)];
6021 [self windowDidMove:nil]; // Update top/left. 6192 [self windowDidMove:nil]; // Update top/left.
6022 } 6193 }
6023} 6194}
@@ -6027,9 +6198,10 @@ not_in_argv (NSString *arg)
6027{ 6198{
6028 int extra = 0; 6199 int extra = 0;
6029 6200
6030 NSTRACE (windowWillResize); 6201 NSTRACE ("windowWillResize: toSize: " NSTRACE_FMT_SIZE,
6031 NSTRACE_SIZE ("Original size", frameSize); 6202 NSTRACE_ARG_SIZE (frameSize));
6032/*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */ 6203 NSTRACE_RECT ("[sender frame]", [sender frame]);
6204 NSTRACE_FSTYPE ("fs_state", fs_state);
6033 6205
6034 if (fs_state == FULLSCREEN_MAXIMIZED 6206 if (fs_state == FULLSCREEN_MAXIMIZED
6035 && (maximized_width != (int)frameSize.width 6207 && (maximized_width != (int)frameSize.width
@@ -6041,6 +6213,7 @@ not_in_argv (NSString *arg)
6041 else if (fs_state == FULLSCREEN_HEIGHT 6213 else if (fs_state == FULLSCREEN_HEIGHT
6042 && maximized_height != (int)frameSize.height) 6214 && maximized_height != (int)frameSize.height)
6043 [self setFSValue: FULLSCREEN_NONE]; 6215 [self setFSValue: FULLSCREEN_NONE];
6216
6044 if (fs_state == FULLSCREEN_NONE) 6217 if (fs_state == FULLSCREEN_NONE)
6045 maximized_width = maximized_height = -1; 6218 maximized_width = maximized_height = -1;
6046 6219
@@ -6090,7 +6263,33 @@ not_in_argv (NSString *arg)
6090 } 6263 }
6091 } 6264 }
6092#endif /* NS_IMPL_COCOA */ 6265#endif /* NS_IMPL_COCOA */
6093/*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */ 6266
6267 NSTRACE_MSG ("cols: %d rows: %d", cols, rows);
6268
6269 /* Restrict the new size to the text gird.
6270
6271 Don't restict the width if the user only adjusted the height, and
6272 vice versa. (Without this, the frame would shrink, and move
6273 slightly, if the window was resized by dragging one of its
6274 borders.) */
6275 if (!frame_resize_pixelwise)
6276 {
6277 NSRect r = [[self window] frame];
6278
6279 if (r.size.width != frameSize.width)
6280 {
6281 frameSize.width =
6282 FRAME_TEXT_COLS_TO_PIXEL_WIDTH (emacsframe, cols);
6283 }
6284
6285 if (r.size.height != frameSize.height)
6286 {
6287 frameSize.height =
6288 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (emacsframe, rows) + extra;
6289 }
6290 }
6291
6292 NSTRACE_RETURN_SIZE (frameSize);
6094 6293
6095 return frameSize; 6294 return frameSize;
6096} 6295}
@@ -6098,6 +6297,8 @@ not_in_argv (NSString *arg)
6098 6297
6099- (void)windowDidResize: (NSNotification *)notification 6298- (void)windowDidResize: (NSNotification *)notification
6100{ 6299{
6300 NSTRACE ("windowDidResize");
6301
6101 if (! [self fsIsNative]) 6302 if (! [self fsIsNative])
6102 { 6303 {
6103 NSWindow *theWindow = [notification object]; 6304 NSWindow *theWindow = [notification object];
@@ -6106,6 +6307,8 @@ not_in_argv (NSString *arg)
6106 if ([self window] != theWindow) return; 6307 if ([self window] != theWindow) return;
6107 } 6308 }
6108 6309
6310 NSTRACE_RECT ("frame", [[notification object] frame]);
6311
6109#ifdef NS_IMPL_GNUSTEP 6312#ifdef NS_IMPL_GNUSTEP
6110 NSWindow *theWindow = [notification object]; 6313 NSWindow *theWindow = [notification object];
6111 6314
@@ -6116,10 +6319,7 @@ not_in_argv (NSString *arg)
6116 sz = [self windowWillResize: theWindow toSize: sz]; 6319 sz = [self windowWillResize: theWindow toSize: sz];
6117#endif /* NS_IMPL_GNUSTEP */ 6320#endif /* NS_IMPL_GNUSTEP */
6118 6321
6119 NSTRACE (windowDidResize); 6322 if (cols > 0 && rows > 0)
6120/*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
6121
6122if (cols > 0 && rows > 0)
6123 { 6323 {
6124 [self updateFrameSize: YES]; 6324 [self updateFrameSize: YES];
6125 } 6325 }
@@ -6148,7 +6348,7 @@ if (cols > 0 && rows > 0)
6148 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); 6348 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe);
6149 struct frame *old_focus = dpyinfo->x_focus_frame; 6349 struct frame *old_focus = dpyinfo->x_focus_frame;
6150 6350
6151 NSTRACE (windowDidBecomeKey); 6351 NSTRACE ("windowDidBecomeKey");
6152 6352
6153 if (emacsframe != old_focus) 6353 if (emacsframe != old_focus)
6154 dpyinfo->x_focus_frame = emacsframe; 6354 dpyinfo->x_focus_frame = emacsframe;
@@ -6168,7 +6368,7 @@ if (cols > 0 && rows > 0)
6168{ 6368{
6169 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); 6369 struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe);
6170 BOOL is_focus_frame = dpyinfo->x_focus_frame == emacsframe; 6370 BOOL is_focus_frame = dpyinfo->x_focus_frame == emacsframe;
6171 NSTRACE (windowDidResignKey); 6371 NSTRACE ("windowDidResignKey");
6172 6372
6173 if (is_focus_frame) 6373 if (is_focus_frame)
6174 dpyinfo->x_focus_frame = 0; 6374 dpyinfo->x_focus_frame = 0;
@@ -6203,7 +6403,7 @@ if (cols > 0 && rows > 0)
6203 6403
6204- (void)windowWillMiniaturize: sender 6404- (void)windowWillMiniaturize: sender
6205{ 6405{
6206 NSTRACE (windowWillMiniaturize); 6406 NSTRACE ("windowWillMiniaturize");
6207} 6407}
6208 6408
6209 6409
@@ -6224,11 +6424,10 @@ if (cols > 0 && rows > 0)
6224 NSRect r, wr; 6424 NSRect r, wr;
6225 Lisp_Object tem; 6425 Lisp_Object tem;
6226 NSWindow *win; 6426 NSWindow *win;
6227 NSSize sz;
6228 NSColor *col; 6427 NSColor *col;
6229 NSString *name; 6428 NSString *name;
6230 6429
6231 NSTRACE (initFrameFromEmacs); 6430 NSTRACE ("initFrameFromEmacs");
6232 6431
6233 windowClosing = NO; 6432 windowClosing = NO;
6234 processingCompose = NO; 6433 processingCompose = NO;
@@ -6283,9 +6482,6 @@ if (cols > 0 && rows > 0)
6283 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 6482 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9
6284 [win useOptimizedDrawing: YES]; 6483 [win useOptimizedDrawing: YES];
6285#endif 6484#endif
6286 sz.width = frame_resize_pixelwise ? 1 : FRAME_COLUMN_WIDTH (f);
6287 sz.height = frame_resize_pixelwise ? 1 : FRAME_LINE_HEIGHT (f);
6288 [win setResizeIncrements: sz];
6289 6485
6290 [[win contentView] addSubview: self]; 6486 [[win contentView] addSubview: self];
6291 6487
@@ -6329,10 +6525,18 @@ if (cols > 0 && rows > 0)
6329 NSScreen *screen = [win screen]; 6525 NSScreen *screen = [win screen];
6330 6526
6331 if (screen != 0) 6527 if (screen != 0)
6332 [win setFrameTopLeftPoint: NSMakePoint 6528 {
6333 (IN_BOUND (-SCREENMAX, f->left_pos, SCREENMAX), 6529 NSPoint pt = NSMakePoint
6334 IN_BOUND (-SCREENMAX, 6530 (IN_BOUND (-SCREENMAX, f->left_pos, SCREENMAX),
6335 [screen frame].size.height - NS_TOP_POS (f), SCREENMAX))]; 6531 IN_BOUND (-SCREENMAX,
6532 [screen frame].size.height - NS_TOP_POS (f), SCREENMAX));
6533
6534 NSTRACE_POINT ("setFrameTopLeftPoint", pt);
6535
6536 [win setFrameTopLeftPoint: pt];
6537
6538 NSTRACE_RECT ("new frame", [win frame]);
6539 }
6336 } 6540 }
6337 6541
6338 [win makeFirstResponder: self]; 6542 [win makeFirstResponder: self];
@@ -6362,7 +6566,7 @@ if (cols > 0 && rows > 0)
6362 NSArray *screens = [NSScreen screens]; 6566 NSArray *screens = [NSScreen screens];
6363 NSScreen *screen = [screens objectAtIndex: 0]; 6567 NSScreen *screen = [screens objectAtIndex: 0];
6364 6568
6365 NSTRACE (windowDidMove); 6569 NSTRACE ("windowDidMove");
6366 6570
6367 if (!emacsframe->output_data.ns) 6571 if (!emacsframe->output_data.ns)
6368 return; 6572 return;
@@ -6380,6 +6584,10 @@ if (cols > 0 && rows > 0)
6380 location so set_window_size moves the frame. */ 6584 location so set_window_size moves the frame. */
6381- (BOOL)windowShouldZoom: (NSWindow *)sender toFrame: (NSRect)newFrame 6585- (BOOL)windowShouldZoom: (NSWindow *)sender toFrame: (NSRect)newFrame
6382{ 6586{
6587 NSTRACE (("[windowShouldZoom:win toFrame:" NSTRACE_FMT_RECT "]"
6588 NSTRACE_FMT_RETURN "YES"),
6589 NSTRACE_ARG_RECT (newFrame));
6590
6383 emacsframe->output_data.ns->zooming = 1; 6591 emacsframe->output_data.ns->zooming = 1;
6384 return YES; 6592 return YES;
6385} 6593}
@@ -6391,71 +6599,124 @@ if (cols > 0 && rows > 0)
6391- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender 6599- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender
6392 defaultFrame:(NSRect)defaultFrame 6600 defaultFrame:(NSRect)defaultFrame
6393{ 6601{
6602 // TODO: Rename to "currentFrame" and assign "result" properly in
6603 // all paths.
6394 NSRect result = [sender frame]; 6604 NSRect result = [sender frame];
6395 6605
6396 NSTRACE (windowWillUseStandardFrame); 6606 NSTRACE (("[windowWillUseStandardFrame: defaultFrame:"
6607 NSTRACE_FMT_RECT "]"),
6608 NSTRACE_ARG_RECT (defaultFrame));
6609 NSTRACE_FSTYPE ("fs_state", fs_state);
6610 NSTRACE_FSTYPE ("fs_before_fs", fs_before_fs);
6611 NSTRACE_FSTYPE ("next_maximized", next_maximized);
6612 NSTRACE_RECT ("ns_userRect", ns_userRect);
6613 NSTRACE_RECT ("[sender frame]", [sender frame]);
6397 6614
6398 if (fs_before_fs != -1) /* Entering fullscreen */ 6615 if (fs_before_fs != -1) /* Entering fullscreen */
6399 {
6400 result = defaultFrame;
6401 }
6402 else if (next_maximized == FULLSCREEN_HEIGHT
6403 || (next_maximized == -1
6404 && abs ((int)(defaultFrame.size.height - result.size.height))
6405 > FRAME_LINE_HEIGHT (emacsframe)))
6406 {
6407 /* first click */
6408 ns_userRect = result;
6409 maximized_height = result.size.height = defaultFrame.size.height;
6410 maximized_width = -1;
6411 result.origin.y = defaultFrame.origin.y;
6412 [self setFSValue: FULLSCREEN_HEIGHT];
6413#ifdef NS_IMPL_COCOA
6414 maximizing_resize = YES;
6415#endif
6416 }
6417 else if (next_maximized == FULLSCREEN_WIDTH)
6418 { 6616 {
6419 ns_userRect = result; 6617 NSTRACE_MSG ("Entering fullscreen");
6420 maximized_width = result.size.width = defaultFrame.size.width; 6618 result = defaultFrame;
6421 maximized_height = -1;
6422 result.origin.x = defaultFrame.origin.x;
6423 [self setFSValue: FULLSCREEN_WIDTH];
6424 } 6619 }
6425 else if (next_maximized == FULLSCREEN_MAXIMIZED 6620 else
6426 || (next_maximized == -1
6427 && abs ((int)(defaultFrame.size.width - result.size.width))
6428 > FRAME_COLUMN_WIDTH (emacsframe)))
6429 { 6621 {
6430 result = defaultFrame; /* second click */ 6622 // Save the window size and position (frame) before the resize.
6431 maximized_width = result.size.width; 6623 if (fs_state != FULLSCREEN_MAXIMIZED
6432 maximized_height = result.size.height; 6624 && fs_state != FULLSCREEN_WIDTH)
6433 [self setFSValue: FULLSCREEN_MAXIMIZED]; 6625 {
6626 ns_userRect.size.width = result.size.width;
6627 ns_userRect.origin.x = result.origin.x;
6628 }
6629
6630 if (fs_state != FULLSCREEN_MAXIMIZED
6631 && fs_state != FULLSCREEN_HEIGHT)
6632 {
6633 ns_userRect.size.height = result.size.height;
6634 ns_userRect.origin.y = result.origin.y;
6635 }
6636
6637 NSTRACE_RECT ("ns_userRect (2)", ns_userRect);
6638
6639 if (next_maximized == FULLSCREEN_HEIGHT
6640 || (next_maximized == -1
6641 && abs ((int)(defaultFrame.size.height - result.size.height))
6642 > FRAME_LINE_HEIGHT (emacsframe)))
6643 {
6644 /* first click */
6645 NSTRACE_MSG ("FULLSCREEN_HEIGHT");
6646 maximized_height = result.size.height = defaultFrame.size.height;
6647 maximized_width = -1;
6648 result.origin.y = defaultFrame.origin.y;
6649 if (ns_userRect.size.height != 0)
6650 {
6651 result.origin.x = ns_userRect.origin.x;
6652 result.size.width = ns_userRect.size.width;
6653 }
6654 [self setFSValue: FULLSCREEN_HEIGHT];
6434#ifdef NS_IMPL_COCOA 6655#ifdef NS_IMPL_COCOA
6435 maximizing_resize = YES; 6656 maximizing_resize = YES;
6436#endif 6657#endif
6437 } 6658 }
6438 else 6659 else if (next_maximized == FULLSCREEN_WIDTH)
6439 { 6660 {
6440 /* restore */ 6661 NSTRACE_MSG ("FULLSCREEN_WIDTH");
6441 result = ns_userRect.size.height ? ns_userRect : result; 6662 maximized_width = result.size.width = defaultFrame.size.width;
6442 ns_userRect = NSMakeRect (0, 0, 0, 0); 6663 maximized_height = -1;
6664 result.origin.x = defaultFrame.origin.x;
6665 if (ns_userRect.size.width != 0)
6666 {
6667 result.origin.y = ns_userRect.origin.y;
6668 result.size.height = ns_userRect.size.height;
6669 }
6670 [self setFSValue: FULLSCREEN_WIDTH];
6671 }
6672 else if (next_maximized == FULLSCREEN_MAXIMIZED
6673 || (next_maximized == -1
6674 && abs ((int)(defaultFrame.size.width - result.size.width))
6675 > FRAME_COLUMN_WIDTH (emacsframe)))
6676 {
6677 NSTRACE_MSG ("FULLSCREEN_MAXIMIZED");
6678
6679 result = defaultFrame; /* second click */
6680 maximized_width = result.size.width;
6681 maximized_height = result.size.height;
6682 [self setFSValue: FULLSCREEN_MAXIMIZED];
6683#ifdef NS_IMPL_COCOA
6684 maximizing_resize = YES;
6685#endif
6686 }
6687 else
6688 {
6689 /* restore */
6690 NSTRACE_MSG ("Restore");
6691 result = ns_userRect.size.height ? ns_userRect : result;
6692 NSTRACE_RECT ("restore (2)", result);
6693 ns_userRect = NSMakeRect (0, 0, 0, 0);
6443#ifdef NS_IMPL_COCOA 6694#ifdef NS_IMPL_COCOA
6444 maximizing_resize = fs_state != FULLSCREEN_NONE; 6695 maximizing_resize = fs_state != FULLSCREEN_NONE;
6445#endif 6696#endif
6446 [self setFSValue: FULLSCREEN_NONE]; 6697 [self setFSValue: FULLSCREEN_NONE];
6447 maximized_width = maximized_height = -1; 6698 maximized_width = maximized_height = -1;
6699 }
6448 } 6700 }
6449 6701
6450 if (fs_before_fs == -1) next_maximized = -1; 6702 if (fs_before_fs == -1) next_maximized = -1;
6703
6704 NSTRACE_RECT ("Final ns_userRect", ns_userRect);
6705 NSTRACE_MSG ("Final maximized_width: %d", maximized_width);
6706 NSTRACE_MSG ("Final maximized_height: %d", maximized_height);
6707 NSTRACE_FSTYPE ("Final next_maximized", next_maximized);
6708
6451 [self windowWillResize: sender toSize: result.size]; 6709 [self windowWillResize: sender toSize: result.size];
6710
6711 NSTRACE_RETURN_RECT (result);
6712
6452 return result; 6713 return result;
6453} 6714}
6454 6715
6455 6716
6456- (void)windowDidDeminiaturize: sender 6717- (void)windowDidDeminiaturize: sender
6457{ 6718{
6458 NSTRACE (windowDidDeminiaturize); 6719 NSTRACE ("windowDidDeminiaturize");
6459 if (!emacsframe->output_data.ns) 6720 if (!emacsframe->output_data.ns)
6460 return; 6721 return;
6461 6722
@@ -6473,7 +6734,7 @@ if (cols > 0 && rows > 0)
6473 6734
6474- (void)windowDidExpose: sender 6735- (void)windowDidExpose: sender
6475{ 6736{
6476 NSTRACE (windowDidExpose); 6737 NSTRACE ("windowDidExpose");
6477 if (!emacsframe->output_data.ns) 6738 if (!emacsframe->output_data.ns)
6478 return; 6739 return;
6479 6740
@@ -6487,7 +6748,7 @@ if (cols > 0 && rows > 0)
6487 6748
6488- (void)windowDidMiniaturize: sender 6749- (void)windowDidMiniaturize: sender
6489{ 6750{
6490 NSTRACE (windowDidMiniaturize); 6751 NSTRACE ("windowDidMiniaturize");
6491 if (!emacsframe->output_data.ns) 6752 if (!emacsframe->output_data.ns)
6492 return; 6753 return;
6493 6754
@@ -6512,11 +6773,13 @@ if (cols > 0 && rows > 0)
6512 6773
6513- (void)windowWillEnterFullScreen:(NSNotification *)notification 6774- (void)windowWillEnterFullScreen:(NSNotification *)notification
6514{ 6775{
6776 NSTRACE ("windowWillEnterFullScreen");
6515 fs_before_fs = fs_state; 6777 fs_before_fs = fs_state;
6516} 6778}
6517 6779
6518- (void)windowDidEnterFullScreen:(NSNotification *)notification 6780- (void)windowDidEnterFullScreen:(NSNotification *)notification
6519{ 6781{
6782 NSTRACE ("windowDidEnterFullScreen");
6520 [self setFSValue: FULLSCREEN_BOTH]; 6783 [self setFSValue: FULLSCREEN_BOTH];
6521 if (! [self fsIsNative]) 6784 if (! [self fsIsNative])
6522 { 6785 {
@@ -6550,12 +6813,16 @@ if (cols > 0 && rows > 0)
6550 6813
6551- (void)windowWillExitFullScreen:(NSNotification *)notification 6814- (void)windowWillExitFullScreen:(NSNotification *)notification
6552{ 6815{
6816 NSTRACE ("windowWillExitFullScreen");
6817
6553 if (next_maximized != -1) 6818 if (next_maximized != -1)
6554 fs_before_fs = next_maximized; 6819 fs_before_fs = next_maximized;
6555} 6820}
6556 6821
6557- (void)windowDidExitFullScreen:(NSNotification *)notification 6822- (void)windowDidExitFullScreen:(NSNotification *)notification
6558{ 6823{
6824 NSTRACE ("windowDidExitFullScreen");
6825
6559 [self setFSValue: fs_before_fs]; 6826 [self setFSValue: fs_before_fs];
6560 fs_before_fs = -1; 6827 fs_before_fs = -1;
6561#ifdef HAVE_NATIVE_FS 6828#ifdef HAVE_NATIVE_FS
@@ -6613,10 +6880,11 @@ if (cols > 0 && rows > 0)
6613 NSWindow *w, *fw; 6880 NSWindow *w, *fw;
6614 BOOL onFirstScreen; 6881 BOOL onFirstScreen;
6615 struct frame *f; 6882 struct frame *f;
6616 NSSize sz;
6617 NSRect r, wr; 6883 NSRect r, wr;
6618 NSColor *col; 6884 NSColor *col;
6619 6885
6886 NSTRACE ("toggleFullScreen");
6887
6620 if (fs_is_native) 6888 if (fs_is_native)
6621 { 6889 {
6622#ifdef HAVE_NATIVE_FS 6890#ifdef HAVE_NATIVE_FS
@@ -6633,9 +6901,6 @@ if (cols > 0 && rows > 0)
6633 (FRAME_DEFAULT_FACE (f)), 6901 (FRAME_DEFAULT_FACE (f)),
6634 f); 6902 f);
6635 6903
6636 sz.width = frame_resize_pixelwise ? 1 : FRAME_COLUMN_WIDTH (f);
6637 sz.height = frame_resize_pixelwise ? 1 : FRAME_LINE_HEIGHT (f);
6638
6639 if (fs_state != FULLSCREEN_BOTH) 6904 if (fs_state != FULLSCREEN_BOTH)
6640 { 6905 {
6641 NSScreen *screen = [w screen]; 6906 NSScreen *screen = [w screen];
@@ -6675,7 +6940,6 @@ if (cols > 0 && rows > 0)
6675 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9 6940 MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_9
6676 [fw useOptimizedDrawing: YES]; 6941 [fw useOptimizedDrawing: YES];
6677#endif 6942#endif
6678 [fw setResizeIncrements: sz];
6679 [fw setBackgroundColor: col]; 6943 [fw setBackgroundColor: col];
6680 if ([col alphaComponent] != (EmacsCGFloat) 1.0) 6944 if ([col alphaComponent] != (EmacsCGFloat) 1.0)
6681 [fw setOpaque: NO]; 6945 [fw setOpaque: NO];
@@ -6712,7 +6976,6 @@ if (cols > 0 && rows > 0)
6712 } 6976 }
6713 6977
6714 [w setContentView:[fw contentView]]; 6978 [w setContentView:[fw contentView]];
6715 [w setResizeIncrements: sz];
6716 [w setBackgroundColor: col]; 6979 [w setBackgroundColor: col];
6717 if ([col alphaComponent] != (EmacsCGFloat) 1.0) 6980 if ([col alphaComponent] != (EmacsCGFloat) 1.0)
6718 [w setOpaque: NO]; 6981 [w setOpaque: NO];
@@ -6733,39 +6996,42 @@ if (cols > 0 && rows > 0)
6733 6996
6734- (void)handleFS 6997- (void)handleFS
6735{ 6998{
6999 NSTRACE ("handleFS");
7000
6736 if (fs_state != emacsframe->want_fullscreen) 7001 if (fs_state != emacsframe->want_fullscreen)
6737 { 7002 {
6738 NSSize sz;
6739 sz.width = frame_resize_pixelwise ? 1 : FRAME_COLUMN_WIDTH (emacsframe);
6740 sz.height = frame_resize_pixelwise ? 1 : FRAME_LINE_HEIGHT (emacsframe);
6741 [[self window] setResizeIncrements:sz];
6742
6743 if (fs_state == FULLSCREEN_BOTH) 7003 if (fs_state == FULLSCREEN_BOTH)
6744 { 7004 {
7005 NSTRACE_MSG ("fs_state == FULLSCREEN_BOTH");
6745 [self toggleFullScreen:self]; 7006 [self toggleFullScreen:self];
6746 } 7007 }
6747 7008
6748 switch (emacsframe->want_fullscreen) 7009 switch (emacsframe->want_fullscreen)
6749 { 7010 {
6750 case FULLSCREEN_BOTH: 7011 case FULLSCREEN_BOTH:
7012 NSTRACE_MSG ("FULLSCREEN_BOTH");
6751 [self toggleFullScreen:self]; 7013 [self toggleFullScreen:self];
6752 break; 7014 break;
6753 case FULLSCREEN_WIDTH: 7015 case FULLSCREEN_WIDTH:
7016 NSTRACE_MSG ("FULLSCREEN_WIDTH");
6754 next_maximized = FULLSCREEN_WIDTH; 7017 next_maximized = FULLSCREEN_WIDTH;
6755 if (fs_state != FULLSCREEN_BOTH) 7018 if (fs_state != FULLSCREEN_BOTH)
6756 [[self window] performZoom:self]; 7019 [[self window] performZoom:self];
6757 break; 7020 break;
6758 case FULLSCREEN_HEIGHT: 7021 case FULLSCREEN_HEIGHT:
7022 NSTRACE_MSG ("FULLSCREEN_HEIGHT");
6759 next_maximized = FULLSCREEN_HEIGHT; 7023 next_maximized = FULLSCREEN_HEIGHT;
6760 if (fs_state != FULLSCREEN_BOTH) 7024 if (fs_state != FULLSCREEN_BOTH)
6761 [[self window] performZoom:self]; 7025 [[self window] performZoom:self];
6762 break; 7026 break;
6763 case FULLSCREEN_MAXIMIZED: 7027 case FULLSCREEN_MAXIMIZED:
7028 NSTRACE_MSG ("FULLSCREEN_MAXIMIZED");
6764 next_maximized = FULLSCREEN_MAXIMIZED; 7029 next_maximized = FULLSCREEN_MAXIMIZED;
6765 if (fs_state != FULLSCREEN_BOTH) 7030 if (fs_state != FULLSCREEN_BOTH)
6766 [[self window] performZoom:self]; 7031 [[self window] performZoom:self];
6767 break; 7032 break;
6768 case FULLSCREEN_NONE: 7033 case FULLSCREEN_NONE:
7034 NSTRACE_MSG ("FULLSCREEN_NONE");
6769 if (fs_state != FULLSCREEN_BOTH) 7035 if (fs_state != FULLSCREEN_BOTH)
6770 { 7036 {
6771 next_maximized = FULLSCREEN_NONE; 7037 next_maximized = FULLSCREEN_NONE;
@@ -6781,6 +7047,9 @@ if (cols > 0 && rows > 0)
6781 7047
6782- (void) setFSValue: (int)value 7048- (void) setFSValue: (int)value
6783{ 7049{
7050 NSTRACE ("setFSValue");
7051 NSTRACE_FSTYPE ("value", value);
7052
6784 Lisp_Object lval = Qnil; 7053 Lisp_Object lval = Qnil;
6785 switch (value) 7054 switch (value)
6786 { 7055 {
@@ -6803,7 +7072,7 @@ if (cols > 0 && rows > 0)
6803 7072
6804- (void)mouseEntered: (NSEvent *)theEvent 7073- (void)mouseEntered: (NSEvent *)theEvent
6805{ 7074{
6806 NSTRACE (mouseEntered); 7075 NSTRACE ("mouseEntered");
6807 if (emacsframe) 7076 if (emacsframe)
6808 FRAME_DISPLAY_INFO (emacsframe)->last_mouse_movement_time 7077 FRAME_DISPLAY_INFO (emacsframe)->last_mouse_movement_time
6809 = EV_TIMESTAMP (theEvent); 7078 = EV_TIMESTAMP (theEvent);
@@ -6814,7 +7083,7 @@ if (cols > 0 && rows > 0)
6814{ 7083{
6815 Mouse_HLInfo *hlinfo = emacsframe ? MOUSE_HL_INFO (emacsframe) : NULL; 7084 Mouse_HLInfo *hlinfo = emacsframe ? MOUSE_HL_INFO (emacsframe) : NULL;
6816 7085
6817 NSTRACE (mouseExited); 7086 NSTRACE ("mouseExited");
6818 7087
6819 if (!hlinfo) 7088 if (!hlinfo)
6820 return; 7089 return;
@@ -6832,7 +7101,7 @@ if (cols > 0 && rows > 0)
6832 7101
6833- menuDown: sender 7102- menuDown: sender
6834{ 7103{
6835 NSTRACE (menuDown); 7104 NSTRACE ("menuDown");
6836 if (context_menu_value == -1) 7105 if (context_menu_value == -1)
6837 context_menu_value = [sender tag]; 7106 context_menu_value = [sender tag];
6838 else 7107 else
@@ -6860,7 +7129,7 @@ if (cols > 0 && rows > 0)
6860 NSEvent *theEvent; 7129 NSEvent *theEvent;
6861 int idx = [item tag] * TOOL_BAR_ITEM_NSLOTS; 7130 int idx = [item tag] * TOOL_BAR_ITEM_NSLOTS;
6862 7131
6863 NSTRACE (toolbarClicked); 7132 NSTRACE ("toolbarClicked");
6864 7133
6865 if (!emacs_event) 7134 if (!emacs_event)
6866 return self; 7135 return self;
@@ -6898,7 +7167,8 @@ if (cols > 0 && rows > 0)
6898 int x = NSMinX (rect), y = NSMinY (rect); 7167 int x = NSMinX (rect), y = NSMinY (rect);
6899 int width = NSWidth (rect), height = NSHeight (rect); 7168 int width = NSWidth (rect), height = NSHeight (rect);
6900 7169
6901 NSTRACE (drawRect); 7170 NSTRACE ("drawRect");
7171 NSTRACE_RECT ("input", rect);
6902 7172
6903 if (!emacsframe || !emacsframe->output_data.ns) 7173 if (!emacsframe || !emacsframe->output_data.ns)
6904 return; 7174 return;
@@ -6924,7 +7194,7 @@ if (cols > 0 && rows > 0)
6924 7194
6925-(NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender 7195-(NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
6926{ 7196{
6927 NSTRACE (draggingEntered); 7197 NSTRACE ("draggingEntered");
6928 return NSDragOperationGeneric; 7198 return NSDragOperationGeneric;
6929} 7199}
6930 7200
@@ -6945,7 +7215,7 @@ if (cols > 0 && rows > 0)
6945 NSDragOperation op = [sender draggingSourceOperationMask]; 7215 NSDragOperation op = [sender draggingSourceOperationMask];
6946 int modifiers = 0; 7216 int modifiers = 0;
6947 7217
6948 NSTRACE (performDragOperation); 7218 NSTRACE ("performDragOperation");
6949 7219
6950 if (!emacs_event) 7220 if (!emacs_event)
6951 return NO; 7221 return NO;
@@ -7045,7 +7315,7 @@ if (cols > 0 && rows > 0)
7045- (id) validRequestorForSendType: (NSString *)typeSent 7315- (id) validRequestorForSendType: (NSString *)typeSent
7046 returnType: (NSString *)typeReturned 7316 returnType: (NSString *)typeReturned
7047{ 7317{
7048 NSTRACE (validRequestorForSendType); 7318 NSTRACE ("validRequestorForSendType");
7049 if (typeSent != nil && [ns_send_types indexOfObject: typeSent] != NSNotFound 7319 if (typeSent != nil && [ns_send_types indexOfObject: typeSent] != NSNotFound
7050 && typeReturned == nil) 7320 && typeReturned == nil)
7051 { 7321 {
@@ -7107,7 +7377,7 @@ if (cols > 0 && rows > 0)
7107- setMiniwindowImage: (BOOL) setMini 7377- setMiniwindowImage: (BOOL) setMini
7108{ 7378{
7109 id image = [[self window] miniwindowImage]; 7379 id image = [[self window] miniwindowImage];
7110 NSTRACE (setMiniwindowImage); 7380 NSTRACE ("setMiniwindowImage");
7111 7381
7112 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation 7382 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
7113 about "AppleDockIconEnabled" notwithstanding, however the set message 7383 about "AppleDockIconEnabled" notwithstanding, however the set message
@@ -7130,6 +7400,11 @@ if (cols > 0 && rows > 0)
7130 cols = c; 7400 cols = c;
7131} 7401}
7132 7402
7403- (int) fullscreenState
7404{
7405 return fs_state;
7406}
7407
7133@end /* EmacsView */ 7408@end /* EmacsView */
7134 7409
7135 7410
@@ -7199,73 +7474,133 @@ if (cols > 0 && rows > 0)
7199} 7474}
7200#endif /* NS_IMPL_COCOA */ 7475#endif /* NS_IMPL_COCOA */
7201 7476
7202/* If we have multiple monitors, one above the other, we don't want to 7477/* Constrain size and placement of a frame.
7203 restrict the height to just one monitor. So we override this. */
7204- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
7205{
7206 /* When making the frame visible for the first time or if there is just
7207 one screen, we want to constrain. Other times not. */
7208 NSArray *screens = [NSScreen screens];
7209 NSUInteger nr_screens = [screens count], nr_eff_screens = 0, i;
7210 NSTRACE (constrainFrameRect);
7211 NSTRACE_RECT ("input", frameRect);
7212 7478
7213 if (ns_menu_bar_should_be_hidden ()) 7479 By returning the original "frameRect", the frame is not
7214 return frameRect; 7480 contrained. This can lead to unwanted situations where, for
7481 example, the menu bar covers the frame.
7215 7482
7216 if (nr_screens == 1) 7483 The default implementation (accessed using "super") constrains the
7217 return [super constrainFrameRect:frameRect toScreen:screen]; 7484 frame to the visible area of SCREEN, minus the menu bar (if
7485 present) and the Dock. Note that default implementation also calls
7486 windowWillResize, with the frame it thinks should have. (This can
7487 make the frame exit maximized mode.)
7488
7489 Note that this should work in situations where multiple monitors
7490 are present. Common configurations are side-by-side monitors and a
7491 monitor on top of another (e.g. when a laptop is placed under a
7492 large screen). */
7493- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
7494{
7495 NSTRACE ("constrainFrameRect:" NSTRACE_FMT_RECT " toScreen:",
7496 NSTRACE_ARG_RECT (frameRect));
7218 7497
7219#ifdef NS_IMPL_COCOA 7498#ifdef NS_IMPL_COCOA
7220#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9 7499#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
7221 // If separate spaces is on, it is like each screen is independent. There is 7500 // If separate spaces is on, it is like each screen is independent. There is
7222 // no spanning of frames across screens. 7501 // no spanning of frames across screens.
7223 if ([NSScreen screensHaveSeparateSpaces]) 7502 if ([NSScreen screensHaveSeparateSpaces])
7224 return [super constrainFrameRect:frameRect toScreen:screen]; 7503 {
7504 NSTRACE_MSG ("Screens have separate spaces");
7505 frameRect = [super constrainFrameRect:frameRect toScreen:screen];
7506 NSTRACE_RETURN_RECT (frameRect);
7507 return frameRect;
7508 }
7225#endif 7509#endif
7226#endif 7510#endif
7227 7511
7228 for (i = 0; i < nr_screens; ++i) 7512 return constrain_frame_rect(frameRect);
7229 { 7513}
7230 NSScreen *s = [screens objectAtIndex: i];
7231 NSRect scrrect = [s frame];
7232 NSRect intersect = NSIntersectionRect (frameRect, scrrect);
7233 7514
7234 if (intersect.size.width > 0 || intersect.size.height > 0)
7235 ++nr_eff_screens;
7236 }
7237 7515
7238 if (nr_eff_screens == 1) 7516- (void)performZoom:(id)sender
7239 return [super constrainFrameRect:frameRect toScreen:screen]; 7517{
7518 NSTRACE ("performZoom");
7240 7519
7241 /* The default implementation does two things 1) ensure that the top 7520 return [super performZoom:sender];
7242 of the rectangle is below the menu bar (or below the top of the 7521}
7243 screen) and 2) resizes windows larger than the screen. As we
7244 don't want the latter, a smaller rectangle is used. */
7245#define FAKE_HEIGHT 64
7246 float old_top = frameRect.origin.y + frameRect.size.height;
7247 NSRect r;
7248 r.size.height = FAKE_HEIGHT;
7249 r.size.width = frameRect.size.width;
7250 r.origin.x = frameRect.origin.x;
7251 r.origin.y = old_top - FAKE_HEIGHT;
7252 7522
7253 NSTRACE_RECT ("input to super", r); 7523- (void)zoom:(id)sender
7524{
7525 struct frame * f = SELECTED_FRAME ();
7254 7526
7255 r = [super constrainFrameRect:r toScreen:screen]; 7527 NSTRACE ("zoom");
7256 7528
7257 NSTRACE_RECT ("output from super", r); 7529 ns_update_auto_hide_menu_bar();
7258 7530
7259 float new_top = r.origin.y + FAKE_HEIGHT; 7531 // Below are three zoom implementations. In the final commit, the
7260 if (new_top < old_top) 7532 // idea is that the last should be included.
7261 {
7262 frameRect.origin.y = new_top - frameRect.size.height;
7263 }
7264 7533
7265 NSTRACE_RECT ("output", frameRect); 7534#if 0
7535 // Native zoom done using the standard zoom animation. Size of the
7536 // resulting frame reduced to accomodate the Dock and, if present,
7537 // the menu-bar.
7538 [super zoom:sender];
7539
7540#elsif 0
7541 // Native zoom done using the standard zoom animation, plus an
7542 // explicit resize to cover the full screen.
7543 [super zoom:sender];
7544
7545 // After the native zoom, resize the resulting frame to fill the
7546 // entire screen, except the menu-bar.
7547 //
7548 // This works for all practical purposes. (The only minor oddity is
7549 // when transiting from full-height frame to a maximized, the
7550 // animation reduces the height of the frame slighty (to the 4
7551 // pixels needed to accomodate the Doc) before it snaps back into
7552 // full height. The user would need a very trained eye to spot
7553 // this.)
7554 NSScreen * screen = [self screen];
7555 if (screen != nil)
7556 {
7557 int fs_state = [(EmacsView *)[self delegate] fullscreenState];
7266 7558
7267 return frameRect; 7559 NSTRACE_FSTYPE ("fullscreenState", fs_state);
7268#undef FAKE_HEIGHT 7560
7561 NSRect sr = [screen frame];
7562 NSRect wr = [self frame];
7563 NSTRACE_RECT ("Rect after zoom", wr);
7564
7565 NSRect newWr = wr;
7566
7567 if (fs_state == FULLSCREEN_MAXIMIZED
7568 || fs_state == FULLSCREEN_HEIGHT)
7569 {
7570 newWr.origin.x = 0;
7571 newWr.size.height = sr.size.height - ns_menu_bar_height(screen);
7572 }
7573
7574 if (fs_state == FULLSCREEN_MAXIMIZED
7575 || fs_state == FULLSCREEN_WIDTH)
7576 {
7577 newWr.origin.y = 0;
7578 newWr.size.width = sr.size.width;
7579 }
7580
7581 if (newWr.size.width != wr.size.width
7582 || newWr.size.height != wr.size.height
7583 || newWr.origin.x != wr.origin.x
7584 || newWr.origin.y != wr.origin.y)
7585 {
7586 NSTRACE_RECT ("Corrected rect", newWr);
7587 [self setFrame: newWr display: NO];
7588 }
7589 }
7590#else
7591 // Non-native zoom which is done instantaneous. The resulting frame
7592 // covert the entire scrren, except the menu-bar, if present.
7593 NSScreen * screen = [self screen];
7594 if (screen != nil)
7595 {
7596 NSRect sr = [screen frame];
7597 sr.size.height -= ns_menu_bar_height (screen);
7598
7599 sr = [[self delegate] windowWillUseStandardFrame:self
7600 defaultFrame:sr];
7601 [self setFrame: sr display: NO];
7602 }
7603#endif
7269} 7604}
7270 7605
7271@end /* EmacsWindow */ 7606@end /* EmacsWindow */
@@ -7316,7 +7651,7 @@ if (cols > 0 && rows > 0)
7316 7651
7317- initFrame: (NSRect )r window: (Lisp_Object)nwin 7652- initFrame: (NSRect )r window: (Lisp_Object)nwin
7318{ 7653{
7319 NSTRACE (EmacsScroller_initFrame); 7654 NSTRACE ("EmacsScroller_initFrame");
7320 7655
7321 r.size.width = [EmacsScroller scrollerWidth]; 7656 r.size.width = [EmacsScroller scrollerWidth];
7322 [super initWithFrame: r/*NSMakeRect (0, 0, 0, 0)*/]; 7657 [super initWithFrame: r/*NSMakeRect (0, 0, 0, 0)*/];
@@ -7362,7 +7697,7 @@ if (cols > 0 && rows > 0)
7362 7697
7363- (void)setFrame: (NSRect)newRect 7698- (void)setFrame: (NSRect)newRect
7364{ 7699{
7365 NSTRACE (EmacsScroller_setFrame); 7700 NSTRACE ("EmacsScroller_setFrame");
7366/* block_input (); */ 7701/* block_input (); */
7367 pixel_height = NSHeight (newRect); 7702 pixel_height = NSHeight (newRect);
7368 if (pixel_height == 0) pixel_height = 1; 7703 if (pixel_height == 0) pixel_height = 1;
@@ -7374,7 +7709,7 @@ if (cols > 0 && rows > 0)
7374 7709
7375- (void)dealloc 7710- (void)dealloc
7376{ 7711{
7377 NSTRACE (EmacsScroller_dealloc); 7712 NSTRACE ("EmacsScroller_dealloc");
7378 if (window) 7713 if (window)
7379 wset_vertical_scroll_bar (window, Qnil); 7714 wset_vertical_scroll_bar (window, Qnil);
7380 window = 0; 7715 window = 0;
@@ -7384,7 +7719,7 @@ if (cols > 0 && rows > 0)
7384 7719
7385- condemn 7720- condemn
7386{ 7721{
7387 NSTRACE (condemn); 7722 NSTRACE ("condemn");
7388 condemned =YES; 7723 condemned =YES;
7389 return self; 7724 return self;
7390} 7725}
@@ -7392,7 +7727,7 @@ if (cols > 0 && rows > 0)
7392 7727
7393- reprieve 7728- reprieve
7394{ 7729{
7395 NSTRACE (reprieve); 7730 NSTRACE ("reprieve");
7396 condemned =NO; 7731 condemned =NO;
7397 return self; 7732 return self;
7398} 7733}
@@ -7400,7 +7735,7 @@ if (cols > 0 && rows > 0)
7400 7735
7401-(bool)judge 7736-(bool)judge
7402{ 7737{
7403 NSTRACE (judge); 7738 NSTRACE ("judge");
7404 bool ret = condemned; 7739 bool ret = condemned;
7405 if (condemned) 7740 if (condemned)
7406 { 7741 {
@@ -7424,7 +7759,7 @@ if (cols > 0 && rows > 0)
7424- (void)resetCursorRects 7759- (void)resetCursorRects
7425{ 7760{
7426 NSRect visible = [self visibleRect]; 7761 NSRect visible = [self visibleRect];
7427 NSTRACE (resetCursorRects); 7762 NSTRACE ("resetCursorRects");
7428 7763
7429 if (!NSIsEmptyRect (visible)) 7764 if (!NSIsEmptyRect (visible))
7430 [self addCursorRect: visible cursor: [NSCursor arrowCursor]]; 7765 [self addCursorRect: visible cursor: [NSCursor arrowCursor]];
@@ -7442,7 +7777,7 @@ if (cols > 0 && rows > 0)
7442 7777
7443- setPosition: (int)position portion: (int)portion whole: (int)whole 7778- setPosition: (int)position portion: (int)portion whole: (int)whole
7444{ 7779{
7445 NSTRACE (setPosition); 7780 NSTRACE ("setPosition");
7446 7781
7447 em_position = position; 7782 em_position = position;
7448 em_portion = portion; 7783 em_portion = portion;
@@ -7547,7 +7882,7 @@ if (cols > 0 && rows > 0)
7547 CGFloat inc = 0.0, loc, kloc, pos; 7882 CGFloat inc = 0.0, loc, kloc, pos;
7548 int edge = 0; 7883 int edge = 0;
7549 7884
7550 NSTRACE (EmacsScroller_mouseDown); 7885 NSTRACE ("EmacsScroller_mouseDown");
7551 7886
7552 switch (part) 7887 switch (part)
7553 { 7888 {
@@ -7644,7 +7979,7 @@ if (cols > 0 && rows > 0)
7644 NSRect sr; 7979 NSRect sr;
7645 double loc, pos; 7980 double loc, pos;
7646 7981
7647 NSTRACE (EmacsScroller_mouseDragged); 7982 NSTRACE ("EmacsScroller_mouseDragged");
7648 7983
7649 sr = [self convertRect: [self rectForPart: NSScrollerKnobSlot] 7984 sr = [self convertRect: [self rectForPart: NSScrollerKnobSlot]
7650 toView: nil]; 7985 toView: nil];
@@ -7813,7 +8148,7 @@ ns_xlfd_to_fontname (const char *xlfd)
7813void 8148void
7814syms_of_nsterm (void) 8149syms_of_nsterm (void)
7815{ 8150{
7816 NSTRACE (syms_of_nsterm); 8151 NSTRACE ("syms_of_nsterm");
7817 8152
7818 ns_antialias_threshold = 10.0; 8153 ns_antialias_threshold = 10.0;
7819 8154