From a6976daa25f03d30231c9cdc22cb33f64f5bc5f7 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 31 Oct 2023 13:18:43 -0600 Subject: [PATCH] Implement copy/cut/paste, only use iced_winit --- Cargo.lock | 313 +++----------------------------------------------- Cargo.toml | 6 +- src/config.rs | 5 +- src/main.rs | 52 ++++++++- src/menu.rs | 6 +- src/tab.rs | 2 +- 6 files changed, 74 insertions(+), 310 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c664824..293f419 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,26 +228,6 @@ dependencies = [ "libloading 0.7.4", ] -[[package]] -name = "ashpd" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7370b58af1d7e96df3ca0f454b57e69acf9aa42ed2d7337bd206923bae0d5754" -dependencies = [ - "enumflags2", - "futures-channel", - "futures-util", - "once_cell", - "rand", - "serde", - "serde_repr", - "url", - "wayland-backend 0.1.2", - "wayland-client 0.30.2", - "wayland-protocols 0.30.1", - "zbus", -] - [[package]] name = "async-broadcast" version = "0.5.1" @@ -308,7 +288,7 @@ dependencies = [ "futures-lite", "log", "parking", - "polling 2.8.0", + "polling", "rustix 0.37.27", "slab", "socket2", @@ -621,32 +601,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "calloop" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b50b5a44d59a98c55a9eeb518f39bf7499ba19fd98ee7d22618687f3f10adbf" -dependencies = [ - "bitflags 2.4.1", - "log", - "polling 3.2.0", - "rustix 0.38.21", - "slab", - "thiserror", -] - -[[package]] -name = "calloop-wayland-source" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" -dependencies = [ - "calloop 0.12.3", - "rustix 0.38.21", - "wayland-backend 0.3.2", - "wayland-client 0.31.1", -] - [[package]] name = "cc" version = "1.0.83" @@ -1058,12 +1012,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" -[[package]] -name = "cursor-icon" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf" - [[package]] name = "d3d12" version = "0.6.0" @@ -1305,17 +1253,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "enum-repr" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad30c9c0fa1aaf1ae5010dab11f1117b15d35faf62cda4bbbc53b9987950f18" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "enumflags2" version = "0.7.8" @@ -1504,9 +1441,6 @@ name = "float-cmp" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" -dependencies = [ - "num-traits", -] [[package]] name = "float_next_after" @@ -2209,7 +2143,6 @@ dependencies = [ "iced_core", "iced_futures", "iced_renderer", - "iced_sctk", "iced_widget", "iced_winit", "image", @@ -2222,7 +2155,6 @@ version = "0.1.0" source = "git+https://github.com/pop-os/libcosmic?branch=menu#4e5e1a7f54ed117c066289758c7b3dfe0487be2c" dependencies = [ "accesskit", - "accesskit_unix", "accesskit_winit", ] @@ -2232,11 +2164,9 @@ version = "0.10.0" source = "git+https://github.com/pop-os/libcosmic?branch=menu#4e5e1a7f54ed117c066289758c7b3dfe0487be2c" dependencies = [ "bitflags 1.3.2", - "iced_accessibility", "instant", "log", "palette", - "smithay-client-toolkit 0.17.0", "thiserror", "twox-hash", ] @@ -2289,37 +2219,11 @@ name = "iced_runtime" version = "0.1.1" source = "git+https://github.com/pop-os/libcosmic?branch=menu#4e5e1a7f54ed117c066289758c7b3dfe0487be2c" dependencies = [ - "iced_accessibility", "iced_core", "iced_futures", - "smithay-client-toolkit 0.17.0", "thiserror", ] -[[package]] -name = "iced_sctk" -version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic?branch=menu#4e5e1a7f54ed117c066289758c7b3dfe0487be2c" -dependencies = [ - "enum-repr", - "float-cmp", - "futures", - "iced_futures", - "iced_graphics", - "iced_runtime", - "iced_style", - "itertools", - "lazy_static", - "raw-window-handle 0.5.2", - "smithay-client-toolkit 0.17.0", - "smithay-clipboard", - "thiserror", - "tracing", - "wayland-backend 0.3.2", - "wayland-protocols 0.31.0", - "xkeysym", -] - [[package]] name = "iced_style" version = "0.9.0" @@ -2380,7 +2284,6 @@ dependencies = [ "iced_style", "num-traits", "ouroboros", - "smithay-client-toolkit 0.17.0", "thiserror", "unicode-segmentation", ] @@ -2536,15 +2439,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.9" @@ -2657,7 +2551,6 @@ version = "0.1.0" source = "git+https://github.com/pop-os/libcosmic?branch=menu#4e5e1a7f54ed117c066289758c7b3dfe0487be2c" dependencies = [ "apply", - "ashpd", "cosmic-config", "cosmic-theme", "css-color", @@ -2669,7 +2562,6 @@ dependencies = [ "iced_futures", "iced_renderer", "iced_runtime", - "iced_sctk", "iced_style", "iced_tiny_skia", "iced_widget", @@ -2677,7 +2569,6 @@ dependencies = [ "lazy_static", "palette", "slotmap", - "smithay-client-toolkit 0.17.0", "taffy", "thiserror", "tracing", @@ -2861,15 +2752,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memmap2" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49388d20533534cd19360ad3d6a7dadc885944aa802ba3995040c5ec11288c6" -dependencies = [ - "libc", -] - [[package]] name = "memmap2" version = "0.8.0" @@ -3662,20 +3544,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "polling" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62a79e457c9898100b4298d57d69ec53d06f9a6ed352431ce5f377e082d2e846" -dependencies = [ - "cfg-if", - "concurrent-queue", - "pin-project-lite", - "rustix 0.38.21", - "tracing", - "windows-sys 0.48.0", -] - [[package]] name = "powerfmt" version = "0.2.0" @@ -4188,7 +4056,7 @@ checksum = "61270629cc6b4d77ec1907db1033d5c2e1a404c412743621981a871dc9c12339" dependencies = [ "crossfont", "log", - "smithay-client-toolkit 0.16.1", + "smithay-client-toolkit", "tiny-skia 0.7.0", ] @@ -4201,7 +4069,7 @@ dependencies = [ "ab_glyph", "log", "memmap2 0.5.10", - "smithay-client-toolkit 0.16.1", + "smithay-client-toolkit", "tiny-skia 0.8.4", ] @@ -4372,7 +4240,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "870427e30b8f2cbe64bf43ec4b86e88fe39b0a84b3f15efd9c9c2d020bc86eb9" dependencies = [ "bitflags 1.3.2", - "calloop 0.10.6", + "calloop", "dlib", "lazy_static", "log", @@ -4380,35 +4248,8 @@ dependencies = [ "nix 0.24.3", "pkg-config", "wayland-client 0.29.5", - "wayland-cursor 0.29.5", - "wayland-protocols 0.29.5", -] - -[[package]] -name = "smithay-client-toolkit" -version = "0.17.0" -source = "git+https://github.com/smithay/client-toolkit?rev=dc8c4a0#dc8c4a035128208af65141fe12142a1dbc4a32bb" -dependencies = [ - "bitflags 2.4.1", - "bytemuck", - "calloop 0.12.3", - "calloop-wayland-source", - "cursor-icon", - "dlib", - "log", - "memmap2 0.7.1", - "nix 0.26.4", - "pkg-config", - "thiserror", - "wayland-backend 0.3.2", - "wayland-client 0.31.1", - "wayland-csd-frame", - "wayland-cursor 0.31.0", - "wayland-protocols 0.31.0", - "wayland-protocols-wlr", - "wayland-scanner 0.31.0", - "xkbcommon", - "xkeysym", + "wayland-cursor", + "wayland-protocols", ] [[package]] @@ -4417,7 +4258,7 @@ version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a345c870a1fae0b1b779085e81b51e614767c239e93503588e54c5b17f4b0e8" dependencies = [ - "smithay-client-toolkit 0.16.1", + "smithay-client-toolkit", "wayland-client 0.29.5", ] @@ -4449,7 +4290,7 @@ dependencies = [ "redox_syscall 0.3.5", "thiserror", "wasm-bindgen", - "wayland-backend 0.1.2", + "wayland-backend", "wayland-client 0.30.2", "wayland-sys 0.30.1", "web-sys", @@ -5042,7 +4883,6 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", - "serde", ] [[package]] @@ -5242,20 +5082,6 @@ dependencies = [ "wayland-sys 0.30.1", ] -[[package]] -name = "wayland-backend" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19152ddd73f45f024ed4534d9ca2594e0ef252c1847695255dae47f34df9fbe4" -dependencies = [ - "cc", - "downcast-rs", - "nix 0.26.4", - "scoped-tls", - "smallvec", - "wayland-sys 0.31.1", -] - [[package]] name = "wayland-client" version = "0.29.5" @@ -5280,22 +5106,10 @@ checksum = "489c9654770f674fc7e266b3c579f4053d7551df0ceb392f153adb1f9ed06ac8" dependencies = [ "bitflags 1.3.2", "nix 0.26.4", - "wayland-backend 0.1.2", + "wayland-backend", "wayland-scanner 0.30.1", ] -[[package]] -name = "wayland-client" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ca7d52347346f5473bf2f56705f360e8440873052e575e55890c4fa57843ed3" -dependencies = [ - "bitflags 2.4.1", - "nix 0.26.4", - "wayland-backend 0.3.2", - "wayland-scanner 0.31.0", -] - [[package]] name = "wayland-commons" version = "0.29.5" @@ -5308,17 +5122,6 @@ dependencies = [ "wayland-sys 0.29.5", ] -[[package]] -name = "wayland-csd-frame" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" -dependencies = [ - "bitflags 2.4.1", - "cursor-icon", - "wayland-backend 0.3.2", -] - [[package]] name = "wayland-cursor" version = "0.29.5" @@ -5330,17 +5133,6 @@ dependencies = [ "xcursor", ] -[[package]] -name = "wayland-cursor" -version = "0.31.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44aa20ae986659d6c77d64d808a046996a932aa763913864dc40c359ef7ad5b" -dependencies = [ - "nix 0.26.4", - "wayland-client 0.31.1", - "xcursor", -] - [[package]] name = "wayland-protocols" version = "0.29.5" @@ -5353,43 +5145,6 @@ dependencies = [ "wayland-scanner 0.29.5", ] -[[package]] -name = "wayland-protocols" -version = "0.30.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b28101e5ca94f70461a6c2d610f76d85ad223d042dd76585ab23d3422dd9b4d" -dependencies = [ - "bitflags 1.3.2", - "wayland-backend 0.1.2", - "wayland-client 0.30.2", - "wayland-scanner 0.30.1", -] - -[[package]] -name = "wayland-protocols" -version = "0.31.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e253d7107ba913923dc253967f35e8561a3c65f914543e46843c88ddd729e21c" -dependencies = [ - "bitflags 2.4.1", - "wayland-backend 0.3.2", - "wayland-client 0.31.1", - "wayland-scanner 0.31.0", -] - -[[package]] -name = "wayland-protocols-wlr" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" -dependencies = [ - "bitflags 2.4.1", - "wayland-backend 0.3.2", - "wayland-client 0.31.1", - "wayland-protocols 0.31.0", - "wayland-scanner 0.31.0", -] - [[package]] name = "wayland-scanner" version = "0.29.5" @@ -5412,17 +5167,6 @@ dependencies = [ "quote", ] -[[package]] -name = "wayland-scanner" -version = "0.31.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8e28403665c9f9513202b7e1ed71ec56fde5c107816843fb14057910b2c09c" -dependencies = [ - "proc-macro2", - "quick-xml 0.30.0", - "quote", -] - [[package]] name = "wayland-sys" version = "0.29.5" @@ -5446,17 +5190,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "wayland-sys" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" -dependencies = [ - "dlib", - "log", - "pkg-config", -] - [[package]] name = "web-sys" version = "0.3.64" @@ -5879,10 +5612,10 @@ dependencies = [ "raw-window-handle 0.4.3", "raw-window-handle 0.5.2", "sctk-adwaita 0.4.3", - "smithay-client-toolkit 0.16.1", + "smithay-client-toolkit", "wasm-bindgen", "wayland-client 0.29.5", - "wayland-protocols 0.29.5", + "wayland-protocols", "web-sys", "windows-sys 0.36.1", "x11-dl", @@ -5911,11 +5644,11 @@ dependencies = [ "raw-window-handle 0.5.2", "redox_syscall 0.3.5", "sctk-adwaita 0.5.4", - "smithay-client-toolkit 0.16.1", + "smithay-client-toolkit", "wasm-bindgen", "wayland-client 0.29.5", "wayland-commons", - "wayland-protocols 0.29.5", + "wayland-protocols", "wayland-scanner 0.29.5", "web-sys", "windows-sys 0.45.0", @@ -6013,25 +5746,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "xkbcommon" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52db25b599e92bf6e3904134618728eeb7b49a5a4f38f107f92399bb9c496b88" -dependencies = [ - "libc", - "memmap2 0.7.1", -] - -[[package]] -name = "xkeysym" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "054a8e68b76250b253f671d1268cb7f1ae089ec35e195b2efb2a4e9a836d0621" -dependencies = [ - "bytemuck", -] - [[package]] name = "xml-rs" version = "0.8.19" @@ -6177,7 +5891,6 @@ dependencies = [ "libc", "serde", "static_assertions", - "url", "zvariant_derive", ] diff --git a/Cargo.toml b/Cargo.toml index 409a7bb..d9ea233 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,9 +26,9 @@ features = ["syntect", "vi"] git = "https://github.com/pop-os/libcosmic" branch = "menu" default-features = false +features = ["winit"] #path = "../libcosmic" [features] -default = ["wayland"] -wayland = ["libcosmic/wayland"] -winit = ["libcosmic/winit"] +default = [] +vi = [] diff --git a/src/config.rs b/src/config.rs index 5d3db0d..49e9841 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,7 @@ use cosmic::iced::keyboard::{KeyCode, Modifiers}; use std::{collections::HashMap, fmt}; -use crate::{fl, Message}; +use crate::Message; #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct KeyBind { @@ -26,6 +26,9 @@ impl KeyBind { }}; } + bind!(CTRL, X, Cut); + bind!(CTRL, C, Copy); + bind!(CTRL, V, Paste); bind!(CTRL, N, New); bind!(CTRL, O, OpenFileDialog); bind!(CTRL, S, Save); diff --git a/src/main.rs b/src/main.rs index e43630b..07231d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use cosmic::{ app::{message, Command, Core, Settings}, executor, iced::{ - event, keyboard, subscription, + clipboard, event, keyboard, subscription, widget::{row, text}, Alignment, Length, Limits, }, @@ -48,7 +48,14 @@ fn main() -> Result<(), Box> { localize::localize(); - let settings = Settings::default().size_limits(Limits::NONE.min_width(400.0).min_height(200.0)); + let mut settings = Settings::default(); + + //TODO: fix wayland resize on iced_winit + settings = settings.client_decorations(false); + + //TODO: allow size limits on iced_winit + //settings = settings.size_limits(Limits::NONE.min_width(400.0).min_height(200.0)); + let flags = (); cosmic::app::run::(settings, flags)?; @@ -65,12 +72,16 @@ pub struct App { #[allow(dead_code)] #[derive(Clone, Debug, Eq, PartialEq)] pub enum Message { + Cut, + Copy, KeyBind(KeyBind), New, OpenFileDialog, OpenFile(PathBuf), OpenProjectDialog, OpenProject(PathBuf), + Paste, + PasteValue(String), Save, TabActivate(segmented_button::Entity), TabClose(segmented_button::Entity), @@ -383,6 +394,27 @@ impl cosmic::Application for App { fn update(&mut self, message: Message) -> Command { match message { + Message::Cut => match self.active_tab() { + Some(tab) => { + let mut editor = tab.editor.lock().unwrap(); + let selection_opt = editor.copy_selection(); + editor.delete_selection(); + if let Some(selection) = selection_opt { + return clipboard::write(selection); + } + } + None => {} + }, + Message::Copy => match self.active_tab() { + Some(tab) => { + let mut editor = tab.editor.lock().unwrap(); + let selection_opt = editor.copy_selection(); + if let Some(selection) = selection_opt { + return clipboard::write(selection); + } + } + None => {} + }, Message::KeyBind(key_bind) => { for (config_key_bind, config_message) in self.config.keybinds.iter() { if config_key_bind == &key_bind { @@ -425,6 +457,22 @@ impl cosmic::Application for App { Message::OpenProject(path) => { self.open_project(path); } + Message::Paste => { + return clipboard::read(|value_opt| match value_opt { + Some(value) => message::app(Message::PasteValue(value)), + None => message::none(), + }); + } + Message::PasteValue(value) => { + println!("Paste {:?}", value); + match self.active_tab() { + Some(tab) => { + let mut editor = tab.editor.lock().unwrap(); + editor.insert_string(&value, None); + } + None => {} + } + } Message::Save => { let mut title_opt = None; diff --git a/src/menu.rs b/src/menu.rs index d21b60c..d3f21dc 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -96,9 +96,9 @@ pub fn menu_bar<'a>(config: &Config) -> Element<'a, Message> { menu_key(fl!("undo"), "Ctrl + Z", Message::Todo), menu_key(fl!("redo"), "Ctrl + Shift + Z", Message::Todo), MenuTree::new(horizontal_rule(1)), - menu_key(fl!("cut"), "Ctrl + X", Message::Todo), - menu_key(fl!("copy"), "Ctrl + C", Message::Todo), - menu_key(fl!("paste"), "Ctrl + V", Message::Todo), + menu_item(fl!("cut"), Message::Cut), + menu_item(fl!("copy"), Message::Copy), + menu_item(fl!("paste"), Message::Paste), MenuTree::new(horizontal_rule(1)), menu_key(fl!("find"), "Ctrl + F", Message::Todo), menu_key(fl!("replace"), "Ctrl + H", Message::Todo), diff --git a/src/tab.rs b/src/tab.rs index a8b41a8..b3ff07a 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -32,7 +32,7 @@ impl Tab { .unwrap(); let mut editor = ViEditor::new(editor); - editor.set_passthrough(false); + editor.set_passthrough(!cfg!(feature = "vi")); Self { path_opt: None,