From The Compiler, 7 Years ago, written in Diff-output.
Embed
  1. From 8b9779800c1c713aee1fd15bbd047bedce8f49cc Mon Sep 17 00:00:00 2001
  2. From: Florian Bruhin <me@the-compiler.org>
  3. Date: Sun, 19 Aug 2012 16:30:29 +0200
  4. Subject: [PATCH] Add a -v (verbose) flag to tag_status
  5.  
  6. ---
  7. doc/herbstluftwm.txt |  4 ++-
  8.  src/command.c        |  5 +++-
  9.  src/main.c           | 82 +++++++++++++++++++++++++++++++++++++++-------------
  10.  3 files changed, 69 insertions(+), 22 deletions(-)
  11.  
  12. diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
  13. index 9e2c0ec..ddc917b 100644
  14. --- a/doc/herbstluftwm.txt
  15. +++ b/doc/herbstluftwm.txt
  16. @@ -511,7 +511,7 @@ complete 'POSITION' ['COMMAND' 'ARGS ...']::
  17.  emit_hook 'ARGS ...'::
  18.      Emits a custom hook to all idling herbstclients.
  19.  
  20. -tag_status ['MONITOR']::
  21. +tag_status [*-v*] ['MONITOR']::
  22.      Print a tab separated list of all tags for specified 'MONITOR' index. If no
  23.      'MONITOR' index is given, the focused monitor is used. Each tag name is
  24.      prefixed with one char, which indicates its state:
  25. @@ -525,6 +525,8 @@ tag_status ['MONITOR']::
  26.          * *%* the tag is viewed on a different 'MONITOR' and it is focused.
  27.          * *!* the tag contains an urgent window
  28.  
  29. +If *-v* is passed, a newline-separated human-readable list is printed instead.
  30. +
  31.  WARNING: If you use a tab in one of the tag names, then tag_status is probably
  32.  quite useless for you.
  33.  
  34. diff --git a/src/command.c b/src/command.c
  35. index 13eb948..1d3e0a0 100644
  36. --- a/src/command.c
  37. +++ b/src/command.c
  38. @@ -21,6 +21,7 @@ static char* completion_focus_args[]    = { "-i", "-e", NULL };
  39.  static char* completion_unrule_args[]   = { "-F", "--all", NULL };
  40.  static char* completion_keyunbind_args[]= { "-F", "--all", NULL };
  41.  static char* completion_flag_args[]     = { "on", "off", "toggle", NULL };
  42. +static char* completion_tag_status_args[]= { "-v", NULL };
  43.  static char* completion_status[]        = { "status", NULL };
  44.  static char* completion_special_winids[]= { "urgent", "", NULL };
  45.  static char* completion_use_index_args[]= { "--skip-visible", NULL };
  46. @@ -104,7 +105,8 @@ struct {
  47.      { "toggle",         2,  no_completion },
  48.      { "set",            3,  no_completion },
  49.      { "set_layout",     2,  no_completion },
  50. -    { "tag_status",     2,  no_completion },
  51. +    { "tag_status",     3,  no_completion },
  52. +    { "tag_status",     2,  first_parameter_is_flag },
  53.      { 0 },
  54.  };
  55.  
  56. @@ -172,6 +174,7 @@ struct {
  57.      { "toggle",         EQ, 1,  .function = complete_against_settings },
  58.      { "cycle_value",    EQ, 1,  .function = complete_against_settings },
  59.      { "set_layout",     EQ, 1,  .list = g_layout_names },
  60. +    { "tag_status",     EQ, 1,  .list = completion_tag_status_args },
  61.      { "cycle_layout",   EQ, 1,  .list = completion_pm_one },
  62.      { "cycle_layout",   GE, 2,  .list = g_layout_names },
  63.      { "unrule",         EQ, 1,  .list = completion_unrule_args },
  64. diff --git a/src/main.c b/src/main.c
  65. index df35f17..ab48ba1 100644
  66. --- a/src/main.c
  67. +++ b/src/main.c
  68. @@ -232,38 +232,80 @@ int load_command(int argc, char** argv, GString** result) {
  69.  
  70.  int print_tag_status_command(int argc, char** argv, GString** result) {
  71.      int monitor_index = g_cur_monitor;
  72. +    int verbose = false;
  73. +    if (argc >= 2) {
  74. +        if (!strcmp(argv[1], "-v")) {
  75. +            verbose = true;
  76. +            (void) SHIFT(argc, argv);
  77. +        } else {
  78. +            *result = g_string_append_c(*result, '\t');
  79. +        }
  80. +    }
  81.      if (argc >= 2) {
  82.          monitor_index = atoi(argv[1]);
  83.      }
  84.      monitor_index = CLAMP(monitor_index, 0, monitor_count());
  85.      tag_update_flags();
  86.      HSMonitor* monitor = monitor_with_index(monitor_index);
  87. -    *result = g_string_append_c(*result, '\t');
  88.      for (int i = 0; i < g_tags->len; i++) {
  89.          HSTag* tag = g_array_index(g_tags, HSTag*, i);
  90. -        // print flags
  91. -        char c = '.';
  92. -        if (tag->flags & TAG_FLAG_USED) {
  93. -            c = ':';
  94. -        }
  95.          HSMonitor *tag_monitor = find_monitor_with_tag(tag);
  96. -        if (tag_monitor == monitor) {
  97. -            c = '+';
  98. -            if (monitor_index == g_cur_monitor) {
  99. -                c = '#';
  100. +        if (verbose == true) {
  101. +            g_string_append_printf(*result, "tag \"%s\": ", tag->name->str);
  102. +            if (tag->flags & TAG_FLAG_USED) {
  103. +                *result = g_string_append(*result, "used, ");
  104. +            } else {
  105. +                *result = g_string_append(*result, "empty, ");
  106.              }
  107. -        } else if (tag_monitor) {
  108. -            c = '-';
  109. -            if (get_current_monitor() == tag_monitor) {
  110. -                c = '%';
  111. +            if (tag_monitor == monitor) {
  112. +                *result = g_string_append(*result,
  113. +                    "viewed on specified monitor, ");
  114. +                if (monitor_index == g_cur_monitor) {
  115. +                    *result = g_string_append(*result, "focused");
  116. +                } else {
  117. +                    *result = g_string_append(*result, "not focused");
  118. +                }
  119. +            } else if (tag_monitor) {
  120. +                *result = g_string_append(*result,
  121. +                    "viewed on different monitor, ");
  122. +                if (get_current_monitor() == tag_monitor) {
  123. +                    *result = g_string_append(*result, "focused");
  124. +                } else {
  125. +                    *result = g_string_append(*result, "not focused");
  126. +                }
  127. +            } else {
  128. +                *result = g_string_append(*result,
  129. +                    "not viewed");
  130.              }
  131. +            if (tag->flags & TAG_FLAG_URGENT) {
  132. +                *result = g_string_append(*result,
  133. +                    ", urgent");
  134. +            }            
  135. +            *result = g_string_append(*result, ".\n");
  136. +        } else {
  137. +            // print flags
  138. +            char c = '.';
  139. +            if (tag->flags & TAG_FLAG_USED) {
  140. +                c = ':';
  141. +            }
  142. +            if (tag_monitor == monitor) {
  143. +                c = '+';
  144. +                if (monitor_index == g_cur_monitor) {
  145. +                    c = '#';
  146. +                }
  147. +            } else if (tag_monitor) {
  148. +                c = '-';
  149. +                if (get_current_monitor() == tag_monitor) {
  150. +                    c = '%';
  151. +                }
  152. +            }
  153. +            if (tag->flags & TAG_FLAG_URGENT) {
  154. +                c = '!';
  155. +            }
  156. +            *result = g_string_append_c(*result, c);
  157. +            *result = g_string_append(*result, tag->name->str);
  158. +            *result = g_string_append_c(*result, '\t');
  159.          }
  160. -        if (tag->flags & TAG_FLAG_URGENT) {
  161. -            c = '!';
  162. -        }
  163. -        *result = g_string_append_c(*result, c);
  164. -        *result = g_string_append(*result, tag->name->str);
  165. -        *result = g_string_append_c(*result, '\t');
  166.      }
  167.      return 0;
  168.  }
  169. --
  170. 1.7.11.5