//! Drive squeekboard visibility over sm.puri.OSK0 as text fields gain/lose focus.

use zbus::blocking::Connection;

pub fn set_visible( visible: bool )
{
	std::thread::spawn( move ||
	{
		let conn = match Connection::session()
		{
			Ok( c )  => c,
			Err( e ) =>
			{
				tracing::warn!( "OSK D-Bus connect failed: {e}" );
				return;
			}
		};
		if let Err( e ) = conn.call_method(
			Some( "sm.puri.OSK0" ),
			"/sm/puri/OSK0",
			Some( "sm.puri.OSK0" ),
			"SetVisible",
			&( visible, ),
		)
		{
			tracing::warn!( "OSK SetVisible({visible}) failed: {e}" );
		}
	} );
}
