changeset 3155:08a7a8fad0d6

Just refactored code
author unexist
date Wed, 14 Dec 2011 21:53:02 +0100
parents 3051728c5e46
children 44a484b6353b
files src/subtle/panel.c src/subtle/screen.c src/subtle/subtle.h src/subtle/tray.c
diffstat 4 files changed, 87 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/src/subtle/panel.c	Wed Dec 14 21:52:29 2011 +0100
+++ b/src/subtle/panel.c	Wed Dec 14 21:53:02 2011 +0100
@@ -103,7 +103,7 @@
       subStyleReset(s, -1);
 
       /* Pick base style */
-      if(!(style = subArrayGet(subtle->styles.views.styles, v->style)))
+      if(!(style = subArrayGet(subtle->styles.views.styles, v->styleid)))
         {
           if(subtle->styles.focus && focus)
             style = subtle->styles.focus;
@@ -136,7 +136,7 @@
 
   /* Pick sublet style */
   if(subtle->styles.sublets.styles)
-    s = subArrayGet(subtle->styles.sublets.styles, p->sublet->style);
+    s = subArrayGet(subtle->styles.sublets.styles, p->sublet->styleid);
 
   return s ? s : &subtle->styles.sublets;
 } /* }}} */
@@ -168,9 +168,9 @@
         p->sublet = SUBLET(subSharedMemoryAlloc(1, sizeof(SubSublet)));
 
         /* Sublet specific */
-        p->sublet->time   = subSubtleTime();
-        p->sublet->text   = subSharedTextNew();
-        p->sublet->style  = -1;
+        p->sublet->time    = subSubtleTime();
+        p->sublet->text    = subSharedTextNew();
+        p->sublet->styleid = -1;
         break; /* }}} */
       case SUB_PANEL_VIEWS: /* {{{ */
         p->flags |= SUB_PANEL_DOWN;
@@ -247,8 +247,8 @@
                       subtle->styles.title.font, c->name,
                       /* Limit string length */
                       len > subtle->styles.clients.right ?
-                      subtle->styles.clients.right : len,
-                      NULL, NULL, True) + width + STYLE_WIDTH(subtle->styles.title);
+                      subtle->styles.clients.right : len, NULL, NULL, True) +
+                      width + STYLE_WIDTH(subtle->styles.title);
 
                     /* Ensure min width */
                     p->width = MAX(subtle->styles.clients.min, p->width);
@@ -275,7 +275,7 @@
                     !(subtle->client_tags & v->tags))
                   continue;
 
-                PanelViewStyle(v, i, (p->screen->vid == i), &s);
+                PanelViewStyle(v, i, (p->screen->viewid == i), &s);
 
                 /* Update view width */
                 if(v->flags & SUB_VIEW_ICON_ONLY)
@@ -373,7 +373,7 @@
             SubClient *c = NULL;
 
             if((c = CLIENT(subSubtleFind(subtle->windows.focus[0], CLIENTID))) &&
-                !(c->flags & SUB_CLIENT_TYPE_DESKTOP))
+                !(c->flags & SUB_CLIENT_TYPE_DESKTOP) && VISIBLE(c))
               {
                 int x = 0, y = 0, width = 0, len = 0;
                 char buf[5] = { 0 };
@@ -423,7 +423,7 @@
                     !(subtle->client_tags & v->tags))
                   continue;
 
-                PanelViewStyle(v, i, (p->screen->vid == i), &s);
+                PanelViewStyle(v, i, (p->screen->viewid == i), &s);
 
                 /* Set window background and border*/
                 PanelRect(drawable, vx, v->width, &s);
@@ -586,7 +586,11 @@
                         /* Check if x is in view rect */
                         if(x >= vx && x <= vx + v->width)
                           {
-                            subViewSwitch(v, -1, False);
+                            /* FIXME */
+                            int sid = subArrayIndex(subtle->screens,
+                              (void *)p->screen);
+
+                            subViewFocus(v, sid, True, False);
 
                             break;
                           }
--- a/src/subtle/screen.c	Wed Dec 14 21:52:29 2011 +0100
+++ b/src/subtle/screen.c	Wed Dec 14 21:53:02 2011 +0100
@@ -195,7 +195,7 @@
   s->geom.width  = width;
   s->geom.height = height;
   s->base        = s->geom; ///< Backup size
