*** empty log message ***
[bpt/emacs.git] / src / xterm.c
index 69c16d8..43f59d0 100644 (file)
@@ -1465,10 +1465,9 @@ construct_mouse_click (result, event, s, part, prefix)
      otherwise.  */
   result->kind = no_event;
   XSET (result->code, Lisp_Int, event->button);
-  XSET (result->timestamp, Lisp_Int, event->time);
+  result->timestamp = event->time;
   result->modifiers = (x_convert_modifiers (event->state)
                       | (event->type == ButtonRelease ? up_modifier : 0));
-  XSET (result->timestamp, Lisp_Int, (event->time & 0x7fffff));
 
   /* Notice if the mouse is still grabbed.  */
   if (event->type == ButtonPress)
@@ -1523,7 +1522,7 @@ construct_mouse_click (result, event, s, part, prefix)
    other kinds of events (focus changes and button clicks, for
    example), or by XQueryPointer calls; when one of these happens, we
    get another MotionNotify event the next time the mouse moves.  This
-   is at least as efficient than getting motion events when mouse
+   is at least as efficient as getting motion events when mouse
    tracking is on, and I suspect only negligibly worse when tracking
    is off.
 
@@ -1537,6 +1536,14 @@ construct_mouse_click (result, event, s, part, prefix)
 static SCREEN_PTR last_mouse_screen;
 static XRectangle last_mouse_glyph;
 
+/* This is a hack.  We would really prefer that XTmouse_position would
+   return the time associated with the position it returns, but there
+   doesn't seem to be any way to wrest the timestamp from the server
+   along with the position query.  So, we just keep track of the time
+   of the last movement we received, and return that in hopes that
+   it's somewhat accurate.  */
+static Time last_mouse_movement_time;
+
 /* Function to report a mouse movement to the mainstream Emacs code.
    The input handler calls this.
 
@@ -1550,6 +1557,8 @@ note_mouse_position (screen, event)
      XMotionEvent *event;
 
 {
+  last_mouse_movement_time = event->time;
+
   /* Has the mouse moved off the glyph it was on at the last sighting?  */
   if (event->x < last_mouse_glyph.x
       || event->x >= last_mouse_glyph.x + last_mouse_glyph.width
@@ -1581,7 +1590,7 @@ static void
 XTmouse_position (s, x, y, time)
      SCREEN_PTR *s;
      Lisp_Object *x, *y;
-     Lisp_Object *time;
+     unsigned long *time;
 {
   int ix, iy, dummy;
   Display *d = x_current_display;
@@ -1636,8 +1645,11 @@ XTmouse_position (s, x, y, time)
   mouse_moved = 0;
 
   /* I don't know how to find the time for the last movement; it seems
-   like XQueryPointer ought to return it, but it doesn't.  */
-  *time = Qnil;
+     like XQueryPointer ought to return it, but it doesn't.  So, we'll
+     return the time of the last MotionNotify event we received.  Note
+     that the use of motion hints means that this isn't guaranteed to
+     be accurate at all.  */
+  *time = last_mouse_movement_time;
 
   UNBLOCK_INPUT;
 }
@@ -1996,9 +2008,9 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
                    {
                      bufp->kind = non_ascii_keystroke;
                      XSET (bufp->code, Lisp_Int, (unsigned) keysym - 0xff50);
-                     bufp->screen = XSCREEN (SCREEN_FOCUS_SCREEN (s));
+                     bufp->screen = s;
                      bufp->modifiers = x_convert_modifiers (modifiers);
-                     XSET (bufp->timestamp, Lisp_Int, event.xkey.time);
+                     bufp->timestamp = event.xkey.time;
                      bufp++;
                      count++;
                      numchars--;
@@ -2012,9 +2024,9 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
                          if (modifiers & Mod1Mask)
                            *copy_buffer |= METABIT;
                          bufp->kind = ascii_keystroke;
-                         bufp->screen = XSCREEN (SCREEN_FOCUS_SCREEN (s));
                          XSET (bufp->code, Lisp_Int, *copy_buffer);
-                         XSET (bufp->timestamp, Lisp_Int, event.xkey.time);
+                         bufp->screen = s;
+                         bufp->timestamp = event.xkey.time;
                          bufp++;
                        }
                      else
@@ -2022,8 +2034,8 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
                          {
                            bufp->kind = ascii_keystroke;
                            XSET (bufp->code, Lisp_Int, copy_buffer[i]);
-                           XSET (bufp->timestamp, Lisp_Int, event.xkey.time);
-                           bufp->screen = XSCREEN (SCREEN_FOCUS_SCREEN (s));
+                           bufp->screen = s;
+                           bufp->timestamp = event.xkey.time;
                            bufp++;
                          }
 
@@ -2072,7 +2084,7 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
                    bufp->kind = ascii_keystroke;
                    XSET (bufp->code, Lisp_Int, where_mapping[i]);
                    XSET (bufp->time, Lisp_Int, event.xkey.time);
-                   bufp->screen = XSCREEN (SCREEN_FOCUS_SCREEN (s));
+                   bufp->screen = s;
                    bufp++;
                  }
                count += nbytes;
