Experimental command socket support

Introduces "start-or-kill" and "toggle-visible" commands. How the
command socket is used will likely change soon.
This commit is contained in:
Kenny Levinsen
2019-08-27 15:09:19 +02:00
parent 1cadf43d49
commit 6deffa91bb
6 changed files with 169 additions and 59 deletions
+49 -35
View File
@@ -17,6 +17,8 @@ use wayland_protocols::wlr::unstable::layer_shell::v1::client::{
use crate::color::Color;
use crate::buffer::Buffer;
use crate::cmd::Cmd;
use crate::modules::backlight::Backlight;
use crate::modules::battery::UpowerBattery;
use crate::modules::calendar::Calendar;
@@ -25,12 +27,9 @@ use crate::modules::launcher::Launcher;
use crate::modules::module::{Input, Module};
use crate::modules::sound::PulseAudio;
pub enum Cmd {
Exit,
Draw,
ForceDraw,
MouseInput { pos: (u32, u32), input: Input },
KeyboardInput { input: Input },
pub enum OutputMode {
Active,
All,
}
struct AppInner {
@@ -41,12 +40,13 @@ struct AppInner {
outputs: Vec<(u32, wl_output::WlOutput)>,
shell: Option<zwlr_layer_shell_v1::ZwlrLayerShellV1>,
dimensions: (u32, u32),
draw_tx: Sender<bool>,
all_outputs: bool,
draw_tx: Sender<Cmd>,
output_mode: OutputMode,
visible: bool,
}
impl AppInner {
fn new(tx: Sender<bool>, all_outputs: bool) -> AppInner{
fn new(tx: Sender<Cmd>, output_mode: OutputMode) -> AppInner{
AppInner{
compositor: None,
surfaces: Vec::new(),
@@ -56,7 +56,8 @@ impl AppInner {
shell: None,
dimensions: (0, 0),
draw_tx: tx,
all_outputs: all_outputs,
output_mode: output_mode,
visible: true,
}
}
@@ -65,7 +66,7 @@ impl AppInner {
shell: &zwlr_layer_shell_v1::ZwlrLayerShellV1,
dimensions: (u32, u32),
configured_surfaces: Arc<Mutex<usize>>,
tx: Sender<bool>,
tx: Sender<Cmd>,
output: Option<&wl_output::WlOutput>
) -> (
wl_surface::WlSurface,
@@ -87,7 +88,7 @@ impl AppInner {
zwlr_layer_surface_v1::Event::Configure { serial, .. } => {
*(configured_surfaces.lock().unwrap()) += 1;
layer.ack_configure(serial);
tx.send(false).unwrap();
tx.send(Cmd::ForceDraw).unwrap();
}
_ => unreachable!(),
},
@@ -114,10 +115,6 @@ impl AppInner {
None => return,
};
if !self.all_outputs && self.shell_surfaces.len() > 0 {
return;
}
for shell_surface in self.shell_surfaces.iter() {
shell_surface.destroy();
}
@@ -127,23 +124,34 @@ impl AppInner {
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);
shell_surfaces.push(shell_surface);
}
self.surfaces = 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];
}
if self.visible {
match self.output_mode {
OutputMode::Active => {
if self.shell_surfaces.len() > 0 {
return;
}
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();
},
OutputMode::All => {
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);
shell_surfaces.push(shell_surface);
}
self.surfaces = surfaces;
self.shell_surfaces = shell_surfaces;
}
}
self.draw_tx.send(Cmd::ForceDraw).unwrap();
} else {
self.surfaces = Vec::new();
self.shell_surfaces = Vec::new();
}
}
fn add_output(&mut self, id: u32, output: wl_output::WlOutput) {
@@ -249,6 +257,12 @@ impl App {
Ok(())
}
pub fn toggle_visible(&mut self) {
let mut inner = self.inner.lock().unwrap();
inner.visible = !inner.visible;
inner.outputs_changed();
}
pub fn cmd_queue(&self) -> Arc<Mutex<VecDeque<Cmd>>> {
self.cmd_queue.clone()
}
@@ -291,8 +305,8 @@ impl App {
None
}
pub fn new(tx: Sender<bool>, all_outputs: bool) -> App {
let inner = Arc::new(Mutex::new(AppInner::new(tx.clone(), all_outputs)));
pub fn new(tx: Sender<Cmd>, output_mode: OutputMode) -> App {
let inner = Arc::new(Mutex::new(AppInner::new(tx.clone(), output_mode)));
//
// Set up modules
@@ -304,7 +318,7 @@ impl App {
Module::new(Box::new(Calendar::new()), (0, 368, 1232, 344)),
];
if let Ok(m) = Launcher::new() {
if let Ok(m) = Launcher::new(tx.clone()) {
modules.push(Module::new(Box::new(m), (0, 728, 1232, 32)));
}