aboutsummaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-10-27 10:05:04 -0700
committerJoe Wilm <joe@jwilm.com>2016-10-27 10:16:08 -0700
commit06ea6c8e565af0fdddc4de80f59435cfe05670c2 (patch)
tree76f5b8b667862da0bde080fc694761052bf46ff5 /src/renderer
parent0958c0f0f28664fe2f48ad1b552b69b0ced731c1 (diff)
downloadalacritty-06ea6c8e565af0fdddc4de80f59435cfe05670c2.tar.gz
alacritty-06ea6c8e565af0fdddc4de80f59435cfe05670c2.zip
Move config reloading to separate thread
This feature was previously shoved into the renderer due to initial proof of concept. Now, providing config updates to other systems is possible. This will be especially important for key bindings!
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/mod.rs61
1 files changed, 12 insertions, 49 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index eccbb8af..bbd07fe5 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -42,37 +42,9 @@ pub trait LoadGlyph {
}
enum Msg {
- ConfigReload(Config),
ShaderReload,
}
-/// Colors!
-///
-/// FIXME this is obviously bad; need static for reload logic for now. Hacking something in with
-/// minimal effort and will improve later.
-///
-/// Only renderer is allowed to access this to prevent race conditions
-static mut COLORS: [Rgb; 18] = [
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
- Rgb { r: 0, g: 0, b: 0 },
-];
-
/// Text drawing program
///
/// Uniforms are prefixed with "u", and vertex attributes are prefixed with "a".
@@ -278,6 +250,7 @@ pub struct RenderApi<'a> {
batch: &'a mut Batch,
atlas: &'a mut Vec<Atlas>,
program: &'a mut ShaderProgram,
+ colors: &'a [Rgb; 18],
}
#[derive(Debug)]
@@ -500,7 +473,6 @@ impl QuadRenderer {
let mut watcher = Watcher::new(tx).unwrap();
watcher.watch(TEXT_SHADER_F_PATH).expect("watch fragment shader");
watcher.watch(TEXT_SHADER_V_PATH).expect("watch vertex shader");
- watcher.watch("/home/jwilm/.alacritty.yml").expect("watch alacritty yml");
loop {
let event = rx.recv().expect("watcher event");
@@ -517,15 +489,8 @@ impl QuadRenderer {
println!("failed to establish watch on {:?}: {:?}", path, err);
}
- if path == ::std::path::Path::new("/home/jwilm/.alacritty.yml") {
- if let Ok(config) = Config::load() {
- msg_tx.send(Msg::ConfigReload(config))
- .expect("msg send ok");
- };
- } else {
- msg_tx.send(Msg::ShaderReload)
- .expect("msg send ok");
- }
+ msg_tx.send(Msg::ShaderReload)
+ .expect("msg send ok");
}
}
}
@@ -545,27 +510,24 @@ impl QuadRenderer {
rx: msg_rx,
};
- unsafe {
- COLORS = config.color_list();
- }
-
let atlas = Atlas::new(ATLAS_SIZE);
renderer.atlas.push(atlas);
renderer
}
+ pub fn update_config(&mut self, config: &Config) {
+ self.colors = config.color_list();
+ self.program.activate();
+ self.program.set_color_uniforms(&self.colors);
+ self.program.deactivate();
+ }
+
pub fn with_api<F, T>(&mut self, props: &term::SizeInfo, func: F) -> T
where F: FnOnce(RenderApi) -> T
{
while let Ok(msg) = self.rx.try_recv() {
match msg {
- Msg::ConfigReload(config) => {
- self.colors = config.color_list();
- self.program.activate();
- self.program.set_color_uniforms(&self.colors);
- self.program.deactivate();
- },
Msg::ShaderReload => {
self.reload_shaders(props.width as u32, props.height as u32);
}
@@ -587,6 +549,7 @@ impl QuadRenderer {
batch: &mut self.batch,
atlas: &mut self.atlas,
program: &mut self.program,
+ colors: &self.colors,
});
unsafe {
@@ -732,7 +695,7 @@ impl<'a> RenderApi<'a> {
glyph_cache: &mut GlyphCache
) {
// TODO should be built into renderer
- let color = unsafe { COLORS[::ansi::Color::Background as usize] };
+ let color = self.colors[::ansi::Color::Background as usize];
unsafe {
gl::ClearColor(
color.r as f32 / 255.0,