@@ -2167,14 +2179,12 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
            break;              /* Entering our own subwindow.  */
 
          {
-           extern int waiting_for_input;
            struct screen *old_s = x_input_screen;
 
            s = x_window_to_screen (event.window);
            x_mouse_screen = s;
 
-           if (waiting_for_input && x_focus_screen == 0)
-             x_new_focus_screen (s);
+           x_new_focus_screen (s);
          }
          break;
 
@@ -2311,13 +2321,13 @@ XTread_socket (sd, bufp, numchars, waitp, expected)
            {
              bufp->kind = ascii_keystroke;
              bufp->code = (char) 'X' & 037; /* C-x */
-             bufp->screen = XSCREEN (SCREEN_FOCUS_SCREEN (s));
+             bufp->screen = s;
              XSET (bufp->time, Lisp_Int, event.xkey.time);
              bufp++;
 
              bufp->kind = ascii_keystroke;
              bufp->code = (char) 0; /* C-@ */
-             bufp->screen = XSCREEN (SCREEN_FOCUS_SCREEN (s));
+             bufp->screen = s;
              XSET (bufp->time, Lisp_Int, event.xkey.time);
              bufp++;
 
@@ -2592,6 +2602,14 @@ x_display_box_cursor (s, on)
 {
   struct screen_glyphs *current_glyphs = SCREEN_CURRENT_GLYPHS (s);
 
+  /* If we're not updating, then we want to use the current screen's
+     cursor position, not our local idea of where the cursor ought to be.  */
+  if (s != updating_screen)
+    {
+      curs_x = SCREEN_CURSOR_X (s);
+      curs_y = SCREEN_CURSOR_Y (s);
+    }
+
   if (! s->visible)
     return;
 
@@ -2605,8 +2623,8 @@ x_display_box_cursor (s, on)
      erase it.  */
   if (s->phys_cursor_x >= 0
       && (!on
-         || s->phys_cursor_x != s->cursor_x
-         || s->phys_cursor_y != s->cursor_y
+         || s->phys_cursor_x != curs_x
+         || s->phys_cursor_y != curs_y
          || (s->display.x->text_cursor_kind != hollow_box_cursor
              && (s != x_highlight_screen))))
     {
@@ -2626,9 +2644,9 @@ x_display_box_cursor (s, on)
              && s == x_highlight_screen)))
     {
       s->phys_cursor_glyph
-       = ((current_glyphs->enable[s->cursor_y]
-           && s->cursor_x < current_glyphs->used[s->cursor_y])
-          ? current_glyphs->glyphs[s->cursor_y][s->cursor_x]
+       = ((current_glyphs->enable[curs_y]
+           && curs_x < current_glyphs->used[curs_y])
+          ? current_glyphs->glyphs[curs_y][curs_x]
           : SPACEGLYPH);
       if (s != x_highlight_screen)
        {
@@ -2637,13 +2655,13 @@ x_display_box_cursor (s, on)
        }
       else
        {
-         x_draw_single_glyph (s, s->cursor_y, s->cursor_x,
+         x_draw_single_glyph (s, curs_y, curs_x,
                               s->phys_cursor_glyph, 2);
          s->display.x->text_cursor_kind = filled_box_cursor;
        }
 
-      s->phys_cursor_x = s->cursor_x;
-      s->phys_cursor_y = s->cursor_y;
+      s->phys_cursor_x = curs_x;
+      s->phys_cursor_y = curs_y;
     }
 
   if (updating_screen != s)
@@ -3601,6 +3619,9 @@ x_wm_set_size_hint (s, prompting)
   Window window = s->display.x->window_desc;
 
   size_hints.flags = PResizeInc | PMinSize | PMaxSize;
+#ifdef PBaseSize
+  size_hints.flags |= PBaseSize;
+#endif
 
   flexlines = s->height;