]> git.decadent.org.uk Git - ion3.git/blob - ioncore/fullscreen.c
Merge commit '20070203' into HEAD
[ion3.git] / ioncore / fullscreen.c
1 /*
2  * ion/ioncore/fullscreen.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
5  *
6  * Ion is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  */
11
12 #include <libtu/setparam.h>
13 #include "common.h"
14 #include "global.h"
15 #include "sizehint.h"
16 #include "clientwin.h"
17 #include "attach.h"
18 #include "screen.h"
19 #include "manage.h"
20 #include "fullscreen.h"
21 #include "mwmhints.h"
22 #include "focus.h"
23 #include "group-cw.h"
24 #include "return.h"
25
26
27
28 /*{{{ Generic full screen mode code */
29
30
31 bool region_fullscreen_scr(WRegion *reg, WScreen *scr, bool switchto)
32 {
33     int rootx, rooty;
34     bool wasfs=TRUE;
35     int swf=(switchto ? MPLEX_ATTACH_SWITCHTO : 0);
36     WPHolder *ph=NULL;
37     bool newph=FALSE, ret;
38
39     ph=region_unset_get_return(reg);
40     
41     if(ph==NULL){
42         ph=region_make_return_pholder(reg);
43         newph=TRUE;
44     }
45     
46     ret=(mplex_attach_simple((WMPlex*)scr, reg, swf)!=NULL);
47     
48     if(!ret)
49         warn(TR("Failed to enter full screen mode."));
50     
51     if(!ret && newph)
52         destroy_obj((Obj*)ph);
53     else if(!region_do_set_return(reg, ph))
54         destroy_obj((Obj*)ph);
55     
56     return TRUE;
57 }
58
59
60 bool region_enter_fullscreen(WRegion *reg, bool switchto)
61 {
62     WScreen *scr=region_screen_of(reg);
63     
64     if(scr==NULL){
65         scr=rootwin_current_scr(region_rootwin_of(reg));
66         if(scr==NULL)
67             return FALSE;
68     }
69     
70     return region_fullscreen_scr(reg, scr, switchto);
71 }
72
73
74 bool region_leave_fullscreen(WRegion *reg, bool switchto)
75 {
76     int swf=(switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
77     WPHolder *ph=region_unset_get_return(reg);
78     
79     if(ph==NULL)
80         return FALSE;
81     
82     if(!pholder_attach_mcfgoto(ph, swf, reg)){
83         warn(TR("Failed to return from full screen mode; remaining manager "
84                 "or parent from previous location refused to manage us."));
85         return FALSE;
86     }
87     
88     destroy_obj((Obj*)ph);
89     
90     return TRUE;
91 }
92
93
94 /*#undef REGION_IS_FULLSCREEN
95 #define REGION_IS_FULLSCREEN(REG) (region_get_return((WRegion*)REG)!=NULL)*/
96
97
98 static bool region_set_fullscreen(WRegion *reg, int sp)
99 {
100     bool set=REGION_IS_FULLSCREEN(reg);
101     bool nset=libtu_do_setparam(sp, set);
102     
103     if(!XOR(nset, set))
104         return set;
105
106     if(nset)
107         region_enter_fullscreen(reg, TRUE);
108     else
109         region_leave_fullscreen(reg, TRUE);
110     
111     return REGION_IS_FULLSCREEN(reg);
112 }
113
114
115 /*}}}*/
116
117
118 /*{{{ Client window requests */
119
120
121 bool clientwin_fullscreen_may_switchto(WClientWin *cwin)
122 {
123     return (region_may_control_focus((WRegion*)cwin)
124             || !REGION_IS_ACTIVE(region_screen_of((WRegion*)cwin)));
125 }
126
127
128 bool clientwin_check_fullscreen_request(WClientWin *cwin, int w, int h,
129                                         bool sw)
130 {
131     WScreen *scr;
132     WMwmHints *mwm;
133     WRectangle *rwgeom;
134     
135     mwm=xwindow_get_mwmhints(cwin->win);
136     if(mwm==NULL || !(mwm->flags&MWM_HINTS_DECORATIONS) ||
137        mwm->decorations!=0)
138         return FALSE;
139     
140     FOR_ALL_SCREENS(scr){
141         if(!region_same_rootwin((WRegion*)scr, (WRegion*)cwin))
142             continue;
143         /* Only Mplayer supports single Xinerama region FS to my knowledge, 
144          * and doesn't set position, so we also don't check position here, 
145          * and instead take the first screen with matching size.
146          */
147         if(REGION_GEOM(scr).w==w && REGION_GEOM(scr).h==h){
148             cwin->flags|=CLIENTWIN_FS_RQ;
149             if(!region_fullscreen_scr((WRegion*)cwin, (WScreen*)scr, sw)){
150                 cwin->flags&=~CLIENTWIN_FS_RQ;
151                 return FALSE;
152             }
153             return TRUE;
154         }
155     }
156     
157     return FALSE;
158 }
159
160
161 /*}}}*/
162
163
164 /*{{{ Group exports */
165
166
167 /*EXTL_DOC
168  * Set client window \var{reg} full screen state according to the 
169  * parameter \var{how} (set/unset/toggle). Resulting state is returned,
170  * which may not be what was requested.
171  */
172 EXTL_EXPORT_AS(WGroup, set_fullscreen)
173 bool group_set_fullscreen_extl(WGroup *grp, const char *how)
174 {
175     return region_set_fullscreen((WRegion*)grp, libtu_string_to_setparam(how));
176 }
177
178
179 /*EXTL_DOC
180  * Is \var{reg} in full screen mode?
181  */
182 EXTL_SAFE
183 EXTL_EXPORT_MEMBER
184 bool group_is_fullscreen(WGroup *grp)
185 {
186     return REGION_IS_FULLSCREEN(grp);
187 }
188
189
190 /*}}}*/
191