-  s->vid         = subtle->screens->ndata; ///< Init
+  s->viewid         = subtle->screens->ndata; ///< Init
 
   /* Create panel windows */
   sattrs.event_mask        = ButtonPressMask|EnterWindowMask|
@@ -315,7 +315,7 @@
       for(i = 0; i < subtle->clients->ndata; i++)
         {
           SubClient *c = CLIENT(subtle->clients->data[i]);
-          int gravity = 0, screen = 0, view = 0, visible = 0;
+          int gravityid = 0, screenid = 0, viewid = 0, visible = 0;
 
           /* Ignore dead or just iconified clients */
           if(c->flags & SUB_CLIENT_DEAD) continue;
@@ -327,23 +327,23 @@
           for(j = 0; j < subtle->screens->ndata; j++)
             {
               s = SCREEN(subtle->screens->data[j]);
-              v = VIEW(subtle->views->data[s->vid]);
+              v = VIEW(subtle->views->data[s->viewid]);
 
               /* Set visible tags and views to ease lookups */
               subtle->visible_tags  |= v->tags;
-              subtle->visible_views |= (1L << (s->vid + 1));
+              subtle->visible_views |= (1L << (s->viewid + 1));
 
               /* Find visible clients */
-              if(VISIBLE(v->tags, c))
+              if(VISIBLETAGS(c, v->tags))
                 {
-                  gravity = c->gravities[s->vid];
-                  view    = s->vid;
-                  screen  = j;
+                  gravityid = c->gravities[s->viewid];
+                  viewid    = s->viewid;
+                  screenid  = j;
                   visible++;
 
                   /* Keep screen on sticky mode */
                   if(c->flags & SUB_CLIENT_MODE_STICK)
-                    screen = c->screen;
+                    screenid = c->screenid;
                 }
             }
 
@@ -351,7 +351,7 @@
           if(0 < visible)
             {
               /* Update client */
-              subClientArrange(c, gravity, screen);
+              subClientArrange(c, gravityid, screenid);
               XMapWindow(subtle->dpy, c->win);
               subEwmhSetWMState(c->win, NormalState);
 
@@ -361,9 +361,9 @@
 
               /* EWMH: Desktop, screen */
               subEwmhSetCardinals(c->win, SUB_EWMH_NET_WM_DESKTOP,
-                (long *)&view, 1);
+                (long *)&viewid, 1);
               subEwmhSetCardinals(c->win, SUB_EWMH_SUBTLE_CLIENT_SCREEN,
-                (long *)&screen, 1);
+                (long *)&screenid, 1);
             }
           else ///< Unmap other windows
             {
@@ -379,11 +379,11 @@
       for(i = 0; i < subtle->screens->ndata; i++)
         {
           s = SCREEN(subtle->screens->data[i]);
-          v = VIEW(subtle->views->data[s->vid]);
+          v = VIEW(subtle->views->data[s->viewid]);
 
           /* Set visible tags and views to ease lookups */
           subtle->visible_tags  |= v->tags;
-          subtle->visible_views |= (1L << (s->vid + 1));
+          subtle->visible_views |= (1L << (s->viewid + 1));
         }
     }
 
@@ -632,22 +632,22 @@
   subSubtleLogDebugSubtle("Resize\n");
 } /* }}} */
 
- /** subScreenJump {{{
-  * @brief Jump to screen
+ /** subScreenWarp {{{
+  * @brief warp pointer to screen
   * @param[in]  s  A #SubScreen
   **/
 
 void
-subScreenJump(SubScreen *s)
+subScreenWarp(SubScreen *s)
 {
   assert(s);
 
-  XWarpPointer(subtle->dpy, None, ROOT, 0, 0, s->geom.x, s->geom.y,
-    s->geom.x + s->geom.width / 2, s->geom.y + s->geom.height / 2);
+  /* Move pointer to screen center */
+  if(!(subtle->flags & SUB_SUBTLE_SKIP_WARP))
+    XWarpPointer(subtle->dpy, None, ROOT, 0, 0, s->geom.x, s->geom.y,
+      s->geom.x + s->geom.width / 2, s->geom.y + s->geom.height / 2);
 
-  subViewFocus(VIEW(subArrayGet(subtle->views, s->vid)), True);
-
-  subSubtleLogDebugSubtle("Jump\n");
+  subSubtleLogDebugSubtle("Warp\n");
 } /* }}} */
 
  /** SubScreenKill {{{
@@ -702,7 +702,7 @@
 
   /* Collect views */
   for(i = 0; i < subtle->screens->ndata; i++)
