Browse Source

Use geo ptr in layout funcs and remove enums typedef

Martin Duquesnoy 12 years ago
parent
commit
1c69a0ec9c
5 changed files with 62 additions and 53 deletions
  1. 14 19
      src/client.c
  2. 9 10
      src/client.h
  3. 19 19
      src/layout.c
  4. 1 2
      src/util.h
  5. 19 3
      src/wmfs.h

+ 14 - 19
src/client.c

@@ -70,7 +70,7 @@ CLIENT_ACTION_LIST(swapsel, prev)
 /** Send a ConfigureRequest event to the struct client
  * \param c struct client pointer
 */
-void
+inline void
 client_configure(struct client *c)
 {
      XConfigureEvent ev =
@@ -118,27 +118,22 @@ client_gb_pos(struct tag *t, int x, int y)
      return NULL;
 }
 
-/** Get client left/right/top/bottom of selected client
-  *\param bc Base client
-  *\param pos Position
-  *\return Client found or NULL
-*/
+/*
+ * Get client left/right/top/bottom of selected client
+ */
 struct client*
-client_next_with_pos(struct client *bc, Position p)
+client_next_with_pos(struct client *bc, enum position p)
 {
      struct client *c;
-     int x, y;
      static const char scanfac[PositionLast] = { +10, -10, 0, 0 };
-     Position ip = Bottom - p;
+     enum position ip = Bottom - p;
+     int x = bc->geo.x + ((p == Right)  ? bc->geo.w : 0);
+     int y = bc->geo.y + ((p == Bottom) ? bc->geo.h : 0);
 
-     /*
-      * Set start place of pointer (edge with position
-      * of base client) for faster scanning.
-      */
-     x = bc->geo.x + ((p == Right)  ? bc->geo.w : 0);
-     y = bc->geo.y + ((p == Bottom) ? bc->geo.h : 0);
-     y += ((LDIR(p))  ? (bc->geo.h >> 1) : 0);
-     x += ((p > Left) ? (bc->geo.w >> 1) : 0);
+     if(p > Left)
+          x += bc->geo.w >> 1;
+     if(LDIR(p))
+          y += bc->geo.h >> 1;
 
      /* Scan in right direction to next(p) physical client */
      while((c = client_gb_pos(bc->tag, x, y)) == bc)
@@ -374,10 +369,10 @@ client_maximize(struct client *c)
 }
 
 void
