Fix dialog and duplicate keyboard events
This commit is contained in:
parent
390673c70f
commit
cf41bfcc6a
3 changed files with 58 additions and 37 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
app::{self, Command, Core, Settings},
|
app::{self, Core, Settings, Task},
|
||||||
executor,
|
executor,
|
||||||
iced::{subscription::Subscription, window},
|
iced::{window, Subscription},
|
||||||
widget, Application, Element,
|
widget, Application, Element,
|
||||||
};
|
};
|
||||||
use cosmic_files::dialog::{Dialog, DialogKind, DialogMessage, DialogResult};
|
use cosmic_files::dialog::{Dialog, DialogKind, DialogMessage, DialogResult};
|
||||||
|
|
@ -42,18 +42,18 @@ impl Application for App {
|
||||||
&mut self.core
|
&mut self.core
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(core: Core, _flags: Self::Flags) -> (Self, Command<Message>) {
|
fn init(core: Core, _flags: Self::Flags) -> (Self, Task<Message>) {
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
core,
|
core,
|
||||||
dialog_opt: None,
|
dialog_opt: None,
|
||||||
result_opt: None,
|
result_opt: None,
|
||||||
},
|
},
|
||||||
Command::none(),
|
Task::none(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Message) -> Command<Message> {
|
fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::DialogMessage(dialog_message) => {
|
Message::DialogMessage(dialog_message) => {
|
||||||
if let Some(dialog) = &mut self.dialog_opt {
|
if let Some(dialog) = &mut self.dialog_opt {
|
||||||
|
|
@ -78,7 +78,7 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_window(&self, window_id: window::Id) -> Element<Message> {
|
fn view_window(&self, window_id: window::Id) -> Element<Message> {
|
||||||
|
|
|
||||||
38
src/app.rs
38
src/app.rs
|
|
@ -3926,25 +3926,31 @@ impl Application for App {
|
||||||
struct TrashWatcherSubscription;
|
struct TrashWatcherSubscription;
|
||||||
|
|
||||||
let mut subscriptions = vec![
|
let mut subscriptions = vec![
|
||||||
event::listen_with(|event, status, _window_id| match event {
|
event::listen_with(|event, status, window_id| {
|
||||||
Event::Keyboard(KeyEvent::KeyPressed { key, modifiers, .. }) => match status {
|
//TODO: why are we getting events for this window Id?
|
||||||
event::Status::Ignored => Some(Message::Key(modifiers, key)),
|
if window_id == window::Id::NONE {
|
||||||
event::Status::Captured => None,
|
return None;
|
||||||
},
|
|
||||||
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
|
||||||
Some(Message::Modifiers(modifiers))
|
|
||||||
}
|
}
|
||||||
Event::Window(WindowEvent::CloseRequested) => Some(Message::WindowClose),
|
match event {
|
||||||
#[cfg(feature = "wayland")]
|
Event::Keyboard(KeyEvent::KeyPressed { key, modifiers, .. }) => match status {
|
||||||
Event::PlatformSpecific(event::PlatformSpecific::Wayland(wayland_event)) => {
|
event::Status::Ignored => Some(Message::Key(modifiers, key)),
|
||||||
match wayland_event {
|
event::Status::Captured => None,
|
||||||
WaylandEvent::Output(output_event, output) => {
|
},
|
||||||
Some(Message::OutputEvent(output_event, output))
|
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
||||||
}
|
Some(Message::Modifiers(modifiers))
|
||||||
_ => None,
|
|
||||||
}
|
}
|
||||||
|
Event::Window(WindowEvent::CloseRequested) => Some(Message::WindowClose),
|
||||||
|
#[cfg(feature = "wayland")]
|
||||||
|
Event::PlatformSpecific(event::PlatformSpecific::Wayland(wayland_event)) => {
|
||||||
|
match wayland_event {
|
||||||
|
WaylandEvent::Output(output_event, output) => {
|
||||||
|
Some(Message::OutputEvent(output_event, output))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
_ => None,
|
|
||||||
}),
|
}),
|
||||||
Config::subscription().map(|update| {
|
Config::subscription().map(|update| {
|
||||||
if !update.errors.is_empty() {
|
if !update.errors.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ impl<M: Send + 'static> Dialog<M> {
|
||||||
settings.platform_specific.application_id = App::APP_ID.to_string();
|
settings.platform_specific.application_id = App::APP_ID.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
//let (window_id, window_command) = window::open(settings);
|
let (window_id, window_command) = window::open(settings.clone());
|
||||||
|
|
||||||
let core = Core::default();
|
let core = Core::default();
|
||||||
let flags = Flags {
|
let flags = Flags {
|
||||||
|
|
@ -184,13 +184,16 @@ impl<M: Send + 'static> Dialog<M> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
//TODO
|
window_id,
|
||||||
window_id: window::Id::NONE,
|
|
||||||
config_handler,
|
config_handler,
|
||||||
config,
|
config,
|
||||||
};
|
};
|
||||||
|
|
||||||
let (cosmic, cosmic_command) = Cosmic::<App>::init((core, flags, settings));
|
// settings here is unused
|
||||||
|
let (mut cosmic, cosmic_command) = Cosmic::<App>::init((core, flags, settings));
|
||||||
|
let update_command = cosmic.update(app::Message::Cosmic(
|
||||||
|
app::cosmic::Message::MainWindowCreated(window_id),
|
||||||
|
));
|
||||||
|
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -198,9 +201,15 @@ impl<M: Send + 'static> Dialog<M> {
|
||||||
mapper,
|
mapper,
|
||||||
on_result: Box::new(on_result),
|
on_result: Box::new(on_result),
|
||||||
},
|
},
|
||||||
cosmic_command
|
Task::batch([
|
||||||
.map(DialogMessage)
|
window_command.map(|_id| message::none()),
|
||||||
.map(move |message| app::Message::App(mapper(message))),
|
cosmic_command
|
||||||
|
.map(DialogMessage)
|
||||||
|
.map(move |message| app::Message::App(mapper(message))),
|
||||||
|
update_command
|
||||||
|
.map(DialogMessage)
|
||||||
|
.map(move |message| app::Message::App(mapper(message))),
|
||||||
|
]),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1582,15 +1591,21 @@ impl Application for App {
|
||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
struct WatcherSubscription;
|
struct WatcherSubscription;
|
||||||
let mut subscriptions = vec![
|
let mut subscriptions = vec![
|
||||||
event::listen_with(|event, status, _window_id| match event {
|
event::listen_with(|event, status, window_id| {
|
||||||
Event::Keyboard(KeyEvent::KeyPressed { key, modifiers, .. }) => match status {
|
//TODO: why are we getting events for this window Id?
|
||||||
event::Status::Ignored => Some(Message::Key(modifiers, key)),
|
if window_id == window::Id::NONE {
|
||||||
event::Status::Captured => None,
|
return None;
|
||||||
},
|
}
|
||||||
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
match event {
|
||||||
Some(Message::Modifiers(modifiers))
|
Event::Keyboard(KeyEvent::KeyPressed { key, modifiers, .. }) => match status {
|
||||||
|
event::Status::Ignored => Some(Message::Key(modifiers, key)),
|
||||||
|
event::Status::Captured => None,
|
||||||
|
},
|
||||||
|
Event::Keyboard(KeyEvent::ModifiersChanged(modifiers)) => {
|
||||||
|
Some(Message::Modifiers(modifiers))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
_ => None,
|
|
||||||
}),
|
}),
|
||||||
Config::subscription().map(|update| {
|
Config::subscription().map(|update| {
|
||||||
if !update.errors.is_empty() {
|
if !update.errors.is_empty() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue