summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ui/inputwidget.c55
-rw-r--r--src/ui/root.c2
-rw-r--r--src/ui/text.c35
-rw-r--r--src/ui/window.c1
4 files changed, 54 insertions, 39 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index a40b77eb..a1635128 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -74,6 +74,7 @@ enum iInputWidgetFlag {
74 eatEscape_InputWidgetFlag = iBit(6), 74 eatEscape_InputWidgetFlag = iBit(6),
75 isMarking_InputWidgetFlag = iBit(7), 75 isMarking_InputWidgetFlag = iBit(7),
76 markWords_InputWidgetFlag = iBit(8), 76 markWords_InputWidgetFlag = iBit(8),
77 needUpdateBuffer_InputWidgetFlag = iBit(9),
77}; 78};
78 79
79struct Impl_InputWidget { 80struct Impl_InputWidget {
@@ -301,29 +302,29 @@ static iString *visText_InputWidget_(const iInputWidget *d) {
301} 302}
302 303
303static void updateBuffered_InputWidget_(iInputWidget *d) { 304static void updateBuffered_InputWidget_(iInputWidget *d) {
304 if (isExposed_Window(get_Window())) { 305 iWindow *win = get_Window();
305 invalidateBuffered_InputWidget_(d); 306 invalidateBuffered_InputWidget_(d);
306 iString *bufText = NULL; 307 iString *bufText = NULL;
307 if (d->inFlags & isUrl_InputWidgetFlag) { 308 if (d->inFlags & isUrl_InputWidgetFlag && as_Widget(d)->root == win->keyRoot) {
308 /* Highlight the host name. */ 309 /* Highlight the host name. */
309 iUrl parts; 310 iUrl parts;
310 const iString *text = collect_String(utf32toUtf8_InputWidget_(d)); 311 const iString *text = collect_String(utf32toUtf8_InputWidget_(d));
311 init_Url(&parts, text); 312 init_Url(&parts, text);
312 if (!isEmpty_Range(&parts.host)) { 313 if (!isEmpty_Range(&parts.host)) {
313 bufText = new_String(); 314 bufText = new_String();
314 appendRange_String(bufText, (iRangecc){ constBegin_String(text), parts.host.start }); 315 appendRange_String(bufText, (iRangecc){ constBegin_String(text), parts.host.start });
315 appendCStr_String(bufText, uiTextStrong_ColorEscape); 316 appendCStr_String(bufText, uiTextStrong_ColorEscape);
316 appendRange_String(bufText, parts.host); 317 appendRange_String(bufText, parts.host);
317 appendCStr_String(bufText, restore_ColorEscape); 318 appendCStr_String(bufText, restore_ColorEscape);
318 appendRange_String(bufText, (iRangecc){ parts.host.end, constEnd_String(text) }); 319 appendRange_String(bufText, (iRangecc){ parts.host.end, constEnd_String(text) });
319 }
320 }
321 if (!bufText) {
322 bufText = visText_InputWidget_(d);
323 } 320 }
324 d->buffered = new_TextBuf(d->font, uiInputText_ColorId, cstr_String(bufText));
325 delete_String(bufText);
326 } 321 }
322 if (!bufText) {
323 bufText = visText_InputWidget_(d);
324 }
325 d->buffered = new_TextBuf(d->font, uiInputText_ColorId, cstr_String(bufText));
326 delete_String(bufText);
327 d->inFlags &= ~needUpdateBuffer_InputWidgetFlag;
327} 328}
328 329
329void setText_InputWidget(iInputWidget *d, const iString *text) { 330void setText_InputWidget(iInputWidget *d, const iString *text) {
@@ -356,7 +357,7 @@ void setText_InputWidget(iInputWidget *d, const iString *text) {
356 iZap(d->mark); 357 iZap(d->mark);
357 } 358 }
358 if (!isFocused_Widget(d)) { 359 if (!isFocused_Widget(d)) {
359 updateBuffered_InputWidget_(d); 360 d->inFlags |= needUpdateBuffer_InputWidgetFlag;
360 } 361 }
361 refresh_Widget(as_Widget(d)); 362 refresh_Widget(as_Widget(d));
362} 363}
@@ -428,7 +429,7 @@ void end_InputWidget(iInputWidget *d, iBool accept) {
428 if (!accept) { 429 if (!accept) {
429 setCopy_Array(&d->text, &d->oldText); 430 setCopy_Array(&d->text, &d->oldText);
430 } 431 }
431 updateBuffered_InputWidget_(d); 432 d->inFlags |= needUpdateBuffer_InputWidgetFlag;
432 SDL_RemoveTimer(d->timer); 433 SDL_RemoveTimer(d->timer);
433 d->timer = 0; 434 d->timer = 0;
434 SDL_StopTextInput(); 435 SDL_StopTextInput();
@@ -705,6 +706,9 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
705 begin_InputWidget(d); 706 begin_InputWidget(d);
706 return iFalse; 707 return iFalse;
707 } 708 }
709 else if (isCommand_UserEvent(ev, "keyroot.changed")) {
710 d->inFlags |= needUpdateBuffer_InputWidgetFlag;
711 }
708 else if (isCommand_UserEvent(ev, "lang.changed")) { 712 else if (isCommand_UserEvent(ev, "lang.changed")) {
709 set_String(&d->hint, &d->srcHint); 713 set_String(&d->hint, &d->srcHint);
710 translate_Lang(&d->hint); 714 translate_Lang(&d->hint);
@@ -725,7 +729,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
725 } 729 }
726 else if (isCommand_UserEvent(ev, "theme.changed")) { 730 else if (isCommand_UserEvent(ev, "theme.changed")) {
727 if (d->buffered) { 731 if (d->buffered) {
728 updateBuffered_InputWidget_(d); 732 d->inFlags |= needUpdateBuffer_InputWidgetFlag;
729 } 733 }
730 return iFalse; 734 return iFalse;
731 } 735 }
@@ -1004,6 +1008,9 @@ static void draw_InputWidget_(const iInputWidget *d) {
1004 const iBool isFocused = isFocused_Widget(w); 1008 const iBool isFocused = isFocused_Widget(w);
1005 const iBool isHover = isHover_Widget(w) && 1009 const iBool isHover = isHover_Widget(w) &&
1006 contains_Widget(w, mouseCoord_Window(get_Window())); 1010 contains_Widget(w, mouseCoord_Window(get_Window()));
1011 if (d->inFlags & needUpdateBuffer_InputWidgetFlag) {
1012 updateBuffered_InputWidget_(iConstCast(iInputWidget *, d));
1013 }
1007 iPaint p; 1014 iPaint p;
1008 init_Paint(&p); 1015 init_Paint(&p);
1009 iString *text = visText_InputWidget_(d); 1016 iString *text = visText_InputWidget_(d);
diff --git a/src/ui/root.c b/src/ui/root.c
index 35eb84ef..548c0ca8 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -655,7 +655,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
655 /* React to the current document only. */ 655 /* React to the current document only. */
656 if (document_Command(cmd) == document_App()) { 656 if (document_Command(cmd) == document_App()) {
657 if (equal_Command(cmd, "document.changed")) { 657 if (equal_Command(cmd, "document.changed")) {
658 iInputWidget *url = findWidget_App("url"); 658 iInputWidget *url = findWidget_Root("url");
659 const iString *urlStr = collect_String(suffix_Command(cmd, "url")); 659 const iString *urlStr = collect_String(suffix_Command(cmd, "url"));
660 trimCache_App(); 660 trimCache_App();
661 visitUrl_Visited(visited_App(), withSpacesEncoded_String(urlStr), 0); /* TODO: internal URI normalization */ 661 visitUrl_Visited(visited_App(), withSpacesEncoded_String(urlStr), 0); /* TODO: internal URI normalization */
diff --git a/src/ui/text.c b/src/ui/text.c
index e0aafc33..34e20bf1 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -1445,20 +1445,27 @@ void init_TextBuf(iTextBuf *d, int font, int color, const char *text) {
1445 SDL_Renderer *render = text_.render; 1445 SDL_Renderer *render = text_.render;
1446 d->size = advance_Text(font, text); 1446 d->size = advance_Text(font, text);
1447 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); 1447 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
1448 d->texture = SDL_CreateTexture(render, 1448 if (d->size.x * d->size.y) {
1449 SDL_PIXELFORMAT_RGBA4444, 1449 d->texture = SDL_CreateTexture(render,
1450 SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, 1450 SDL_PIXELFORMAT_RGBA4444,
1451 d->size.x, 1451 SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET,
1452 d->size.y); 1452 d->size.x,
1453 SDL_Texture *oldTarget = SDL_GetRenderTarget(render); 1453 d->size.y);
1454 SDL_SetRenderTarget(render, d->texture); 1454 }
1455 SDL_SetTextureBlendMode(text_.cache, SDL_BLENDMODE_NONE); /* blended when TextBuf is drawn */ 1455 else {
1456 SDL_SetRenderDrawColor(text_.render, 0, 0, 0, 0); 1456 d->texture = NULL;
1457 SDL_RenderClear(text_.render); 1457 }
1458 draw_Text_(font, zero_I2(), color | fillBackground_ColorId, range_CStr(text)); 1458 if (d->texture) {
1459 SDL_SetTextureBlendMode(text_.cache, SDL_BLENDMODE_BLEND); 1459 SDL_Texture *oldTarget = SDL_GetRenderTarget(render);
1460 SDL_SetRenderTarget(render, oldTarget); 1460 SDL_SetRenderTarget(render, d->texture);
1461 SDL_SetTextureBlendMode(d->texture, SDL_BLENDMODE_BLEND); 1461 SDL_SetTextureBlendMode(text_.cache, SDL_BLENDMODE_NONE); /* blended when TextBuf is drawn */
1462 SDL_SetRenderDrawColor(text_.render, 0, 0, 0, 0);
1463 SDL_RenderClear(text_.render);
1464 draw_Text_(font, zero_I2(), color | fillBackground_ColorId, range_CStr(text));
1465 SDL_SetTextureBlendMode(text_.cache, SDL_BLENDMODE_BLEND);
1466 SDL_SetRenderTarget(render, oldTarget);
1467 SDL_SetTextureBlendMode(d->texture, SDL_BLENDMODE_BLEND);
1468 }
1462} 1469}
1463 1470
1464void deinit_TextBuf(iTextBuf *d) { 1471void deinit_TextBuf(iTextBuf *d) {
diff --git a/src/ui/window.c b/src/ui/window.c
index 704e6f2a..61851ca5 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -903,6 +903,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) {
903iBool setKeyRoot_Window(iWindow *d, iRoot *root) { 903iBool setKeyRoot_Window(iWindow *d, iRoot *root) {
904 if (d->keyRoot != root) { 904 if (d->keyRoot != root) {
905 d->keyRoot = root; 905 d->keyRoot = root;
906 postCommand_App("keyroot.changed");
906 postRefresh_App(); 907 postRefresh_App();
907 return iTrue; 908 return iTrue;
908 } 909 }