remove x11rb as dependency

This commit is contained in:
Ashley Wulber 2022-01-19 13:56:20 -05:00
parent cc577b1367
commit 6ed9fdc9cd
6 changed files with 12 additions and 91 deletions

View file

@ -1,10 +1,7 @@
use std::rc::Rc;
use crate::app_grid::AppGrid;
use crate::group_grid::GroupGrid;
use cascade::cascade;
use gdk4_x11::X11Display;
use gdk4_x11::X11Surface;
use glib::Object;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
@ -17,9 +14,6 @@ use gtk4::SearchEntry;
use gtk4::Separator;
use gtk4::{gio, glib};
use libcosmic::x;
use once_cell::sync::OnceCell;
use x11rb::connection::Connection;
use x11rb::protocol::xproto::*;
mod imp;
@ -147,10 +141,6 @@ impl AppLibraryWindow {
window.connect_realize(move |window| {
if let Some((display, surface)) = x::get_window_x11(window) {
let (conn, _screen_num) = x11rb::connect(None).expect("Failed to connect to X");
let x11rb_conn = Rc::new(OnceCell::new());
x11rb_conn.set(conn).unwrap();
// ignore all x11 errors...
let xdisplay = display
.clone()
@ -166,8 +156,7 @@ impl AppLibraryWindow {
&[x::Atom::new(&display, "_NET_WM_WINDOW_TYPE_DIALOG").unwrap()],
);
}
let resize = glib::clone!(@weak window, @strong x11rb_conn => move || {
let s = window.surface();
let resize = glib::clone!(@weak window => move || {
let height = window.height();
let width = window.width();
@ -182,21 +171,9 @@ impl AppLibraryWindow {
// dbg!(monitor_height);
// dbg!(width);
// dbg!(height);
let w_conf = ConfigureWindowAux::default()
.x(monitor_x + monitor_width / 2 - width / 2)
.y(monitor_y + monitor_height / 2 - height / 2);
let x11surface = gdk4_x11::X11Surface::xid(
&s.clone().downcast::<X11Surface>()
.expect("Failed to downcast Surface to X11Surface"),
);
let conn = x11rb_conn.get().unwrap();
conn.configure_window(
x11surface.try_into().expect("Failed to convert XID"),
&w_conf,
)
.expect("failed to configure window...");
conn.flush().expect("failed to flush");
unsafe { x::set_position(&display, &surface,
monitor_x + monitor_width / 2 - width / 2,
monitor_y + monitor_height / 2 - height / 2)};
}
});
let s = window.surface();

View file

@ -15,7 +15,6 @@ use once_cell::sync::{Lazy, OnceCell};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tokio::sync::mpsc;
use x11rb::rust_connection::RustConnection;
use zbus::Connection;
use zvariant_derive::Type;
@ -35,7 +34,6 @@ const DEST: &str = "com.System76.PopShell";
const PATH: &str = "/com/System76/PopShell";
static TX: OnceCell<mpsc::Sender<Event>> = OnceCell::new();
static X11_CONN: OnceCell<RustConnection> = OnceCell::new();
static PLUGINS: Lazy<Mutex<HashMap<String, libloading::Library>>> =
Lazy::new(|| Mutex::new(HashMap::new()));
@ -133,11 +131,6 @@ fn main() {
std::process::exit(1);
};
let (conn, _screen_num) = x11rb::connect(None).expect("Failed to connect to X");
if X11_CONN.set(conn).is_err() {
eprintln!("failed to set X11_CONN. Exiting");
std::process::exit(1);
};
let window = Window::new(app);
window.show();

View file

@ -1,6 +1,5 @@
use cascade::cascade;
use gdk4_x11::X11Display;
use gdk4_x11::X11Surface;
use glib::Object;
use glib::Type;
use gtk4::prelude::*;
@ -15,15 +14,11 @@ use gtk4::Revealer;
use gtk4::RevealerTransitionType;
use gtk4::Separator;
use gtk4::{gio, glib};
use x11rb::connection::Connection;
use x11rb::protocol::xproto;
use x11rb::protocol::xproto::ConnectionExt;
use libcosmic::x;
use crate::dock_list::DockList;
use crate::dock_list::DockListType;
use crate::X11_CONN;
mod imp;
@ -139,7 +134,6 @@ impl Window {
);
}
let resize = glib::clone!(@weak window, @weak revealer => move || {
let s = window.surface();
let height = if revealer.reveals_child() { window.height() } else { 4 };
let width = window.width();
@ -156,23 +150,9 @@ impl Window {
// dbg!(monitor_height);
// dbg!(width);
// dbg!(height);
let w_conf = xproto::ConfigureWindowAux::default()
.x((monitor_x + monitor_width / 2 - width / 2).clamp(0, monitor_x + monitor_width - 1))
.y((monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1));
let conn = X11_CONN.get().expect("Failed to get X11_CONN");
let x11surface = gdk4_x11::X11Surface::xid(
&s.clone().downcast::<X11Surface>()
.expect("Failed to downcast Surface to X11Surface"),
);
conn.configure_window(
x11surface.try_into().expect("Failed to convert XID"),
&w_conf,
)
.expect("failed to configure window...");
conn.flush().expect("failed to flush");
// fix (dock:294469): Gdk-CRITICAL **: 19:19:25.652: gdk_surface_request_layout: assertion 'frame_clock' failed
s.request_layout();
unsafe { x::set_position(&display, &surface,
(monitor_x + monitor_width / 2 - width / 2).clamp(0, monitor_x + monitor_width - 1),
(monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1));}
}
});

View file

@ -9,7 +9,6 @@ use gtk4::StyleContext;
use once_cell::sync::OnceCell;
use pop_launcher_service::IpcClient;
use tokio::sync::mpsc;
use x11rb::rust_connection::RustConnection;
use crate::utils::BoxedSearchResult;
@ -23,7 +22,6 @@ mod window;
const NUM_LAUNCHER_ITEMS: u8 = 10;
static TX: OnceCell<mpsc::Sender<Event>> = OnceCell::new();
static X11_CONN: OnceCell<RustConnection> = OnceCell::new();
pub enum Event {
Response(pop_launcher::Response),
@ -85,13 +83,6 @@ fn main() {
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");
std::process::exit(1);
};
let window = Window::new(app);
window.show();

View file

@ -1,7 +1,5 @@
use cascade::cascade;
use gdk4::Rectangle;
use gdk4_x11::X11Display;
use gdk4_x11::X11Surface;
use glib::Object;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
@ -11,16 +9,12 @@ use gtk4::ListView;
use gtk4::Orientation;
use gtk4::{gio, glib};
use gtk4::{Application, SignalListItemFactory};
use x11rb::connection::Connection;
use x11rb::protocol::xproto;
use x11rb::protocol::xproto::ConnectionExt;
use libcosmic::x;
use crate::search_result_row::SearchResultRow;
use crate::SearchResultObject;
use crate::TX;
use crate::X11_CONN;
mod imp;
@ -198,7 +192,6 @@ impl Window {
);
}
let resize = glib::clone!(@weak window => move || {
let s = window.surface();
let height = window.height();
let width = window.width();
@ -213,21 +206,9 @@ impl Window {
// dbg!(monitor_height);
// dbg!(width);
// dbg!(height);
let w_conf = xproto::ConfigureWindowAux::default()
.x((monitor_x + monitor_width / 2 - width / 2).clamp(0, monitor_x + monitor_width - 1))
.y((monitor_y + monitor_height / 2 - height / 2).clamp(0, monitor_y + monitor_height - 1));
let conn = X11_CONN.get().expect("Failed to get X11_CONN");
let x11surface = gdk4_x11::X11Surface::xid(
&s.clone().downcast::<X11Surface>()
.expect("Failed to downcast Surface to X11Surface"),
);
conn.configure_window(
x11surface.try_into().expect("Failed to convert XID"),
&w_conf,
)
.expect("failed to configure window...");
conn.flush().expect("failed to flush");
unsafe { x::set_position(&display, &surface,
(monitor_x + monitor_width / 2 - width / 2).clamp(0, monitor_x + monitor_width - 1),
(monitor_y + monitor_height / 2 - height / 2).clamp(0, monitor_y + monitor_height - 1))};
}
});
let s = window.surface();