]> git.decadent.org.uk Git - ion3.git/blob - ioncore/fullscreen.c
a49d4f5eee31372dfdb2d27d2bc329ada5b297bc
[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.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 WScreen *clientwin_fullscreen_chkrq(WClientWin *cwin, int w, int h)
129 {
130     WScreen *scr;
131     WMwmHints *mwm;
132     WRectangle *rwgeom;
133     
134     mwm=xwindow_get_mwmhints(cwin->win);
135     if(mwm==NULL || !(mwm->flags&MWM_HINTS_DECORATIONS) ||
136        mwm->decorations!=0)
137         return NULL;
138     
139     FOR_ALL_SCREENS(scr){
140         if(!region_same_rootwin((WRegion*)scr, (WRegion*)cwin))
141             continue;
142         /* Only Mplayer supports single Xinerama region FS to my knowledge, 
143          * and doesn't set position, so we also don't check position here, 
144          * and instead take the first screen with matching size.
145          */
146         if(REGION_GEOM(scr).w==w && REGION_GEOM(scr).h==h)
147             return scr;
148     }
149     
150     return NULL;
151 }
152
153
154 /*}}}*/
155
156
157 /*{{{ Group exports */
158
159
160 /*EXTL_DOC
161  * Set client window \var{reg} full screen state according to the 
162  * parameter \var{how} (set/unset/toggle). Resulting state is returned,
163  * which may not be what was requested.
164  */
165 EXTL_EXPORT_AS(WGroup, set_fullscreen)
166 bool group_set_fullscreen_extl(WGroup *grp, const char *how)
167 {
168     return region_set_fullscreen((WRegion*)grp, libtu_string_to_setparam(how));
169 }
170
171
172 /*EXTL_DOC
173  * Is \var{reg} in full screen mode?
174  */
175 EXTL_SAFE
176 EXTL_EXPORT_MEMBER
177 bool group_is_fullscreen(WGroup *grp)
178 {
179     return REGION_IS_FULLSCREEN(grp);
180 }
181
182
183 /*}}}*/
184