discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppIcon Issue...


From: Dan Pascu
Subject: Re: AppIcon Issue...
Date: Tue, 30 Jan 2001 00:53:25 +0200 (EET)

On 28 Jan, Richard Frith-Macdonald wrote:
> Window Maker re-parents the icon window you give it - so when you move the
> icon window, it moves within the parent Window Maker has given it (which
> makes it disappear) - because (for some reason) Window Maker does not
> intercept the events and move the parent.
> Similarly, Window Maker doesn't pass the events for that window to the app,
> so the app can't detect the right mouse click.

How is that? There are already plenty of so named dockapps, that
consist only in the appicon itself (no menu or any other window on
screen), and which completely control the appicon window. They receive
_any_ mouse button click, and there are even ones that can assign
various actions to different button clicks in their window (take wmmon
as example). They also draw whatever they like in the appicon window in
real time (like the network analyzers: wmnet, wmifs, wmnd or the cpu
monitor previously mentioned: wmmon).
There is even a dockapp that one can type in it's window: wmpinboard.

Here are plenty examples of dockapps that do all these things:

http://www.bensinclair.com/dockapp/

> 
> I don't know how to ask Window Maker to give control of the icon to the app,
> or even if there is any way to do this.  My suspicion is that a substantial
> amount of work needs to be done in Window maker itsself ... but it may
> actually all be hidden in there somewhere.

I doubt that any substantial work needs to be done in wmaker, as it
already permits the existence of dockapps that make anything they want
with the appicon window (regarding drawing in it and receiving any
events from that window). Except maybe for some small fixes for
particular things gnustep may need I think all is already in there.
As an dockapp can get any mouse button and assign an event to it (like
running an external app), gnustep can use the intercepted right click
to open its menu or whatever it needs to do on right click on the
appicon.

As dockapps can already do these things, I think there is nothing that
stops gnustep to do the same.

Here is some example code that shows what needs to be done to be able
to draw in the appicon window, and to receive events from it:

The init method is the most important for this issue. Notice the 2
windows: _mainWindow required to assign hints to the app, so that
wmaker will make the appicon for it, and _window which is the icon
window itself in which you can draw and receive events from.
Also don't forget the relaying of mouse button events back to wmaker,
or else you will not be able to move them around without keeping Alt
pressed while you do this.
As you notice, you need to pass ButtonPressMask, ButtonReleaseMask and
ButtonMotionMask for XSelectInput() to be able to receive any button
events in the appicon window.

- (BarfToplevel*)init: (char*)name
            onDisplay: (Display*)display
                 argv: (char**)argv
                 argc: (int)argc
{
    XClassHint *chint = XAllocClassHint();
    XWMHints *whint = XAllocWMHints();

    assert(chint && whint);

    [self init: name  argv: argv  argc: argc];

    _iconSize.width = 64;
    _iconSize.height = 64;

    _dpy = display;

    _window = XCreateSimpleWindow(_dpy, DefaultRootWindow(_dpy),
                                0, 0, _iconSize.width, _iconSize.height,
                                0, 0, 0);

    _mainWindow = XCreateSimpleWindow(_dpy, DefaultRootWindow(_dpy),
                                0, 0, 1, 1, 0, 0, 0);


    XSelectInput(_dpy, _window, ButtonPressMask|ButtonReleaseMask|
                                ButtonMotionMask|PointerMotionMask|
                                EnterWindowMask|LeaveWindowMask|
                                ExposureMask|StructureNotifyMask);


    XSetCommand(_dpy, _mainWindow, argv, argc);

    chint->res_class = "DockApp";
    chint->res_name = name;
    XSetClassHint(_dpy, _mainWindow, chint);
    XFree(chint);


    whint->flags = WindowGroupHint | StateHint | IconWindowHint;
    whint->initial_state = WithdrawnState;
    whint->window_group = _mainWindow;
    whint->icon_window = _window;
    XSetWMHints(_dpy, _mainWindow, whint);

    return self;
}


- (void)show
{
    [super show];

    XMapRaised(_dpy, _mainWindow);
}



- (void)sendEvent: (BarfEvent*)event
{
    if ([event type] == BSystemEvent) {
        XEvent *xev = ((XEvent*)[event systemEvent]);
        
        switch (xev->type) {
         case ReparentNotify:
            _parentWindow = xev->xreparent.parent;
            break;
         case DestroyNotify:
            puts("WINDOW DIED");
            exit(1);
            break;
         default:
            [super sendEvent: event];
            break;
        }
    } else {
        [super sendEvent: event];
    }
}



/*
 *----------------------------------------------------------------------
 * relayEvent
 *      Sends the event (buttonPress ones) to the dock icon.
 * Only buttonPress events will be relayed.
 *
 * Returns:
 *      Nothing
 *
 * Side effects:
 *      wmaker will receive a synthetic event for the button press.
 *----------------------------------------------------------------------
 */
- (void)relayEvent: (BarfEvent*)event
{
    XEvent xev;

    if (_parentWindow == None) {
        return;
    }

    xev = *(XEvent*)[event systemEvent];

    switch (xev.type) {
     case ButtonPress:
        xev.xbutton.window = _parentWindow;
        XUngrabPointer(_dpy, CurrentTime);
        XSendEvent(_dpy, _parentWindow, True, ButtonPressMask, &xev);
        XFlush(_dpy);
        break;
    }
}


- (void)flush
{
    BPixmapFactory *fac = [BPixmapFactory sharedFactory];

    [super flush];

    XSetWindowBackgroundPixmap(_dpy, _window, 
                               (Pixmap)[fac convertToPixmap: _currentImage]);

    XClearWindow(_dpy, _window);
    XFlush(_dpy);
}




-- 
Dan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]