Skip to content

Commit

Permalink
fix: reduce darkreader mode white flash further by using QWebEnginePa…
Browse files Browse the repository at this point in the history
…ge::setBackgroundColor() (for Qt6.6.3+) (#1406)

* fix: reduce darkreader mode white flash further by using
QWebEnginePage::setBackgroundColor() (for Qt6.6.3+)

In previous Qt6.x versions, this function only set background once and
become invalidated if reload a page.

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
shenlebantongying and autofix-ci[bot] authored Feb 27, 2024
1 parent 6e00732 commit 32391bd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/ui/articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ ArticleView::ArticleView( QWidget * parent,

webview->setUp( const_cast< Config::Class * >( &cfg ) );

syncBackgroundColorWithCfgDarkReader();

goBackAction.setShortcut( QKeySequence( "Alt+Left" ) );
webview->addAction( &goBackAction );
connect( &goBackAction, &QAction::triggered, this, &ArticleView::back );
Expand Down Expand Up @@ -1360,6 +1362,20 @@ void ArticleView::setDelayedHighlightText( QString const & text )
delayedHighlightText = text;
}

void ArticleView::syncBackgroundColorWithCfgDarkReader() const
{
// Only works Qt6.6.3+ https://bugreports.qt.io/browse/QTBUG-112013
#if QT_VERSION >= QT_VERSION_CHECK( 6, 6, 3 )
if ( cfg.preferences.darkReaderMode ) {
webview->page()->setBackgroundColor( Qt::black );
}
else {
webview->page()->setBackgroundColor( Qt::white );
}
#endif
}


void ArticleView::back()
{
// Don't allow navigating back to page 0, which is usually the initial
Expand Down
3 changes: 3 additions & 0 deletions src/ui/articleview.hh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public:

void setDelayedHighlightText( QString const & text );

/// \brief Set background as black if darkreader mode is enabled.
void syncBackgroundColorWithCfgDarkReader() const;

private:
// widgets
ArticleWebView * webview;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,7 @@ void MainWindow::editPreferences()
ArticleView & view = dynamic_cast< ArticleView & >( *( ui.tabWidget->widget( x ) ) );

view.setSelectionBySingleClick( p.selectWordBySingleClick );

view.syncBackgroundColorWithCfgDarkReader();
if ( needReload ) {
view.reload();
}
Expand Down
2 changes: 2 additions & 0 deletions src/ui/scanpopup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ void ScanPopup::refresh()

updateDictionaryBar();

definition->syncBackgroundColorWithCfgDarkReader();

connect( ui.groupList, &GroupComboBox::currentIndexChanged, this, &ScanPopup::currentGroupChanged );
#ifdef HAVE_X11
selectionDelayTimer.setInterval( cfg.preferences.selectionChangeDelayTimer );
Expand Down

0 comments on commit 32391bd

Please sign in to comment.