Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop files from TUI into GUI #21

Open
GiorgosXou opened this issue Nov 21, 2022 · 9 comments
Open

Drop files from TUI into GUI #21

GiorgosXou opened this issue Nov 21, 2022 · 9 comments
Labels
enhancement New feature or request help wanted Extra attention is needed Partially Solved

Comments

@GiorgosXou
Copy link
Owner

We need to figure out, how to drop a file from terminal into GUIs (especially browsers) [...]

@GiorgosXou GiorgosXou added enhancement New feature or request help wanted Extra attention is needed labels Nov 21, 2022
@GiorgosXou
Copy link
Owner Author

GiorgosXou commented Nov 21, 2022

"mimic drag and drop behavior of: GUI file-managers, like nautilus"

@GiorgosXou GiorgosXou changed the title Drop files ftom TUI into GUI Drop files from TUI into GUI Dec 9, 2022
@GiorgosXou
Copy link
Owner Author

Ok, i think i found a solution for linux:

@GiorgosXou
Copy link
Owner Author

meh

@GiorgosXou
Copy link
Owner Author

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

@GiorgosXou
Copy link
Owner Author

GiorgosXou commented Feb 16, 2023

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....

@GiorgosXou
Copy link
Owner Author

GiorgosXou commented Jun 21, 2023

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?

@GiorgosXou
Copy link
Owner Author

@GiorgosXou
Copy link
Owner Author

(Ok at least there's some progress) I think that something along those steps would work for X11:

@GiorgosXou
Copy link
Owner Author

#92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed Partially Solved
Projects
None yet
Development

No branches or pull requests

1 participant