From 25ed4dfefc9172b9b2dd819e25d4de0ac405c533 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 30 Sep 2014 17:20:43 +0000 Subject: [PATCH] Linux: Fix browser window position in cefclient when using integrated window menu bar (issue #1388). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1851 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- tests/cefclient/cefclient_gtk.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/cefclient/cefclient_gtk.cpp b/tests/cefclient/cefclient_gtk.cpp index 255adce37..45e3deed4 100644 --- a/tests/cefclient/cefclient_gtk.cpp +++ b/tests/cefclient/cefclient_gtk.cpp @@ -38,6 +38,9 @@ char szWorkingDir[512]; // The current working directory // Height of the buttons at the top of the GTK window. int g_toolbar_height = 0; +// Height of the integrated menu bar (if any) at the top of the GTK window. +int g_menubar_height = 0; + class MainBrowserProvider : public OSRBrowserProvider { virtual CefRefPtr GetBrowser() { if (g_handler.get()) @@ -89,9 +92,9 @@ void TerminationSignalHandler(int signatl) { AppQuitMessageLoop(); } -void VboxSizeAllocated(GtkWidget *widget, - GtkAllocation *allocation, - void *data) { +void VboxSizeAllocated(GtkWidget* widget, + GtkAllocation* allocation, + void* data) { if (g_handler) { CefRefPtr browser = g_handler->GetBrowser(); if (browser && !browser->GetHost()->IsWindowRenderingDisabled()) { @@ -100,18 +103,26 @@ void VboxSizeAllocated(GtkWidget *widget, ::Window xwindow = browser->GetHost()->GetWindowHandle(); XWindowChanges changes = {0}; changes.width = allocation->width; - changes.height = allocation->height - g_toolbar_height; - XConfigureWindow(xdisplay, xwindow, CWHeight | CWWidth, &changes); + changes.height = allocation->height - + (g_toolbar_height + g_menubar_height); + changes.y = g_toolbar_height + g_menubar_height; + XConfigureWindow(xdisplay, xwindow, CWHeight | CWWidth | CWY, &changes); } } } -void ToolbarSizeAllocated(GtkWidget *widget, - GtkAllocation *allocation, - void *data) { +void ToolbarSizeAllocated(GtkWidget* widget, + GtkAllocation* allocation, + void* data) { g_toolbar_height = allocation->height; } +void MenubarSizeAllocated(GtkWidget* widget, + GtkAllocation* allocation, + void* data) { + g_menubar_height = allocation->height; +} + gboolean WindowFocusIn(GtkWidget* widget, GdkEventFocus* event, gpointer user_data) { @@ -450,6 +461,8 @@ int main(int argc, char* argv[]) { gtk_container_add(GTK_CONTAINER(window), vbox); GtkWidget* menu_bar = CreateMenuBar(); + g_signal_connect(menu_bar, "size-allocate", + G_CALLBACK(MenubarSizeAllocated), NULL); gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, FALSE, 0);