AmendHub

Download:

jcs

/

wallops

/

amendments

/

100

chatter: Fix some annoying quirks with redrawing and input handling

If long text is typed in input_te and it starts scrolling
horizontally, when the TE is cleared and scrolled back to 0, 0, it
starts with the TE seemingly scrolled slightly over so the cursor
isn't visible. Fix this by reducing the inset margin to 0 and just
making the TE thinner.
 
Also fix the TE not getting reactivated on MultiFinder activation.
 
And finally, use the new static input buffer rather than malloc'ing
a small buffer every time.

jcs made amendment 100 about 1 month ago
--- chatter.c Thu Sep 12 21:59:44 2024 +++ chatter.c Fri Sep 13 17:51:11 2024 @@ -184,14 +184,15 @@ chatter_layout(struct chatter *chatter, bool init, Rec win_bounds = &chatter->win->portRect; /* input */ - bounds.left = win_bounds->left; - bounds.right = win_bounds->right - SCROLLBAR_WIDTH + 1; + bounds.left = win_bounds->left + 3; + bounds.right = win_bounds->right - SCROLLBAR_WIDTH + 1 - 3; bounds.top = win_bounds->bottom - SCROLLBAR_WIDTH + 1; bounds.bottom = win_bounds->bottom; + inset_bounds = bounds; + inset_bounds.top += 1; + inset_bounds.bottom -= 1; + inset_bounds.right = win_bounds->right * 2; if (init) { - inset_bounds = bounds; - InsetRect(&inset_bounds, 3, 1); - inset_bounds.right = win_bounds->right * 2; chatter->input_te = TENew(&inset_bounds, &bounds); HLock(chatter->input_te); (*(chatter->input_te))->crOnly = -1; @@ -201,8 +202,7 @@ chatter_layout(struct chatter *chatter, bool init, Rec } else { HLock(chatter->input_te); (*(chatter->input_te))->viewRect = bounds; - InsetRect(&bounds, 3, 1); - (*(chatter->input_te))->destRect = bounds; + (*(chatter->input_te))->destRect = inset_bounds; TECalText(chatter->input_te); HUnlock(chatter->input_te); } @@ -423,6 +423,10 @@ chatter_resume(struct focusable *focusable, EventRecor struct chatter *chatter = (struct chatter *)(focusable->cookie); focusable_show(focusable); + if (chatter->current_tab->nick_list) + LActivate(true, chatter->current_tab->nick_list); + TEActivate(chatter->current_tab->messages_te); + TEActivate(chatter->input_te); InvalRect(&chatter->win->portRect); } @@ -578,7 +582,7 @@ chatter_update(struct focusable *focusable, EventRecor HLock(chatter->input_te); r = (*(chatter->input_te))->viewRect; - InsetRect(&r, -1, -1); + InsetRect(&r, -4, -1); FrameRect(&r); TEUpdate(&(*(chatter->input_te))->viewRect, chatter->input_te); HUnlock(chatter->input_te); @@ -1041,26 +1045,28 @@ chatter_key_down(struct focusable *focusable, EventRec struct chatter *chatter = (struct chatter *)(focusable->cookie); struct chatter_tab *tab = chatter->current_tab; TERec *te; - char *input, k; + char k; k = (event->message & charCodeMask); if (k == '\r') { HLock(chatter->input_te); te = *(chatter->input_te); HLock(te->hText); - (*(te->hText))[te->teLength] = '\0'; - input = xstrdup(*(te->hText)); - TESetText(&k, 0, chatter->input_te); - TEScroll(0, 0, chatter->input_te); + memcpy(chatter->input, *(te->hText), + MIN(te->teLength, sizeof(chatter->input) - 1)); + chatter->input[MIN(te->teLength, sizeof(chatter->input) - 1)] = '\0'; EraseRect(&te->viewRect); + TESetText("", 0, chatter->input_te); + TEPinScroll(-SHRT_MAX, SHRT_MAX, chatter->input_te); ValidRect(&te->viewRect); TEIdle(chatter->input_te); HUnlock(te->hText); HUnlock(chatter->input_te); irc_process_input(tab->conn, tab->channel, - (tab->query_nick[0] ? tab->query_nick : NULL), input); - xfree(&input); - } else { + (tab->query_nick[0] ? tab->query_nick : NULL), chatter->input); + /* this is needed to get TEIdle working again */ + TESelView(chatter->input_te); + } else if (te->teLength < IRC_MAX_MSG_SIZE - 1) { TEKey(k, chatter->input_te); TESelView(chatter->input_te); }