2 * ion/ioncore/screen-notify.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * See the included file LICENSE for details.
11 #include <libtu/minmax.h>
12 #include <libmainloop/defer.h>
24 #include "screen-notify.h"
28 /*{{{ Generic stuff */
31 static WInfoWin *do_get_notifywin(WScreen *scr, Watch *watch, uint pos,
35 WInfoWin *iw=(WInfoWin*)(watch->obj);
39 WMPlexAttachParams param=MPLEXATTACHPARAMS_INIT;
41 param.flags=(MPLEX_ATTACH_UNNUMBERED|
42 MPLEX_ATTACH_SIZEPOLICY|
45 param.level=STACKING_LEVEL_ON_TOP;
54 param.szplcy=SIZEPOLICY_GRAVITY_NORTHWEST;
59 param.szplcy=SIZEPOLICY_GRAVITY_NORTHEAST;
60 param.geom.x=REGION_GEOM(scr).w-1;
64 param.szplcy=SIZEPOLICY_GRAVITY_SOUTHWEST;
66 param.geom.y=REGION_GEOM(scr).h-1;
70 param.szplcy=SIZEPOLICY_GRAVITY_SOUTHEAST;
71 param.geom.x=REGION_GEOM(scr).w-1;
72 param.geom.y=REGION_GEOM(scr).h-1;
77 iw=(WInfoWin*)mplex_do_attach_new(&scr->mplex, ¶m,
78 (WRegionCreateFn*)create_infowin,
82 watch_setup(watch, (Obj*)iw, NULL);
89 static void do_unnotify(Watch *watch)
94 mainloop_defer_destroy((Obj*)iw);
105 static WInfoWin *get_notifywin(WScreen *scr)
107 WRegion *stdisp=NULL;
108 WMPlexSTDispInfo info;
109 uint pos=MPLEX_STDISP_TL;
111 mplex_get_stdisp(&scr->mplex, &stdisp, &info);
115 return do_get_notifywin(scr, &scr->notifywin_watch, pos, "actnotify");
119 void screen_notify(WScreen *scr, const char *str)
121 WInfoWin *iw=get_notifywin(scr);
124 int maxw=REGION_GEOM(scr).w/3;
125 infowin_set_text(iw, str, maxw);
130 void screen_unnotify(WScreen *scr)
132 do_unnotify(&scr->notifywin_watch);
136 static bool ws_mapped(WScreen *scr, WRegion *reg)
139 WRegion *mgr=REGION_MANAGER(reg);
144 if(mgr==(WRegion*)scr)
145 return REGION_IS_MAPPED(reg);
152 static void screen_managed_activity(WScreen *scr)
158 ObjList *actlist=ioncore_activity_list();
161 int nfound=0, nadded=0;
162 int w=0, maxw=REGION_GEOM(scr).w/4;
164 /* Lisäksi minimipituus (10ex tms.), ja sen yli menevät jätetään
167 FOR_ALL_ON_OBJLIST(WRegion*, reg, actlist, tmp){
168 if(region_screen_of(reg)!=scr || ws_mapped(scr, reg))
170 if(region_name(reg)==NULL)
172 if(ptrlist_insert_last(&found, reg))
179 iw=get_notifywin(scr);
187 notstr=scopy(TR("act: "));
192 FOR_ALL_ON_PTRLIST(WRegion*, reg, found, tmp2){
193 const char *nm=region_name(reg);
194 char *nstr=NULL, *label=NULL;
196 w=grbrush_get_text_width(iw->brush, notstr, strlen(notstr));
201 label=grbrush_make_label(iw->brush, nm, maxw-w);
204 ? scat3(notstr, ", ", label)
205 : scat(notstr, label));
219 libtu_asprintf(&nstr, "%s +%d", notstr, nfound-nadded);
227 ptrlist_clear(&found);
229 infowin_set_text(iw, notstr, 0);
236 screen_unnotify(scr);
240 static void screen_do_update_notifywin(WScreen *scr)
242 if(ioncore_g.screen_notify)
243 screen_managed_activity(scr);
245 screen_unnotify(scr);
255 static WInfoWin *get_infowin(WScreen *scr)
257 WRegion *stdisp=NULL;
258 WMPlexSTDispInfo info;
259 uint pos=MPLEX_STDISP_TR;
261 mplex_get_stdisp(&scr->mplex, &stdisp, &info);
262 if(stdisp!=NULL && info.pos==MPLEX_STDISP_TR)
265 return do_get_notifywin(scr, &scr->infowin_watch, pos, "tab-info");
269 void screen_windowinfo(WScreen *scr, const char *str)
271 WInfoWin *iw=get_infowin(scr);
274 int maxw=REGION_GEOM(scr).w/3;
275 infowin_set_text(iw, str, maxw);
280 void screen_nowindowinfo(WScreen *scr)
282 do_unnotify(&scr->infowin_watch);
287 GR_DEFATTR(inactive);
288 GR_DEFATTR(selected);
290 GR_DEFATTR(not_tagged);
291 GR_DEFATTR(not_dragged);
292 GR_DEFATTR(activity);
293 GR_DEFATTR(no_activity);
296 static void init_attr()
299 GR_ALLOCATTR(active);
300 GR_ALLOCATTR(inactive);
301 GR_ALLOCATTR(selected);
302 GR_ALLOCATTR(tagged);
303 GR_ALLOCATTR(not_tagged);
304 GR_ALLOCATTR(not_dragged);
305 GR_ALLOCATTR(no_activity);
306 GR_ALLOCATTR(activity);
311 static void screen_do_update_infowin(WScreen *scr)
313 WRegion *reg=mplex_mx_current(&(scr->mplex));
314 bool tag=(reg!=NULL && region_is_tagged(reg));
315 bool act=(reg!=NULL && region_is_activity_r(reg) && !REGION_IS_ACTIVE(scr));
316 bool sac=REGION_IS_ACTIVE(scr);
319 const char *n=region_displayname(reg);
322 screen_windowinfo(scr, n);
324 iw=(WInfoWin*)scr->infowin_watch.obj;
327 GrStyleSpec *spec=infowin_stylespec(iw);
331 gr_stylespec_unalloc(spec);
333 gr_stylespec_set(spec, GR_ATTR(selected));
334 gr_stylespec_set(spec, GR_ATTR(not_dragged));
335 gr_stylespec_set(spec, sac ? GR_ATTR(active) : GR_ATTR(inactive));
336 gr_stylespec_set(spec, tag ? GR_ATTR(tagged) : GR_ATTR(not_tagged));
337 gr_stylespec_set(spec, act ? GR_ATTR(activity) : GR_ATTR(no_activity));
341 screen_nowindowinfo(scr);
350 /*{{{ Notification callbacks and deferred updates*/
353 void screen_update_infowin(WScreen *scr)
355 mainloop_defer_action((Obj*)scr,
356 (WDeferredAction*)screen_do_update_infowin);
360 void screen_update_notifywin(WScreen *scr)
362 mainloop_defer_action((Obj*)scr,
363 (WDeferredAction*)screen_do_update_notifywin);
367 void screen_managed_notify(WScreen *scr, WRegion *reg, WRegionNotify how)
369 if(how==ioncore_g.notifies.tag)
370 screen_update_infowin(scr);
374 void ioncore_screen_activity_notify(WRegion *reg, WRegionNotify how)
376 if(how==ioncore_g.notifies.activity){
377 screen_update_notifywin(region_screen_of(reg));
378 }else if(how==ioncore_g.notifies.name){
379 if(region_is_activity(reg))
380 screen_update_notifywin(region_screen_of(reg));