aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2023-08-10 14:15:03 +0800
committerPo Lu2023-08-10 14:15:03 +0800
commit49248878d4da7dbf901a7cd555e129803ac5e095 (patch)
treeb74adf360e88a4ef950ade7379a024f97f9643eb /src
parentea1295ff2ca55adfc79f029d87a0b7a1a949238d (diff)
downloademacs-49248878d4da7dbf901a7cd555e129803ac5e095.tar.gz
emacs-49248878d4da7dbf901a7cd555e129803ac5e095.zip
; Improve sectioning and documentation in xterm.c
* src/xterm.c (x_dnd_compute_toplevels, x_dnd_get_target_window_1) (x_dnd_get_wm_state_and_proto, xi_frame_selected_for) (xi_convert_event_state, x_free_xi_devices) (xi_populate_device_from_info): Improve sectioning, fill some lines to 80 columns. Not all lines could be filled as a result of XCB's heretically long identifier names.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c190
1 files changed, 124 insertions, 66 deletions
diff --git a/src/xterm.c b/src/xterm.c
index f454733c659..6a1642ff56e 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1215,6 +1215,8 @@ static void x_set_input_focus (struct x_display_info *, Window, Time);
1215static void x_scroll_bar_redraw (struct scroll_bar *); 1215static void x_scroll_bar_redraw (struct scroll_bar *);
1216#endif 1216#endif
1217 1217
1218
1219
1218/* Global state maintained during a drag-and-drop operation. */ 1220/* Global state maintained during a drag-and-drop operation. */
1219 1221
1220/* Flag that indicates if a drag-and-drop operation is in progress. */ 1222/* Flag that indicates if a drag-and-drop operation is in progress. */
@@ -1543,6 +1545,8 @@ static struct x_client_list_window *x_dnd_toplevels;
1543 for `x_dnd_toplevels' to work. */ 1545 for `x_dnd_toplevels' to work. */
1544static bool x_dnd_use_toplevels; 1546static bool x_dnd_use_toplevels;
1545 1547
1548
1549
1546/* Motif drag-and-drop protocol support. */ 1550/* Motif drag-and-drop protocol support. */
1547 1551
1548/* Pointer to a variable which stores whether or not an X error 1552/* Pointer to a variable which stores whether or not an X error
@@ -2914,6 +2918,11 @@ x_dnd_send_xm_leave_for_drop (struct x_display_info *dpyinfo,
2914 wdesc, &lmsg); 2918 wdesc, &lmsg);
2915} 2919}
2916 2920
2921
2922
2923/* Drag-and-drop and XDND protocol primitives employed by the event
2924 loop. */
2925
2917static void 2926static void
2918x_dnd_free_toplevels (bool display_alive) 2927x_dnd_free_toplevels (bool display_alive)
2919{ 2928{
@@ -3259,9 +3268,10 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3259 if (!xm_property_reply) 3268 if (!xm_property_reply)
3260 free (error); 3269 free (error);
3261 3270
3262 extent_property_reply = xcb_get_property_reply (dpyinfo->xcb_connection, 3271 extent_property_reply
3263 extent_property_cookies[i], 3272 = xcb_get_property_reply (dpyinfo->xcb_connection,
3264 &error); 3273 extent_property_cookies[i],
3274 &error);
3265 3275
3266 if (!extent_property_reply) 3276 if (!extent_property_reply)
3267 free (error); 3277 free (error);
@@ -3342,7 +3352,8 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3342#else 3352#else
3343 if (xm_property_reply 3353 if (xm_property_reply
3344 && xm_property_reply->format == 8 3354 && xm_property_reply->format == 8
3345 && xm_property_reply->type == dpyinfo->Xatom_MOTIF_DRAG_RECEIVER_INFO 3355 && (xm_property_reply->type
3356 == dpyinfo->Xatom_MOTIF_DRAG_RECEIVER_INFO)
3346 && xcb_get_property_value_length (xm_property_reply) >= 4) 3357 && xcb_get_property_value_length (xm_property_reply) >= 4)
3347 { 3358 {
3348 xmdata = xcb_get_property_value (xm_property_reply); 3359 xmdata = xcb_get_property_value (xm_property_reply);
@@ -3391,9 +3402,10 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3391 XFree (rects); 3402 XFree (rects);
3392 } 3403 }
3393#else 3404#else
3394 bounding_rect_reply = xcb_shape_get_rectangles_reply (dpyinfo->xcb_connection, 3405 bounding_rect_reply
3395 bounding_rect_cookies[i], 3406 = xcb_shape_get_rectangles_reply (dpyinfo->xcb_connection,
3396 &error); 3407 bounding_rect_cookies[i],
3408 &error);
3397 3409
3398 if (bounding_rect_reply) 3410 if (bounding_rect_reply)
3399 { 3411 {
@@ -3404,7 +3416,8 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3404 * sizeof *tem->bounding_rects); 3416 * sizeof *tem->bounding_rects);
3405 tem->n_bounding_rects = 0; 3417 tem->n_bounding_rects = 0;
3406 3418
3407 for (; bounding_rect_iterator.rem; xcb_rectangle_next (&bounding_rect_iterator)) 3419 for (; bounding_rect_iterator.rem;
3420 xcb_rectangle_next (&bounding_rect_iterator))
3408 { 3421 {
3409 tem->bounding_rects[tem->n_bounding_rects].x 3422 tem->bounding_rects[tem->n_bounding_rects].x
3410 = bounding_rect_iterator.data->x; 3423 = bounding_rect_iterator.data->x;
@@ -3429,9 +3442,10 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3429 || (dpyinfo->xshape_major == 1 3442 || (dpyinfo->xshape_major == 1
3430 && dpyinfo->xshape_minor >= 1)) 3443 && dpyinfo->xshape_minor >= 1))
3431 { 3444 {
3432 input_rect_reply = xcb_shape_get_rectangles_reply (dpyinfo->xcb_connection, 3445 input_rect_reply
3433 input_rect_cookies[i], 3446 = xcb_shape_get_rectangles_reply (dpyinfo->xcb_connection,
3434 &error); 3447 input_rect_cookies[i],
3448 &error);
3435 3449
3436 if (input_rect_reply) 3450 if (input_rect_reply)
3437 { 3451 {
@@ -3442,7 +3456,8 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3442 * sizeof *tem->input_rects); 3456 * sizeof *tem->input_rects);
3443 tem->n_input_rects = 0; 3457 tem->n_input_rects = 0;
3444 3458
3445 for (; input_rect_iterator.rem; xcb_rectangle_next (&input_rect_iterator)) 3459 for (; input_rect_iterator.rem;
3460 xcb_rectangle_next (&input_rect_iterator))
3446 { 3461 {
3447 tem->input_rects[tem->n_input_rects].x 3462 tem->input_rects[tem->n_input_rects].x
3448 = input_rect_iterator.data->x; 3463 = input_rect_iterator.data->x;
@@ -3509,17 +3524,25 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3509 if (tem->n_input_rects == -1 3524 if (tem->n_input_rects == -1
3510 && tem->n_bounding_rects == 1 3525 && tem->n_bounding_rects == 1
3511#ifdef USE_XCB 3526#ifdef USE_XCB
3512 && tem->bounding_rects[0].width == (geometry_reply->width 3527 && (tem->bounding_rects[0].width
3513 + geometry_reply->border_width) 3528 == (geometry_reply->width
3514 && tem->bounding_rects[0].height == (geometry_reply->height 3529 + geometry_reply->border_width))
3515 + geometry_reply->border_width) 3530 && (tem->bounding_rects[0].height
3516 && tem->bounding_rects[0].x == -geometry_reply->border_width 3531 == (geometry_reply->height
3517 && tem->bounding_rects[0].y == -geometry_reply->border_width 3532 + geometry_reply->border_width))
3533 && (tem->bounding_rects[0].x
3534 == -geometry_reply->border_width)
3535 && (tem->bounding_rects[0].y
3536 == -geometry_reply->border_width)
3518#else 3537#else
3519 && tem->bounding_rects[0].width == attrs.width + attrs.border_width 3538 && (tem->bounding_rects[0].width
3520 && tem->bounding_rects[0].height == attrs.height + attrs.border_width 3539 == attrs.width + attrs.border_width)
3521 && tem->bounding_rects[0].x == -attrs.border_width 3540 && (tem->bounding_rects[0].height
3522 && tem->bounding_rects[0].y == -attrs.border_width 3541 == attrs.height + attrs.border_width)
3542 && (tem->bounding_rects[0].x
3543 == -attrs.border_width)
3544 && (tem->bounding_rects[0].y
3545 == -attrs.border_width)
3523#endif 3546#endif
3524 ) 3547 )
3525 { 3548 {
@@ -3542,9 +3565,10 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3542#ifdef HAVE_XCB_SHAPE 3565#ifdef HAVE_XCB_SHAPE
3543 if (dpyinfo->xshape_supported_p) 3566 if (dpyinfo->xshape_supported_p)
3544 { 3567 {
3545 bounding_rect_reply = xcb_shape_get_rectangles_reply (dpyinfo->xcb_connection, 3568 bounding_rect_reply
3546 bounding_rect_cookies[i], 3569 = xcb_shape_get_rectangles_reply (dpyinfo->xcb_connection,
3547 &error); 3570 bounding_rect_cookies[i],
3571 &error);
3548 3572
3549 if (bounding_rect_reply) 3573 if (bounding_rect_reply)
3550 free (bounding_rect_reply); 3574 free (bounding_rect_reply);
@@ -3559,9 +3583,10 @@ x_dnd_compute_toplevels (struct x_display_info *dpyinfo)
3559 || (dpyinfo->xshape_major == 1 3583 || (dpyinfo->xshape_major == 1
3560 && dpyinfo->xshape_minor >= 1))) 3584 && dpyinfo->xshape_minor >= 1)))
3561 { 3585 {
3562 input_rect_reply = xcb_shape_get_rectangles_reply (dpyinfo->xcb_connection, 3586 input_rect_reply
3563 input_rect_cookies[i], 3587 = xcb_shape_get_rectangles_reply (dpyinfo->xcb_connection,
3564 &error); 3588 input_rect_cookies[i],
3589 &error);
3565 3590
3566 if (input_rect_reply) 3591 if (input_rect_reply)
3567 free (input_rect_reply); 3592 free (input_rect_reply);
@@ -3784,8 +3809,10 @@ x_dnd_get_target_window_1 (struct x_display_info *dpyinfo,
3784 if (tem->n_input_rects == -1 3809 if (tem->n_input_rects == -1
3785 || x_dnd_get_target_window_2 (tem->input_rects, 3810 || x_dnd_get_target_window_2 (tem->input_rects,
3786 tem->n_input_rects, 3811 tem->n_input_rects,
3787 tem->border_width + root_x - tem->x, 3812 (tem->border_width
3788 tem->border_width + root_y - tem->y)) 3813 + root_x - tem->x),
3814 (tem->border_width
3815 + root_y - tem->y)))
3789 { 3816 {
3790 chosen = tem; 3817 chosen = tem;
3791 break; 3818 break;
@@ -3872,11 +3899,12 @@ x_dnd_get_wm_state_and_proto (struct x_display_info *dpyinfo,
3872 (xcb_window_t) window, 3899 (xcb_window_t) window,
3873 (xcb_atom_t) dpyinfo->Xatom_XdndProxy, 3900 (xcb_atom_t) dpyinfo->Xatom_XdndProxy,
3874 XA_WINDOW, 0, 1); 3901 XA_WINDOW, 0, 1);
3875 xm_style_cookie = xcb_get_property (dpyinfo->xcb_connection, 0, 3902 xm_style_cookie
3876 (xcb_window_t) window, 3903 = xcb_get_property (dpyinfo->xcb_connection, 0,
3877 (xcb_atom_t) dpyinfo->Xatom_MOTIF_DRAG_RECEIVER_INFO, 3904 (xcb_window_t) window,
3878 (xcb_atom_t) dpyinfo->Xatom_MOTIF_DRAG_RECEIVER_INFO, 3905 (xcb_atom_t) dpyinfo->Xatom_MOTIF_DRAG_RECEIVER_INFO,
3879 0, 4); 3906 (xcb_atom_t) dpyinfo->Xatom_MOTIF_DRAG_RECEIVER_INFO,
3907 0, 4);
3880 3908
3881 reply = xcb_get_property_reply (dpyinfo->xcb_connection, 3909 reply = xcb_get_property_reply (dpyinfo->xcb_connection,
3882 wmstate_cookie, &error); 3910 wmstate_cookie, &error);
@@ -4920,6 +4948,11 @@ x_dnd_cleanup_drag_and_drop (void *frame)
4920 x_restore_events_after_dnd (f, &x_dnd_old_window_attrs); 4948 x_restore_events_after_dnd (f, &x_dnd_old_window_attrs);
4921} 4949}
4922 4950
4951
4952
4953/* Primitives for simplified drag-and-drop tracking when items are
4954 being dragged between frames comprising the same Emacs session. */
4955
4923static void 4956static void
4924x_dnd_note_self_position (struct x_display_info *dpyinfo, Window target, 4957x_dnd_note_self_position (struct x_display_info *dpyinfo, Window target,
4925 unsigned short root_x, unsigned short root_y) 4958 unsigned short root_x, unsigned short root_y)
@@ -5050,6 +5083,10 @@ x_dnd_note_self_drop (struct x_display_info *dpyinfo, Window target,
5050 kbd_buffer_store_event (&ie); 5083 kbd_buffer_store_event (&ie);
5051} 5084}
5052 5085
5086
5087
5088/* Miscellaneous X event and graphics extension functions. */
5089
5053/* Flush display of frame F. */ 5090/* Flush display of frame F. */
5054 5091
5055static void 5092static void
@@ -5134,28 +5171,9 @@ record_event (char *locus, int type)
5134 5171
5135#endif 5172#endif
5136 5173
5137#ifdef HAVE_XINPUT2 5174
5138bool
5139xi_frame_selected_for (struct frame *f, unsigned long event)
5140{
5141 XIEventMask *masks;
5142 int i;
5143
5144 masks = FRAME_X_OUTPUT (f)->xi_masks;
5145
5146 if (!masks)
5147 return false;
5148
5149 for (i = 0; i < FRAME_X_OUTPUT (f)->num_xi_masks; ++i)
5150 {
5151 if (masks[i].mask_len >= XIMaskLen (event)
5152 && XIMaskIsSet (masks[i].mask, event))
5153 return true;
5154 }
5155 5175
5156 return false; 5176/* Miscelaneous event handling functions. */
5157}
5158#endif
5159 5177
5160static void 5178static void
5161x_toolkit_position (struct frame *f, int x, int y, 5179x_toolkit_position (struct frame *f, int x, int y,
@@ -5300,10 +5318,36 @@ x_extension_initialize (struct x_display_info *dpyinfo)
5300 5318
5301#endif /* HAVE_CAIRO */ 5319#endif /* HAVE_CAIRO */
5302 5320
5321
5322
5323/* X input extension device and event mask management functions. */
5324
5303#ifdef HAVE_XINPUT2 5325#ifdef HAVE_XINPUT2
5304 5326
5327bool
5328xi_frame_selected_for (struct frame *f, unsigned long event)
5329{
5330 XIEventMask *masks;
5331 int i;
5332
5333 masks = FRAME_X_OUTPUT (f)->xi_masks;
5334
5335 if (!masks)
5336 return false;
5337
5338 for (i = 0; i < FRAME_X_OUTPUT (f)->num_xi_masks; ++i)
5339 {
5340 if (masks[i].mask_len >= XIMaskLen (event)
5341 && XIMaskIsSet (masks[i].mask, event))
5342 return true;
5343 }
5344
5345 return false;
5346}
5347
5305/* Convert XI2 button state IN to a standard X button modifier 5348/* Convert XI2 button state IN to a standard X button modifier
5306 mask, and place it in OUT. */ 5349 mask, and place it in OUT. */
5350
5307static void 5351static void
5308xi_convert_button_state (XIButtonState *in, unsigned int *out) 5352xi_convert_button_state (XIButtonState *in, unsigned int *out)
5309{ 5353{
@@ -5325,7 +5369,7 @@ xi_convert_button_state (XIButtonState *in, unsigned int *out)
5325 5369
5326#ifdef USE_GTK 5370#ifdef USE_GTK
5327static 5371static
5328#endif 5372#endif /* USE_GTK */
5329unsigned int 5373unsigned int
5330xi_convert_event_state (XIDeviceEvent *xev) 5374xi_convert_event_state (XIDeviceEvent *xev)
5331{ 5375{
@@ -5351,12 +5395,13 @@ xi_convert_event_keyboard_state (XIDeviceEvent *xev)
5351} 5395}
5352 5396
5353/* Free all XI2 devices on DPYINFO. */ 5397/* Free all XI2 devices on DPYINFO. */
5398
5354static void 5399static void
5355x_free_xi_devices (struct x_display_info *dpyinfo) 5400x_free_xi_devices (struct x_display_info *dpyinfo)
5356{ 5401{
5357#ifdef HAVE_XINPUT2_2 5402#ifdef HAVE_XINPUT2_2
5358 struct xi_touch_point_t *tem, *last; 5403 struct xi_touch_point_t *tem, *last;
5359#endif 5404#endif /* HAVE_XINPUT2_2 */
5360 5405
5361 block_input (); 5406 block_input ();
5362 5407
@@ -5366,7 +5411,7 @@ x_free_xi_devices (struct x_display_info *dpyinfo)
5366 { 5411 {
5367#ifdef HAVE_XINPUT2_1 5412#ifdef HAVE_XINPUT2_1
5368 xfree (dpyinfo->devices[i].valuators); 5413 xfree (dpyinfo->devices[i].valuators);
5369#endif 5414#endif /* HAVE_XINPUT2_1 */
5370 5415
5371#ifdef HAVE_XINPUT2_2 5416#ifdef HAVE_XINPUT2_2
5372 tem = dpyinfo->devices[i].touchpoints; 5417 tem = dpyinfo->devices[i].touchpoints;
@@ -5376,7 +5421,7 @@ x_free_xi_devices (struct x_display_info *dpyinfo)
5376 tem = tem->next; 5421 tem = tem->next;
5377 xfree (last); 5422 xfree (last);
5378 } 5423 }
5379#endif 5424#endif /* HAVE_XINPUT2_2 */
5380 } 5425 }
5381 5426
5382 xfree (dpyinfo->devices); 5427 xfree (dpyinfo->devices);
@@ -5441,7 +5486,7 @@ xi_populate_scroll_valuator (struct xi_device_t *device,
5441 valuator->number = info->number; 5486 valuator->number = info->number;
5442} 5487}
5443 5488
5444#endif 5489#endif /* HAVE_XINPUT2_1 */
5445 5490
5446static void 5491static void
5447xi_populate_device_from_info (struct x_display_info *dpyinfo, 5492xi_populate_device_from_info (struct x_display_info *dpyinfo,
@@ -5453,14 +5498,14 @@ xi_populate_device_from_info (struct x_display_info *dpyinfo,
5453 int actual_valuator_count, c; 5498 int actual_valuator_count, c;
5454 XIScrollClassInfo *info; 5499 XIScrollClassInfo *info;
5455 XIValuatorClassInfo *valuator_info; 5500 XIValuatorClassInfo *valuator_info;
5456#endif 5501#endif /* HAVE_XINPUT2_1 */
5457#ifdef HAVE_XINPUT2_2 5502#ifdef HAVE_XINPUT2_2
5458 XITouchClassInfo *touch_info; 5503 XITouchClassInfo *touch_info;
5459#endif 5504#endif /* HAVE_XINPUT2_2 */
5460 5505
5461#ifdef HAVE_XINPUT2_1 5506#ifdef HAVE_XINPUT2_1
5462 USE_SAFE_ALLOCA; 5507 USE_SAFE_ALLOCA;
5463#endif 5508#endif /* HAVE_XINPUT2_1 */
5464 5509
5465 /* Initialize generic information about the device: its ID, which 5510 /* Initialize generic information about the device: its ID, which
5466 buttons are currently pressed and thus presumably actively 5511 buttons are currently pressed and thus presumably actively
@@ -5917,8 +5962,12 @@ xi_reset_scroll_valuators_for_device_id (struct x_display_info *dpyinfo,
5917} 5962}
5918 5963
5919#endif /* HAVE_XINPUT2_1 */ 5964#endif /* HAVE_XINPUT2_1 */
5965#endif /* HAVE_XINPUT2 */
5920 5966
5921#endif 5967
5968
5969/* Cairo context, X rendering extension, and GC auxiliary data
5970 management functions. */
5922 5971
5923#ifdef USE_CAIRO 5972#ifdef USE_CAIRO
5924 5973
@@ -6404,6 +6453,7 @@ x_cr_export_frames (Lisp_Object frames, cairo_surface_type_t surface_type)
6404#endif /* USE_CAIRO */ 6453#endif /* USE_CAIRO */
6405 6454
6406#if defined HAVE_XRENDER 6455#if defined HAVE_XRENDER
6456
6407void 6457void
6408x_xr_apply_ext_clip (struct frame *f, GC gc) 6458x_xr_apply_ext_clip (struct frame *f, GC gc)
6409{ 6459{
@@ -6427,7 +6477,8 @@ x_xr_reset_ext_clip (struct frame *f)
6427 FRAME_X_PICTURE (f), 6477 FRAME_X_PICTURE (f),
6428 CPClipMask, &attrs); 6478 CPClipMask, &attrs);
6429} 6479}
6430#endif 6480
6481#endif /* HAVE_XRENDER */
6431 6482
6432static void 6483static void
6433x_set_clip_rectangles (struct frame *f, GC gc, XRectangle *rectangles, int n) 6484x_set_clip_rectangles (struct frame *f, GC gc, XRectangle *rectangles, int n)
@@ -6631,6 +6682,9 @@ x_fill_rectangle (struct frame *f, GC gc, int x, int y, int width, int height,
6631#endif 6682#endif
6632} 6683}
6633 6684
6685
6686
6687/* Graphics primitives. */
6634 6688
6635static void 6689static void
6636x_clear_rectangle (struct frame *f, GC gc, int x, int y, int width, int height, 6690x_clear_rectangle (struct frame *f, GC gc, int x, int y, int width, int height,
@@ -6923,6 +6977,8 @@ x_set_frame_alpha (struct frame *f)
6923 x_stop_ignoring_errors (dpyinfo); 6977 x_stop_ignoring_errors (dpyinfo);
6924} 6978}
6925 6979
6980
6981
6926/*********************************************************************** 6982/***********************************************************************
6927 Starting and ending an update 6983 Starting and ending an update
6928 ***********************************************************************/ 6984 ***********************************************************************/
@@ -7618,6 +7674,8 @@ XTbuffer_flipping_unblocked_hook (struct frame *f)
7618} 7674}
7619#endif 7675#endif
7620 7676
7677
7678
7621/** 7679/**
7622 * x_clear_under_internal_border: 7680 * x_clear_under_internal_border:
7623 * 7681 *