From d3002d21808c2b1559657caeadb827c83dd9ce8d Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Thu, 12 Jan 2023 00:13:08 +0100 Subject: [PATCH] Exit when no longer activated --- src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 506ee86..ed77192 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,7 @@ use widgets::{ Margin, VerticalLayout, Widget, WidgetUpdater, }; -use std::{cell::RefCell, env, mem, rc::Rc, thread}; +use std::{cell::RefCell, env, mem, rc::Rc, thread, process::exit}; enum MaybeFontMap { Waiting(thread::JoinHandle), @@ -66,6 +66,7 @@ impl MaybeFontMap { struct State { running: bool, dirty: bool, + activated: bool, base_surface: Option, wm_base: Option, xdg_surface: Option<(xdg_surface::XdgSurface, xdg_toplevel::XdgToplevel)>, @@ -193,6 +194,7 @@ fn main() { let mut state = State { running: true, dirty: true, + activated: false, base_surface: None, wm_base: None, xdg_surface: None, @@ -459,10 +461,19 @@ impl Dispatch for State { _: &QueueHandle, ) { match event { - xdg_toplevel::Event::Configure { width, height, .. } => { + xdg_toplevel::Event::Configure { width, height, states, .. } => { if (width, height) == (0, 0) { return; } + let activated = states.iter().find(|&st| *st as u32 == xdg_toplevel::State::Activated as u32).is_some(); + + if activated { + state.activated = true; + } else if state.activated && !activated { + exit(0); + } + + if state.dimensions != (width, height) { state.bufmgr.clear_buffers(); state.dimensions = (width, height);