Skip to content

Commit

Permalink
feat: show display name when select screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Dec 20, 2023
1 parent c9507a3 commit 83598ff
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
21 changes: 19 additions & 2 deletions libwaysip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,30 @@ impl AreaInfo {

impl SecondState {
fn redraw_screen(&self) {
for ((index, info), ZXdgOutputInfo { width, height, .. }) in self
for (
(index, info),
ZXdgOutputInfo {
width,
height,
start_x,
start_y,
name,
description,
..
},
) in self
.wl_surfaces
.iter()
.enumerate()
.zip(self.zxdgoutputs.iter())
{
info.redraw_select_screen(self.current_screen == index, (*width, *height));
info.redraw_select_screen(
self.current_screen == index,
(*width, *height),
(*start_x, *start_y),
name,
description,
);
}
}
fn redraw(&self) {
Expand Down
36 changes: 34 additions & 2 deletions libwaysip/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,49 @@ use std::fs::File;
use super::LayerSurfaceInfo;

const FONT_FAMILY: &str = "Sans";
const FONT_SIZE: i32 = 10;
const FONT_SIZE: i32 = 20;

impl LayerSurfaceInfo {
pub fn redraw_select_screen(&self, is_selected: bool, (width, height): (i32, i32)) {
pub fn redraw_select_screen(
&self,
is_selected: bool,
(width, height): (i32, i32),
(start_x, start_y): (i32, i32),
name: &str,
descriptin: &str,
) {
let cairoinfo = &self.cairo_t;
cairoinfo.set_operator(cairo::Operator::Source);
let color = if is_selected { 0. } else { 0.4 };
let alpha = if is_selected { 0. } else { 0.5 };
cairoinfo.set_source_rgba(color, color, color, alpha);
cairoinfo.paint().unwrap();

cairoinfo.set_source_rgb(0.3_f64, 0_f64, 0_f64);

let font_size = FONT_SIZE;
let pangolayout = pangocairo::create_layout(cairoinfo);
let mut desc = pango::FontDescription::new();
desc.set_family(FONT_FAMILY);
desc.set_weight(pango::Weight::Bold);

desc.set_size(font_size * pango::SCALE);
pangolayout.set_font_description(Some(&desc));

let name_txt = format!("{name} {descriptin}");
pangolayout.set_text(&name_txt);
cairoinfo.save().unwrap();
cairoinfo.move_to(10., 60.);
pangocairo::show_layout(cairoinfo, &pangolayout);
cairoinfo.restore().unwrap();

let pos_txt = format!("pos: {start_x}, {start_y}");
pangolayout.set_text(&pos_txt);
cairoinfo.save().unwrap();
cairoinfo.move_to(10., 90.);
pangocairo::show_layout(cairoinfo, &pangolayout);
cairoinfo.restore().unwrap();

self.wl_surface.attach(Some(&self.buffer), 0, 0);
self.wl_surface.damage(0, 0, width, height);
self.wl_surface.commit();
Expand Down

0 comments on commit 83598ff

Please sign in to comment.