#![allow(non_upper_case_globals, non_snake_case)]
use super::libx11::*;
#[derive(Default)]
pub struct X11DnD {
source: Window, version: libc::c_long, format: Atom, }
impl super::X11Display {
pub(super) unsafe fn init_drag_n_drop(&mut self) {
(self.libx11.XChangeProperty)(
self.display,
self.window,
self.libx11.extensions.xdnd_aware,
4 as _,
32,
PropModeReplace,
[5].as_ptr() as _, 1,
);
}
}
impl X11DnD {
pub unsafe fn on_enter(
&mut self,
libx11: &mut LibX11,
display: *mut Display,
_window: Window,
data: ClientMessageData,
) {
self.source = data.l[0] as _;
self.version = data.l[1] >> 24;
self.format = 0;
let formats: Vec<Atom> = if data.l[1] & 1 == 0 {
vec![data.l[2] as _, data.l[3] as _, data.l[4] as _]
} else {
let bytes = super::clipboard::get_property_bytes(
libx11,
display,
self.source,
libx11.extensions.xdnd_type_list,
);
bytes.align_to::<Atom>().1.to_vec()
};
for format in formats {
if format == libx11.extensions.utf8_string {
self.format = format;
break;
}
}
}
pub unsafe fn on_position(
&mut self,
libx11: &mut LibX11,
display: *mut Display,
window: Window,
_data: ClientMessageData,
) {
if self.version <= 5 {
let mut reply = XClientMessageEvent {
type_0: ClientMessage,
serial: 0,
send_event: true as _,
message_type: libx11.extensions.xdnd_status,
window: self.source,
display,
format: 32,
data: ClientMessageData {
l: [window as _, 0, 0, 0, 0],
},
};
if self.format != 0 {
reply.data.l[1] = 1;
if self.version >= 2 {
reply.data.l[4] = libx11.extensions.xdnd_action_copy as _;
}
}
(libx11.XSendEvent)(
display,
self.source,
false as _,
NoEventMask,
&mut reply as *mut XClientMessageEvent as *mut _,
);
(libx11.XFlush)(display);
}
}
pub unsafe fn on_drop(
&mut self,
libx11: &mut LibX11,
display: *mut Display,
window: Window,
data: ClientMessageData,
) {
if self.version <= 5 {
if self.format != 0 {
let mut time = CurrentTime;
if self.version >= 1 {
time = data.l[3];
}
(libx11.XConvertSelection)(
display,
libx11.extensions.xdnd_selection,
self.format,
libx11.extensions.xdnd_selection,
window,
time as Time,
);
} else if self.version >= 2 {
let mut reply = XClientMessageEvent {
type_0: ClientMessage,
serial: 0,
send_event: true as _,
message_type: libx11.extensions.xdnd_finished,
window: self.source,
display,
format: 32,
data: ClientMessageData {
l: [window as _, 0, 0, 0, 0],
},
};
(libx11.XSendEvent)(
display,
self.source,
false as _,
NoEventMask,
&mut reply as *mut XClientMessageEvent as *mut _,
);
(libx11.XFlush)(display);
}
}
}
}