upgrade gtk-rs version

This commit is contained in:
Ashley Wulber 2022-01-19 10:19:56 -05:00
parent 0b5f6b8386
commit cc577b1367
23 changed files with 401 additions and 317 deletions

View file

@ -4,37 +4,37 @@ version = "0.1.0"
edition = "2021"
[dependencies]
cascade = "1"
derivative = "2"
gdk4 = "0.3.1"
gdk4-wayland = { version = "0.3", optional = true }
gdk4-x11 = "0.3.0"
gio = "0.14.8"
gobject-sys = "0.14.0"
wayland-client = { version = "0.28", optional = true }
wayland-protocols = { version = "0.28", features = [ "client", "unstable_protocols" ], optional = true }
x11 = { version = "2", features = ["xlib"] }
cascade = "1.0.0"
derivative = "2.2.0"
gdk4 = "0.4.3"
gdk4-wayland = { version = "0.4.2", optional = true }
gdk4-x11 = { version = "0.4.2", features = [ "xlib" ] }
gio = "0.15.2"
gobject-sys = "0.15.1"
wayland-client = { version = "0.29.4", optional = true }
wayland-protocols = { version = "0.29.4", features = [ "client", "unstable_protocols" ], optional = true }
x11 = { version = "2.19.1", features = ["xlib"] }
# examples
gtk4 = { version ="0.3.1", features = ["v4_4"] }
glib-sys = "0.14.0"
gtk4 = { version = "0.4.3", features = ["v4_4"] }
gtk4-sys = "0.4.2"
glib-sys = "0.15.1"
relm4-macros = { git = "https://github.com/AaronErhardt/Relm4" }
pop-launcher-service = { git = "https://github.com/wash2/launcher.git" }
pop-launcher = { git = "https://github.com/wash2/launcher.git" }
serde = "1.0.130"
serde_json = "1.0.72"
serde = "1.0.133"
serde_json = "1.0.75"
tokio = { version = "1.15.0", features = ["sync"] }
futures = "0.3.17"
futures = "0.3.19"
futures-util = "0.3.19"
once_cell = "1.8.0"
once_cell = "1.9.0"
xdg = "2.4.0"
x11rb = "0.9.0"
# zbus
zbus = "2.0.0"
zvariant = "3.0.0"
zvariant_derive = "3.0.0"
libloading = "0.7.2"
gtk4-sys = "0.3.1"
zbus = "2.0.1"
zvariant = "3.1.0"
zvariant_derive = "3.1.0"
libloading = "0.7.3"
[profile.release]
incremental = true

View file

