4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
9 #include <libtu/objp.h>
10 #include <libextl/extl.h>
16 #include "fullscreen.h"
29 WScreen *clientwin_find_suitable_screen(WClientWin *cwin,
30 const WManageParams *param)
32 WScreen *scr=NULL, *found=NULL;
33 bool respectpos=(param->tfor!=NULL || param->userpos);
36 if(!region_same_rootwin((WRegion*)scr, (WRegion*)cwin))
39 if(!OBJ_IS(scr, WRootWin)){
40 /* The root window itself is only a fallback */
42 if(REGION_IS_ACTIVE(scr)){
48 if(rectangle_contains(®ION_GEOM(scr),
49 param->geom.x, param->geom.y)){
64 /*extern WRegion *ioncore_newly_created;*/
67 static WPHolder *try_target(WClientWin *cwin, const WManageParams *param,
70 WRegion *r=ioncore_lookup_region(target, NULL);
75 if(!region_same_rootwin(r, (WRegion*)cwin))
78 return region_prepare_manage(r, cwin, param, MANAGE_PRIORITY_NONE);
82 static bool handle_target_winprops(WClientWin *cwin, const WManageParams *param,
83 WScreen *scr, WPHolder **ph_ret)
85 char *layout=NULL, *target=NULL;
89 if(extl_table_gets_s(cwin->proptab, "target", &target))
90 ph=try_target(cwin, param, target);
92 if(ph==NULL && extl_table_gets_s(cwin->proptab, "new_group", &layout)){
93 ExtlTab lo=ioncore_get_layout(layout);
97 if(lo!=extl_table_none()){
98 WMPlexAttachParams par=MPLEXATTACHPARAMS_INIT;
99 int mask=MPLEX_ATTACH_SWITCHTO;
103 par.flags|=MPLEX_ATTACH_SWITCHTO;
105 /*ioncore_newly_created=(WRegion*)cwin;*/
107 reg=mplex_attach_new_(&scr->mplex, &par, mask, lo);
109 extl_unref_table(lo);
111 /*ioncore_newly_created=NULL;*/
113 mgd=(region_manager((WRegion*)cwin)!=NULL);
115 if(reg!=NULL && !mgd){
117 ph=try_target(cwin, param, target);
120 ph=region_prepare_manage(reg, cwin, param,
121 MANAGE_PRIORITY_NONE);
124 destroy_obj((Obj*)reg);
139 static bool try_fullscreen(WClientWin *cwin, WScreen *dflt,
140 const WManageParams *param)
142 WScreen *fs_scr=NULL;
145 /* Check fullscreen mode. (This is intentionally not done
146 * for transients and windows with target winprops.)
148 if(extl_table_gets_b(cwin->proptab, "fullscreen", &tmp)){
155 fs_scr=netwm_check_initial_fullscreen(cwin);
158 fs_scr=clientwin_fullscreen_chkrq(cwin, param->geom.w, param->geom.h);
161 WPHolder *fs_ph=region_prepare_manage((WRegion*)fs_scr, cwin, param,
162 MANAGE_PRIORITY_NOREDIR);
165 int swf=(param->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
167 cwin->flags|=CLIENTWIN_FS_RQ;
169 fs=pholder_attach(fs_ph, swf, (WRegion*)cwin);
172 cwin->flags&=~CLIENTWIN_FS_RQ;
174 destroy_obj((Obj*)fs_ph);
182 bool clientwin_do_manage_default(WClientWin *cwin,
183 const WManageParams *param)
187 int swf=(param->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
189 WRegion *createroot=NULL;
191 /* Find a suitable screen */
192 scr=clientwin_find_suitable_screen(cwin, param);
194 warn(TR("Unable to find a screen for a new client window."));
198 if(handle_target_winprops(cwin, param, scr, &ph))
201 /* Check if param->tfor or any of its managers want to manage cwin. */
202 if(ph==NULL && param->tfor!=NULL){
203 assert(param->tfor!=cwin);
204 ph=region_prepare_manage_transient((WRegion*)param->tfor, cwin,
210 /* Find a placeholder for non-fullscreen state */
211 ph=region_prepare_manage((WRegion*)scr, cwin, param,
212 MANAGE_PRIORITY_NONE);
214 if(try_fullscreen(cwin, scr, param)){
215 if(pholder_target(ph)!=(WRegion*)region_screen_of((WRegion*)cwin)){
216 WRegion *grp=region_groupleader_of((WRegion*)cwin);
217 if(region_do_set_return(grp, ph))
220 destroy_obj((Obj*)ph);
229 /* Not in full-screen mode; use the placeholder to attach. */
231 WRegionAttachData data;
232 data.type=REGION_ATTACH_REPARENT;
233 data.u.reg=(WRegion*)cwin;
235 createroot=pholder_do_attach(ph,
236 swf|PHOLDER_ATTACH_RETURN_CREATEROOT,
240 destroy_obj((Obj*)ph);
242 if(uq && createroot!=NULL)
243 ioncore_unsqueeze(createroot, FALSE);
245 return (createroot!=NULL);
252 /*{{{ region_prepare_manage/region_manage_clientwin/etc. */
255 WPHolder *region_prepare_manage(WRegion *reg, const WClientWin *cwin,
256 const WManageParams *param, int priority)
259 CALL_DYN_RET(ret, WPHolder*, region_prepare_manage, reg,
260 (reg, cwin, param, priority));
265 WPHolder *region_prepare_manage_default(WRegion *reg, const WClientWin *cwin,
266 const WManageParams *param, int priority)
268 int cpriority=MANAGE_PRIORITY_SUB(priority, MANAGE_PRIORITY_NONE);
269 WRegion *curr=region_current(reg);
274 return region_prepare_manage(curr, cwin, param, cpriority);
278 WPHolder *region_prepare_manage_transient(WRegion *reg,
279 const WClientWin *cwin,
280 const WManageParams *param,
284 CALL_DYN_RET(ret, WPHolder*, region_prepare_manage_transient, reg,
285 (reg, cwin, param, unused));
290 WPHolder *region_prepare_manage_transient_default(WRegion *reg,
291 const WClientWin *cwin,
292 const WManageParams *param,
295 WRegion *mgr=REGION_MANAGER(reg);
298 return region_prepare_manage_transient(mgr, cwin, param, unused);
304 bool region_manage_clientwin(WRegion *reg, WClientWin *cwin,
305 const WManageParams *par, int priority)
308 WPHolder *ph=region_prepare_manage(reg, cwin, par, priority);
309 int swf=(par->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
314 ret=pholder_attach(ph, swf, (WRegion*)cwin);
316 destroy_obj((Obj*)ph);
328 DECLSTRUCT(WRescueInfo){
337 static WRegion *iter_children(void *st)
339 WRegion **nextp=(WRegion**)st;
340 WRegion *next=*nextp;
341 *nextp=(next==NULL ? NULL : next->p_next);
346 bool region_rescue_child_clientwins(WRegion *reg, WRescueInfo *info)
348 WRegion *next=reg->children;
349 return region_rescue_some_clientwins(reg, info, iter_children, &next);
353 WPHolder *rescueinfo_pholder(WRescueInfo *info)
359 info->ph=region_get_rescue_pholder(info->get_rescue);
361 info->failed_get=TRUE;
370 /* Bah, unsplitissä oikestaan pitäisi tehä non-deep rescue */
372 bool region_do_rescue_this(WRegion *tosave_, WRescueInfo *info, int ph_flags)
374 WClientWin *cwin=OBJ_CAST(tosave_, WClientWin);
375 WRegion *tosave=NULL;
378 if(cwin->flags&CLIENTWIN_UNMAP_RQ)
380 tosave=(WRegion*)cwin;
381 }else if(info->flags®ION_RESCUE_NODEEP){
384 /* Try to rescue whole groups. */
385 /*tosave=(WRegion*)OBJ_CAST(tosave_, WGroupCW);*/
389 return region_rescue_clientwins(tosave_, info);
391 int phf=(info->flags®ION_RESCUE_PHFLAGS_OK ? ph_flags : 0);
392 WPHolder *ph=rescueinfo_pholder(info);
396 : pholder_attach(info->ph, phf, tosave));
401 bool region_rescue_some_clientwins(WRegion *reg, WRescueInfo *info,
402 WRegionIterator *iter, void *st)
410 reg->flags|=REGION_CWINS_BEING_RESCUED;
413 WRegion *tosave=iter(st);
418 if(!region_do_rescue_this(tosave, info, 0)){
425 reg->flags&=~REGION_CWINS_BEING_RESCUED;
427 return (fails==0 && !info->failed_get);
431 bool region_rescue_clientwins(WRegion *reg, WRescueInfo *info)
434 CALL_DYN_RET(ret, bool, region_rescue_clientwins, reg, (reg, info));
439 bool region_rescue(WRegion *reg, WPHolder *ph, int flags)
448 info.failed_get=FALSE;
450 ret=region_rescue_clientwins(reg, &info);
453 destroy_obj((Obj*)info.ph);
459 bool region_rescue_needed(WRegion *reg)
467 info.failed_get=FALSE;
469 return !region_rescue_clientwins(reg, &info);
479 ExtlTab manageparams_to_table(const WManageParams *mp)
481 ExtlTab t=extl_create_table();
482 extl_table_sets_b(t, "switchto", mp->switchto);
483 extl_table_sets_b(t, "jumpto", mp->jumpto);
484 extl_table_sets_b(t, "userpos", mp->userpos);
485 extl_table_sets_b(t, "dockapp", mp->dockapp);
486 extl_table_sets_b(t, "maprq", mp->maprq);
487 extl_table_sets_i(t, "gravity", mp->gravity);
488 extl_table_sets_rectangle(t, "geom", &(mp->geom));
489 extl_table_sets_o(t, "tfor", (Obj*)(mp->tfor));