Consistency fixes
[notion.git] / ioncore / fullscreen.c
blob811d373abed2263078249a5e49e417be12df59a9
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 swf=(switchto ? MPLEX_ATTACH_SWITCHTO : 0);
31 WPHolder *ph=NULL;
32 bool newph=FALSE, ret;
34 ph=region_unset_get_return(reg);
36 if(ph==NULL){
37 ph=region_make_return_pholder(reg);
38 newph=TRUE;
41 ret=(mplex_attach_simple((WMPlex*)scr, reg, swf)!=NULL);
43 if(!ret)
44 warn(TR("Failed to enter full screen mode."));
46 if(!ret && newph)
47 destroy_obj((Obj*)ph);
48 else if(!region_do_set_return(reg, ph))
49 destroy_obj((Obj*)ph);
51 return TRUE;
55 bool region_enter_fullscreen(WRegion *reg, bool switchto)
57 WScreen *scr=region_screen_of(reg);
59 if(scr==NULL){
60 scr=rootwin_current_scr(region_rootwin_of(reg));
61 if(scr==NULL)
62 return FALSE;
65 return region_fullscreen_scr(reg, scr, switchto);
69 bool region_leave_fullscreen(WRegion *reg, bool switchto)
71 int swf=(switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
72 WPHolder *ph=region_unset_get_return(reg);
74 if(ph==NULL)
75 return FALSE;
77 if(!pholder_attach_mcfgoto(ph, swf, reg)){
78 warn(TR("Failed to return from full screen mode; remaining manager "
79 "or parent from previous location refused to manage us."));
80 return FALSE;
83 destroy_obj((Obj*)ph);
85 return TRUE;
89 /*#undef REGION_IS_FULLSCREEN
90 #define REGION_IS_FULLSCREEN(REG) (region_get_return((WRegion*)REG)!=NULL)*/
93 static bool region_set_fullscreen(WRegion *reg, int sp)
95 bool set=REGION_IS_FULLSCREEN(reg);
96 bool nset=libtu_do_setparam(sp, set);
98 if(!XOR(nset, set))
99 return set;
101 if(nset)
102 region_enter_fullscreen(reg, TRUE);
103 else
104 region_leave_fullscreen(reg, TRUE);
106 return REGION_IS_FULLSCREEN(reg);
110 /*}}}*/
113 /*{{{ Client window requests */
116 bool clientwin_fullscreen_may_switchto(WClientWin *cwin)
118 return (region_may_control_focus((WRegion*)cwin)
119 || !REGION_IS_ACTIVE(region_screen_of((WRegion*)cwin)));
123 WScreen *clientwin_fullscreen_chkrq(WClientWin *cwin, int w, int h)
125 WScreen *scr;
126 WMwmHints *mwm;
128 mwm=xwindow_get_mwmhints(cwin->win);
129 if(mwm==NULL || !(mwm->flags&MWM_HINTS_DECORATIONS) ||
130 mwm->decorations!=0)
131 return NULL;
133 FOR_ALL_SCREENS(scr){
134 if(!region_same_rootwin((WRegion*)scr, (WRegion*)cwin))
135 continue;
136 /* Only Mplayer supports single Xinerama region FS to my knowledge,
137 * and doesn't set position, so we also don't check position here,
138 * and instead take the first screen with matching size.
140 if(REGION_GEOM(scr).w==w && REGION_GEOM(scr).h==h)
141 return scr;
144 return NULL;
148 /*}}}*/
151 /*{{{ Group exports */
154 /*EXTL_DOC
155 * Set client window \var{reg} full screen state according to the
156 * parameter \var{how} (one of \codestr{set}, \codestr{unset}, or
157 * \codestr{toggle}). Resulting state is returned, which may not be
158 * what was requested.
160 EXTL_EXPORT_AS(WGroup, set_fullscreen)
161 bool group_set_fullscreen_extl(WGroup *grp, const char *how)
163 return region_set_fullscreen((WRegion*)grp, libtu_string_to_setparam(how));
167 /*}}}*/