Hide all output mode behind WLDASH_ALL_OUTPUTS=1

This commit is contained in:
Kenny Levinsen
2019-08-26 17:53:11 +02:00
parent 2f9534f75f
commit 560f92a64e
2 changed files with 75 additions and 41 deletions
+58 -30
View File
@@ -42,10 +42,11 @@ struct AppInner {
shell: Option<zwlr_layer_shell_v1::ZwlrLayerShellV1>, shell: Option<zwlr_layer_shell_v1::ZwlrLayerShellV1>,
dimensions: (u32, u32), dimensions: (u32, u32),
draw_tx: Sender<bool>, draw_tx: Sender<bool>,
all_outputs: bool,
} }
impl AppInner { impl AppInner {
fn new(tx: Sender<bool>) -> AppInner{ fn new(tx: Sender<bool>, all_outputs: bool) -> AppInner{
AppInner{ AppInner{
compositor: None, compositor: None,
surfaces: Vec::new(), surfaces: Vec::new(),
@@ -55,47 +56,36 @@ impl AppInner {
shell: None, shell: None,
dimensions: (0, 0), dimensions: (0, 0),
draw_tx: tx, draw_tx: tx,
all_outputs: all_outputs,
} }
} }
fn outputs_changed(&mut self) { fn add_shell_surface(
let shell = match self.shell { compositor: &wl_compositor::WlCompositor,
Some(ref shell) => shell.to_owned(), shell: &zwlr_layer_shell_v1::ZwlrLayerShellV1,
None => return, dimensions: (u32, u32),
}; configured_surfaces: Arc<Mutex<usize>>,
let compositor = match self.compositor { tx: Sender<bool>,
Some(ref c) => c.to_owned(), output: Option<&wl_output::WlOutput>
None => return, ) -> (
}; wl_surface::WlSurface,
zwlr_layer_surface_v1::ZwlrLayerSurfaceV1
for shell_surface in self.shell_surfaces.iter() { ) {
shell_surface.destroy();
}
for surface in self.surfaces.iter() {
surface.destroy();
}
let mut surfaces = Vec::new();
let mut shell_surfaces = Vec::new();
self.configured_surfaces = Arc::new(Mutex::new(0));
for output in self.outputs.iter() {
let surface = compositor let surface = compositor
.create_surface(NewProxy::implement_dummy) .create_surface(NewProxy::implement_dummy)
.unwrap(); .unwrap();
let configured = self.configured_surfaces.clone();
let tx = self.draw_tx.clone();
let shell_surface = shell let shell_surface = shell
.get_layer_surface( .get_layer_surface(
&surface, &surface,
Some(&output.1), output,
zwlr_layer_shell_v1::Layer::Overlay, zwlr_layer_shell_v1::Layer::Overlay,
"".to_string(), "".to_string(),
move |layer| { move |layer| {
layer.implement_closure( layer.implement_closure(
move |evt, layer| match evt { move |evt, layer| match evt {
zwlr_layer_surface_v1::Event::Configure { serial, .. } => { zwlr_layer_surface_v1::Event::Configure { serial, .. } => {
*(configured.lock().unwrap()) += 1; *(configured_surfaces.lock().unwrap()) += 1;
layer.ack_configure(serial); layer.ack_configure(serial);
tx.send(false).unwrap(); tx.send(false).unwrap();
} }
@@ -108,13 +98,51 @@ impl AppInner {
.unwrap(); .unwrap();
shell_surface.set_keyboard_interactivity(1); shell_surface.set_keyboard_interactivity(1);
shell_surface.set_size(self.dimensions.0, self.dimensions.1); shell_surface.set_size(dimensions.0, dimensions.1);
surface.commit(); surface.commit();
shell_surfaces.push(shell_surface); (surface, shell_surface)
}
fn outputs_changed(&mut self) {
let shell = match self.shell {
Some(ref shell) => shell.to_owned(),
None => return,
};
let compositor = match self.compositor {
Some(ref c) => c.to_owned(),
None => return,
};
if !self.all_outputs && self.shell_surfaces.len() > 0 {
return;
}
for shell_surface in self.shell_surfaces.iter() {
shell_surface.destroy();
}
for surface in self.surfaces.iter() {
surface.destroy();
}
self.configured_surfaces = Arc::new(Mutex::new(0));
if self.all_outputs {
let mut surfaces = Vec::new();
let mut shell_surfaces = Vec::new();
for output in self.outputs.iter() {
let (surface, shell_surface) = AppInner::add_shell_surface(&compositor, &shell, self.dimensions, self.configured_surfaces.clone(), self.draw_tx.clone(), Some(&output.1));
surfaces.push(surface); surfaces.push(surface);
shell_surfaces.push(shell_surface);
} }
self.surfaces = surfaces; self.surfaces = surfaces;
self.shell_surfaces = shell_surfaces; self.shell_surfaces = shell_surfaces;
} else {
let (surface, shell_surface) = AppInner::add_shell_surface(&compositor, &shell, self.dimensions, self.configured_surfaces.clone(), self.draw_tx.clone(), None);
self.surfaces = vec![surface];
self.shell_surfaces = vec![shell_surface];
}
self.draw_tx.send(false).unwrap(); self.draw_tx.send(false).unwrap();
} }
@@ -263,8 +291,8 @@ impl App {
None None
} }
pub fn new(tx: Sender<bool>) -> App { pub fn new(tx: Sender<bool>, all_outputs: bool) -> App {
let inner = Arc::new(Mutex::new(AppInner::new(tx.clone()))); let inner = Arc::new(Mutex::new(AppInner::new(tx.clone(), all_outputs)));
// //
// Set up modules // Set up modules
+7 -1
View File
@@ -1,6 +1,7 @@
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::env;
use nix::poll::{poll, PollFd, PollFlags}; use nix::poll::{poll, PollFd, PollFlags};
use os_pipe::pipe; use os_pipe::pipe;
@@ -17,7 +18,12 @@ fn main() {
let (mut rx_pipe, mut tx_pipe) = pipe().unwrap(); let (mut rx_pipe, mut tx_pipe) = pipe().unwrap();
let (tx_draw, rx_draw) = channel(); let (tx_draw, rx_draw) = channel();
let mut app = App::new(tx_draw); let all_outputs = match env::var("WLDASH_ALL_OUTPUTS") {
Ok(_) => true,
Err(_) => false,
};
let mut app = App::new(tx_draw, all_outputs);
app.wipe(); app.wipe();
let worker_queue = app.cmd_queue(); let worker_queue = app.cmd_queue();