Open GiorgosXou opened 1 year ago
"mimic drag and drop behavior of: GUI file-managers, like nautilus"
Ok, i think i found a solution for linux:
meh
I think it's possible without dragon by using xdtools to get the window and pid of proccess and then invoking somehow the events of DND or something? https://docs.gtk.org/gtk4/drag-and-drop.html
So there's something called XDND (X Drag-and-Drop) protocol for x11, I've no idea how it works but I asked chat-GPT for help and it gave me plenty of intresting but unusefull example using the xpybutil module....
It also gave me this example (that obviously is completly wrong) that has some interesting elements ...
from Xlib import X, display
from Xlib.protocol.event import ClientMessage
from Xlib import Xatom
# Connect to the X server
d = display.Display()
# Get the root window
root = d.screen().root
# Create a window for the drag source
source_window = root.create_window(
100, 100, 100, 100, # x, y, width, height
1, # border width
X.CopyFromParent, # depth
X.InputOutput, # class
X.CopyFromParent, # visual
background_pixel=d.screen().black_pixel
)
# Create a window for the drop target
target_window = root.create_window(
200, 200, 200, 200, # x, y, width, height
1, # border width
X.CopyFromParent, # depth
X.InputOutput, # class
X.CopyFromParent, # visual
background_pixel=d.screen().white_pixel
)
# Map the windows
source_window.map()
target_window.map()
# Simulate the drag and drop action
text_to_send = "Hello, world!" # Modify this line to change the text to be sent
source_data = [
d.intern_atom('XdndSelection'), # selection atom
Xatom.STRING, # target atom
0, # timestamp
source_window.id, # source window
X.CurrentTime # time
]
source_event = ClientMessage(
display=d,
window=target_window.id,
client_type=d.intern_atom('XdndEnter'),
data=(32, source_data) # 32 is the data format
)
source_window.send_event(source_event)
target_data = [
source_window.id, # source window
target_window.id, # target window
X.CurrentTime # time
]
target_event = ClientMessage(
display=d,
window=target_window.id,
client_type=d.intern_atom('XdndDrop'),
data=(32, source_data) # 32 is the data format
)
target_window.send_event(target_event)
# Flush the event queue and wait for events
d.flush()
while True:
event = d.next_event()
if event.type == X.ClientMessage:
message_type = d.get_atom_name(event.client_type)
print(f"Received message of type: {message_type}")
print(event)
# break
# Close the display connection
d.close()
PS. use xwininfo
and convert the hex id
to a decimical if you want to use another winndow instead of the one window created?
(Ok at least there's some progress) I think that something along those steps would work for X11:
kxOUT
kxIN
with ncurses
We need to figure out, how to drop a file from terminal into GUIs (especially browsers) [...]