prototype DnD that works with plank dock

This commit is contained in:
Ashley Wulber 2021-12-07 17:14:54 -05:00 committed by Jeremy Soller
parent 7e6f6d22f8
commit 8725329651
4 changed files with 40 additions and 19 deletions

View file

@ -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);
}
}
}
}
}

View file

@ -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();
}

View file

@ -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;
}

View file

@ -50,7 +50,6 @@
<property name="propagate-natural-height">true</property>
<property name="min-content-height">150</property>
<property name="max-content-height">300</property>
<property name="margin-top">12</property>
<child>
<object class="GtkGridView" id="group_grid_view">
<property name="min-columns">8</property>