refactor x11
This commit is contained in:
parent
28151177d0
commit
eefe17e3c6
2 changed files with 15 additions and 20 deletions
|
|
@ -2,8 +2,6 @@ use gtk4::gdk::Display;
|
||||||
use gtk4::prelude::*;
|
use gtk4::prelude::*;
|
||||||
use gtk4::CssProvider;
|
use gtk4::CssProvider;
|
||||||
use gtk4::StyleContext;
|
use gtk4::StyleContext;
|
||||||
use once_cell::sync::OnceCell;
|
|
||||||
use x11rb::rust_connection::RustConnection;
|
|
||||||
|
|
||||||
use window::AppLibraryWindow;
|
use window::AppLibraryWindow;
|
||||||
|
|
||||||
|
|
@ -14,8 +12,6 @@ mod group_grid;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
static X11_CONN: OnceCell<RustConnection> = OnceCell::new();
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = gtk4::Application::new(Some("com.cosmic.app_library"), Default::default());
|
let app = gtk4::Application::new(Some("com.cosmic.app_library"), Default::default());
|
||||||
app.connect_startup(|_app| {
|
app.connect_startup(|_app| {
|
||||||
|
|
@ -45,10 +41,6 @@ fn load_css() {
|
||||||
fn build_ui(app: >k4::Application) {
|
fn build_ui(app: >k4::Application) {
|
||||||
// Create a new custom window and show it
|
// Create a new custom window and show it
|
||||||
let window = AppLibraryWindow::new(app);
|
let window = AppLibraryWindow::new(app);
|
||||||
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);
|
|
||||||
};
|
|
||||||
window.show();
|
window.show();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use crate::app_grid::AppGrid;
|
||||||
|
use crate::group_grid::GroupGrid;
|
||||||
use cascade::cascade;
|
use cascade::cascade;
|
||||||
use gdk4::Rectangle;
|
use gdk4::Rectangle;
|
||||||
use gdk4_x11::X11Display;
|
use gdk4_x11::X11Display;
|
||||||
|
|
@ -13,15 +17,10 @@ use gtk4::Orientation;
|
||||||
use gtk4::SearchEntry;
|
use gtk4::SearchEntry;
|
||||||
use gtk4::Separator;
|
use gtk4::Separator;
|
||||||
use gtk4::{gio, glib};
|
use gtk4::{gio, glib};
|
||||||
use x11rb::connection::Connection;
|
|
||||||
use x11rb::protocol::xproto;
|
|
||||||
use x11rb::protocol::xproto::ConnectionExt;
|
|
||||||
|
|
||||||
use libcosmic::x;
|
use libcosmic::x;
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use crate::app_grid::AppGrid;
|
use x11rb::connection::Connection;
|
||||||
use crate::group_grid::GroupGrid;
|
use x11rb::protocol::xproto::*;
|
||||||
use crate::X11_CONN;
|
|
||||||
|
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
|
|
@ -151,6 +150,10 @@ impl AppLibraryWindow {
|
||||||
|
|
||||||
window.connect_realize(move |window| {
|
window.connect_realize(move |window| {
|
||||||
if let Some((display, surface)) = x::get_window_x11(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...
|
// ignore all x11 errors...
|
||||||
let xdisplay = display
|
let xdisplay = display
|
||||||
.clone()
|
.clone()
|
||||||
|
|
@ -166,7 +169,7 @@ impl AppLibraryWindow {
|
||||||
&[x::Atom::new(&display, "_NET_WM_WINDOW_TYPE_DIALOG").unwrap()],
|
&[x::Atom::new(&display, "_NET_WM_WINDOW_TYPE_DIALOG").unwrap()],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let resize = glib::clone!(@weak window => move || {
|
let resize = glib::clone!(@weak window, @strong x11rb_conn => move || {
|
||||||
let s = window.surface().expect("Failed to get Surface for AppLibraryWindow");
|
let s = window.surface().expect("Failed to get Surface for AppLibraryWindow");
|
||||||
let height = window.height();
|
let height = window.height();
|
||||||
let width = window.width();
|
let width = window.width();
|
||||||
|
|
@ -185,15 +188,15 @@ impl AppLibraryWindow {
|
||||||
// dbg!(monitor_height);
|
// dbg!(monitor_height);
|
||||||
// dbg!(width);
|
// dbg!(width);
|
||||||
// dbg!(height);
|
// dbg!(height);
|
||||||
let w_conf = xproto::ConfigureWindowAux::default()
|
let w_conf = ConfigureWindowAux::default()
|
||||||
.x(monitor_x + monitor_width / 2 - width / 2)
|
.x(monitor_x + monitor_width / 2 - width / 2)
|
||||||
.y(monitor_y + monitor_height / 2 - height / 2);
|
.y(monitor_y + monitor_height / 2 - height / 2);
|
||||||
let conn = X11_CONN.get().expect("Failed to get X11_CONN");
|
|
||||||
|
|
||||||
let x11surface = gdk4_x11::X11Surface::xid(
|
let x11surface = gdk4_x11::X11Surface::xid(
|
||||||
&s.clone().downcast::<X11Surface>()
|
&s.clone().downcast::<X11Surface>()
|
||||||
.expect("Failed to downcast Surface to X11Surface"),
|
.expect("Failed to downcast Surface to X11Surface"),
|
||||||
);
|
);
|
||||||
|
let conn = x11rb_conn.get().unwrap();
|
||||||
conn.configure_window(
|
conn.configure_window(
|
||||||
x11surface.try_into().expect("Failed to convert XID"),
|
x11surface.try_into().expect("Failed to convert XID"),
|
||||||
&w_conf,
|
&w_conf,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue