diff --git a/examples/app_library/grid_item/mod.rs b/examples/app_library/grid_item/mod.rs index b7c895b3..6ae2ef2b 100644 --- a/examples/app_library/grid_item/mod.rs +++ b/examples/app_library/grid_item/mod.rs @@ -1,5 +1,11 @@ use crate::app_group::AppGroup; +use gdk4::ContentProvider; +use gdk4::Display; +use gio::File; use gtk4 as gtk; +use gtk4::traits::WidgetExt; +use gtk4::DragSource; +use gtk4::IconTheme; mod imp; use gtk::prelude::*; @@ -26,8 +32,35 @@ impl GridItem { pub fn set_app_info(&self, app_info: &gio::DesktopAppInfo) { let self_ = imp::GridItem::from_instance(self); self_.name.set_text(&app_info.name()); + + let drag = DragSource::builder() + .name("application library drag source") + .actions(gdk4::DragAction::COPY) + // .content() + .build(); + self.add_controller(&drag); + if let Some(file) = app_info.filename() { + let file = File::for_path(file); + let provider = ContentProvider::for_value(&file.to_value()); + drag.set_content(Some(&provider)); + } if let Some(icon) = app_info.icon() { self_.image.set_from_gicon(&icon); + // set drag source icon if possible... + // gio Icon is not easily converted to a Paintable, but this seems to be the correct method + if let Some(default_display) = &Display::default() { + if let Some(icon_theme) = IconTheme::for_display(default_display) { + if let Some(paintable_icon) = icon_theme.lookup_by_gicon( + &icon, + 64, + 1, + gtk4::TextDirection::None, + gtk4::IconLookupFlags::empty(), + ) { + drag.set_icon(Some(&paintable_icon), 0, 0); + } + } + } } } diff --git a/examples/app_library/main.rs b/examples/app_library/main.rs index 340d4d1c..a9a65c51 100644 --- a/examples/app_library/main.rs +++ b/examples/app_library/main.rs @@ -13,12 +13,15 @@ use window::Window; fn main() { let app = gtk::Application::new(Some("com.cosmic.app_library"), Default::default()); - app.connect_startup(|_app| load_css()); - - app.connect_activate(|app| { - build_ui(app); + app.connect_startup(|app| { + load_css(); + build_ui(&app); }); + // app.connect_activate(|app| { + // build_ui(app); + // }); + app.run(); } diff --git a/examples/app_library/style.css b/examples/app_library/style.css index 0c72f8a3..8b137891 100644 --- a/examples/app_library/style.css +++ b/examples/app_library/style.css @@ -1,15 +1 @@ -description { - line-height: 1.5em; - background-image: none; - background-color: red; -} -row.row1 { - background-image: none; - background-color: black; -} - -shortcut { - background-image: none; - background-color: green; -} diff --git a/examples/app_library/window/window.ui b/examples/app_library/window/window.ui index b56178bf..8a1dc373 100644 --- a/examples/app_library/window/window.ui +++ b/examples/app_library/window/window.ui @@ -50,7 +50,6 @@ true 150 300 - 12 8