diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2019-11-24 09:56:02 -0500 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-12-16 17:30:00 +0000 |
commit | f3f7ea23c4611856f051cb6aeca115c27ef5b1e7 (patch) | |
tree | 089b1ccd5c9cdbaf7763b7f5b5f2b6bc7630348e /sfx2 | |
parent | d1739c7fc0713190b2dcbcbdda831490759f331a (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 15f21057aa0e..bb6a08e48d8e 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) |