cargo: Update gtk-rs stack

This commit is contained in:
Sophie Herold 2024-02-05 16:27:05 +01:00
parent a7116925bf
commit 0ed7036098
11 changed files with 230 additions and 199 deletions

View file

@ -27,7 +27,7 @@ use crate::deps::*;
mod imp {
use adw::subclass::prelude::*;
use glib::{ParamSpec, Properties, Value};
use once_cell::sync::OnceCell;
use std::cell::OnceCell;
use super::*;

View file

@ -296,7 +296,7 @@ mod imp {
);
obj.connect_realize(glib::clone!(@weak surface_signals => move |obj| {
surface_signals.set_target(obj.native().map(|x| x.surface()).as_ref());
surface_signals.set_target(obj.native().and_then(|x| x.surface()).as_ref());
}));
obj.connect_unrealize(glib::clone!(@weak surface_signals => move |_| {

View file

@ -85,10 +85,7 @@ impl imp::LpImage {
let node = snapshot.to_node()?;
let renderer = obj.root()?.renderer();
if !renderer.is_realized() {
return None;
}
let renderer = obj.root()?.renderer()?;
// Render the small version of the image and download to RAM
let texture = renderer.render_texture(node, None);

View file

@ -82,7 +82,7 @@ impl imp::LpImage {
(f64::exp(-y * f64::ln(ZOOM_FACTOR_SCROLL_SURFACE)), false)
}
unknown_unit => {
log::warn!("Ignoring unknown scroll unit: {unknown_unit}");
log::warn!("Ignoring unknown scroll unit: {unknown_unit:?}");
(1., false)
}
};

View file

@ -42,7 +42,7 @@ impl LpImage {
.add_to_snapshot(&snapshot, scale, &render_options);
let node = snapshot.to_node()?;
let renderer = self.root()?.renderer();
let renderer = self.root()?.renderer()?;
Some(renderer.render_texture(&node, None))
}

View file

@ -299,13 +299,10 @@ impl imp::LpImage {
let obj = self.obj();
// TODO: This avoids panics and should be fixed upstream
if obj.is_realized() {
obj.native()
.map(|x| x.surface().scale())
.unwrap_or_else(|| obj.scale_factor() as f64)
} else {
1.
}
obj.native()
.and_then(|x| x.surface())
.map(|x| x.scale())
.unwrap_or_else(|| obj.scale_factor() as f64)
}
/// Monitor size in physical pixels
@ -313,8 +310,8 @@ impl imp::LpImage {
let obj = self.obj();
if let Some(display) = gdk::Display::default() {
if let Some(native) = obj.native() {
if let Some(monitor) = display.monitor_at_surface(&native.surface()) {
if let Some(surface) = obj.native().and_then(|x| x.surface()) {
if let Some(monitor) = display.monitor_at_surface(&surface) {
let hidpi_scale = self.scaling();
let monitor_geometry = monitor.geometry();
let monitor_size = (

View file

@ -140,4 +140,12 @@ impl LpImage {
pub fn is_vscrollable(&self) -> bool {
self.imp().max_vadjustment_value() != 0.
}
pub fn hadjustment(&self) -> gtk::Adjustment {
todo!()
}
pub fn vadjustment(&self) -> gtk::Adjustment {
todo!()
}
}

View file

@ -18,14 +18,13 @@
//! The print layout widget that also coordinates the print process
use std::cell::{Cell, RefCell};
use std::cell::{Cell, OnceCell, RefCell};
use std::rc::Rc;
use adw::prelude::*;
use adw::subclass::prelude::*;
use glib::Properties;
use gtk::CompositeTemplate;
use once_cell::sync::OnceCell;
use crate::decoder::{self};
use crate::deps::*;

View file

@ -52,6 +52,8 @@ const HIDE_CONTROLS_ANIMATION_DURATION: u32 = 1000;
const HIDE_CONTROLS_IDLE_TIMEOUT: u64 = 3000;
mod imp {
use gio::glib::VariantTy;
use super::*;
// To use composite templates, you need
@ -125,20 +127,15 @@ mod imp {
// CompositeTemplate macro to bind all children at once.
Self::bind_template(klass);
klass.add_binding(
gdk::Key::c,
gdk::ModifierType::CONTROL_MASK,
|window, _| {
if window.has_metadata_selected() {
// Pass on to normal copy handler to copy selected metadata
false
} else {
window.copy_image();
true
}
},
None,
);
klass.add_binding(gdk::Key::c, gdk::ModifierType::CONTROL_MASK, |window| {
if window.has_metadata_selected() {
// Pass on to normal copy handler to copy selected metadata
glib::Propagation::Proceed
} else {
window.copy_image();
glib::Propagation::Stop
}
});
// Set up actions
klass.install_action("win.toggle-fullscreen", None, move |win, _, _| {
@ -209,9 +206,13 @@ mod imp {
win.zoom_in_center();
});
klass.install_action("win.zoom-to-exact", Some("d"), move |win, _, level| {
win.zoom_to_exact(level.unwrap().get().unwrap());
});
klass.install_action(
"win.zoom-to-exact",
Some(&VariantTy::new("d").unwrap()),
move |win, _, level| {
win.zoom_to_exact(level.unwrap().get().unwrap());
},
);
klass.install_action("win.zoom-best-fit", None, move |win, _, _| {
win.zoom_best_fit();
@ -275,11 +276,15 @@ mod imp {
win.trash().await;
});
klass.install_action("win.show-toast", Some("(si)"), move |win, _, var| {
if let Some((ref toast, i)) = var.and_then(|v| v.get::<(String, i32)>()) {
win.show_toast(toast, adw::ToastPriority::__Unknown(i));
}
});
klass.install_action(
"win.show-toast",
Some(VariantTy::new("(si)").unwrap()),
move |win, _, var| {
if let Some((ref toast, i)) = var.and_then(|v| v.get::<(String, i32)>()) {
win.show_toast(toast, adw::ToastPriority::__Unknown(i));
}
},
);
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {