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

View file

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

View file

@ -21,10 +21,7 @@ impl AppGroup {
("category", &data.category), ("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()) { self_.set_property("appnames", data.app_names.to_variant());
println!("failed to set category icon property");
dbg!(e);
};
self_ self_
} }

View file

@ -94,37 +94,29 @@ impl GridItem {
// set drag source icon if possible... // set drag source icon if possible...
// gio Icon is not easily converted to a Paintable, but this seems to be the correct method // 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(default_display) = &Display::default() {
if let Some(icon_theme) = IconTheme::for_display(default_display) { let icon_theme = IconTheme::for_display(default_display);
if let Some(paintable_icon) = icon_theme.lookup_by_gicon( let paintable_icon = icon_theme.lookup_by_gicon(
&icon, &icon,
64, 64,
1, 1,
gtk4::TextDirection::None, gtk4::TextDirection::None,
gtk4::IconLookupFlags::empty(), gtk4::IconLookupFlags::empty(),
) { );
_self.set_icon(Some(&paintable_icon), 32, 32); _self.set_icon(Some(&paintable_icon), 32, 32);
}
}
} }
})); }));
} }
pub fn set_group_info(&self, app_group: AppGroup) { pub fn set_group_info(&self, app_group: AppGroup) {
let self_ = imp::GridItem::from_instance(self); let self_ = imp::GridItem::from_instance(self);
if let Ok(name) = app_group.property("name") { self_
self_.name.borrow().set_text( .name
&name .borrow()
.get::<String>() .set_text(&app_group.property::<String>("name"));
.expect("property name needs to be a string."), self_
); .image
} .borrow()
if let Ok(icon) = app_group.property("icon") { .set_from_icon_name(Some(&app_group.property::<String>("icon")));
self_.image.borrow().set_from_icon_name(Some(
&icon
.get::<String>()
.expect("Property name needs to be a String."),
));
}
} }
pub fn set_index(&self, index: u32) { pub fn set_index(&self, index: u32) {

View file

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

View file

@ -3,7 +3,6 @@ use std::rc::Rc;
use crate::app_grid::AppGrid; use crate::app_grid::AppGrid;
use crate::group_grid::GroupGrid; use crate::group_grid::GroupGrid;
use cascade::cascade; use cascade::cascade;
use gdk4::Rectangle;
use gdk4_x11::X11Display; use gdk4_x11::X11Display;
use gdk4_x11::X11Surface; use gdk4_x11::X11Surface;
use glib::Object; use glib::Object;
@ -98,17 +97,15 @@ impl AppLibraryWindow {
let entry = &imp.entry.get().unwrap(); let entry = &imp.entry.get().unwrap();
group_grid group_grid.connect_local(
.connect_local( "group-changed",
"group-changed", false,
false, glib::clone!(@weak app_grid => @default-return None, move |args| {
glib::clone!(@weak app_grid => @default-return None, move |args| { let new_filter = args[1].get::<CustomFilter>().unwrap();
let new_filter = args[1].get::<CustomFilter>().unwrap(); app_grid.set_group_filter(&new_filter);
app_grid.set_group_filter(&new_filter); None
None }),
}), );
)
.unwrap();
entry.connect_changed( entry.connect_changed(
glib::clone!(@weak app_grid => move |search: &gtk4::SearchEntry| { 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 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 height = window.height();
let width = window.width(); let width = window.width();
if let Some((display, _surface)) = x::get_window_x11(&window) { if let Some((display, _surface)) = x::get_window_x11(&window) {
let monitor = display let geom = display
.primary_monitor() .primary_monitor().geometry();
.expect("Failed to get Monitor"); let monitor_x = geom.x();
let Rectangle { let monitor_y = geom.y();
x: monitor_x, let monitor_width = geom.width();
y: monitor_y, let monitor_height = geom.height();
width: monitor_width,
height: monitor_height,
} = monitor.geometry();
// dbg!(monitor_width); // dbg!(monitor_width);
// dbg!(monitor_height); // dbg!(monitor_height);
// dbg!(width); // dbg!(width);
@ -205,9 +199,7 @@ impl AppLibraryWindow {
conn.flush().expect("failed to flush"); conn.flush().expect("failed to flush");
} }
}); });
let s = window let s = window.surface();
.surface()
.expect("Failed to get Surface for AppLibraryWindow");
let resize_height = resize.clone(); let resize_height = resize.clone();
s.connect_height_notify(move |_s| { s.connect_height_notify(move |_s| {
glib::source::idle_add_local_once(resize_height.clone()); 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); item_box.append(&popover);
let self_clone = self_.clone(); let self_clone = self_.clone();
popover.connect_closed(move |_| { popover.connect_closed(move |_| {
self_clone let _ = self_clone.emit_by_name::<()>("popover-closed", &[]);
.emit_by_name::<&str>("popover-closed", &[])
.unwrap();
}); });
let popover_menu = cascade! { let popover_menu = cascade! {
DockPopover::new(); DockPopover::new();
}; };
popover.set_child(Some(&popover_menu)); popover.set_child(Some(&popover_menu));
popover_menu popover_menu.connect_local(
.connect_local( "menu-hide",
"menu-hide", false,
false, glib::clone!(@weak popover, @weak popover_menu => @default-return None, move |_| {
glib::clone!(@weak popover, @weak popover_menu => @default-return None, move |_| { popover.popdown();
popover.popdown(); popover_menu.reset_menu();
popover_menu.reset_menu(); None
None }),
}), );
)
.unwrap();
let imp = imp::DockItem::from_instance(&self_); let imp = imp::DockItem::from_instance(&self_);
imp.image.replace(Some(image)); imp.image.replace(Some(image));
@ -105,25 +101,20 @@ impl DockItem {
self_.item_box.borrow().prepend(&image); self_.item_box.borrow().prepend(&image);
self_.image.replace(Some(image)); self_.image.replace(Some(image));
} }
if let Ok(active_value) = dock_object.property("active") { let active = dock_object.property::<BoxedWindowList>("active");
if let Ok(active) = active_value.get::<BoxedWindowList>() { let dots = self_.dots.borrow();
let dots = self_.dots.borrow(); dots.set_text("");
dots.set_text(""); for _ in active.0 {
for _ in active.0 { dots.set_text(format!("{}{}", dots.text(), " · ").as_str());
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>() { let popover = dock_object.property::<bool>("popover");
// dbg!(popover); // dbg!(popover);
// dbg!(dock_object); // dbg!(dock_object);
if popover { if popover {
self.add_popover(dock_object); self.add_popover(dock_object);
} else { } else {
self.clear_popover(); self.clear_popover();
}
}
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -6,12 +6,12 @@ use std::future::Future;
use crate::DockObject; use crate::DockObject;
use crate::Item; use crate::Item;
#[derive(Clone, Debug, Default, glib::GBoxed)] #[derive(Clone, Debug, Default, glib::Boxed)]
#[gboxed(type_name = "BoxedWindowList")] #[boxed_type(name = "BoxedWindowList")]
pub struct BoxedWindowList(pub Vec<Item>); pub struct BoxedWindowList(pub Vec<Item>);
#[derive(Clone, Debug, Default, glib::GBoxed)] #[derive(Clone, Debug, Default, glib::Boxed)]
#[gboxed(type_name = "BoxedDockObject")] #[boxed_type(name = "BoxedDockObject")]
pub struct BoxedDockObject(pub Option<DockObject>); pub struct BoxedDockObject(pub Option<DockObject>);
pub fn data_path() -> PathBuf { pub fn data_path() -> PathBuf {
@ -25,7 +25,6 @@ pub fn data_path() -> PathBuf {
pub fn thread_context() -> glib::MainContext { pub fn thread_context() -> glib::MainContext {
glib::MainContext::thread_default().unwrap_or_else(|| { glib::MainContext::thread_default().unwrap_or_else(|| {
let ctx = glib::MainContext::new(); let ctx = glib::MainContext::new();
ctx.push_thread_default();
ctx ctx
}) })
} }
@ -34,5 +33,6 @@ pub fn block_on<F>(future: F) -> F::Output
where where
F: Future, 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 cascade::cascade;
use gdk4::Rectangle;
use gdk4_x11::X11Display; use gdk4_x11::X11Display;
use gdk4_x11::X11Surface; use gdk4_x11::X11Surface;
use glib::Object; use glib::Object;
@ -140,20 +139,17 @@ impl Window {
); );
} }
let resize = glib::clone!(@weak window, @weak revealer => move || { 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 height = if revealer.reveals_child() { window.height() } else { 4 };
let width = window.width(); let width = window.width();
if let Some((display, _surface)) = x::get_window_x11(&window) { if let Some((display, _surface)) = x::get_window_x11(&window) {
let monitor = display let geom = display
.primary_monitor() .primary_monitor().geometry();
.expect("Failed to get Monitor"); let monitor_x = geom.x();
let Rectangle { let monitor_y = geom.y();
x: monitor_x, let monitor_width = geom.width();
y: monitor_y, let monitor_height = geom.height();
width: monitor_width,
height: monitor_height,
} = monitor.geometry();
// dbg!(monitor_x); // dbg!(monitor_x);
// dbg!(monitor_y); // dbg!(monitor_y);
// dbg!(monitor_width); // 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(); let resize_height = resize.clone();
s.connect_height_notify(move |_s| { s.connect_height_notify(move |_s| {
glib::source::idle_add_local_once(resize_height.clone()); glib::source::idle_add_local_once(resize_height.clone());
@ -260,9 +256,7 @@ impl Window {
let mut drop_actions = gdk4::DragAction::COPY; let mut drop_actions = gdk4::DragAction::COPY;
drop_actions.insert(gdk4::DragAction::MOVE); drop_actions.insert(gdk4::DragAction::MOVE);
let drop_format = gdk4::ContentFormats::for_type(Type::STRING); let drop_format = gdk4::ContentFormats::for_type(Type::STRING);
let drop_format = drop_format let drop_format = drop_format.union(&gdk4::ContentFormats::for_type(Type::U32));
.union(&gdk4::ContentFormats::for_type(Type::U32))
.expect("couldn't make union");
let window_drop_target_controller = DropTarget::builder() let window_drop_target_controller = DropTarget::builder()
.actions(drop_actions) .actions(drop_actions)

View file

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

View file

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

View file

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

View file

@ -102,18 +102,15 @@ impl SearchResultRow {
pub fn set_search_result(&self, search_obj: SearchResultObject) { pub fn set_search_result(&self, search_obj: SearchResultObject) {
let self_ = imp::SearchResultRow::from_instance(self); let self_ = imp::SearchResultRow::from_instance(self);
if let Ok(search_result) = search_obj.property("data") { let search_result = search_obj.property::<BoxedSearchResult>("data");
if let Ok(search_result) = search_result.get::<BoxedSearchResult>() { if let Some(search_result) = search_result.0 {
if let Some(search_result) = search_result.0 { self_.name.borrow().set_text(&search_result.name);
self_.name.borrow().set_text(&search_result.name); self_
self_ .description
.description .borrow()
.borrow() .set_text(&search_result.description);
.set_text(&search_result.description); icon_source(&self_.image, &search_result.icon);
icon_source(&self_.image, &search_result.icon); icon_source(&self_.category_image, &search_result.category_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::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
#[derive(Clone, Debug, Default, glib::GBoxed)] #[derive(Clone, Debug, Default, glib::Boxed)]
#[gboxed(type_name = "BoxedSearchResult")] #[boxed_type(name = "BoxedSearchResult")]
pub struct BoxedSearchResult(pub Option<pop_launcher::SearchResult>); pub struct BoxedSearchResult(pub Option<pop_launcher::SearchResult>);
pub fn icon_source(icon: &Rc<RefCell<gtk4::Image>>, source: &Option<pop_launcher::IconSource>) { 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 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 height = window.height();
let width = window.width(); let width = window.width();
if let Some((display, _surface)) = x::get_window_x11(&window) { if let Some((display, _surface)) = x::get_window_x11(&window) {
let monitor = display let geom = display
.primary_monitor() .primary_monitor().geometry();
.expect("Failed to get Monitor"); let monitor_x = geom.x();
let Rectangle { let monitor_y = geom.y();
x: monitor_x, let monitor_width = geom.width();
y: monitor_y, let monitor_height = geom.height();
width: monitor_width,
height: monitor_height,
} = monitor.geometry();
// dbg!(monitor_width); // dbg!(monitor_width);
// dbg!(monitor_height); // dbg!(monitor_height);
// dbg!(width); // dbg!(width);
@ -233,7 +230,7 @@ impl Window {
conn.flush().expect("failed to flush"); 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(); let resize_height = resize.clone();
s.connect_height_notify(move |_s| { s.connect_height_notify(move |_s| {
glib::source::idle_add_local_once(resize_height.clone()); 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)> { ) -> Option<(gdk4_x11::X11Display, gdk4_x11::X11Surface)> {
let surface = window let surface = window
.upcast_ref() .upcast_ref()
.surface()? .surface()
.downcast::<gdk4_x11::X11Surface>() .downcast::<gdk4_x11::X11Surface>()
.ok()?; .ok()?;
let display = surface.display()?.downcast::<gdk4_x11::X11Display>().ok()?; let display = surface.display().downcast::<gdk4_x11::X11Display>().ok()?;
Some((display, surface)) Some((display, surface))
} }