Browse Source

Infobar/Wmfs: Fix infobar_draw_statustext, remove useless screen_count()

Martin Duquesnoy 14 years ago
parent
commit
7acf0139d4
6 changed files with 40 additions and 30 deletions
  1. 5 3
      src/event.c
  2. 15 10
      src/ewmh.c
  3. 11 10
      src/infobar.c
  4. 4 3
      src/screen.c
  5. 0 1
      src/tag.c
  6. 5 3
      src/wmfs.c

+ 5 - 3
src/event.c

@@ -140,7 +140,7 @@ void
 clientmessageevent(XClientMessageEvent *ev)
 {
      Client *c;
-     int i, mess_t = 0;
+     int s, i, mess_t = 0;
      Atom rt;
      int rf;
      ulong ir, il;
@@ -151,7 +151,9 @@ clientmessageevent(XClientMessageEvent *ev)
      if(ev->format != 32)
           return;
 
-     for(i = 0; i < net_last + screen_count(); ++i)
+     s = screen_count();
+
+     for(i = 0; i < net_last + s; ++i)
           if(net_atom[i] == ev->message_type)
                mess_t = i;
 
@@ -166,7 +168,7 @@ clientmessageevent(XClientMessageEvent *ev)
           /* Manage _WMFS_SET_SCREEN */
           if(mess_t == wmfs_set_screen
              && ev->data.l[0] >= 0
-             && ev->data.l[0] <= screen_count())
+             && ev->data.l[0] <= s)
                screen_set_sel((int)(ev->data.l[0]));
 
           /* Manage _NET_ACTIVE_WINDOW */

+ 15 - 10
src/ewmh.c

@@ -42,12 +42,13 @@
 void
 ewmh_init_hints(void)
 {
-     int i = 1, j, showing_desk = 0;
+     int i = 1, s, j, showing_desk = 0;
      char root_name[] = WMFS_VERSION;
      char class[] = "wmfs", st[64];
      long pid = (long)getpid();
 
-     net_atom = emalloc(net_last + screen_count(), sizeof(Atom));
+     s = screen_count();
+     net_atom = emalloc(net_last + s, sizeof(Atom));
 
      /* EWMH hints */
      net_atom[net_supported]                  = ATOM("_NET_SUPPORTED");
@@ -93,14 +94,14 @@ ewmh_init_hints(void)
      net_atom[wmfs_cmd]                       = ATOM("_WMFS_CMD");
 
      /* Multi atom _WMFS_STATUSTEXT_<screennum> */
-     for(j = 0; j < screen_count(); ++j)
+     for(j = 0; j < s; ++j)
      {
           sprintf(st, "_WMFS_STATUSTEXT_%d", j);
           net_atom[wmfs_statustext + j] = ATOM(st);
      }
 
      XChangeProperty(dpy, ROOT, net_atom[net_supported], XA_ATOM, 32,
-                     PropModeReplace, (uchar*)net_atom, net_last + screen_count());
+                     PropModeReplace, (uchar*)net_atom, net_last + s);
 
      XChangeProperty(dpy, ROOT, net_atom[wmfs_running], XA_CARDINAL, 32,
                      PropModeReplace, (uchar*)&i, 1);
