SaraF

fancybarclickable

Jun 11th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.22 KB | None | 0 0
  1. --- a/config.def.h  2010-06-04 06:39:15.000000000 -0400
  2. +++ b/config.def.h  2011-06-11 09:30:07.032880714 -0400
  3. @@ -89,6 +89,7 @@
  4.     /* click                event mask      button          function        argument */
  5.     { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
  6.     { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
  7. +    { ClkWinTitle,          0,              Button1,        focusonclick,   {0} },
  8.     { ClkWinTitle,          0,              Button2,        zoom,           {0} },
  9.     { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
  10.     { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
  11. --- a/dwm.c 2010-06-04 06:39:15.000000000 -0400
  12. +++ b/dwm.c 2011-05-31 10:36:47.906683796 -0400
  13. @@ -140,6 +140,8 @@
  14.     Monitor *next;
  15.     Window barwin;
  16.     const Layout *lt[2];
  17. +   int titlebarbegin;
  18. +   int titlebarend;
  19.  };
  20.  
  21.  typedef struct {
  22. @@ -175,11 +177,13 @@
  23.  static Monitor *dirtomon(int dir);
  24.  static void drawbar(Monitor *m);
  25.  static void drawbars(void);
  26. +static void drawvline(unsigned long col[ColLast]);
  27.  static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
  28.  static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
  29.  static void enternotify(XEvent *e);
  30.  static void expose(XEvent *e);
  31.  static void focus(Client *c);
  32. +static void focusonclick(const Arg *arg);
  33.  static void focusin(XEvent *e);
  34.  static void focusmon(const Arg *arg);
  35.  static void focusstack(const Arg *arg);
  36. @@ -443,10 +447,12 @@
  37.         }
  38.         else if(ev->x < x + blw)
  39.             click = ClkLtSymbol;
  40. -       else if(ev->x > selmon->wx + selmon->ww - TEXTW(stext))
  41. +       else if(ev->x > selmon->titlebarend)
  42.             click = ClkStatusText;
  43. -       else
  44. +       else {
  45. +           arg.ui = ev->x;
  46.             click = ClkWinTitle;
  47. +       }
  48.     }
  49.     else if((c = wintoclient(ev->window))) {
  50.         focus(c);
  51. @@ -455,7 +461,7 @@
  52.     for(i = 0; i < LENGTH(buttons); i++)
  53.         if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
  54.         && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
  55. -           buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
  56. +           buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
  57.  }
  58.  
  59.  void
  60. @@ -683,12 +689,15 @@
  61.  
  62.  void
  63.  drawbar(Monitor *m) {
  64. -   int x;
  65. -   unsigned int i, occ = 0, urg = 0;
  66. +   int x, ow, mw = 0, extra, tw;
  67. +   unsigned int i, n = 0, occ = 0, urg = 0;
  68.     unsigned long *col;
  69. -   Client *c;
  70. +   Client *c, *firstvis, *lastvis = NULL;
  71. +   DC seldc;
  72.  
  73.     for(c = m->clients; c; c = c->next) {
  74. +       if(ISVISIBLE(c))
  75. +           n++;
  76.         occ |= c->tags;
  77.         if(c->isurgent)
  78.             urg |= c->tags;
  79. @@ -714,19 +723,68 @@
  80.             dc.w = m->ww - x;
  81.         }
  82.         drawtext(stext, dc.norm, False);
  83. +       m->titlebarend=dc.x;
  84.     }
  85. -   else
  86. +   else {
  87.         dc.x = m->ww;
  88. -   if((dc.w = dc.x - x) > bh) {
  89. -       dc.x = x;
  90. -       if(m->sel) {
  91. -           col = m == selmon ? dc.sel : dc.norm;
  92. -           drawtext(m->sel->name, col, False);
  93. -           drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
  94. +        m->titlebarbegin=dc.x;
  95. +   }
  96. +
  97. +   for(c = m->clients; c && !ISVISIBLE(c); c = c->next);
  98. +   firstvis = c;
  99. +
  100. +   col = m == selmon ? dc.sel : dc.norm;
  101. +   dc.w = dc.x - x;
  102. +   dc.x = x;
  103. +
  104. +   if(n > 0) {
  105. +       mw = dc.w / n;
  106. +       extra = 0;
  107. +       seldc = dc;
  108. +       i = 0;
  109. +
  110. +       while(c) {
  111. +           lastvis = c;
  112. +           tw = TEXTW(c->name);
  113. +           if(tw < mw) extra += (mw - tw); else i++;
  114. +           for(c = c->next; c && !ISVISIBLE(c); c = c->next);
  115.         }
  116. -       else
  117. +
  118. +       if(i > 0) mw += extra / i;
  119. +
  120. +       c = firstvis;
  121. +       x = dc.x;
  122. +   }
  123. +   m->titlebarbegin=dc.x;
  124. +   while(dc.w > bh) {
  125. +       if(c) {
  126. +           ow = dc.w;
  127. +           tw = TEXTW(c->name);
  128. +           dc.w = MIN(ow, tw);
  129. +
  130. +           if(dc.w > mw) dc.w = mw;
  131. +           if(m->sel == c) seldc = dc;
  132. +           if(c == lastvis) dc.w = ow;
  133. +
  134. +           drawtext(c->name, col, True);
  135. +           if(c != firstvis) drawvline(col);
  136. +           drawsquare(c->isfixed, c->isfloating, False, col);
  137. +
  138. +           dc.x += dc.w;
  139. +           dc.w = ow - dc.w;
  140. +           for(c = c->next; c && !ISVISIBLE(c); c = c->next);
  141. +       } else {
  142.             drawtext(NULL, dc.norm, False);
  143. +           break;
  144. +       }
  145.     }
  146. +
  147. +   if(m == selmon && m->sel && ISVISIBLE(m->sel)) {
  148. +       dc = seldc;
  149. +       drawtext(m->sel->name, col, False);
  150. +       drawsquare(m->sel->isfixed, m->sel->isfloating, True, col);
  151. +   }
  152. +
  153.     XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
  154.     XSync(dpy, False);
  155.  }
  156. @@ -740,6 +798,15 @@
  157.  }
  158.  
  159.  void
  160. +drawvline(unsigned long col[ColLast]) {
  161. +   XGCValues gcv;
  162. +
  163. +   gcv.foreground = col[ColBG];
  164. +   XChangeGC(dpy, dc.gc, GCForeground, &gcv);
  165. +   XDrawLine(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.x, dc.y + (dc.font.ascent + dc.font.descent + 2));
  166. +}
  167. +
  168. +void
  169.  drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
  170.     int x;
  171.     XGCValues gcv;
  172. @@ -840,6 +907,50 @@
  173.  }
  174.  
  175.  void
  176. +focusonclick(const Arg *arg) {
  177. +   int x, w, mw = 0, tw, n = 0, i = 0, extra = 0;
  178. +       Monitor *m = selmon;
  179. +       Client *c, *firstvis;
  180. +
  181. +       for(c = m->clients; c && !ISVISIBLE(c); c = c->next);
  182. +       firstvis = c;
  183. +  
  184. +       for(c = m->clients; c; c = c->next)
  185. +       if (ISVISIBLE(c))
  186. +           n++;
  187. +  
  188. +       if(n > 0) {
  189. +           mw = (m->titlebarend - m->titlebarbegin) / n;
  190. +           c = firstvis;
  191. +           while(c) {
  192. +               tw = TEXTW(c->name);
  193. +               if(tw < mw) extra += (mw - tw); else i++;
  194. +               for(c = c->next; c && !ISVISIBLE(c); c = c->next);
  195. +           }
  196. +           if(i > 0) mw += extra / i;
  197. +       }
  198. +
  199. +       x=m->titlebarbegin;
  200. +
  201. +       c = firstvis;
  202. +           while(x < m->titlebarend) {
  203. +           if(c) {
  204. +           w=MIN(TEXTW(c->name), mw);
  205. +               if (x < arg->i && x+w > arg->i) {
  206. +               focus(c);
  207. +                   restack(selmon);
  208. +                   break;
  209. +               } else
  210. +               x+=w;
  211. +          
  212. +               for(c = c->next; c && !ISVISIBLE(c); c = c->next);
  213. +       } else {
  214. +           break;
  215. +       }  
  216. +           }
  217. +}      
  218. +
  219. +void
  220.  focusin(XEvent *e) { /* there are some broken focus acquiring clients */
  221.     XFocusChangeEvent *ev = &e->xfocus;
  222.  
  223. @@ -1291,8 +1402,7 @@
  224.         }
  225.         if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
  226.             updatetitle(c);
  227. -           if(c == c->mon->sel)
  228. -               drawbar(c->mon);
  229. +           drawbar(c->mon);
  230.         }
  231.     }
  232.  }
Advertisement
Add Comment
Please, Sign In to add comment