X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=ioncore%2Ffocus.c;h=c25ec716ff1750906c2a9ad50927eccca32f0cb9;hp=fb2159bf7f992f6ee0dc74f51d2681b3f95b3470;hb=20070203;hpb=8366314611bf30a0f31d25bf5f5023186fa87692 diff --git a/ioncore/focus.c b/ioncore/focus.c index fb2159b..c25ec71 100644 --- a/ioncore/focus.c +++ b/ioncore/focus.c @@ -1,7 +1,7 @@ /* * ion/ioncore/focus.c * - * Copyright (c) Tuomo Valkonen 1999-2006. + * Copyright (c) Tuomo Valkonen 1999-2007. * * Ion is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by @@ -25,8 +25,6 @@ WHook *region_do_warp_alt=NULL; -WHook *region_activated_hook=NULL; -WHook *region_inactivated_hook=NULL; /*}}}*/ @@ -35,22 +33,27 @@ WHook *region_inactivated_hook=NULL; /*{{{ Focus list */ -void region_focuslist_remove(WRegion *reg) +void region_focuslist_remove_with_mgrs(WRegion *reg) { + WRegion *mgrp=region_manager_or_parent(reg); + UNLINK_ITEM(ioncore_g.focus_current, reg, active_next, active_prev); + + if(mgrp!=NULL) + region_focuslist_remove_with_mgrs(mgrp); } void region_focuslist_push(WRegion *reg) { - region_focuslist_remove(reg); + region_focuslist_remove_with_mgrs(reg); LINK_ITEM_FIRST(ioncore_g.focus_current, reg, active_next, active_prev); } void region_focuslist_move_after(WRegion *reg, WRegion *after) { - region_focuslist_remove(reg); + region_focuslist_remove_with_mgrs(reg); LINK_ITEM_AFTER(ioncore_g.focus_current, after, reg, active_next, active_prev); } @@ -62,8 +65,8 @@ void region_focuslist_deinit(WRegion *reg) if(replace!=NULL) region_focuslist_move_after(replace, reg); - - region_focuslist_remove(reg); + + UNLINK_ITEM(ioncore_g.focus_current, reg, active_next, active_prev); } @@ -99,6 +102,34 @@ WRegion *ioncore_goto_previous() } +/*EXTL_DOC + * Iterate over focus history until \var{iterfn} returns \code{false}. + * The function itself returns \code{true} if it reaches the end of list + * without this happening. + */ +EXTL_EXPORT +bool ioncore_focushistory_i(ExtlFn iterfn) +{ + WRegion *next; + + if(ioncore_g.focus_current==NULL) + return FALSE; + + /* Find the first region on focus history list that isn't currently + * active. + */ + for(next=ioncore_g.focus_current->active_next; + next!=NULL; + next=next->active_next){ + + if(!extl_iter_obj(iterfn, (Obj*)next)) + return FALSE; + } + + return TRUE; +} + + /*}}}*/ @@ -161,9 +192,9 @@ static void check_clear_await(WRegion *reg) } -bool ioncore_await_focus() +WRegion *ioncore_await_focus() { - return (await_watch.obj!=NULL); + return (WRegion*)(await_watch.obj); } @@ -175,7 +206,7 @@ bool ioncore_await_focus() void region_got_focus(WRegion *reg) { - WRegion *par, *mgr, *tmp; + WRegion *par; check_clear_await(reg); @@ -188,30 +219,18 @@ void region_got_focus(WRegion *reg) if(!REGION_IS_ACTIVE(reg)){ D(fprintf(stderr, "got focus (inact) %s [%p]\n", OBJ_TYPESTR(reg), reg);) + reg->flags|=REGION_ACTIVE; + region_set_manager_pseudoactivity(reg); par=REGION_PARENT_REG(reg); if(par!=NULL){ par->active_sub=reg; region_update_owned_grabs(par); } - - region_activated(reg); - mgr=REGION_MANAGER(reg); - tmp=reg; - while(mgr!=NULL){ - /* We need to loop over managing non-windows (workspaces) here to - * signal their managers. - */ - region_managed_activated(mgr, tmp); - - if(REGION_PARENT_REG(reg)==mgr) - break; - - tmp=mgr; - mgr=REGION_MANAGER(mgr); - } + region_activated(reg); + region_notify_change(reg, ioncore_g.notifies.activated); }else{ D(fprintf(stderr, "got focus (act) %s [%p]\n", OBJ_TYPESTR(reg), reg);) } @@ -223,16 +242,12 @@ void region_got_focus(WRegion *reg) */ if(reg->active_sub==NULL && !OBJ_IS(reg, WClientWin)) rootwin_install_colormap(region_rootwin_of(reg), None); - - extl_protect(NULL); - hook_call_o(region_activated_hook, (Obj*)reg); - extl_unprotect(NULL); } void region_lost_focus(WRegion *reg) { - WRegion *r, *par; + WRegion *par; if(!REGION_IS_ACTIVE(reg)){ D(fprintf(stderr, "lost focus (inact) %s [%p:]\n", OBJ_TYPESTR(reg), reg);) @@ -260,14 +275,10 @@ void region_lost_focus(WRegion *reg) D(fprintf(stderr, "lost focus (act) %s [%p:]\n", OBJ_TYPESTR(reg), reg);) reg->flags&=~REGION_ACTIVE; - region_inactivated(reg); - r=REGION_MANAGER(reg); - if(r!=NULL) - region_managed_inactivated(r, reg); + region_unset_manager_pseudoactivity(reg); - extl_protect(NULL); - hook_call_o(region_inactivated_hook, (Obj*)reg); - extl_unprotect(NULL); + region_inactivated(reg); + region_notify_change(reg, ioncore_g.notifies.inactivated); } @@ -290,28 +301,14 @@ bool region_is_active(WRegion *reg) bool region_may_control_focus(WRegion *reg) { - WRegion *par, *r2; - if(OBJ_IS_BEING_DESTROYED(reg)) return FALSE; - if(REGION_IS_ACTIVE(reg)) + if(REGION_IS_ACTIVE(reg) || REGION_IS_PSEUDOACTIVE(reg)) return TRUE; if(region_is_await(reg)) return TRUE; - - par=REGION_PARENT_REG(reg); - - if(par==NULL || !REGION_IS_ACTIVE(par)) - return FALSE; - - r2=par->active_sub; - while(r2!=NULL && r2!=par){ - if(r2==reg) - return TRUE; - r2=REGION_MANAGER(r2); - } return FALSE; } @@ -395,6 +392,14 @@ void region_maybewarp(WRegion *reg, bool warp) } +void region_maybewarp_now(WRegion *reg, bool warp) +{ + ioncore_g.focus_next=NULL; + /* TODO: what if focus isn't set? Should focus_next be reset then? */ + region_do_set_focus(reg, warp); +} + + void region_set_focus(WRegion *reg) { region_maybewarp(reg, FALSE); @@ -432,4 +437,49 @@ WRegion *ioncore_current() return ioncore_g.focus_current; } + +/*}}}*/ + + +/*{{{ Pointer focus hack */ + + +/* This ugly hack tries to prevent focus change, when the pointer is + * in a window to be unmapped (or destroyed), and that does not have + * the focus, or should not soon have it. + */ +void region_pointer_focus_hack(WRegion *reg) +{ + WRegion *act=ioncore_await_focus(); + const WRectangle *g=®ION_GEOM(reg); + int x, y; + + if(ioncore_g.opmode!=IONCORE_OPMODE_NORMAL) + return; + + if(!REGION_IS_ACTIVE(reg) && act==NULL) + act=ioncore_g.focus_current; + + if(act==NULL || OBJ_IS_BEING_DESTROYED(act)) + return; + + /* Ok, anything under us should not get focus as we're unmapped: + * Either we don't have the focus, or focus change somewhere else + * is pending. + * + * It might be possible to do the pointer check more efficiently + * by trying to maintain our internal pointer containment state + * by tracking Enter/Leave events... + */ + + xwindow_pointer_pos(region_xwindow(reg), &x, &y); + + if(x>=0 && y>=0 && xw && yh){ + D(fprintf(stderr, "Pointer here and shouldn't alter focus!\n")); + region_set_focus(act); + } +} + + /*}}}*/ +