-    views[i] = SCREEN(subtle->screens->data[i])->vid;
+    views[i] = SCREEN(subtle->screens->data[i])->viewid;
 
   subEwmhSetCardinals(ROOT, SUB_EWMH_SUBTLE_SCREEN_VIEWS,
     views, subtle->screens->ndata);
--- a/src/subtle/subtle.h	Wed Dec 14 21:52:29 2011 +0100
+++ b/src/subtle/subtle.h	Wed Dec 14 21:53:02 2011 +0100
@@ -63,41 +63,43 @@
   (SUB_LOG_EVENTS|SUB_LOG_RUBY|SUB_LOG_XERROR| \
   SUB_LOG_SUBTLE|SUB_LOG_DEBUG)                                   ///< Debug loglevel
 
-#define BORDER(c) \
-  (c->flags & SUB_CLIENT_MODE_BORDERLESS ? 0 : \
+#define BORDER(C) \
+  (C->flags & SUB_CLIENT_MODE_BORDERLESS ? 0 : \
   subtle->styles.clients.border.top)                              ///< Get border width
 
-#define STYLE_TOP(s) \
-  (s.border.top + s.padding.top + s.margin.top)                   ///< Get style top
-#define STYLE_RIGHT(s) \
-  (s.border.right + s.padding.right + s.margin.right)             ///< Get style right
-#define STYLE_BOTTOM(s) \
-  (s.border.bottom + s.padding.bottom + s.margin.bottom)          ///< Get style bottom
-#define STYLE_LEFT(s) \
-  (s.border.left + s.padding.left + s.margin.left)                ///< Get style left
+#define STYLE_TOP(S) \
+  (S.border.top + S.padding.top + S.margin.top)                   ///< Get style top
+#define STYLE_RIGHT(S) \
+  (S.border.right + S.padding.right + S.margin.right)             ///< Get style right
+#define STYLE_BOTTOM(S) \
+  (S.border.bottom + S.padding.bottom + S.margin.bottom)          ///< Get style bottom
+#define STYLE_LEFT(S) \
+  (S.border.left + S.padding.left + S.margin.left)                ///< Get style left
 
-#define STYLE_WIDTH(s)  (STYLE_LEFT(s) + STYLE_RIGHT(s))          ///< Get style width
-#define STYLE_HEIGHT(s) (STYLE_TOP(s) + STYLE_BOTTOM(s))          ///< Get style height
+#define STYLE_WIDTH(S)  (STYLE_LEFT(S) + STYLE_RIGHT(S))          ///< Get style width
+#define STYLE_HEIGHT(S) (STYLE_TOP(S) + STYLE_BOTTOM(S))          ///< Get style height
 
-#define STYLE_FLAG(flag)    (1L << (10 + flag))                   ///< Get style flag
+#define STYLE_FLAG(Flag)    (1L << (10 + Flag))                   ///< Get style flag
+
+#define MIN(A,B)     (A >= B ? B : A)                             ///< Minimum
+#define MAX(A,B)     (A >= B ? A : B)                             ///< Maximum
 
-#define MIN(a,b)     (a >= b ? b : a)                             ///< Minimum
-#define MAX(a,b)     (a >= b ? a : b)                             ///< Maximum
+#define ALIVE(C) (C && !(C->flags & SUB_CLIENT_DEAD))             ///< Check if client is alive
+#define DEAD(C) \
+  if(!C || C->flags & SUB_CLIENT_DEAD) return;                    ///< Check dead clients
 
-#define ALIVE(c) (c && !(c->flags & SUB_CLIENT_DEAD))             ///< Check if client is alive
-#define DEAD(c) \
-  if(!c || c->flags & SUB_CLIENT_DEAD) return;                    ///< Check dead clients
+#define MINMAX(Val,Min,Max) \
+  ((Val < Min) ? Min : ((Val > Max) ? Max : Val))                 ///< Value min/max
 
-#define MINMAX(val,min,max) \
-  ((val < min) ? min : ((val > max) ? max : val))                 ///< Value min/max
+#define XYINRECT(Wx,Wy,R) \
+  (Wx >= R.x && Wx <= (R.x + R.width) && \
+   Wy >= R.y && Wy <= (R.y + R.height))                           ///< Whether x/y is in rect
 
-#define XYINRECT(wx,wy,r) \
-  (wx >= r.x && wx <= (r.x + r.width) && \
-   wy >= r.y && wy <= (r.y + r.height))                           ///< Whether x/y is in rect
+#define VISIBLE(C) VISIBLETAGS(C,subtle->visible_tags)            ///< Whether client is visible
 
-#define VISIBLE(visible_tags,c) \
-  (c && (visible_tags & c->tags || \
-  c->flags & (SUB_CLIENT_TYPE_DESKTOP|SUB_CLIENT_MODE_STICK)))    ///< Visible on view
+#define VISIBLETAGS(C,Tags) \
+  (C && (Tags & c->tags || \
+  C->flags & (SUB_CLIENT_TYPE_DESKTOP|SUB_CLIENT_MODE_STICK)))    ///< Whether client is visible on tags
 
 #define ROOT DefaultRootWindow(subtle->dpy)                       ///< Root window
 #define SCRN DefaultScreen(subtle->dpy)                           ///< Default screen
@@ -255,8 +257,8 @@
 #define SUB_GRAB_CHAIN_START          (1L << 14)                  ///< Chain grab start
 #define SUB_GRAB_CHAIN_LINK           (1L << 15)                  ///< Chain grab link
 #define SUB_GRAB_CHAIN_END            (1L << 16)                  ///< Chain grab end
-#define SUB_GRAB_VIEW_JUMP            (1L << 17)                  ///< Jump to view
-#define SUB_GRAB_VIEW_SWITCH          (1L << 18)                  ///< Jump to view
+#define SUB_GRAB_VIEW_FOCUS           (1L << 17)                  ///< Jump to view
+#define SUB_GRAB_VIEW_SWAP            (1L << 18)                  ///< Jump to view
 #define SUB_GRAB_VIEW_SELECT          (1L << 19)                  ///< Jump to view
 #define SUB_GRAB_SCREEN_JUMP          (1L << 20)                  ///< Jump to screen
 #define SUB_GRAB_SUBTLE_RELOAD        (1L << 21)                  ///< Reload subtle
@@ -335,7 +337,8 @@
 #define SUB_SUBTLE_RELOAD             (1L << 10)                  ///< Reload config
 #define SUB_SUBTLE_TRAY               (1L << 11)                  ///< Use tray
 #define SUB_SUBTLE_TILING             (1L << 12)                  ///< Enable tiling
-#define SUB_SUBTLE_CLICK_TO_FOCUS     (1L << 13)                  ///< Click to focus
+#define SUB_SUBTLE_FOCUS_CLICK        (1L << 13)                  ///< Click to focus
+#define SUB_SUBTLE_SKIP_WARP          (1L << 14)                  ///< Skip pointer warp
 
 /* Tag flags */
 #define SUB_TAG_GRAVITY               (1L << 10)                  ///< Gravity property
@@ -444,7 +447,8 @@
   float      minr, maxr;                                          ///< Client ratios
   int        minw, minh, maxw, maxh, incw, inch, basew, baseh;    ///< Client sizes
 
-  int        dir, screen, gravity, *gravities;                    ///< Client placement
+  int        dir, screenid, gravityid;                            ///< Client restacking dir, current screen id, current gravity id
+  int        *gravities;                                          ///< Client gravities for views
 } SubClient; /* }}} */
 
 typedef enum subewmh_t /* {{{ */
