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

Implement Drag and Drop for X11 #5316

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion wezterm-gui/src/termwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,28 @@ impl TermWindow {
}
Ok(true)
}
WindowEvent::DroppedString(text) => {
let pane = match self.get_active_pane_or_overlay() {
Some(pane) => pane,
None => return Ok(true),
};
pane.send_paste(text.as_str())?;
Ok(true)
}
WindowEvent::DroppedUrl(urls) => {
let pane = match self.get_active_pane_or_overlay() {
Some(pane) => pane,
None => return Ok(true),
};
let urls = urls
.iter()
.map(|url| self.config.quote_dropped_files.escape(&url.to_string()))
.collect::<Vec<_>>()
.join(" ")
+ " ";
pane.send_paste(urls.as_str())?;
Ok(true)
}
WindowEvent::DroppedFile(paths) => {
let pane = match self.get_active_pane_or_overlay() {
Some(pane) => pane,
Expand All @@ -1024,7 +1046,8 @@ impl TermWindow {
.escape(&path.to_string_lossy())
})
.collect::<Vec<_>>()
.join(" ");
.join(" ")
+ " ";
pane.send_paste(&paths)?;
Ok(true)
}
Expand Down
2 changes: 2 additions & 0 deletions window/examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ impl MyWindow {
| WindowEvent::FocusChanged(_)
| WindowEvent::DraggedFile(_)
| WindowEvent::DroppedFile(_)
| WindowEvent::DroppedUrl(_)
| WindowEvent::DroppedString(_)
| WindowEvent::PerformKeyAssignment(_)
| WindowEvent::MouseLeave
| WindowEvent::SetInnerSizeCompleted => {}
Expand Down
7 changes: 7 additions & 0 deletions window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::any::Any;
use std::path::PathBuf;
use std::rc::Rc;
use thiserror::Error;
use url::Url;
pub mod bitmaps;
pub use wezterm_color_types as color;
mod configuration;
Expand Down Expand Up @@ -205,6 +206,12 @@ pub enum WindowEvent {
// Called when the files are dropped into the window
DroppedFile(Vec<PathBuf>),

// Called when urls are dropped into the window
DroppedUrl(Vec<Url>),

// Called when text is dropped into the window
DroppedString(String),

/// Called by menubar dispatching stuff on some systems
PerformKeyAssignment(config::keyassignment::KeyAssignment),

Expand Down
48 changes: 48 additions & 0 deletions window/src/os/x11/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ pub struct XConnection {
pub atom_xsel_data: Atom,
pub atom_targets: Atom,
pub atom_clipboard: Atom,
pub atom_texturilist: Atom,
pub atom_xmozurl: Atom,
pub atom_xdndaware: Atom,
pub atom_xdndtypelist: Atom,
pub atom_xdndselection: Atom,
pub atom_xdndenter: Atom,
pub atom_xdndposition: Atom,
pub atom_xdndstatus: Atom,
pub atom_xdndleave: Atom,
pub atom_xdnddrop: Atom,
pub atom_xdndfinished: Atom,
pub atom_xdndactioncopy: Atom,
pub atom_xdndactionmove: Atom,
pub atom_xdndactionlink: Atom,
pub atom_xdndactionask: Atom,
pub atom_xdndactionprivate: Atom,
pub atom_gtk_edge_constraints: Atom,
pub atom_xsettings_selection: Atom,
pub atom_xsettings_settings: Atom,
Expand Down Expand Up @@ -610,6 +626,22 @@ impl XConnection {
let atom_xsel_data = Self::intern_atom(&conn, "XSEL_DATA")?;
let atom_targets = Self::intern_atom(&conn, "TARGETS")?;
let atom_clipboard = Self::intern_atom(&conn, "CLIPBOARD")?;
let atom_texturilist = Self::intern_atom(&conn, "text/uri-list")?;
let atom_xmozurl = Self::intern_atom(&conn, "text/x-moz-url")?;
let atom_xdndaware = Self::intern_atom(&conn, "XdndAware")?;
let atom_xdndtypelist = Self::intern_atom(&conn, "XdndTypeList")?;
let atom_xdndselection = Self::intern_atom(&conn, "XdndSelection")?;
let atom_xdndenter = Self::intern_atom(&conn, "XdndEnter")?;
let atom_xdndposition = Self::intern_atom(&conn, "XdndPosition")?;
let atom_xdndstatus = Self::intern_atom(&conn, "XdndStatus")?;
let atom_xdndleave = Self::intern_atom(&conn, "XdndLeave")?;
let atom_xdnddrop = Self::intern_atom(&conn, "XdndDrop")?;
let atom_xdndfinished = Self::intern_atom(&conn, "XdndFinished")?;
let atom_xdndactioncopy = Self::intern_atom(&conn, "XdndActionCopy")?;
let atom_xdndactionmove = Self::intern_atom(&conn, "XdndActionMove")?;
let atom_xdndactionlink = Self::intern_atom(&conn, "XdndActionLink")?;
let atom_xdndactionask = Self::intern_atom(&conn, "XdndActionAsk")?;
let atom_xdndactionprivate = Self::intern_atom(&conn, "XdndActionPrivate")?;
let atom_gtk_edge_constraints = Self::intern_atom(&conn, "_GTK_EDGE_CONSTRAINTS")?;
let atom_xsettings_selection =
Self::intern_atom(&conn, &format!("_XSETTINGS_S{}", screen_num))?;
Expand Down Expand Up @@ -731,6 +763,22 @@ impl XConnection {
xrm: RefCell::new(xrm),
atom_protocols,
atom_clipboard,
atom_texturilist,
atom_xmozurl,
atom_xdndaware,
atom_xdndtypelist,
atom_xdndselection,
atom_xdndenter,
atom_xdndposition,
atom_xdndstatus,
atom_xdndleave,
atom_xdnddrop,
atom_xdndfinished,
atom_xdndactioncopy,
atom_xdndactionmove,
atom_xdndactionlink,
atom_xdndactionask,
atom_xdndactionprivate,
atom_gtk_edge_constraints,
atom_xsettings_selection,
atom_xsettings_settings,
Expand Down
Loading