big refactor and cleanup of dock + use tokio mpsc

This commit is contained in:
Ashley Wulber 2022-01-02 01:46:44 -05:00
parent 346701b16d
commit 35eb571528
14 changed files with 578 additions and 674 deletions

View file

@ -8,8 +8,7 @@ use gtk4::CssProvider;
use gtk4::StyleContext;
use once_cell::sync::OnceCell;
use pop_launcher_service::IpcClient;
use postage::mpsc::Sender;
use postage::prelude::*;
use tokio::sync::mpsc;
use x11rb::rust_connection::RustConnection;
use crate::utils::BoxedSearchResult;
@ -23,7 +22,7 @@ mod utils;
mod window;
const NUM_LAUNCHER_ITEMS: u8 = 10;
static TX: OnceCell<Sender<Event>> = OnceCell::new();
static TX: OnceCell<mpsc::Sender<Event>> = OnceCell::new();
static X11_CONN: OnceCell<RustConnection> = OnceCell::new();
pub enum Event {
@ -32,7 +31,7 @@ pub enum Event {
Activate(u32),
}
fn spawn_launcher(mut tx: Sender<Event>) -> IpcClient {
fn spawn_launcher(tx: mpsc::Sender<Event>) -> IpcClient {
let (launcher, responses) =
pop_launcher_service::IpcClient::new().expect("failed to connect to launcher service");
@ -79,12 +78,13 @@ fn main() {
load_css()
});
app.connect_activate(move |app| {
let (tx, mut rx) = postage::mpsc::channel(1);
let (tx, mut rx) = mpsc::channel(100);
let mut launcher = spawn_launcher(tx.clone());
if TX.set(tx).is_err() {
println!("failed to set global Sender. Exiting");
std::process::exit(1);
};
let (conn, _screen_num) = x11rb::connect(None).expect("Failed to connect to X");
if X11_CONN.set(conn).is_err() {
println!("failed to set X11_CONN. Exiting");

View file

@ -1,4 +1,4 @@
use gdk4::glib::Object;
use gtk4::glib;
use crate::utils::BoxedSearchResult;
@ -10,6 +10,6 @@ glib::wrapper! {
impl SearchResultObject {
pub fn new(search_result: &BoxedSearchResult) -> Self {
Object::new(&[("data", search_result)]).expect("Failed to create Application Object")
glib::Object::new(&[("data", search_result)]).expect("Failed to create Application Object")
}
}

View file

@ -1,5 +1,5 @@
use cascade::cascade;
use glib;
use gtk4::glib;
use gtk4::pango::EllipsizeMode;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;

View file

@ -1,3 +1,4 @@
use gtk4::glib;
use std::cell::RefCell;
use std::rc::Rc;

View file

@ -11,7 +11,6 @@ use gtk4::ListView;
use gtk4::Orientation;
use gtk4::{gio, glib};
use gtk4::{Application, SignalListItemFactory};
use postage::prelude::Sink;
use x11rb::connection::Connection;
use x11rb::protocol::xproto;
use x11rb::protocol::xproto::ConnectionExt;
@ -126,7 +125,6 @@ impl Window {
glib::MainContext::default().spawn_local(async move {
if let Some(tx) = TX.get() {
let mut tx = tx.clone();
let _ = tx.send(crate::Event::Activate(id)).await;
}
});
@ -153,7 +151,6 @@ impl Window {
glib::MainContext::default().spawn_local(async move {
if let Some(tx) = TX.get() {
let mut tx = tx.clone();
let _ = tx.send(crate::Event::Activate(id)).await;
}
});
@ -165,7 +162,6 @@ impl Window {
glib::MainContext::default().spawn_local(async move {
if let Some(tx) = TX.get() {
let mut tx = tx.clone();
let _ = tx.send(crate::Event::Search(search)).await;
}
});
@ -176,7 +172,6 @@ impl Window {
glib::MainContext::default().spawn_local(async move {
if let Some(tx) = TX.get() {
let mut tx = tx.clone();
let _ = tx.send(crate::Event::Search(search)).await;
}
});