changeset 64276:0a062d2d75f3

Don't include stdlib.h or composite.h. (x_use_underline_position_properties, last_mouse_press_frame) (x_noop_count, Qvendor_specific_keysyms): Remove unused variables. (syms_of_macterm, mac_initialize): Don't initialize them. (waiting_for_input, initial_argv, initial_argc) (Vcommand_line_args, Vx_no_window_manager, errno, window_scroll) (set_frame_menubar, path_from_vol_dir_name): Remove externs. (extra_keyboard_modifiers): Fix type in extern. (x_window_to_frame, x_window_to_scroll_bar): Remove declarations. (x_scroll_bar_report_motion): Add argument types to declaration. (mac_compute_glyph_string_overhangs): Add declaration. (disable_mouse_highlight): Remove unused variable. [USE_TOOLKIT_SCROLL_BARS] (construct_scroll_bar_click) (x_scroll_bar_handle_press, x_scroll_bar_handle_release) (x_scroll_bar_handle_drag): Remove argument `timestamp'. All callers changed. [USE_TOOLKIT_SCROLL_BARS] (construct_scroll_bar_click): Don't set timestamp. [USE_CARBON_EVENTS] (mac_handle_mouse_event): Likewise. (x_scroll_bar_create, XTset_vertical_scroll_bar): Show scroll bar only when its width is less than the height. (XTredeem_scroll_bar): Sync with xterm.c. (font_name_table, font_name_table_size, font_name_count): Make static. (drag_and_drop_file_list): Remove variable. Previous use is now local to function. (do_ae_open_documents): Move DRAG_N_DROP event construction part from XTread_socket. (XTread_socket): Consolidate setting of event timestamp. Move DRAG_N_DROP event construction part to do_ae_open_documents. Support extra_keyboard_modifiers.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Wed, 13 Jul 2005 09:12:59 +0000
parents a6a8c13a3caa
children 72dab4f8f589
files src/macterm.c
diffstat 1 files changed, 155 insertions(+), 320 deletions(-) [+]
line wrap: on
line diff
--- a/src/macterm.c	Wed Jul 13 09:11:35 2005 +0000
+++ b/src/macterm.c	Wed Jul 13 09:12:59 2005 +0000
@@ -22,10 +22,10 @@
 
 #include <config.h>
 #include <signal.h>
+
 #include <stdio.h>
-#include <stdlib.h>
+
 #include "lisp.h"
-#include "charset.h"
 #include "blockinput.h"
 
 #include "macterm.h"
@@ -62,8 +62,6 @@
 
 #include "systty.h"
 #include "systime.h"
-#include "atimer.h"
-#include "keymap.h"
 
 #include <ctype.h>
 #include <errno.h>
@@ -71,7 +69,8 @@
 #include <sys/stat.h>
 #include <sys/param.h>
 
-#include "keyboard.h"
+#include "charset.h"
+#include "coding.h"
 #include "frame.h"
 #include "dispextern.h"
 #include "fontset.h"
@@ -82,9 +81,10 @@
 #include "disptab.h"
 #include "buffer.h"
 #include "window.h"
+#include "keyboard.h"
 #include "intervals.h"
-#include "composite.h"
-#include "coding.h"
+#include "atimer.h"
+#include "keymap.h"
 
 /* Set of macros that handle mapping of Mac modifier keys to emacs.  */
 #define macCtrlKey     (NILP (Vmac_reverse_ctrl_meta) ? controlKey :	\
@@ -114,15 +114,6 @@
 /* Last window where we saw the mouse.  Used by mouse-autoselect-window.  */
 static Lisp_Object last_window;
 
-/* Non-zero means make use of UNDERLINE_POSITION font properties.  */
-
-int x_use_underline_position_properties;
-
-/* Non-zero means draw block and hollow cursor as wide as the glyph
-   under it.  For example, if a block cursor is over a tab, it will be
-   drawn as wide as that tab on the display.  */
-
-
 /* This is a chain of structures for all the X displays currently in
    use.  */
 
@@ -148,8 +139,6 @@
 
 extern struct frame *updating_frame;
 
-extern int waiting_for_input;
-
 /* This is a frame waiting to be auto-raised, within XTread_socket.  */
 
 struct frame *pending_autoraise_frame;
@@ -177,7 +166,6 @@
 /* Where the mouse was last time we reported a mouse event.  */
 
 static Rect last_mouse_glyph;
-static Lisp_Object last_mouse_press_frame;
 
 /* The scroll bar in which the last X motion event occurred.
 
@@ -211,45 +199,24 @@
 static int input_signal_count;
 #endif
 
-/* Used locally within XTread_socket.  */
-
-static int x_noop_count;
-
-/* Initial values of argv and argc.  */
-
-extern char **initial_argv;
-extern int initial_argc;
-
-extern Lisp_Object Vcommand_line_args, Vsystem_name;
-
-/* Tells if a window manager is present or not.  */
-
-extern Lisp_Object Vx_no_window_manager;
-
-extern int errno;
+extern Lisp_Object Vsystem_name;
 
 /* A mask of extra modifier bits to put into every keyboard char.  */
 
-extern int extra_keyboard_modifiers;
+extern EMACS_INT extra_keyboard_modifiers;
 
 /* The keysyms to use for the various modifiers.  */
 
 static Lisp_Object Qalt, Qhyper, Qsuper, Qmodifier_value;
 
-static Lisp_Object Qvendor_specific_keysyms;
-
-#if 0
-extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *));
-#endif
-
 extern int inhibit_window_system;
 
 #if __MRC__ && !TARGET_API_MAC_CARBON
 QDGlobals qd;  /* QuickDraw global information structure.  */
 #endif
 
-
-struct frame * x_window_to_frame (struct mac_display_info *, WindowPtr);
+#define mac_window_to_frame(wp) (((mac_output *) GetWRefCon (wp))->mFP)
+
 struct mac_display_info *mac_display_info_for_display (Display *);
 static void x_update_window_end P_ ((struct window *, int, int));
 static int x_io_error_quitter P_ ((Display *));
@@ -289,17 +256,18 @@
 static void x_update_begin P_ ((struct frame *));
 static void x_update_window_begin P_ ((struct window *));
 static void x_after_update_window_line P_ ((struct glyph_row *));
+static void x_scroll_bar_report_motion P_ ((struct frame **, Lisp_Object *,
+					    enum scroll_bar_part *,
+					    Lisp_Object *, Lisp_Object *,
+					    unsigned long *));
 
 static int is_emacs_window (WindowPtr);
 
 int x_bitmap_icon (struct frame *, Lisp_Object);
 void x_make_frame_visible (struct frame *);
 
-extern void window_scroll (Lisp_Object, int, int, int);
-
 /* Defined in macmenu.h.  */
 extern void menubar_selection_callback (FRAME_PTR, int);
-extern void set_frame_menubar (FRAME_PTR, int, int);
 
 /* X display function emulation */
 
@@ -912,24 +880,6 @@
 }
 
 
-#if 0
-/* Convert a pair of local coordinates to global (screen) coordinates.
-   Assume graphic port has been properly set.  */
-static void
-local_to_global_coord (short *h, short *v)
-{
-  Point p;
-
-  p.h = *h;
-  p.v = *v;
-
-  LocalToGlobal (&p);
-
-  *h = p.h;
-  *v = p.v;
-}
-#endif
-
 /* Mac replacement for XCopyArea: used only for scrolling.  */
 
 static void
@@ -953,23 +903,10 @@
   Rect src_r, dest_r;
 
   SetPort (w);
-#if 0
-  mac_set_colors (gc, NULL);
-#endif
 
   SetRect (&src_r, src_x, src_y, src_x + width, src_y + height);
   SetRect (&dest_r, dest_x, dest_y, dest_x + width, dest_y + height);
 
-#if 0
-  /* Need to use global coordinates and screenBits since src and dest
-     areas overlap in general.  */
-  local_to_global_coord (&src_r.left, &src_r.top);
-  local_to_global_coord (&src_r.right, &src_r.bottom);
-  local_to_global_coord (&dest_r.left, &dest_r.top);
-  local_to_global_coord (&dest_r.right, &dest_r.bottom);
-
-  CopyBits (&qd.screenBits, &qd.screenBits, &src_r, &dest_r, srcCopy, 0);
-#else
   /* In Color QuickDraw, set ForeColor and BackColor as follows to avoid
      color mapping in CopyBits.  Otherwise, it will be slow.  */
   ForeColor (blackColor);
@@ -977,7 +914,6 @@
   CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0);
 
   mac_set_colors (gc, NULL);
-#endif
 #endif /* not TARGET_API_MAC_CARBON */
 }
 
@@ -1345,7 +1281,6 @@
 	     f->output_data.mac->normal_gc, x, y0, x, y1);
 }
 
-
 /* End update of window W (which is equal to updated_window).
 
    Draw vertical borders between horizontally adjacent windows, and
@@ -1357,7 +1292,7 @@
 
    W may be a menu bar pseudo-window in case we don't have X toolkit
    support.  Such windows don't have a cursor, so don't display it
-   here. */
+   here.  */
 
 static void
 x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p)
@@ -1390,14 +1325,6 @@
       dpyinfo->mouse_face_window = Qnil;
     }
 
-#if 0
-  /* Unhide the caret.  This won't actually show the cursor, unless it
-     was visible before the corresponding call to HideCaret in
-     x_update_window_begin.  */
-  if (w32_use_visible_system_caret)
-    SendMessage (w32_system_caret_hwnd, WM_EMACS_SHOW_CARET, 0, 0);
-#endif
-
   updated_window = NULL;
 }
 
@@ -1483,19 +1410,18 @@
 	  height > 0))
     {
       int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y));
+
       /* Internal border is drawn below the tool bar.  */
       if (WINDOWP (f->tool_bar_window)
 	  && w == XWINDOW (f->tool_bar_window))
 	y -= width;
 
       BLOCK_INPUT;
-
       XClearArea (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f),
 		  0, y, width, height, 0);
       XClearArea (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f),
 		  FRAME_PIXEL_WIDTH (f) - width, y,
 		  width, height, 0);
-
       UNBLOCK_INPUT;
     }
 }
@@ -1581,6 +1507,7 @@
 }
 
 
+
 /* This is called when starting Emacs and when restarting after
    suspend.  When starting Emacs, no window is mapped.  And nothing
    must be done to Emacs's own window if it is suspended (though that
@@ -1599,6 +1526,7 @@
 {
 }
 
+
 
 /***********************************************************************
 			   Display Iterator
@@ -1786,6 +1714,7 @@
  ***********************************************************************/
 
 
+
 static void x_set_glyph_string_clipping P_ ((struct glyph_string *));
 static void x_set_glyph_string_gc P_ ((struct glyph_string *));
 static void x_draw_glyph_string_background P_ ((struct glyph_string *,
@@ -1794,6 +1723,7 @@
 static void x_draw_composite_glyph_string_foreground P_ ((struct glyph_string *));
 static void x_draw_glyph_string_box P_ ((struct glyph_string *));
 static void x_draw_glyph_string  P_ ((struct glyph_string *));
+static void mac_compute_glyph_string_overhangs P_ ((struct glyph_string *));
 static void x_set_cursor_gc P_ ((struct glyph_string *));
 static void x_set_mode_line_face_gc P_ ((struct glyph_string *));
 static void x_set_mouse_face_gc P_ ((struct glyph_string *));
@@ -3397,7 +3327,6 @@
     }
 }
 
-
 
 /* Specify how many text lines, from the top of the window,
    should be affected by insert-lines and delete-lines operations.
@@ -3832,43 +3761,6 @@
 
 
 
-#if 0
-/* Mouse clicks and mouse movement.  Rah.  */
-
-/* Prepare a mouse-event in *RESULT for placement in the input queue.
-
-   If the event is a button press, then note that we have grabbed
-   the mouse.  */
-
-static Lisp_Object
-construct_mouse_click (result, event, f)
-     struct input_event *result;
-     EventRecord *event;
-     struct frame *f;
-{
-  Point mouseLoc;
-
-  result->kind = MOUSE_CLICK_EVENT;
-  result->code = 0;  /* only one mouse button */
-  result->timestamp = event->when;
-  result->modifiers = event->what == mouseDown ? down_modifier : up_modifier;
-
-  mouseLoc = event->where;
-
-  SetPortWindowPort (FRAME_MAC_WINDOW (f));
-
-  GlobalToLocal (&mouseLoc);
-  XSETINT (result->x, mouseLoc.h);
-  XSETINT (result->y, mouseLoc.v);
-
-  XSETFRAME (result->frame_or_window, f);
-
-  result->arg = Qnil;
-  return Qnil;
-}
-#endif
-
-
 /* Function to report a mouse movement to the mainstream Emacs code.
    The input handler calls this.
 
@@ -3924,18 +3816,11 @@
     }
 }
 
-/* This is used for debugging, to turn off note_mouse_highlight.  */
-
-int disable_mouse_highlight;
-
-
 
 /************************************************************************
 			      Mouse Face
  ************************************************************************/
 
-static struct scroll_bar *x_window_to_scroll_bar ();
-static void x_scroll_bar_report_motion ();
 static int glyph_rect P_ ((struct frame *f, int, int, Rect *));
 
 
@@ -4147,20 +4032,16 @@
 static OSStatus set_scroll_bar_timer P_ ((EventTimerInterval));
 static int control_part_code_to_scroll_bar_part P_ ((ControlPartCode));
 static void construct_scroll_bar_click P_ ((struct scroll_bar *, int,
-					    unsigned long,
 					    struct input_event *));
 static OSErr get_control_part_bounds P_ ((ControlHandle, ControlPartCode,
 					  Rect *));
 static void x_scroll_bar_handle_press P_ ((struct scroll_bar *,
 					   ControlPartCode,
-					   unsigned long,
 					   struct input_event *));
 static void x_scroll_bar_handle_release P_ ((struct scroll_bar *,
-					     unsigned long,
 					     struct input_event *));
 static void x_scroll_bar_handle_drag P_ ((WindowPtr, struct scroll_bar *,
-					  Point, unsigned long,
-					  struct input_event *));
+					  Point, struct input_event *));
 static void x_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *,
 						int, int, int));
 
@@ -4259,10 +4140,9 @@
 }
 
 static void
-construct_scroll_bar_click (bar, part, timestamp, bufp)
+construct_scroll_bar_click (bar, part, bufp)
      struct scroll_bar *bar;
      int part;
-     unsigned long timestamp;
      struct input_event *bufp;
 {
   bufp->kind = SCROLL_BAR_CLICK_EVENT;
@@ -4270,7 +4150,6 @@
   bufp->arg = Qnil;
   bufp->part = part;
   bufp->code = 0;
-  bufp->timestamp = timestamp;
   XSETINT (bufp->x, 0);
   XSETINT (bufp->y, 0);
   bufp->modifiers = 0;
@@ -4294,10 +4173,9 @@
 }
 
 static void
-x_scroll_bar_handle_press (bar, part_code, timestamp, bufp)
+x_scroll_bar_handle_press (bar, part_code, bufp)
      struct scroll_bar *bar;
      ControlPartCode part_code;
-     unsigned long timestamp;
      struct input_event *bufp;
 {
   int part = control_part_code_to_scroll_bar_part (part_code);
@@ -4307,7 +4185,7 @@
 
   if (part != scroll_bar_handle)
     {
-      construct_scroll_bar_click (bar, part, timestamp, bufp);
+      construct_scroll_bar_click (bar, part, bufp);
       HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), part_code);
       set_scroll_bar_timer (SCROLL_BAR_FIRST_DELAY);
     }
@@ -4318,14 +4196,13 @@
 }
 
 static void
-x_scroll_bar_handle_release (bar, timestamp, bufp)
+x_scroll_bar_handle_release (bar, bufp)
      struct scroll_bar *bar;
-     unsigned long timestamp;
      struct input_event *bufp;
 {
   if (last_scroll_bar_part != scroll_bar_handle
       || !GC_NILP (bar->dragging))
-    construct_scroll_bar_click (bar, scroll_bar_end_scroll, timestamp, bufp);
+    construct_scroll_bar_click (bar, scroll_bar_end_scroll, bufp);
 
   HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), 0);
   set_scroll_bar_timer (kEventDurationForever);
@@ -4336,11 +4213,10 @@
 }
 
 static void
-x_scroll_bar_handle_drag (win, bar, mouse_pos, timestamp, bufp)
+x_scroll_bar_handle_drag (win, bar, mouse_pos, bufp)
      WindowPtr win;
      struct scroll_bar *bar;
      Point mouse_pos;
-     unsigned long timestamp;
      struct input_event *bufp;
 {
   ControlHandle ch = SCROLL_BAR_CONTROL_HANDLE (bar);
@@ -4360,13 +4236,13 @@
       top_range = (XINT (bar->track_height) - (r.bottom - r.top)) *
 	(1.0 + (float) GetControlViewSize (ch) / GetControl32BitMaximum (ch))
 	+ .5;
-      
+
       if (top < 0)
 	top = 0;
       if (top > top_range)
 	top = top_range;
 
-      construct_scroll_bar_click (bar, scroll_bar_handle, timestamp, bufp);
+      construct_scroll_bar_click (bar, scroll_bar_handle, bufp);
       XSETINT (bufp->x, top);
       XSETINT (bufp->y, top_range);
     }
@@ -4404,7 +4280,7 @@
       else if (part != last_scroll_bar_part
 	       || scroll_bar_timer_event_posted_p)
 	{
-	  construct_scroll_bar_click (bar, part, timestamp, bufp);
+	  construct_scroll_bar_click (bar, part, bufp);
 	  last_scroll_bar_part = part;
 	  HiliteControl (SCROLL_BAR_CONTROL_HANDLE (bar), part_code);
 	  set_scroll_bar_timer (SCROLL_BAR_CONTINUOUS_DELAY);
@@ -4475,11 +4351,11 @@
   r.bottom = disp_top + disp_height;
 
 #if TARGET_API_MAC_CARBON
-  ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", 1, 0, 0, 0,
-		   kControlScrollBarProc, (long) bar);
+  ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height,
+		   0, 0, 0, kControlScrollBarProc, (long) bar);
 #else
-  ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", 1, 0, 0, 0,
-		   scrollBarProc, (long) bar);
+  ch = NewControl (FRAME_MAC_WINDOW (f), &r, "\p", width < disp_height,
+		   0, 0, 0, scrollBarProc, (long) bar);
 #endif
   SET_SCROLL_BAR_CONTROL_HANDLE (bar, ch);
 
@@ -4604,10 +4480,12 @@
   UNBLOCK_INPUT;
 }
 
+
 /* Set the handle of the vertical scroll bar for WINDOW to indicate
    that we are displaying PORTION characters out of a total of WHOLE
    characters, starting at POSITION.  If WINDOW has no scroll bar,
    create one.  */
+
 static void
 XTset_vertical_scroll_bar (w, portion, whole, position)
      struct window *w;
@@ -4702,7 +4580,8 @@
           MoveControl (ch, sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM, disp_top);
           SizeControl (ch, sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2,
 		       disp_height);
-          ShowControl (ch);
+	  if (sb_width < disp_height)
+	    ShowControl (ch);
 
           /* Remember new settings.  */
           XSETINT (bar->left, sb_left);
@@ -4805,6 +4684,7 @@
      struct window *window;
 {
   struct scroll_bar *bar;
+  struct frame *f;
 
   /* We can't redeem this window's scroll bar if it doesn't have one.  */
   if (NILP (window->vertical_scroll_bar))
@@ -4813,36 +4693,33 @@
   bar = XSCROLL_BAR (window->vertical_scroll_bar);
 
   /* Unlink it from the condemned list.  */
-  {
-    FRAME_PTR f = XFRAME (WINDOW_FRAME (window));
-
-    if (NILP (bar->prev))
-      {
-	/* If the prev pointer is nil, it must be the first in one of
-           the lists.  */
-	if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar))
-	  /* It's not condemned.  Everything's fine.  */
-	  return;
-	else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f),
-		     window->vertical_scroll_bar))
-	  FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next;
-	else
-	  /* If its prev pointer is nil, it must be at the front of
-             one or the other!  */
-	  abort ();
-      }
-    else
-      XSCROLL_BAR (bar->prev)->next = bar->next;
-
-    if (! NILP (bar->next))
-      XSCROLL_BAR (bar->next)->prev = bar->prev;
-
-    bar->next = FRAME_SCROLL_BARS (f);
-    bar->prev = Qnil;
-    XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
-    if (! NILP (bar->next))
-      XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
-  }
+  f = XFRAME (WINDOW_FRAME (window));
+  if (NILP (bar->prev))
+    {
+      /* If the prev pointer is nil, it must be the first in one of
+	 the lists.  */
+      if (EQ (FRAME_SCROLL_BARS (f), window->vertical_scroll_bar))
+	/* It's not condemned.  Everything's fine.  */
+	return;
+      else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f),
+		   window->vertical_scroll_bar))
+	FRAME_CONDEMNED_SCROLL_BARS (f) = bar->next;
+      else
+	/* If its prev pointer is nil, it must be at the front of
+	   one or the other!  */
+	abort ();
+    }
+  else
+    XSCROLL_BAR (bar->prev)->next = bar->next;
+
+  if (! NILP (bar->next))
+    XSCROLL_BAR (bar->next)->prev = bar->prev;
+
+  bar->next = FRAME_SCROLL_BARS (f);
+  bar->prev = Qnil;
+  XSETVECTOR (FRAME_SCROLL_BARS (f), bar);
+  if (! NILP (bar->next))
+    XSETVECTOR (XSCROLL_BAR (bar->next)->prev, bar);
 }
 
 /* Remove all scroll bars on FRAME that haven't been saved since the
@@ -4981,8 +4858,8 @@
 
 #endif /* !USE_TOOLKIT_SCROLL_BARS */
 
-/* Return information to the user about the current position of the
-   mouse on the scroll bar.  */
+/* Return information to the user about the current position of the mouse
+   on the scroll bar.  */
 
 static void
 x_scroll_bar_report_motion (fp, bar_window, part, x, y, time)
@@ -5500,6 +5377,7 @@
 }
 
 
+
 /* Calculate the absolute position in frame F
    from its current recorded position values and gravity.  */
 
@@ -5731,7 +5609,6 @@
   UNBLOCK_INPUT;
 #endif
 }
-
 
 /* focus shifting, raising and lowering.  */
 
@@ -5758,6 +5635,7 @@
 }
 
 /* Raise frame F.  */
+
 void
 x_raise_frame (f)
      struct frame *f;
@@ -5771,6 +5649,7 @@
 }
 
 /* Lower frame F.  */
+
 void
 x_lower_frame (f)
      struct frame *f;
@@ -6179,9 +6058,9 @@
 }
 
 /* the global font name table */
-char **font_name_table = NULL;
-int font_name_table_size = 0;
-int font_name_count = 0;
+static char **font_name_table = NULL;
+static int font_name_table_size = 0;
+static int font_name_count = 0;
 
 /* Alist linking character set strings to Mac text encoding and Emacs
    coding system. */
@@ -7435,22 +7314,6 @@
 #define MIN_DOC_SIZE 64
 #define MAX_DOC_SIZE 32767
 
-#if 0
-/* sleep time for WaitNextEvent */
-#define WNE_SLEEP_AT_SUSPEND 10
-#define WNE_SLEEP_AT_RESUME  1
-
-/* the flag appl_is_suspended is used both for determining the sleep
-   time to be passed to WaitNextEvent and whether the cursor should be
-   drawn when updating the display.  The cursor is turned off when
-   Emacs is suspended.  Redrawing it is unnecessary and what needs to
-   be done depends on whether the cursor lies inside or outside the
-   redraw region.  So we might as well skip drawing it when Emacs is
-   suspended.  */
-static Boolean app_is_suspended = false;
-static long app_sleep_time = WNE_SLEEP_AT_RESUME;
-#endif
-
 #define EXTRA_STACK_ALLOC (256 * 1024)
 
 #define ARGV_STRING_LIST_ID 129
@@ -7487,8 +7350,8 @@
 Lisp_Object Vmac_pass_control_to_system;
 
 /* Points to the variable `inev' in the function XTread_socket.  It is
-   used for passing an input event to the function back from a Carbon
-   event handler.  */
+   used for passing an input event to the function back from
+   Carbon/Apple event handlers.  */
 static struct input_event *read_socket_inev = NULL;
 #endif
 
@@ -7496,8 +7359,6 @@
    drag and drop events.  */
 Lisp_Object Qmac_ready_for_drag_n_drop;
 
-Lisp_Object drag_and_drop_file_list;
-
 Point saved_menu_event_location;
 
 /* Apple Events */
@@ -7833,20 +7694,12 @@
 do_app_resume ()
 {
   /* Window-activate events will do the job. */
-#if 0
-  app_is_suspended = false;
-  app_sleep_time = WNE_SLEEP_AT_RESUME;
-#endif
 }
 
 static void
 do_app_suspend ()
 {
   /* Window-deactivate events will do the job. */
-#if 0
-  app_is_suspended = true;
-  app_sleep_time = WNE_SLEEP_AT_SUSPEND;
-#endif
 }
 
 
@@ -8400,8 +8253,6 @@
 	XSETINT (read_socket_inev->x, point.h);
 	XSETINT (read_socket_inev->y, point.v);
 	XSETFRAME (read_socket_inev->frame_or_window, f);
-	read_socket_inev->timestamp =
-	  EventTimeToTicks (GetEventTime (event)) * (1000/60);
 
 	return noErr;
       }
