Skip to content

Commit

Permalink
Omit tray icon snip animation in some cases
Browse files Browse the repository at this point in the history
Don't snip if:
- a client only starts,
- monitor fetches commands to run,
- display commands set display data,
- filters for menu commands enable/disable menu items,
- some simple non-modifying functions are called.
  • Loading branch information
hluk committed Sep 9, 2018
1 parent 0a0388e commit dd84356
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/app/clipboardserver.cpp
Expand Up @@ -375,8 +375,6 @@ void ClipboardServer::onClientMessageReceived(
{
switch (messageCode) {
case CommandFunctionCall: {
m_wnd->snip();

const auto &clientData = m_clients.value(clientId);
if (!clientData.isValid())
return;
Expand Down
46 changes: 28 additions & 18 deletions src/scriptable/scriptableproxy.cpp
Expand Up @@ -99,7 +99,7 @@ const quint32 serializedFunctionCallVersion = 2;
f.setArguments arguments; \
emit sendMessage(f.serializeAndClear(functionCallId), CommandFunctionCall)

#define INVOKE(function, arguments) \
#define INVOKE_NO_SNIP(function, arguments) \
if (!m_wnd) { \
using Result = decltype(function arguments); \
const auto functionCallId = ++m_lastFunctionCallId; \
Expand All @@ -108,14 +108,24 @@ const quint32 serializedFunctionCallVersion = 2;
return result.value<Result>(); \
}

#define INVOKE2(function, arguments) \
#define INVOKE_NO_SNIP2(FUNCTION, ARGUMENTS) \
if (!m_wnd) { \
const auto functionCallId = ++m_lastFunctionCallId; \
INVOKE_(function, arguments, functionCallId); \
INVOKE_(FUNCTION, ARGUMENTS, functionCallId); \
waitForFunctionCallFinished(functionCallId); \
return; \
}

#define INVOKE(FUNCTION, ARGUMENTS) \
INVOKE_NO_SNIP(FUNCTION, ARGUMENTS) \
if (m_wnd) \
m_wnd->snip()

#define INVOKE2(FUNCTION, ARGUMENTS) \
INVOKE_NO_SNIP2(FUNCTION, ARGUMENTS) \
if (m_wnd) \
m_wnd->snip()

Q_DECLARE_METATYPE(QFile*)

QDataStream &operator<<(QDataStream &out, const NotificationButton &button)
Expand Down Expand Up @@ -970,7 +980,7 @@ void ScriptableProxy::setInputDialogResult(const QByteArray &bytes)

QVariantMap ScriptableProxy::getActionData(int id)
{
INVOKE(getActionData, (id));
INVOKE_NO_SNIP(getActionData, (id));
m_actionData = m_wnd->actionData(id);
m_actionId = id;

Expand All @@ -982,7 +992,7 @@ QVariantMap ScriptableProxy::getActionData(int id)

void ScriptableProxy::setActionData(int id, const QVariantMap &data)
{
INVOKE2(setActionData, (id, data));
INVOKE_NO_SNIP2(setActionData, (id, data));
m_wnd->setActionData(id, data);
}

Expand Down Expand Up @@ -1719,7 +1729,7 @@ void ScriptableProxy::setUserValue(const QString &key, const QVariant &value)

void ScriptableProxy::setSelectedItemsData(const QString &mime, const QVariant &value)
{
INVOKE2(setSelectedItemsData, (mime, value));
INVOKE_NO_SNIP2(setSelectedItemsData, (mime, value));
const QList<QPersistentModelIndex> selected = selectedIndexes();
for (const auto &index : selected) {
ClipboardBrowser *c = m_wnd->browserForItem(index);
Expand Down Expand Up @@ -1748,7 +1758,7 @@ QString ScriptableProxy::filter()

QVector<Command> ScriptableProxy::commands()
{
INVOKE(commands, ());
INVOKE_NO_SNIP(commands, ());
return loadAllCommands();
}

Expand Down Expand Up @@ -1844,25 +1854,25 @@ Qt::KeyboardModifiers ScriptableProxy::queryKeyboardModifiers()

QString ScriptableProxy::pluginsPath()
{
INVOKE(pluginsPath, ());
INVOKE_NO_SNIP(pluginsPath, ());
return ::pluginsPath();
}

QString ScriptableProxy::themesPath()
{
INVOKE(themesPath, ());
INVOKE_NO_SNIP(themesPath, ());
return ::themesPath();
}

QString ScriptableProxy::translationsPath()
{
INVOKE(translationsPath, ());
INVOKE_NO_SNIP(translationsPath, ());
return ::translationsPath();
}

QString ScriptableProxy::iconColor()
{
INVOKE(iconColor, ());
INVOKE_NO_SNIP(iconColor, ());
const auto color = m_wnd->sessionIconColor();
return color.isValid() ? color.name() : QString();
}
Expand All @@ -1881,7 +1891,7 @@ bool ScriptableProxy::setIconColor(const QString &colorName)

QString ScriptableProxy::iconTag()
{
INVOKE(iconTag, ());
INVOKE_NO_SNIP(iconTag, ());
return m_wnd->sessionIconTag();
}

Expand Down Expand Up @@ -2016,38 +2026,38 @@ void ScriptableProxy::showDataNotification(const QVariantMap &data)

QStringList ScriptableProxy::menuItemMatchCommands(int actionId)
{
INVOKE(menuItemMatchCommands, (actionId));
INVOKE_NO_SNIP(menuItemMatchCommands, (actionId));
return m_wnd->menuItemMatchCommands(actionId);
}

bool ScriptableProxy::enableMenuItem(int actionId, int menuItemMatchCommandIndex, bool enabled)
{
INVOKE(enableMenuItem, (actionId, menuItemMatchCommandIndex, enabled));
INVOKE_NO_SNIP(enableMenuItem, (actionId, menuItemMatchCommandIndex, enabled));
return m_wnd->setMenuItemEnabled(actionId, menuItemMatchCommandIndex, enabled);
}

QVariantMap ScriptableProxy::setDisplayData(int actionId, const QVariantMap &displayData)
{
INVOKE(setDisplayData, (actionId, displayData));
INVOKE_NO_SNIP(setDisplayData, (actionId, displayData));
m_actionData = m_wnd->setDisplayData(actionId, displayData);
return m_actionData;
}

QVector<Command> ScriptableProxy::automaticCommands()
{
INVOKE(automaticCommands, ());
INVOKE_NO_SNIP(automaticCommands, ());
return m_wnd->automaticCommands();
}

QVector<Command> ScriptableProxy::displayCommands()
{
INVOKE(displayCommands, ());
INVOKE_NO_SNIP(displayCommands, ());
return m_wnd->displayCommands();
}

QVector<Command> ScriptableProxy::scriptCommands()
{
INVOKE(scriptCommands, ());
INVOKE_NO_SNIP(scriptCommands, ());
return m_wnd->scriptCommands();
}

Expand Down

0 comments on commit dd84356

Please sign in to comment.