Skip to content

Commit

Permalink
Configure window position
Browse files Browse the repository at this point in the history
  • Loading branch information
l4l committed Dec 4, 2020
1 parent b519971 commit 5387c5f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Sample configuration:
# ~~Global values, used as fallback if needed
width = 400
height = 512
# if unset, places window at the center
# window_offsets = [500, -50] # in format [top_offset, left_offset]
# font = "DejaVu Sans"
bg_color = 0x272822ee # ~~colors are specified in 0xRRGGBBAA format
# font_color = 0xf8f8f2ff
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod params;
pub struct Config {
width: Option<u32>,
height: Option<u32>,
window_offsets: Option<(i32, i32)>,
term: Option<String>,
font: Option<String>,
bg_color: Option<u32>,
Expand Down
1 change: 1 addition & 0 deletions src/config/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl<'a> From<&'a Config> for SurfaceParams {
SurfaceParams {
width: config.width.unwrap_or(400),
height: config.height.unwrap_or(512),
window_offsets: config.window_offsets,
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum EventStatus {
pub struct Params {
pub width: u32,
pub height: u32,
pub window_offsets: Option<(i32, i32)>,
}

pub struct Surface {
Expand Down Expand Up @@ -53,6 +54,12 @@ impl Surface {
let width = params.width;
let height = params.height;

if let Some((top_offset, left_offset)) = params.window_offsets {
let mut anchor = zwlr_layer_surface_v1::Anchor::Left;
anchor.insert(zwlr_layer_surface_v1::Anchor::Top);
layer_surface.set_anchor(anchor);
layer_surface.set_margin(top_offset, 0, 0, left_offset);
}
layer_surface.set_size(width, height);
layer_surface.set_keyboard_interactivity(1);

Expand Down

0 comments on commit 5387c5f

Please sign in to comment.