@@ -8475,11 +8326,6 @@
 }
 
 
-/* Defined in mac.c.  */
-extern int
-path_from_vol_dir_name (char *, int, short, long, char *);
-
-
 /* Called when we receive an AppleEvent with an ID of
    "kAEOpenDocuments".  This routine gets the direct parameter,
    extracts the FSSpecs in it, and puts their names on a list.  */
@@ -8503,6 +8349,9 @@
   DescType actual_type;
   Size actual_size;
   SelectionRange position;
+  Lisp_Object file_list = Qnil;
+
+  xassert (read_socket_inev);
 
   err = AEGetParamDesc (message, keyDirectObject, typeAEList, &the_desc);
   if (err != noErr)
@@ -8510,10 +8359,10 @@
 
   err = AEGetParamPtr (message, keyAEPosition, typeChar, &actual_type, &position, sizeof(SelectionRange), &actual_size);
   if (err == noErr)
-    drag_and_drop_file_list = Fcons (list3 (make_number (position.lineNum + 1),
-					    make_number (position.startRange + 1),
-					    make_number (position.endRange + 1)),
-				     drag_and_drop_file_list);
+    file_list = Fcons (list3 (make_number (position.lineNum + 1),
+			      make_number (position.startRange + 1),
+			      make_number (position.endRange + 1)),
+		       file_list);
 
   /* Check to see that we got all of the required parameters from the
      event descriptor.  For an 'odoc' event this should just be the
@@ -8567,12 +8416,49 @@
 					  sizeof (unix_path_name) - 1) == noErr)
 #endif
 	      /* x-dnd functions expect undecoded filenames.  */
