Renamed package to ion1, and made it conflict with package 'ion'.
[ion1.git] / src / focus.c
blob9296cbdc7872b20a6137d3e223d04e247f84f1e9
1 /*
2 * ion/focus.c
4 * Copyright (c) Tuomo Valkonen 1999-2001.
5 * See the included file LICENSE for details.
6 */
8 #include "common.h"
9 #include "focus.h"
10 #include "thingp.h"
11 #include "global.h"
12 #include "wedln.h"
13 #include "query.h"
16 /*{{{ Previous active thing */
19 static WThing *current_client_or_frame()
21 WWindow *cw=wglobal.current_wswindow;
23 if(cw!=NULL && WTHING_IS(cw, WFrame) &&
24 ((WFrame*)cw)->current_client!=NULL){
25 return (WThing*)((WFrame*)cw)->current_client;
27 return (WThing*)cw;
31 static WThing *get_next_previous(WThing *next)
33 WThing *current=current_client_or_frame();
35 if(current==next || current==NULL)
36 return NULL;
38 if((WThing*)FIND_PARENT(current, WWindow)==next)
39 return NULL;
41 return current;
45 void set_previous(WThing *thing)
47 WThing *previous;
49 if(wglobal.previous_protect!=0)
50 return;
52 previous=get_next_previous(thing);
54 if(previous!=NULL)
55 wglobal.previous=previous;
59 void protect_previous()
61 wglobal.previous_protect++;
65 void unprotect_previous()
67 assert(wglobal.previous_protect>0);
68 wglobal.previous_protect--;
72 /*}}}*/
75 /*{{{ set_focus, warp */
77 void set_input_focus(Window win)
79 XSetInputFocus(wglobal.dpy, win, RevertToParent, CurrentTime);
82 void do_set_focus(WThing *thing)
84 if(thing==NULL){
85 thing=(WThing*)wglobal.current_screen;
86 if(thing==NULL)
87 return;
88 }else if(!on_visible_workspace(thing)){
89 return;
92 query_set_function_thing(thing);
94 if(WTHING_IS(thing, WFrame))
95 focus_frame((WFrame*)thing);
96 else if(WTHING_IS(thing, WWindow))
97 focus_window((WWindow*)thing);
98 else if(WTHING_IS(thing, WClient))
99 focus_client((WClient*)thing);
100 else if(WTHING_IS(thing, WClientWin))
101 focus_clientwin((WClientWin*)thing);
102 else{
103 if(wglobal.current_screen!=NULL){
104 XSetInputFocus(wglobal.dpy, wglobal.current_screen->root.win,
105 RevertToNone, CurrentTime);
111 void set_focus(WThing *thing)
113 wglobal.focus_next=thing;
114 query_set_function_thing(thing);
118 void warp(WWindow *wwin)
120 #ifdef CF_WARP
121 XWarpPointer(wglobal.dpy, None, wwin->win, 0, 0, 0, 0,
122 5, 5);
123 #endif
124 set_focus((WThing*)wwin);
125 query_set_function_thing((WThing*)wwin);
129 /*}}}*/