focus open window when dock item selected
This commit is contained in:
parent
86b7c2f341
commit
2171fd8eac
5 changed files with 134 additions and 147 deletions
|
|
@ -55,7 +55,6 @@ impl DockItem {
|
||||||
let self_ = imp::DockItem::from_instance(self);
|
let self_ = imp::DockItem::from_instance(self);
|
||||||
if let Ok(app_info_value) = app_info.property("appinfo") {
|
if let Ok(app_info_value) = app_info.property("appinfo") {
|
||||||
if let Ok(Some(app_info)) = app_info_value.get::<Option<DesktopAppInfo>>() {
|
if let Ok(Some(app_info)) = app_info_value.get::<Option<DesktopAppInfo>>() {
|
||||||
println!("setting app info {}", &app_info.name());
|
|
||||||
self_.image.set_tooltip_text(Some(&app_info.name()));
|
self_.image.set_tooltip_text(Some(&app_info.name()));
|
||||||
|
|
||||||
let icon = app_info.icon().unwrap_or(
|
let icon = app_info.icon().unwrap_or(
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ impl DockObject {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
dbg!(&appinfo);
|
// dbg!(&appinfo);
|
||||||
Object::new(&[("appinfo", &appinfo), ("active", &results)])
|
Object::new(&[("appinfo", &appinfo), ("active", &results)])
|
||||||
.expect("Failed to create `DockObject`.")
|
.expect("Failed to create `DockObject`.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ mod window;
|
||||||
|
|
||||||
use crate::utils::BoxedWindowList;
|
use crate::utils::BoxedWindowList;
|
||||||
use async_io::Timer;
|
use async_io::Timer;
|
||||||
use futures::StreamExt;
|
use futures::executor::block_on;
|
||||||
use gdk4::Display;
|
use gdk4::Display;
|
||||||
use gio::DesktopAppInfo;
|
use gio::DesktopAppInfo;
|
||||||
use gtk::gio;
|
use gtk::gio;
|
||||||
|
|
@ -17,7 +17,6 @@ use gtk4 as gtk;
|
||||||
use gtk4::CssProvider;
|
use gtk4::CssProvider;
|
||||||
use gtk4::StyleContext;
|
use gtk4::StyleContext;
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use pop_launcher_service::IpcClient;
|
|
||||||
use postage::mpsc::Sender;
|
use postage::mpsc::Sender;
|
||||||
use postage::prelude::*;
|
use postage::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -30,16 +29,17 @@ use zvariant_derive::Type;
|
||||||
use self::dock_object::DockObject;
|
use self::dock_object::DockObject;
|
||||||
use self::window::Window;
|
use self::window::Window;
|
||||||
|
|
||||||
|
const DEST: &str = "com.System76.PopShell";
|
||||||
|
const PATH: &str = "/com/System76/PopShell";
|
||||||
const NUM_LAUNCHER_ITEMS: u8 = 10;
|
const NUM_LAUNCHER_ITEMS: u8 = 10;
|
||||||
|
|
||||||
static TX: OnceCell<Sender<Event>> = OnceCell::new();
|
static TX: OnceCell<Sender<Event>> = OnceCell::new();
|
||||||
static X11_CONN: OnceCell<RustConnection> = OnceCell::new();
|
static X11_CONN: OnceCell<RustConnection> = OnceCell::new();
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
Response(pop_launcher::Response),
|
|
||||||
WindowList(Vec<Item>),
|
WindowList(Vec<Item>),
|
||||||
|
Activate((u32, u32)),
|
||||||
RefreshFromCache,
|
RefreshFromCache,
|
||||||
Search(String),
|
|
||||||
Activate(u32),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Type, Clone, PartialEq, Eq)]
|
#[derive(Debug, Deserialize, Serialize, Type, Clone, PartialEq, Eq)]
|
||||||
|
|
@ -50,30 +50,15 @@ pub struct Item {
|
||||||
desktop_entry: String,
|
desktop_entry: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_launcher(tx: Sender<Event>) -> IpcClient {
|
fn spawn_launcher(tx: Sender<Event>) -> Connection {
|
||||||
let (launcher, responses) =
|
let connection = block_on(Connection::session()).unwrap();
|
||||||
pop_launcher_service::IpcClient::new().expect("failed to connect to launcher service");
|
|
||||||
|
|
||||||
let mut sender = tx.clone();
|
|
||||||
glib::MainContext::default().spawn_local(async move {
|
|
||||||
futures::pin_mut!(responses);
|
|
||||||
while let Some(event) = responses.next().await {
|
|
||||||
let _ = sender.send(Event::Response(event)).await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut sender = tx.clone();
|
let mut sender = tx.clone();
|
||||||
|
let conn = connection.clone();
|
||||||
glib::MainContext::default().spawn_local(async move {
|
glib::MainContext::default().spawn_local(async move {
|
||||||
loop {
|
loop {
|
||||||
let connection = Connection::session().await.unwrap();
|
let m = conn
|
||||||
let m = connection
|
.call_method(Some(DEST), PATH, Some(DEST), "WindowList", &())
|
||||||
.call_method(
|
|
||||||
Some("com.System76.PopShell"),
|
|
||||||
"/com/System76/PopShell",
|
|
||||||
Some("com.System76.PopShell"),
|
|
||||||
"WindowList",
|
|
||||||
&(),
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
if let Ok(m) = m {
|
if let Ok(m) = m {
|
||||||
if let Ok(reply) = m.body::<Vec<Item>>() {
|
if let Ok(reply) = m.body::<Vec<Item>>() {
|
||||||
|
|
@ -84,7 +69,7 @@ fn spawn_launcher(tx: Sender<Event>) -> IpcClient {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
launcher
|
connection
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_shortcuts(app: &Application) {
|
fn setup_shortcuts(app: &Application) {
|
||||||
|
|
@ -126,7 +111,7 @@ fn main() {
|
||||||
// Seems that over a long period of time, this might be called multiple times
|
// Seems that over a long period of time, this might be called multiple times
|
||||||
// The global variables should be initialized outside this closure
|
// The global variables should be initialized outside this closure
|
||||||
let (tx, mut rx) = postage::mpsc::channel(1);
|
let (tx, mut rx) = postage::mpsc::channel(1);
|
||||||
let mut launcher = spawn_launcher(tx.clone());
|
let zbus_conn = spawn_launcher(tx.clone());
|
||||||
if TX.set(tx).is_err() {
|
if TX.set(tx).is_err() {
|
||||||
println!("failed to set global Sender. Exiting");
|
println!("failed to set global Sender. Exiting");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
|
@ -145,86 +130,96 @@ fn main() {
|
||||||
futures::pin_mut!(cached_results);
|
futures::pin_mut!(cached_results);
|
||||||
while let Some(event) = rx.recv().await {
|
while let Some(event) = rx.recv().await {
|
||||||
match event {
|
match event {
|
||||||
Event::Search(search) => {
|
Event::Activate(e) => {
|
||||||
let _ = launcher.send(pop_launcher::Request::Search(search)).await;
|
let _activate_window = zbus_conn
|
||||||
}
|
.call_method(Some(DEST), PATH, Some(DEST), "WindowFocus", &((e,)))
|
||||||
Event::Activate(index) => {
|
.await
|
||||||
let _ = launcher.send(pop_launcher::Request::Activate(index)).await;
|
.expect("Failed to focus selected window");
|
||||||
|
dbg!(_activate_window);
|
||||||
}
|
}
|
||||||
Event::RefreshFromCache => {
|
Event::RefreshFromCache => {
|
||||||
//TODO refresh the model from cached_results (required after DnD for example)
|
//TODO refresh the model from cached_results (required after DnD for example)
|
||||||
}
|
}
|
||||||
Event::WindowList(mut results) => {
|
Event::WindowList(mut results) => {
|
||||||
// sort to make comparison with cache easier
|
// sort to make comparison with cache easier
|
||||||
let mut cached_results = cached_results.as_mut();
|
let mut cached_results = cached_results.as_mut();
|
||||||
results.sort_by(|a, b| a.name.cmp(&b.name));
|
results.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
|
||||||
|
// dbg!(&results);
|
||||||
|
// dbg!(&cached_results);
|
||||||
|
// // check if cache equals the new polled results
|
||||||
|
// 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()
|
||||||
|
{
|
||||||
|
continue; // skip this update
|
||||||
|
}
|
||||||
|
|
||||||
// dbg!(&results);
|
// build active app stacks for each app
|
||||||
// dbg!(&cached_results);
|
let stack_active = results.iter().fold(
|
||||||
// // check if cache equals the new polled results
|
BTreeMap::new(),
|
||||||
// skip if equal
|
|mut acc: BTreeMap<String, BoxedWindowList>, elem| {
|
||||||
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() {
|
|
||||||
continue // skip this update
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("updating active apps");
|
|
||||||
// build active app stacks for each app
|
|
||||||
let stack_active = results.iter().fold(BTreeMap::new(), |mut acc: BTreeMap<String, BoxedWindowList>, elem| {
|
|
||||||
if let Some(v) = acc.get_mut(&elem.description) {
|
if let Some(v) = acc.get_mut(&elem.description) {
|
||||||
v.0.push(elem.clone());
|
v.0.push(elem.clone());
|
||||||
} else {
|
} else {
|
||||||
acc.insert(elem.description.clone(), BoxedWindowList(vec![elem.clone()]));
|
acc.insert(
|
||||||
|
elem.description.clone(),
|
||||||
|
BoxedWindowList(vec![elem.clone()]),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
acc
|
acc
|
||||||
});
|
},
|
||||||
let mut stack_active: Vec<BoxedWindowList> = stack_active.into_values().collect();
|
);
|
||||||
|
let mut stack_active: Vec<BoxedWindowList> =
|
||||||
|
stack_active.into_values().collect();
|
||||||
|
|
||||||
// update active app stacks for saved apps into the saved app model
|
// update active app stacks for saved apps into the saved app model
|
||||||
// then put the rest in the active app model (which doesn't include saved apps)
|
// then put the rest in the active app model (which doesn't include saved apps)
|
||||||
let saved_app_model = window.saved_app_model();
|
let saved_app_model = window.saved_app_model();
|
||||||
|
|
||||||
let mut i: u32 = 0;
|
let mut i: u32 = 0;
|
||||||
while let Some(item) = saved_app_model.item(i) {
|
while let Some(item) = saved_app_model.item(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.property("appinfo").expect("property appinfo missing from DockObject").get::<Option<DesktopAppInfo>>() {
|
if let Ok(Some(cur_app_info)) = dock_obj
|
||||||
if let Some((i, s)) = stack_active.iter().enumerate().find(|(_i, s)| s.0[0].description == cur_app_info.name()) {
|
.property("appinfo")
|
||||||
println!("found active saved app {} at {}", s.0[0].name, i);
|
.expect("property appinfo missing from DockObject")
|
||||||
let active = stack_active.remove(i);
|
.get::<Option<DesktopAppInfo>>()
|
||||||
dock_obj.set_property("active", active.to_value()).expect("failed to update dock active apps");
|
{
|
||||||
saved_app_model.items_changed(i.try_into().unwrap(), 0, 0);
|
if let Some((i, _s)) = stack_active
|
||||||
}
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_i, s)| s.0[0].description == cur_app_info.name())
|
||||||
|
{
|
||||||
|
// 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");
|
||||||
|
saved_app_model.items_changed(i.try_into().unwrap(), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
i += 1;
|
||||||
let active_app_model = window.active_app_model();
|
|
||||||
let model_len = active_app_model.n_items();
|
|
||||||
let new_results: Vec<glib::Object> = stack_active
|
|
||||||
.into_iter()
|
|
||||||
.map(|v| DockObject::from_search_results(v).upcast())
|
|
||||||
.collect();
|
|
||||||
active_app_model.splice(0, model_len, &new_results[..]);
|
|
||||||
cached_results.splice(.., results);
|
|
||||||
}
|
|
||||||
Event::Response(event) => {
|
|
||||||
// TODO investigate why polled results are out of date after launching a new window
|
|
||||||
if let pop_launcher::Response::DesktopEntry {
|
|
||||||
path,
|
|
||||||
gpu_preference: _gpu_preference, // TODO use GPU preference when launching app
|
|
||||||
} = event
|
|
||||||
{
|
|
||||||
let app_info =
|
|
||||||
DesktopAppInfo::new(&path.file_name().expect("desktop entry path needs to be a valid filename").to_string_lossy())
|
|
||||||
.expect("failed to create a Desktop App info for launching the application.");
|
|
||||||
app_info
|
|
||||||
.launch(&[], Some(&window.display().app_launch_context())).expect("failed to launch the application.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let active_app_model = window.active_app_model();
|
||||||
|
let model_len = active_app_model.n_items();
|
||||||
|
let new_results: Vec<glib::Object> = stack_active
|
||||||
|
.into_iter()
|
||||||
|
.map(|v| DockObject::from_search_results(v).upcast())
|
||||||
|
.collect();
|
||||||
|
active_app_model.splice(0, model_len, &new_results[..]);
|
||||||
|
cached_results.splice(.., results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ mod imp;
|
||||||
// use crate::ApplicationObject;
|
// use crate::ApplicationObject;
|
||||||
use crate::dock_item::DockItem;
|
use crate::dock_item::DockItem;
|
||||||
use crate::dock_object::DockObject;
|
use crate::dock_object::DockObject;
|
||||||
|
use crate::BoxedWindowList;
|
||||||
|
use crate::Event;
|
||||||
|
use crate::TX;
|
||||||
use crate::X11_CONN;
|
use crate::X11_CONN;
|
||||||
use gdk4::Rectangle;
|
use gdk4::Rectangle;
|
||||||
use gdk4::Surface;
|
use gdk4::Surface;
|
||||||
|
|
@ -12,6 +15,7 @@ use gtk4 as gtk;
|
||||||
use gtk4::prelude::ListModelExt;
|
use gtk4::prelude::ListModelExt;
|
||||||
use gtk4::DropTarget;
|
use gtk4::DropTarget;
|
||||||
use gtk4::EventControllerMotion;
|
use gtk4::EventControllerMotion;
|
||||||
|
use postage::prelude::Sink;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use x11rb::connection::Connection;
|
use x11rb::connection::Connection;
|
||||||
use x11rb::protocol::xproto::ConnectionExt;
|
use x11rb::protocol::xproto::ConnectionExt;
|
||||||
|
|
@ -73,7 +77,7 @@ impl Window {
|
||||||
.for_each(|xdg_data_path| {
|
.for_each(|xdg_data_path| {
|
||||||
let defaults = ["Firefox Web Browser", "Files", "Terminal", "Pop!_Shop"];
|
let defaults = ["Firefox Web Browser", "Files", "Terminal", "Pop!_Shop"];
|
||||||
xdg_data_path.push("applications");
|
xdg_data_path.push("applications");
|
||||||
dbg!(&xdg_data_path);
|
// dbg!(&xdg_data_path);
|
||||||
if let Ok(dir_iter) = std::fs::read_dir(xdg_data_path) {
|
if let Ok(dir_iter) = std::fs::read_dir(xdg_data_path) {
|
||||||
dir_iter.for_each(|dir_entry| {
|
dir_iter.for_each(|dir_entry| {
|
||||||
if let Ok(dir_entry) = dir_entry {
|
if let Ok(dir_entry) = dir_entry {
|
||||||
|
|
@ -135,46 +139,32 @@ impl Window {
|
||||||
.expect("List view missing selection model")
|
.expect("List view missing selection model")
|
||||||
.downcast::<gtk::SingleSelection>()
|
.downcast::<gtk::SingleSelection>()
|
||||||
.expect("could not downcast listview model to single selection model");
|
.expect("could not downcast listview model to single selection model");
|
||||||
|
let active_app_selection_model = imp
|
||||||
saved_app_selection_model.connect_selected_notify(
|
.active_app_list_view
|
||||||
glib::clone!(@weak window => move |model| {
|
|
||||||
let position = model.selected();
|
|
||||||
println!("selected app {}", position);
|
|
||||||
// Launch the application when an item of the list is activated
|
|
||||||
if let Some(item) = model.item(position) {
|
|
||||||
let app_info = item.downcast::<DockObject>().expect("App model must only contain DockObject");
|
|
||||||
if let Ok(Some(app_info)) = app_info.property("appinfo").expect("DockObject must have appinfo property").get::<Option<DesktopAppInfo>>() {
|
|
||||||
let context = window.display().app_launch_context();
|
|
||||||
if let Err(err) = app_info.launch(&[], Some(&context)) {
|
|
||||||
gtk::MessageDialog::builder()
|
|
||||||
.text(&format!("Failed to start {}", app_info.name()))
|
|
||||||
.secondary_text(&err.to_string())
|
|
||||||
.message_type(gtk::MessageType::Error)
|
|
||||||
.modal(true)
|
|
||||||
.transient_for(&window)
|
|
||||||
.build()
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
model.set_selected(gtk4::INVALID_LIST_POSITION);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
let active_app_selection_model = saved_app_list_view
|
|
||||||
.model()
|
.model()
|
||||||
.expect("List view missing selection model")
|
.expect("List view missing selection model")
|
||||||
.downcast::<gtk::SingleSelection>()
|
.downcast::<gtk::SingleSelection>()
|
||||||
.expect("could not downcast listview model to single selection model");
|
.expect("could not downcast listview model to single selection model");
|
||||||
|
|
||||||
active_app_selection_model.connect_selected_notify(
|
let selected_handler = glib::clone!(@weak window => move |model: >k::SingleSelection| {
|
||||||
glib::clone!(@weak window => move |model| {
|
let position = model.selected();
|
||||||
let position = model.selected();
|
println!("selected app {}", position);
|
||||||
println!("selected app {}", position);
|
// Launch the application when an item of the list is activated
|
||||||
// Launch the application when an item of the list is activated
|
if let Some(item) = model.item(position) {
|
||||||
if let Some(item) = model.item(position) {
|
let dockobject = item.downcast::<DockObject>().expect("App model must only contain DockObject");
|
||||||
let app_info = item.downcast::<DockObject>().expect("App model must only contain DockObject");
|
if let Ok(active) = dockobject.property("active").expect("DockObject must have active property").get::<BoxedWindowList>() {
|
||||||
if let Ok(Some(app_info)) = app_info.property("appinfo").expect("DockObject must have appinfo property").get::<Option<DesktopAppInfo>>() {
|
dbg!(&active);
|
||||||
|
if let Some(focused_item) = active.0.iter().next() {
|
||||||
|
let entity = focused_item.entity.clone();
|
||||||
|
dbg!(&entity);
|
||||||
|
glib::MainContext::default().spawn_local(async move {
|
||||||
|
if let Some(tx) = TX.get() {
|
||||||
|
let mut tx = tx.clone();
|
||||||
|
let _ = tx.send(Event::Activate(entity)).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if let Ok(Some(app_info)) = dockobject.property("appinfo").expect("DockObject must have appinfo property").get::<Option<DesktopAppInfo>>() {
|
||||||
let context = window.display().app_launch_context();
|
let context = window.display().app_launch_context();
|
||||||
if let Err(err) = app_info.launch(&[], Some(&context)) {
|
if let Err(err) = app_info.launch(&[], Some(&context)) {
|
||||||
gtk::MessageDialog::builder()
|
gtk::MessageDialog::builder()
|
||||||
|
|
@ -188,9 +178,12 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model.set_selected(gtk4::INVALID_LIST_POSITION);
|
}
|
||||||
}),
|
model.set_selected(gtk4::INVALID_LIST_POSITION);
|
||||||
);
|
});
|
||||||
|
saved_app_selection_model.connect_selected_notify(selected_handler.clone());
|
||||||
|
|
||||||
|
active_app_selection_model.connect_selected_notify(selected_handler);
|
||||||
|
|
||||||
let cursor_event_controller = &imp.cursor_event_controller.get().unwrap();
|
let cursor_event_controller = &imp.cursor_event_controller.get().unwrap();
|
||||||
let drop_controller = &imp.drop_controller.get().unwrap();
|
let drop_controller = &imp.drop_controller.get().unwrap();
|
||||||
|
|
@ -198,7 +191,7 @@ impl Window {
|
||||||
let revealer = &imp.revealer.get();
|
let revealer = &imp.revealer.get();
|
||||||
window.connect_show(
|
window.connect_show(
|
||||||
glib::clone!(@weak revealer, @weak cursor_event_controller => move |_| {
|
glib::clone!(@weak revealer, @weak cursor_event_controller => move |_| {
|
||||||
dbg!(!cursor_event_controller.contains_pointer());
|
// dbg!(!cursor_event_controller.contains_pointer());
|
||||||
if !cursor_event_controller.contains_pointer() {
|
if !cursor_event_controller.contains_pointer() {
|
||||||
revealer.set_reveal_child(false);
|
revealer.set_reveal_child(false);
|
||||||
}
|
}
|
||||||
|
|
@ -218,7 +211,7 @@ impl Window {
|
||||||
|
|
||||||
//TODO clean up duplicated code
|
//TODO clean up duplicated code
|
||||||
cursor_event_controller.connect_enter(glib::clone!(@weak revealer, @weak window => move |_evc, _x, _y| {
|
cursor_event_controller.connect_enter(glib::clone!(@weak revealer, @weak window => move |_evc, _x, _y| {
|
||||||
dbg!("hello, mouse entered me :)");
|
// dbg!("hello, mouse entered me :)");
|
||||||
revealer.set_reveal_child(true);
|
revealer.set_reveal_child(true);
|
||||||
let s = window.surface().expect("Failed to get Surface for Window");
|
let s = window.surface().expect("Failed to get Surface for Window");
|
||||||
let height = s.height() * s.scale_factor();
|
let height = s.height() * s.scale_factor();
|
||||||
|
|
@ -262,7 +255,7 @@ impl Window {
|
||||||
revealer.connect_child_revealed_notify(glib::clone!(@weak window => move |r| {
|
revealer.connect_child_revealed_notify(glib::clone!(@weak window => move |r| {
|
||||||
if !r.is_child_revealed() {
|
if !r.is_child_revealed() {
|
||||||
let s = window.surface().expect("Failed to get Surface for Window");
|
let s = window.surface().expect("Failed to get Surface for Window");
|
||||||
dbg!(r.is_child_revealed());
|
// dbg!(r.is_child_revealed());
|
||||||
let height = 4;
|
let height = 4;
|
||||||
if let Some((display, _surface)) = x::get_window_x11(&window) {
|
if let Some((display, _surface)) = x::get_window_x11(&window) {
|
||||||
let monitor = display
|
let monitor = display
|
||||||
|
|
@ -354,7 +347,7 @@ impl Window {
|
||||||
glib::clone!(@weak revealer, @weak drop_controller => move |_evc| {
|
glib::clone!(@weak revealer, @weak drop_controller => move |_evc| {
|
||||||
// only hide if DnD is not happening
|
// only hide if DnD is not happening
|
||||||
if drop_controller.current_drop().is_none() {
|
if drop_controller.current_drop().is_none() {
|
||||||
dbg!("hello, mouse left me :)");
|
// dbg!("hello, mouse left me :)");
|
||||||
revealer.set_reveal_child(false);
|
revealer.set_reveal_child(false);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
@ -376,7 +369,7 @@ impl Window {
|
||||||
drop_controller.connect_drop(
|
drop_controller.connect_drop(
|
||||||
glib::clone!(@weak saved_app_model, @weak saved_app_list_view => @default-return true, move |_self, drop_value, x, y| {
|
glib::clone!(@weak saved_app_model, @weak saved_app_list_view => @default-return true, move |_self, drop_value, x, y| {
|
||||||
if let Ok(Some(path_str)) = drop_value.get::<Option<String>>() {
|
if let Ok(Some(path_str)) = drop_value.get::<Option<String>>() {
|
||||||
dbg!(&path_str);
|
// dbg!(&path_str);
|
||||||
let desktop_path = &Path::new(&path_str);
|
let desktop_path = &Path::new(&path_str);
|
||||||
if let Some(pathbase) = desktop_path.file_name() {
|
if let Some(pathbase) = desktop_path.file_name() {
|
||||||
if let Some(app_info) = gio::DesktopAppInfo::new(&pathbase.to_string_lossy()) {
|
if let Some(app_info) = gio::DesktopAppInfo::new(&pathbase.to_string_lossy()) {
|
||||||
|
|
@ -385,7 +378,7 @@ impl Window {
|
||||||
while let Some(item) = saved_app_model.item(i) {
|
while let Some(item) = saved_app_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 Ok(Some(cur_app_info)) = cur_app_info.property("appinfo").expect("property appinfo missing from DockObject").get::<Option<DesktopAppInfo>>() {
|
||||||
dbg!(cur_app_info.filename());
|
// dbg!(cur_app_info.filename());
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
@ -393,20 +386,20 @@ impl Window {
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
dbg!(app_info.name());
|
// dbg!(app_info.name());
|
||||||
dbg!(index_of_existing_app);
|
// dbg!(index_of_existing_app);
|
||||||
if let Some(index_of_existing_app) = index_of_existing_app {
|
if let Some(index_of_existing_app) = index_of_existing_app {
|
||||||
// remove existing entry
|
// remove existing entry
|
||||||
saved_app_model.remove(index_of_existing_app);
|
saved_app_model.remove(index_of_existing_app);
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate insertion location
|
//calculate insertion location
|
||||||
dbg!(x);
|
// dbg!(x);
|
||||||
dbg!(y);
|
// dbg!(y);
|
||||||
let max_y = saved_app_list_view.allocated_height();
|
let max_y = saved_app_list_view.allocated_height();
|
||||||
let max_x = saved_app_list_view.allocated_width();
|
let max_x = saved_app_list_view.allocated_width();
|
||||||
dbg!(max_x);
|
// dbg!(max_x);
|
||||||
dbg!(max_y);
|
// dbg!(max_y);
|
||||||
let n_buckets = saved_app_model.n_items() * 2;
|
let n_buckets = saved_app_model.n_items() * 2;
|
||||||
|
|
||||||
let drop_bucket = (x * n_buckets as f64 / (max_x as f64 + 0.1)) as u32;
|
let drop_bucket = (x * n_buckets as f64 / (max_x as f64 + 0.1)) as u32;
|
||||||
|
|
@ -417,15 +410,15 @@ impl Window {
|
||||||
} else {
|
} else {
|
||||||
(drop_bucket + 1) / 2
|
(drop_bucket + 1) / 2
|
||||||
};
|
};
|
||||||
dbg!(index);
|
// dbg!(index);
|
||||||
dbg!("dropped it!");
|
// dbg!("dropped it!");
|
||||||
dbg!(drop_value.type_());
|
// dbg!(drop_value.type_());
|
||||||
saved_app_model.insert(index, &DockObject::new(app_info));
|
saved_app_model.insert(index, &DockObject::new(app_info));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dbg!("rejecting drop");
|
// dbg!("rejecting drop");
|
||||||
_self.reject();
|
_self.reject();
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
<object class="GtkRevealer" id="revealer">
|
<object class="GtkRevealer" id="revealer">
|
||||||
<property name="reveal-child">true</property>
|
<property name="reveal-child">true</property>
|
||||||
<property name="transition-duration">300</property>
|
<property name="transition-duration">300</property>
|
||||||
<property name="transition-type">cross-fade</property>
|
<property name="transition-type">slide-up</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
<property name="height-request">0</property>
|
<property name="height-request">0</property>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue