1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00

fixup tests + wayland bits

This commit is contained in:
Wez Furlong 2021-07-10 18:07:16 -07:00
parent cc2b9507f8
commit 37ec16329e
3 changed files with 68 additions and 60 deletions

View File

@ -8,7 +8,6 @@ struct MyWindow {
allow_close: bool,
cursor_pos: Point,
dims: Dimensions,
win: Option<Window>,
gl: Option<Rc<glium::backend::Context>>,
}
@ -19,12 +18,7 @@ impl Drop for MyWindow {
}
impl MyWindow {
fn dispatch(&mut self, event: WindowEvent) {
let win = match self.win.as_ref() {
Some(win) => win,
None => return,
};
fn dispatch(&mut self, event: WindowEvent, win: &Window) {
match dbg!(event) {
WindowEvent::CloseRequested => {
eprintln!("can I close?");
@ -95,7 +89,6 @@ async fn spawn_window() -> Result<(), Box<dyn std::error::Error>> {
pixel_height: 600,
dpi: 0,
},
win: None,
gl: None,
}));
@ -107,15 +100,13 @@ async fn spawn_window() -> Result<(), Box<dyn std::error::Error>> {
600,
None,
fontconfig,
move |event| {
move |event, window| {
let mut state = cb_state.borrow_mut();
state.dispatch(event)
state.dispatch(event, window)
},
)
.await?;
state.borrow_mut().win.replace(win.clone());
eprintln!("before show");
win.show();
let gl = win.enable_opengl().await?;

View File

@ -3,6 +3,7 @@ use anyhow::Context;
use promise::spawn::spawn;
#[cfg(target_os = "macos")]
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use std::cell::RefCell;
use std::rc::Rc;
use wezterm_font::FontConfiguration;
@ -190,41 +191,14 @@ impl MyWindow {
gpu.swap_chain = gpu.device.create_swap_chain(&gpu.surface, &gpu.sc_desc);
}
}
}
async fn spawn_window() -> anyhow::Result<()> {
let fontconfig = Rc::new(FontConfiguration::new(
None,
::window::default_dpi() as usize,
)?);
let (win, events) =
Window::new_window("myclass", "the title", 800, 600, None, fontconfig).await?;
let mut state = MyWindow {
allow_close: false,
cursor_pos: Point::new(100, 200),
dims: Dimensions {
pixel_width: 800,
pixel_height: 600,
dpi: 0,
},
gpu: None,
render_pipeline: None,
};
eprintln!("before show");
win.show().await?;
state.enable_wgpu(&win).await?;
eprintln!("window is visible, do loop");
while let Ok(event) = events.recv().await {
fn dispatch(&mut self, event: WindowEvent, win: &Window) {
match event {
WindowEvent::CloseRequested => {
eprintln!("can I close?");
if state.allow_close {
if self.allow_close {
win.close();
} else {
state.allow_close = true;
self.allow_close = true;
}
}
WindowEvent::Destroyed => {
@ -235,7 +209,7 @@ async fn spawn_window() -> anyhow::Result<()> {
dimensions,
is_full_screen: _,
} => {
state.resize(dimensions);
self.resize(dimensions);
#[cfg(target_os = "macos")]
if let RawWindowHandle::MacOS(h) = win.raw_window_handle() {
use cocoa::base::{id, NO};
@ -246,11 +220,11 @@ async fn spawn_window() -> anyhow::Result<()> {
let () = msg_send![layer, setOpaque: NO];
}
state.paint()?;
self.paint()?;
}
}
WindowEvent::MouseEvent(event) => {
state.cursor_pos = event.coords;
self.cursor_pos = event.coords;
win.invalidate();
win.set_cursor(Some(MouseCursor::Arrow));
@ -264,11 +238,52 @@ async fn spawn_window() -> anyhow::Result<()> {
win.default_key_processing(key);
}
WindowEvent::NeedRepaint => {
state.paint()?;
self.paint().unwrap();
}
WindowEvent::Notification(_) | WindowEvent::FocusChanged(_) => {}
}
}
}
async fn spawn_window() -> anyhow::Result<()> {
let fontconfig = Rc::new(FontConfiguration::new(
None,
::window::default_dpi() as usize,
)?);
let state = Rc::new(RefCell::new(MyWindow {
allow_close: false,
cursor_pos: Point::new(100, 200),
dims: Dimensions {
pixel_width: 800,
pixel_height: 600,
dpi: 0,
},
gpu: None,
render_pipeline: None,
}));
let cb_state = Rc::clone(&state);
let win = Window::new_window(
"myclass",
"the title",
800,
600,
None,
fontconfig,
move |event, window| {
let mut state = cb_state.borrow_mut();
state.dispatch(event, window)
},
)
.await?;
eprintln!("before show");
win.show();
{
let mut state = state.borrow_mut();
state.enable_wgpu(&win).await?;
}
eprintln!("window is visible, do loop");
Ok(())
}

View File

@ -24,7 +24,8 @@ use wezterm_font::{FontConfiguration, FontMetrics, GlyphInfo, RasterizedGlyph};
fn color_to_paint(c: RgbColor) -> Paint<'static> {
let mut paint = Paint::default();
paint.set_color_rgba8(c.blue, c.green, c.red, 0xff);
let (red, green, blue) = c.to_tuple_rgb8();
paint.set_color_rgba8(blue, green, red, 0xff);
paint.anti_alias = true;
paint
}
@ -463,7 +464,8 @@ impl ConceptFrame {
let title_color = match self.active {
WindowState::Active => colors.active_titlebar_fg,
WindowState::Inactive => colors.inactive_titlebar_fg,
};
}
.to_tuple_rgba();
for info in infos {
if let Ok(mut glyph) = font.rasterize_glyph(info.glyph_pos, info.font_idx) {
@ -481,10 +483,9 @@ impl ConceptFrame {
} else {
// Apply the preferred title color
*p = ColorU8::from_rgba(
((b as f32 / 255.) * (title_color.red as f32 / 255.) * 255.) as u8,
((g as f32 / 255.) * (title_color.green as f32 / 255.) * 255.)
as u8,
((r as f32 / 255.) * (title_color.blue as f32 / 255.) * 255.) as u8,
((b as f32 / 255.) * (title_color.0 * 255.)) as u8,
((g as f32 / 255.) * (title_color.1 * 255.)) as u8,
((r as f32 / 255.) * (title_color.2 * 255.)) as u8,
a,
)
.premultiply();
@ -1190,17 +1191,18 @@ fn request_for_location_on_rmb(pointer_data: &PointerUserData) -> Option<FrameRe
// result is as transparent as the most transparent color
fn mix_colors(x: RgbColor, y: RgbColor) -> RgbColor {
#[inline]
fn gamma_mix(x: u8, y: u8) -> u8 {
let x = x as f32 / 255.0;
let y = y as f32 / 255.0;
fn gamma_mix(x: f32, y: f32) -> f32 {
let z = ((x * x + y * y) / 2.0).sqrt();
(z * 255.0) as u8
z
}
RgbColor::new(
gamma_mix(x.red, y.red),
gamma_mix(x.green, y.green),
gamma_mix(x.blue, y.blue),
let x = x.to_tuple_rgba();
let y = y.to_tuple_rgba();
RgbColor::new_f32(
gamma_mix(x.0, y.0),
gamma_mix(x.1, y.1),
gamma_mix(x.2, y.2),
)
}