[BACK]Return to window-tree.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/window-tree.c between version 1.39 and 1.40

version 1.39, 2019/05/28 07:18:42 version 1.40, 2019/08/16 11:49:12
Line 89 
Line 89 
         "name",          "name",
         "time"          "time"
 };  };
   static struct mode_tree_sort_criteria *window_tree_sort;
   
 enum window_tree_type {  enum window_tree_type {
         WINDOW_TREE_NONE,          WINDOW_TREE_NONE,
Line 184 
Line 185 
 }  }
   
 static int  static int
 window_tree_cmp_session_name(const void *a0, const void *b0)  window_tree_cmp_session(const void *a0, const void *b0)
 {  {
         const struct session *const *a = a0;          const struct session *const     *a = a0;
         const struct session *const *b = b0;          const struct session *const     *b = b0;
           const struct session            *sa = *a;
           const struct session            *sb = *b;
           int                              result;
   
         return (strcmp((*a)->name, (*b)->name));          switch (window_tree_sort->field) {
 }          case WINDOW_TREE_BY_INDEX:
                   result = sa->id - sb->id;
                   break;
           case WINDOW_TREE_BY_TIME:
                   if (timercmp(&sa->activity_time, &sb->activity_time, >)) {
                           result = -1;
                           break;
                   }
                   if (timercmp(&sa->activity_time, &sb->activity_time, <)) {
                           result = 1;
                           break;
                   }
                   /* FALLTHROUGH */
           case WINDOW_TREE_BY_NAME:
                   result = strcmp(sa->name, sb->name);
                   break;
           }
   
 static int          if (window_tree_sort->reversed)
 window_tree_cmp_session_time(const void *a0, const void *b0)                  result = -result;
 {          return (result);
         const struct session *const *a = a0;  
         const struct session *const *b = b0;  
   
         if (timercmp(&(*a)->activity_time, &(*b)->activity_time, >))  
                 return (-1);  
         if (timercmp(&(*a)->activity_time, &(*b)->activity_time, <))  
                 return (1);  
         return (strcmp((*a)->name, (*b)->name));  
 }  }
   
 static int  static int
 window_tree_cmp_window_name(const void *a0, const void *b0)  window_tree_cmp_window(const void *a0, const void *b0)
 {  {
         const struct winlink *const *a = a0;          const struct winlink *const     *a = a0;
         const struct winlink *const *b = b0;          const struct winlink *const     *b = b0;
           const struct winlink            *wla = *a;
           const struct winlink            *wlb = *b;
           struct window                   *wa = wla->window;
           struct window                   *wb = wlb->window;
           int                              result;
   
         return (strcmp((*a)->window->name, (*b)->window->name));          switch (window_tree_sort->field) {
 }          case WINDOW_TREE_BY_INDEX:
                   result = wla->idx - wlb->idx;
                   break;
           case WINDOW_TREE_BY_TIME:
                   if (timercmp(&wa->activity_time, &wb->activity_time, >)) {
                           result = -1;
                           break;
                   }
                   if (timercmp(&wa->activity_time, &wb->activity_time, <)) {
                           result = 1;
                           break;
                   }
                   /* FALLTHROUGH */
           case WINDOW_TREE_BY_NAME:
                   result = strcmp(wa->name, wb->name);
                   break;
           }
   
 static int          if (window_tree_sort->reversed)
 window_tree_cmp_window_time(const void *a0, const void *b0)                  result = -result;
 {          return (result);
         const struct winlink *const *a = a0;  
         const struct winlink *const *b = b0;  
   
         if (timercmp(&(*a)->window->activity_time,  
             &(*b)->window->activity_time, >))  
                 return (-1);  
         if (timercmp(&(*a)->window->activity_time,  
             &(*b)->window->activity_time, <))  
                 return (1);  
         return (strcmp((*a)->window->name, (*b)->window->name));  
 }  }
   
 static int  static int
 window_tree_cmp_pane_time(const void *a0, const void *b0)  window_tree_cmp_pane(const void *a0, const void *b0)
 {  {
         const struct window_pane *const *a = a0;          const struct window_pane *const *a = a0;
         const struct window_pane *const *b = b0;          const struct window_pane *const *b = b0;
           int                              result;
   
         if ((*a)->active_point < (*b)->active_point)          if (window_tree_sort->field == WINDOW_TREE_BY_TIME)
                 return (-1);                  result = (*a)->active_point - (*b)->active_point;
         if ((*a)->active_point > (*b)->active_point)          else {
                 return (1);                  /*
         return (0);                   * Panes don't have names, so use number order for any other
                    * sort field.
                    */
                   result = (*a)->id - (*b)->id;
           }
           if (window_tree_sort->reversed)
                   result *= -1;
           return (result);
 }  }
   
 static void  static void
