Просмотр исходного кода

Use rect for border instead WindowBorder

Martin Duquesnoy 12 лет назад
Родитель
Сommit
389b0a9cc5
5 измененных файлов с 54 добавлено и 33 удалено
  1. 38 18
      wmfs2/src/client.c
  2. 2 1
      wmfs2/src/client.h
  3. 7 0
      wmfs2/src/draw.h
  4. 6 13
      wmfs2/src/layout.c
  5. 1 1
      wmfs2/src/wmfs.h

+ 38 - 18
wmfs2/src/client.c

@@ -11,6 +11,7 @@
 #include "barwin.h"
 #include "ewmh.h"
 #include "layout.h"
+#include "draw.h"
 
 #define CLIENT_MOUSE_MOD Mod1Mask
 
@@ -62,7 +63,7 @@ client_gb_win(Window w)
      return c;
 }
 
-static struct client*
+struct client*
 client_gb_pos(struct tag *t, int x, int y)
 {
      struct client *c;
@@ -141,25 +142,32 @@ client_grabbuttons(struct client *c, bool focused)
 
 }
 
+static inline void
+client_draw_bord(void)
+{
+     struct geo g = { 0, 0, W->screen->ugeo.w, W->screen->ugeo.h };
+
+     draw_rect(W->screen->seltag->frame, g, THEME_DEFAULT->client_n.bg);
+
+     /* Selected client's border */
+     if(W->client)
+          draw_rect(W->client->tag->frame, W->client->geo, THEME_DEFAULT->client_s.bg);
+}
+
+
 void
 client_focus(struct client *c)
 {
      /* Unfocus selected */
      if(W->client && W->client != c)
-     {
-          XSetWindowBorder(W->dpy, W->client->win, THEME_DEFAULT->client_n.bg);
-
           client_grabbuttons(W->client, false);
-     }
 
      /* Focus c */
      if((W->client = c))
      {
           c->tag->sel = c;
 
-          XSetWindowBorder(W->dpy, c->win, THEME_DEFAULT->client_s.bg);
-
-          XSetInputFocus(W->dpy, c->win, RevertToPointerRoot, CurrentTime);
+          client_draw_bord();
 
           client_grabbuttons(c, true);
      }
@@ -251,15 +259,14 @@ client_new(Window w, XWindowAttributes *wa)
      c->geo.y = wa->y;
      c->geo.w = wa->width;
      c->geo.h = wa->height;
-     c->tgeo = c->geo;
+     c->tgeo = c->wgeo = c->geo;
 
      /* Set tag */
      tag_client(W->screen->seltag, c);
 
      /* X window attributes */
      XSelectInput(W->dpy, w, EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PropertyChangeMask);
-     XSetWindowBorder(W->dpy, w, THEME_DEFAULT->client_n.bg);
-     XSetWindowBorderWidth(W->dpy, w, THEME_DEFAULT->client_border_width);
+     XSetWindowBorderWidth(W->dpy, w, 0);
      client_grabbuttons(c, false);
 
      /* Attach */
@@ -277,9 +284,21 @@ client_new(Window w, XWindowAttributes *wa)
 void
 client_moveresize(struct client *c, struct geo g)
 {
-     c->geo = g;
+     int bord = THEME_DEFAULT->client_border_width;
+
+     c->geo = c->wgeo = g;
+
+     /* Window geo */
+     c->wgeo.x += bord;
+     c->wgeo.y += bord ;
+     c->wgeo.w -= (bord << 1);
+     c->wgeo.h -= (bord << 1);
+
+     XMoveResizeWindow(W->dpy, c->win,
+                       c->wgeo.x, c->wgeo.y,
+                       c->wgeo.w, c->wgeo.h);
 
-     XMoveResizeWindow(W->dpy, c->win, g.x, g.y, g.w, g.h);
+     client_draw_bord();
 }
 
 void
@@ -288,8 +307,8 @@ client_maximize(struct client *c)
      c->geo = c->tag->screen->ugeo;
 
      c->geo.x = c->geo.y = 0; /* Frame x/y, not screen geo */
-     c->geo.w = c->tag->screen->ugeo.w - (THEME_DEFAULT->client_border_width << 1);
-     c->geo.h = c->tag->screen->ugeo.h - (THEME_DEFAULT->client_border_width << 1);
+     c->geo.w = c->tag->screen->ugeo.w;
+     c->geo.h = c->tag->screen->ugeo.h;
 
      client_moveresize(c, c->geo);
 }
@@ -298,15 +317,16 @@ void
 client_fac_resize(struct client *c, Position p, int fac)
 {
      struct client *gc = client_next_with_pos(c, p);
+     Position rp = RPOS(p);
 
      if(!gc || gc->screen != c->screen)
           return;
 
      /* Check futur size/pos */
      if(!client_fac_geo(c, p, fac)
-        || !client_fac_geo(gc, RPOS(p), -fac)
+        || !client_fac_geo(gc, rp, -fac)
         || !client_fac_check_row(c, p, fac)
-        || !client_fac_check_row(gc, RPOS(p), -fac))
+        || !client_fac_check_row(gc, rp, -fac))
           return;
 
 
@@ -320,7 +340,7 @@ client_fac_resize(struct client *c, Position p, int fac)
      else
      {
           client_fac_arrange_row(c, p, fac);
-          client_fac_arrange_row(gc, RPOS(p), -fac);
+          client_fac_arrange_row(gc, rp, -fac);
      }
 }
 

+ 2 - 1
wmfs2/src/client.h

@@ -11,6 +11,7 @@
 
 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);
 void client_focus(struct client *c);
 void client_get_name(struct client *c);
@@ -53,7 +54,7 @@ client_fac_geo(struct client *c, Position p, int fac)
 
      /* Check for incompatible geo */
      if(cg.w > c->screen->ugeo.w || cg.h > c->screen->ugeo.h
-               || cg.w < 1 || cg.h < 1)
+               || cg.w < 3 || cg.h < 3)
           return false;
 
      /* Set transformed geo in tmp geo */

+ 7 - 0
wmfs2/src/draw.h

@@ -22,6 +22,13 @@ draw_text(Drawable d, struct theme *t, int x, int y, Color fg, const char *str)
      XmbDrawString(W->dpy, d, t->font.fontset, W->gc, x, y, str, strlen(str));
 }
 
+static inline void
+draw_rect(Drawable d, struct geo g, Color bg)
+{
+     XSetForeground(W->dpy, W->gc, bg);
+     XFillRectangle(W->dpy, d, W->gc, g.x, g.y, g.w, g.h);
+}
+
 static inline unsigned short
 draw_textw(struct theme *t, const char *str)
 {

+ 6 - 13
wmfs2/src/layout.c

@@ -12,14 +12,13 @@ static struct geo
 layout_split(struct client *c, bool vertical)
 {
      struct geo og, geo;
-     int bord = THEME_DEFAULT->client_border_width;
 
      geo = og = c->geo;
 
      if(vertical)
      {
           c->geo.w >>= 1;
-          geo.x = (c->geo.x + bord) + (c->geo.w + bord);
+          geo.x = c->geo.x + c->geo.w;
           geo.w >>= 1;
 
           /* Remainder */
@@ -28,7 +27,7 @@ layout_split(struct client *c, bool vertical)
      else
      {
           c->geo.h >>= 1;
-          geo.y = (c->geo.y + bord) + (c->geo.h + bord);
+          geo.y = c->geo.y + c->geo.h;
           geo.h >>= 1;
 
           /* Remainder */
@@ -45,14 +44,14 @@ layout_split_arrange_size(struct geo g, struct client *c, Position p)
 {
      if(LDIR(p))
      {
-          c->geo.w += g.w + (THEME_DEFAULT->client_border_width << 1);
+          c->geo.w += g.w;
 
           if(p == Right)
                c->geo.x = g.x;
      }
      else
      {
-          c->geo.h += g.h + (THEME_DEFAULT->client_border_width << 1);
+          c->geo.h += g.h;
 
           if(p == Bottom)
                c->geo.y = g.y;
@@ -66,23 +65,18 @@ layout_split_check_row_dir(struct client *c, struct client *g, Position p)
 {
      struct geo cgeo = c->geo;
      struct client *cc;
-     int bord = THEME_DEFAULT->client_border_width;
-     int i = 0, s = 0, cs = (LDIR(p) ? g->geo.h : g->geo.w );
+     int s = 0, cs = (LDIR(p) ? g->geo.h : g->geo.w);
 
      SLIST_FOREACH(cc, &c->tag->clients, tnext)
           if(GEO_PARENTROW(cgeo, cc->geo, RPOS(p))
                     && GEO_CHECK_ROW(cc->geo, g->geo, p))
           {
-               s += (LDIR(p)
-                         ? cc->geo.h + bord
-                         : cc->geo.w + bord) + (i > 1 ? bord : 0);
+               s += (LDIR(p) ? cc->geo.h : cc->geo.w);
 
                if(s == cs)
                     return true;
                if(s > cs)
                     return false;
-
-               ++i;
           }
 
      return false;
@@ -147,7 +141,6 @@ layout_split_arrange_closed(struct client *ghost)
                     }
           }
      }
-
 }
 
 /* Integrate a client in split layout: split sc and fill c in new geo */

+ 1 - 1
wmfs2/src/wmfs.h

@@ -104,7 +104,7 @@ struct client
      struct tag *tag;
      struct screen *screen;
      struct barwin *titlebar;
-     struct geo geo, tgeo;
+     struct geo geo, tgeo, wgeo;
      char *title;
      Flags flags;
      Window win;