]> code.delx.au - gnu-emacs/blobdiff - src/xfns.c
* keyboard.c (make_lispy_movement): Deal properly with mouse
[gnu-emacs] / src / xfns.c
index 57e756c32be63654c43f404da03d1cb048cb29cb..6905a67b6d50c1130cbfbe3a264036e8342b21d3 100644 (file)
@@ -33,11 +33,16 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "buffer.h"
 #include "dispextern.h"
 #include "keyboard.h"
+#include "blockinput.h"
 
 #ifdef HAVE_X_WINDOWS
 extern void abort ();
 
+#ifndef VMS
 #include <X11/bitmaps/gray>
+#else
+#include "[.bitmaps]gray.xbm"
+#endif
 
 #define min(a,b) ((a) < (b) ? (a) : (b))
 #define max(a,b) ((a) > (b) ? (a) : (b))
@@ -193,6 +198,8 @@ struct face *x_face_table[MAX_FACES_AND_GLYPHS];
 /* Return the Emacs frame-object corresponding to an X window.
    It could be the frame's main window or an icon window.  */
 
+/* This function can be called during GC, so use XGCTYPE.  */
+
 struct frame *
 x_window_to_frame (wdesc)
      int wdesc;
@@ -200,10 +207,11 @@ x_window_to_frame (wdesc)
   Lisp_Object tail, frame;
   struct frame *f;
 
-  for (tail = Vframe_list; CONSP (tail); tail = XCONS (tail)->cdr)
+  for (tail = Vframe_list; XGCTYPE (tail) == Lisp_Cons;
+       tail = XCONS (tail)->cdr)
     {
       frame = XCONS (tail)->car;
-      if (XTYPE (frame) != Lisp_Frame)
+      if (XGCTYPE (frame) != Lisp_Frame)
         continue;
       f = XFRAME (frame);
       if (FRAME_X_WINDOW (f) == wdesc
@@ -642,6 +650,7 @@ x_set_cursor_color (f, arg, oldval)
       if (f->display.x->cursor_pixel == fore_pixel)
        fore_pixel = f->display.x->background_pixel;
     }
+  f->display.x->cursor_foreground_pixel = fore_pixel;
 
   if (FRAME_X_WINDOW (f) != 0)
     {
@@ -889,6 +898,13 @@ x_set_menu_bar_lines (f, value, oldval)
   int nlines;
   int olines = FRAME_MENU_BAR_LINES (f);
 
+  /* Right now, menu bars don't work properly in minibuf-only frames;
+     most of the commands try to apply themselves to the minibuffer
+     frame itslef, and get an error because you can't switch buffers
+     in or split the minibuffer window.  */
+  if (FRAME_MINIBUF_ONLY_P (f))
+    return;
+
   if (XTYPE (value) == Lisp_Int)
     nlines = XINT (value);
   else
@@ -1439,7 +1455,7 @@ x_get_arg (alist, param, attribute, class, type)
                      || !strcmp (XSTRING (tem)->data, "false"))
                  return Qnil;
                else
-                 return intern (tem);
+                 return Fintern (tem, Qnil);
              }
 
            default:
@@ -1742,6 +1758,8 @@ x_make_gc (f)
   GC temp_gc;
   XImage tileimage;
 
+  BLOCK_INPUT;
+
   /* Create the GC's of this frame.
      Note that many default values are used. */
 
@@ -1788,6 +1806,10 @@ x_make_gc (f)
        f->display.x->foreground_pixel,
        f->display.x->background_pixel,
        DefaultDepth (x_current_display, XDefaultScreen (x_current_display))));
+
+  init_frame_faces (f);
+
+  UNBLOCK_INPUT;
 }
 #endif /* HAVE_X11 */
 