-client_fac_resize(struct client *c, Position p, int fac)
+client_fac_resize(struct client *c, enum position p, int fac)
 {
      struct client *gc = client_next_with_pos(c, p);
-     Position rp = RPOS(p);
+     enum position rp = RPOS(p);
 
      if(!gc || gc->screen != c->screen)
           return;

+ 9 - 10
src/client.h

@@ -9,10 +9,10 @@
 #include "wmfs.h"
 #include "layout.h"
 
-void client_configure(struct client *c);
+inline void client_configure(struct client *c);
 struct client *client_gb_win(Window w);
 struct client *client_gb_pos(struct tag *t, int x, int y);
-struct client *client_next_with_pos(struct client *bc, Position p);
+struct client *client_next_with_pos(struct client *bc, enum position p);
 void client_swap(struct client *c1, struct client *c2);
 void client_focus(struct client *c);
 void client_get_name(struct client *c);
@@ -21,7 +21,7 @@ void uicb_client_close(Uicb cmd);
 struct client *client_new(Window w, XWindowAttributes *wa);
 void client_moveresize(struct client *c, struct geo g);
 void client_maximize(struct client *c);
-void client_fac_resize(struct client *c, Position p, int fac);
+void client_fac_resize(struct client *c, enum position p, int fac);
 void client_remove(struct client *c);
 void client_free(void);
 
@@ -54,17 +54,16 @@ client_next(struct client *c)
 static inline struct client*
 client_prev(struct client *c)
 {
-     struct client *cc;
+     struct client *cc = SLIST_FIRST(&c->tag->clients);
 
-     for(cc = SLIST_FIRST(&c->tag->clients);
-         SLIST_NEXT(cc, tnext) && SLIST_NEXT(cc, tnext) != c;
-         cc = SLIST_NEXT(cc, tnext));
+     while(SLIST_NEXT(cc, tnext) && SLIST_NEXT(cc, tnext) != c)
+          cc = SLIST_NEXT(cc, tnext);
 
      return cc;
 }
 
 static inline bool
-client_fac_geo(struct client *c, Position p, int fac)
+client_fac_geo(struct client *c, enum position p, int fac)
 {
      struct geo cg = c->geo;
 
@@ -99,7 +98,7 @@ client_fac_geo(struct client *c, Position p, int fac)
 }
 
 static inline bool
-client_fac_check_row(struct client *c, Position p, int fac)
+client_fac_check_row(struct client *c, enum position p, int fac)
 {
      struct geo g = c->geo;
      struct client *cc;
@@ -113,7 +112,7 @@ client_fac_check_row(struct client *c, Position p, int fac)
 }
 
 static inline void
-client_fac_arrange_row(struct client *c, Position p, int fac)
+client_fac_arrange_row(struct client *c, enum position p, int fac)
 {
      struct geo g = c->geo;
      struct client *cc;

+ 19 - 19
src/layout.c

@@ -40,28 +40,28 @@ layout_split(struct client *c, bool vertical)
 }
 
 static inline void
-layout_split_arrange_size(struct geo g, struct client *c, Position p)
+layout_split_arrange_size(struct geo *g, struct client *c, enum position p)
 {
      if(LDIR(p))
      {
-          c->geo.w += g.w;
+          c->geo.w += g->w;
 
           if(p == Right)
-               c->geo.x = g.x;
+               c->geo.x = g->x;
      }
      else
      {
-          c->geo.h += g.h;
+          c->geo.h += g->h;
 
           if(p == Bottom)
-               c->geo.y = g.y;
+               c->geo.y = g->y;
      }
 
      client_moveresize(c, c->geo);
 }
 
 static inline bool
-layout_split_check_row_dir(struct client *c, struct client *g, Position p)
+layout_split_check_row_dir(struct client *c, struct client *g, enum position p)
 {
      struct geo cgeo = c->geo;
      struct client *cc;
@@ -99,7 +99,7 @@ layout_split_arrange_closed(struct client *ghost)
      struct client *c, *cc;
      struct geo g;
      bool b = false;
-     Position p;
+     enum position p;
 
 
      /* Search for single parent for easy resize
@@ -115,7 +115,7 @@ layout_split_arrange_closed(struct client *ghost)
           if((c = client_next_with_pos(ghost, p)))
                if(GEO_CHECK2(ghost->geo, c->geo, p))
                {
-                    layout_split_arrange_size(ghost->geo, c, p);
+                    layout_split_arrange_size(&ghost->geo, c, p);
                     return;
                }
      }
@@ -138,7 +138,7 @@ layout_split_arrange_closed(struct client *ghost)
                     if(GEO_PARENTROW(g, cc->geo, RPOS(p))
                               && GEO_CHECK_ROW(cc->geo, ghost->geo, p))
                     {
-                         layout_split_arrange_size(ghost->geo, cc, p);
+                         layout_split_arrange_size(&ghost->geo, cc, p);
                          b = true;
                     }
           }
@@ -200,14 +200,14 @@ layout_fix_hole(struct client *c)
 /* Layout rotation: Rotate 90° all client to right or left.
  * Avoid if(left) condition in layout_rotate loop; use func ptr
  *
- * Left rotation
+ * Right rotation
  *  ____________        ____________
  * |    |   B   |  ->  |  |   A     |
  * |  A |_______|  ->  |__|_________|
  * |____| C | D |  ->  |_____|   B  |
  * |____|___|___|  ->  |_____|______|
  *
- * Right rotation
+ * Left rotation
  *  ____________        ____________
  * |    |   B   |  ->  |   B  |_____|
  * |  A |_______|  ->  |______|_____|
@@ -217,17 +217,17 @@ layout_fix_hole(struct client *c)
  */
 
 static inline void
-_pos_rotate_left(struct geo *g, struct geo ug, struct geo og)
+_pos_rotate_left(struct geo *g, struct geo *ug, struct geo *og)
 {
-     g->x = (ug.h - (og.y + og.h));
-     g->y = og.x;
+     g->x = (ug->h - (og->y + og->h));
+     g->y = og->x;
 }
 
 static inline void
-_pos_rotate_right(struct geo *g, struct geo ug, struct geo og)
+_pos_rotate_right(struct geo *g, struct geo *ug, struct geo *og)
 {
-     g->x = og.y;
-     g->y = (ug.w - (og.x + og.w));
+     g->x = og->y;
+     g->y = (ug->w - (og->x + og->w));
 }
 
 static void
@@ -237,12 +237,12 @@ layout_rotate(struct tag *t, bool left)
      struct geo g;
      float f1 = (float)t->screen->ugeo.w / (float)t->screen->ugeo.h;
      float f2 = 1 / f1;
-     void (*pos)(struct geo*, struct geo, struct geo) =
+     void (*pos)(struct geo*, struct geo*, struct geo*) =
           (left ? _pos_rotate_left : _pos_rotate_right);
 
      SLIST_FOREACH(c, &t->clients, tnext)
      {
-          pos(&g, t->screen->ugeo, c->geo);
+          pos(&g, &t->screen->ugeo, &c->geo);
 
           g.x *= f1;
           g.y *= f2;

+ 1 - 2
src/util.h

@@ -1,4 +1,4 @@
-/*
+;/*
  *  wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  *  For license, see COPYING.
  */
@@ -25,7 +25,6 @@
      X##t##Window(W->dpy, w);     \
 } while( /* CONSTCOND */ 0);
 
-
 #define ATOM(a)          XInternAtom(W->dpy, (a), False)
 #define LEN(x)           (sizeof(x) / sizeof(*x))
 #define FLAGINT(i)       (1 << i)

+ 19 - 3
src/wmfs.h

@@ -30,8 +30,24 @@
 typedef unsigned int Flags;
 typedef unsigned int Color;
 typedef const char* Uicb;
-typedef enum { BarTop = 0, BarBottom, BarHide, BarLast } Barpos;
-typedef enum { Right = 0, Left, Top, Bottom, Center, PositionLast } Position;
+
+enum barpos
+{
+     BarTop = 0,
+     BarBottom,
+     BarHide,
+     BarLast
+};
+
+enum position
+{
+     Right = 0,
+     Left,
+     Top,
+     Bottom,
+     Center,
+     PositionLast
+};
 
 /*
  * Structures
@@ -71,8 +87,8 @@ struct infobar
      struct geo geo;
      struct screen *screen;
      struct theme *theme;
+     enum barpos pos;
      char *elemorder;
-     Barpos pos;
      TAILQ_HEAD(esub, element) elements;
      SLIST_ENTRY(infobar) next;
 };