Qt ui: turn off screen after inactivity (#2583)

* qt ui: turn off screen after inactivity

* handle touch events globally

* whitespace
old-commit-hash: 7f3bf2093f
commatwo_master
Willem Melching 5 years ago committed by GitHub
parent 2d2ff5733b
commit d7ab2ec365
  1. 2
      selfdrive/ui/qt/ui.cc
  2. 47
      selfdrive/ui/qt/window.cc
  3. 38
      selfdrive/ui/qt/window.hpp

@ -25,6 +25,8 @@ int main(int argc, char *argv[]) {
w.setFixedSize(vwp_w, vwp_h); w.setFixedSize(vwp_w, vwp_h);
w.show(); w.show();
a.installEventFilter(&w);
#ifdef QCOM2 #ifdef QCOM2
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
wl_surface *s = reinterpret_cast<wl_surface*>(native->nativeResourceForWindow("surface", w.windowHandle())); wl_surface *s = reinterpret_cast<wl_surface*>(native->nativeResourceForWindow("surface", w.windowHandle()));

@ -10,8 +10,6 @@
#include <QMouseEvent> #include <QMouseEvent>
#include "window.hpp" #include "window.hpp"
#include "offroad/settings.hpp"
#include "offroad/onboarding.hpp"
#include "paint.hpp" #include "paint.hpp"
#include "common/util.h" #include "common/util.h"
@ -22,6 +20,18 @@
volatile sig_atomic_t do_exit = 0; volatile sig_atomic_t do_exit = 0;
static void handle_display_state(UIState *s, int dt, bool user_input) {
static int awake_timeout = 0;
awake_timeout = std::max(awake_timeout-dt, 0);
if (user_input || s->ignition || s->started) {
s->awake = true;
awake_timeout = 30*UI_FREQ;
} else if (awake_timeout == 0){
s->awake = false;
}
}
static void set_backlight(int brightness){ static void set_backlight(int brightness){
std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness"); std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness");
if (brightness_control.is_open()){ if (brightness_control.is_open()){
@ -37,13 +47,13 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
set_core_affinity(7); set_core_affinity(7);
#endif #endif
GLWindow *glWindow = new GLWindow(this); glWindow = new GLWindow(this);
main_layout->addWidget(glWindow); main_layout->addWidget(glWindow);
SettingsWindow *settingsWindow = new SettingsWindow(this); settingsWindow = new SettingsWindow(this);
main_layout->addWidget(settingsWindow); main_layout->addWidget(settingsWindow);
OnboardingWindow *onboardingWindow = new OnboardingWindow(this); onboardingWindow = new OnboardingWindow(this);
main_layout->addWidget(onboardingWindow); main_layout->addWidget(onboardingWindow);
main_layout->setMargin(0); main_layout->setMargin(0);
@ -56,6 +66,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
QObject::connect(onboardingWindow, SIGNAL(onboardingDone()), this, SLOT(closeSettings())); QObject::connect(onboardingWindow, SIGNAL(onboardingDone()), this, SLOT(closeSettings()));
onboardingWindow->updateActiveScreen(); onboardingWindow->updateActiveScreen();
setStyleSheet(R"( setStyleSheet(R"(
* { * {
color: white; color: white;
@ -73,6 +84,14 @@ void MainWindow::closeSettings() {
} }
bool MainWindow::eventFilter(QObject *obj, QEvent *event){
if (event->type() == QEvent::MouseButtonPress) {
glWindow->wake();
}
return false;
}
GLWindow::GLWindow(QWidget *parent) : QOpenGLWidget(parent) { GLWindow::GLWindow(QWidget *parent) : QOpenGLWidget(parent) {
timer = new QTimer(this); timer = new QTimer(this);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate())); QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()));
@ -107,6 +126,8 @@ void GLWindow::initializeGL() {
ui_state->fb_h = vwp_h; ui_state->fb_h = vwp_h;
ui_init(ui_state); ui_init(ui_state);
wake();
timer->start(0); timer->start(0);
backlight_timer->start(BACKLIGHT_DT * 100); backlight_timer->start(BACKLIGHT_DT * 100);
} }
@ -119,11 +140,9 @@ void GLWindow::backlightUpdate(){
smooth_brightness = clipped_brightness * k + smooth_brightness * (1.0f - k); smooth_brightness = clipped_brightness * k + smooth_brightness * (1.0f - k);
int brightness = smooth_brightness; int brightness = smooth_brightness;
#ifdef QCOM2 if (!ui_state->awake){
if (!ui_state->started){ brightness = 0;
brightness = 150;
} }
#endif
std::thread{set_backlight, brightness}.detach(); std::thread{set_backlight, brightness}.detach();
} }
@ -136,6 +155,10 @@ void GLWindow::timerUpdate(){
} }
#endif #endif
// Fix awake timeout if running 1 Hz when offroad
int dt = timer->interval() == 0 ? 1 : 20;
handle_display_state(ui_state, dt, false);
ui_update(ui_state); ui_update(ui_state);
repaint(); repaint();
} }
@ -148,7 +171,13 @@ void GLWindow::paintGL() {
ui_draw(ui_state); ui_draw(ui_state);
} }
void GLWindow::wake(){
handle_display_state(ui_state, 1, true);
}
void GLWindow::mousePressEvent(QMouseEvent *e) { void GLWindow::mousePressEvent(QMouseEvent *e) {
wake();
// Settings button click // Settings button click
if (!ui_state->scene.uilayout_sidebarcollapsed && settings_btn.ptInRect(e->x(), e->y())) { if (!ui_state->scene.uilayout_sidebarcollapsed && settings_btn.ptInRect(e->x(), e->y())) {
emit openSettings(); emit openSettings();

@ -8,20 +8,8 @@
#include "qt/qt_sound.hpp" #include "qt/qt_sound.hpp"
#include "ui/ui.hpp" #include "ui/ui.hpp"
#include "offroad/settings.hpp"
class MainWindow : public QWidget { #include "offroad/onboarding.hpp"
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
private:
QStackedLayout *main_layout;
public slots:
void openSettings();
void closeSettings();
};
#ifdef QCOM2 #ifdef QCOM2
const int vwp_w = 2160; const int vwp_w = 2160;
@ -30,12 +18,14 @@ const int vwp_w = 1920;
#endif #endif
const int vwp_h = 1080; const int vwp_h = 1080;
class GLWindow : public QOpenGLWidget, protected QOpenGLFunctions { class GLWindow : public QOpenGLWidget, protected QOpenGLFunctions {
Q_OBJECT Q_OBJECT
public: public:
using QOpenGLWidget::QOpenGLWidget; using QOpenGLWidget::QOpenGLWidget;
explicit GLWindow(QWidget *parent = 0); explicit GLWindow(QWidget *parent = 0);
void wake();
~GLWindow(); ~GLWindow();
protected: protected:
@ -65,3 +55,23 @@ public slots:
signals: signals:
void openSettings(); void openSettings();
}; };
class MainWindow : public QWidget {
Q_OBJECT
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
public:
explicit MainWindow(QWidget *parent = 0);
private:
QStackedLayout *main_layout;
GLWindow *glWindow;
SettingsWindow *settingsWindow;
OnboardingWindow *onboardingWindow;
public slots:
void openSettings();
void closeSettings();
};

Loading…
Cancel
Save