@@ -604,7 +608,7 @@
 {
   FLAGS             flags;                                        ///< Screen flags
 
-  int               vid;                                          ///< Screen current view id
+  int               viewid;                                       ///< Screen current view id
   XRectangle        geom, base;                                   ///< Screen geom, base
   Pixmap            stipple;                                      ///< Screen stipple
   Drawable          drawable;                                     ///< Screen drawable
@@ -623,7 +627,7 @@
 
 typedef struct subsublet_t { /* {{{ */
   FLAGS             flags;                                        ///< Sublet flags
-  int               watch, width, style;                          ///< Sublet watch id, width and style state
+  int               watch, width, styleid;                        ///< Sublet watch id, width and style id
   char              *name;                                        ///< Sublet name
   unsigned long     instance;                                     ///< Sublet ruby instance, fg, bg and icon color
   time_t            time, interval;                               ///< Sublet update/interval time
@@ -735,7 +739,7 @@
   char              *name;                                        ///< View name
   TAGS              tags;                                         ///< View tags
   Window            focus;                                        ///< View window, focus
-  int               width, style;                                 ///< View width, style state
+  int               width, styleid;                               ///< View width, style id
 
   struct subicon_t  *icon;                                        ///< View icon
 } SubView; /* }}} */
@@ -760,9 +764,9 @@
 SubClient *subClientNew(Window win);                              ///< Create client
 void subClientConfigure(SubClient *c);                            ///< Send configure request
 void subClientDimension(int id);                                  ///< Dimension clients
-void subClientRender(SubClient *c);                               ///< Render client
 void subClientFocus(SubClient *c, int warp);                      ///< Focus client
-void subClientWarp(SubClient *c);                                 ///< Warp to client
+SubClient *subClientNext(int screenid);                      ///< Focus next client
+void subClientWarp(SubClient *c);                                 ///< Warp pointer to client
 void subClientDrag(SubClient *c, int mode, int direction);        ///< Move/drag client
 void subClientUpdate(int vid);                                    ///< Update clients
 void subClientTag(SubClient *c, int tag, int *flags);             ///< Tag client
@@ -826,7 +830,7 @@
 void subGrabInit(void);                                           ///< Init keymap
 SubGrab *subGrabNew(const char *keys, int *duplicate);            ///< Create grab
 SubGrab *subGrabFind(int code, unsigned int mod);                 ///< Find grab
-void subGrabSet(Window win);                                      ///< Grab window
+void subGrabSet(Window win, int mask);                            ///< Grab window
 void subGrabUnset(Window win);                                    ///< Ungrab window
 int subGrabCompare(const void *a, const void *b);                 ///< Compare grabs
 void subGrabKill(SubGrab *g);                                     ///< Kill grab
@@ -879,12 +883,12 @@
 SubScreen *subScreenNew(int x, int y, unsigned int width,
   unsigned int height);                                           ///< Create screen
 SubScreen *subScreenFind(int x, int y, int *sid);                 ///< Find screen by coordinates
-SubScreen *subScreenCurrent(int *sid);                            ///< Get current screen
+SubScreen * subScreenCurrent(int *sid);                           ///< Get current screen
 void subScreenConfigure(void);                                    ///< Configure screens
 void subScreenUpdate(void);                                       ///< Update screens
 void subScreenRender(void);                                       ///< Render screens
 void subScreenResize(void);                                       ///< Update screen sizes
-void subScreenJump(SubScreen *s);                                 ///< Jump to screen
+void subScreenWarp(SubScreen *s);                                 ///< Warp pointer to screen
 void subScreenPublish(void);                                      ///< Publish screens
 void subScreenKill(SubScreen *s);                                 ///< Kill screen
 /* }}} */
@@ -901,7 +905,6 @@
 /* subtle.c {{{ */
 XPointer * subSubtleFind(Window win, XContext id);                ///< Find window
 time_t subSubtleTime(void);                                       ///< Get current time
-Window subSubtleFocus(int focus);                                 ///< Focus window
 void subSubtleLog(int level, const char *file,
   int line, const char *format, ...);                             ///< Print messages
 void subSubtleFinish(void);                                       ///< Finish subtle
@@ -930,9 +933,8 @@
 
 /* view.c {{{ */
 SubView *subViewNew(char *name, char *tags);                      ///< Create view
-void subViewFocus(SubView *v, int focus);                         ///< Restore view focus
-void subViewJump(SubView *v);                                     ///< Jump to view
-void subViewSwitch(SubView *v, int sid, int focus);               ///< Switch view
+void subViewFocus(SubView *v, int screenid,
+  int swap, int focus);                                           ///< Focus view
 void subViewKill(SubView *v);                                     ///< Kill view
 void subViewPublish(void);                                        ///< Publish views
 /* }}} */
--- a/src/subtle/tray.c	Wed Dec 14 21:52:29 2011 +0100
+++ b/src/subtle/tray.c	Wed Dec 14 21:53:02 2011 +0100
@@ -247,7 +247,11 @@
       subScreenRender();
 
       /* Update focus if necessary */
-      if(focus) subSubtleFocus(True);
+      if(focus)
+        {
+          SubClient *c = subClientNext(0);
+          if(c) subClientFocus(c, True);
+        }
     }
 
   subSubtleLogDebugSubtle("Close\n");