Skip to content

Commit

Permalink
ios: unbreak on-screen-keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
andoma committed Aug 15, 2016
1 parent 0b4551b commit 264700f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 35 deletions.
7 changes: 7 additions & 0 deletions ios/Movian/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ - (void)tearDownGL;
@interface GLWView: GLKView <UIKeyInput>
@property (nonatomic) prop_t *eventSink;
@property (nonatomic) glw_rect_t rect;
@property (nonatomic) glw_root_t *gr;
@property (nonatomic) int oskscroll;
@end

Expand Down Expand Up @@ -71,6 +72,7 @@ - (BOOL)canBecomeFirstResponder {

- (void)openOSKforWidget:(struct glw *)w position:(const glw_rect_t *)rect
{
self.gr = w->glw_root;
self.rect = *rect;
[self becomeFirstResponder];
}
Expand All @@ -94,6 +96,11 @@ - (void)keyboardWasShown:(NSNotification*)aNotification
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
self.oskscroll = 0;
if(self.gr) {
glw_lock(self.gr);
glw_osk_close(self.gr);
glw_unlock(self.gr);
}
}
#endif

Expand Down
94 changes: 64 additions & 30 deletions src/ui/glw/glw.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const float glw_identitymtx[16] = {
0,0,0,1};


static void glw_osk_open(glw_root_t *gr, const char *title, const char *input,
glw_t *w, int password);
static void glw_osk_open_default(glw_root_t *gr, const char *title, const char *input,
glw_t *w, int password);


/*
Expand Down Expand Up @@ -309,7 +309,7 @@ glw_init4(glw_root_t *gr,
gr->gr_ui_start = arch_get_ts();
gr->gr_frame_start = gr->gr_ui_start;
glw_register_activity(gr);
gr->gr_open_osk = glw_osk_open;
gr->gr_open_osk = glw_osk_open_default;
return 0;
}

Expand Down Expand Up @@ -2404,6 +2404,15 @@ glw_dispatch_event(glw_root_t *gr, event_t *e)
{
runcontrol_activity();

if(gr->gr_osk_widget != NULL) {
if(event_is_type(e, EVENT_INSERT_STRING) ||
event_is_action(e, ACTION_ENTER) ||
event_is_action(e, ACTION_BS)) {
glw_event_to_widget(gr->gr_osk_widget, e);
return;
}
}

if(e->e_type == EVENT_REPAINT_UI) {
glw_text_flush(gr);
return;
Expand Down Expand Up @@ -3127,6 +3136,19 @@ glw_osk_text(void *opaque, const char *str)
}
}


/**
*
*/
void
glw_osk_close(glw_root_t *gr)
{
glw_unref(gr->gr_osk_widget);
gr->gr_osk_widget = NULL;
}



/**
*
*/
Expand All @@ -3144,13 +3166,12 @@ glw_osk_done(glw_root_t *gr, int submit)
w->glw_class->gc_update_text(w, gr->gr_osk_revert);
}

glw_unref(gr->gr_osk_widget);
prop_unsubscribe(gr->gr_osk_text_sub);
prop_unsubscribe(gr->gr_osk_ev_sub);

gr->gr_osk_widget = NULL;
gr->gr_osk_text_sub = NULL;
gr->gr_osk_ev_sub = NULL;
glw_osk_close(gr);
}

prop_t *osk = prop_create(gr->gr_prop_ui, "osk");
Expand Down Expand Up @@ -3184,42 +3205,55 @@ glw_osk_event(void *opaque, prop_event_t event, ...)
/**
*
*/
static void
void
glw_osk_open(glw_root_t *gr, const char *title, const char *input,
glw_t *w, int password)
glw_t *w, int password)
{
prop_t *osk = prop_create(gr->gr_prop_ui, "osk");
mystrset(&gr->gr_osk_revert, input);

if(gr->gr_osk_widget != NULL) {
if(gr->gr_osk_widget != NULL)
glw_unref(gr->gr_osk_widget);
prop_unsubscribe(gr->gr_osk_text_sub);
prop_unsubscribe(gr->gr_osk_ev_sub);
}

gr->gr_osk_widget = w;
glw_ref(w);

gr->gr_open_osk(gr, title, input, w, password);
}


