Skip to content

Commit

Permalink
Implement new window layouter
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschwarzer committed Aug 5, 2023
1 parent a80f489 commit 8aaf4f0
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/daemon/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(clippy::implicit_return)]
#![allow(clippy::needless_return)]
use std::cmp::max;
use std::{
ffi::c_void,
io, mem,
Expand Down Expand Up @@ -78,7 +79,7 @@ impl Daemon {
// The daemon console can be treated as a client console when it comes
// to figuring out where to put it on the screen.
// TODO: the daemon console should always be on the bottom left
let (x, y, width, height) = determine_client_spacial_attributes(
let (x, y, width, height) = determine_client_spatial_attributes(
number_of_consoles,
number_of_consoles,
&workspace_area,
Expand Down Expand Up @@ -157,18 +158,41 @@ impl Daemon {
}
}

fn determine_client_spacial_attributes(
fn determine_client_spatial_attributes(
index: i32,
number_of_consoles: i32,
workspace_area: &workspace::WorkspaceArea,
) -> (i32, i32, i32, i32) {
// FIXME: if number of hosts is < 3 or =5 determination of client spacial attributes falls apart
let height_width_ratio = workspace_area.height as f64 / workspace_area.width as f64;
let number_of_columns = (number_of_consoles as f64 / height_width_ratio).sqrt() as i32;
let console_width = workspace_area.width / number_of_columns;
let console_height = (console_width as f64 * height_width_ratio) as i32;
let x = workspace_area.width / number_of_columns * (index % number_of_columns);
let y = index / number_of_columns * console_height;
let aspect_ratio = workspace_area.width as f64 / workspace_area.height as f64;

const ASPECT_RATIO_ADJUSTMENT: f64 = 0.5;

let grid_columns = max(
((number_of_consoles as f64).sqrt() * (aspect_ratio + ASPECT_RATIO_ADJUSTMENT)) as i32,
1,
);
let grid_rows = max(
(number_of_consoles as f64 / grid_columns as f64).ceil() as i32,
1,
);

let grid_column_index = index % grid_columns;
let grid_row_index = index / grid_columns;

let is_last_row = grid_row_index == grid_rows - 1;
let last_row_console_count = number_of_consoles % grid_columns;

let console_width = if is_last_row && last_row_console_count != 0 {
workspace_area.width / last_row_console_count
} else {
workspace_area.width / grid_columns
};

let console_height = workspace_area.height / grid_rows;

let x = grid_column_index * console_width;
let y = grid_row_index * console_height;

return (
workspace_area.x + x,
workspace_area.y + y,
Expand Down Expand Up @@ -283,7 +307,7 @@ async fn launch_clients(
let _username = username.clone();
let process_ids_arc = Arc::clone(&process_ids);
let future = tokio::spawn(async move {
let (x, y, width, height) = determine_client_spacial_attributes(
let (x, y, width, height) = determine_client_spatial_attributes(
index as i32,
number_of_consoles,
&workspace_area,
Expand Down

0 comments on commit 8aaf4f0

Please sign in to comment.