main: Moved event loop definition close to actor
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
use std::thread;
|
||||
use zbus::{Connection, ObjectServer, dbus_interface, fdo};
|
||||
|
||||
use crate::event_loop;
|
||||
use crate::main;
|
||||
use crate::state;
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ use std::convert::TryInto;
|
||||
|
||||
/// Accepts commands controlling the debug mode
|
||||
struct Manager {
|
||||
sender: event_loop::driver::Threaded,
|
||||
sender: main::EventLoop,
|
||||
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 {
|
||||
sender,
|
||||
enabled: false,
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
|
||||
use crate::event_loop;
|
||||
use crate::logging;
|
||||
use crate::state::Application;
|
||||
use glib;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
@ -36,8 +35,6 @@ type UISender<S> = glib::Sender<
|
||||
>::Commands
|
||||
>;
|
||||
|
||||
pub type Threaded = Threaded_<Application>;
|
||||
|
||||
/// This loop driver spawns a new thread which updates the state in a loop,
|
||||
/// in response to incoming events.
|
||||
/// 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,
|
||||
// so that the C call-ins can be thrown away from here and defined near events.
|
||||
#[derive(Clone)]
|
||||
pub struct Threaded_<S>
|
||||
pub struct Threaded<S>
|
||||
where
|
||||
S: ActorState + Send,
|
||||
S::Event: Send,
|
||||
@ -57,7 +54,7 @@ where
|
||||
thread: mpsc::Sender<S::Event>,
|
||||
}
|
||||
|
||||
impl<S> Threaded_<S>
|
||||
impl<S> Threaded<S>
|
||||
where
|
||||
// Not sure why this needs 'static. It's already owned.
|
||||
S: ActorState + Send + 'static,
|
||||
@ -134,6 +131,7 @@ where
|
||||
mod c {
|
||||
use super::*;
|
||||
|
||||
use crate::main;
|
||||
use crate::state::{Event, Presence};
|
||||
use crate::state::LayoutChoice;
|
||||
use crate::state::visibility;
|
||||
@ -143,7 +141,7 @@ mod c {
|
||||
|
||||
#[no_mangle]
|
||||
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 = sender.borrow();
|
||||
sender.send(Event::Visibility(visibility::Event::ForceVisible))
|
||||
@ -152,7 +150,7 @@ mod c {
|
||||
|
||||
#[no_mangle]
|
||||
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.borrow();
|
||||
sender.send(Event::Visibility(visibility::Event::ForceHidden))
|
||||
@ -161,7 +159,7 @@ mod c {
|
||||
|
||||
#[no_mangle]
|
||||
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.borrow();
|
||||
let state =
|
||||
@ -174,7 +172,7 @@ mod c {
|
||||
#[no_mangle]
|
||||
pub extern "C"
|
||||
fn squeek_state_send_layout_set(
|
||||
sender: Wrapped<Threaded>,
|
||||
sender: Wrapped<main::EventLoop>,
|
||||
name: *const c_char,
|
||||
source: *const c_char,
|
||||
// TODO: use when synthetic events are needed
|
||||
|
||||
@ -10,7 +10,7 @@ use std::num::Wrapping;
|
||||
use std::string::String;
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::event_loop::driver;
|
||||
use crate::main;
|
||||
use crate::state;
|
||||
use crate::state::Event;
|
||||
use ::logging;
|
||||
@ -322,7 +322,7 @@ impl Default for IMProtocolState {
|
||||
pub struct IMService {
|
||||
/// Owned reference (still created and destroyed in C)
|
||||
pub im: c::InputMethod,
|
||||
sender: driver::Threaded,
|
||||
sender: main::EventLoop,
|
||||
|
||||
pending: IMProtocolState,
|
||||
current: IMProtocolState, // turn current into an idiomatic representation?
|
||||
@ -338,7 +338,7 @@ pub enum SubmitError {
|
||||
impl IMService {
|
||||
pub fn new(
|
||||
im: c::InputMethod,
|
||||
sender: driver::Threaded,
|
||||
sender: main::EventLoop,
|
||||
) -> Box<IMService> {
|
||||
// IMService will be referenced to by C,
|
||||
// so it needs to stay in the same place in memory via Box
|
||||
|
||||
@ -7,7 +7,9 @@ use crate::actors;
|
||||
use crate::animation;
|
||||
use crate::debug;
|
||||
use crate::data::loading;
|
||||
use crate::event_loop;
|
||||
use crate::panel;
|
||||
use crate::state;
|
||||
use glib::{Continue, MainContext, PRIORITY_DEFAULT, Receiver};
|
||||
|
||||
|
||||
@ -46,7 +48,7 @@ mod c {
|
||||
/// The handle to which Commands should be sent
|
||||
/// for processing in the main loop.
|
||||
receiver: Wrapped<Receiver<Commands>>,
|
||||
state_manager: Wrapped<driver::Threaded>,
|
||||
state_manager: Wrapped<EventLoop>,
|
||||
submission: Wrapped<Submission>,
|
||||
/// Not wrapped, because C needs to access this.
|
||||
wayland: *mut Wayland,
|
||||
@ -204,6 +206,10 @@ mod c {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub type EventLoop = event_loop::driver::Threaded<state::Application>;
|
||||
|
||||
|
||||
pub mod commands {
|
||||
use crate::animation;
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
|
||||
use std::ops;
|
||||
use std::vec::Vec;
|
||||
use crate::event_loop;
|
||||
use ::logging;
|
||||
use crate::logging;
|
||||
use crate::main;
|
||||
use crate::util::DivCeil;
|
||||
|
||||
// traits
|
||||
@ -438,11 +438,11 @@ type GlobalId = u32;
|
||||
/// The outputs manager
|
||||
pub struct Outputs {
|
||||
outputs: Vec<(Output, GlobalId)>,
|
||||
sender: event_loop::driver::Threaded,
|
||||
sender: main::EventLoop,
|
||||
}
|
||||
|
||||
impl Outputs {
|
||||
pub fn new(sender: event_loop::driver::Threaded) -> Outputs {
|
||||
pub fn new(sender: main::EventLoop) -> Outputs {
|
||||
Outputs {
|
||||
outputs: Vec::new(),
|
||||
sender,
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
/*! Defines the application-wide message bus for updating state.*/
|
||||
|
||||
use crate::event_loop::driver::Threaded;
|
||||
use crate::main;
|
||||
|
||||
pub mod c {
|
||||
use super::*;
|
||||
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.
|
||||
// There's no need to keep it in a Rc.
|
||||
// The C version uses Wrapped with an underlying Rc,
|
||||
// because Wrapped is well-tested already.
|
||||
pub type State = Threaded;
|
||||
pub type State = main::EventLoop;
|
||||
Reference in New Issue
Block a user