/**
*
*/
static void
glw_osk_open_default(glw_root_t *gr, const char *title, const char *input,
glw_t *w, int password)
{
prop_t *osk = prop_create(gr->gr_prop_ui, "osk");

prop_unsubscribe(gr->gr_osk_text_sub);
prop_unsubscribe(gr->gr_osk_ev_sub);

prop_set(osk, "title", PROP_SET_STRING, title);
prop_set(osk, "text", PROP_SET_STRING, input);
prop_set(osk, "password", PROP_SET_INT, password);
prop_set(osk, "show", PROP_SET_INT, 1);

gr->gr_osk_widget = w;
glw_ref(w);



gr->gr_osk_text_sub =
prop_subscribe(0,
PROP_TAG_CALLBACK_STRING, glw_osk_text, gr,
PROP_TAG_NAME("ui", "osk", "text"),
PROP_TAG_ROOT, gr->gr_prop_ui,
PROP_TAG_COURIER, gr->gr_courier,
NULL);

prop_subscribe(0,
PROP_TAG_CALLBACK_STRING, glw_osk_text, gr,
PROP_TAG_NAME("ui", "osk", "text"),
PROP_TAG_ROOT, gr->gr_prop_ui,
PROP_TAG_COURIER, gr->gr_courier,
NULL);
gr->gr_osk_ev_sub =
prop_subscribe(0,
PROP_TAG_CALLBACK, glw_osk_event, gr,
PROP_TAG_NAME("ui", "osk", "eventSink"),
PROP_TAG_ROOT, gr->gr_prop_ui,
PROP_TAG_COURIER, gr->gr_courier,
NULL);
prop_subscribe(0,
PROP_TAG_CALLBACK, glw_osk_event, gr,
PROP_TAG_NAME("ui", "osk", "eventSink"),
PROP_TAG_ROOT, gr->gr_prop_ui,
PROP_TAG_COURIER, gr->gr_courier,
NULL);
}


Expand Down
6 changes: 6 additions & 0 deletions src/ui/glw/glw.h
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,12 @@ int glw_attrib_set_float4(float *dst, const float *src);
int glw_attrib_set_int16_4(int16_t *dst, const int16_t *src);


void glw_osk_close(glw_root_t *gr);

void glw_osk_open(glw_root_t *gr, const char *title, const char *input,
glw_t *w, int password);


/**
*
*/
Expand Down
10 changes: 5 additions & 5 deletions src/ui/glw/glw_text_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ glw_text_bitmap_layout(glw_t *w, const glw_rctx_t *rc)

gtb->gtb_paint_cursor =
gtb->gtb_flags & GTB_PERMANENT_CURSOR ||
(w->glw_class == &glw_text && glw_is_focused(w));
(w->glw_class == &glw_text && (glw_is_focused(w) || gr->gr_osk_widget == w));

if(gtb->gtb_paint_cursor && rc->rc_alpha > GLW_ALPHA_EPSILON)
glw_need_refresh(gr, 0);
Expand Down Expand Up @@ -724,10 +724,10 @@ glw_text_bitmap_event(glw_t *w, event_t *e)
if(event_is_action(e, ACTION_ACTIVATE) && e->e_flags & EVENT_MOUSE)
return 1;

w->glw_root->gr_open_osk(w->glw_root,
gtb->gtb_description,
gtb->gtb_caption, w,
gtb->gtb_flags & GTB_PASSWORD);
glw_osk_open(w->glw_root,
gtb->gtb_description,
gtb->gtb_caption, w,
gtb->gtb_flags & GTB_PASSWORD);
}
return 1;
}
Expand Down

0 comments on commit 264700f

Please sign in to comment.