4 * Copyright (c) Tuomo Valkonen 1999-2006.
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.
12 #include <libtu/objp.h>
13 #include <libextl/extl.h>
19 #include "fullscreen.h"
28 WScreen *clientwin_find_suitable_screen(WClientWin *cwin,
29 const WManageParams *param)
31 WScreen *scr=NULL, *found=NULL;
32 bool respectpos=(param->tfor!=NULL || param->userpos);
35 if(!region_same_rootwin((WRegion*)scr, (WRegion*)cwin))
37 if(REGION_IS_ACTIVE(scr)){
43 if(rectangle_contains(®ION_GEOM(scr), param->geom.x, param->geom.y)){
57 bool clientwin_do_manage_default(WClientWin *cwin,
58 const WManageParams *param)
67 /* Check if param->tfor or any of its managers want to manage cwin. */
68 if(param->tfor!=NULL){
69 assert(param->tfor!=cwin);
70 ph=region_prepare_manage_transient((WRegion*)param->tfor, cwin,
74 /* Find a suitable screen */
75 scr=clientwin_find_suitable_screen(cwin, param);
77 warn(TR("Unable to find a screen for a new client window."));
82 /* Find a placeholder for non-fullscreen state */
83 ph=region_prepare_manage((WRegion*)scr, cwin, param,
84 MANAGE_REDIR_PREFER_YES);
87 /* Check fullscreen mode */
88 if(extl_table_gets_b(cwin->proptab, "fullscreen", &tmp))
92 fs=netwm_check_initial_fullscreen(cwin, param->switchto);
95 fs=clientwin_check_fullscreen_request(cwin,
102 /* Full-screen mode succesfull. */
103 if(pholder_target(ph)==(WRegion*)scr){
104 /* Discard useless placeholder. */
105 destroy_obj((Obj*)ph);
108 assert(cwin->fs_pholder==NULL);
116 /* Not in full-screen mode; use the placeholder to attach. */
118 swf=(param->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
119 ok=pholder_attach(ph, swf, (WRegion*)cwin);
120 destroy_obj((Obj*)ph);
129 /*{{{ region_prepare_manage/region_manage_clientwin/etc. */
132 WPHolder *region_prepare_manage(WRegion *reg, const WClientWin *cwin,
133 const WManageParams *param, int redir)
136 CALL_DYN_RET(ret, WPHolder*, region_prepare_manage, reg,
137 (reg, cwin, param, redir));
142 WPHolder *region_prepare_manage_default(WRegion *reg, const WClientWin *cwin,
143 const WManageParams *param, int redir)
147 if(redir==MANAGE_REDIR_STRICT_NO)
150 curr=region_current(reg);
155 return region_prepare_manage(curr, cwin, param, MANAGE_REDIR_PREFER_YES);
159 WPHolder *region_prepare_manage_transient(WRegion *reg,
160 const WClientWin *cwin,
161 const WManageParams *param,
165 CALL_DYN_RET(ret, WPHolder*, region_prepare_manage_transient, reg,
166 (reg, cwin, param, unused));
171 WPHolder *region_prepare_manage_transient_default(WRegion *reg,
172 const WClientWin *cwin,
173 const WManageParams *param,
176 WRegion *mgr=REGION_MANAGER(reg);
179 return region_prepare_manage_transient(mgr, cwin, param, unused);
185 bool region_manage_clientwin(WRegion *reg, WClientWin *cwin,
186 const WManageParams *par, int redir)
189 WPHolder *ph=region_prepare_manage(reg, cwin, par, redir);
190 int swf=(par->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
195 ret=pholder_attach(ph, swf, (WRegion*)cwin);
197 destroy_obj((Obj*)ph);
209 static WRegion *iter_children(void *st)
211 WRegion **nextp=(WRegion**)st;
212 WRegion *next=*nextp;
213 *nextp=(next==NULL ? NULL : next->p_next);
218 bool region_rescue_child_clientwins(WRegion *reg, WPHolder *ph)
220 WRegion *next=reg->children;
221 return region_rescue_some_clientwins(reg, ph, iter_children, &next);
225 bool region_rescue_some_clientwins(WRegion *reg, WPHolder *ph,
226 WRegionIterator *iter, void *st)
231 reg->flags|=REGION_CWINS_BEING_RESCUED;
234 WRegion *tosave=iter(st);
239 if(!OBJ_IS(tosave, WClientWin)){
240 if(!region_rescue_clientwins(tosave, ph))
243 if(!pholder_attach(ph, 0, tosave))
248 reg->flags&=~REGION_CWINS_BEING_RESCUED;
254 bool region_rescue_clientwins(WRegion *reg, WPHolder *ph)
257 CALL_DYN_RET(ret, bool, region_rescue_clientwins, reg, (reg, ph));
268 ExtlTab manageparams_to_table(const WManageParams *mp)
270 ExtlTab t=extl_create_table();
271 extl_table_sets_b(t, "switchto", mp->switchto);
272 extl_table_sets_b(t, "jumpto", mp->jumpto);
273 extl_table_sets_b(t, "userpos", mp->userpos);
274 extl_table_sets_b(t, "dockapp", mp->dockapp);
275 extl_table_sets_b(t, "maprq", mp->maprq);
276 extl_table_sets_i(t, "gravity", mp->gravity);
277 extl_table_sets_rectangle(t, "geom", &(mp->geom));
278 extl_table_sets_o(t, "tfor", (Obj*)(mp->tfor));