@@ -1859,7 +1881,12 @@ be shared by the new frame.")
 
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
-  x_default_parameter (f, parms, Qfont, build_string ("9x15"),
+  x_default_parameter (f, parms, Qfont, 
+                      build_string
+                      /* If we use an XLFD name for this font, the lisp code
+                         knows how to find variants which are bold, italic,
+                         etcetera.  */
+                      ("-*-fixed-*-*-*-*-*-120-*-*-c-*-iso8859-1"),
                       "font", "Font", string);
   x_default_parameter (f, parms, Qborder_width, make_number (2),
                       "borderwidth", "BorderWidth", number);
@@ -2030,7 +2057,7 @@ be shared by the new frame.")
       BLOCK_INPUT;
       XGetWindowInfo (FRAME_X_WINDOW (f), &wininfo);
       XQueryTree (FRAME_X_WINDOW (f), &parent, &nchildren, &children);
-      free (children);
+      xfree (children);
       UNBLOCK_INPUT;
 
       height = PIXEL_TO_CHAR_HEIGHT (f, wininfo.height);
@@ -2279,7 +2306,7 @@ x_rubber_band (f, x, y, width, height, geo, str, hscroll, vscroll)
       *x -= wininfo.x;
       *y -= wininfo.y;
       XQueryTree (tempwindow, &tempwindow, &nchildren, &children);
-      free (children);
+      xfree (children);
     }
 
   UNBLOCK_INPUT;
@@ -3292,212 +3319,6 @@ x_draw_pixmap (f, x, y, image_data, width, height)
              f->display.x->normal_gc, 0, 0, width, height, x, y);
 }
 #endif