Line 285 
Line 316 
 }  }
   
 static int  static int
 window_tree_build_window(struct session *s, struct winlink *wl, void* modedata,  window_tree_build_window(struct session *s, struct winlink *wl,
     u_int sort_type, struct mode_tree_item *parent, const char *filter)      void* modedata, struct mode_tree_sort_criteria *sort_crit,
       struct mode_tree_item *parent, const char *filter)
 {  {
         struct window_tree_modedata     *data = modedata;          struct window_tree_modedata     *data = modedata;
         struct window_tree_itemdata     *item;          struct window_tree_itemdata     *item;
Line 335 
Line 367 
         if (n == 0)          if (n == 0)
                 goto empty;                  goto empty;
   
         switch (sort_type) {          window_tree_sort = sort_crit;
         case WINDOW_TREE_BY_INDEX:          qsort(l, n, sizeof *l, window_tree_cmp_pane);
                 break;  
         case WINDOW_TREE_BY_NAME:  
                 /* Panes don't have names, so leave in number order. */  
                 break;  
         case WINDOW_TREE_BY_TIME:  
                 qsort(l, n, sizeof *l, window_tree_cmp_pane_time);  
                 break;  
         }  
   
         for (i = 0; i < n; i++)          for (i = 0; i < n; i++)
                 window_tree_build_pane(s, wl, l[i], modedata, mti);                  window_tree_build_pane(s, wl, l[i], modedata, mti);
Line 360 
Line 384 
   
 static void  static void
 window_tree_build_session(struct session *s, void* modedata,  window_tree_build_session(struct session *s, void* modedata,
     u_int sort_type, const char *filter)      struct mode_tree_sort_criteria *sort_crit, const char *filter)
 {  {
         struct window_tree_modedata     *data = modedata;          struct window_tree_modedata     *data = modedata;
         struct window_tree_itemdata     *item;          struct window_tree_itemdata     *item;
Line 392 
Line 416 
                 l = xreallocarray(l, n + 1, sizeof *l);                  l = xreallocarray(l, n + 1, sizeof *l);
                 l[n++] = wl;                  l[n++] = wl;
         }          }
         switch (sort_type) {          window_tree_sort = sort_crit;
         case WINDOW_TREE_BY_INDEX:          qsort(l, n, sizeof *l, window_tree_cmp_window);
                 break;  
         case WINDOW_TREE_BY_NAME:  
                 qsort(l, n, sizeof *l, window_tree_cmp_window_name);  
                 break;  
         case WINDOW_TREE_BY_TIME:  
                 qsort(l, n, sizeof *l, window_tree_cmp_window_time);  
                 break;  
         }  
   
         empty = 0;          empty = 0;
         for (i = 0; i < n; i++) {          for (i = 0; i < n; i++) {
                 if (!window_tree_build_window(s, l[i], modedata, sort_type, mti,                  if (!window_tree_build_window(s, l[i], modedata, sort_crit, mti,
                     filter))                      filter))
                         empty++;                          empty++;
         }          }
Line 418 
Line 434 
 }  }
   
 static void  static void
 window_tree_build(void *modedata, u_int sort_type, uint64_t *tag,  window_tree_build(void *modedata, struct mode_tree_sort_criteria *sort_crit,
     const char *filter)      uint64_t *tag, const char *filter)
 {  {
         struct window_tree_modedata     *data = modedata;          struct window_tree_modedata     *data = modedata;
         struct session                  *s, **l;          struct session                  *s, **l;
Line 446 
Line 462 
                 l = xreallocarray(l, n + 1, sizeof *l);                  l = xreallocarray(l, n + 1, sizeof *l);
                 l[n++] = s;                  l[n++] = s;
         }          }
         switch (sort_type) {          window_tree_sort = sort_crit;
         case WINDOW_TREE_BY_INDEX:          qsort(l, n, sizeof *l, window_tree_cmp_session);
                 break;  
         case WINDOW_TREE_BY_NAME:  
                 qsort(l, n, sizeof *l, window_tree_cmp_session_name);  
                 break;  
         case WINDOW_TREE_BY_TIME:  
                 qsort(l, n, sizeof *l, window_tree_cmp_session_time);  
                 break;  
         }  
   
         for (i = 0; i < n; i++)          for (i = 0; i < n; i++)
                 window_tree_build_session(l[i], modedata, sort_type, filter);                  window_tree_build_session(l[i], modedata, sort_crit, filter);
         free(l);          free(l);
   
         switch (data->type) {          switch (data->type) {

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40