2 * ion/ioncore/screen-notify.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
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.
14 #include <libtu/minmax.h>
15 #include <libmainloop/defer.h>
27 #include "screen-notify.h"
31 /*{{{ Generic stuff */
34 static WInfoWin *do_get_notifywin(WScreen *scr, Watch *watch, uint pos,
38 WInfoWin *iw=(WInfoWin*)(watch->obj);
42 WMPlexAttachParams param=MPLEXATTACHPARAMS_INIT;
44 param.flags=(MPLEX_ATTACH_UNNUMBERED|
45 MPLEX_ATTACH_SIZEPOLICY|
48 param.level=STACKING_LEVEL_ON_TOP;
57 param.szplcy=SIZEPOLICY_GRAVITY_NORTHWEST;
62 param.szplcy=SIZEPOLICY_GRAVITY_NORTHEAST;
63 param.geom.x=REGION_GEOM(scr).w-1;
67 param.szplcy=SIZEPOLICY_GRAVITY_SOUTHWEST;
69 param.geom.y=REGION_GEOM(scr).h-1;
73 param.szplcy=SIZEPOLICY_GRAVITY_SOUTHEAST;
74 param.geom.x=REGION_GEOM(scr).w-1;
75 param.geom.y=REGION_GEOM(scr).h-1;
80 iw=(WInfoWin*)mplex_do_attach_new(&scr->mplex, ¶m,
81 (WRegionCreateFn*)create_infowin,
85 watch_setup(watch, (Obj*)iw, NULL);
92 static void do_unnotify(Watch *watch)
97 mainloop_defer_destroy((Obj*)iw);
108 static WInfoWin *get_notifywin(WScreen *scr)
110 WRegion *stdisp=NULL;
111 WMPlexSTDispInfo info;
112 uint pos=MPLEX_STDISP_TL;
114 mplex_get_stdisp(&scr->mplex, &stdisp, &info);
118 return do_get_notifywin(scr, &scr->notifywin_watch, pos, "actnotify");
122 void screen_notify(WScreen *scr, const char *str)
124 WInfoWin *iw=get_notifywin(scr);
127 int maxw=REGION_GEOM(scr).w/3;
128 infowin_set_text(iw, str, maxw);
133 void screen_unnotify(WScreen *scr)
135 do_unnotify(&scr->notifywin_watch);
139 static bool ws_mapped(WScreen *scr, WRegion *reg)
142 WRegion *mgr=REGION_MANAGER(reg);
147 if(mgr==(WRegion*)scr)
148 return REGION_IS_MAPPED(reg);
155 static void screen_managed_activity(WScreen *scr)
161 ObjList *actlist=ioncore_activity_list();
164 int nfound=0, nadded=0;
165 int w=0, maxw=REGION_GEOM(scr).w/4;
167 /* Lisäksi minimipituus (10ex tms.), ja sen yli menevät jätetään
170 FOR_ALL_ON_OBJLIST(WRegion*, reg, actlist, tmp){
171 if(region_screen_of(reg)!=scr || ws_mapped(scr, reg))
173 if(region_name(reg)==NULL)
175 if(ptrlist_insert_last(&found, reg))
182 iw=get_notifywin(scr);
190 notstr=scopy(TR("act: "));
195 FOR_ALL_ON_PTRLIST(WRegion*, reg, found, tmp2){
196 const char *nm=region_name(reg);
197 char *nstr=NULL, *label=NULL;
199 w=grbrush_get_text_width(iw->brush, notstr, strlen(notstr));
204 label=grbrush_make_label(iw->brush, nm, maxw-w);
207 ? scat3(notstr, ", ", label)
208 : scat(notstr, label));
222 libtu_asprintf(&nstr, "%s +%d", notstr, nfound-nadded);
230 ptrlist_clear(&found);
232 infowin_set_text(iw, notstr, 0);
239 screen_unnotify(scr);
243 static void screen_do_update_notifywin(WScreen *scr)
245 if(ioncore_g.screen_notify)
246 screen_managed_activity(scr);
248 screen_unnotify(scr);
258 static WInfoWin *get_infowin(WScreen *scr)
260 WRegion *stdisp=NULL;
261 WMPlexSTDispInfo info;
262 uint pos=MPLEX_STDISP_TR;
264 mplex_get_stdisp(&scr->mplex, &stdisp, &info);
265 if(stdisp!=NULL && info.pos==MPLEX_STDISP_TR)
268 return do_get_notifywin(scr, &scr->infowin_watch, pos, "tab-info");
272 void screen_windowinfo(WScreen *scr, const char *str)
274 WInfoWin *iw=get_infowin(scr);
277 int maxw=REGION_GEOM(scr).w/3;
278 infowin_set_text(iw, str, maxw);
283 void screen_nowindowinfo(WScreen *scr)
285 do_unnotify(&scr->infowin_watch);
290 GR_DEFATTR(inactive);
291 GR_DEFATTR(selected);
293 GR_DEFATTR(not_tagged);
294 GR_DEFATTR(not_dragged);
295 GR_DEFATTR(activity);
296 GR_DEFATTR(no_activity);
299 static void init_attr()
302 GR_ALLOCATTR(active);
303 GR_ALLOCATTR(inactive);
304 GR_ALLOCATTR(selected);
305 GR_ALLOCATTR(tagged);
306 GR_ALLOCATTR(not_tagged);
307 GR_ALLOCATTR(not_dragged);
308 GR_ALLOCATTR(no_activity);
309 GR_ALLOCATTR(activity);
314 static void screen_do_update_infowin(WScreen *scr)
316 WRegion *reg=mplex_mx_current(&(scr->mplex));
317 bool tag=(reg!=NULL && region_is_tagged(reg));
318 bool act=(reg!=NULL && region_is_activity_r(reg) && !REGION_IS_ACTIVE(scr));
319 bool sac=REGION_IS_ACTIVE(scr);
322 const char *n=region_displayname(reg);
325 screen_windowinfo(scr, n);
327 iw=(WInfoWin*)scr->infowin_watch.obj;
330 GrStyleSpec *spec=infowin_stylespec(iw);
334 gr_stylespec_unalloc(spec);
336 gr_stylespec_set(spec, GR_ATTR(selected));
337 gr_stylespec_set(spec, GR_ATTR(not_dragged));
338 gr_stylespec_set(spec, sac ? GR_ATTR(active) : GR_ATTR(inactive));
339 gr_stylespec_set(spec, tag ? GR_ATTR(tagged) : GR_ATTR(not_tagged));
340 gr_stylespec_set(spec, act ? GR_ATTR(activity) : GR_ATTR(no_activity));
344 screen_nowindowinfo(scr);
353 /*{{{ Notification callbacks and deferred updates*/
356 void screen_update_infowin(WScreen *scr)
358 mainloop_defer_action((Obj*)scr,
359 (WDeferredAction*)screen_do_update_infowin);
363 void screen_update_notifywin(WScreen *scr)
365 mainloop_defer_action((Obj*)scr,
366 (WDeferredAction*)screen_do_update_notifywin);
370 void screen_managed_notify(WScreen *scr, WRegion *reg, WRegionNotify how)
372 if(how==ioncore_g.notifies.tag)
373 screen_update_infowin(scr);
377 void ioncore_screen_activity_notify(WRegion *reg, WRegionNotify how)
379 if(how==ioncore_g.notifies.activity){
380 WScreen *scr=region_screen_of(reg);
382 screen_update_infowin(scr);
383 screen_update_notifywin(scr);