-\f
-#if 0
-
-#ifdef HAVE_X11
-#define XMouseEvent XEvent
-#define WhichMouseButton xbutton.button
-#define MouseWindow xbutton.window
-#define MouseX xbutton.x
-#define MouseY xbutton.y
-#define MouseTime xbutton.time
-#define ButtonReleased ButtonRelease
-#define ButtonPressed ButtonPress
-#else
-#define XMouseEvent XButtonEvent
-#define WhichMouseButton detail
-#define MouseWindow window
-#define MouseX x
-#define MouseY y
-#define MouseTime time
-#endif /* X11 */
-
-DEFUN ("x-mouse-events", Fx_mouse_events, Sx_mouse_events, 0, 0, 0,
-  "Return number of pending mouse events from X window system.")
-  ()
-{
-  return make_number (queue_event_count (&x_mouse_queue));
-}
-
-/* Encode the mouse button events in the form expected by the
-   mouse code in Lisp.  For X11, this means moving the masks around. */
-
-static int
-encode_mouse_button (mouse_event)
-     XMouseEvent mouse_event;
-{
-  register int event_code;
-  register char key_mask;
-
-  event_code = mouse_event.detail & 3;
-  key_mask = (mouse_event.detail >> 8) & 0xf0;
-  event_code |= key_mask >> 1;
-  if (mouse_event.type == ButtonReleased) event_code |= 0x04;
-  return event_code;
-}
-
-DEFUN ("x-get-mouse-event", Fx_get_mouse_event, Sx_get_mouse_event,
-  0, 1, 0,
-  "Get next mouse event out of mouse event buffer.\n\
-Optional ARG non-nil means return nil immediately if no pending event;\n\
-otherwise, wait for an event.  Returns a four-part list:\n\
-  ((X-POS Y-POS) WINDOW FRAME-PART KEYSEQ TIMESTAMP).\n\
-Normally X-POS and Y-POS are the position of the click on the frame\n\
- (measured in characters and lines), and WINDOW is the window clicked in.\n\
-KEYSEQ is a string, the key sequence to be looked up in the mouse maps.\n\
-If FRAME-PART is non-nil, the event was on a scroll bar;\n\
-then Y-POS is really the total length of the scroll bar, while X-POS is\n\
-the relative position of the scroll bar's value within that total length,\n\
-and a third element OFFSET appears in that list: the height of the thumb-up\n\
-area at the top of the scroll bar.\n\
-FRAME-PART is one of the following symbols:\n\
- `vertical-scroll-bar', `vertical-thumbup', `vertical-thumbdown',\n\
- `horizontal-scroll-bar', `horizontal-thumbleft', `horizontal-thumbright'.\n\
-TIMESTAMP is the lower 23 bits of the X-server's timestamp for\n\
-the mouse event.")
-  (arg)
-     Lisp_Object arg;
-{
-  XMouseEvent xrep;
-  register int com_letter;
-  register Lisp_Object tempx;
-  register Lisp_Object tempy;
-  Lisp_Object part, pos, timestamp;
-  int prefix;
-  struct frame *f;
-  
-  int tem;
-  
-  while (1)
-    {
-      BLOCK_INPUT;
-      tem = dequeue_event (&xrep, &x_mouse_queue);
-      UNBLOCK_INPUT;
-      
-      if (tem)
-       {
-         switch (xrep.type)
-           {
-           case ButtonPressed:
-           case ButtonReleased:
-
-             com_letter = encode_mouse_button (xrep);
-             mouse_timestamp = xrep.MouseTime;
-
-             if ((f = x_window_to_frame (xrep.MouseWindow)) != 0)
-               {
-                 Lisp_Object frame;
-                 
-                 if (f->display.x->icon_desc == xrep.MouseWindow)
-                   {
-                     x_make_frame_visible (f);
-                     continue;
-                   }
-
-                 XSET (tempx, Lisp_Int,
-                       min (f->width-1, max (0, (xrep.MouseX - f->display.x->internal_border_width)/FONT_WIDTH (f->display.x->font))));
-                 XSET (tempy, Lisp_Int,
-                       min (f->height-1, max (0, (xrep.MouseY - f->display.x->internal_border_width)/FONT_HEIGHT (f->display.x->font))));
-                 XSET (timestamp, Lisp_Int, (xrep.MouseTime & 0x7fffff));
-                 XSET (frame, Lisp_Frame, f);
-                 
-                 pos = Fcons (tempx, Fcons (tempy, Qnil));
-                 Vmouse_window
-                   = Flocate_window_from_coordinates (frame, pos);
-                 
-                 Vmouse_event
-                   = Fcons (pos,
-                            Fcons (Vmouse_window,
-                                   Fcons (Qnil,
-                                          Fcons (Fchar_to_string (make_number (com_letter)),
-                                                 Fcons (timestamp, Qnil)))));
-                 return Vmouse_event;
-               }
-             else if ((f = x_window_to_scroll_bar (xrep.MouseWindow, &part, &prefix)) != 0)
-               {
-                 int pos, len;
-                 Lisp_Object keyseq;
-                 char *partname;
-                 
-                 keyseq = concat2 (Fchar_to_string (make_number (prefix)),
-                                   Fchar_to_string (make_number (com_letter)));
-                 
-                 pos = xrep.MouseY - (f->display.x->v_scroll_bar_width - 2);
-                 XSET (tempx, Lisp_Int, pos);
-                 len = ((FONT_HEIGHT (f->display.x->font) * f->height)
-                        + f->display.x->internal_border_width
-                        - (2 * (f->display.x->v_scroll_bar_width - 2)));
-                 XSET (tempy, Lisp_Int, len);
-                 XSET (timestamp, Lisp_Int, (xrep.MouseTime & 0x7fffff));
-                 Vmouse_window = f->selected_window;
-                 Vmouse_event
-                   = Fcons (Fcons (tempx, Fcons (tempy, 
-                                                 Fcons (make_number (f->display.x->v_scroll_bar_width - 2),
-                                                        Qnil))),
-                            Fcons (Vmouse_window,
-                                   Fcons (intern (part),
-                                          Fcons (keyseq, Fcons (timestamp,
-                                                                Qnil)))));
-                 return Vmouse_event;
-               }
-             else
-               continue;
-
-#ifdef HAVE_X11
-           case MotionNotify:
-
-             com_letter = x11_encode_mouse_button (xrep);
-             if ((f = x_window_to_frame (xrep.MouseWindow)) != 0)
-               {
-                 Lisp_Object frame;
-                 
-                 XSET (tempx, Lisp_Int,
-                       min (f->width-1,
-                            max (0, (xrep.MouseX - f->display.x->internal_border_width)
-                                 / FONT_WIDTH (f->display.x->font))));
-                 XSET (tempy, Lisp_Int,
-                       min (f->height-1,
-                            max (0, (xrep.MouseY - f->display.x->internal_border_width)
-                                 / FONT_HEIGHT (f->display.x->font))));
-                                 
-                 XSET (frame, Lisp_Frame, f);
-                 XSET (timestamp, Lisp_Int, (xrep.MouseTime & 0x7fffff));
-                 
-                 pos = Fcons (tempx, Fcons (tempy, Qnil));
-                 Vmouse_window
-                   = Flocate_window_from_coordinates (frame, pos);
-                 
-                 Vmouse_event
-                   = Fcons (pos,
-                            Fcons (Vmouse_window,
-                                   Fcons (Qnil,
-                                          Fcons (Fchar_to_string (make_number (com_letter)),
-                                                 Fcons (timestamp, Qnil)))));
-                 return Vmouse_event;
-               }
-
-             break;
-#endif /* HAVE_X11 */
-
-           default:
-             if (f = x_window_to_frame (xrep.MouseWindow))
-               Vmouse_window = f->selected_window;
-             else if (f = x_window_to_scroll_bar (xrep.MouseWindow, &part, &prefix))
-               Vmouse_window = f->selected_window;
-             return Vmouse_event = Qnil;
-           }
-       }
-      
-      if (!NILP (arg))
-       return Qnil;
-
-      /* Wait till we get another mouse event.  */
-      wait_reading_process_input (0, 0, 2, 0);
-    }
-}
-#endif
-
 \f
 #ifndef HAVE_X11
 DEFUN ("x-store-cut-buffer", Fx_store_cut_buffer, Sx_store_cut_buffer,
@@ -3721,7 +3542,7 @@ select_visual (screen, depth)
 #ifdef HAVE_X11R4
   vinfo_template.visualid = XVisualIDFromVisual (v);
 #else
-  vinfo_template.visualid = x->visualid;
+  vinfo_template.visualid = v->visualid;
 #endif
 
   vinfo = XGetVisualInfo (x_current_display, VisualIDMask, &vinfo_template,
@@ -3928,15 +3749,21 @@ syms_of_xfns ()
   mouse_buffer_offset = 0;
 
   DEFVAR_INT ("x-pointer-shape", &Vx_pointer_shape,
-             "The shape of the pointer when over text.");
+             "The shape of the pointer when over text.\n\
+Changing the value does not affect existing frames\n\
+unless you set the mouse color.");
   Vx_pointer_shape = Qnil;
 
+#if 0
   DEFVAR_INT ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape,
              "The shape of the pointer when not over text.");
+#endif
   Vx_nontext_pointer_shape = Qnil;
 
+#if 0
   DEFVAR_INT ("x-mode-pointer-shape", &Vx_mode_pointer_shape,
              "The shape of the pointer when over the mode line.");
+#endif
   Vx_mode_pointer_shape = Qnil;
 
   DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel,
@@ -3995,13 +3822,6 @@ syms_of_xfns ()
   defsubr (&Sx_open_connection);
   defsubr (&Sx_close_current_connection);
   defsubr (&Sx_synchronize);
-
-  /* This was used in the old event interface which used a separate
-     event queue.*/
-#if 0
-  defsubr (&Sx_mouse_events);
-  defsubr (&Sx_get_mouse_event);
-#endif
 }
 
 #endif /* HAVE_X_WINDOWS */