Resolves: tdf#145786 get the correct bounds with window scaling enabled
the per-window/app scaling as opposed to the global desktop one which
wasn't affected.
the menubutton thought it saw the mouse release happen outside the
window it popped up when the combobox inside it was clicked, so popped
down the popup from underneath the combobox.
Change-Id: Iace9538073bb2380443d87600a872e88885934d3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125810
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 4b1cd40..94184ca 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -9414,6 +9414,29 @@ GtkPositionType show_menu(GtkWidget* pMenuButton, GtkWindow* pMenu)
return ePosUsed;
}
bool button_event_is_outside(GtkWidget* pMenuHack, GdkEventButton* pEvent)
{
//we want to pop down if the button was released outside our popup
gdouble x = pEvent->x_root;
gdouble y = pEvent->y_root;
gint window_x, window_y;
GdkSurface* pWindow = widget_get_surface(pMenuHack);
gdk_window_get_position(pWindow, &window_x, &window_y);
GtkAllocation alloc;
gtk_widget_get_allocation(pMenuHack, &alloc);
gint x1 = window_x;
gint y1 = window_y;
gint x2 = x1 + alloc.width;
gint y2 = y1 + alloc.height;
if (x > x1 && x < x2 && y > y1 && y < y2)
return false;
return true;
}
#endif
/* four types of uses of this
@@ -9548,36 +9571,17 @@ private:
}
}
static gboolean signalButtonRelease(GtkWidget* pWidget, GdkEventButton* pEvent, gpointer widget)
static gboolean signalButtonRelease(GtkWidget* /*pWidget*/, GdkEventButton* pEvent, gpointer widget)
{
GtkInstanceMenuButton* pThis = static_cast<GtkInstanceMenuButton*>(widget);
return pThis->button_release(pWidget, pEvent);
return pThis->button_release(pEvent);
}
bool button_release(GtkWidget* pWidget, GdkEventButton* pEvent)
bool button_release(GdkEventButton* pEvent)
{
//we want to pop down if the button was released outside our popup
gdouble x = pEvent->x_root;
gdouble y = pEvent->y_root;
gint xoffset, yoffset;
gdk_window_get_root_origin(widget_get_surface(pWidget), &xoffset, &yoffset);
GtkAllocation alloc;
gtk_widget_get_allocation(pWidget, &alloc);
xoffset += alloc.x;
yoffset += alloc.y;
gtk_widget_get_allocation(GTK_WIDGET(m_pMenuHack), &alloc);
gint x1 = alloc.x + xoffset;
gint y1 = alloc.y + yoffset;
gint x2 = x1 + alloc.width;
gint y2 = y1 + alloc.height;
if (x > x1 && x < x2 && y > y1 && y < y2)
return false;
set_active(false);
if (button_event_is_outside(GTK_WIDGET(m_pMenuHack), pEvent))
set_active(false);
return false;
}
@@ -19749,36 +19753,17 @@ private:
}
}
static gboolean signalButtonPress(GtkWidget* pWidget, GdkEventButton* pEvent, gpointer widget)
static gboolean signalButtonPress(GtkWidget* /*pWidget*/, GdkEventButton* pEvent, gpointer widget)
{
GtkInstanceComboBox* pThis = static_cast<GtkInstanceComboBox*>(widget);
return pThis->button_press(pWidget, pEvent);
return pThis->button_press(pEvent);
}
bool button_press(GtkWidget* pWidget, GdkEventButton* pEvent)
bool button_press(GdkEventButton* pEvent)
{
//we want to pop down if the button was pressed outside our popup
gdouble x = pEvent->x_root;
gdouble y = pEvent->y_root;
gint xoffset, yoffset;
gdk_window_get_root_origin(widget_get_surface(pWidget), &xoffset, &yoffset);
GtkAllocation alloc;
gtk_widget_get_allocation(pWidget, &alloc);
xoffset += alloc.x;
yoffset += alloc.y;
gtk_widget_get_allocation(GTK_WIDGET(m_pMenuWindow), &alloc);
gint x1 = alloc.x + xoffset;
gint y1 = alloc.y + yoffset;
gint x2 = x1 + alloc.width;
gint y2 = y1 + alloc.height;
if (x > x1 && x < x2 && y > y1 && y < y2)
return false;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_pToggleButton), false);
if (button_event_is_outside(GTK_WIDGET(m_pMenuWindow), pEvent))
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_pToggleButton), false);
return false;
}