-	      drag_and_drop_file_list =
-		Fcons (make_unibyte_string (unix_path_name,
-					    strlen (unix_path_name)),
-		       drag_and_drop_file_list);
+	      file_list = Fcons (make_unibyte_string (unix_path_name,
+						      strlen (unix_path_name)),
+				 file_list);
 	  }
       }
+
+    /* Build a DRAG_N_DROP_EVENT type event as is done in
+       constuct_drag_n_drop in w32term.c.  */
+    if (!NILP (file_list))
+      {
+	struct frame *f = mac_focus_frame (&one_mac_display_info);
+	WindowPtr wp;
+	Lisp_Object frame;
+
+	read_socket_inev->kind = DRAG_N_DROP_EVENT;
+	read_socket_inev->code = 0;
+	read_socket_inev->modifiers = 0;
+
+	XSETINT (read_socket_inev->x, 0);
+	XSETINT (read_socket_inev->y, 0);
+
+	XSETFRAME (frame, f);
+	read_socket_inev->frame_or_window = Fcons (frame, file_list);
+
+#if 0
+	/* Regardless of whether Emacs was suspended or in the
+	   foreground, ask it to redraw its entire screen.  Otherwise
+	   parts of the screen can be left in an inconsistent
+	   state.  */
+	wp = FRAME_MAC_WINDOW (f);
+	if (wp)
+#if TARGET_API_MAC_CARBON
+	  {
+	    Rect r;
+
+	    GetWindowPortBounds (wp, &r);
+	    InvalWindowRect (wp, &r);
+	  }
+#else /* not TARGET_API_MAC_CARBON */
+	InvalRect (&(wp->portRect));
+#endif /* not TARGET_API_MAC_CARBON */
+#endif
+      }
   }
 
 error_exit:
@@ -8665,11 +8551,12 @@
   ItemReference theItem;
   HFSFlavor data;
   Size size = sizeof (HFSFlavor);
+  Lisp_Object file_list;
 
   if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
     return dragNotAcceptedErr;
 
-  drag_and_drop_file_list = Qnil;
+  file_list = Qnil;
   GetDragMouse (theDrag, &mouse, 0L);
   CountDragItems (theDrag, &items);
   for (index = 1; index <= items; index++)
@@ -8695,15 +8582,14 @@
 					sizeof (unix_path_name) - 1) == noErr)
 #endif
 	    /* x-dnd functions expect undecoded filenames.  */
-            drag_and_drop_file_list =
-	      Fcons (make_unibyte_string (unix_path_name,
-					  strlen (unix_path_name)),
-		     drag_and_drop_file_list);
+            file_list = Fcons (make_unibyte_string (unix_path_name,
+						    strlen (unix_path_name)),
+			       file_list);
 	}
     }
   /* If there are items in the list, construct an event and post it to
      the queue like an interrupt using kbd_buffer_store_event.  */
-  if (!NILP (drag_and_drop_file_list))
+  if (!NILP (file_list))
     {
       struct input_event event;
       Lisp_Object frame;
@@ -8720,7 +8606,7 @@
       XSETINT (event.x, mouse.h);
       XSETINT (event.y, mouse.v);
       XSETFRAME (frame, f);
-      event.frame_or_window = Fcons (frame, drag_and_drop_file_list);
+      event.frame_or_window = Fcons (frame, file_list);
       event.arg = Qnil;
       /* Post to the interrupt queue */
       kbd_buffer_store_event (&event);
@@ -8979,6 +8865,7 @@
     {
       int do_help = 0;
       struct frame *f;
+      unsigned long timestamp;
 
       /* It is necessary to set this (additional) argument slot of an
 	 event to nil because keyboard.c protects incompletely
@@ -8989,6 +8876,12 @@
       inev.arg = Qnil;
 
 #if USE_CARBON_EVENTS
+      timestamp = GetEventTime (eventRef) / kEventDurationMillisecond;
+#else
+      timestamp = er.when * (1000 / 60); /* ticks to milliseconds */
+#endif
+
+#if USE_CARBON_EVENTS
       /* Handle new events */
       if (!mac_convert_event_ref (eventRef, &er))
 	{
@@ -9089,8 +8982,6 @@
 #endif
 		    XSETINT (inev.x, mouse_loc.h);
 		    XSETINT (inev.y, mouse_loc.v);
-		    inev.timestamp = er.when * (1000 / 60);
-		    /* ticks to milliseconds */
 
 		    if (dpyinfo->grabbed && tracked_scroll_bar
 			|| ch != 0
@@ -9124,10 +9015,9 @@
 						     &er, &inev);
 			else if (er.what == mouseDown)
 			  x_scroll_bar_handle_press (bar, control_part_code,
-						     inev.timestamp, &inev);
+						     &inev);
 			else
-			  x_scroll_bar_handle_release (bar, inev.timestamp,
-						       &inev);
+			  x_scroll_bar_handle_release (bar, &inev);
 #else  /* not USE_TOOLKIT_SCROLL_BARS */
 			x_scroll_bar_handle_click (bar, control_part_code,
 						   &er, &inev);
@@ -9301,8 +9191,7 @@
 		  if (dpyinfo->grabbed && tracked_scroll_bar)
 #ifdef USE_TOOLKIT_SCROLL_BARS
 		    x_scroll_bar_handle_drag (wp, tracked_scroll_bar,
-					      mouse_pos, er.when * (1000 / 60),
-					      &inev);
+					      mouse_pos, &inev);
 #else /* not USE_TOOLKIT_SCROLL_BARS */
 		    x_scroll_bar_note_movement (tracked_scroll_bar,
 						mouse_pos.v
@@ -9390,11 +9279,10 @@
 
 		    EVENT_INIT (event);
 		    event.kind = NO_EVENT;
-		    x_scroll_bar_handle_release (tracked_scroll_bar,
-						 er.when * (1000 / 60),
-						 &event);
+		    x_scroll_bar_handle_release (tracked_scroll_bar, &event);
 		    if (event.kind != NO_EVENT)
 		      {
+			event.timestamp = timestamp;
 			kbd_buffer_store_event_hold (&event, hold_quit);
 			count++;
 		      }
@@ -9470,6 +9358,7 @@
 		  event.kind = LANGUAGE_CHANGE_EVENT;
 		  event.arg = Qnil;
 		  event.code = current_key_script;
+		  event.timestamp = timestamp;
 		  kbd_buffer_store_event (&event);
 		  count++;
 		}
@@ -9534,58 +9423,18 @@
 #else
 	  inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
 #endif
+	  inev.modifiers |= (extra_keyboard_modifiers
+			     & (meta_modifier | alt_modifier
+				| hyper_modifier | super_modifier));
 	  XSETFRAME (inev.frame_or_window, mac_focus_frame (dpyinfo));
-	  inev.timestamp = er.when * (1000 / 60);  /* ticks to milliseconds */
 	  break;
 
 	case kHighLevelEvent:
-	  drag_and_drop_file_list = Qnil;
-
-	  AEProcessAppleEvent(&er);
-
-	  /* Build a DRAG_N_DROP_EVENT type event as is done in
-	     constuct_drag_n_drop in w32term.c.  */
-	  if (!NILP (drag_and_drop_file_list))
-	    {
-	      struct frame *f = mac_focus_frame (dpyinfo);
-	      WindowPtr wp;
-	      Lisp_Object frame;
-
-	      inev.kind = DRAG_N_DROP_EVENT;
-	      inev.code = 0;
-	      inev.timestamp = er.when * (1000 / 60);
-	      /* ticks to milliseconds */
-#if USE_CARBON_EVENTS
-	      inev.modifiers = mac_event_to_emacs_modifiers (eventRef);
-#else
-	      inev.modifiers = mac_to_emacs_modifiers (er.modifiers);
-#endif
-
-	      XSETINT (inev.x, 0);
-	      XSETINT (inev.y, 0);
-
-	      XSETFRAME (frame, f);
-	      inev.frame_or_window = Fcons (frame, drag_and_drop_file_list);
-
-#if 0
-	      /* Regardless of whether Emacs was suspended or in the
-		 foreground, ask it to redraw its entire screen.
-		 Otherwise parts of the screen can be left in an
-		 inconsistent state.  */
-	      wp = FRAME_MAC_WINDOW (f);
-	      if (wp)
-#if TARGET_API_MAC_CARBON
-		{
-		  Rect r;
-
-		  GetWindowPortBounds (wp, &r);
-		  InvalWindowRect (wp, &r);
-		}
-#else /* not TARGET_API_MAC_CARBON */
-                InvalRect (&(wp->portRect));
-#endif /* not TARGET_API_MAC_CARBON */
-#endif
-	    }
+	  read_socket_inev = &inev;
+	  AEProcessAppleEvent (&er);
+	  read_socket_inev = NULL;
+	  break;
+
 	default:
 	  break;
 	}
