4 * Copyright (c) Tuomo Valkonen 1999-2008.
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);
190 /* Find a suitable screen */
191 scr=clientwin_find_suitable_screen(cwin, param);
193 warn(TR("Unable to find a screen for a new client window."));
197 if(handle_target_winprops(cwin, param, scr, &ph))
200 /* Check if param->tfor or any of its managers want to manage cwin. */
201 if(ph==NULL && param->tfor!=NULL){
202 assert(param->tfor!=cwin);
203 ph=region_prepare_manage_transient((WRegion*)param->tfor, cwin,
209 /* Find a placeholder for non-fullscreen state */
210 ph=region_prepare_manage((WRegion*)scr, cwin, param,
211 MANAGE_PRIORITY_NONE);
213 if(try_fullscreen(cwin, scr, param)){
214 if(pholder_target(ph)!=(WRegion*)region_screen_of((WRegion*)cwin)){
215 WRegion *grp=region_groupleader_of((WRegion*)cwin);
216 if(region_do_set_return(grp, ph))
219 destroy_obj((Obj*)ph);
228 /* Not in full-screen mode; use the placeholder to attach. */
230 ok=pholder_attach(ph, swf, (WRegion*)cwin);
232 destroy_obj((Obj*)ph);
235 ioncore_unsqueeze((WRegion*)cwin, FALSE);
244 /*{{{ region_prepare_manage/region_manage_clientwin/etc. */
247 WPHolder *region_prepare_manage(WRegion *reg, const WClientWin *cwin,
248 const WManageParams *param, int priority)
251 CALL_DYN_RET(ret, WPHolder*, region_prepare_manage, reg,
252 (reg, cwin, param, priority));
257 WPHolder *region_prepare_manage_default(WRegion *reg, const WClientWin *cwin,
258 const WManageParams *param, int priority)
260 int cpriority=MANAGE_PRIORITY_SUB(priority, MANAGE_PRIORITY_NONE);
261 WRegion *curr=region_current(reg);
266 return region_prepare_manage(curr, cwin, param, cpriority);
270 WPHolder *region_prepare_manage_transient(WRegion *reg,
271 const WClientWin *cwin,
272 const WManageParams *param,
276 CALL_DYN_RET(ret, WPHolder*, region_prepare_manage_transient, reg,
277 (reg, cwin, param, unused));
282 WPHolder *region_prepare_manage_transient_default(WRegion *reg,
283 const WClientWin *cwin,
284 const WManageParams *param,
287 WRegion *mgr=REGION_MANAGER(reg);
290 return region_prepare_manage_transient(mgr, cwin, param, unused);
296 bool region_manage_clientwin(WRegion *reg, WClientWin *cwin,
297 const WManageParams *par, int priority)
300 WPHolder *ph=region_prepare_manage(reg, cwin, par, priority);
301 int swf=(par->switchto ? PHOLDER_ATTACH_SWITCHTO : 0);
306 ret=pholder_attach(ph, swf, (WRegion*)cwin);
308 destroy_obj((Obj*)ph);
320 DECLSTRUCT(WRescueInfo){
329 static WRegion *iter_children(void *st)
331 WRegion **nextp=(WRegion**)st;
332 WRegion *next=*nextp;
333 *nextp=(next==NULL ? NULL : next->p_next);
338 bool region_rescue_child_clientwins(WRegion *reg, WRescueInfo *info)
340 WRegion *next=reg->children;
341 return region_rescue_some_clientwins(reg, info, iter_children, &next);
345 WPHolder *rescueinfo_pholder(WRescueInfo *info)
351 info->ph=region_get_rescue_pholder(info->get_rescue);
353 info->failed_get=TRUE;
362 /* Bah, unsplitissä oikestaan pitäisi tehä non-deep rescue */
364 bool region_do_rescue_this(WRegion *tosave_, WRescueInfo *info, int ph_flags)
366 WClientWin *cwin=OBJ_CAST(tosave_, WClientWin);
367 WRegion *tosave=NULL;
370 if(cwin->flags&CLIENTWIN_UNMAP_RQ)
372 tosave=(WRegion*)cwin;
373 }else if(info->flags®ION_RESCUE_NODEEP){
376 /* Try to rescue whole groups. */
377 /*tosave=(WRegion*)OBJ_CAST(tosave_, WGroupCW);*/
381 return region_rescue_clientwins(tosave_, info);
383 int phf=(info->flags®ION_RESCUE_PHFLAGS_OK ? ph_flags : 0);
384 WPHolder *ph=rescueinfo_pholder(info);
388 : pholder_attach(info->ph, phf, tosave));
393 bool region_rescue_some_clientwins(WRegion *reg, WRescueInfo *info,
394 WRegionIterator *iter, void *st)
402 reg->flags|=REGION_CWINS_BEING_RESCUED;
405 WRegion *tosave=iter(st);
410 if(!region_do_rescue_this(tosave, info, 0)){
417 reg->flags&=~REGION_CWINS_BEING_RESCUED;
419 return (fails==0 && !info->failed_get);
423 bool region_rescue_clientwins(WRegion *reg, WRescueInfo *info)
426 CALL_DYN_RET(ret, bool, region_rescue_clientwins, reg, (reg, info));
431 bool region_rescue(WRegion *reg, WPHolder *ph, int flags)
440 info.failed_get=FALSE;
442 ret=region_rescue_clientwins(reg, &info);
445 destroy_obj((Obj*)info.ph);
451 bool region_rescue_needed(WRegion *reg)
459 info.failed_get=FALSE;
461 return !region_rescue_clientwins(reg, &info);
471 ExtlTab manageparams_to_table(const WManageParams *mp)
473 ExtlTab t=extl_create_table();
474 extl_table_sets_b(t, "switchto", mp->switchto);
475 extl_table_sets_b(t, "jumpto", mp->jumpto);
476 extl_table_sets_b(t, "userpos", mp->userpos);
477 extl_table_sets_b(t, "dockapp", mp->dockapp);
478 extl_table_sets_b(t, "maprq", mp->maprq);
479 extl_table_sets_i(t, "gravity", mp->gravity);
480 extl_table_sets_rectangle(t, "geom", &(mp->geom));
481 extl_table_sets_o(t, "tfor", (Obj*)(mp->tfor));