window: Remove default drop target style

The default does not fit well with our new custom one.

This also removes a bunch of code which was not used.

Part-of: <https://gitlab.gnome.org/GNOME/loupe/-/merge_requests/258>
This commit is contained in:
Sophie Herold 2023-07-15 20:43:01 +02:00
parent cf8fa499d9
commit 08a9c3e450
4 changed files with 24 additions and 29 deletions

View file

@ -169,12 +169,9 @@
<property name="reveal-flap" bind-source="properties_button" bind-property="active" bind-flags="bidirectional|sync-create"/> <property name="reveal-flap" bind-source="properties_button" bind-property="active" bind-flags="bidirectional|sync-create"/>
<property name="content"> <property name="content">
<object class="LpDragOverlay" id="drag_overlay"> <object class="LpDragOverlay" id="drag_overlay">
<property name="drop_target">drop_target</property>
<property name="overlayed"> <property name="overlayed">
<object class="AdwBin"> <object class="AdwBin">
<property name="margin-top">24</property>
<property name="margin-bottom">24</property>
<property name="margin-start">24</property>
<property name="margin-end">24</property>
<property name="can-target">false</property> <property name="can-target">false</property>
<style> <style>
<class name="lp-dragging-area-highlight"/> <class name="lp-dragging-area-highlight"/>
@ -185,6 +182,9 @@
<object class="GtkStack" id="stack"> <object class="GtkStack" id="stack">
<property name="visible-child">status_page</property> <property name="visible-child">status_page</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<style>
<class name="drop-widget" />
</style>
<child> <child>
<object class="GtkDropTarget" id="drop_target"> <object class="GtkDropTarget" id="drop_target">
<property name="actions">copy</property> <property name="actions">copy</property>

View file

@ -31,13 +31,17 @@ row.property label.subtitle {
box-shadow: 0 0 10px rgba(0, 0, 0, 200); box-shadow: 0 0 10px rgba(0, 0, 0, 200);
} }
.custom-drag-n-drop-highlight { /* Remove default adwaita style */
.drop-widget:drop(active):focus,
.drop-widget:drop(active) {
box-shadow: none; box-shadow: none;
} }
/* Drag overlay */
.lp-dragging-area-highlight { .lp-dragging-area-highlight {
border-radius: 8px; border-radius: 8px;
background-color: alpha(@blue_2, 0.35); background-color: alpha(@blue_2, 0.35);
margin: 24px;
} }
lpprintpreview { lpprintpreview {

View file

@ -16,10 +16,11 @@
// //
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
use gtk::{glib, prelude::*}; use crate::deps::*;
use adw::prelude::*;
mod imp { mod imp {
use std::cell::RefCell; use once_cell::sync::OnceCell;
use adw::subclass::prelude::*; use adw::subclass::prelude::*;
use glib::{ParamSpec, Properties, Value}; use glib::{ParamSpec, Properties, Value};
@ -37,9 +38,8 @@ mod imp {
pub overlayed: Option<gtk::Widget>, pub overlayed: Option<gtk::Widget>,
pub overlay: gtk::Overlay, pub overlay: gtk::Overlay,
pub revealer: gtk::Revealer, pub revealer: gtk::Revealer,
#[property(set = Self::set_drop_target, get, explicit_notify)] #[property(set = Self::set_drop_target, get, explicit_notify, construct_only)]
pub drop_target: RefCell<Option<gtk::DropTarget>>, pub drop_target: OnceCell<gtk::DropTarget>,
pub handler_id: RefCell<Option<glib::SignalHandlerId>>,
} }
#[glib::object_subclass] #[glib::object_subclass]
@ -47,6 +47,10 @@ mod imp {
const NAME: &'static str = "LpDragOverlay"; const NAME: &'static str = "LpDragOverlay";
type Type = super::LpDragOverlay; type Type = super::LpDragOverlay;
type ParentType = adw::Bin; type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) {
klass.set_css_name("lpdragoverlay");
}
} }
impl ObjectImpl for LpDragOverlay { impl ObjectImpl for LpDragOverlay {
@ -88,29 +92,17 @@ mod imp {
self.revealer.set_child(overlayed.as_ref()); self.revealer.set_child(overlayed.as_ref());
} }
pub fn set_drop_target(&self, drop_target: &gtk::DropTarget) { pub fn set_drop_target(&self, drop_target: gtk::DropTarget) {
if let Some(target) = self.drop_target.borrow_mut().take() { drop_target.connect_current_drop_notify(
self.obj().remove_controller(&target);
if let Some(handler_id) = self.handler_id.borrow_mut().take() {
target.disconnect(handler_id);
}
}
let handler_id = drop_target.connect_current_drop_notify(
glib::clone!(@weak self.revealer as revealer => move |target| { glib::clone!(@weak self.revealer as revealer => move |target| {
let reveal = target.current_drop().is_some(); let reveal = target.current_drop().is_some();
revealer.set_reveal_child(reveal); revealer.set_reveal_child(reveal);
}), }),
); );
self.handler_id.replace(Some(handler_id));
// avoid `gtk_event_controller_get_widget (controller) == NULL` failing self.drop_target.set(drop_target).unwrap();
if drop_target.widget().is_visible() {
self.obj().add_controller(drop_target.clone()); self.obj().notify("drop-target");
self.drop_target.replace(Some(drop_target.clone()));
self.obj().notify("drop-target");
}
} }
} }
} }

View file

@ -419,7 +419,6 @@ mod imp {
true true
}), }),
); );
self.drag_overlay.set_drop_target(&*self.drop_target);
} }
} }