Compare commits

..

2 Commits

Author SHA1 Message Date
ae2f100b38 Ensure gtk apps only run on X11 2023-09-25 12:00:42 -07:00
3c48ab1c7f Update dependencies 2023-09-25 12:00:42 -07:00
11 changed files with 852 additions and 599 deletions

1381
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,11 +10,3 @@ members = [
"systemd", "systemd",
"xcb-xembed", "xcb-xembed",
] ]
[patch.crates-io]
# git source needed until extension event error resolution fix is released
xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e" }
# xkb package depends on xcb 0.9
xkb = { git = "https://github.com/kelnos/rust-xkb", branch = "xcb-1.x" }
# Build error in v0.7.5 when x11 feature enabled
ffi = { package = "xkbcommon-sys", git = "https://github.com/kelnos/rust-xkbcommon-sys", branch = "release-0.7.x" }

View File

@ -5,11 +5,11 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1" anyhow = "1"
async-std = { version = "1.11", features = ["attributes"] } async-std = { version = "1", features = ["attributes"] }
async-xcb = { path = "../async-xcb" } async-xcb = { path = "../async-xcb" }
bscreensaver-command = { path = "../command" } bscreensaver-command = { path = "../command" }
bscreensaver-util = { path = "../util" } bscreensaver-util = { path = "../util" }
futures = "0.3" futures = "0.3"
log = "0.4" log = "0.4"
xcb = { version = "1", features = ["dpms"] } xcb = { version = "1", features = ["dpms"] }
zbus = "2" zbus = "3"

View File

