Getting colder with our second freeze... it's 3.31.91 release day and string freeze, upload a tarball and lock those strings 🏂

Commit f74fbb57 authored by Daniel García Moreno's avatar Daniel García Moreno

Escape management in only one method

I've moved the leave full screen on escape from the media_viewer to the
existing escape method in state.rs to have all the behaviour in only one
place.

Doing this I've also added the functionality to go back to the chat when
we're in the MediaViewer and to do this I've to modify a little the
autocomplete, to avoid the close when we press escape on the
autocomplete popover.

I've also changed the key management on key press instead of key release
because the keypress is grabbed by child windows or popovers and the
release isn't.

Close #277
parent 6999de57
Pipeline #17950 failed with stage
in 16 seconds
...@@ -198,25 +198,5 @@ impl App { ...@@ -198,25 +198,5 @@ impl App {
next_media_button.connect_clicked(move |_| { next_media_button.connect_clicked(move |_| {
op.lock().unwrap().next_media(); op.lock().unwrap().next_media();
}); });
// Connecting escape key to leave fullscreen mode
let main_window = self.ui.builder
.get_object::<gtk::ApplicationWindow>("main_window")
.expect("Cant find main_window in ui file.");
let op = self.op.clone();
main_window.connect_key_release_event(move |w, k| {
// leave full screen only if we're currently in fullscreen
if let Some(win) = w.get_window() {
if !win.get_state().contains(gdk::WindowState::FULLSCREEN) {
return Inhibit(false);
}
}
if k.get_keyval() == gdk::enums::key::Escape {
op.lock().unwrap().leave_full_screen();
}
Inhibit(false)
});
} }
} }
...@@ -44,14 +44,13 @@ impl App { ...@@ -44,14 +44,13 @@ impl App {
}); });
let op = self.op.clone(); let op = self.op.clone();
let chat: gtk::Widget = self.ui.builder let main_window = self.ui.builder
.get_object("room_view_stack") .get_object::<gtk::ApplicationWindow>("main_window")
.expect("Couldn't find room_view_stack in ui file."); .expect("Cant find main_window in ui file.");
chat.connect_key_release_event(move |_, k| { main_window.connect_key_press_event(move |w, k| {
match k.get_keyval() { match k.get_keyval() {
gdk::enums::key::Escape => { gdk::enums::key::Escape => {
op.lock().unwrap().escape(); Inhibit(op.lock().unwrap().escape(w))
Inhibit(true)
}, },
_ => Inhibit(false) _ => Inhibit(false)
} }
......
...@@ -80,10 +80,7 @@ pub struct AppOp { ...@@ -80,10 +80,7 @@ pub struct AppOp {
pub more_members_btn: gtk::Button, pub more_members_btn: gtk::Button,
pub unsent_messages: HashMap<String, (String, i32)>, pub unsent_messages: HashMap<String, (String, i32)>,
pub highlighted_entry: Vec<String>, pub inhibit_escape: bool,
pub popover_position: Option<i32>,
pub popover_search: Option<String>,
pub popover_closing: bool,
pub state: AppState, pub state: AppState,
pub since: Option<String>, pub since: Option<String>,
...@@ -138,10 +135,7 @@ impl AppOp { ...@@ -138,10 +135,7 @@ impl AppOp {
member_limit: 50, member_limit: 50,
unsent_messages: HashMap::new(), unsent_messages: HashMap::new(),
highlighted_entry: vec![], inhibit_escape: false,
popover_position: None,
popover_search: None,
popover_closing: false,
logged_in: false, logged_in: false,
loading_more: false, loading_more: false,
......
extern crate gtk; extern crate gtk;
extern crate gdk;
use self::gtk::prelude::*; use self::gtk::prelude::*;
use self::gdk::WindowExt;
use appop::AppOp; use appop::AppOp;
use appop::room::RoomPanel; use appop::room::RoomPanel;
...@@ -72,11 +74,31 @@ impl AppOp { ...@@ -72,11 +74,31 @@ impl AppOp {
} }
} }
pub fn escape(&mut self) { pub fn escape(&mut self, w: &gtk::ApplicationWindow) -> bool {
if let AppState::Chat = self.state { if self.inhibit_escape {
self.room_panel(RoomPanel::NoRoom); return true;
self.active_room = None; }
self.clear_tmp_msgs();
// leave full screen only if we're currently in fullscreen
if let Some(win) = w.get_window() {
if win.get_state().contains(gdk::WindowState::FULLSCREEN) {
self.leave_full_screen();
return true;
}
}
match self.state {
AppState::Chat => {
self.room_panel(RoomPanel::NoRoom);
self.active_room = None;
self.clear_tmp_msgs();
true
},
AppState::MediaViewer => {
self.hide_media_viewer();
true
},
_ => { false }
} }
} }
} }
...@@ -293,6 +293,7 @@ impl Autocomplete { ...@@ -293,6 +293,7 @@ impl Autocomplete {
self.popover_search = None; self.popover_search = None;
let visible = self.popover.is_visible(); let visible = self.popover.is_visible();
self.popover.popdown(); self.popover.popdown();
self.op.lock().unwrap().inhibit_escape = false;
visible visible
} }
...@@ -418,11 +419,11 @@ impl Autocomplete { ...@@ -418,11 +419,11 @@ impl Autocomplete {
let mut widget_list : HashMap<String, gtk::EventBox> = HashMap::new(); let mut widget_list : HashMap<String, gtk::EventBox> = HashMap::new();
if list.len() > 0 { if list.len() > 0 {
let guard = self.op.lock().unwrap();
for m in list.iter() { for m in list.iter() {
let alias = &m.alias.clone().unwrap_or_default().trim_right_matches(" (IRC)").to_owned(); let alias = &m.alias.clone().unwrap_or_default().trim_right_matches(" (IRC)").to_owned();
let widget; let widget;
{ {
let guard = self.op.lock().unwrap();
let mb = widgets::MemberBox::new(&m, &guard); let mb = widgets::MemberBox::new(&m, &guard);
widget = mb.widget(true); widget = mb.widget(true);
} }
...@@ -453,10 +454,12 @@ impl Autocomplete { ...@@ -453,10 +454,12 @@ impl Autocomplete {
} }
self.popover.popup(); self.popover.popup();
self.op.lock().unwrap().inhibit_escape = true;
} }
else { else {
self.autocomplete_enter(); self.autocomplete_enter();
} }
return widget_list; return widget_list;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment