X-Git-Url: https://git.decadent.org.uk/gitweb/?p=ion3.git;a=blobdiff_plain;f=ioncore%2Fframe-draw.c;h=fbe58061bafed48a608e1407bbaf4a1aeeda6e52;hp=116f10cff63759050ff4e1e55cdcd1d24c3f68ee;hb=e3aec18706513a87eaa7839dfdaf7e0fcd0d8d2a;hpb=8366314611bf30a0f31d25bf5f5023186fa87692 diff --git a/ioncore/frame-draw.c b/ioncore/frame-draw.c index 116f10c..fbe5806 100644 --- a/ioncore/frame-draw.c +++ b/ioncore/frame-draw.c @@ -1,12 +1,9 @@ /* * ion/ioncore/frame-draw.c * - * Copyright (c) Tuomo Valkonen 1999-2006. + * Copyright (c) Tuomo Valkonen 1999-2009. * - * Ion is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. + * See the included file LICENSE for details. */ #include @@ -20,8 +17,10 @@ #include "framep.h" #include "frame-draw.h" #include "strings.h" +#include "activity.h" #include "names.h" #include "gr.h" +#include "gr-util.h" #define BAR_INSIDE_BORDER(FRAME) \ @@ -30,6 +29,68 @@ #define BAR_H(FRAME) (FRAME)->bar_h +/*{{{ Attributes */ + + +GR_DEFATTR(active); +GR_DEFATTR(inactive); +GR_DEFATTR(selected); +GR_DEFATTR(unselected); +GR_DEFATTR(tagged); +GR_DEFATTR(not_tagged); +GR_DEFATTR(dragged); +GR_DEFATTR(not_dragged); +GR_DEFATTR(activity); +GR_DEFATTR(no_activity); + + +static void ensure_create_attrs() +{ + GR_ALLOCATTR_BEGIN; + GR_ALLOCATTR(active); + GR_ALLOCATTR(inactive); + GR_ALLOCATTR(selected); + GR_ALLOCATTR(unselected); + GR_ALLOCATTR(tagged); + GR_ALLOCATTR(not_tagged); + GR_ALLOCATTR(dragged); + GR_ALLOCATTR(not_dragged); + GR_ALLOCATTR(no_activity); + GR_ALLOCATTR(activity); + GR_ALLOCATTR_END; +} + + +void frame_update_attr(WFrame *frame, int i, WRegion *reg) +{ + GrStyleSpec *spec; + bool selected, tagged, dragged, activity; + + if(i>=frame->titles_n){ + /* Might happen when deinitialising */ + return; + } + + ensure_create_attrs(); + + spec=&frame->titles[i].attr; + + selected=(reg==FRAME_CURRENT(frame)); + tagged=(reg!=NULL && reg->flags®ION_TAGGED); + dragged=(i==frame->tab_dragged_idx); + activity=(reg!=NULL && region_is_activity_r(reg)); + + gr_stylespec_unalloc(spec); + gr_stylespec_set(spec, selected ? GR_ATTR(selected) : GR_ATTR(unselected)); + gr_stylespec_set(spec, tagged ? GR_ATTR(tagged) : GR_ATTR(not_tagged)); + gr_stylespec_set(spec, dragged ? GR_ATTR(dragged) : GR_ATTR(not_dragged)); + gr_stylespec_set(spec, activity ? GR_ATTR(activity) : GR_ATTR(no_activity)); +} + + +/*}}}*/ + + /*{{{ (WFrame) dynfun default implementations */ @@ -82,7 +143,7 @@ void frame_bar_geom(const WFrame *frame, WRectangle *geom) uint off; if(BAR_INSIDE_BORDER(frame)){ - off=get_spacing(frame); + off=0; /*get_spacing(frame);*/ frame_border_inner_geom(frame, geom); }else{ off=0; @@ -105,10 +166,12 @@ void frame_managed_geom(const WFrame *frame, WRectangle *geom) frame_border_inner_geom(frame, geom); + /* geom->x+=spacing; geom->y+=spacing; geom->w-=2*spacing; geom->h-=2*spacing; + */ if(BAR_INSIDE_BORDER(frame) && BAR_EXISTS(frame)){ geom->y+=frame->bar_h+spacing; @@ -120,6 +183,22 @@ void frame_managed_geom(const WFrame *frame, WRectangle *geom) } +int frame_shaded_height(const WFrame *frame) +{ + if(frame->barmode==FRAME_BAR_NONE){ + return 0; + }else if(!BAR_INSIDE_BORDER(frame)){ + return frame->bar_h; + }else { + GrBorderWidths bdw; + + grbrush_get_border_widths(frame->brush, &bdw); + + return frame->bar_h+bdw.top+bdw.bottom; + } +} + + void frame_set_shape(WFrame *frame) { WRectangle gs[2]; @@ -147,7 +226,7 @@ void frame_clear_shape(WFrame *frame) #define CF_TAB_MAX_TEXT_X_OFF 10 -static void frame_shaped_recalc_bar_size(WFrame *frame) +static void frame_shaped_recalc_bar_size(WFrame *frame, bool complete) { int bar_w=0, textw=0, tmaxw=frame->tab_min_w, tmp=0; WLListIterTmp itmp; @@ -165,7 +244,7 @@ static void frame_shaped_recalc_bar_size(WFrame *frame) if(m>0){ grbrush_get_border_widths(frame->bar_brush, &bdw); - bdtotal=((m-1)*(bdw.tb_ileft+bdw.tb_iright) + bdtotal=((m-1)*(bdw.tb_ileft+bdw.tb_iright+bdw.spacing) +bdw.right+bdw.left); FRAME_MX_FOR_ALL(sub, frame, itmp){ @@ -201,7 +280,7 @@ static void frame_shaped_recalc_bar_size(WFrame *frame) bar_w=frame->bar_max_width_q*REGION_GEOM(frame).w; } - if(frame->bar_w!=bar_w){ + if(complete || frame->bar_w!=bar_w){ frame->bar_w=bar_w; frame_set_shape(frame); } @@ -223,7 +302,7 @@ static int init_title(WFrame *frame, int i) } -void frame_recalc_bar(WFrame *frame) +void frame_recalc_bar(WFrame *frame, bool complete) { int textw, i; WLListIterTmp tmp; @@ -234,14 +313,17 @@ void frame_recalc_bar(WFrame *frame) return; if(frame->barmode==FRAME_BAR_SHAPED) - frame_shaped_recalc_bar_size(frame); + frame_shaped_recalc_bar_size(frame, complete); + else if(complete) + frame_clear_shape(frame); i=0; if(FRAME_MCOUNT(frame)==0){ textw=init_title(frame, i); if(textw>0){ - title=grbrush_make_label(frame->bar_brush, CF_STR_EMPTY, textw); + title=grbrush_make_label(frame->bar_brush, TR(""), + textw); frame->titles[i].text=title; } return; @@ -250,18 +332,7 @@ void frame_recalc_bar(WFrame *frame) FRAME_MX_FOR_ALL(sub, frame, tmp){ textw=init_title(frame, i); if(textw>0){ - if(frame->flags&FRAME_SHOW_NUMBERS){ - char *s=NULL; - libtu_asprintf(&s, "[%d]", i+1); - if(s!=NULL){ - title=grbrush_make_label(frame->bar_brush, s, textw); - free(s); - }else{ - title=NULL; - } - }else{ - title=region_make_label(sub, textw, frame->bar_brush); - } + title=region_make_label(sub, textw, frame->bar_brush); frame->titles[i].text=title; } i++; @@ -272,8 +343,6 @@ void frame_recalc_bar(WFrame *frame) void frame_draw_bar(const WFrame *frame, bool complete) { WRectangle geom; - const char *cattr=(REGION_IS_ACTIVE(frame) - ? "active" : "inactive"); if(frame->bar_brush==NULL || !BAR_EXISTS(frame) @@ -285,27 +354,29 @@ void frame_draw_bar(const WFrame *frame, bool complete) grbrush_begin(frame->bar_brush, &geom, GRBRUSH_AMEND); + grbrush_init_attr(frame->bar_brush, &frame->baseattr); + grbrush_draw_textboxes(frame->bar_brush, &geom, frame->titles_n, - frame->titles, complete, cattr); + frame->titles, complete); grbrush_end(frame->bar_brush); } - void frame_draw(const WFrame *frame, bool complete) { WRectangle geom; - const char *attr=(REGION_IS_ACTIVE(frame) - ? "active" : "inactive"); if(frame->brush==NULL) return; - + frame_border_geom(frame, &geom); grbrush_begin(frame->brush, &geom, (complete ? 0 : GRBRUSH_NO_CLEAR_OK)); - grbrush_draw_border(frame->brush, &geom, attr); + grbrush_init_attr(frame->brush, &frame->baseattr); + + grbrush_draw_border(frame->brush, &geom); + frame_draw_bar(frame, TRUE); grbrush_end(frame->brush); @@ -314,19 +385,21 @@ void frame_draw(const WFrame *frame, bool complete) void frame_brushes_updated(WFrame *frame) { - WFrameBarMode barmode=FRAME_BAR_INSIDE; + WFrameBarMode barmode; ExtlTab tab; char *s; if(frame->brush==NULL) return; - if(frame->mode==FRAME_MODE_FLOATING) + if(frame->mode==FRAME_MODE_FLOATING){ barmode=FRAME_BAR_SHAPED; - else if(frame->mode==FRAME_MODE_TRANSIENT) - barmode=FRAME_BAR_NONE; - else if(frame->mode==FRAME_MODE_TILED_ALT) + }else if(frame->mode==FRAME_MODE_TILED || frame->mode==FRAME_MODE_UNKNOWN || + frame->mode==FRAME_MODE_TRANSIENT_ALT){ + barmode=FRAME_BAR_INSIDE; + }else{ barmode=FRAME_BAR_NONE; + } if(grbrush_get_extra(frame->brush, "bar", 's', &s)){ if(strcmp(s, "inside")==0) @@ -388,16 +461,20 @@ void frame_updategr(WFrame *frame) region_updategr_default((WRegion*)frame); mplex_fit_managed(&frame->mplex); - frame_recalc_bar(frame); + frame_recalc_bar(frame, TRUE); frame_set_background(frame, TRUE); } -StringIntMap frame_tab_styles[]={ +static StringIntMap frame_tab_styles[]={ + {"tab-frame-unknown", FRAME_MODE_UNKNOWN}, + {"tab-frame-unknown-alt", FRAME_MODE_UNKNOWN_ALT}, {"tab-frame-tiled", FRAME_MODE_TILED}, {"tab-frame-tiled-alt", FRAME_MODE_TILED_ALT}, {"tab-frame-floating", FRAME_MODE_FLOATING}, + {"tab-frame-floating-alt", FRAME_MODE_FLOATING_ALT}, {"tab-frame-transient", FRAME_MODE_TRANSIENT}, + {"tab-frame-transient-alt", FRAME_MODE_TRANSIENT_ALT}, END_STRINGINTMAP }; @@ -478,4 +555,40 @@ bool frame_set_background(WFrame *frame, bool set_always) } +void frame_setup_dragwin_style(WFrame *frame, GrStyleSpec *spec, int tab) +{ + gr_stylespec_append(spec, &frame->baseattr); + gr_stylespec_append(spec, &frame->titles[tab].attr); +} + + /*}}}*/ + + +/*{{{ Activated/inactivated */ + + +void frame_inactivated(WFrame *frame) +{ + ensure_create_attrs(); + + gr_stylespec_set(&frame->baseattr, GR_ATTR(inactive)); + gr_stylespec_unset(&frame->baseattr, GR_ATTR(active)); + + window_draw((WWindow*)frame, FALSE); +} + + +void frame_activated(WFrame *frame) +{ + ensure_create_attrs(); + + gr_stylespec_set(&frame->baseattr, GR_ATTR(active)); + gr_stylespec_unset(&frame->baseattr, GR_ATTR(inactive)); + + window_draw((WWindow*)frame, FALSE); +} + + +/*}}}*/ +