Fix launcher example position

This commit is contained in:
Jeremy Soller 2021-11-16 10:32:29 -07:00
parent 38cb195351
commit 48f983cf22
No known key found for this signature in database
GPG key ID: E988B49EE78A7FB1
2 changed files with 39 additions and 52 deletions

View file

@ -7,6 +7,7 @@ edition = "2021"
cascade = "1" cascade = "1"
gdk4 = "0.3.1" gdk4 = "0.3.1"
gdk4-x11 = "0.3.0" gdk4-x11 = "0.3.0"
glib = "0.14.8"
gtk4 = "0.3.1" gtk4 = "0.3.1"
x11 = { version = "2", features = ["xlib"] } x11 = { version = "2", features = ["xlib"] }
# examples/launcher # examples/launcher

View file

@ -1,7 +1,5 @@
use gdk4 as gdk;
use gtk4 as gtk; use gtk4 as gtk;
use gdk::prelude::*;
use gtk::prelude::*; use gtk::prelude::*;
use libcosmic::x; use libcosmic::x;
use std::{ use std::{
@ -22,14 +20,6 @@ fn main() {
.build(); .build();
app.connect_activate(move |app| { app.connect_activate(move |app| {
let display = gdk::Display::default().unwrap();
let monitors = display.monitors().unwrap();
for i in 0..monitors.n_items() {
let monitor: gdk::Monitor = monitors.item(i).unwrap().downcast().unwrap();
let rect = monitor.geometry();
//TODO: get monitor with mouse cursor
if i == 0 {
let window = gtk::ApplicationWindow::builder() let window = gtk::ApplicationWindow::builder()
.application(app) .application(app)
.default_width(480) .default_width(480)
@ -54,9 +44,10 @@ fn main() {
}); });
} }
window.show(); // Setting the window to dialog type must happen between realize and show. Dialog windows
// show up centered on the display with the cursor, so we do not have to set position
if let Some((display, surface)) = x::get_window_x11(&window) { window.connect_realize(move |window| {
if let Some((display, surface)) = x::get_window_x11(window) {
unsafe { unsafe {
x::change_property( x::change_property(
&display, &display,
@ -65,19 +56,14 @@ fn main() {
x::PropMode::Replace, x::PropMode::Replace,
&[x::Atom::new(&display, "_NET_WM_WINDOW_TYPE_DIALOG").unwrap()], &[x::Atom::new(&display, "_NET_WM_WINDOW_TYPE_DIALOG").unwrap()],
); );
x::set_position(
&display,
&surface,
rect.x + (rect.width - 480) / 2,
rect.y + (rect.height - 440) / 2
);
} }
} else { } else {
println!("Failed to get X11 window"); println!("failed to get X11 window");
}
}
} }
}); });
window.show();
});
app.run(); app.run();
} }