mirror of
https://github.com/wez/wezterm.git
synced 2024-12-18 19:01:36 +03:00
c778307b0e
The opengl based render first clears the window to the background color and then renders the cells over the top. on macOS I noticed a weird lighter strip to the bottom and right of the window and ran it down to the initial clear: our colors are SRGB rather than plain RGB and the discrepancy from rendering SRGB as RGB results in the color being made a brighter shade. This was less noticeable for black backgrounds.
76 lines
1.8 KiB
Rust
76 lines
1.8 KiB
Rust
use ::window::*;
|
|
use std::any::Any;
|
|
|
|
struct MyWindow {
|
|
allow_close: bool,
|
|
cursor_pos: (u16, u16),
|
|
}
|
|
|
|
impl WindowCallbacks for MyWindow {
|
|
fn destroy(&mut self) {
|
|
Connection::get().unwrap().terminate_message_loop();
|
|
}
|
|
|
|
fn paint(&mut self, context: &mut dyn PaintContext) {
|
|
// Window contents are black in software mode
|
|
context.clear(Color::rgb(0x0, 0x0, 0x0));
|
|
}
|
|
|
|
#[cfg(feature = "opengl")]
|
|
fn paint_opengl(&mut self, frame: &mut glium::Frame) {
|
|
// Window contents are gray in opengl mode
|
|
use glium::Surface;
|
|
frame.clear_color_srgb(0.15, 0.15, 0.15, 1.0);
|
|
}
|
|
|
|
fn as_any(&mut self) -> &mut dyn Any {
|
|
self
|
|
}
|
|
}
|
|
|
|
fn spawn_window() -> anyhow::Result<()> {
|
|
let win = Window::new_window(
|
|
"myclass",
|
|
"the title",
|
|
800,
|
|
600,
|
|
Box::new(MyWindow {
|
|
allow_close: false,
|
|
cursor_pos: (100, 200),
|
|
}),
|
|
)?;
|
|
|
|
#[cfg(feature = "opengl")]
|
|
win.enable_opengl(|_any, _window, maybe_ctx| {
|
|
match maybe_ctx {
|
|
Ok(_ctx) => eprintln!("opengl enabled!"),
|
|
Err(err) => eprintln!("opengl fail: {}", err),
|
|
};
|
|
Ok(())
|
|
});
|
|
|
|
#[cfg(not(feature = "opengl"))]
|
|
eprintln!(
|
|
"opengl not enabled at compile time: cargo run --feature opengl --example basic_opengl"
|
|
);
|
|
|
|
win.show();
|
|
win.apply(|myself, _win| {
|
|
if let Some(myself) = myself.downcast_ref::<MyWindow>() {
|
|
eprintln!(
|
|
"got myself; allow_close={}, cursor_pos:{:?}",
|
|
myself.allow_close, myself.cursor_pos
|
|
);
|
|
}
|
|
Ok(())
|
|
});
|
|
Ok(())
|
|
}
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
pretty_env_logger::init();
|
|
let conn = Connection::init()?;
|
|
spawn_window()?;
|
|
conn.run_message_loop()
|
|
}
|