refresh mit cooldown

This commit is contained in:
Tristan Krause 2019-04-05 13:29:14 +02:00
parent 167e0a3ce8
commit 24688ff183
5 changed files with 33 additions and 6 deletions

Binary file not shown.

View file

@ -14,6 +14,9 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <future>
#include <thread>
#include <chrono>
#include "ui/view_selection.h" #include "ui/view_selection.h"
#include "ui/view_info.h" #include "ui/view_info.h"
#include "ui/view_monitor.h" #include "ui/view_monitor.h"
@ -25,8 +28,14 @@ std::string ERR_MSG;
std::vector<View*> win_stack; std::vector<View*> win_stack;
volatile int win_changed_cooldown = 0;
volatile bool t_refresh_active = false;
std::thread t_refresh;
void cleanup() void cleanup()
{ {
if(t_refresh.joinable())
t_refresh.join();
clrtoeol(); clrtoeol();
refresh(); refresh();
endwin(); endwin();
@ -36,11 +45,26 @@ void signal_handler(int signal)
{ {
if(signal == SIGWINCH) if(signal == SIGWINCH)
{ {
if(win_stack.size()) win_changed_cooldown = 10; // 100ms
if (!t_refresh_active)
{ {
usleep(1000); if(t_refresh.joinable())
win_stack.back()->repaint(); t_refresh.join();
t_refresh_active = true;
t_refresh = std::thread([](){
while(win_changed_cooldown--)
std::this_thread::sleep_for(std::chrono::milliseconds(10));
t_refresh_active = false;
if(win_stack.size())
win_stack.back()->repaint();
});
} }
} }
else if(signal == SIGINT) else if(signal == SIGINT)
{ {
@ -56,7 +80,7 @@ void init()
{ {
// init b15 driver // init b15 driver
B15F::getInstance(); B15F::getInstance();
//std::cout << std::endl << "Starte in 3s ..." << std::endl; std::cout << std::endl << "Starte in 3s ..." << std::endl;
//sleep(3); //sleep(3);
// init all ncurses stuff // init all ncurses stuff

BIN
driver/main Executable file

Binary file not shown.

View file

@ -58,9 +58,8 @@ std::function<void(int)> ViewPromt::keypress(int& key)
if(input.length()) if(input.length())
input.pop_back(); input.pop_back();
break; break;
case '\t':
case KEY_LEFT: case KEY_LEFT:
selection = (selection + 1 ) % 2;
break;
case KEY_RIGHT: case KEY_RIGHT:
selection = (selection + 1 ) % 2; selection = (selection + 1 ) % 2;
break; break;

View file

@ -29,11 +29,14 @@ std::function<void(int)> ViewSelection::keypress(int& key)
selection = (selection - 1 + choices.size()) % choices.size(); selection = (selection - 1 + choices.size()) % choices.size();
while(!choices[selection].length() && choices.size()); while(!choices[selection].length() && choices.size());
break; break;
case '\t':
case KEY_DOWN: case KEY_DOWN:
do do
selection = (selection + 1) % choices.size(); selection = (selection + 1) % choices.size();
while(!choices[selection].length() && choices.size()); while(!choices[selection].length() && choices.size());
break; break;
case KEY_MOUSE: case KEY_MOUSE:
{ {
// http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
@ -58,6 +61,7 @@ std::function<void(int)> ViewSelection::keypress(int& key)
// fall through to next case // fall through to next case
__attribute__ ((fallthrough)); __attribute__ ((fallthrough));
} }
case KEY_ENT: case KEY_ENT:
if(selection == choices.size() - 1) // exit if(selection == choices.size() - 1) // exit
key = -1; // do return from view key = -1; // do return from view