Explanation of this part of code in mbdesktop.c
Diana Joseph <[email protected]> Tue, 26 Jul 2005 15:35:15 +0900
| Newsgroups | gmane.comp.handhelds.matchbox |
|---|---|
| Message-ID | <[email protected]> |
I have some problems with selection of the proper active_item in the
desktop window.
Anyone can brief me what the handle_button_event(MBDesktop *mb,
XButtonEvent *e) API does in matchbox-desktop/mbdesktop.c
Please tell me what you feel...thank you
void
handle_button_event(MBDesktop *mb, XButtonEvent *e)
{
XEvent ev;
MBDesktopItem *active_item = NULL;
active_item = mbdesktop_item_get_from_coords(mb, e->x, e->y);
if (active_item)
{
Bool canceled = False;
if (XGrabPointer(mb->dpy, mb->win_top_level, False,
ButtonPressMask|ButtonReleaseMask|
PointerMotionMask|EnterWindowMask|LeaveWindowMask,
GrabModeAsync,
GrabModeAsync, None, None, CurrentTime)
== GrabSuccess)
{
if (mb->have_focus && mb->had_kbd_input)
{
mbdesktop_view_item_highlight (mb, mb->kbd_focus_item,
HIGHLIGHT_OUTLINE_CLEAR);
}
mbdesktop_view_item_highlight (mb, active_item, HIGHLIGHT_FILL);
/// Action starts here for next mouse input.....So causes
error.....When swapped with keyboard action starts at if(active_item)
causing correct behavior
for (;;)
{
int x1 = active_item->x;
int x2 = active_item->x + active_item->width;
int y1 = active_item->y;
int y2 = active_item->y + active_item->height;
XMaskEvent(mb->dpy,
ButtonPressMask|ButtonReleaseMask|
PointerMotionMask, &ev);
switch (ev.type)
{
case MotionNotify:
if (canceled
&& ev.xmotion.x > x1
&& ev.xmotion.x < x2
&& ev.xmotion.y > y1
&& ev.xmotion.y < y2
)
{
mbdesktop_view_item_highlight (mb, active_item, HIGHLIGHT_FILL);
canceled = False;
break;
}
if (!canceled
&& ( ev.xmotion.x < x1
|| ev.xmotion.x > x2
|| ev.xmotion.y < y1
|| ev.xmotion.y > y2
))
{
mbdesktop_view_item_highlight (mb, active_item, HIGHLIGHT_FILL_CLEAR);
canceled = True;
break;
}
break;
case ButtonRelease:
XUngrabPointer(mb->dpy, CurrentTime);
if (!canceled)
{
mbdesktop_view_item_highlight (mb, active_item,
HIGHLIGHT_FILL_CLEAR);
if (active_item->activate_cb)
active_item->activate_cb((void *)mb,
(void *)active_item);
return;
}
else
{
if (mb->have_focus && mb->had_kbd_input)
{
mb->kbd_focus_item = active_item;
mbdesktop_view_item_highlight (mb,
mb->kbd_focus_item,
HIGHLIGHT_OUTLINE_CLEAR);
}
return;
}
}
}
}
}
else
{
if (e->y < mb->workarea_y + 20)
{
if (e->x > (mb->workarea_x + mb->workarea_width -24))
mbdesktop_scroll_up(mb);
else if (e->x > (mb->workarea_x + mb->workarea_width -40))
mbdesktop_scroll_down(mb);
mbdesktop_view_paint(mb, False);
}
}
}
Thanks