2016-03-23 113 views
0

如何獲取X11中窗口的標題/標題高度?我使用以下來獲得邊框厚度:獲取X11窗口標題高度

XWindowAttributes wndattr; 
::XGetWindowAttributes(display, wnd, &wndattr) 
... = lWndAttr->border_width; 

我似乎無法找到任何標題欄的簡單內容。 (This答案似乎暗示我需要經過一個字體,但不能是正確的,對不對?)

+1

這個答案當然是不正確的。 –

回答

0

XGetWindowAttributes返回一個指向XWindowAttributes structurex,它看起來像這樣:

typedef struct { 
    int x, y;     /* location of window */ 
    int width, height;   /* width and height of window */ 
    int border_width;   /* border width of window */ 
    int depth;     /* depth of window */ 
    Visual *visual;    /* the associated visual structure */ 
    Window root;    /* root of screen containing window */ 
#if defined(__cplusplus) || defined(c_plusplus) 
    int c_class;    /* C++ InputOutput, InputOnly*/ 
#else 
    int class;     /* InputOutput, InputOnly*/ 
#endif 
    int bit_gravity;   /* one of bit gravity values */ 
    int win_gravity;   /* one of the window gravity values */ 
    int backing_store;   /* NotUseful, WhenMapped, Always */ 
    unsigned long backing_planes;/* planes to be preserved if possible */ 
    unsigned long backing_pixel;/* value to be used when restoring planes */ 
    Bool save_under;   /* boolean, should bits under be saved? */ 
    Colormap colormap;   /* color map to be associated with window */ 
    Bool map_installed;   /* boolean, is color map currently installed*/ 
    int map_state;    /* IsUnmapped, IsUnviewable, IsViewable */ 
    long all_event_masks;  /* set of events all people have interest in*/ 
    long your_event_mask;  /* my event mask */ 
    long do_not_propagate_mask; /* set of events that should not propagate */ 
    Bool override_redirect;  /* boolean value for override-redirect */ 
    Screen *screen;    /* back pointer to correct screen */ 
} XWindowAttributes; 

唯一有趣的部分是開頭,給出了窗口小部件的位置和大小。 標題不是該窗口的一部分。它由窗口管理器管理,並且是所謂的「裝飾」的一部分。

延伸閱讀:

0

的答案真的取決於所使用的窗口管理器,芽最WMS的重新設置父級目標窗口是兒童一個框架,所以算法將是:

  • 走到父窗口,直到到達根目錄。根之前的一個可能是框架
  • 比較你的目標窗口矩形與框架矩形。支撐架頂部減去目標頂部會給你的標題高度
0

現代的窗口管理器通過Extended Window Manager Hints規範遵守,所以你只需要檢查_NET_FRAME_EXTENTS屬性。

#include <X11/Xlib.h> 
#include <stdio.h> 

int main() 
{ 
    Display* d; 
    Window w, root; 
    Atom a, t; 
    int s; 
    long fg, bg; 
    int f; 
    unsigned long n, b; 
    unsigned char *data = 0; 
    long* extents; 
    XEvent e; 

    d = XOpenDisplay(0); 
    s = DefaultScreen(d); 
    root = DefaultRootWindow(d); 
    fg = BlackPixel(d, s); 
    bg = WhitePixel(d, s); 
    w = XCreateSimpleWindow(d, root, 0, 0, 200, 200, 0, fg, bg); 
    XSelectInput(d, w, ExposureMask|ButtonPressMask|KeyPressMask|PropertyChangeMask); 

    XMapWindow(d,w); 

    a = XInternAtom(d, "_NET_FRAME_EXTENTS", True); /* Property to check */ 

    /* Window manager doesn't set up the extents immediately */ 
    /* Wait until they are set up and there are 4 of them */ 
    while (XGetWindowProperty(d, w, a, 
        0, 4, False, AnyPropertyType, 
        &t, &f, 
        &n, &b, &data) != Success || n != 4 || b != 0) 
    { 
     printf ("Waiting for extents\n"); 
     XNextEvent(d, &e); 
    } 

    /* OK got extents */ 
    extents = (long*) data; 
    printf ("Got frame extents: left %ld right %ld top %ld bottom %ld\n", 
      extents[0], extents[1], extents[2], extents[3]); 

    return 0; 
} 

如果您使用的是不太現代化的WM,那麼您就是您自己的。按照安德烈的回答建議,沿着窗口樹走。這很可能會起作用,但不能保證。一些窗口管理器根本不使用單獨的「幀」窗口(例如,它們可以在覆蓋圖中在單個窗口上繪製所有幀)。

+0

我總共是X11 n00b,並且非常感謝一個最小(僞?)代碼示例,謝謝! –