Unify FRAME_window_system_DISPLAY_INFO macros between all ports.
[bpt/emacs.git] / src / xselect.c
index f43efab..238eea5 100644 (file)
@@ -45,26 +45,14 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 struct prop_location;
 struct selection_data;
 
-static Lisp_Object x_atom_to_symbol (Display *dpy, Atom atom);
-static Atom symbol_to_x_atom (struct x_display_info *, Lisp_Object);
-static void x_own_selection (Lisp_Object, Lisp_Object, Lisp_Object);
-static Lisp_Object x_get_local_selection (Lisp_Object, Lisp_Object, int,
-                                         struct x_display_info *);
 static void x_decline_selection_request (struct input_event *);
-static Lisp_Object x_selection_request_lisp_error (Lisp_Object);
-static Lisp_Object queue_selection_requests_unwind (Lisp_Object);
-static Lisp_Object x_catch_errors_unwind (Lisp_Object);
-static void x_reply_selection_request (struct input_event *, struct x_display_info *);
 static int x_convert_selection (struct input_event *, Lisp_Object, Lisp_Object,
                                Atom, int, struct x_display_info *);
 static int waiting_for_other_props_on_window (Display *, Window);
 static struct prop_location *expect_property_change (Display *, Window,
                                                      Atom, int);
 static void unexpect_property_change (struct prop_location *);
-static Lisp_Object wait_for_property_change_unwind (Lisp_Object);
 static void wait_for_property_change (struct prop_location *);
-static Lisp_Object x_get_foreign_selection (Lisp_Object, Lisp_Object,
-                                           Lisp_Object, Lisp_Object);
 static Lisp_Object x_get_window_property_as_lisp_data (Display *,
                                                        Window, Atom,
                                                        Lisp_Object, Atom);
