Skip to content

Commit

Permalink
Configure window width/height
Browse files Browse the repository at this point in the history
  • Loading branch information
l4l committed Dec 4, 2020
1 parent 40a361a commit b519971
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Sample configuration:
```toml
# This file should be placed at ~/.config/yofi/yofi.config

# ~~Fallback values
# ~~Global values, used as fallback if needed
width = 400
height = 512
# font = "DejaVu Sans"
bg_color = 0x272822ee # ~~colors are specified in 0xRRGGBBAA format
# font_color = 0xf8f8f2ff
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ mod params;

#[derive(Default, Serialize, Deserialize)]
pub struct Config {
width: Option<u32>,
height: Option<u32>,
term: Option<String>,
font: Option<String>,
bg_color: Option<u32>,
Expand Down
10 changes: 10 additions & 0 deletions src/config/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use raqote::SolidSource;

use super::Config;
use crate::draw::{BgParams, InputTextParams, ListParams};
use crate::surface::Params as SurfaceParams;

impl<'a> From<&'a Config> for InputTextParams {
fn from(config: &'a Config) -> InputTextParams {
Expand Down Expand Up @@ -73,6 +74,15 @@ impl<'a> From<&'a Config> for BgParams {
}
}

impl<'a> From<&'a Config> for SurfaceParams {
fn from(config: &'a Config) -> SurfaceParams {
SurfaceParams {
width: config.width.unwrap_or(400),
height: config.height.unwrap_or(512),
}
}
}

std::thread_local! {
static FONT: Font = SystemSource::new()
.select_best_match(&[FamilyName::SansSerif], &Properties::new())
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
.expect("Initial roundtrip failed!");
let mut event_loop = calloop::EventLoop::<()>::new().unwrap();

let mut surface = surface::Surface::new(&env);
let mut surface = surface::Surface::new(&env, config.param());

let (_input, key_stream) = input::InputHandler::new(&env, &event_loop);

Expand Down
11 changes: 8 additions & 3 deletions src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub enum EventStatus {
Idle,
}

pub struct Params {
pub width: u32,
pub height: u32,
}

pub struct Surface {
surface: wl_surface::WlSurface,
layer_surface: Main<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1>,
Expand All @@ -30,7 +35,7 @@ pub struct Surface {
}

impl Surface {
pub fn new(env: &Environment<super::Env>) -> Self {
pub fn new(env: &Environment<super::Env>, params: Params) -> Self {
let pools = env
.create_double_pool(|_| {})
.expect("Failed to create a memory pool!");
Expand All @@ -45,8 +50,8 @@ impl Surface {
"yofi".to_owned(),
);

let width = 400;
let height = 512;
let width = params.width;
let height = params.height;

layer_surface.set_size(width, height);
layer_surface.set_keyboard_interactivity(1);
Expand Down

0 comments on commit b519971

Please sign in to comment.