Kaydet (Commit) d06197f6 authored tarafından Michael Meeks's avatar Michael Meeks Kaydeden (comit) Miklos Vajna

unipoll: add a --unipoll parameter to gtktiledviewer.

Arguably should be the default. Implementation is a bit cute -
re-starting the main-loop as a child of a callback from its
idle handler.

Change-Id: I95e87c8a4ae3de745d7ca1f636859dd1d8deca17
Reviewed-on: https://gerrit.libreoffice.org/72070Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
üst 42977af4
...@@ -348,9 +348,18 @@ gtv_application_window_load_document(GtvApplicationWindow* window, ...@@ -348,9 +348,18 @@ gtv_application_window_load_document(GtvApplicationWindow* window,
*(priv->m_pRenderingArgs) = *aArgs; *(priv->m_pRenderingArgs) = *aArgs;
// setup lokdocview // setup lokdocview
window->lokdocview = lok_doc_view_new_from_user_profile(priv->m_pRenderingArgs->m_aLoPath.c_str(), const char *pUserProfile = priv->m_pRenderingArgs->m_aUserProfile.empty() ?
priv->m_pRenderingArgs->m_aUserProfile.empty() ? nullptr : priv->m_pRenderingArgs->m_aUserProfile.c_str(), nullptr : priv->m_pRenderingArgs->m_aUserProfile.c_str();
nullptr, nullptr);
window->lokdocview = GTK_WIDGET(
g_initable_new(LOK_TYPE_DOC_VIEW, nullptr, nullptr,
"lopath", priv->m_pRenderingArgs->m_aLoPath.c_str(),
"unipoll", priv->m_pRenderingArgs->m_bUnipoll,
"userprofileurl", pUserProfile,
"halign", GTK_ALIGN_CENTER,
"valign", GTK_ALIGN_CENTER,
nullptr));
gtk_container_add(GTK_CONTAINER(window->scrolledwindow), window->lokdocview); gtk_container_add(GTK_CONTAINER(window->scrolledwindow), window->lokdocview);
setupDocView(window); setupDocView(window);
......
...@@ -24,6 +24,7 @@ struct GtvRenderingArgs ...@@ -24,6 +24,7 @@ struct GtvRenderingArgs
std::string m_aLoPath; std::string m_aLoPath;
std::string m_aUserProfile; std::string m_aUserProfile;
bool m_bEnableTiledAnnotations; bool m_bEnableTiledAnnotations;
bool m_bUnipoll;
std::string m_aBackgroundColor; std::string m_aBackgroundColor;
bool m_bHidePageShadow; bool m_bHidePageShadow;
...@@ -31,6 +32,7 @@ struct GtvRenderingArgs ...@@ -31,6 +32,7 @@ struct GtvRenderingArgs
GtvRenderingArgs() GtvRenderingArgs()
: m_bEnableTiledAnnotations(false), : m_bEnableTiledAnnotations(false),
m_bUnipoll(false),
m_bHidePageShadow(false), m_bHidePageShadow(false),
m_bHideWhiteSpace(false) m_bHideWhiteSpace(false)
{ } { }
......
...@@ -52,6 +52,7 @@ gtv_application_init(GtvApplication* app) ...@@ -52,6 +52,7 @@ gtv_application_init(GtvApplication* app)
{ {
{ "version", 0, 0, G_OPTION_ARG_NONE, nullptr, "Show LOkit version", nullptr }, { "version", 0, 0, G_OPTION_ARG_NONE, nullptr, "Show LOkit version", nullptr },
{ "lo-path", 0, 0, G_OPTION_ARG_STRING, nullptr, "LO path", nullptr }, { "lo-path", 0, 0, G_OPTION_ARG_STRING, nullptr, "LO path", nullptr },
{ "unipoll", 0, 0, G_OPTION_ARG_NONE, nullptr, "Enable unified polling loop", nullptr },
{ "user-profile", 0, 0, G_OPTION_ARG_STRING, nullptr, "User profile to use", nullptr }, { "user-profile", 0, 0, G_OPTION_ARG_STRING, nullptr, "User profile to use", nullptr },
{ "enable-tiled-annotations", 0, 0, G_OPTION_ARG_NONE, nullptr, "Whether tiled annotations should be enabled", nullptr }, { "enable-tiled-annotations", 0, 0, G_OPTION_ARG_NONE, nullptr, "Whether tiled annotations should be enabled", nullptr },
{ "background-color", 0, 0, G_OPTION_ARG_STRING, nullptr, "Background color", nullptr }, { "background-color", 0, 0, G_OPTION_ARG_STRING, nullptr, "Background color", nullptr },
...@@ -98,11 +99,13 @@ gtv_application_handle_local_options(GApplication* app, GVariantDict* options) ...@@ -98,11 +99,13 @@ gtv_application_handle_local_options(GApplication* app, GVariantDict* options)
return 1; // Cannot afford to continue in absence of this param return 1; // Cannot afford to continue in absence of this param
} }
if (g_variant_dict_contains(options, "unipoll"))
priv->m_pRenderingArgs->m_bUnipoll = true;
if (g_variant_dict_contains(options, "version")) if (g_variant_dict_contains(options, "version"))
{ {
if (!priv->m_pRenderingArgs->m_aLoPath.empty()) if (!priv->m_pRenderingArgs->m_aLoPath.empty())
{ {
// FIXME: Crashes for some reason
GtkWidget* pDocView = lok_doc_view_new(priv->m_pRenderingArgs->m_aLoPath.c_str(), nullptr, nullptr); GtkWidget* pDocView = lok_doc_view_new(priv->m_pRenderingArgs->m_aLoPath.c_str(), nullptr, nullptr);
const gchar* versionInfo = lok_doc_view_get_version_info(LOK_DOC_VIEW(pDocView)); const gchar* versionInfo = lok_doc_view_get_version_info(LOK_DOC_VIEW(pDocView));
if (versionInfo) if (versionInfo)
......
...@@ -85,6 +85,7 @@ struct LOKDocViewPrivateImpl ...@@ -85,6 +85,7 @@ struct LOKDocViewPrivateImpl
gboolean m_bInit; // initializeForRendering() has been called gboolean m_bInit; // initializeForRendering() has been called
gboolean m_bCanZoomIn; gboolean m_bCanZoomIn;
gboolean m_bCanZoomOut; gboolean m_bCanZoomOut;
gboolean m_bUnipoll;
LibreOfficeKit* m_pOffice; LibreOfficeKit* m_pOffice;
LibreOfficeKitDocument* m_pDocument; LibreOfficeKitDocument* m_pDocument;
...@@ -198,6 +199,7 @@ struct LOKDocViewPrivateImpl ...@@ -198,6 +199,7 @@ struct LOKDocViewPrivateImpl
m_bInit(false), m_bInit(false),
m_bCanZoomIn(true), m_bCanZoomIn(true),
m_bCanZoomOut(true), m_bCanZoomOut(true),
m_bUnipoll(false),
m_pOffice(nullptr), m_pOffice(nullptr),
m_pDocument(nullptr), m_pDocument(nullptr),
lokThreadPool(nullptr), lokThreadPool(nullptr),
...@@ -286,6 +288,7 @@ enum ...@@ -286,6 +288,7 @@ enum
PROP_0, PROP_0,
PROP_LO_PATH, PROP_LO_PATH,
PROP_LO_UNIPOLL,
PROP_LO_POINTER, PROP_LO_POINTER,
PROP_USER_PROFILE_URL, PROP_USER_PROFILE_URL,
PROP_DOC_PATH, PROP_DOC_PATH,
...@@ -2523,6 +2526,9 @@ static void lok_doc_view_set_property (GObject* object, guint propId, const GVal ...@@ -2523,6 +2526,9 @@ static void lok_doc_view_set_property (GObject* object, guint propId, const GVal
case PROP_LO_PATH: case PROP_LO_PATH:
priv->m_aLOPath = g_value_get_string (value); priv->m_aLOPath = g_value_get_string (value);
break; break;
case PROP_LO_UNIPOLL:
priv->m_bUnipoll = g_value_get_boolean (value);
break;
case PROP_LO_POINTER: case PROP_LO_POINTER:
priv->m_pOffice = static_cast<LibreOfficeKit*>(g_value_get_pointer(value)); priv->m_pOffice = static_cast<LibreOfficeKit*>(g_value_get_pointer(value));
break; break;
...@@ -2585,6 +2591,9 @@ static void lok_doc_view_get_property (GObject* object, guint propId, GValue *va ...@@ -2585,6 +2591,9 @@ static void lok_doc_view_get_property (GObject* object, guint propId, GValue *va
case PROP_LO_PATH: case PROP_LO_PATH:
g_value_set_string (value, priv->m_aLOPath.c_str()); g_value_set_string (value, priv->m_aLOPath.c_str());
break; break;
case PROP_LO_UNIPOLL:
g_value_set_boolean (value, priv->m_bUnipoll);
break;
case PROP_LO_POINTER: case PROP_LO_POINTER:
g_value_set_pointer(value, priv->m_pOffice); g_value_set_pointer(value, priv->m_pOffice);
break; break;
...@@ -2710,6 +2719,41 @@ static void lok_doc_view_finalize (GObject* object) ...@@ -2710,6 +2719,41 @@ static void lok_doc_view_finalize (GObject* object)
G_OBJECT_CLASS (lok_doc_view_parent_class)->finalize (object); G_OBJECT_CLASS (lok_doc_view_parent_class)->finalize (object);
} }
// kicks the mainloop awake
static gboolean timeout_wakeup(void *)
{
return FALSE;
}
// integrate our mainloop with LOK's
static int lok_poll_callback(void*, int timeoutUs)
{
if (timeoutUs)
{
guint timeout = g_timeout_add(timeoutUs / 1000, timeout_wakeup, nullptr);
g_main_context_iteration(nullptr, TRUE);
g_source_remove(timeout);
}
else
g_main_context_iteration(nullptr, FALSE);
return 0;
}
// thread-safe wakeup of our mainloop
static void lok_wake_callback(void *)
{
g_main_context_wakeup(nullptr);
}
static gboolean spin_lok_loop(void *pData)
{
LOKDocView *pDocView = LOK_DOC_VIEW (pData);
LOKDocViewPrivate& priv = getPrivate(pDocView);
priv->m_pOffice->pClass->runLoop(priv->m_pOffice, lok_poll_callback, lok_wake_callback, nullptr);
return FALSE;
}
static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* /*cancellable*/, GError **error) static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* /*cancellable*/, GError **error)
{ {
LOKDocView *pDocView = LOK_DOC_VIEW (initable); LOKDocView *pDocView = LOK_DOC_VIEW (initable);
...@@ -2718,6 +2762,9 @@ static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* / ...@@ -2718,6 +2762,9 @@ static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* /
if (priv->m_pOffice != nullptr) if (priv->m_pOffice != nullptr)
return TRUE; return TRUE;
if (priv->m_bUnipoll)
g_setenv("SAL_LOK_OPTIONS", "unipoll", FALSE);
priv->m_pOffice = lok_init_2(priv->m_aLOPath.c_str(), priv->m_aUserProfileURL.empty() ? nullptr : priv->m_aUserProfileURL.c_str()); priv->m_pOffice = lok_init_2(priv->m_aLOPath.c_str(), priv->m_aUserProfileURL.empty() ? nullptr : priv->m_aUserProfileURL.c_str());
if (priv->m_pOffice == nullptr) if (priv->m_pOffice == nullptr)
...@@ -2732,6 +2779,9 @@ static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* / ...@@ -2732,6 +2779,9 @@ static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* /
priv->m_nLOKFeatures |= LOK_FEATURE_VIEWID_IN_VISCURSOR_INVALIDATION_CALLBACK; priv->m_nLOKFeatures |= LOK_FEATURE_VIEWID_IN_VISCURSOR_INVALIDATION_CALLBACK;
priv->m_pOffice->pClass->setOptionalFeatures(priv->m_pOffice, priv->m_nLOKFeatures); priv->m_pOffice->pClass->setOptionalFeatures(priv->m_pOffice, priv->m_nLOKFeatures);
if (priv->m_bUnipoll)
g_idle_add(spin_lok_loop, pDocView);
return TRUE; return TRUE;
} }
...@@ -2771,6 +2821,19 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) ...@@ -2771,6 +2821,19 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
/**
* LOKDocView:unipoll:
*
* Whether we use our own unified polling mainloop in place of glib's
*/
properties[PROP_LO_UNIPOLL] =
g_param_spec_boolean("unipoll",
"Unified Polling",
"Whether we use a custom unified polling loop",
FALSE,
static_cast<GParamFlags>(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/** /**
* LOKDocView:lopointer: * LOKDocView:lopointer:
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment