state: Use IM hint and purpose for layout selection
This commit is contained in:
		@ -128,6 +128,8 @@ settings_get_layout(GSettings *settings, char **type, char **layout)
 | 
				
			|||||||
    g_variant_unref(inputs);
 | 
					    g_variant_unref(inputs);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void eekboard_context_service_set_layout(EekboardContextService *context, struct squeek_layout *layout, uint32_t timestamp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
eekboard_context_service_use_layout(EekboardContextService *context, struct squeek_layout_state *state, uint32_t timestamp) {
 | 
					eekboard_context_service_use_layout(EekboardContextService *context, struct squeek_layout_state *state, uint32_t timestamp) {
 | 
				
			||||||
    gchar *layout_name = state->layout_name;
 | 
					    gchar *layout_name = state->layout_name;
 | 
				
			||||||
@ -146,6 +148,10 @@ eekboard_context_service_use_layout(EekboardContextService *context, struct sque
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    // generic part follows
 | 
					    // generic part follows
 | 
				
			||||||
    struct squeek_layout *layout = squeek_load_layout(layout_name, state->arrangement, state->purpose, overlay_name);
 | 
					    struct squeek_layout *layout = squeek_load_layout(layout_name, state->arrangement, state->purpose, overlay_name);
 | 
				
			||||||
 | 
					    eekboard_context_service_set_layout(context, layout, timestamp);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void eekboard_context_service_set_layout(EekboardContextService *context, struct squeek_layout *layout, uint32_t timestamp) {
 | 
				
			||||||
    LevelKeyboard *keyboard = level_keyboard_new(layout);
 | 
					    LevelKeyboard *keyboard = level_keyboard_new(layout);
 | 
				
			||||||
    // set as current
 | 
					    // set as current
 | 
				
			||||||
    LevelKeyboard *previous_keyboard = context->keyboard;
 | 
					    LevelKeyboard *previous_keyboard = context->keyboard;
 | 
				
			||||||
 | 
				
			|||||||
@ -6,19 +6,21 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use std::time::Duration;
 | 
					use std::time::Duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::imservice::ContentPurpose;
 | 
				
			||||||
 | 
					use crate::layout::ArrangementKind;
 | 
				
			||||||
use crate::outputs::OutputId;
 | 
					use crate::outputs::OutputId;
 | 
				
			||||||
use crate::panel::PixelSize;
 | 
					use crate::panel::PixelSize;
 | 
				
			||||||
use crate::layout::ArrangementKind;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// The keyboard should hide after this has elapsed to prevent flickering.
 | 
					/// The keyboard should hide after this has elapsed to prevent flickering.
 | 
				
			||||||
pub const HIDING_TIMEOUT: Duration = Duration::from_millis(200);
 | 
					pub const HIDING_TIMEOUT: Duration = Duration::from_millis(200);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Panel contents
 | 
					/// Description of parameters which influence panel contents
 | 
				
			||||||
#[derive(PartialEq, Clone, Debug)]
 | 
					#[derive(PartialEq, Clone, Debug)]
 | 
				
			||||||
pub struct Contents {
 | 
					pub struct Contents {
 | 
				
			||||||
    pub name: String,
 | 
					    pub name: String,
 | 
				
			||||||
    pub kind: ArrangementKind,
 | 
					    pub kind: ArrangementKind,
 | 
				
			||||||
    pub overlay_name: Option<String>,
 | 
					    pub overlay_name: Option<String>,
 | 
				
			||||||
 | 
					    pub purpose: ContentPurpose,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// The outwardly visible state of visibility
 | 
					/// The outwardly visible state of visibility
 | 
				
			||||||
 | 
				
			|||||||
@ -305,6 +305,17 @@ fn load_layout_data_with_fallback(
 | 
				
			|||||||
    panic!("No useful layout found!");
 | 
					    panic!("No useful layout found!");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn load_layout(
 | 
				
			||||||
 | 
					    name: String,
 | 
				
			||||||
 | 
					    kind: ArrangementKind,
 | 
				
			||||||
 | 
					    variant: ContentPurpose,
 | 
				
			||||||
 | 
					    overlay: Option<String>,
 | 
				
			||||||
 | 
					) -> layout::Layout {
 | 
				
			||||||
 | 
					    let overlay = overlay.as_ref().map(String::as_str);
 | 
				
			||||||
 | 
					    let (found_kind, layout)
 | 
				
			||||||
 | 
					        = load_layout_data_with_fallback(&name, kind, variant, overlay);
 | 
				
			||||||
 | 
					    layout::Layout::new(layout, found_kind, variant)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
mod tests {
 | 
					mod tests {
 | 
				
			||||||
 | 
				
			|||||||
@ -226,7 +226,7 @@ bitflags!{
 | 
				
			|||||||
/// use rs::imservice::ContentPurpose;
 | 
					/// use rs::imservice::ContentPurpose;
 | 
				
			||||||
/// assert_eq!(ContentPurpose::Alpha as u32, 1);
 | 
					/// assert_eq!(ContentPurpose::Alpha as u32, 1);
 | 
				
			||||||
/// ```
 | 
					/// ```
 | 
				
			||||||
#[derive(Debug, Copy, Clone)]
 | 
					#[derive(Debug, Copy, Clone, PartialEq)]
 | 
				
			||||||
pub enum ContentPurpose {
 | 
					pub enum ContentPurpose {
 | 
				
			||||||
    Normal = 0,
 | 
					    Normal = 0,
 | 
				
			||||||
    Alpha = 1,
 | 
					    Alpha = 1,
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,7 @@ mod c {
 | 
				
			|||||||
    use crate::event_loop::driver;
 | 
					    use crate::event_loop::driver;
 | 
				
			||||||
    use crate::imservice::IMService;
 | 
					    use crate::imservice::IMService;
 | 
				
			||||||
    use crate::imservice::c::InputMethod;
 | 
					    use crate::imservice::c::InputMethod;
 | 
				
			||||||
 | 
					    use crate::layout;
 | 
				
			||||||
    use crate::outputs::Outputs;
 | 
					    use crate::outputs::Outputs;
 | 
				
			||||||
    use crate::state;
 | 
					    use crate::state;
 | 
				
			||||||
    use crate::submission::Submission;
 | 
					    use crate::submission::Submission;
 | 
				
			||||||
@ -79,6 +80,8 @@ mod c {
 | 
				
			|||||||
        #[allow(improper_ctypes)]
 | 
					        #[allow(improper_ctypes)]
 | 
				
			||||||
        fn init_wayland(wayland: *mut Wayland);
 | 
					        fn init_wayland(wayland: *mut Wayland);
 | 
				
			||||||
        fn eekboard_context_service_set_hint_purpose(service: HintManager, hint: u32, purpose: u32);
 | 
					        fn eekboard_context_service_set_hint_purpose(service: HintManager, hint: u32, purpose: u32);
 | 
				
			||||||
 | 
					        #[allow(improper_ctypes)]
 | 
				
			||||||
 | 
					        fn eekboard_context_service_set_layout(service: HintManager, layout: *const layout::Layout, timestamp: u32);
 | 
				
			||||||
        // This should probably only get called from the gtk main loop,
 | 
					        // This should probably only get called from the gtk main loop,
 | 
				
			||||||
        // given that dbus handler is using glib.
 | 
					        // given that dbus handler is using glib.
 | 
				
			||||||
        fn dbus_handler_set_visible(dbus: *const DBusHandler, visible: u8);
 | 
					        fn dbus_handler_set_visible(dbus: *const DBusHandler, visible: u8);
 | 
				
			||||||
@ -176,6 +179,7 @@ mod c {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        if let Some(commands::SetLayout { description }) = msg.layout_selection {
 | 
					        if let Some(commands::SetLayout { description }) = msg.layout_selection {
 | 
				
			||||||
 | 
					            //loading::
 | 
				
			||||||
            dbg!(description);
 | 
					            dbg!(description);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -462,6 +462,10 @@ Outcome:
 | 
				
			|||||||
                            kind: arrangement,
 | 
					                            kind: arrangement,
 | 
				
			||||||
                            name: layout_name,
 | 
					                            name: layout_name,
 | 
				
			||||||
                            overlay_name: overlay,
 | 
					                            overlay_name: overlay,
 | 
				
			||||||
 | 
					                            purpose: match self.im {
 | 
				
			||||||
 | 
					                                InputMethod::Active(InputMethodDetails { purpose, .. }) => purpose,
 | 
				
			||||||
 | 
					                                InputMethod::InactiveSince(_) => ContentPurpose::Normal,
 | 
				
			||||||
 | 
					                            },
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    };
 | 
					                    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user