CEF 3无边框窗口

时间:2017-09-14 07:36:21

标签: c++ ubuntu-12.04 chromium-embedded

我是CEF的新手,我正在尝试在ubuntu 12.04 x64上创建新的无边界浏览器(仅用于网页查看)。 目前我已经尝试过这种方式(gtk顶级窗口 - >禁用装饰 - >设置窗口信息,父级设置为先前创建的窗口 - >创建浏览器):

GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_decorated (GTK_WINDOW(window), FALSE);
CefWindowHandle window_handle = GDK_WINDOW_XWINDOW (GTK_WIDGET (window)->window);

CefWindowInfo window_info;
window_info.SetAsChild(window_handle, CefRect(100, 100, 800, 600));

CefBrowserHost::CreateBrowser(window_info, handler, url, browser_settings, NULL);

但是这只会在指定位置打开一个具有正确宽度/高度的浏览器,但它仍然有边框。

另一方面,我已经在Windows上成功创建了无边界浏览器窗口:

CefWindowInfo window_info;
window_info.style = WS_VISIBLE | WS_POPUP;
window_info.x = 2120;
window_info.y = 200;
window_info.width = 800;
window_info.height = 600;

CefBrowserHost::CreateBrowserSync(window_info, handler, url, browser_settings, NULL);

注意:

  • 我不能重建整个CEF,
  • 我无法升级Ubuntu。

1 个答案:

答案 0 :(得分:1)

我用X11窗口管理器解决了这个问题。

首先,我创建了一个删除窗口边框的功能:

#include <X11/Xlib.h>

static void RemoveBorders(Window window) {
  struct Data {
    unsigned long flags;
    unsigned long functions;
    unsigned long decorations;
    long          inputMode;
    unsigned long status;
  } data = {2, 0, 0, 0, 0};
  auto display = cef_get_xdisplay();
  auto atom = XInternAtom(display, "_MOTIF_WM_HINTS", True);
  XChangeProperty(display, window, atom, atom, 32, PropModeReplace, (unsigned char*)&data, 5);
}

在我创建浏览器之后,我同步创建它以检索创建的浏览器句柄并在浏览器窗口句柄上调用RemoveBorders函数:

...
auto browser = CefBrowserHost::CreateBrowserSync(window_info, handler, url, browser_settings, NULL);
RemoveBorders(browser->GetHost()->GetWindowHandle());
...