diff --git a/examples/app_library/app_group/imp.rs b/examples/app_library/app_group/imp.rs index 734e1b77..68a5ee7e 100644 --- a/examples/app_library/app_group/imp.rs +++ b/examples/app_library/app_group/imp.rs @@ -142,7 +142,7 @@ impl ObjectImpl for AppGroup { .get::() .expect("The icon needs to be a Variant"), ) - .expect("The icon variant needs to be a Vec"); + .expect("The icon variant needs to be a Vec"); self.data.borrow_mut().app_names = appnames; } _ => unimplemented!(), diff --git a/examples/app_library/app_group/mod.rs b/examples/app_library/app_group/mod.rs index 8b3622dd..2e674ba9 100644 --- a/examples/app_library/app_group/mod.rs +++ b/examples/app_library/app_group/mod.rs @@ -20,7 +20,7 @@ impl AppGroup { ("icon", &data.icon), ("category", &data.category), ]) - .expect("Failed to create `ApplicationObject`."); + .expect("Failed to create `ApplicationObject`."); if let Err(e) = self_.set_property("appnames", data.app_names.to_variant()) { println!("failed to set category icon property"); dbg!(e); diff --git a/examples/app_library/grid_item/imp.rs b/examples/app_library/grid_item/imp.rs index 22db023d..38383d43 100644 --- a/examples/app_library/grid_item/imp.rs +++ b/examples/app_library/grid_item/imp.rs @@ -1,9 +1,9 @@ use std::cell::Cell; -use gtk4::CompositeTemplate; use gtk4::glib; use gtk4::prelude::*; use gtk4::subclass::prelude::*; +use gtk4::CompositeTemplate; #[derive(Debug, Default, CompositeTemplate)] #[template(file = "grid_item.ui")] diff --git a/examples/app_library/grid_item/mod.rs b/examples/app_library/grid_item/mod.rs index 8bb8cbad..f0fc538f 100644 --- a/examples/app_library/grid_item/mod.rs +++ b/examples/app_library/grid_item/mod.rs @@ -2,12 +2,12 @@ use gdk4::ContentProvider; use gdk4::Display; use gio::File; use gio::Icon; -use gtk4::{gio, glib}; -use gtk4::DragSource; -use gtk4::IconTheme; use gtk4::prelude::*; use gtk4::subclass::prelude::*; use gtk4::traits::WidgetExt; +use gtk4::DragSource; +use gtk4::IconTheme; +use gtk4::{gio, glib}; use crate::app_group::AppGroup; diff --git a/examples/app_library/main.rs b/examples/app_library/main.rs index e424360d..9a25204d 100644 --- a/examples/app_library/main.rs +++ b/examples/app_library/main.rs @@ -1,6 +1,6 @@ -use gtk4::CssProvider; use gtk4::gdk::Display; use gtk4::prelude::*; +use gtk4::CssProvider; use gtk4::StyleContext; use once_cell::sync::OnceCell; use x11rb::rust_connection::RustConnection; diff --git a/examples/app_library/window/mod.rs b/examples/app_library/window/mod.rs index f600f2bc..e7e9217f 100644 --- a/examples/app_library/window/mod.rs +++ b/examples/app_library/window/mod.rs @@ -6,13 +6,13 @@ use gdk4_x11::X11Surface; use glib::FromVariant; use glib::Object; use glib::Variant; -use gtk4::{gio, glib}; -use gtk4::{Application, SignalListItemFactory}; +use gtk4::prelude::*; +use gtk4::subclass::prelude::*; use gtk4::Dialog; use gtk4::Entry; use gtk4::Label; -use gtk4::prelude::*; -use gtk4::subclass::prelude::*; +use gtk4::{gio, glib}; +use gtk4::{Application, SignalListItemFactory}; use x11rb::connection::Connection; use x11rb::protocol::xproto; use x11rb::protocol::xproto::ConnectionExt; @@ -171,10 +171,10 @@ impl Window { category: "".to_string(), }), ] - .iter() - .for_each(|group| { - group_model.append(group); - }); + .iter() + .for_each(|group| { + group_model.append(group); + }); let group_selection = gtk4::SingleSelection::new(Some(&group_model)); imp.group_grid_view.set_model(Some(&group_selection)); } diff --git a/examples/dock/dock_item/dock_item.ui b/examples/dock/dock_item/dock_item.ui deleted file mode 100644 index b4e698fb..00000000 --- a/examples/dock/dock_item/dock_item.ui +++ /dev/null @@ -1,21 +0,0 @@ - - - - diff --git a/examples/dock/dock_item/imp.rs b/examples/dock/dock_item/imp.rs index e78c9816..9104158c 100644 --- a/examples/dock/dock_item/imp.rs +++ b/examples/dock/dock_item/imp.rs @@ -1,15 +1,12 @@ use gtk4::glib; -use gtk4::prelude::*; use gtk4::subclass::prelude::*; -use gtk4::CompositeTemplate; +use std::cell::RefCell; +use std::rc::Rc; -#[derive(Debug, Default, CompositeTemplate)] -#[template(file = "dock_item.ui")] +#[derive(Debug, Default)] pub struct DockItem { - #[template_child] - pub image: TemplateChild, - #[template_child] - pub dots: TemplateChild, + pub image: Rc>, + pub dots: Rc>, } #[glib::object_subclass] @@ -17,14 +14,6 @@ impl ObjectSubclass for DockItem { const NAME: &'static str = "DockItem"; type Type = super::DockItem; type ParentType = gtk4::Box; - - fn class_init(klass: &mut Self::Class) { - Self::bind_template(klass); - } - - fn instance_init(obj: &glib::subclass::InitializingObject) { - obj.init_template(); - } } impl ObjectImpl for DockItem {} diff --git a/examples/dock/dock_item/mod.rs b/examples/dock/dock_item/mod.rs index d13290e5..c55dfc12 100644 --- a/examples/dock/dock_item/mod.rs +++ b/examples/dock/dock_item/mod.rs @@ -1,8 +1,12 @@ +use cascade::cascade; use gio::DesktopAppInfo; use gio::Icon; use gtk4::glib; use gtk4::prelude::*; use gtk4::subclass::prelude::*; +use gtk4::Align; +use gtk4::Image; +use gtk4::Label; use crate::dock_object::DockObject; use crate::utils::BoxedWindowList; @@ -11,7 +15,9 @@ mod imp; glib::wrapper! { pub struct DockItem(ObjectSubclass) - @extends gtk4::Widget, gtk4::Box; + @extends gtk4::Widget, gtk4::Box, + @implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget, gtk4::Orientable; + } impl Default for DockItem { @@ -23,6 +29,25 @@ impl Default for DockItem { impl DockItem { pub fn new() -> Self { let self_: DockItem = glib::Object::new(&[]).expect("Failed to create DockItem"); + self_.set_orientation(gtk4::Orientation::Vertical); + let image = cascade! { + Image::new(); + ..set_margin_start(4); + ..set_margin_end(4); + ..set_margin_top(4); + ..set_pixel_size(48); + }; + let dots = cascade! { + Label::new(Some("")); + ..set_hexpand(true); + ..set_halign(Align::Center); + }; + self_.append(&image); + self_.append(&dots); + let imp = imp::DockItem::from_instance(&self_); + imp.image.replace(image); + imp.dots.replace(dots); + self_.show(); self_ } @@ -31,24 +56,26 @@ impl DockItem { let self_ = imp::DockItem::from_instance(self); if let Ok(app_info_value) = dock_object.property("appinfo") { if let Ok(Some(app_info)) = app_info_value.get::>() { - self_.image.set_tooltip_text(Some(&app_info.name())); + self_ + .image + .borrow() + .set_tooltip_text(Some(&app_info.name())); let icon = app_info.icon().unwrap_or( Icon::for_string("image-missing").expect("Failed to set default icon"), ); - self_.image.set_from_gicon(&icon); + self_.image.borrow().set_from_gicon(&icon); } } else { println!("initializing dock item failed..."); } if let Ok(active_value) = dock_object.property("active") { if let Ok(active) = active_value.get::() { - self_.dots.set_text(""); + let dots = self_.dots.borrow(); + dots.set_text(""); for _ in active.0 { - self_ - .dots - .set_text(format!("{}{}", self_.dots.text(), " · ").as_str()); + dots.set_text(format!("{}{}", dots.text(), " · ").as_str()); } } } diff --git a/examples/dock/main.rs b/examples/dock/main.rs index 87e96208..67f0d772 100644 --- a/examples/dock/main.rs +++ b/examples/dock/main.rs @@ -4,11 +4,11 @@ use std::time::Duration; use futures::executor::block_on; use gdk4::Display; use gio::DesktopAppInfo; -use gtk4::Application; -use gtk4::CssProvider; use gtk4::gio; use gtk4::glib; use gtk4::prelude::*; +use gtk4::Application; +use gtk4::CssProvider; use gtk4::StyleContext; use once_cell::sync::OnceCell; use postage::mpsc::Sender; @@ -131,7 +131,7 @@ fn main() { match event { Event::Activate(e) => { let _activate_window = zbus_conn - .call_method(Some(DEST), PATH, Some(DEST), "WindowFocus", &((e, ))) + .call_method(Some(DEST), PATH, Some(DEST), "WindowFocus", &((e,))) .await .expect("Failed to focus selected window"); } @@ -225,16 +225,16 @@ fn main() { // skip if equal if cached_results.len() == results.len() && results.iter().zip(cached_results.iter()).fold( - 0, - |acc, z: (&Item, &Item)| { - let (a, b) = z; - if a.name == b.name { - acc + 1 - } else { - acc - } - }, - ) == cached_results.len() + 0, + |acc, z: (&Item, &Item)| { + let (a, b) = z; + if a.name == b.name { + acc + 1 + } else { + acc + } + }, + ) == cached_results.len() { continue; // skip this update } diff --git a/examples/dock/window/mod.rs b/examples/dock/window/mod.rs index bde86692..854dc58e 100644 --- a/examples/dock/window/mod.rs +++ b/examples/dock/window/mod.rs @@ -12,15 +12,15 @@ use gio::Icon; // use crate::application_row::ApplicationRow; use glib::Object; use glib::Type; -use gtk4::{gio, glib}; -use gtk4::{Application, SignalListItemFactory}; -use gtk4::{DragSource, GestureClick}; +use gtk4::prelude::ListModelExt; +use gtk4::prelude::*; +use gtk4::subclass::prelude::*; use gtk4::DropTarget; use gtk4::EventControllerMotion; use gtk4::IconTheme; -use gtk4::prelude::*; -use gtk4::prelude::ListModelExt; -use gtk4::subclass::prelude::*; +use gtk4::{gio, glib}; +use gtk4::{Application, SignalListItemFactory}; +use gtk4::{DragSource, GestureClick}; use postage::prelude::Sink; use x11rb::connection::Connection; use x11rb::protocol::xproto; @@ -32,10 +32,10 @@ use crate::BoxedWindowList; // use crate::ApplicationObject; use crate::dock_item::DockItem; use crate::dock_object::DockObject; +use crate::utils::data_path; use crate::Event; use crate::Item; use crate::TX; -use crate::utils::data_path; use crate::X11_CONN; mod imp; diff --git a/examples/launcher/main.rs b/examples/launcher/main.rs index 38ce05b8..f7da4aad 100644 --- a/examples/launcher/main.rs +++ b/examples/launcher/main.rs @@ -1,10 +1,10 @@ use gdk4::Display; use gio::DesktopAppInfo; -use gtk4::Application; -use gtk4::CssProvider; use gtk4::gio; use gtk4::glib; use gtk4::prelude::*; +use gtk4::Application; +use gtk4::CssProvider; use gtk4::StyleContext; use once_cell::sync::OnceCell; use pop_launcher_service::IpcClient; diff --git a/examples/launcher/search_result_row/imp.rs b/examples/launcher/search_result_row/imp.rs index cc46589c..53dc0158 100644 --- a/examples/launcher/search_result_row/imp.rs +++ b/examples/launcher/search_result_row/imp.rs @@ -1,7 +1,7 @@ -use gtk4::CompositeTemplate; use gtk4::glib; use gtk4::prelude::*; use gtk4::subclass::prelude::*; +use gtk4::CompositeTemplate; #[derive(Debug, Default, CompositeTemplate)] #[template(file = "application_row.ui")] diff --git a/examples/launcher/search_result_row/mod.rs b/examples/launcher/search_result_row/mod.rs index 93f74b8a..8e46a091 100644 --- a/examples/launcher/search_result_row/mod.rs +++ b/examples/launcher/search_result_row/mod.rs @@ -2,8 +2,8 @@ use gtk4::glib; use gtk4::prelude::*; use gtk4::subclass::prelude::*; -use crate::BoxedSearchResult; use crate::icon_source; +use crate::BoxedSearchResult; use crate::SearchResultObject; mod imp; diff --git a/examples/launcher/window/imp.rs b/examples/launcher/window/imp.rs index cf1dc83f..0954fcdd 100644 --- a/examples/launcher/window/imp.rs +++ b/examples/launcher/window/imp.rs @@ -1,8 +1,8 @@ use glib::subclass::InitializingObject; -use gtk4::{gio, glib}; -use gtk4::{CompositeTemplate, Entry, ListView}; use gtk4::prelude::*; use gtk4::subclass::prelude::*; +use gtk4::{gio, glib}; +use gtk4::{CompositeTemplate, Entry, ListView}; use once_cell::sync::OnceCell; // Object holding the state diff --git a/examples/launcher/window/mod.rs b/examples/launcher/window/mod.rs index 3e600ff3..06c1135a 100644 --- a/examples/launcher/window/mod.rs +++ b/examples/launcher/window/mod.rs @@ -2,10 +2,10 @@ use gdk4::Rectangle; use gdk4_x11::X11Display; use gdk4_x11::X11Surface; use glib::Object; -use gtk4::{gio, glib}; -use gtk4::{Application, SignalListItemFactory}; use gtk4::prelude::*; use gtk4::subclass::prelude::*; +use gtk4::{gio, glib}; +use gtk4::{Application, SignalListItemFactory}; use postage::prelude::Sink; use x11rb::connection::Connection; use x11rb::protocol::xproto;