Tray icon window drawing - Xwindows

This is a discussion on Tray icon window drawing - Xwindows ; Hi, I want to draw a window with a transparent pixmap (an icon), destined to be docked in the tray. The problem is that I don't know how to redraw the window properly: drawing the icon works fine, but due ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Tray icon window drawing

  1. Tray icon window drawing

    Hi,

    I want to draw a window with a transparent pixmap (an icon), destined to be
    docked in the tray. The problem is that I don't know how to redraw the window
    properly: drawing the icon works fine, but due to the pixmap mask, and due to
    the fact that my window has no background (because i want it to have the same
    background as the tray), the transparent parts are not redrawn. What is the
    usual way of doing this? I tried creating the window with the background of
    the tray, but it seems that color is black (instead of the color it actually
    has).

    thanks,
    Remko

  2. Re: Tray icon window drawing

    Remko Troncon writes:

    > Hi,
    >
    > I want to draw a window with a transparent pixmap (an icon),
    > destined to be docked in the tray. The problem is that I don't know
    > how to redraw the window properly: drawing the icon works fine, but
    > due to the pixmap mask, and due to the fact that my window has no
    > background (because i want it to have the same background as the
    > tray), the transparent parts are not redrawn. What is the usual way
    > of doing this? I tried creating the window with the background of
    > the tray, but it seems that color is black (instead of the color it
    > actually has).


    Not coping with transparent icon windows sounds like a bug in the tray
    application. As for the background colour, the window used for
    communication with the tray application is not the actual tray window,
    so querying the colour of that window will no yield any useful
    information. If you need to know the colour of the tray window you
    have to request ReparentNotify events from the X server. This will
    give you the actual tray window. Keep in mind, though, that the tray
    window doesn't need to have a solid background colour. You may be
    able to force a repaint of the tray background by using XClearArea()
    on your part of the parent window.

    --
    Måns Rullgård
    mans@mansr.com

  3. Re: Tray icon window drawing

    > Not coping with transparent icon windows sounds like a bug in the tray
    > application.


    I was using xystray, so I checked with kicker, and it seems to behave the same
    way. A window created without a background *draws* properly initially, but when
    I redraw (after a window moved over it), the transparent parts get messed up.
    I tried an XClearWindow, but that didn't help (as the docs predicted).

    > have to request ReparentNotify events from the X server. This will
    > give you the actual tray window. Keep in mind, though, that the tray
    > window doesn't need to have a solid background colour. You may be
    > able to force a repaint of the tray background by using XClearArea()
    > on your part of the parent window.


    Even when I watch the parent with ReparentNotify, the background color of
    both system trays appears to be 0.

    thanks,
    Remko

  4. Re: Tray icon window drawing

    Hi,

    Below is a dummy application that creates a transparent window and docks it.
    Whenever a window gets dragged over the dock, it doesn't redraw (which is not
    surprising, since I don't do anything to redraw). What is the way to make sure
    that this (empty) window gets redrawn properly?

    thanks,
    Remko


    #include
    #include

    int main(int argc, char** argv)
    {
    Display* display = XOpenDisplay(NULL);
    int screen = DefaultScreen(display);

    // Find the dock
    std:stringstream os;
    os << "_NET_SYSTEM_TRAY_S" << (unsigned int) screen;
    int selection_atom = XInternAtom(display, os.str().c_str(), False);
    int manager_atom = XInternAtom(display, "MANAGER", False);
    Window tray_window = XGetSelectionOwner(display, selection_atom);

    // Create the window
    XSetWindowAttributes window_attributes;
    Window icon_window = XCreateWindow(display, tray_window, 0, 0, 22, 22, 0, DefaultDepth(display,screen),InputOutput,CopyFromP arent, 0, &window_attributes);
    XSelectInput(display, icon_window, ExposureMask | ButtonPressMask | StructureNotifyMask);
    XMapWindow(display,icon_window);

    // Dock the window
    XEvent ev;
    memset(&ev, 0, sizeof(ev));
    ev.xclient.type = ClientMessage;
    ev.xclient.window = tray_window;
    ev.xclient.message_type = XInternAtom(display, "_NET_SYSTEM_TRAY_OPCODE", False);
    ev.xclient.format = 32;
    ev.xclient.data.l[0] = CurrentTime;
    ev.xclient.data.l[1] = 0;
    ev.xclient.data.l[2] = icon_window;
    XSendEvent(display, tray_window, False, NoEventMask, &ev);

    XEvent event;
    while (true) {
    XNextEvent(display, &event);
    switch (event.type) {
    default:
    break;
    }
    }
    }

  5. Re: Tray icon window drawing

    Remko Tron?on writes:

    > Hi,
    >
    > Below is a dummy application that creates a transparent window and
    > docks it. Whenever a window gets dragged over the dock, it doesn't
    > redraw (which is not surprising, since I don't do anything to
    > redraw). What is the way to make sure that this (empty) window gets
    > redrawn properly?


    Redraw it whenever you receive an Expose event.

    --
    Måns Rullgård
    mans@mansr.com

  6. Re: Tray icon window drawing

    > Redraw it whenever you receive an Expose event.

    Right, but how do I redraw it? XClearArea does nothing, because it's a
    transparent window. And it's an empty window, so there's nothing to draw.
    I want to draw what is underneath it, in order to keep it transparent.

    Other tray icons must be able to do it, because they seem to work fine with
    transparent icons.

    thanks,
    Remko

  7. Re: Tray icon window drawing

    Remko Troncon writes:

    >> Redraw it whenever you receive an Expose event.

    >
    > Right, but how do I redraw it? XClearArea does nothing, because it's a
    > transparent window. And it's an empty window, so there's nothing to draw.
    > I want to draw what is underneath it, in order to keep it transparent.


    XClearArea() doesn't do what you seem to think it does.

    --
    Måns Rullgård
    mans@mansr.com

+ Reply to Thread