Basic "command" parser

This commit is contained in:
Yash Karandikar 2022-06-28 18:15:37 +05:30
parent d1e153eac7
commit 1d988b7e38
2 changed files with 12 additions and 3 deletions

View file

@ -134,7 +134,7 @@ async fn main() -> Result<()> {
// starved by x11 events. Probably unnecessary, but better safe than sorry.
tokio::select! {
biased;
Some(s) = recv.recv() => msg_listener::on_recv(s).await?,
Some(s) = recv.recv() => msg_listener::on_recv(s, &mut manager, &mut conn).await?,
Ok(ev) = conn.wait_for_event_async() => process_event(ev, &mut manager, &mut conn, root).await?,
}
}

View file

@ -13,7 +13,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::x11::client::XcrabWindowManager;
use crate::Result;
use breadx::AsyncDisplay;
use std::path::Path;
use tokio::io::AsyncReadExt;
use tokio::net::UnixListener;
@ -44,7 +46,14 @@ pub async fn listener_task(socket_path: &Path, sender: UnboundedSender<String>)
}
}
pub async fn on_recv(data: String) -> Result<()> {
println!("{}", data);
pub async fn on_recv<Dpy: AsyncDisplay + ?Sized>(
data: String,
manager: &mut XcrabWindowManager,
conn: &mut Dpy,
) -> Result<()> {
match &*data {
"close" => manager.remove_focused_client(conn).await?,
_ => println!("{}", data),
}
Ok(())
}