C 使用Xlib了解面板的大小
我正在编写一个应用程序,将停靠点放在屏幕右侧,如下所示: 我可以使用C 使用Xlib了解面板的大小,c,x11,xlib,C,X11,Xlib,我正在编写一个应用程序,将停靠点放在屏幕右侧,如下所示: 我可以使用\u NET\u WM\u struct\u PARTIAL在屏幕侧面预留空间,这样最大化的窗口就不会与码头重叠 在图中,您可以看到有一个顶部面板。问题是,码头将与面板重叠。是否有办法确定配电盘的尺寸,或使配电盘缩小为码头的开放空间 顺便说一句,我使用的是Xlib。我想你必须跟踪所有出现的顶级窗口,以及它们是否有_NET\u WM\u struct\u PARTIAL,以便自己计算工作区域,减去自己的窗口。您可以查看libwn
\u NET\u WM\u struct\u PARTIAL
在屏幕侧面预留空间,这样最大化的窗口就不会与码头重叠
在图中,您可以看到有一个顶部面板。问题是,码头将与面板重叠。是否有办法确定配电盘的尺寸,或使配电盘缩小为码头的开放空间
顺便说一句,我使用的是Xlib。我想你必须跟踪所有出现的顶级窗口,以及它们是否有_NET\u WM\u struct\u PARTIAL,以便自己计算工作区域,减去自己的窗口。您可以查看libwnck代码,了解如何跟踪所有顶层,以及窗口管理器如何计算_NET_工作区,以了解如何做到这一点。然后重做这项工作,但减去你自己的struts。这其中的一个问题是,如果每个面板都这样做了,就会有一个无限循环,它们都围绕着彼此工作。但是你可以假设人们只有一个默认的桌面面板,而不是你的
另一种选择可能是使面板的窗口始终为全屏高度,但如果任何窗口在您上方,请将您绘制的内容(以及偏移事件处理)向下偏移一点。问题是很难跟踪窗口是如何重叠的。XVisibilityEvent有点帮助,但不会告诉您顶部的窗口何时移动。此外,如果一部全屏电影最终覆盖了整个面板,你必须确保不要中断。我想使用这种方法,您可能仍然会像第一种方法一样扫描所有顶层面板。通过使用提供的良好提示,我能够制定以下代码,返回顶部对接面板的高度:
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
static Display* display;
// looks for the maximum "docking height" of all children of this window
static int top_panel_height(Window window)
{
int height = 0; // maximum height
Window w;
Window* children;
unsigned int n_children;
XQueryTree(display, window, &w, &w, &children, &n_children);
// looks for each one of the children
int i;
for(i=0; i<n_children; i++)
{
// this is the property we're looking for
Atom strut = XInternAtom(display, "_NET_WM_STRUT_PARTIAL",
False);
Atom type_return;
int actual_type;
unsigned long nitems, bytes;
unsigned char* data = NULL;
// load window attributes (we only want to know about the
// windows where y = 0)
XWindowAttributes xwa;
XGetWindowAttributes(display, window, &xwa);
// load the property _NET_WM_STRUT_PARTIAL
int s = XGetWindowProperty(display, window, strut, 0, LONG_MAX,
False,
XA_CARDINAL, &type_return, &actual_type,
&nitems, &bytes, (unsigned char**)&data);
if(s == Success)
{
Atom *state = (Atom *) data;
// state[2] contains the "dock height"
if(xwa.y == 0 && nitems > 0 && state[2])
if(state[2] > height)
height = state[2];
}
// recursively, traverse the tree of all children of children
int children_max_height = top_panel_height(children[i]);
if(children_max_height > height)
height = children_max_height;
}
return height;
}
int main()
{
display = XOpenDisplay(NULL);
Window root = RootWindow(display, DefaultScreen(display));
printf("%d\n", top_panel_height(root));
return 0;
}
#包括
#包括
#包括
#包括
#包括
静态显示*显示;
//查找此窗口所有子窗口的最大“停靠高度”
静态内部顶部面板高度(窗口)
{
int height=0;//最大高度
窗口w;
窗口*儿童;
未签名整数n_子项;
XQueryTree(显示、窗口、&w、&w、&children、&n_children);
//寻找每个孩子
int i;
对于(i=0;i