X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt%2FGuiApplication.cpp;h=ff33065fe34fe313fd051ef1d21227d614f02ec2;hb=b41293352ea8d52890b7668f059fd07f09bd6bb6;hp=9e6f18a3335fbaa792542ee5e97bc0f74a6c575d;hpb=0e0b76a76e6a660a379ea9955a92c440a6401acd;p=features.git diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp index 9e6f18a333..ff33065fe3 100644 --- a/src/frontends/qt/GuiApplication.cpp +++ b/src/frontends/qt/GuiApplication.cpp @@ -197,6 +197,20 @@ frontend::Application * createApplication(int & argc, char * argv[]) #endif +#if defined(Q_OS_MAC) + int const cursor_time_on = NSTextInsertionPointBlinkPeriodOn(); + int const cursor_time_off = NSTextInsertionPointBlinkPeriodOff(); + if (cursor_time_on > 0 && cursor_time_off > 0) { + QApplication::setCursorFlashTime(cursor_time_on + cursor_time_off); + } else if (cursor_time_on <= 0 && cursor_time_off > 0) { + // Off is set and On is undefined of zero + QApplication::setCursorFlashTime(0); + } else if (cursor_time_off <= 0 && cursor_time_on > 0) { + // On is set and Off is undefined of zero + QApplication::setCursorFlashTime(0); + } +#endif + // Setup high DPI handling. This is a bit complicated, but will be default in Qt6. // macOS does it by itself. #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && !defined(Q_OS_MAC) @@ -511,6 +525,47 @@ QString themeIconName(QString const & action) } +namespace { + +/* Get aliases for icon name. This allows to avoid duplication of + * icons when new versions of functions are introduced for the + * toolbar. A good example is the introduction of layout-toggle in + * #9864. + * The file is parsed by Lexer. Each line is of the form + * + * + * The return value is another icon file name that can be queried. + */ +// FIXME: consider using regular expressions. +QString getAlias(QString name) { + static bool has_aliases = false; + static vector > aliases; + // Initialize aliases list (once). + if (!has_aliases) { + FileName alfile = libFileSearch("images", "icon.aliases"); + if (alfile.exists()) { + Lexer lex; + lex.setFile(alfile); + while(lex.isOK()) { + string from, to; + lex >> from >> to; + if (!from.empty()) + aliases.push_back({toqstr(from), toqstr(to)}); + } + } + has_aliases = true; + } + // check for the following aliases + for (auto const & alias : aliases) { + if (name.contains(alias.first)) + name.replace(alias.first, alias.second); + } + return name; +} + +} // namespace + + IconInfo iconInfo(FuncRequest const & f, bool unknown, bool rtl) { IconInfo res; @@ -524,9 +579,10 @@ IconInfo iconInfo(FuncRequest const & f, bool unknown, bool rtl) name.replace(' ', '_'); name.replace(';', '_'); name.replace('\\', "backslash"); - // avoid duplication for these - name.replace("dialog-toggle", "dialog-show"); names << name; + QString alias = getAlias(name); + if (alias != name) + names << alias; // then special default icon for some lfuns switch (f.action()) { @@ -558,6 +614,9 @@ IconInfo iconInfo(FuncRequest const & f, bool unknown, bool rtl) // next thing to try is function name alone names << lfunname; + QString alias = getAlias(lfunname); + if (alias != lfunname) + names << alias; // and finally maybe the unknown icon if (unknown) @@ -2322,6 +2381,12 @@ void GuiApplication::onLocaleChanged() } +void GuiApplication::onPaletteChanged() +{ + colorCache().setPalette(palette()); +} + + void GuiApplication::handleKeyFunc(FuncCode action) { char_type c = 0; @@ -2710,6 +2775,18 @@ Menus & GuiApplication::menus() } +bool GuiApplication::needsBackingStore() const +{ + /* Qt on macOS and Wayland does not respect the + * Qt::WA_OpaquePaintEvent attribute and resets the widget backing + * store at each update. Therefore, we use our own backing store + * in these two cases. It is also possible to force the use of the + * backing store for cases like x11 with transparent WM themes. + */ + return platformName() == "cocoa" || platformName().contains("wayland"); +} + + QList GuiApplication::viewIds() const { return d->views_.keys(); @@ -2965,6 +3042,11 @@ bool GuiApplication::event(QEvent * e) e->accept(); return true; #endif + case QEvent::ApplicationPaletteChange: { + // runtime switch from/to dark mode + onPaletteChanged(); + return QApplication::event(e); + } default: return QApplication::event(e); }