@@ -9595,6 +9444,7 @@
 
       if (inev.kind != NO_EVENT)
 	{
+	  inev.timestamp = timestamp;
 	  kbd_buffer_store_event_hold (&inev, hold_quit);
 	  count++;
 	}
@@ -10067,7 +9917,7 @@
       kbd_buffer_store_event (&e);
     }
 }
-#endif /* MAC_OSX */
+#endif	/* MAC_OSX */
 
 static void
 init_menu_bar ()
@@ -10170,7 +10020,6 @@
 				   off the bottom */
   baud_rate = 19200;
 
-  x_noop_count = 0;
   last_tool_bar_item = -1;
   any_help_event_p = 0;
 
@@ -10242,12 +10091,6 @@
   staticpro (&last_mouse_scroll_bar);
   last_mouse_scroll_bar = Qnil;
 
-  staticpro (&Qvendor_specific_keysyms);
-  Qvendor_specific_keysyms = intern ("vendor-specific-keysyms");
-
-  staticpro (&last_mouse_press_frame);
-  last_mouse_press_frame = Qnil;
-
   Qmac_ready_for_drag_n_drop = intern ("mac-ready-for-drag-n-drop");
   staticpro (&Qmac_ready_for_drag_n_drop);
 
@@ -10259,14 +10102,6 @@
   Vx_toolkit_scroll_bars = Qnil;
 #endif
 
-  DEFVAR_BOOL ("x-use-underline-position-properties",
-               &x_use_underline_position_properties,
-     doc: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
-nil means ignore them.  If you encounter fonts with bogus
-UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
-to 4.1, set this to nil.  */);
-  x_use_underline_position_properties = 0;
-
   staticpro (&last_mouse_motion_frame);
   last_mouse_motion_frame = Qnil;