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