Better error message
[notion/jeffpc.git] / ioncore / fullscreen.c
blob04fc7eaf76d721472c82dce7d196d965b93ca0d2
1 /*
2 * ion/ioncore/fullscreen.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
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"
25 /*{{{ Generic full screen mode code */
28 bool region_fullscreen_scr(WRegion *reg, WScreen *scr, bool switchto)
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;
36 ph=region_unset_get_return(reg);
38 if(ph==NULL){
39 ph=region_make_return_pholder(reg);
40 newph=TRUE;
43 ret=(mplex_attach_simple((WMPlex*)scr, reg, swf)!=NULL);
45 if(!ret)
46 warn(TR("Failed to enter full screen mode."));
48 if(!ret && newph)
49 destroy_obj((Obj*)ph);
50 else if(!region_do_set_return(reg, ph))
51 destroy_obj((Obj*)ph);
53 return TRUE;
57 bool region_enter_fullscreen(WRegion *reg, bool switchto)
59 WScreen *scr=region_screen_of(reg);
61 if(scr==NULL){
62 scr=rootwin_current_scr(region_rootwin_of(reg));
63 if(scr==NULL)
64 return FALSE;
67 return region_fullscreen_scr(reg, scr, switchto);
71 bool region_leave_fullscreen(WRegion *reg, bool switchto)
73 int swf=(switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
74 WPHolder *ph=region_unset_get_return(reg);
76 if(ph==NULL)
77 return FALSE;
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;
85 destroy_obj((Obj*)ph);
87 return TRUE;
91 /*#undef REGION_IS_FULLSCREEN
92 #define REGION_IS_FULLSCREEN(REG) (region_get_return((WRegion*)REG)!=NULL)*/
95 static bool region_set_fullscreen(WRegion *reg, int sp)
97 bool set=REGION_IS_FULLSCREEN(reg);
98 bool nset=libtu_do_setparam(sp, set);
100 if(!XOR(nset, set))
101 return set;
103 if(nset)
104 region_enter_fullscreen(reg, TRUE);
105 else
106 region_leave_fullscreen(reg, TRUE);
108 return REGION_IS_FULLSCREEN(reg);
112 /*}}}*/
115 /*{{{ Client window requests */
118 bool clientwin_fullscreen_may_switchto(WClientWin *cwin)
120 return (region_may_control_focus((WRegion*)cwin)
121 || !REGION_IS_ACTIVE(region_screen_of((WRegion*)cwin)));
125 WScreen *clientwin_fullscreen_chkrq(WClientWin *cwin, int w, int h)
127 WScreen *scr;
128 WMwmHints *mwm;
129 WRectangle *rwgeom;
131 mwm=xwindow_get_mwmhints(cwin->win);
132 if(mwm==NULL || !(mwm->flags&MWM_HINTS_DECORATIONS) ||
133 mwm->decorations!=0)
134 return NULL;
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.
143 if(REGION_GEOM(scr).w==w && REGION_GEOM(scr).h==h)
144 return scr;
147 return NULL;
151 /*}}}*/
154 /*{{{ Group exports */
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.
163 EXTL_EXPORT_AS(WGroup, set_fullscreen)
164 bool group_set_fullscreen_extl(WGroup *grp, const char *how)
166 return region_set_fullscreen((WRegion*)grp, libtu_string_to_setparam(how));
170 /*}}}*/