attempt to lessen screentearing
This commit is contained in:
parent
9a6786b2b5
commit
7a35f96a9a
4 changed files with 96 additions and 35 deletions
|
|
@ -1,11 +1,45 @@
|
|||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "_ncurses.h"
|
||||
#include "ncrswrap.h"
|
||||
#include "ncurses.h"
|
||||
#include "node.h"
|
||||
#include "tree.h"
|
||||
|
||||
volatile sig_atomic_t got_winch = 0;
|
||||
|
||||
void handle_SIGWINCH(int sig) {
|
||||
// endwin();
|
||||
// Needs to be called after an endwin() so ncurses will initialize
|
||||
// itself with the new terminal dimensions.
|
||||
got_winch = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If ncurses is configured to supply its own SIGWINCH handler,
|
||||
* - on receipt of a SIGWINCH, the handler sets a flag
|
||||
* - which is tested in wgetch(3X), doupdate(3X) and restartterm(3X),
|
||||
* - in turn, calling the resizeterm function,
|
||||
* - which ungetch's a KEY_RESIZE which will be read on the next call to
|
||||
* wgetch. REF: `man resizeterm(3x)`
|
||||
*/
|
||||
static void bind_SIGWINCH(void) {
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = handle_SIGWINCH;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART; /* Restart functions if
|
||||
interrupted by handler */
|
||||
if (sigaction(SIGWINCH, &sa, NULL) == -1) {
|
||||
perror("bind_SIGWINCH");
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
int ct_init(struct ct_tree **const tree) {
|
||||
// bind_SIGWINCH();
|
||||
/* Initialise NCurses Library & Root Node */
|
||||
init_ncurses();
|
||||
init_tree(tree);
|
||||
|
|
@ -34,10 +68,13 @@ static int __update_rec(struct ct_node *const node) {
|
|||
*/
|
||||
dims = IS_ROOT_NODE(node) ? termdims() : dup_dims(node->surface->dims);
|
||||
resize_node(node, dims);
|
||||
node->flags &= ~NFLAG_RESIZE;
|
||||
result = 1;
|
||||
}
|
||||
if (node->surface->updatereq) {
|
||||
sfflush(node->surface);
|
||||
// TODO: is this necessary or does mvresize_win do this for us?
|
||||
wnoutrefresh(node->surface->win);
|
||||
node->surface->updatereq = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < node->cindex; i++) {
|
||||
|
|
@ -47,7 +84,17 @@ static int __update_rec(struct ct_node *const node) {
|
|||
}
|
||||
|
||||
void ct_update(struct ct_tree *const tree) {
|
||||
// WARNING: update_rec does not flush the screen, wgetch will do that for us
|
||||
if (__update_rec(tree->root)) {
|
||||
doupdate();
|
||||
// redrawwin(curscr);
|
||||
// wrefresh(curscr);
|
||||
}
|
||||
}
|
||||
|
||||
void ct_process(struct ct_tree *const tree) {
|
||||
const int key = wgetch(curscr);
|
||||
// int key = -1;
|
||||
|
||||
/* ncurses binds a SIGWINCH handler if SIGWINCH has SIG_DFL disposition
|
||||
* when initscr(3x) is called. This handler emits KEY_RESIZE (decimal 410) to
|
||||
|
|
@ -58,8 +105,9 @@ void ct_update(struct ct_tree *const tree) {
|
|||
// wclear(tree->root->surface->win);
|
||||
// mvwprintw(tree->root->surface->win, 0, 0, " \r-1\n");
|
||||
// wrefresh(tree->root->surface->win);
|
||||
return;
|
||||
break;
|
||||
case KEY_RESIZE:
|
||||
// got_winch = 1;
|
||||
tree->root->flags |= NFLAG_RESIZE;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -69,7 +117,12 @@ void ct_update(struct ct_tree *const tree) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (__update_rec(tree->root)) {
|
||||
ct_redraw();
|
||||
}
|
||||
// if (got_winch == 1) {
|
||||
// tree->root->flags |= NFLAG_RESIZE;
|
||||
// got_winch = 0;
|
||||
// }
|
||||
|
||||
// if (__update_rec(tree->root)) {
|
||||
// ct_redraw();
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@
|
|||
/* === External Interface === */
|
||||
int ct_init(struct ct_tree **const tree);
|
||||
void ct_update(struct ct_tree *const tree);
|
||||
void ct_process(struct ct_tree *const tree);
|
||||
|
||||
#endif /* CURSETREE_CURSETREE_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue