2010-10-23 25 views
1

我正在寫把碼頭在屏幕的右側的應用程序面板的大小,類似這樣的:發現與Xlib的

Image

我可以在屏幕的一側預留空間通過使用_NET_WM_STRUT_PARTIAL,以便最大化的窗口不會與碼頭重疊。

在圖像中,你可以看到,有一個頂部面板。問題是,碼頭將面板重疊。有沒有方法可以找出面板的尺寸,或者制定一種方法來減少面板的開放空間?

我使用Xlib的,順便說一句。

回答

0

通過使用由Havoc P給出很好的提示,我能夠來提出這個代碼,返回頂部對接面板的高度:

#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; 
} 

它可能不漂亮,但它工作:-)

3

我想你必須跟蹤出現,他們是否有_NET_WM_STRUT_PARTIAL爲了計算自己的工作區中的所有頂層窗口,減去自己的Windows。您可以查看libwnck代碼以瞭解如何跟蹤所有頂層,並瞭解窗口管理器如何計算_NET_WORKAREA,以瞭解如何執行此操作。然後重做那個工作,但是減去你自己的支柱。與此有關的一個問題是,如果每個小組都做到了,那麼他們之間就會有一個無限循環,彼此都在一起工作。但是,你可以假設人們只有一個默認的桌面面板不會這樣做,再加上你的。

另一種選擇可能是隻讓你的面板的窗口總是全屏幕高度,但如果任何窗口上面的是你,你抵消得出什麼(和偏移事件處理)下降了一點。問題是很難追蹤窗戶如何與你重疊。 XVisibilityEvent有點幫助,但不會告訴你頂部窗口何時移動。如果說全屏幕電影結束覆蓋整個面板,您還必須確保不會中斷。我想用這種方法你可能最終會掃描所有面板的頂層,就像第一種方法一樣。