@@ -213,15 +214,17 @@ void
 ewmh_get_desktop_names(void)
 {
      char *str = NULL;
-     int s, i, len = 0, pos = 0;
+     int S, s, i, len = 0, pos = 0;
 
-     for(s = 0 ; s < screen_count(); ++s)
+     S = screen_count();
+
+     for(s = 0 ; s < S; ++s)
           for(i = 1; i < conf.ntag[s] + 1; ++i)
                len += strlen(tags[s][i].name);
 
      str = emalloc(len + i + 1, sizeof(char*));
 
-     for(s = 0; s < screen_count(); ++s)
+     for(s = 0; s < S; ++s)
           for(i = 1; i < conf.ntag[s] + 1; ++i, ++pos)
           {
                strncpy(str + pos, tags[s][i].name, strlen(tags[s][i].name));
@@ -264,14 +267,16 @@ void
 ewmh_set_workarea(void)
 {
      long *data;
-     int i, j, tag_c = 0, pos = 0;
+     int i, s, j, tag_c = 0, pos = 0;
 
-     for(i = 0; i < screen_count(); ++i)
+     s = screen_count();
+
+     for(i = 0; i < s; ++i)
           tag_c += conf.ntag[i];
 
      data = emalloc(tag_c * 4, sizeof(long));
 
-     for(i = 0; i < screen_count(); ++i)
+     for(i = 0; i < s; ++i)
           for(j = 0; j < conf.ntag[i]; ++j)
           {
                data[pos++] = spgeo[i].x;

+ 11 - 10
src/infobar.c

@@ -37,12 +37,14 @@
 void
 infobar_init(void)
 {
-     int sc, i, j;
+     int s, sc, i, j;
+
+     s = screen_count();
 
      if(!infobar)
-          infobar = emalloc(screen_count(), sizeof(InfoBar));
+          infobar = emalloc(s, sizeof(InfoBar));
 
-     for(sc = 0; sc < screen_count(); ++sc)
+     for(sc = 0; sc < s; ++sc)
      {
           j = 0;
           infobar[sc].geo.height = INFOBARH;
@@ -97,7 +99,7 @@ infobar_init(void)
           barwin_refresh(infobar[sc].bar);
 
           /* Default statustext is set here */
-          for(i = 0; i < screen_count(); ++i)
+          for(i = 0; i < s; ++i)
                infobar[i].statustext = _strdup(WMFS_VERSION);
           infobar_draw(sc);
      }
@@ -187,7 +189,7 @@ infobar_draw_statustext(int sc, char *str)
      lastst = infobar[sc].statustext;
 
      infobar[sc].statustext = _strdup(str);
-     strcpy(strwc, &str[sizeof(strwc)]);
+     strcpy(strwc, str);
 
      /* Count how many color block there is and make a string without color block (\#....\)*/
      for(i = j = c = 0;
@@ -220,16 +222,15 @@ infobar_draw_statustext(int sc, char *str)
                {
                     /* Store current color in col[] */
                     for(j = 0, ++i; str[i] != '\\'; col[j++] = str[i++]);
-                    strcpy(buf, &buf[k]);
 
                     /* Draw a rectangle with the bar color to draw the text properly */
-                    draw_rectangle(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - textw(buf),
-                                   0, INFOBARH - (sgeo[sc].width - SHADH) - textw(buf),
+                    draw_rectangle(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - textw(&buf[k]),
+                                   0, INFOBARH - (sgeo[sc].width - SHADH) - textw(&buf[k]),
                                    INFOBARH, conf.colors.bar);
 
                     /* Draw text with its color */
-                    draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - textw(buf),
-                              FHINFOBAR,  col, 0, buf);
+                    draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - textw(&buf[k]),
+                              FHINFOBAR,  col, 0, &buf[k]);
 
                     strcpy(buf, strwc);
                     ++i;

+ 4 - 3
src/screen.c

@@ -166,11 +166,12 @@ void
 screen_init_geo(void)
 {
      int i;
+     int s = screen_count();
 
-     sgeo = emalloc(screen_count(), sizeof(XRectangle));
-     spgeo = emalloc(screen_count(), sizeof(XRectangle));
+     sgeo = emalloc(s, sizeof(XRectangle));
+     spgeo = emalloc(s, sizeof(XRectangle));
 
-     for(i = 0; i < screen_count(); ++i)
+     for(i = 0; i < s; ++i)
           sgeo[i] = screen_get_geo(i);
 
      spgeo[0].x = 0;

+ 0 - 1
src/tag.c

@@ -28,7 +28,6 @@
 *      THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *      OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 */
 
 #include "wmfs.h"

+ 5 - 3
src/wmfs.c

@@ -210,11 +210,13 @@ scan(void)
      XWindowAttributes wa;
      Window usl, usl2, *w = NULL;
      Atom rt;
-     int rf, tag = -1, screen = -1, free = -1;
+     int s, rf, tag = -1, screen = -1, free = -1;
      ulong ir, il;
      uchar *ret;
      Client *c;
 
+     s = screen_count();
+
      if(XQueryTree(dpy, ROOT, &usl, &usl2, &w, &n))
           for(i = n - 1; i != -1; --i)
                if(XGetWindowAttributes(dpy, w[i], &wa)
@@ -246,7 +248,7 @@ scan(void)
 
                     if(tag != -1)
                          c->tag = tag;
-                    if(screen != -1 && screen <= screen_count() - 1)
+                    if(screen != -1 && screen <= s - 1)
                          c->screen = screen;
                     if(free != -1)
                          c->flags |= (free) ? FreeFlag : 0;
@@ -262,7 +264,7 @@ scan(void)
           tags[c->screen][c->tag].request_update = True;
      }
 
-     for(i = 0; i < screen_count(); ++i)
+     for(i = 0; i < s; ++i)
           arrange(i, True);
 
      XFree(w);