From ae2f100b380671e347b2517d0017eabc26ef90bf Mon Sep 17 00:00:00 2001 From: "Brian J. Tarricone" Date: Mon, 25 Sep 2023 11:08:27 -0700 Subject: [PATCH] Ensure gtk apps only run on X11 --- dialog-gtk3/src/main.rs | 8 ++++++++ settings/src/main.rs | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dialog-gtk3/src/main.rs b/dialog-gtk3/src/main.rs index f6d564b..50b784b 100644 --- a/dialog-gtk3/src/main.rs +++ b/dialog-gtk3/src/main.rs @@ -77,6 +77,14 @@ fn main() -> anyhow::Result<()> { init_logging("BSCREENSAVER_DIALOG_GTK3_LOG"); 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 new_login_command = if config.new_login_command == NewLoginCommand::Disabled { diff --git a/settings/src/main.rs b/settings/src/main.rs index e8bc73d..a68d839 100644 --- a/settings/src/main.rs +++ b/settings/src/main.rs @@ -1,7 +1,7 @@ use gtk::{glib, prelude::*}; use glib::clone; 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}; @@ -18,6 +18,14 @@ fn main() -> anyhow::Result<()> { init_logging("BSCREENSAVER_SETTINGS"); 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() .application_id("org.spurint.bscreensaver-settings") .build();