aboutsummaryrefslogtreecommitdiffstats
path: root/src/xselect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xselect.c')
-rw-r--r--src/xselect.c95
1 files changed, 46 insertions, 49 deletions
diff --git a/src/xselect.c b/src/xselect.c
index 92e89822293..3f8a1321954 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -46,9 +46,10 @@ struct prop_location;
46struct selection_data; 46struct selection_data;
47 47
48static void x_decline_selection_request (struct input_event *); 48static void x_decline_selection_request (struct input_event *);
49static int x_convert_selection (struct input_event *, Lisp_Object, Lisp_Object, 49static bool x_convert_selection (struct input_event *, Lisp_Object,
50 Atom, int, struct x_display_info *); 50 Lisp_Object, Atom, bool,
51static int waiting_for_other_props_on_window (Display *, Window); 51 struct x_display_info *);
52static bool waiting_for_other_props_on_window (Display *, Window);
52static struct prop_location *expect_property_change (Display *, Window, 53static struct prop_location *expect_property_change (Display *, Window,
53 Atom, int); 54 Atom, int);
54static void unexpect_property_change (struct prop_location *); 55static void unexpect_property_change (struct prop_location *);
@@ -360,7 +361,7 @@ x_own_selection (Lisp_Object selection_name, Lisp_Object selection_value,
360 361
361static Lisp_Object 362static Lisp_Object
362x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type, 363x_get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
363 int local_request, struct x_display_info *dpyinfo) 364 bool local_request, struct x_display_info *dpyinfo)
364{ 365{
365 Lisp_Object local_value; 366 Lisp_Object local_value;
366 Lisp_Object handler_fn, value, check; 367 Lisp_Object handler_fn, value, check;
@@ -470,7 +471,7 @@ struct selection_data
470 ptrdiff_t size; 471 ptrdiff_t size;
471 int format; 472 int format;
472 Atom type; 473 Atom type;
473 int nofree; 474 bool nofree;
474 Atom property; 475 Atom property;
475 /* This can be set to non-NULL during x_reply_selection_request, if 476 /* This can be set to non-NULL during x_reply_selection_request, if
476 the selection is waiting for an INCR transfer to complete. Don't 477 the selection is waiting for an INCR transfer to complete. Don't
@@ -498,7 +499,7 @@ x_selection_request_lisp_error (void)
498 for (cs = converted_selections; cs; cs = next) 499 for (cs = converted_selections; cs; cs = next)
499 { 500 {
500 next = cs->next; 501 next = cs->next;
501 if (cs->nofree == 0 && cs->data) 502 if (! cs->nofree && cs->data)
502 xfree (cs->data); 503 xfree (cs->data);
503 xfree (cs); 504 xfree (cs);
504 } 505 }
@@ -531,7 +532,7 @@ struct prop_location
531 Window window; 532 Window window;
532 Atom property; 533 Atom property;
533 int desired_state; 534 int desired_state;
534 int arrived; 535 bool arrived;
535 struct prop_location *next; 536 struct prop_location *next;
536}; 537};
537 538
@@ -747,7 +748,7 @@ x_handle_selection_request (struct input_event *event)
747 Lisp_Object target_symbol = x_atom_to_symbol (dpyinfo, target); 748 Lisp_Object target_symbol = x_atom_to_symbol (dpyinfo, target);
748 Atom property = SELECTION_EVENT_PROPERTY (event); 749 Atom property = SELECTION_EVENT_PROPERTY (event);
749 Lisp_Object local_selection_data; 750 Lisp_Object local_selection_data;
750 int success = 0; 751 bool success = false;
751 ptrdiff_t count = SPECPDL_INDEX (); 752 ptrdiff_t count = SPECPDL_INDEX ();
752 GCPRO2 (local_selection_data, target_symbol); 753 GCPRO2 (local_selection_data, target_symbol);
753 754
@@ -805,9 +806,9 @@ x_handle_selection_request (struct input_event *event)
805 806
806 if (subproperty != None) 807 if (subproperty != None)
807 x_convert_selection (event, selection_symbol, subtarget, 808 x_convert_selection (event, selection_symbol, subtarget,
808 subproperty, 1, dpyinfo); 809 subproperty, true, dpyinfo);
809 } 810 }
810 success = 1; 811 success = true;
811 } 812 }
812 else 813 else
813 { 814 {
@@ -815,7 +816,7 @@ x_handle_selection_request (struct input_event *event)
815 property = SELECTION_EVENT_TARGET (event); 816 property = SELECTION_EVENT_TARGET (event);
816 success = x_convert_selection (event, selection_symbol, 817 success = x_convert_selection (event, selection_symbol,
817 target_symbol, property, 818 target_symbol, property,
818 0, dpyinfo); 819 false, dpyinfo);
819 } 820 }
820 821
821 DONE: 822 DONE:
@@ -844,15 +845,15 @@ x_handle_selection_request (struct input_event *event)
844 845
845/* Perform the requested selection conversion, and write the data to 846/* Perform the requested selection conversion, and write the data to
846 the converted_selections linked list, where it can be accessed by 847 the converted_selections linked list, where it can be accessed by
847 x_reply_selection_request. If FOR_MULTIPLE is non-zero, write out 848 x_reply_selection_request. If FOR_MULTIPLE, write out
848 the data even if conversion fails, using conversion_fail_tag. 849 the data even if conversion fails, using conversion_fail_tag.
849 850
850 Return 0 if the selection failed to convert, 1 otherwise. */ 851 Return true iff successful. */
851 852
852static int 853static bool
853x_convert_selection (struct input_event *event, Lisp_Object selection_symbol, 854x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
854 Lisp_Object target_symbol, Atom property, 855 Lisp_Object target_symbol, Atom property,
855 int for_multiple, struct x_display_info *dpyinfo) 856 bool for_multiple, struct x_display_info *dpyinfo)
856{ 857{
857 struct gcpro gcpro1; 858 struct gcpro gcpro1;
858 Lisp_Object lisp_selection; 859 Lisp_Object lisp_selection;
@@ -861,7 +862,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
861 862
862 lisp_selection 863 lisp_selection
863 = x_get_local_selection (selection_symbol, target_symbol, 864 = x_get_local_selection (selection_symbol, target_symbol,
864 0, dpyinfo); 865 false, dpyinfo);
865 866
866 /* A nil return value means we can't perform the conversion. */ 867 /* A nil return value means we can't perform the conversion. */
867 if (NILP (lisp_selection) 868 if (NILP (lisp_selection)
@@ -874,7 +875,7 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
874 cs->size = 1; 875 cs->size = 1;
875 cs->format = 32; 876 cs->format = 32;
876 cs->type = XA_ATOM; 877 cs->type = XA_ATOM;
877 cs->nofree = 1; 878 cs->nofree = true;
878 cs->property = property; 879 cs->property = property;
879 cs->wait_object = NULL; 880 cs->wait_object = NULL;
880 cs->next = converted_selections; 881 cs->next = converted_selections;
@@ -882,20 +883,20 @@ x_convert_selection (struct input_event *event, Lisp_Object selection_symbol,
882 } 883 }
883 884
884 UNGCPRO; 885 UNGCPRO;
885 return 0; 886 return false;
886 } 887 }
887 888
888 /* Otherwise, record the converted selection to binary. */ 889 /* Otherwise, record the converted selection to binary. */
889 cs = xmalloc (sizeof *cs); 890 cs = xmalloc (sizeof *cs);
890 cs->data = NULL; 891 cs->data = NULL;
891 cs->nofree = 1; 892 cs->nofree = true;
892 cs->property = property; 893 cs->property = property;
893 cs->wait_object = NULL; 894 cs->wait_object = NULL;
894 cs->next = converted_selections; 895 cs->next = converted_selections;
895 converted_selections = cs; 896 converted_selections = cs;
896 lisp_data_to_selection_data (dpyinfo, lisp_selection, cs); 897 lisp_data_to_selection_data (dpyinfo, lisp_selection, cs);
897 UNGCPRO; 898 UNGCPRO;
898 return 1; 899 return true;
899} 900}
900 901
901/* Handle a SelectionClear event EVENT, which indicates that some 902/* Handle a SelectionClear event EVENT, which indicates that some
@@ -1012,19 +1013,16 @@ x_clear_frame_selections (struct frame *f)
1012 } 1013 }
1013} 1014}
1014 1015
1015/* Nonzero if any properties for DISPLAY and WINDOW 1016/* True if any properties for DISPLAY and WINDOW
1016 are on the list of what we are waiting for. */ 1017 are on the list of what we are waiting for. */
1017 1018
1018static int 1019static bool
1019waiting_for_other_props_on_window (Display *display, Window window) 1020waiting_for_other_props_on_window (Display *display, Window window)
1020{ 1021{
1021 struct prop_location *rest = property_change_wait_list; 1022 for (struct prop_location *p = property_change_wait_list; p; p = p->next)
1022 while (rest) 1023 if (p->display == display && p->window == window)
1023 if (rest->display == display && rest->window == window) 1024 return true;
1024 return 1; 1025 return false;
1025 else
1026 rest = rest->next;
1027 return 0;
1028} 1026}
1029 1027
1030/* Add an entry to the list of property changes we are waiting for. 1028/* Add an entry to the list of property changes we are waiting for.
@@ -1043,7 +1041,7 @@ expect_property_change (Display *display, Window window,
1043 pl->property = property; 1041 pl->property = property;
1044 pl->desired_state = state; 1042 pl->desired_state = state;
1045 pl->next = property_change_wait_list; 1043 pl->next = property_change_wait_list;
1046 pl->arrived = 0; 1044 pl->arrived = false;
1047 property_change_wait_list = pl; 1045 property_change_wait_list = pl;
1048 return pl; 1046 return pl;
1049} 1047}
@@ -1106,7 +1104,7 @@ wait_for_property_change (struct prop_location *location)
1106 EMACS_INT secs = timeout / 1000; 1104 EMACS_INT secs = timeout / 1000;
1107 int nsecs = (timeout % 1000) * 1000000; 1105 int nsecs = (timeout % 1000) * 1000000;
1108 TRACE2 (" Waiting %"pI"d secs, %d nsecs", secs, nsecs); 1106 TRACE2 (" Waiting %"pI"d secs, %d nsecs", secs, nsecs);
1109 wait_reading_process_output (secs, nsecs, 0, 0, 1107 wait_reading_process_output (secs, nsecs, 0, false,
1110 property_change_reply, NULL, 0); 1108 property_change_reply, NULL, 0);
1111 1109
1112 if (NILP (XCAR (property_change_reply))) 1110 if (NILP (XCAR (property_change_reply)))
@@ -1138,7 +1136,7 @@ x_handle_property_notify (const XPropertyEvent *event)
1138 (event->state == PropertyDelete ? "deletion" : "change"), 1136 (event->state == PropertyDelete ? "deletion" : "change"),
1139 XGetAtomName (event->display, event->atom)); 1137 XGetAtomName (event->display, event->atom));
1140 1138
1141 rest->arrived = 1; 1139 rest->arrived = true;
1142 1140
1143 /* If this is the one wait_for_property_change is waiting for, 1141 /* If this is the one wait_for_property_change is waiting for,
1144 tell it to wake up. */ 1142 tell it to wake up. */
@@ -1204,7 +1202,7 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
1204 during this time. In fact, the SAVE_TARGETS mechanism requires 1202 during this time. In fact, the SAVE_TARGETS mechanism requires
1205 us to handle a clipboard manager's requests before it returns 1203 us to handle a clipboard manager's requests before it returns
1206 SelectionNotify. */ 1204 SelectionNotify. */
1207#if 0 1205#if false
1208 x_start_queuing_selection_requests (); 1206 x_start_queuing_selection_requests ();
1209 record_unwind_protect_void (x_stop_queuing_selection_requests); 1207 record_unwind_protect_void (x_stop_queuing_selection_requests);
1210#endif 1208#endif
@@ -1216,7 +1214,7 @@ x_get_foreign_selection (Lisp_Object selection_symbol, Lisp_Object target_type,
1216 secs = timeout / 1000; 1214 secs = timeout / 1000;
1217 nsecs = (timeout % 1000) * 1000000; 1215 nsecs = (timeout % 1000) * 1000000;
1218 TRACE1 (" Start waiting %"pI"d secs for SelectionNotify", secs); 1216 TRACE1 (" Start waiting %"pI"d secs for SelectionNotify", secs);
1219 wait_reading_process_output (secs, nsecs, 0, 0, 1217 wait_reading_process_output (secs, nsecs, 0, false,
1220 reading_selection_reply, NULL, 0); 1218 reading_selection_reply, NULL, 0);
1221 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply))); 1219 TRACE1 (" Got event = %d", !NILP (XCAR (reading_selection_reply)));
1222 1220
@@ -1240,7 +1238,7 @@ static void
1240x_get_window_property (Display *display, Window window, Atom property, 1238x_get_window_property (Display *display, Window window, Atom property,
1241 unsigned char **data_ret, ptrdiff_t *bytes_ret, 1239 unsigned char **data_ret, ptrdiff_t *bytes_ret,
1242 Atom *actual_type_ret, int *actual_format_ret, 1240 Atom *actual_type_ret, int *actual_format_ret,
1243 unsigned long *actual_size_ret, int delete_p) 1241 unsigned long *actual_size_ret)
1244{ 1242{
1245 ptrdiff_t total_size; 1243 ptrdiff_t total_size;
1246 unsigned long bytes_remaining; 1244 unsigned long bytes_remaining;
@@ -1413,7 +1411,7 @@ receive_incremental_selection (struct x_display_info *dpyinfo,
1413 XFlush (display); 1411 XFlush (display);
1414 unblock_input (); 1412 unblock_input ();
1415 1413
1416 while (1) 1414 while (true)
1417 { 1415 {
1418 unsigned char *tmp_data; 1416 unsigned char *tmp_data;
1419 ptrdiff_t tmp_size_bytes; 1417 ptrdiff_t tmp_size_bytes;
@@ -1427,7 +1425,7 @@ receive_incremental_selection (struct x_display_info *dpyinfo,
1427 TRACE0 (" Get property value"); 1425 TRACE0 (" Get property value");
1428 x_get_window_property (display, window, property, 1426 x_get_window_property (display, window, property,
1429 &tmp_data, &tmp_size_bytes, 1427 &tmp_data, &tmp_size_bytes,
1430 type_ret, format_ret, size_ret, 1); 1428 type_ret, format_ret, size_ret);
1431 1429
1432 TRACE1 (" Read increment of %"pD"d bytes", tmp_size_bytes); 1430 TRACE1 (" Read increment of %"pD"d bytes", tmp_size_bytes);
1433 1431
@@ -1488,13 +1486,12 @@ x_get_window_property_as_lisp_data (struct x_display_info *dpyinfo,
1488 TRACE0 ("Reading selection data"); 1486 TRACE0 ("Reading selection data");
1489 1487
1490 x_get_window_property (display, window, property, &data, &bytes, 1488 x_get_window_property (display, window, property, &data, &bytes,
1491 &actual_type, &actual_format, &actual_size, 1); 1489 &actual_type, &actual_format, &actual_size);
1492 if (! data) 1490 if (! data)
1493 { 1491 {
1494 int there_is_a_selection_owner;
1495 block_input (); 1492 block_input ();
1496 there_is_a_selection_owner 1493 bool there_is_a_selection_owner
1497 = XGetSelectionOwner (display, selection_atom); 1494 = XGetSelectionOwner (display, selection_atom) != 0;
1498 unblock_input (); 1495 unblock_input ();
1499 if (there_is_a_selection_owner) 1496 if (there_is_a_selection_owner)
1500 signal_error ("Selection owner couldn't convert", 1497 signal_error ("Selection owner couldn't convert",
@@ -1687,7 +1684,7 @@ lisp_data_to_selection_data (struct x_display_info *dpyinfo,
1687 Lisp_Object type = Qnil; 1684 Lisp_Object type = Qnil;
1688 1685
1689 eassert (cs != NULL); 1686 eassert (cs != NULL);
1690 cs->nofree = 0; 1687 cs->nofree = false;
1691 1688
1692 if (CONSP (obj) && SYMBOLP (XCAR (obj))) 1689 if (CONSP (obj) && SYMBOLP (XCAR (obj)))
1693 { 1690 {
@@ -1714,7 +1711,7 @@ lisp_data_to_selection_data (struct x_display_info *dpyinfo,
1714 cs->format = 8; 1711 cs->format = 8;
1715 cs->size = SBYTES (obj); 1712 cs->size = SBYTES (obj);
1716 cs->data = SDATA (obj); 1713 cs->data = SDATA (obj);
1717 cs->nofree = 1; 1714 cs->nofree = true;
1718 } 1715 }
1719 else if (SYMBOLP (obj)) 1716 else if (SYMBOLP (obj))
1720 { 1717 {
@@ -1981,7 +1978,7 @@ On Nextstep, TIME-STAMP and TERMINAL are unused. */)
1981 if (!f) 1978 if (!f)
1982 error ("X selection unavailable for this frame"); 1979 error ("X selection unavailable for this frame");
1983 1980
1984 val = x_get_local_selection (selection_symbol, target_type, 1, 1981 val = x_get_local_selection (selection_symbol, target_type, true,
1985 FRAME_DISPLAY_INFO (f)); 1982 FRAME_DISPLAY_INFO (f));
1986 1983
1987 if (NILP (val) && FRAME_LIVE_P (f)) 1984 if (NILP (val) && FRAME_LIVE_P (f))
@@ -2432,7 +2429,7 @@ FRAME is on. If FRAME is nil, the selected frame is used. */)
2432 2429
2433/* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT. */ 2430/* Convert an XClientMessageEvent to a Lisp event of type DRAG_N_DROP_EVENT. */
2434 2431
2435int 2432bool
2436x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event, 2433x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event,
2437 struct x_display_info *dpyinfo, struct input_event *bufp) 2434 struct x_display_info *dpyinfo, struct input_event *bufp)
2438{ 2435{
@@ -2448,7 +2445,7 @@ x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event,
2448 for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i) 2445 for (i = 0; i < dpyinfo->x_dnd_atoms_length; ++i)
2449 if (dpyinfo->x_dnd_atoms[i] == event->message_type) break; 2446 if (dpyinfo->x_dnd_atoms[i] == event->message_type) break;
2450 2447
2451 if (i == dpyinfo->x_dnd_atoms_length) return 0; 2448 if (i == dpyinfo->x_dnd_atoms_length) return false;
2452 2449
2453 XSETFRAME (frame, f); 2450 XSETFRAME (frame, f);
2454 2451
@@ -2484,7 +2481,7 @@ x_handle_dnd_message (struct frame *f, const XClientMessageEvent *event,
2484 bufp->arg = vec; 2481 bufp->arg = vec;
2485 bufp->modifiers = 0; 2482 bufp->modifiers = 0;
2486 2483
2487 return 1; 2484 return true;
2488} 2485}
2489 2486
2490DEFUN ("x-send-client-message", Fx_send_client_message, 2487DEFUN ("x-send-client-message", Fx_send_client_message,
@@ -2535,7 +2532,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2535 Window wdest; 2532 Window wdest;
2536 XEvent event; 2533 XEvent event;
2537 struct frame *f = decode_window_system_frame (from); 2534 struct frame *f = decode_window_system_frame (from);
2538 int to_root; 2535 bool to_root;
2539 2536
2540 CHECK_NUMBER (format); 2537 CHECK_NUMBER (format);
2541 CHECK_CONS (values); 2538 CHECK_CONS (values);
@@ -2592,7 +2589,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2592 event then goes to clients selecting for events on the root window. */ 2589 event then goes to clients selecting for events on the root window. */
2593 x_catch_errors (dpyinfo->display); 2590 x_catch_errors (dpyinfo->display);
2594 { 2591 {
2595 int propagate = to_root ? False : True; 2592 bool propagate = !to_root;
2596 long mask = to_root ? 0xffffff : 0; 2593 long mask = to_root ? 0xffffff : 0;
2597 2594
2598 XSendEvent (dpyinfo->display, wdest, propagate, mask, &event); 2595 XSendEvent (dpyinfo->display, wdest, propagate, mask, &event);