input method: Pop up the keyboard
This commit is contained in:
		@ -2,6 +2,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <glib.h>
 | 
					#include <glib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "eekboard/eekboard-context-service.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void imservice_handle_text_change_cause(void *data, struct zwp_input_method_v2 *input_method) {}
 | 
					void imservice_handle_text_change_cause(void *data, struct zwp_input_method_v2 *input_method) {}
 | 
				
			||||||
void imservice_handle_content_type(void *data, struct zwp_input_method_v2 *input_method) {}
 | 
					void imservice_handle_content_type(void *data, struct zwp_input_method_v2 *input_method) {}
 | 
				
			||||||
@ -18,18 +20,24 @@ static const struct zwp_input_method_v2_listener input_method_listener = {
 | 
				
			|||||||
    .unavailable = imservice_handle_unavailable,
 | 
					    .unavailable = imservice_handle_unavailable,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct imservice* get_imservice(struct zwp_input_method_manager_v2 *manager,
 | 
					struct imservice* get_imservice(EekboardContextService *context,
 | 
				
			||||||
 | 
					                                struct zwp_input_method_manager_v2 *manager,
 | 
				
			||||||
                                struct wl_seat *seat) {
 | 
					                                struct wl_seat *seat) {
 | 
				
			||||||
    struct zwp_input_method_v2 *im = zwp_input_method_manager_v2_get_input_method(manager, seat);
 | 
					    struct zwp_input_method_v2 *im = zwp_input_method_manager_v2_get_input_method(manager, seat);
 | 
				
			||||||
    struct imservice *imservice = imservice_new(im);
 | 
					    struct imservice *imservice = imservice_new(im, context);
 | 
				
			||||||
    zwp_input_method_v2_add_listener(im,
 | 
					    zwp_input_method_v2_add_listener(im,
 | 
				
			||||||
        &input_method_listener, imservice);
 | 
					        &input_method_listener, imservice);
 | 
				
			||||||
    return imservice;
 | 
					    return imservice;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void imservice_make_visible(struct imservice *imservice) {
 | 
					void imservice_make_visible(EekboardContextService *context,
 | 
				
			||||||
    g_log("squeek", G_LOG_LEVEL_DEBUG, "Visibiling");
 | 
					                            struct zwp_input_method_v2 *im) {
 | 
				
			||||||
 | 
					    (void)im;
 | 
				
			||||||
 | 
					    eekboard_context_service_show_keyboard (context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
void imservice_try_hide(struct imservice *imservice) {
 | 
					
 | 
				
			||||||
    g_log("squeek", G_LOG_LEVEL_DEBUG, "Hiding");
 | 
					void imservice_try_hide(EekboardContextService *context,
 | 
				
			||||||
 | 
					                        struct zwp_input_method_v2 *im) {
 | 
				
			||||||
 | 
					    (void)im;
 | 
				
			||||||
 | 
					    eekboard_context_service_hide_keyboard (context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,16 +2,17 @@
 | 
				
			|||||||
#define __IMSERVICE_H
 | 
					#define __IMSERVICE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "input-method-unstable-v2-client-protocol.h"
 | 
					#include "input-method-unstable-v2-client-protocol.h"
 | 
				
			||||||
 | 
					#include "eek/eek-types.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct imservice;
 | 
					struct imservice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct imservice* get_imservice(struct zwp_input_method_manager_v2 *manager,
 | 
					struct imservice* get_imservice(EekboardContextService *context,
 | 
				
			||||||
 | 
					                                struct zwp_input_method_manager_v2 *manager,
 | 
				
			||||||
                                struct wl_seat *seat);
 | 
					                                struct wl_seat *seat);
 | 
				
			||||||
void imservice_make_visible(struct imservice *imservice);
 | 
					 | 
				
			||||||
void imservice_try_hide(struct imservice *imservice);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Defined in Rust
 | 
					// Defined in Rust
 | 
				
			||||||
struct imservice* imservice_new(struct zwp_input_method_v2 *im);
 | 
					struct imservice* imservice_new(struct zwp_input_method_v2 *im,
 | 
				
			||||||
 | 
					                                EekboardContextService *context);
 | 
				
			||||||
void imservice_handle_input_method_activate(void *data, struct zwp_input_method_v2 *input_method);
 | 
					void imservice_handle_input_method_activate(void *data, struct zwp_input_method_v2 *input_method);
 | 
				
			||||||
void imservice_handle_input_method_deactivate(void *data, struct zwp_input_method_v2 *input_method);
 | 
					void imservice_handle_input_method_deactivate(void *data, struct zwp_input_method_v2 *input_method);
 | 
				
			||||||
void imservice_handle_surrounding_text(void *data, struct zwp_input_method_v2 *input_method,
 | 
					void imservice_handle_surrounding_text(void *data, struct zwp_input_method_v2 *input_method,
 | 
				
			||||||
 | 
				
			|||||||
@ -19,24 +19,29 @@ pub mod c {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    // The following defined in C
 | 
					    // The following defined in C
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    /// struct zwp_input_method_v2 *input_method
 | 
					    /// struct zwp_input_method_v2*
 | 
				
			||||||
    #[repr(transparent)]
 | 
					    #[repr(transparent)]
 | 
				
			||||||
    pub struct InputMethod(*const c_void);
 | 
					    pub struct InputMethod(*const c_void);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    /// EekboardContextService*
 | 
				
			||||||
 | 
					    #[repr(transparent)]
 | 
				
			||||||
 | 
					    pub struct UIManager(*const c_void);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    #[no_mangle]
 | 
					    #[no_mangle]
 | 
				
			||||||
    extern "C" {
 | 
					    extern "C" {
 | 
				
			||||||
        fn imservice_make_visible(imservice: *mut IMService);
 | 
					        fn imservice_make_visible(imservice: *const UIManager);
 | 
				
			||||||
        fn imservice_try_hide(imservice: *mut IMService);
 | 
					        fn imservice_try_hide(imservice: *const UIManager);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers
 | 
					    // The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    #[no_mangle]
 | 
					    #[no_mangle]
 | 
				
			||||||
    pub unsafe extern "C"
 | 
					    pub unsafe extern "C"
 | 
				
			||||||
    fn imservice_new(im: *const InputMethod) -> *mut IMService {
 | 
					    fn imservice_new(im: *const InputMethod, ui_manager: *const UIManager) -> *mut IMService {
 | 
				
			||||||
        Box::<IMService>::into_raw(Box::new(
 | 
					        Box::<IMService>::into_raw(Box::new(
 | 
				
			||||||
            IMService {
 | 
					            IMService {
 | 
				
			||||||
                im: im,
 | 
					                im: im,
 | 
				
			||||||
 | 
					                ui_manager: ui_manager,
 | 
				
			||||||
                pending: IMProtocolState::default(),
 | 
					                pending: IMProtocolState::default(),
 | 
				
			||||||
                current: IMProtocolState::default(),
 | 
					                current: IMProtocolState::default(),
 | 
				
			||||||
                preedit_string: String::new(),
 | 
					                preedit_string: String::new(),
 | 
				
			||||||
@ -87,10 +92,10 @@ pub mod c {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    #[no_mangle]
 | 
					    #[no_mangle]
 | 
				
			||||||
    pub unsafe extern "C"
 | 
					    pub unsafe extern "C"
 | 
				
			||||||
    fn imservice_handle_commit_state(imservice_ptr: *mut IMService,
 | 
					    fn imservice_handle_commit_state(imservice: *mut IMService,
 | 
				
			||||||
        _im: *const InputMethod)
 | 
					        _im: *const InputMethod)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        let imservice = &mut *imservice_ptr;
 | 
					        let imservice = &mut *imservice;
 | 
				
			||||||
        let active_changed = imservice.current.active ^ imservice.pending.active;
 | 
					        let active_changed = imservice.current.active ^ imservice.pending.active;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        imservice.serial += Wrapping(1u32);
 | 
					        imservice.serial += Wrapping(1u32);
 | 
				
			||||||
@ -101,14 +106,14 @@ pub mod c {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
        if active_changed {
 | 
					        if active_changed {
 | 
				
			||||||
            if imservice.current.active {
 | 
					            if imservice.current.active {
 | 
				
			||||||
                imservice_make_visible(imservice_ptr);
 | 
					                imservice_make_visible(imservice.ui_manager);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                imservice_try_hide(imservice_ptr);
 | 
					                imservice_try_hide(imservice.ui_manager);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    // FIXME: destroy
 | 
					    // FIXME: destroy and deallocate
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Describes the desired state of the input method as requested by the server
 | 
					/// Describes the desired state of the input method as requested by the server
 | 
				
			||||||
@ -120,9 +125,13 @@ struct IMProtocolState {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct IMService {
 | 
					pub struct IMService {
 | 
				
			||||||
 | 
					    /// Owned reference (still created and destroyed in C)
 | 
				
			||||||
    im: *const c::InputMethod,
 | 
					    im: *const c::InputMethod,
 | 
				
			||||||
 | 
					    /// Unowned reference. Be careful, it's shared with C at large
 | 
				
			||||||
 | 
					    ui_manager: *const c::UIManager,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pending: IMProtocolState,
 | 
					    pending: IMProtocolState,
 | 
				
			||||||
    current: IMProtocolState, // turn into an idiomatic representation?
 | 
					    current: IMProtocolState, // turn current into an idiomatic representation?
 | 
				
			||||||
    preedit_string: String,
 | 
					    preedit_string: String,
 | 
				
			||||||
    serial: Wrapping<u32>,
 | 
					    serial: Wrapping<u32>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -251,7 +251,8 @@ main (int argc, char **argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    struct imservice *imservice = NULL;
 | 
					    struct imservice *imservice = NULL;
 | 
				
			||||||
    if (instance.wayland.input_method_manager) {
 | 
					    if (instance.wayland.input_method_manager) {
 | 
				
			||||||
        imservice = get_imservice(instance.wayland.input_method_manager,
 | 
					        imservice = get_imservice(instance.context,
 | 
				
			||||||
 | 
					                                  instance.wayland.input_method_manager,
 | 
				
			||||||
                                  instance.wayland.seat);
 | 
					                                  instance.wayland.seat);
 | 
				
			||||||
        if (imservice) {
 | 
					        if (imservice) {
 | 
				
			||||||
            instance.imservice = imservice;
 | 
					            instance.imservice = imservice;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user