1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-17 17:58:46 +00:00

Handle coordinates of Motif drop start messages

* src/xterm.c (xm_read_drop_start_message): New function.
(xm_read_drag_motion_message): Check that the originator is
correct.
(x_coords_from_dnd_message): Read drop start messages as well.
This commit is contained in:
Po Lu 2022-06-14 13:52:38 +08:00
parent 6fd33fbf6a
commit 82ce218394

View File

@ -2339,6 +2339,44 @@ xm_read_drop_start_reply (const XEvent *msg, xm_drop_start_reply *reply)
return 0;
}
static int
xm_read_drop_start_message (const XEvent *msg,
xm_drop_start_message *dmsg)
{
const uint8_t *data;
data = (const uint8_t *) &msg->xclient.data.b[0];
if ((XM_DRAG_REASON_ORIGINATOR (data[0])
!= XM_DRAG_ORIGINATOR_INITIATOR)
|| (XM_DRAG_REASON_CODE (data[0])
!= XM_DRAG_REASON_DROP_START))
return 1;
dmsg->reason = *(data++);
dmsg->byte_order = *(data++);
dmsg->side_effects = *(uint16_t *) data;
dmsg->timestamp = *(uint32_t *) (data + 2);
dmsg->x = *(uint16_t *) (data + 6);
dmsg->y = *(uint16_t *) (data + 8);
dmsg->index_atom = *(uint32_t *) (data + 10);
dmsg->source_window = *(uint32_t *) (data + 14);
if (dmsg->byte_order != XM_BYTE_ORDER_CUR_FIRST)
{
SWAPCARD16 (dmsg->side_effects);
SWAPCARD32 (dmsg->timestamp);
SWAPCARD16 (dmsg->x);
SWAPCARD16 (dmsg->y);
SWAPCARD32 (dmsg->index_atom);
SWAPCARD32 (dmsg->source_window);
}
dmsg->byte_order = XM_BYTE_ORDER_CUR_FIRST;
return 0;
}
static int
xm_read_drag_receiver_info (struct x_display_info *dpyinfo,
Window wdesc, xm_drag_receiver_info *rec)
@ -2395,7 +2433,7 @@ xm_read_drag_receiver_info (struct x_display_info *dpyinfo,
return !rc;
}
static void
static int
xm_read_drag_motion_message (const XEvent *msg,
xm_drag_motion_message *dmsg)
{
@ -2403,6 +2441,12 @@ xm_read_drag_motion_message (const XEvent *msg,
data = (const uint8_t *) &msg->xclient.data.b[0];
if ((XM_DRAG_REASON_CODE (data[0])
!= XM_DRAG_REASON_DRAG_MOTION)
|| (XM_DRAG_REASON_ORIGINATOR (data[0])
!= XM_DRAG_ORIGINATOR_INITIATOR))
return 1;
dmsg->reason = *(data++);
dmsg->byteorder = *(data++);
dmsg->side_effects = *(uint16_t *) data;
@ -2417,6 +2461,10 @@ xm_read_drag_motion_message (const XEvent *msg,
SWAPCARD16 (dmsg->x);
SWAPCARD16 (dmsg->y);
}
dmsg->byteorder = XM_BYTE_ORDER_CUR_FIRST;
return 0;
}
static void
@ -15794,6 +15842,8 @@ x_coords_from_dnd_message (struct x_display_info *dpyinfo,
XEvent *event, int *x_out, int *y_out)
{
xm_drag_motion_message dmsg;
xm_drop_start_message smsg;
xm_drop_start_reply reply;
if (event->type != ClientMessage)
return false;
@ -15814,13 +15864,25 @@ x_coords_from_dnd_message (struct x_display_info *dpyinfo,
== dpyinfo->Xatom_MOTIF_DRAG_AND_DROP_MESSAGE)
&& event->xclient.format == 8)
{
if (event->xclient.data.b[0]
== XM_DRAG_REASON_DRAG_MOTION)
if (!xm_read_drag_motion_message (event, &dmsg))
{
xm_read_drag_motion_message (event, &dmsg);
*x_out = dmsg.x;
*y_out = dmsg.y;
return true;
}
else if (!xm_read_drop_start_message (event, &smsg))
{
*x_out = smsg.x;
*y_out = smsg.y;
return true;
}
else if (!xm_read_drop_start_reply (event, &reply))
{
*x_out = reply.better_x;
*y_out = reply.better_y;
return true;
}
}