diff --git a/docs/scripting-api.rst b/docs/scripting-api.rst index 3c6149851b..6523080271 100644 --- a/docs/scripting-api.rst +++ b/docs/scripting-api.rst @@ -851,7 +851,9 @@ omitted. Get or set current tray and window icon color name. - Throws exception is the color name is invalid. + Resets color if color name is empty string. + + Throws exception is the color name is not empty and invalid. .. code-block:: js diff --git a/docs/sessions.rst b/docs/sessions.rst index af80bc7006..823e5b3867 100644 --- a/docs/sessions.rst +++ b/docs/sessions.rst @@ -32,10 +32,15 @@ Default session has empty name but it can be overridden by setting ``COPYQ_SESSION_NAME`` environment variable. Icon for each session is bit different. The color is generated from session -name and can be changed using ``COPYQ_SESSION_COLOR`` environment variable (the -color to override can be set with ``COPYQ_APP_COLOR`` environment variable). +name and can be changed using ``COPYQ_SESSION_COLOR`` environment variable. :: COPYQ_SESSION_COLOR="yellow" copyq COPYQ_SESSION_COLOR="#f90" copyq + +.. note:: + + On Linux, changing icon color won't work if current icon theme contains + icon named "copyq-normal" or doesn't contain "copyq-mask" (and + "copyq-busy-mask"). diff --git a/src/gui/iconfactory.cpp b/src/gui/iconfactory.cpp index 3eb361fb7e..44b1ae3fd7 100644 --- a/src/gui/iconfactory.cpp +++ b/src/gui/iconfactory.cpp @@ -53,6 +53,11 @@ const int lightThreshold = 100; QPointer activePaintDevice; +bool hasNormalIcon() +{ + return QIcon::hasThemeIcon(COPYQ_ICON_NAME "-normal"); +} + QString sessionName() { return qApp->property("CopyQ_session_name").toString(); @@ -69,22 +74,10 @@ QColor colorFromEnv(const char *envVaribleName) return QColor( textFromEnv(envVaribleName) ); } -QColor appIconColorHelper() -{ - const auto color = colorFromEnv("COPYQ_APP_COLOR"); - return color.isValid() ? QColor(color) : QColor(0x7f, 0xca, 0x9b); -} - -QColor appIconColor() -{ - static const QColor color = appIconColorHelper(); - return color; -} - QColor sessionNameToColor(const QString &name) { if (name.isEmpty()) - return appIconColor(); + return QColor(); int r = 0; int g = 0; @@ -111,7 +104,7 @@ QColor sessionNameToColor(const QString &name) QColor sessionIconColorHelper() { const auto color = colorFromEnv("COPYQ_SESSION_COLOR"); - return color.isValid() ? QColor(color) : sessionNameToColor( sessionName() ); + return color.isValid() ? color : sessionNameToColor( sessionName() ); } QColor &sessionIconColorVariable() @@ -172,6 +165,9 @@ QString iconPath(const QString &iconSuffix) QPixmap appPixmap(const QString &iconSuffix, QSize size) { + if ( iconSuffix.isEmpty() && hasNormalIcon() ) + return appPixmap("-normal", size); + const auto icon = QIcon::fromTheme(COPYQ_ICON_NAME + iconSuffix); QPixmap pix; @@ -481,11 +477,13 @@ class AppIconEngine : public BaseIconEngine const auto suffix = running ? QLatin1String("-busy") : QLatin1String(""); auto pix = appPixmap(suffix, size); - const auto sessionColor = sessionIconColor(); - const auto appColor = appIconColor(); - if (sessionColor != appColor) - replaceColor(&pix, suffix, sessionColor); + // If copyq-normal icon exist in theme, omit changing color. + if ( !hasNormalIcon() ) { + const auto sessionColor = sessionIconColor(); + if ( sessionColor.isValid() ) + replaceColor(&pix, suffix, sessionColor); + } return pix; } @@ -615,7 +613,7 @@ unsigned short toIconId(const QString &fileNameOrId) void setSessionIconColor(QColor color) { - sessionIconColorVariable() = color; + sessionIconColorVariable() = color.isValid() ? color : sessionIconColorHelper(); } void setSessionIconTag(const QString &tag) diff --git a/src/scriptable/scriptableproxy.cpp b/src/scriptable/scriptableproxy.cpp index f35b75e43d..91d518acfe 100644 --- a/src/scriptable/scriptableproxy.cpp +++ b/src/scriptable/scriptableproxy.cpp @@ -1621,14 +1621,16 @@ QString ScriptableProxy::translationsPath() QString ScriptableProxy::iconColor() { INVOKE(iconColor, ()); - return m_wnd->sessionIconColor().name(); + const auto color = m_wnd->sessionIconColor(); + return color.isValid() ? color.name() : QString(); } bool ScriptableProxy::setIconColor(const QString &colorName) { INVOKE(setIconColor, (colorName)); + QColor color(colorName); - if ( !color.isValid() ) + if ( !colorName.isEmpty() && !color.isValid() ) return false; m_wnd->setSessionIconColor(color); diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 0b627cfd24..a657b26f73 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -1295,6 +1295,9 @@ void Tests::commandIcon() RUN_EXPECT_ERROR("iconColor" << "BAD_COLOR_NAME", CommandException); RUN("iconColor", "#ff0000\n"); + RUN("iconColor" << "", ""); + RUN("iconColor", QByteArray(defaultSessionColor) + "\n"); + RUN("iconColor" << defaultSessionColor, ""); RUN("iconColor", QByteArray(defaultSessionColor) + "\n"); }