@ -1,6 +1,10 @@
use std::cell::RefCell;
use std::rc::Rc;
use gdk4::glib::ParamSpecBoolean;
use gdk4::glib::ParamSpecString;
use gdk4::glib::ParamSpecUInt;
use gdk4::glib::ParamSpecVariant;
use glib::{FromVariant, ParamFlags, ParamSpec, ToVariant, Value, Variant, VariantTy};
use gtk4::glib;
use gtk4::prelude::*;
@ -28,7 +32,7 @@ impl ObjectImpl for AppGroup {
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
vec![
ParamSpec::new_uint(
ParamSpecUInt::new(
// Name
"id",
// Nickname
@ -42,7 +46,7 @@ impl ObjectImpl for AppGroup {
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpec::new_string(
ParamSpecString::new(
// Name
"name",
// Nickname
@ -54,7 +58,7 @@ impl ObjectImpl for AppGroup {
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpec::new_boolean(
ParamSpecBoolean::new(
// Name
"mutable",
// Nickname
@ -66,7 +70,7 @@ impl ObjectImpl for AppGroup {
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpec::new_string(
ParamSpecString::new(
// Name
"icon",
// Nickname
@ -78,7 +82,7 @@ impl ObjectImpl for AppGroup {
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpec::new_string(
ParamSpecString::new(
// Name
"category",
// Nickname
@ -90,7 +94,7 @@ impl ObjectImpl for AppGroup {
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpec::new_variant(
ParamSpecVariant::new(
// Name
"appnames",
// Nickname

View file

@ -21,10 +21,7 @@ impl AppGroup {
("category", &data.category),
])
.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);
};
self_.set_property("appnames", data.app_names.to_variant());
self_
}

View file

@ -94,37 +94,29 @@ impl GridItem {
// 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(),
) {
_self.set_icon(Some(&paintable_icon), 32, 32);
}
}
let icon_theme = IconTheme::for_display(default_display);
let paintable_icon = icon_theme.lookup_by_gicon(
&icon,
64,
1,
gtk4::TextDirection::None,
gtk4::IconLookupFlags::empty(),
);
_self.set_icon(Some(&paintable_icon), 32, 32);
}
}));
}
pub fn set_group_info(&self, app_group: AppGroup) {
let self_ = imp::GridItem::from_instance(self);
if let Ok(name) = app_group.property("name") {
self_.name.borrow().set_text(
&name
.get::<String>()
.expect("property name needs to be a string."),
);
}
if let Ok(icon) = app_group.property("icon") {
self_.image.borrow().set_from_icon_name(Some(
&icon
.get::<String>()
.expect("Property name needs to be a String."),
));
}
self_
.name
.borrow()
.set_text(&app_group.property::<String>("name"));
self_
.image
.borrow()
.set_from_icon_name(Some(&app_group.property::<String>("icon")));
}
pub fn set_index(&self, index: u32) {

View file

@ -1,12 +1,12 @@
use cascade::cascade;
use glib::Object;
use glib::{FromVariant, Variant};
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use gtk4::{
gio, glib, Dialog, Entry, GridView, Label, PolicyType, ScrolledWindow, SignalListItemFactory,
Window,
};
use gtk4::{prelude::*, CustomFilter};
use std::fs::File;
use crate::app_group::AppGroup;
@ -239,18 +239,10 @@ impl GroupGrid {
.downcast::<AppGroup>()
.unwrap();
let category =
if let Ok(category_prop) = app_info.property("category") {
category_prop.get::<String>().unwrap_or("".to_string()).to_lowercase()
} else {
"".to_string()
};
app_info.property::<String>("category").to_lowercase();
let app_names =
if let Ok(app_names_prop) = app_info.property("appnames") {
<Vec<String>>::from_variant(&app_names_prop.get::<Variant>().expect("appnames nneds to be a variant.")).unwrap_or_default()
} else {
vec![]
};
<Vec<String>>::from_variant(&app_info.property::<Variant>("appnames")).unwrap_or_default();
dbg!(&app_names);
let new_filter: gtk4::CustomFilter = gtk4::CustomFilter::new(move |obj| {
let app = obj
@ -265,8 +257,7 @@ impl GroupGrid {
}
});
self_clone
.emit_by_name::<&str>("group-changed", &[&new_filter])
.unwrap();
.emit_by_name::<CustomFilter>("group-changed", &[&new_filter]);
});
}

View file

@ -3,7 +3,6 @@ use std::rc::Rc;
use crate::app_grid::AppGrid;
use crate::group_grid::GroupGrid;
use cascade::cascade;
use gdk4::Rectangle;
use gdk4_x11::X11Display;
use gdk4_x11::X11Surface;
use glib::Object;
@ -98,17 +97,15 @@ impl AppLibraryWindow {
let entry = &imp.entry.get().unwrap();
group_grid
.connect_local(
"group-changed",
false,
glib::clone!(@weak app_grid => @default-return None, move |args| {
let new_filter = args[1].get::<CustomFilter>().unwrap();
app_grid.set_group_filter(&new_filter);
None
}),
)
.unwrap();
group_grid.connect_local(
"group-changed",
false,
glib::clone!(@weak app_grid => @default-return None, move |args| {
let new_filter = args[1].get::<CustomFilter>().unwrap();
app_grid.set_group_filter(&new_filter);
None
}),
);
entry.connect_changed(
glib::clone!(@weak app_grid => move |search: &gtk4::SearchEntry| {
@ -170,20 +167,17 @@ impl AppLibraryWindow {
);
}
let resize = glib::clone!(@weak window, @strong x11rb_conn => move || {
let s = window.surface().expect("Failed to get Surface for AppLibraryWindow");
let s = window.surface();
let height = window.height();
let width = window.width();
if let Some((display, _surface)) = x::get_window_x11(&window) {
let monitor = display
.primary_monitor()
.expect("Failed to get Monitor");
let Rectangle {
x: monitor_x,
y: monitor_y,
width: monitor_width,
height: monitor_height,
} = monitor.geometry();
let geom = display
.primary_monitor().geometry();
let monitor_x = geom.x();
let monitor_y = geom.y();
let monitor_width = geom.width();
let monitor_height = geom.height();
// dbg!(monitor_width);
// dbg!(monitor_height);
// dbg!(width);
@ -205,9 +199,7 @@ impl AppLibraryWindow {
conn.flush().expect("failed to flush");
}
});
let s = window
.surface()
.expect("Failed to get Surface for AppLibraryWindow");
let s = window.surface();
let resize_height = resize.clone();
s.connect_height_notify(move |_s| {
glib::source::idle_add_local_once(resize_height.clone());

View file

@ -0,0 +1,28 @@
use gtk4::glib;
use gtk4::subclass::prelude::*;
use gtk4::SearchEntry;
use once_cell::sync::OnceCell;
use crate::app_grid::AppGrid;
use crate::group_grid::GroupGrid;
#[derive(Default)]
pub struct AppLibraryWindowInner {
pub entry: OnceCell<SearchEntry>,
pub app_grid: OnceCell<AppGrid>,
pub group_grid: OnceCell<GroupGrid>,
}
#[glib::object_subclass]
impl ObjectSubclass for AppLibraryWindowInner {
// `NAME` needs to match `class` attribute of template
const NAME: &'static str = "AppLibraryWindowInner";
type Type = super::AppLibraryWindowInner;
type ParentType = gtk4::Box;
}
impl ObjectImpl for AppLibraryWindowInner {}
impl WidgetImpl for AppLibraryWindowInner {}
impl BoxImpl for AppLibraryWindowInner {}

View file

@ -0,0 +1,130 @@
use cascade::cascade;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use gtk4::{gio, glib, Align, CustomFilter, Orientation, SearchEntry, Separator};
use crate::app_grid::AppGrid;
use crate::group_grid::GroupGrid;
mod imp;
glib::wrapper! {
pub struct AppLibraryWindowInner(ObjectSubclass<imp::AppLibraryWindowInner>)
@extends gtk4::Widget, gtk4::Box,
@implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget, gtk4::Orientable;
}
impl Default for AppLibraryWindowInner {
fn default() -> Self {
Self::new()
}
}
impl AppLibraryWindowInner {
pub fn new() -> Self {
let self_: Self = glib::Object::new(&[]).expect("Failed to create AppLibraryWindowInner");
let imp = imp::AppLibraryWindowInner::from_instance(&self_);
cascade! {
&self_;
..set_orientation(Orientation::Vertical);
..add_css_class("app_library_container");
};
let entry = cascade! {
SearchEntry::new();
..set_width_request(300);
..set_halign(Align::Center);
..set_margin_top(12);
..set_margin_bottom(12);
..set_placeholder_text(Some(" Type to search"));
};
self_.append(&entry);
let app_grid = AppGrid::new();
self_.append(&app_grid);
let separator = cascade! {
Separator::new(Orientation::Horizontal);
..set_hexpand(true);
..set_margin_bottom(12);
..set_margin_top(12);
};
self_.append(&separator);
let group_grid = GroupGrid::new();
self_.append(&group_grid);
imp.entry.set(entry).unwrap();
imp.app_grid.set(app_grid).unwrap();
imp.group_grid.set(group_grid).unwrap();
Self::setup_callbacks(&self_);
self_
}
pub fn group_grid(&self) -> Option<&GroupGrid> {
let imp = imp::AppLibraryWindowInner::from_instance(self);
imp.group_grid.get()
}
fn setup_callbacks(&self) {
// Get state
let imp = imp::AppLibraryWindowInner::from_instance(self);
let app_grid = &imp.app_grid.get().unwrap();
let group_grid = &imp.group_grid.get().unwrap();
let entry = &imp.entry.get().unwrap();
group_grid
.connect_local(
"group-changed",
false,
glib::clone!(@weak app_grid => @default-return None, move |args| {
let new_filter = args[1].get::<CustomFilter>().unwrap();
app_grid.set_group_filter(&new_filter);
None
}),
)
.unwrap();
entry.connect_changed(
glib::clone!(@weak app_grid => move |search: &gtk4::SearchEntry| {
let search_text = search.text().to_string().to_lowercase();
let new_filter: gtk4::CustomFilter = gtk4::CustomFilter::new(move |obj| {
let search_res = obj.downcast_ref::<gio::DesktopAppInfo>()
.expect("The Object needs to be of type AppInfo");
search_res.name().to_string().to_lowercase().contains(&search_text)
});
let search_text = search.text().to_string().to_lowercase();
let new_sorter: gtk4::CustomSorter = gtk4::CustomSorter::new(move |obj1, obj2| {
let app_info1 = obj1.downcast_ref::<gio::DesktopAppInfo>().unwrap();
let app_info2 = obj2.downcast_ref::<gio::DesktopAppInfo>().unwrap();
if search_text == "" {
return app_info1
.name()
.to_lowercase()
.cmp(&app_info2.name().to_lowercase())
.into();
}
let i_1 = app_info1.name().to_lowercase().find(&search_text);
let i_2 = app_info2.name().to_lowercase().find(&search_text);
match (i_1, i_2) {
(Some(i_1), Some(i_2)) => i_1.cmp(&i_2).into(),
(Some(_), None) => std::cmp::Ordering::Less.into(),
(None, Some(_)) => std::cmp::Ordering::Greater.into(),
_ => app_info1
.name()
.to_lowercase()
.cmp(&app_info2.name().to_lowercase())
.into()
}
});
app_grid.set_search_filter(&new_filter);
app_grid.set_app_sorter(&new_sorter);
}),
);
}
}

View file

@ -58,26 +58,22 @@ impl DockItem {
item_box.append(&popover);
let self_clone = self_.clone();
popover.connect_closed(move |_| {
self_clone
.emit_by_name::<&str>("popover-closed", &[])
.unwrap();
let _ = self_clone.emit_by_name::<()>("popover-closed", &[]);
});
let popover_menu = cascade! {
DockPopover::new();
};
popover.set_child(Some(&popover_menu));
popover_menu
.connect_local(
"menu-hide",
false,
glib::clone!(@weak popover, @weak popover_menu => @default-return None, move |_| {
popover.popdown();
popover_menu.reset_menu();
None
}),
)
.unwrap();
popover_menu.connect_local(
"menu-hide",
false,
glib::clone!(@weak popover, @weak popover_menu => @default-return None, move |_| {
popover.popdown();
popover_menu.reset_menu();
None
}),
);
let imp = imp::DockItem::from_instance(&self_);
imp.image.replace(Some(image));
@ -105,25 +101,20 @@ impl DockItem {
self_.item_box.borrow().prepend(&image);
self_.image.replace(Some(image));
}
if let Ok(active_value) = dock_object.property("active") {
if let Ok(active) = active_value.get::<BoxedWindowList>() {
let dots = self_.dots.borrow();
dots.set_text("");
for _ in active.0 {
dots.set_text(format!("{}{}", dots.text(), " · ").as_str());
}
}
let active = dock_object.property::<BoxedWindowList>("active");
let dots = self_.dots.borrow();
dots.set_text("");
for _ in active.0 {
dots.set_text(format!("{}{}", dots.text(), " · ").as_str());
}
if let Ok(popover_value) = dock_object.property("popover") {
if let Ok(popover) = popover_value.get::<bool>() {
// dbg!(popover);
// dbg!(dock_object);
if popover {
self.add_popover(dock_object);
} else {
self.clear_popover();
}
}
let popover = dock_object.property::<bool>("popover");
// dbg!(popover);
// dbg!(dock_object);
if popover {
self.add_popover(dock_object);
} else {
self.clear_popover();
}
}

View file

@ -15,6 +15,7 @@ use gio::DesktopAppInfo;
use gio::Icon;
use glib::Object;
use glib::Type;
use gtk4::glib;
use gtk4::prelude::ListModelExt;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
@ -24,7 +25,6 @@ use gtk4::ListView;
use gtk4::Orientation;
use gtk4::SignalListItemFactory;
use gtk4::Window;
use gtk4::{gio, glib};
use gtk4::{DragSource, GestureClick};
use std::ffi::CStr;
use std::fs::File;
@ -236,11 +236,7 @@ impl DockList {
.downcast_ref::<DockObject>()
.expect("The object needs to be of type `AppGroupData`.");
// Add todo data to vector and increase position
if let Ok(Some(app_info)) = dock_object
.property("appinfo")
.expect("DockObject must have appinfo property")
.get::<Option<DesktopAppInfo>>()
{
if let Some(app_info) = dock_object.property::<Option<DesktopAppInfo>>("appinfo") {
if let Some(f) = app_info.filename() {
backup_data.push(f);
}
@ -347,8 +343,8 @@ impl DockList {
if let Some(item) = model.item(index) {
if let Ok(dock_object) = item.downcast::<DockObject>() {
let active = dock_object.property("active").expect("DockObject must have active property").get::<BoxedWindowList>().expect("Failed to convert value to WindowList");
let app_info = dock_object.property("appinfo").expect("DockObject must have appinfo property").get::<Option<DesktopAppInfo>>().expect("Failed to convert value to DesktopAppInfo");
let active = dock_object.property::<BoxedWindowList>("active");
let app_info = dock_object.property::<Option<DesktopAppInfo>>("appinfo");
match (self_.current_button(), click_modifier, active.0.iter().next(), app_info) {
(click, Some(click_modifier), Some(first_focused_item), _) if click == 1 && !click_modifier.contains(ModifierType::CONTROL_MASK) => focus_window(first_focused_item),
(click, None, Some(first_focused_item), _) if click == 1 => focus_window(first_focused_item),
@ -399,9 +395,7 @@ impl DockList {
let mut drop_actions = gdk4::DragAction::COPY;
drop_actions.insert(gdk4::DragAction::MOVE);
let drop_format = gdk4::ContentFormats::for_type(Type::STRING);
let drop_format = drop_format
.union(&gdk4::ContentFormats::for_type(Type::U32))
.expect("couldn't make union");
let drop_format = drop_format.union(&gdk4::ContentFormats::for_type(Type::U32));
let drop_controller = DropTarget::builder()
.preload(true)
.actions(drop_actions)
@ -437,7 +431,7 @@ impl DockList {
let mut index_of_existing_app: Option<u32> = None;
while let Some(item) = model.item(i) {
if let Ok(cur_app_info) = item.downcast::<DockObject>() {
if let Ok(Some(cur_app_info)) = cur_app_info.property("appinfo").expect("property appinfo missing from DockObject").get::<Option<DesktopAppInfo>>() {
if let Some(cur_app_info) = cur_app_info.property::<Option<DesktopAppInfo>>("appinfo") {
if cur_app_info.filename() == Some(Path::new(&path_str).to_path_buf()) {
index_of_existing_app = Some(i);
}
@ -544,23 +538,21 @@ impl DockList {
}
}
if let Ok(dock_object) = item.downcast::<DockObject>() {
if let Ok(Some(app_info)) = dock_object.property("appinfo").expect("property appinfo missing from DockObject").get::<Option<DesktopAppInfo>>() {
if let Some(app_info) = dock_object.property::<Option<DesktopAppInfo>>("appinfo") {
let icon = app_info
.icon()
.unwrap_or(Icon::for_string("image-missing").expect("Failed to set default icon"));
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(),
) {
self_.set_icon(Some(&paintable_icon), 32, 32);
}
}
let icon_theme = IconTheme::for_display(default_display);
let paintable_icon = icon_theme.lookup_by_gicon(
&icon,
64,
1,
gtk4::TextDirection::None,
gtk4::IconLookupFlags::empty(),
);
self_.set_icon(Some(&paintable_icon), 32, 32);
}
// saved app list provides index
@ -612,8 +604,7 @@ impl DockList {
}
None
})
.unwrap();
});
list_item.set_child(Some(&dock_item));
}),
);

View file

@ -1,6 +1,9 @@
use std::cell::Cell;
use std::cell::RefCell;
use gdk4::glib::ParamSpecBoolean;
use gdk4::glib::ParamSpecBoxed;
use gdk4::glib::ParamSpecObject;
use gio::DesktopAppInfo;
use glib::{ParamFlags, ParamSpec, Value};
use gtk4::glib;
@ -34,7 +37,7 @@ impl ObjectImpl for DockObject {
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
vec![
ParamSpec::new_object(
ParamSpecObject::new(
// Name
"appinfo",
// Nickname
@ -45,7 +48,7 @@ impl ObjectImpl for DockObject {
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpec::new_boxed(
ParamSpecBoxed::new(
// Name
"active",
// Nickname
@ -56,14 +59,14 @@ impl ObjectImpl for DockObject {
// The property can be read and written to
ParamFlags::READWRITE,
),
ParamSpec::new_boolean(
ParamSpecBoolean::new(
"saved",
"saved",
"Indicates whether app is saved to the dock",
false,
ParamFlags::READWRITE,
),
ParamSpec::new_boolean(
ParamSpecBoolean::new(
"popover",
"popover",
"Indicates whether there is a popover menu displayed for this object",

View file

@ -62,48 +62,43 @@ impl DockPopover {
Box::new(Orientation::Vertical, 4);
};
menu_handle.append(&all_windows_item_container);
if let Ok(window_list) = dock_object
.property("active")
.unwrap()
.get::<BoxedWindowList>()
{
if window_list.0.len() == 0 {
all_windows_item_container.hide();
} else {
let window_listbox = cascade! {
ListBox::new();
..set_activate_on_single_click(true);
let window_list = dock_object.property::<BoxedWindowList>("active");
if window_list.0.len() == 0 {
all_windows_item_container.hide();
} else {
let window_listbox = cascade! {
ListBox::new();
..set_activate_on_single_click(true);
};
all_windows_item_container.append(&window_listbox);
for w in window_list.0 {
let window_box = cascade! {
Box::new(Orientation::Vertical, 4);
};
all_windows_item_container.append(&window_listbox);
for w in window_list.0 {
let window_box = cascade! {
Box::new(Orientation::Vertical, 4);
};
window_listbox.append(&window_box);
window_listbox.append(&window_box);
let window_title = cascade! {
Label::new(Some(w.name.as_str()));
..set_margin_start(4);
..set_margin_end(4);
..set_margin_top(4);
..set_margin_bottom(4);
..set_wrap(true);
..set_max_width_chars(20);
..set_ellipsize(EllipsizeMode::End);
..add_css_class("title-4");
..add_css_class("window_title");
};
let window_title = cascade! {
Label::new(Some(w.name.as_str()));
..set_margin_start(4);
..set_margin_end(4);
..set_margin_top(4);
..set_margin_bottom(4);
..set_wrap(true);
..set_max_width_chars(20);
..set_ellipsize(EllipsizeMode::End);
..add_css_class("title-4");
..add_css_class("window_title");
};
let window_image = cascade! {
//TODO fill with image of window
Image::from_pixbuf(None);
};
window_box.append(&window_image);
window_box.append(&window_title);
}
// imp.all_windows_item_revealer.replace(window_list_revealer);
imp.window_list.replace(window_listbox);
let window_image = cascade! {
//TODO fill with image of window
Image::from_pixbuf(None);
};
window_box.append(&window_image);
window_box.append(&window_title);
}
// imp.all_windows_item_revealer.replace(window_list_revealer);
imp.window_list.replace(window_listbox);
}
let launch_item_container = cascade! {
@ -119,33 +114,30 @@ impl DockPopover {
imp.launch_new_item.replace(launch_new_item);
let favorite_item = cascade! {
Button::with_label(if dock_object.property("saved").unwrap().get::<bool>().unwrap() {"Remove from Favorites"} else {"Add to Favorites"});
Button::with_label(if dock_object.property::<bool>("saved") {"Remove from Favorites"} else {"Add to Favorites"});
};
menu_handle.append(&favorite_item);
imp.favorite_item.replace(favorite_item);
if let Ok(window_list) = dock_object
.property("active")
.unwrap()
.get::<BoxedWindowList>()
{
if window_list.0.len() > 1 {
let quit_all_item = cascade! {
Button::with_label(format!("Quit {} Windows", window_list.0.len()).as_str());
};
menu_handle.append(&quit_all_item);
imp.quit_all_item.replace(quit_all_item);
} else {
let quit_all_item = cascade! {
Button::with_label("Quit");
};
menu_handle.append(&quit_all_item);
if window_list.0.len() == 0 {
quit_all_item.hide();
}
imp.quit_all_item.replace(quit_all_item);
let window_list = dock_object.property::<BoxedWindowList>("active");
if window_list.0.len() > 1 {
let quit_all_item = cascade! {
Button::with_label(format!("Quit {} Windows", window_list.0.len()).as_str());
};
menu_handle.append(&quit_all_item);
imp.quit_all_item.replace(quit_all_item);
} else {
let quit_all_item = cascade! {
Button::with_label("Quit");
};
menu_handle.append(&quit_all_item);
if window_list.0.len() == 0 {
quit_all_item.hide();
}
imp.quit_all_item.replace(quit_all_item);
}
self.setup_handlers();
}
}
@ -161,7 +153,7 @@ impl DockPopover {
}
fn emit_hide(&self) {
self.emit_by_name::<&str>("menu-hide", &[]).unwrap();
self.emit_by_name::<()>("menu-hide", &[]);
}
pub fn reset_menu(&self) {
@ -190,7 +182,7 @@ impl DockPopover {
// println!("setting up popover menu handlers");
let self_ = self.clone();
launch_new_item.connect_clicked(glib::clone!(@weak dock_object, => move |_| {
let app_info = dock_object.property("appinfo").expect("DockObject must have appinfo property").get::<Option<DesktopAppInfo>>().expect("Failed to convert value to DesktopAppInfo").unwrap();
let app_info = dock_object.property::<Option<DesktopAppInfo>>("appinfo").expect("Failed to convert value to DesktopAppInfo");
let window = self_.root().unwrap().downcast::<Window>().unwrap();
let context = window.display().app_launch_context();
@ -209,7 +201,7 @@ impl DockPopover {
let self_ = self.clone();
quit_all_item.connect_clicked(glib::clone!(@weak dock_object => move |_| {
let active = dock_object.property("active").expect("DockObject must have active property").get::<BoxedWindowList>().expect("Failed to convert value to WindowList").0;
let active = dock_object.property::<BoxedWindowList>("active").0;
for w in active {
let entity = w.entity.clone();
glib::MainContext::default().spawn_local(async move {
@ -223,7 +215,7 @@ impl DockPopover {
let self_ = self.clone();
favorite_item.connect_clicked(glib::clone!(@weak dock_object => move |_| {
let saved = dock_object.property("saved").expect("DockObject must have saved property").get::<bool>().expect("Failed to convert value to bool");
let saved = dock_object.property::<bool>("saved");
glib::MainContext::default().spawn_local(async move {
if let Some(tx) = TX.get() {
@ -244,16 +236,18 @@ impl DockPopover {
// );
let self_ = self.clone();
window_listbox.connect_row_activated(glib::clone!(@weak dock_object => move |_, item| {
let active = dock_object.property("active").expect("DockObject must have active property").get::<BoxedWindowList>().expect("Failed to convert value to WindowList").0;
let entity = active[usize::try_from(item.index()).unwrap()].entity.clone();
glib::MainContext::default().spawn_local(async move {
if let Some(tx) = TX.get() {
let _ = tx.send(Event::Activate(entity)).await;
}
});
self_.emit_hide();
}));
window_listbox.connect_row_activated(
glib::clone!(@weak dock_object => move |_, item| {
let active = dock_object.property::<BoxedWindowList>("active").0;
let entity = active[usize::try_from(item.index()).unwrap()].entity.clone();
glib::MainContext::default().spawn_local(async move {
if let Some(tx) = TX.get() {
let _ = tx.send(Event::Activate(entity)).await;
}
});
self_.emit_hide();
}),
);
}
}
}

View file

@ -6,7 +6,6 @@ use crate::dock_list::DockListType;
use crate::utils::{block_on, BoxedWindowList};
use gdk4::Display;
use gio::DesktopAppInfo;
use gtk4::gio;
use gtk4::glib;
use gtk4::prelude::*;
use gtk4::Application;
@ -61,7 +60,7 @@ fn spawn_zbus(tx: mpsc::Sender<Event>) -> Connection {
let sender = tx.clone();
let conn = connection.clone();
let _ = std::thread::spawn(|| {
let _ = std::thread::spawn(move || {
let cached_results: Vec<Item> = vec![];
block_on(async move {
futures::pin_mut!(cached_results);
@ -229,10 +228,8 @@ fn main() {
let mut saved_i: u32 = 0;
while let Some(item) = saved_app_model.item(saved_i) {
if let Ok(dock_obj) = item.downcast::<DockObject>() {
if let Ok(Some(cur_app_info)) = dock_obj
.property("appinfo")
.expect("property appinfo missing from DockObject")
.get::<Option<DesktopAppInfo>>()
if let Some(cur_app_info) =
dock_obj.property::<Option<DesktopAppInfo>>("appinfo")
{
if let Some((i, _s)) = stack_active
.iter()
@ -244,9 +241,7 @@ fn main() {
// _s.0[0].name, i
// );
let active = stack_active.remove(i);
dock_obj
.set_property("active", active.to_value())
.expect("failed to update dock active apps");
dock_obj.set_property("active", active.to_value());
saved_app_model.items_changed(
saved_i.try_into().unwrap(),
0,
@ -256,12 +251,10 @@ fn main() {
.iter()
.find(|s| s.description == cur_app_info.name())
{
dock_obj
.set_property(
"active",
BoxedWindowList(Vec::new()).to_value(),
)
.expect("failed to update dock active apps");
dock_obj.set_property(
"active",
BoxedWindowList(Vec::new()).to_value(),
);
saved_app_model.items_changed(
saved_i.try_into().unwrap(),
0,
@ -310,10 +303,8 @@ fn main() {
let mut saved_i: u32 = 0;
while let Some(item) = saved_app_model.item(saved_i) {
if let Ok(dock_obj) = item.downcast::<DockObject>() {
if let Ok(Some(cur_app_info)) = dock_obj
.property("appinfo")
.expect("property appinfo missing from DockObject")
.get::<Option<DesktopAppInfo>>()
if let Some(cur_app_info) =
dock_obj.property::<Option<DesktopAppInfo>>("appinfo")
{
if let Some((i, _s)) = stack_active
.iter()
@ -322,9 +313,7 @@ fn main() {
{
// println!("found active saved app {} at {}", s.0[0].name, i);
let active = stack_active.remove(i);
dock_obj
.set_property("active", active.to_value())
.expect("failed to update dock active apps");
dock_obj.set_property("active", active.to_value());
saved_app_model.items_changed(
saved_i.try_into().unwrap(),
0,
@ -334,12 +323,10 @@ fn main() {
.iter()
.find(|s| s.description == cur_app_info.name())
{
dock_obj
.set_property(
"active",
BoxedWindowList(Vec::new()).to_value(),
)
.expect("failed to update dock active apps");
dock_obj.set_property(
"active",
BoxedWindowList(Vec::new()).to_value(),
);
saved_app_model.items_changed(
saved_i.try_into().unwrap(),
0,
@ -362,7 +349,7 @@ fn main() {
}
}
}
})
});
});
app.run();

View file

@ -1,7 +1,7 @@
use gtk4::glib;
#[derive(Clone, Debug, Default, gtk4::glib::GBoxed)]
#[gboxed(type_name = "BoxedDockPlugin")]
#[derive(Clone, Debug, Default, gtk4::glib::Boxed)]
#[boxed_type(name = "BoxedDockPlugin")]
pub struct BoxedDockPlugin {
pub path: String,
pub name: String,

View file

@ -6,12 +6,12 @@ use std::future::Future;
use crate::DockObject;
use crate::Item;
#[derive(Clone, Debug, Default, glib::GBoxed)]
#[gboxed(type_name = "BoxedWindowList")]
#[derive(Clone, Debug, Default, glib::Boxed)]
#[boxed_type(name = "BoxedWindowList")]
pub struct BoxedWindowList(pub Vec<Item>);
#[derive(Clone, Debug, Default, glib::GBoxed)]
#[gboxed(type_name = "BoxedDockObject")]
#[derive(Clone, Debug, Default, glib::Boxed)]
#[boxed_type(name = "BoxedDockObject")]
pub struct BoxedDockObject(pub Option<DockObject>);
pub fn data_path() -> PathBuf {
@ -25,7 +25,6 @@ pub fn data_path() -> PathBuf {
pub fn thread_context() -> glib::MainContext {
glib::MainContext::thread_default().unwrap_or_else(|| {
let ctx = glib::MainContext::new();
ctx.push_thread_default();
ctx
})
}
@ -34,5 +33,6 @@ pub fn block_on<F>(future: F) -> F::Output
where
F: Future,
{
thread_context().block_on(future)
let ctx = thread_context();
ctx.with_thread_default(|| ctx.block_on(future)).unwrap()
}

View file

@ -1,5 +1,4 @@
use cascade::cascade;
use gdk4::Rectangle;
use gdk4_x11::X11Display;
use gdk4_x11::X11Surface;
use glib::Object;
@ -140,20 +139,17 @@ impl Window {
);
}
let resize = glib::clone!(@weak window, @weak revealer => move || {
let s = window.surface().expect("Failed to get Surface for Window");
let s = window.surface();
let height = if revealer.reveals_child() { window.height() } else { 4 };
let width = window.width();
if let Some((display, _surface)) = x::get_window_x11(&window) {
let monitor = display
.primary_monitor()
.expect("Failed to get Monitor");
let Rectangle {
x: monitor_x,
y: monitor_y,
width: monitor_width,
height: monitor_height,
} = monitor.geometry();
let geom = display
.primary_monitor().geometry();
let monitor_x = geom.x();
let monitor_y = geom.y();
let monitor_width = geom.width();
let monitor_height = geom.height();
// dbg!(monitor_x);
// dbg!(monitor_y);
// dbg!(monitor_width);
@ -201,7 +197,7 @@ impl Window {
}
}));
let s = window.surface().expect("Failed to get Surface for Window");
let s = window.surface();
let resize_height = resize.clone();
s.connect_height_notify(move |_s| {
glib::source::idle_add_local_once(resize_height.clone());
@ -260,9 +256,7 @@ impl Window {
let mut drop_actions = gdk4::DragAction::COPY;
drop_actions.insert(gdk4::DragAction::MOVE);
let drop_format = gdk4::ContentFormats::for_type(Type::STRING);
let drop_format = drop_format
.union(&gdk4::ContentFormats::for_type(Type::U32))
.expect("couldn't make union");
let drop_format = drop_format.union(&gdk4::ContentFormats::for_type(Type::U32));
let window_drop_target_controller = DropTarget::builder()
.actions(drop_actions)

View file

@ -130,7 +130,7 @@ fn main() {
}
}
}
})
});
});
app.run();

View file

@ -1,7 +1,7 @@
use std::cell::RefCell;
use std::rc::Rc;
use glib::{ParamFlags, ParamSpec, Value};
use glib::{ParamFlags, ParamSpec, ParamSpecBoxed, Value};
use gtk4::glib;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
@ -27,7 +27,7 @@ impl ObjectSubclass for SearchResultObject {
impl ObjectImpl for SearchResultObject {
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
vec![ParamSpec::new_boxed(
vec![ParamSpecBoxed::new(
// Name
"data",
// Nickname

View file

@ -14,11 +14,7 @@ impl SearchResultObject {
}
pub fn data(&self) -> Option<pop_launcher::SearchResult> {
if let Ok(data) = self.property("data") {
if let Ok(search_result) = data.get::<BoxedSearchResult>() {
return search_result.0;
}
}
None
let search_result = self.property::<BoxedSearchResult>("data");
return search_result.0;
}
}

View file

@ -102,18 +102,15 @@ impl SearchResultRow {
pub fn set_search_result(&self, search_obj: SearchResultObject) {
let self_ = imp::SearchResultRow::from_instance(self);
if let Ok(search_result) = search_obj.property("data") {
if let Ok(search_result) = search_result.get::<BoxedSearchResult>() {
if let Some(search_result) = search_result.0 {
self_.name.borrow().set_text(&search_result.name);
self_
.description
.borrow()
.set_text(&search_result.description);
icon_source(&self_.image, &search_result.icon);
icon_source(&self_.category_image, &search_result.category_icon);
}
}
let search_result = search_obj.property::<BoxedSearchResult>("data");
if let Some(search_result) = search_result.0 {
self_.name.borrow().set_text(&search_result.name);
self_
.description
.borrow()
.set_text(&search_result.description);
icon_source(&self_.image, &search_result.icon);
icon_source(&self_.category_image, &search_result.category_icon);
}
}

View file

@ -2,8 +2,8 @@ use gtk4::glib;
use std::cell::RefCell;
use std::rc::Rc;
#[derive(Clone, Debug, Default, glib::GBoxed)]
#[gboxed(type_name = "BoxedSearchResult")]
#[derive(Clone, Debug, Default, glib::Boxed)]
#[boxed_type(name = "BoxedSearchResult")]
pub struct BoxedSearchResult(pub Option<pop_launcher::SearchResult>);
pub fn icon_source(icon: &Rc<RefCell<gtk4::Image>>, source: &Option<pop_launcher::IconSource>) {

View file

@ -198,20 +198,17 @@ impl Window {
);
}
let resize = glib::clone!(@weak window => move || {
let s = window.surface().expect("Failed to get Surface for Window");
let s = window.surface();
let height = window.height();
let width = window.width();
if let Some((display, _surface)) = x::get_window_x11(&window) {
let monitor = display
.primary_monitor()
.expect("Failed to get Monitor");
let Rectangle {
x: monitor_x,
y: monitor_y,
width: monitor_width,
height: monitor_height,
} = monitor.geometry();
let geom = display
.primary_monitor().geometry();
let monitor_x = geom.x();
let monitor_y = geom.y();
let monitor_width = geom.width();
let monitor_height = geom.height();
// dbg!(monitor_width);
// dbg!(monitor_height);
// dbg!(width);
@ -233,7 +230,7 @@ impl Window {
conn.flush().expect("failed to flush");
}
});
let s = window.surface().expect("Failed to get Surface for Window");
let s = window.surface();
let resize_height = resize.clone();
s.connect_height_notify(move |_s| {
glib::source::idle_add_local_once(resize_height.clone());

View file

@ -16,10 +16,10 @@ pub fn get_window_x11<T: IsA<gtk4::Window>>(
) -> Option<(gdk4_x11::X11Display, gdk4_x11::X11Surface)> {
let surface = window
.upcast_ref()
.surface()?
.surface()
.downcast::<gdk4_x11::X11Surface>()
.ok()?;
let display = surface.display()?.downcast::<gdk4_x11::X11Display>().ok()?;
let display = surface.display().downcast::<gdk4_x11::X11Display>().ok()?;
Some((display, surface))
}