Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ pub struct Args {
/// This argument does nothing when combined with --standalone, as a standalone instance can't have any apps running already.
#[arg(long, short)]
pub single: bool,
/// Grab exclusive keyboard focus, default is on demand keyboard capture (false)
#[arg(long, short = 'x')]
pub exclusive: bool,
}
22 changes: 15 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::cli::Args;
use crate::ipc::{AppSpawnOptions, ClientboundMessage, IpcC2S, ServerboundMessage};
use crate::mode::launch::Launcher;
use crate::polymodo::Polymodo;
use crate::server::BackendOptions;
use app::AppName;
use clap::Parser;
use slint::BackendSelector;
Expand All @@ -31,11 +32,18 @@ fn main() -> anyhow::Result<()> {
setup_logging()?;

let args = cli::Args::parse();
let backend_options = server::BackendOptions {
keyboard_interactivity: if args.exclusive {
KeyboardInteractivity::Exclusive
} else {
KeyboardInteractivity::OnDemand
},
};

if args.standalone {
log::info!("Starting standalone polymodo");

run_standalone()?;
run_standalone(backend_options)?;

std::process::exit(0);
}
Expand All @@ -59,7 +67,7 @@ fn main() -> anyhow::Result<()> {
// let's become that!
log::info!("Starting polymodo daemon");

server::run_server()?;
server::run_server(backend_options)?;

unreachable!();
}
Expand Down Expand Up @@ -105,8 +113,8 @@ async fn run_client(args: Args, client: IpcC2S) -> anyhow::Result<Option<String>
/// Run polymodo without connecting to a server and without setting up IPC.
///
/// This function returns when the spawned app dies.
pub fn run_standalone() -> anyhow::Result<()> {
setup_slint_backend();
pub fn run_standalone(backend_options: BackendOptions) -> anyhow::Result<()> {
setup_slint_backend(backend_options);

slint::invoke_from_event_loop(|| {
let poly = Polymodo::new().into_handle();
Expand Down Expand Up @@ -150,13 +158,13 @@ fn setup_logging() -> anyhow::Result<()> {
Ok(())
}

pub fn setup_slint_backend() {
pub fn setup_slint_backend(backend_options: BackendOptions) {
BackendSelector::default()
.with_winit_window_attributes_hook(|mut attrs| {
.with_winit_window_attributes_hook(move |mut attrs| {
attrs.platform = Some(Box::new(
WindowAttributesWayland::layer_shell()
.with_layer(Layer::Overlay)
.with_keyboard_interactivity(KeyboardInteractivity::OnDemand),
.with_keyboard_interactivity(backend_options.keyboard_interactivity),
));
attrs
})
Expand Down
5 changes: 4 additions & 1 deletion src/mode/launch/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ pub async fn load_icon(icon: &str) -> Option<StaticImage> {
icon.to_string()
} else {
let icon_string = icon.to_string();
let icon = ICONS.lock().unwrap().find_default_icon(icon_string.as_str(), 32, 1);
let icon = ICONS
.lock()
.unwrap()
.find_default_icon(icon_string.as_str(), 32, 1);

if let Some(icon) = icon {
icon.path().to_string_lossy().to_string()
Expand Down
9 changes: 7 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use crate::ipc::{AppSpawnOptions, ClientboundMessage, IpcS2C, IpcServer, ServerboundMessage};
use crate::mode::launch::Launcher;
use crate::polymodo::{Polymodo, PolymodoHandle};
use slint::winit_030::winit::platform::wayland::KeyboardInteractivity;

#[derive(Debug, derive_more::Error, derive_more::Display, derive_more::From)]
enum ServerError {
#[display("the server could not retrieve the app's result")]
FailedToGetResult,
}

pub fn run_server() -> anyhow::Result<std::convert::Infallible> {
crate::setup_slint_backend();
pub struct BackendOptions {
pub keyboard_interactivity: KeyboardInteractivity,
}

pub fn run_server(backend_options: BackendOptions) -> anyhow::Result<std::convert::Infallible> {
crate::setup_slint_backend(backend_options);

// set up the polymodo daemon socket for clients to connect to
let ipc_server = crate::ipc::create_ipc_server()?; // TODO: try? here is probably not good
Expand Down