Skip to content

Commit

Permalink
add --window-gaps CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
Antikyth committed Nov 21, 2023
1 parent 1b1e758 commit a14735e
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 12 deletions.
26 changes: 26 additions & 0 deletions .run/Run AquariWM (Wayland).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public -->
<!-- License, v. 2.0. If a copy of the MPL was not distributed with this -->
<!-- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->

<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run AquariWM (Wayland)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run --package aquariwm --bin aquariwm -- --testing wayland" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<envs>
<env name="RUST_LOG" value="warn,aquariwm=debug" />
<env name="TERM" value="kitty" />
</envs>
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>
26 changes: 26 additions & 0 deletions .run/Run AquariWM (X11).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public -->
<!-- License, v. 2.0. If a copy of the MPL was not distributed with this -->
<!-- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->

<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run AquariWM (X11)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run --package aquariwm --bin aquariwm -- --testing x11" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<envs>
<env name="RUST_LOG" value="warn,aquariwm=debug" />
<env name="TERM" value="kitty" />
</envs>
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub struct Cli {
#[arg(long = "no-testing", alias = "no-test", overrides_with = "testing")]
pub no_testing: bool,

#[arg(long = "window-gap", alias = "gap")]
/// The gap between windows in a tiling layout.
pub window_gap: Option<u32>,

#[command(subcommand)]
pub subcommand: Subcommand,
}
Expand Down
4 changes: 3 additions & 1 deletion src/display_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub use wayland::Wayland;
#[cfg(feature = "x11")]
pub use x11::X11;

use crate::layout::LayoutSettings;

#[cfg(feature = "wayland")]
pub mod wayland;
#[cfg(feature = "x11")]
Expand All @@ -24,7 +26,7 @@ pub trait DisplayServer {
const NAME: &'static str;

/// Runs the AquariWM implementation for this display server.
fn run(testing: bool) -> Self::Output;
fn run(testing: bool, settings: LayoutSettings) -> Self::Output;

/// Returns AquariWM's title, formatted with the display server [`NAME`].
///
Expand Down
9 changes: 6 additions & 3 deletions src/display_server/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use smithay::{
use thiserror::Error;
use tracing::{event, span, Level};

use crate::display_server::{DisplayServer, SyncDisplayServer};
use crate::{
display_server::{DisplayServer, SyncDisplayServer},
layout::LayoutSettings,
};

pub mod grabs;
mod input;
Expand Down Expand Up @@ -62,14 +65,14 @@ impl DisplayServer for Wayland {
type Output = Result<(), Error>;
const NAME: &'static str = "Wayland";

fn run(testing: bool) -> Result<(), Error> {
fn run(testing: bool, settings: LayoutSettings) -> Result<(), Error> {
// Log initialisation.
let init_span = span!(Level::INFO, "Initialising").entered();

// Create an event loop for the compositor to run with.
let mut event_loop = <EventLoop<state::WaylandState>>::try_new()?;
// Initialise the AquariWM state.
let mut state = state::WaylandState::new(Display::new()?, &mut event_loop);
let mut state = state::WaylandState::new(Display::new()?, &mut event_loop, settings);

// Init winit for testing if the testing feature is enabled.
#[cfg(feature = "testing")]
Expand Down
4 changes: 2 additions & 2 deletions src/display_server/wayland/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ delegate_shm!(WaylandState);
// }}}

impl WaylandState {
pub fn new(display: Display<Self>, event_loop: &mut EventLoop<Self>) -> Self {
pub fn new(display: Display<Self>, event_loop: &mut EventLoop<Self>, settings: LayoutSettings) -> Self {
let start_time = time::Instant::now();
let display_handle = display.handle();

Expand All @@ -319,7 +319,7 @@ impl WaylandState {
space: Space::default(),
loop_signal: event_loop.get_signal(),

aquariwm_state: crate::state::AquariWm::new(LayoutSettings::default()),
aquariwm_state: crate::state::AquariWm::new(settings),

// A whole bunch of Smithay-related state.
compositor_state: CompositorState::new::<Self>(&display_handle),
Expand Down
4 changes: 2 additions & 2 deletions src/display_server/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl DisplayServer for X11 {
type Output = impl Future<Output = Result<(), Error>>;
const NAME: &'static str = "X11";

fn run(testing: bool) -> Self::Output {
fn run(testing: bool, settings: LayoutSettings) -> Self::Output {
async move {
let init_span = span!(Level::INFO, "Initialisation").entered();

Expand Down Expand Up @@ -167,7 +167,7 @@ impl DisplayServer for X11 {
width as u32,
height as u32,
wm.query_windows().await?,
LayoutSettings::default(),
settings,
);

if testing {
Expand Down
2 changes: 1 addition & 1 deletion src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct LayoutSettings {
///
/// [nodes]: Node
/// [tiling layout]: TilingLayout
#[default = 10]
#[default = 15]
pub window_gap: u32,
}

Expand Down
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{env, ffi::OsString, io, process};
use clap::Parser;
use thiserror::Error;

use crate::display_server::DisplayServer;
use crate::{display_server::DisplayServer, layout::LayoutSettings};

mod cli;
pub mod display_server;
Expand Down Expand Up @@ -49,16 +49,21 @@ fn main() -> Result<()> {
// Whether testing is enabled.
let testing = args.testing();

let settings = match args.window_gap {
Some(window_gap) => LayoutSettings::new().window_gap(window_gap),
None => LayoutSettings::default(),
};

match &args.subcommand {
#[cfg(feature = "wayland")]
cli::Subcommand::Wayland => Ok(display_server::Wayland::run(testing)?),
cli::Subcommand::Wayland => Ok(display_server::Wayland::run(testing, settings)?),

#[cfg(feature = "x11")]
cli::Subcommand::X11 => Ok(tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async { display_server::X11::run(testing).await })?),
.block_on(async { display_server::X11::run(testing, settings).await })?),
}
}

Expand Down

0 comments on commit a14735e

Please sign in to comment.