@@ -74,7 +62,6 @@ static Lisp_Object selection_data_to_lisp_data (Display *,
 static void lisp_data_to_selection_data (Display *, Lisp_Object,
                                          unsigned char **, Atom *,
                                         ptrdiff_t *, int *, int *);
-static Lisp_Object clean_local_selection_data (Lisp_Object);
 
 /* Printing traces to stderr.  */
 
@@ -331,7 +318,7 @@ x_own_selection (Lisp_Object selection_name, Lisp_Object selection_value,
 {
   struct frame *f = XFRAME (frame);
   Window selecting_window = FRAME_X_WINDOW (f);
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Display *display = dpyinfo->display;
   Time timestamp = last_event_timestamp;
   Atom selection_atom = symbol_to_x_atom (dpyinfo, selection_name);
@@ -513,8 +500,8 @@ static Atom conversion_fail_tag;
    an error, we tell the requestor that we were unable to do what they wanted
    before we throw to top-level or go into the debugger or whatever.  */
 
-static Lisp_Object
-x_selection_request_lisp_error (Lisp_Object ignore)
+static void
+x_selection_request_lisp_error (void)
 {
   struct selection_data *cs, *next;
 
@@ -530,16 +517,14 @@ x_selection_request_lisp_error (Lisp_Object ignore)
   if (x_selection_current_request != 0
       && selection_request_dpyinfo->display)
     x_decline_selection_request (x_selection_current_request);
-  return Qnil;
 }
 
-static Lisp_Object
-x_catch_errors_unwind (Lisp_Object dummy)
+static void
+x_catch_errors_unwind (void)
 {
   block_input ();
   x_uncatch_errors ();
   unblock_input ();
-  return Qnil;
 }
 \f
 
@@ -560,11 +545,6 @@ struct prop_location
   struct prop_location *next;
 };
 
-static struct prop_location *expect_property_change (Display *display, Window window, Atom property, int state);
-static void wait_for_property_change (struct prop_location *location);
-static void unexpect_property_change (struct prop_location *location);
-static int waiting_for_other_props_on_window (Display *display, Window window);
-
 static int prop_location_identifier;
 
 static Lisp_Object property_change_reply;
@@ -573,13 +553,6 @@ static struct prop_location *property_change_reply_object;
 
 static struct prop_location *property_change_wait_list;
 
-static Lisp_Object
-queue_selection_requests_unwind (Lisp_Object tem)
-{
-  x_stop_queuing_selection_requests ();
-  return Qnil;
-}
-
 \f
 /* Send the reply to a selection request event EVENT.  */
 
@@ -614,7 +587,7 @@ x_reply_selection_request (struct input_event *event,
   /* The protected block contains wait_for_property_change, which can
      run random lisp code (process handlers) or signal.  Therefore, we
      put the x_uncatch_errors call in an unwind.  */
-  record_unwind_protect (x_catch_errors_unwind, Qnil);
+  record_unwind_protect_void (x_catch_errors_unwind);
   x_catch_errors (display);
 
   /* Loop over converted selections, storing them in the requested
@@ -681,7 +654,7 @@ x_reply_selection_request (struct input_event *event,
     if (cs->wait_object)
       {
        int format_bytes = cs->format / 8;
-       int had_errors = x_had_errors_p (display);
+       bool had_errors_p = x_had_errors_p (display);
        unblock_input ();
 
        bytes_remaining = cs->size;
@@ -689,7 +662,7 @@ x_reply_selection_request (struct input_event *event,
 
        /* Wait for the requestor to ack by deleting the property.
           This can run Lisp code (process handlers) or signal.  */
-       if (! had_errors)
+       if (! had_errors_p)
          {
            TRACE1 ("Waiting for ACK (deletion of %s)",
                    XGetAtomName (display, cs->property));
@@ -721,10 +694,10 @@ x_reply_selection_request (struct input_event *event,
            cs->data += i * ((cs->format == 32) ? sizeof (long)
                             : format_bytes);
            XFlush (display);
-           had_errors = x_had_errors_p (display);
+           had_errors_p = x_had_errors_p (display);
            unblock_input ();
 
-           if (had_errors) break;
+           if (had_errors_p) break;
 
            /* Wait for the requestor to ack this chunk by deleting
               the property.  This can run Lisp code or signal.  */
@@ -805,12 +778,12 @@ x_handle_selection_request (struct input_event *event)
 
   x_selection_current_request = event;
   selection_request_dpyinfo = dpyinfo;
-  record_unwind_protect (x_selection_request_lisp_error, Qnil);
+  record_unwind_protect_void (x_selection_request_lisp_error);
 
   /* We might be able to handle nested x_handle_selection_requests,
      but this is difficult to test, and seems unimportant.  */
   x_start_queuing_selection_requests ();
-  record_unwind_protect (queue_selection_requests_unwind, Qnil);
+  record_unwind_protect_void (x_stop_queuing_selection_requests);
 
   TRACE2 ("x_handle_selection_request: selection=%s, target=%s",
          SDATA (SYMBOL_NAME (selection_symbol)),
@@ -1020,11 +993,11 @@ x_handle_selection_event (struct input_event *event)
    We do this when about to delete a frame.  */
 
 void
-x_clear_frame_selections (FRAME_PTR f)
+x_clear_frame_selections (struct frame *f)
 {
   Lisp_Object frame;
   Lisp_Object rest;
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   struct terminal *t = dpyinfo->terminal;
 
   XSETFRAME (frame, f);
@@ -1117,15 +1090,14 @@ unexpect_property_change (struct prop_location *location)
 
 /* Remove the property change expectation element for IDENTIFIER.  */
 
-static Lisp_Object
-wait_for_property_change_unwind (Lisp_Object loc)
+static void
+wait_for_property_change_unwind (void *loc)
 {
-  struct prop_location *location = XSAVE_VALUE (loc)->pointer;
+  struct prop_location *location = loc;
 
   unexpect_property_change (location);
   if (location == property_change_reply_object)
     property_change_reply_object = 0;
-  return Qnil;
 }
 
 /* Actually wait for a property change.
@@ -1140,8 +1112,7 @@ wait_for_property_change (struct prop_location *location)
     emacs_abort ();
 
   /* Make sure to do unexpect_property_change if we quit or err.  */
-  record_unwind_protect (wait_for_property_change_unwind,
-                        make_save_value (location, 0));
+  record_unwind_protect_ptr (wait_for_property_change_unwind, location);
 
   XSETCAR (property_change_reply, Qnil);
   property_change_reply_object = location;
@@ -1214,7 +1185,7 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
                         Lisp_Object time_stamp, Lisp_Object frame)
 {
   struct frame *f = XFRAME (frame);
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Display *display = dpyinfo->display;
   Window requestor_window = FRAME_X_WINDOW (f);
   Time requestor_time = last_event_timestamp;
@@ -1254,7 +1225,7 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
      SelectionNotify. */
 #if 0
   x_start_queuing_selection_requests ();
-  record_unwind_protect (queue_selection_requests_unwind, Qnil);
+  record_unwind_protect_void (x_stop_queuing_selection_requests);
 #endif
 
   unblock_input ();
@@ -1388,7 +1359,7 @@ x_get_window_property (Display *display, Window window, Atom property,
          data = data1;
        }
 
-      if (32 < BITS_PER_LONG && *actual_format_ret == 32)
+      if (BITS_PER_LONG > 32 && *actual_format_ret == 32)
         {
           unsigned long i;
          int  *idata = (int *) (data + offset);
@@ -1670,11 +1641,10 @@ selection_data_to_lisp_data (Display *display, const unsigned char *data,
        return x_atom_to_symbol (display, (Atom) idata[0]);
       else
        {
-         Lisp_Object v = Fmake_vector (make_number (size / sizeof (int)),
-                                       make_number (0));
+         Lisp_Object v = make_uninit_vector (size / sizeof (int));
+
          for (i = 0; i < size / sizeof (int); i++)
-           Faset (v, make_number (i),
-                   x_atom_to_symbol (display, (Atom) idata[i]));
+           ASET (v, i, x_atom_to_symbol (display, (Atom) idata[i]));
          return v;
        }
     }
@@ -1694,24 +1664,24 @@ selection_data_to_lisp_data (Display *display, const unsigned char *data,
   else if (format == 16)
     {
       ptrdiff_t i;
-      Lisp_Object v;
-      v = Fmake_vector (make_number (size / 2), make_number (0));
+      Lisp_Object v = make_uninit_vector (size / 2);
+
       for (i = 0; i < size / 2; i++)
        {
          short j = ((short *) data) [i];
-         Faset (v, make_number (i), make_number (j));
+         ASET (v, i, make_number (j));
        }
       return v;
     }
   else
     {
       ptrdiff_t i;
-      Lisp_Object v = Fmake_vector (make_number (size / X_LONG_SIZE),
-                                   make_number (0));
+      Lisp_Object v = make_uninit_vector (size / X_LONG_SIZE);
+
       for (i = 0; i < size / X_LONG_SIZE; i++)
        {
          int j = ((int *) data) [i];
-         Faset (v, make_number (i), INTEGER_TO_CONS (j));
+         ASET (v, i, INTEGER_TO_CONS (j));
        }
       return v;
     }
@@ -1904,7 +1874,7 @@ clean_local_selection_data (Lisp_Object obj)
       Lisp_Object copy;
       if (size == 1)
        return clean_local_selection_data (AREF (obj, 0));
-      copy = Fmake_vector (make_number (size), Qnil);
+      copy = make_uninit_vector (size);
       for (i = 0; i < size; i++)
        ASET (copy, i, clean_local_selection_data (AREF (obj, i)));
       return copy;
@@ -2039,7 +2009,7 @@ On Nextstep, TIME-STAMP and TERMINAL are unused.  */)
     error ("X selection unavailable for this frame");
 
   val = x_get_local_selection (selection_symbol, target_type, 1,
-                              FRAME_X_DISPLAY_INFO (f));
+                              FRAME_DISPLAY_INFO (f));
 
   if (NILP (val) && FRAME_LIVE_P (f))
     {
@@ -2086,7 +2056,7 @@ On MS-DOS, all this does is return non-nil if we own the selection.  */)
   if (!f)
     return Qnil;
 
-  dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  dpyinfo = FRAME_DISPLAY_INFO (f);
   CHECK_SYMBOL (selection);
 
   /* Don't disown the selection when we're not the owner.  */
@@ -2138,7 +2108,7 @@ On Nextstep, TERMINAL is unused.  */)
   if (EQ (selection, Qnil)) selection = QPRIMARY;
   if (EQ (selection, Qt)) selection = QSECONDARY;
 
-  if (f && !NILP (LOCAL_SELECTION (selection, FRAME_X_DISPLAY_INFO (f))))
+  if (f && !NILP (LOCAL_SELECTION (selection, FRAME_DISPLAY_INFO (f))))
     return Qt;
   else
     return Qnil;
@@ -2171,7 +2141,7 @@ On Nextstep, TERMINAL is unused.  */)
   if (!f)
     return Qnil;
 
-  dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  dpyinfo = FRAME_DISPLAY_INFO (f);
 
   if (!NILP (LOCAL_SELECTION (selection, dpyinfo)))
     return Qt;
@@ -2192,7 +2162,7 @@ static Lisp_Object
 x_clipboard_manager_save (Lisp_Object frame)
 {
   struct frame *f = XFRAME (frame);
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Atom data = dpyinfo->Xatom_UTF8_STRING;
 
   XChangeProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
@@ -2242,7 +2212,7 @@ x_clipboard_manager_save_frame (Lisp_Object frame)
       && (f = XFRAME (frame), FRAME_X_P (f))
       && FRAME_LIVE_P (f))
     {
-      struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+      struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
       Lisp_Object local_selection
        = LOCAL_SELECTION (QCLIPBOARD, dpyinfo);
 
@@ -2407,7 +2377,7 @@ x_property_data_to_lisp (struct frame *f, const unsigned char *data,
 /* Get the mouse position in frame relative coordinates.  */
 
 static void
-mouse_position_for_drop (FRAME_PTR f, int *x, int *y)
+mouse_position_for_drop (struct frame *f, int *x, int *y)
 {
   Window root, dummy_window;
   int dummy;
@@ -2451,23 +2421,23 @@ Use the display for FRAME or the current frame if FRAME is not given or nil.
 If the value is 0 or the atom is not known, return the empty string.  */)
   (Lisp_Object value, Lisp_Object frame)
 {
-  struct frame *f = check_x_frame (frame);
+  struct frame *f = decode_window_system_frame (frame);
   char *name = 0;
   char empty[] = "";
   Lisp_Object ret = Qnil;
   Display *dpy = FRAME_X_DISPLAY (f);
   Atom atom;
-  int had_errors;
+  bool had_errors_p;
 
   CONS_TO_INTEGER (value, Atom, atom);
 
   block_input ();
   x_catch_errors (dpy);
   name = atom ? XGetAtomName (dpy, atom) : empty;
-  had_errors = x_had_errors_p (dpy);
+  had_errors_p = x_had_errors_p (dpy);
   x_uncatch_errors ();
 
-  if (!had_errors)
+  if (!had_errors_p)
     ret = build_string (name);
 
   if (atom && name) XFree (name);
@@ -2486,9 +2456,9 @@ FRAME is on.  If FRAME is nil, the selected frame is used.  */)
   (Lisp_Object atom, Lisp_Object frame)
 {
   Atom x_atom;
-  struct frame *f = check_x_frame (frame);
+  struct frame *f = decode_window_system_frame (frame);
   ptrdiff_t i;
-  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
 
 
   if (SYMBOLP (atom))
@@ -2542,7 +2512,7 @@ x_handle_dnd_message (struct frame *f, XClientMessageEvent *event,
      function expects them to be of size int (i.e. 32).  So to be able to
      use that function, put the data in the form it expects if format is 32. */
 
-  if (32 < BITS_PER_LONG && event->format == 32)
+  if (BITS_PER_LONG > 32 && event->format == 32)
     {
       for (i = 0; i < 5; ++i) /* There are only 5 longs in a ClientMessage. */
        idata[i] = event->data.l[i];
@@ -2572,7 +2542,7 @@ x_handle_dnd_message (struct frame *f, XClientMessageEvent *event,
   return 1;
 }
 
-DEFUN ("x-send-client-message", Fx_send_client_event,
+DEFUN ("x-send-client-message", Fx_send_client_message,
        Sx_send_client_message, 6, 6, 0,
        doc: /* Send a client message of MESSAGE-TYPE to window DEST on DISPLAY.
 
@@ -2619,7 +2589,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
   struct x_display_info *dpyinfo = check_x_display_info (display);
   Window wdest;
   XEvent event;
-  struct frame *f = check_x_frame (from);
+  struct frame *f = decode_window_system_frame (from);
   int to_root;
 
   CHECK_NUMBER (format);
@@ -2636,7 +2606,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
 
   if (FRAMEP (dest) || NILP (dest))
     {
-      struct frame *fdest = check_x_frame (dest);
+      struct frame *fdest = decode_window_system_frame (dest);
       wdest = FRAME_OUTER_WINDOW (fdest);
     }
   else if (STRINGP (dest))
@@ -2658,6 +2628,8 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
 
   block_input ();
 
+  event.xclient.send_event = True;
+  event.xclient.serial = 0;
   event.xclient.message_type = message_type;
   event.xclient.display = dpyinfo->display;
 
@@ -2665,19 +2637,19 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
      when sending to the root window.  */
   event.xclient.window = to_root ? FRAME_OUTER_WINDOW (f) : wdest;
 
-
-  memset (event.xclient.data.b, 0, sizeof (event.xclient.data.b));
+  memset (event.xclient.data.l, 0, sizeof (event.xclient.data.l));
   x_fill_property_data (dpyinfo->display, values, event.xclient.data.b,
                         event.xclient.format);
 
   /* If event mask is 0 the event is sent to the client that created
      the destination window.  But if we are sending to the root window,
-     there is no such client.  Then we set the event mask to 0xffff.  The
+     there is no such client.  Then we set the event mask to 0xffffff.  The
      event then goes to clients selecting for events on the root window.  */
   x_catch_errors (dpyinfo->display);
   {
     int propagate = to_root ? False : True;
-    unsigned mask = to_root ? 0xffff : 0;
+    long mask = to_root ? 0xffffff : 0;
+
     XSendEvent (dpyinfo->display, wdest, propagate, mask, &event);
     XFlush (dpyinfo->display);
   }