diff -urN nanowmnew/actions.c nanowm/actions.c --- nanowmnew/actions.c Thu Jun 14 11:41:28 2001 +++ nanowm/actions.c Sun Jan 21 11:11:35 2001 @@ -21,6 +21,7 @@ GR_WINDOW_INFO info; GR_WM_PROPERTIES props; GR_BOOL active; + GR_WINDOW_ID focusedwindow; Dprintf("container_exposure window %d\n", window->wid); @@ -35,12 +36,63 @@ */ if (props.flags == 0) return; - - active = (window->clientid == GrGetFocus()); + + /*Get window with Keyboard focus --Amit Kulkarni*/ + focusedwindow=GrGetFocus(); + /* + * Check if the current window or any of its ancestors has the focus + * A window is active even if any of its ancestors has focus + * --Amit Kulkarni + */ + active = CheckHasFocus(window->clientid,focusedwindow); + /* + * Note that we should also raise the window if its active and behind. + * an active window deserves to be on the top + * :-) + * -- Amit Kulkarni + */ + if(active) + GrRaiseWindow(window->wid); + /* + * I dont know where all we are maintaining the active field + * in the window data structure. To be doubly sure + * better save it here as well + * -- Amit Kulkarni + */ + window->active=active; + nxPaintNCArea(window->wid, info.width, info.height, props.title, active, props.props); } +/* + * This function performs a depth first search on window + * and finds if any of its children has focus. + * i.e. wid equal to ref + * -- Amit Kulkarni + */ + +GR_BOOL CheckHasFocus(GR_WINDOW_ID wid,GR_WINDOW_ID ref) +{ + GR_WINDOW_INFO winfo; + GR_WINDOW_ID childwid; + if(wid==ref) + return GR_TRUE; + GrGetWindowInfo(wid, &winfo); + /*Go down*/ + childwid = winfo.child; + while (childwid) + { + if( CheckHasFocus(childwid,ref)) + return GR_TRUE; + GrGetWindowInfo (childwid,&winfo); + /*Go right*/ + childwid=winfo.sibling; + } + /*Nah.. no match here*/ + return GR_FALSE; +} + void container_exposure(win *window, GR_EVENT_EXPOSURE *event) { Dprintf("container_exposure window %d\n", window->wid); @@ -64,7 +116,7 @@ GR_GC_ID gc; Dprintf("container_buttondown window %d\n", window->wid); - if(window->active) return; + //if(window->active) return; GrGetWindowInfo(window->wid, &info); @@ -96,8 +148,18 @@ } } - /* Set focus on button down*/ - GrSetFocus(window->clientid); + /* + * Set focus to the window only if client + * or the container itself is clicked. + * if any of the children (of the client) + * are clicked better not take the focus + * away from them. They might require handling + * the focus themself. + * -- Amit Kulkarni + */ + + if(window->wid==event->subwid) + GrSetFocus(window->wid); /* check for corner resize */ r.x = info.width - 5; @@ -133,6 +195,13 @@ pos->width = info.width; pos->height = info.height; + /* + * This window is being resized. So now it is active. + * The client should have focus now. + * -- Amit Kulkarni + */ + GrSetFocus(window->clientid); + return; } @@ -149,6 +218,14 @@ /* Check for mousedn in caption box*/ if (!PtInRect(&r, event->x, event->y)) return; + + /* + * Now we have a click on the caption. + * So window is active. + * Set focus to the client + * --Amit Kulkarni + */ + GrSetFocus(window->clientid); /* Raise window if mouse down and allowed*/ if (!(info.props & GR_WM_PROPS_NORAISE)) @@ -180,13 +257,14 @@ GrDestroyGC(gc); #endif window->active = GR_TRUE; + window->moving = GR_TRUE; } void container_buttonup(win *window, GR_EVENT_BUTTON *event) { Dprintf("container_buttonup window %d\n", window->wid); - if(window->active) { + if(window->moving) { struct pos_size * pos = (struct pos_size *)window->data; #ifdef OUTLINE_MOVE GR_GC_ID gc; @@ -198,7 +276,7 @@ #endif free(pos); - window->active = GR_FALSE; + window->moving = GR_FALSE; window->data = 0; } @@ -231,7 +309,7 @@ GR_WINDOW_INFO info; GR_GC_ID gc; - Dprintf("container_mousemoved window %d\n", window->wid); + //Dprintf("container_mousemoved window %d\n", window->wid); if(window->sizing) { @@ -256,9 +334,10 @@ return; } - if(!window->active) return; + if(!window->moving) return; pos = (struct pos_size *) window->data; + if(!pos)return; #ifdef OUTLINE_MOVE gc = GrNewGC(); @@ -300,7 +379,7 @@ TITLE_BAR_HEIGHT, window->active ? closebutton_pressed : closebutton_notpressed); } - +#endif void topbar_buttondown(win *window, GR_EVENT_BUTTON *event) { struct position *pos; @@ -316,12 +395,12 @@ pos = (struct position *) window->data; - pos->x = event->x + TITLE_BAR_HEIGHT; /* actually width*/ + pos->x = event->x ;//+ TITLE_BAR_HEIGHT; /* actually width*/ pos->y = event->y; window->active = GR_TRUE; } - +#if 0000 void resizebar_buttondown(win *window, GR_EVENT_BUTTON *event) { GR_WINDOW_INFO wi; diff -urN nanowmnew/events.c nanowm/events.c --- nanowmnew/events.c Thu Jun 14 11:41:28 2001 +++ nanowm/events.c Sun Jan 21 10:43:35 2001 @@ -165,12 +165,12 @@ void do_key_up(GR_EVENT_KEYSTROKE *event) { - Dprintf("do_key_up: wid %d, subwid %d, rootx %d, rooty %d, x %d, " + /*Dprintf("do_key_up: wid %d, subwid %d, rootx %d, rooty %d, x %d, " "y %d, buttons %d, modifiers %d, uch %lu, special %d, " "ch %d, content %d\n", event->wid, event->subwid, event->rootx, event->rooty, event->x, event->y, event->buttons, event->modifiers, event->uch, event->special, event->ch, - event->content); + event->content);*/ } void do_update(GR_EVENT_UPDATE *event) diff -urN nanowmnew/nanowm.h nanowm/nanowm.h --- nanowmnew/nanowm.h Thu Jun 14 11:41:28 2001 +++ nanowm/nanowm.h Sun Jan 21 10:40:20 2001 @@ -22,8 +22,8 @@ enum { WINDOW_TYPE_ROOT, WINDOW_TYPE_CONTAINER, - WINDOW_TYPE_CLIENT - /***WINDOW_TYPE_TOPBAR, + WINDOW_TYPE_CLIENT, + /**WINDOW_TYPE_TOPBAR WINDOW_TYPE_LEFTBAR, WINDOW_TYPE_RIGHTBAR, WINDOW_TYPE_BOTTOMBAR, @@ -55,6 +55,7 @@ GR_WINDOW_ID clientid; /* clientid for container window*/ int type; /* What kind of window this is */ int sizing; /* True if in the middle of a sizing request */ + int moving; /* True if in the middle of a moving request */ int active; /* Whether this window is active or not */ void *data; /* Data associated with this window */ struct windowlist *next; /* The next window in the list */ @@ -99,6 +100,7 @@ int new_client_window(GR_WINDOW_ID wid); void client_window_destroy(win *window); void redraw_ncarea(win *window); +GR_BOOL CheckHasFocus(GR_WINDOW_ID wid,GR_WINDOW_ID ref); void do_exposure(GR_EVENT_EXPOSURE *event); void do_button_down(GR_EVENT_BUTTON *event); void do_button_up(GR_EVENT_BUTTON *event);