main: Moved event loop definition close to actor

This commit is contained in:
Dorota Czaplejewicz
2022-11-28 15:46:05 +00:00
parent e5be92efae
commit 6d01386d8a
6 changed files with 27 additions and 23 deletions

View File

@ -6,7 +6,7 @@
use std::thread; use std::thread;
use zbus::{Connection, ObjectServer, dbus_interface, fdo}; use zbus::{Connection, ObjectServer, dbus_interface, fdo};
use crate::event_loop; use crate::main;
use crate::state; use crate::state;
@ -15,7 +15,7 @@ use std::convert::TryInto;
/// Accepts commands controlling the debug mode /// Accepts commands controlling the debug mode
struct Manager { struct Manager {
sender: event_loop::driver::Threaded, sender: main::EventLoop,
enabled: bool, enabled: bool,
} }
@ -54,7 +54,7 @@ fn start(mgr: Manager) -> Result<(), Box<dyn std::error::Error>> {
} }
} }
pub fn init(sender: event_loop::driver::Threaded) { pub fn init(sender: main::EventLoop) {
let mgr = Manager { let mgr = Manager {
sender, sender,
enabled: false, enabled: false,

View File

@ -18,7 +18,6 @@
use crate::event_loop; use crate::event_loop;
use crate::logging; use crate::logging;
use crate::state::Application;
use glib; use glib;
use std::sync::mpsc; use std::sync::mpsc;
use std::thread; use std::thread;
@ -36,8 +35,6 @@ type UISender<S> = glib::Sender<
>::Commands >::Commands
>; >;
pub type Threaded = Threaded_<Application>;
/// This loop driver spawns a new thread which updates the state in a loop, /// This loop driver spawns a new thread which updates the state in a loop,
/// in response to incoming events. /// in response to incoming events.
/// It sends outcomes to the glib main loop using a channel. /// It sends outcomes to the glib main loop using a channel.
@ -47,7 +44,7 @@ pub type Threaded = Threaded_<Application>;
// This can/should be abstracted over Event and Commands, // This can/should be abstracted over Event and Commands,
// so that the C call-ins can be thrown away from here and defined near events. // so that the C call-ins can be thrown away from here and defined near events.
#[derive(Clone)] #[derive(Clone)]
pub struct Threaded_<S> pub struct Threaded<S>
where where
S: ActorState + Send, S: ActorState + Send,
S::Event: Send, S::Event: Send,
@ -57,7 +54,7 @@ where
thread: mpsc::Sender<S::Event>, thread: mpsc::Sender<S::Event>,
} }
impl<S> Threaded_<S> impl<S> Threaded<S>
where where
// Not sure why this needs 'static. It's already owned. // Not sure why this needs 'static. It's already owned.
S: ActorState + Send + 'static, S: ActorState + Send + 'static,
@ -134,6 +131,7 @@ where
mod c { mod c {
use super::*; use super::*;
use crate::main;
use crate::state::{Event, Presence}; use crate::state::{Event, Presence};
use crate::state::LayoutChoice; use crate::state::LayoutChoice;
use crate::state::visibility; use crate::state::visibility;
@ -143,7 +141,7 @@ mod c {
#[no_mangle] #[no_mangle]
pub extern "C" pub extern "C"
fn squeek_state_send_force_visible(mgr: Wrapped<Threaded>) { fn squeek_state_send_force_visible(mgr: Wrapped<main::EventLoop>) {
let sender = mgr.clone_ref(); let sender = mgr.clone_ref();
let sender = sender.borrow(); let sender = sender.borrow();
sender.send(Event::Visibility(visibility::Event::ForceVisible)) sender.send(Event::Visibility(visibility::Event::ForceVisible))
@ -152,7 +150,7 @@ mod c {
#[no_mangle] #[no_mangle]
pub extern "C" pub extern "C"
fn squeek_state_send_force_hidden(sender: Wrapped<Threaded>) { fn squeek_state_send_force_hidden(sender: Wrapped<main::EventLoop>) {
let sender = sender.clone_ref(); let sender = sender.clone_ref();
let sender = sender.borrow(); let sender = sender.borrow();
sender.send(Event::Visibility(visibility::Event::ForceHidden)) sender.send(Event::Visibility(visibility::Event::ForceHidden))
@ -161,7 +159,7 @@ mod c {
#[no_mangle] #[no_mangle]
pub extern "C" pub extern "C"
fn squeek_state_send_keyboard_present(sender: Wrapped<Threaded>, present: u32) { fn squeek_state_send_keyboard_present(sender: Wrapped<main::EventLoop>, present: u32) {
let sender = sender.clone_ref(); let sender = sender.clone_ref();
let sender = sender.borrow(); let sender = sender.borrow();
let state = let state =
@ -174,7 +172,7 @@ mod c {
#[no_mangle] #[no_mangle]
pub extern "C" pub extern "C"
fn squeek_state_send_layout_set( fn squeek_state_send_layout_set(
sender: Wrapped<Threaded>, sender: Wrapped<main::EventLoop>,
name: *const c_char, name: *const c_char,
source: *const c_char, source: *const c_char,
// TODO: use when synthetic events are needed // TODO: use when synthetic events are needed

View File

@ -10,7 +10,7 @@ use std::num::Wrapping;
use std::string::String; use std::string::String;
use std::time::Instant; use std::time::Instant;
use crate::event_loop::driver; use crate::main;
use crate::state; use crate::state;
use crate::state::Event; use crate::state::Event;
use ::logging; use ::logging;
@ -322,7 +322,7 @@ impl Default for IMProtocolState {
pub struct IMService { pub struct IMService {
/// Owned reference (still created and destroyed in C) /// Owned reference (still created and destroyed in C)
pub im: c::InputMethod, pub im: c::InputMethod,
sender: driver::Threaded, sender: main::EventLoop,
pending: IMProtocolState, pending: IMProtocolState,
current: IMProtocolState, // turn current into an idiomatic representation? current: IMProtocolState, // turn current into an idiomatic representation?
@ -338,7 +338,7 @@ pub enum SubmitError {
impl IMService { impl IMService {
pub fn new( pub fn new(
im: c::InputMethod, im: c::InputMethod,
sender: driver::Threaded, sender: main::EventLoop,
) -> Box<IMService> { ) -> Box<IMService> {
// IMService will be referenced to by C, // IMService will be referenced to by C,
// so it needs to stay in the same place in memory via Box // so it needs to stay in the same place in memory via Box

View File

@ -7,7 +7,9 @@ use crate::actors;
use crate::animation; use crate::animation;
use crate::debug; use crate::debug;
use crate::data::loading; use crate::data::loading;
use crate::event_loop;
use crate::panel; use crate::panel;
use crate::state;
use glib::{Continue, MainContext, PRIORITY_DEFAULT, Receiver}; use glib::{Continue, MainContext, PRIORITY_DEFAULT, Receiver};
@ -46,7 +48,7 @@ mod c {
/// The handle to which Commands should be sent /// The handle to which Commands should be sent
/// for processing in the main loop. /// for processing in the main loop.
receiver: Wrapped<Receiver<Commands>>, receiver: Wrapped<Receiver<Commands>>,
state_manager: Wrapped<driver::Threaded>, state_manager: Wrapped<EventLoop>,
submission: Wrapped<Submission>, submission: Wrapped<Submission>,
/// Not wrapped, because C needs to access this. /// Not wrapped, because C needs to access this.
wayland: *mut Wayland, wayland: *mut Wayland,
@ -204,6 +206,10 @@ mod c {
} }
} }
pub type EventLoop = event_loop::driver::Threaded<state::Application>;
pub mod commands { pub mod commands {
use crate::animation; use crate::animation;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

View File

@ -6,8 +6,8 @@
use std::ops; use std::ops;
use std::vec::Vec; use std::vec::Vec;
use crate::event_loop; use crate::logging;
use ::logging; use crate::main;
use crate::util::DivCeil; use crate::util::DivCeil;
// traits // traits
@ -438,11 +438,11 @@ type GlobalId = u32;
/// The outputs manager /// The outputs manager
pub struct Outputs { pub struct Outputs {
outputs: Vec<(Output, GlobalId)>, outputs: Vec<(Output, GlobalId)>,
sender: event_loop::driver::Threaded, sender: main::EventLoop,
} }
impl Outputs { impl Outputs {
pub fn new(sender: event_loop::driver::Threaded) -> Outputs { pub fn new(sender: main::EventLoop) -> Outputs {
Outputs { Outputs {
outputs: Vec::new(), outputs: Vec::new(),
sender, sender,

View File

@ -1,15 +1,15 @@
/*! Defines the application-wide message bus for updating state.*/ /*! Defines the application-wide message bus for updating state.*/
use crate::event_loop::driver::Threaded; use crate::main;
pub mod c { pub mod c {
use super::*; use super::*;
use crate::util::c::Wrapped; use crate::util::c::Wrapped;
pub type State = Wrapped<Threaded>; pub type State = Wrapped<main::EventLoop>;
} }
// The state receiver is an endpoint of a channel, so it's safely cloneable. // The state receiver is an endpoint of a channel, so it's safely cloneable.
// There's no need to keep it in a Rc. // There's no need to keep it in a Rc.
// The C version uses Wrapped with an underlying Rc, // The C version uses Wrapped with an underlying Rc,
// because Wrapped is well-tested already. // because Wrapped is well-tested already.
pub type State = Threaded; pub type State = main::EventLoop;