@ -77,6 +77,14 @@ fn main() -> anyhow::Result<()> {
init_logging("BSCREENSAVER_DIALOG_GTK3_LOG"); init_logging("BSCREENSAVER_DIALOG_GTK3_LOG");
glib::log_set_default_handler(glib::rust_log_handler); glib::log_set_default_handler(glib::rust_log_handler);
// Can't use the rust version as it requires gtk_init() to be
// called first, but the underlying C function requires that
// it hasn't.
let backends = CString::new("x11").unwrap();
unsafe {
gtk::gdk::ffi::gdk_set_allowed_backends(backends.as_ptr());
};
let config = Configuration::load()?; let config = Configuration::load()?;
let new_login_command = let new_login_command =
if config.new_login_command == NewLoginCommand::Disabled { if config.new_login_command == NewLoginCommand::Disabled {

View File

@ -50,4 +50,5 @@ log = "0.4"
nix = "0.23" nix = "0.23"
xcb = { version = "1", features = ["randr", "xkb", "xfixes", "xinput"] } xcb = { version = "1", features = ["randr", "xkb", "xfixes", "xinput"] }
xcb-xembed = { path = "../xcb-xembed" } xcb-xembed = { path = "../xcb-xembed" }
xkb = { version = "0.2", features = ["x11"] } xkb = { version = "0.3", features = ["x11"] }
xkbcommon-sys = { version = "1", feature = "x11" }

View File

@ -2,6 +2,7 @@ pub(crate) mod monitor;
pub(crate) mod pidfd; pub(crate) mod pidfd;
pub mod screensaver; pub mod screensaver;
pub mod subservice; pub mod subservice;
pub mod xkb_ext;
use log::{debug, info}; use log::{debug, info};
use xcb::{x, XidNew}; use xcb::{x, XidNew};

View File

@ -21,7 +21,7 @@ use std::{
}; };
use xcb::{randr, x, xfixes, xinput}; use xcb::{randr, x, xfixes, xinput};
use bscreensaver::{screensaver::{BlankerState, CommandHandlers, Screensaver}, subservice::Subservices}; use bscreensaver::{screensaver::{BlankerState, CommandHandlers, Screensaver}, subservice::Subservices, xkb_ext};
use bscreensaver_util::{*, settings::Configuration}; use bscreensaver_util::{*, settings::Configuration};
const BLANKED_ARG: &str = "blanked"; const BLANKED_ARG: &str = "blanked";
@ -71,7 +71,7 @@ fn main() -> anyhow::Result<()> {
init_xfixes(&conn)?; init_xfixes(&conn)?;
init_xinput(&conn)?; init_xinput(&conn)?;
init_randr(&conn)?; init_randr(&conn)?;
xkb::x11::setup(&conn, xkb::x11::MIN_MAJOR_XKB_VERSION, xkb::x11::MIN_MINOR_XKB_VERSION, xkb::x11::NO_FLAGS) xkb_ext::x11_setup(&conn, xkb::x11::MIN_MAJOR_XKB_VERSION, xkb::x11::MIN_MINOR_XKB_VERSION)
.map_err(|_| anyhow::anyhow!("Failed to initialize XKB extension"))?; .map_err(|_| anyhow::anyhow!("Failed to initialize XKB extension"))?;
let helper_dir = PathBuf::from(env!("HELPER_DIR")); let helper_dir = PathBuf::from(env!("HELPER_DIR"));

28
locker/src/xkb_ext.rs Normal file
View File

@ -0,0 +1,28 @@
use std::mem::MaybeUninit;
#[inline]
pub fn x11_setup(connection: &xcb::Connection, major_version: u16, minor_version: u16) -> Result<(u16, u16, u8, u8), ()> {
let mut actual_major = MaybeUninit::uninit();
let mut actual_minor = MaybeUninit::uninit();
let mut base_event = MaybeUninit::uninit();
let mut base_error = MaybeUninit::uninit();
let ret = unsafe {
xkbcommon_sys::xkb_x11_setup_xkb_extension(
connection.get_raw_conn() as *mut _,
major_version,
minor_version,
xkbcommon_sys::XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS,
actual_major.as_mut_ptr(),
actual_minor.as_mut_ptr(),
base_event.as_mut_ptr(),
base_error.as_mut_ptr()
)
};
if ret != 1 {
Err(())
} else {
Ok(unsafe { (actual_major.assume_init(), actual_minor.assume_init(), base_event.assume_init(), base_error.assume_init()) })
}
}

View File

@ -1,7 +1,7 @@
use gtk::{glib, prelude::*}; use gtk::{glib, prelude::*};
use glib::clone; use glib::clone;
use log::warn; use log::warn;
use std::{env, process::exit, time::Duration}; use std::{env, process::exit, time::Duration, ffi::CString};
use bscreensaver_util::{init_logging, settings::Configuration, desktop::NewLoginCommand}; use bscreensaver_util::{init_logging, settings::Configuration, desktop::NewLoginCommand};
@ -18,6 +18,14 @@ fn main() -> anyhow::Result<()> {
init_logging("BSCREENSAVER_SETTINGS"); init_logging("BSCREENSAVER_SETTINGS");
let config = Configuration::load()?; let config = Configuration::load()?;
// Can't use the rust version as it requires gtk_init() to be
// called first, but the underlying C function requires that
// it hasn't.
let backends = CString::new("x11").unwrap();
unsafe {
gtk::gdk::ffi::gdk_set_allowed_backends(backends.as_ptr());
};
let app = gtk::Application::builder() let app = gtk::Application::builder()
.application_id("org.spurint.bscreensaver-settings") .application_id("org.spurint.bscreensaver-settings")
.build(); .build();

View File

@ -13,5 +13,5 @@ futures = "0.3"
log = "0.4" log = "0.4"
nix = "0.23" nix = "0.23"
xcb = "1" xcb = "1"
zbus = "2.2" zbus = "3"
logind-zbus = "3" logind-zbus = "3"

View File

@ -16,4 +16,4 @@ shell-words = "1"
toml = "0.5" toml = "0.5"
xcb = "1" xcb = "1"
xdg = "2" xdg = "2"
zbus = "2" zbus = "3"