通知区域协议在GNOME或KDE中不起作用(尝试使用Ubuntu 10.10)

我不能为我的生活获得freedesktop.xorg“系统托盘”协议 使用GNOME或KDE的规范,尽管我认为它们都支持 它。不幸的是,我遇到了同样令人沮丧的失败,试图将这个问题发布到古老的freedesktop.xorg Gmane新闻组存档(允许我只有80个字符来解释我的问题)。单凭这种心态,我对以下失败并不感到惊讶。 这是我尝试过的唯一两个窗口/桌面管理器(Ubuntu 10.10)。我在用:
GNOME version 2.32.0
KDE version 4.5.1
对于GNOME,我的潘多拉“托盘图标”旁边有一个2像素宽的小条子 当我执行以下程序时。对于KDE,我得到一个灰色图标。我期待 看到一个不均匀的彩色图标,或一个全黑的图标,因为我只有 初始化下面的缓冲区变量的宽度和高度,而不是像素值。 不幸的是,在花了几个小时之后,我已经放弃并决定了 不支持此功能。如果我只是做一些愚蠢的事情,我想要 在这里发布此信息,以便其他人可以从我的错误中学习。除此以外, 如果这是一个错误,也许我将在以后解决它时包含此功能。无论如何,我很乐意尝试其他人的建议或尝试任何你可能获得的经验教训。 我引用了以下网站以获得解决此问题的指导(没有 解): http://kobelisk.de/files/doxygen/trayicon__x11_8cpp-source.html http://libjdic-java.sourcearchive.com/documentation/0.9.5-6/Tray_8c-source.html 我有更多的超链接,但由于我是这个网站的新手,我不允许发布它们。 我很清楚还有其他库来实现这一点,比如gtk。对于我的场景,这不属于可接受的解决方案领域。 这是我使用的命令:
gcc -lX11 -lstdc++ -L/usr/X11/lib -o test test.cpp
这是一个重新创建问题的通用程序(Ubuntu 10.10):
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#define WIDTH 16
#define HEIGHT 16

void send_message( Display* dpy, Window w,    long message, long data1 , long
data2 , long data3 )
{
    XEvent ev;

    memset (&ev, 0, sizeof (ev));
    ev.xclient.type = ClientMessage;
    ev.xclient.window = w;
    ev.xclient.message_type =
        XInternAtom (dpy, "_NET_SYSTEM_TRAY_OPCODE", False);
    ev.xclient.format = 32;
    ev.xclient.data.l[0] = CurrentTime;
    ev.xclient.data.l[1] = message;
    ev.xclient.data.l[2] = data1;
    ev.xclient.data.l[3] = data2;
    ev.xclient.data.l[4] = data3;

    XSendEvent (dpy, w, False, NoEventMask, &ev);
    XSync (dpy, False);
}

int main( int argc, char **argv )
{

    unsigned int buffer[WIDTH * HEIGHT];
    Display *dis = XOpenDisplay(0);
    int s = DefaultScreen(dis);
    Atom net_wm_icon = XInternAtom(dis, "_NET_WM_ICON", False);
    Atom cardinal = XInternAtom(dis, "CARDINAL", False);
    Window win;
    XEvent e;
    XSizeHints *  size_hints;
    XWMHints   *  wm_hints;
    XClassHint *  class_hints;
    XTextProperty windowName, iconName;

    char *       window_name = "huh";
    char *       icon_name   = "huh";

    if ( !( size_hints  = XAllocSizeHints() ) || 
            !( wm_hints    = XAllocWMHints()   ) ||
            !( class_hints = XAllocClassHint() )    ) {
        fprintf(stderr, "Couldn't allocate memory.n");
        return 0;
    }

    //win = XCreateSimpleWindow(dis, RootWindow(dis, 0), 1, 1, 500, 500, 0,
BlackPixel (dis, 0), BlackPixel(dis, 0));
    //w = XCreateWindow(d, RootWindow(d, s), 0, 0, 200, 200, 0,
    //                  CopyFromParent, InputOutput, CopyFromParent, 0, 0);

    win = XCreateWindow(dis,RootWindow(dis,0), 0,0,10,10,1, CopyFromParent,
CopyFromParent, CopyFromParent, 0, 0);   

    if ( XStringListToTextProperty(&window_name, 1, &windowName) == 0 ) {
        fprintf(stderr, "%s: structure allocation for windowName failed.n",
                "yo");
        return 0;
    }

    if ( XStringListToTextProperty(&icon_name, 1, &iconName) == 0 ) {
        fprintf(stderr, "%s: structure allocation for iconName failed.n",
                "yo");
        return 0;
    }

    size_hints->flags       = PPosition | PSize | PMinSize;
    size_hints->min_width   = 1;
    size_hints->min_height  = 1;

    wm_hints->flags         = StateHint | InputHint | IconPixmapHint |
IconMaskHint; // | WindowGroupHint;
    wm_hints->initial_state = NormalState;
    wm_hints->input         = True;
    wm_hints->icon_pixmap   = XCreatePixmap(dis, win, WIDTH, HEIGHT,
DefaultDepth(dis, s));
    wm_hints->icon_mask     = XCreatePixmap(dis, win, WIDTH, HEIGHT,
DefaultDepth(dis, s));
    //wm_hints->window_group  = bla;

    class_hints->res_name   = "huh";
    class_hints->res_class  = "huh";

    XSetWMProperties(dis, win, &windowName, &iconName, NULL, 0,
            size_hints, wm_hints, class_hints);

    int length = 2 + WIDTH * HEIGHT + 2 + WIDTH * HEIGHT;
    buffer[0] = WIDTH;
    buffer[1] = HEIGHT;
    XChangeProperty(dis, win, net_wm_icon, cardinal, 32,
                     PropModeReplace, (const unsigned char*) buffer, length);


    XSync(dis, false);
    XFlush(dis);

    XMapWindow(dis, win);
    int data[2];
    data[0] = 0;
    data[1] = 1;

    Atom net_system_tray = XInternAtom(dis,"_NET_SYSTEM_TRAY_S0",False);
    Atom embed_type = XInternAtom(dis,"_XEMBED_INFO",False);

    Window tray_owner = XGetSelectionOwner(dis,net_system_tray);

    XChangeProperty(dis,win,embed_type,embed_type,32,PropModeReplace,(const
unsigned char *)data,2);
    send_message(dis,tray_owner,0,win,0,0);
    XSync(dis,False);

    while(1) XNextEvent(dis, &e);
}
    
已邀请:

要回复问题请先登录注册