summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2019-11-24 09:56:02 -0500
committerMichael Meeks <michael.meeks@collabora.com>2020-05-27 21:53:53 +0100
commit36604a74f153c37f95e930adab803772aa79cbad (patch)
tree6fae945af5cf71d02ad18159b72c13178265f63d
parent5343d4c314295e39ec5c4a7683f0c09bf3ce64d2 (diff)
sidebar: do not emit unnecessary created notifications
This also breaks a potentially recursive cycle where each 'created' notification requests a re-rendering, which triggers view change (when more than one view is open on the doc), which triggers a frame change, which resets the sidebar, causing a 'created' notification, thereby starting the cycle anew. Change-Id: I1aafe7f45871748afb393fa55c357037215e6c33 Reviewed-on: https://gerrit.libreoffice.org/83629 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r--sfx2/source/sidebar/SidebarDockingWindow.cxx45
1 files changed, 33 insertions, 12 deletions
diff --git a/sfx2/source/sidebar/SidebarDockingWindow.cxx b/sfx2/source/sidebar/SidebarDockingWindow.cxx
index c0aa3050ef64..7df5e451d89d 100644
--- a/sfx2/source/sidebar/SidebarDockingWindow.cxx
+++ b/sfx2/source/sidebar/SidebarDockingWindow.cxx
@@ -42,19 +42,23 @@ namespace sfx2 { namespace sidebar {
class SidebarNotifyIdle : public Idle
{
- SidebarDockingWindow &mrSidebarDockingWin;
+ SidebarDockingWindow& m_rSidebarDockingWin;
+ std::string m_LastNotificationMessage;
+ vcl::LOKWindowId m_LastLOKWindowId;
public:
SidebarNotifyIdle(SidebarDockingWindow &rSidebarDockingWin) :
Idle("Sidebar notify"),
- mrSidebarDockingWin(rSidebarDockingWin)
+ m_rSidebarDockingWin(rSidebarDockingWin),
+ m_LastNotificationMessage(),
+ m_LastLOKWindowId(0)
{
SetPriority(TaskPriority::POST_PAINT);
}
void Invoke() override
{
- auto pNotifier = mrSidebarDockingWin.GetLOKNotifier();
+ auto pNotifier = m_rSidebarDockingWin.GetLOKNotifier();
if (!pNotifier || !comphelper::LibreOfficeKit::isActive())
return;
@@ -64,19 +68,36 @@ public:
{
// Mobile.
std::stringstream aStream;
- boost::property_tree::write_json(aStream, mrSidebarDockingWin.DumpAsPropertyTree());
- pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, aStream.str().c_str());
+ boost::property_tree::write_json(aStream, m_rSidebarDockingWin.DumpAsPropertyTree());
+ const std::string message = aStream.str();
+ if (message != m_LastNotificationMessage)
+ {
+ m_LastNotificationMessage = message;
+ pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, message.c_str());
+ }
}
else
{
// On desktop use the classic notifications.
- std::vector<vcl::LOKPayloadItem> aItems;
- aItems.emplace_back("type", "deck");
- const Point pos = Point(mrSidebarDockingWin.GetOutOffXPixel(),
- mrSidebarDockingWin.GetOutOffYPixel());
- aItems.emplace_back("position", pos.toString());
- aItems.emplace_back("size", mrSidebarDockingWin.GetSizePixel().toString());
- pNotifier->notifyWindow(mrSidebarDockingWin.GetLOKWindowId(), "created", aItems);
+ const Point pos(m_rSidebarDockingWin.GetOutOffXPixel(),
+ m_rSidebarDockingWin.GetOutOffYPixel());
+ const OString posMessage = pos.toString();
+ const OString sizeMessage = m_rSidebarDockingWin.GetSizePixel().toString();
+
+ const std::string message = OString(posMessage + sizeMessage).getStr();
+ const vcl::LOKWindowId lokWindowId = m_rSidebarDockingWin.GetLOKWindowId();
+
+ if (lokWindowId != m_LastLOKWindowId || message != m_LastNotificationMessage)
+ {
+ m_LastLOKWindowId = lokWindowId;
+ m_LastNotificationMessage = message;
+
+ std::vector<vcl::LOKPayloadItem> aItems;
+ aItems.emplace_back("type", "deck");
+ aItems.emplace_back("position", posMessage);
+ aItems.emplace_back("size", sizeMessage);
+ pNotifier->notifyWindow(lokWindowId, "created", aItems);
+ }
}
}
catch (boost::property_tree::json_parser::json_parser_error& rError)