diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2019-11-24 09:56:02 -0500 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2019-11-25 13:37:46 +0100 |
commit | e8a2d9f3ff86f53d6ace6f81a324c0c28dca50f3 (patch) | |
tree | 0a433446c5c3f809bac891ea4d3818515907b622 /sfx2 | |
parent | 5c43becf829b13109a50cdd2276fe4437ec27143 (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>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/sidebar/SidebarDockingWindow.cxx | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/sfx2/source/sidebar/SidebarDockingWindow.cxx b/sfx2/source/sidebar/SidebarDockingWindow.cxx index b40f47eb4bad..0b7ee183f5c1 100644 --- a/sfx2/source/sidebar/SidebarDockingWindow.cxx +++ b/sfx2/source/sidebar/SidebarDockingWindow.cxx @@ -39,19 +39,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; @@ -61,19 +65,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 = Point(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) |