From d6490d3c7bb686ee07654f9d0ade6e145043c0f3 Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Thu, 3 Aug 2017 22:58:04 +0530 Subject: lokdialog: Move the floating window to its actual position gtk_window_move them to the position broadcasted to us by vcl Change-Id: Id27b52a24e721b51d7a153cc7c0e03197a99ee2f --- libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx | 14 +++++++++++--- libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx | 2 +- .../qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'libreofficekit') diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx index 1bfb9d538ead..6b19ddc506c0 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx @@ -460,7 +460,7 @@ gtv_lok_dialog_invalidate(GtvLokDialog* dialog) gtk_widget_queue_draw(priv->pDialogDrawingArea); } -void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog) +void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog, int nX, int nY) { g_info("Dialog's floating window invalidate"); @@ -474,14 +474,22 @@ void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog) gtk_container_add(GTK_CONTAINER(priv->pFloatingWin), pDrawingArea); gtk_window_set_transient_for(GTK_WINDOW(priv->pFloatingWin), GTK_WINDOW(dialog)); - gtk_window_set_position(GTK_WINDOW(priv->pFloatingWin), GTK_WIN_POS_MOUSE); gtk_window_set_destroy_with_parent(GTK_WINDOW(priv->pFloatingWin), true); - g_signal_connect(G_OBJECT(pDrawingArea), "draw", G_CALLBACK(gtv_lok_dialog_floating_win_draw), dialog); gtk_widget_set_size_request(priv->pFloatingWin, 1, 1); + gtk_window_set_type_hint(GTK_WINDOW(priv->pFloatingWin), GDK_WINDOW_TYPE_HINT_POPUP_MENU); + gtk_window_set_screen(GTK_WINDOW(priv->pFloatingWin), gtk_window_get_screen(GTK_WINDOW(dialog))); + gtk_widget_show_all(priv->pFloatingWin); gtk_window_present(GTK_WINDOW(priv->pFloatingWin)); + + // Get the root coords of our new floating window + GdkWindow* pGdkWin = gtk_widget_get_window(GTK_WIDGET(dialog)); + int nrX = 0; + int nrY = 0; + gdk_window_get_root_coords(pGdkWin, nX, nY, &nrX, &nrY); + gtk_window_move(GTK_WINDOW(priv->pFloatingWin), nrX, nrY); } void gtv_lok_dialog_child_close(GtvLokDialog* dialog) diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx index bce9edbadba1..ba565b4cebb0 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.hxx @@ -39,7 +39,7 @@ GtkWidget* gtv_lok_dialog_new(LOKDocView* pDocView, const gchar* dialogId); void gtv_lok_dialog_invalidate(GtvLokDialog* dialog); -void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog); +void gtv_lok_dialog_child_invalidate(GtvLokDialog* dialog, int nX, int nY); void gtv_lok_dialog_child_close(GtvLokDialog* dialog); diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx index 8896566499c1..3acd6b78e234 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lokdocview-signal-handlers.cxx @@ -309,6 +309,19 @@ void LOKDocViewSigHandlers::dialogChild(LOKDocView* pDocView, gchar* pPayload, g boost::property_tree::read_json(aStream, aRoot); //std::string aDialogId = aRoot.get("dialogId"); std::string aAction = aRoot.get("action"); + std::string aPos = aRoot.get("position"); + gchar** ppCoordinates = g_strsplit(aPos.c_str(), ", ", 2); + gchar** ppCoordinate = ppCoordinates; + int nX = 0; + int nY = 0; + + if (*ppCoordinate) + nX = atoi(*ppCoordinate); + ++ppCoordinate; + if (*ppCoordinate) + nY = atoi(*ppCoordinate); + + g_strfreev(ppCoordinates); // temporary hack to invalidate/close floating window of all opened dialogs GList* pChildWins = gtv_application_window_get_all_child_windows(window); @@ -316,7 +329,7 @@ void LOKDocViewSigHandlers::dialogChild(LOKDocView* pDocView, gchar* pPayload, g for (pIt = pChildWins; pIt != nullptr; pIt = pIt->next) { if (aAction == "invalidate") - gtv_lok_dialog_child_invalidate(GTV_LOK_DIALOG(pIt->data)); + gtv_lok_dialog_child_invalidate(GTV_LOK_DIALOG(pIt->data), nX, nY); else if (aAction == "close") gtv_lok_dialog_child_close(GTV_LOK_DIALOG(pIt->data)); } -- cgit