创建没有标题栏的窗口 [英] Create window without title bar

查看:138
本文介绍了创建没有标题栏的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用c ++在Arch Linux中为Openbox创建一个简单的面板,但是我不知道如何从窗口中删除标题栏.

I am trying to create a simple panel for Openbox in Arch Linux using c++, but I cannot figure out how to remove the title bar from a window.

我正在使用 XCreateWindow(...)创建窗口,该窗口具有正确的大小,但是它包含标题栏,并且该窗口也在左上角打开无论我指定什么偏移坐标,都在屏幕的一角.

I am creating the window with XCreateWindow(...), and that gives a window with the correct size, but it contains a title bar, and the window also opens in the top-left corner of the screen, no matter what offset coordinates I specify.

我在此处读到,这两个问题都可能是由窗口管理器(Openbox)引起的,它会覆盖窗口我在 XCreateWindow(...,& window_attributes)中指定的属性.可以通过添加 window_attributes.override_redirect = True; 来解决,尽管这似乎对我没有任何帮助.当我尝试这个时,我得到与以前完全相同的窗口.(此更改后,我确实编译了该文件.)

I read here that both of these problems are probably caused by the window manager (Openbox), which overrides the window attributes I specified in XCreateWindow(..., &window_attributes). This could be solved by adding window_attributes.override_redirect = True;, although this does not seem to do anything for me. When I try this I get the exact same window as before. (I did compile the file after this change.)

我也阅读了Tint2的代码(链接),这是Openbox的另一个面板.他们使用以下代码创建一个窗口:

Also I read into the code of Tint2 (link), which is another panel for Openbox. They create a window using the following code:

XSetWindowAttributes att = { .colormap=server.colormap, .background_pixel=0, .border_pixel=0 };
p->main_win = XCreateWindow(server.dsp, server.root_win, p->posx, p->posy, p->area.width, p->area.height, 0, server.depth, InputOutput, server.visual, mask, &att);

我在他们的代码中的任何地方都看不到 override_redirect ,所以我不确定他们如何删除标题栏.

I don't see an override_redirect anywhere in their code, so I'm not sure how they are removing the title bar.

作为其他信息,我认为值得一提的是我如何执行脚本:

As additional information, I thought it would be worth mentioning how I'm executing the script:

/* The c++ file is saved as 'panel.cpp' */
$ gcc panel.cpp -lX11 -o panel
$ ./panel

此外,我正在通过VirtualBox(以Windows 8为主机)运行Arch Linux.我不确定这是否会更改任何内容,但是提及它不会有任何伤害.

Also, I am running Arch Linux through VirtualBox with Windows 8 as host. I'm not sure if this changes anything, but it won't hurt to mention.

推荐答案

一种更正确的方法是使用

A more correct way is to use the Extended Window Manager Hints.

这个想法是,您不告诉窗口管理器如何装饰窗口或不装饰窗口,您只需使用

The idea is that you don't tell the window manager how to decorate or not your window, you just indicate the window type with _NET_WM_WINDOW_TYPE :

Atom window_type = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
long value = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DOCK", False);
XChangeProperty(display, your_window, window_type,
   XA_ATOM, 32, PropModeReplace, (unsigned char *) &value,1 );

停靠"是面板和任务栏的类型.通常,它们是未经修饰的,并出现在所有桌面上.正如文档中所写,以前, _MOTIF_WM_HINTS 属性用于定义窗口的外观和装饰.窗口管理器仍然支持它,但是首选 _NET_WM_WINDOW_TYPE 来描述该功能,并让窗口管理器(和用户)决定该类型窗口的外观和行为.

"Dock" is the type for panels and taskbar. Usually they are undecorated and appear on all desktops. As written on the documentation, previously the _MOTIF_WM_HINTS property was used to define the appearance and decorations of the window. Window managers still support it, but _NET_WM_WINDOW_TYPE is prefered as it describe the function and let the window manager (and user) decide on the appearance and behavior of that type of window.

另一个有趣的面板属性是 _NET_WM_STRUT_PARTIAL ,以保留"空间.

Another interesting property for a panel is _NET_WM_STRUT_PARTIAL, to "reserve" space.

这篇关于创建没有标题栏的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