From The Compiler, 6 Years ago, written in Diff-output.
Embed
  1. From 28393decc2c837408aa01aea112cc89fbd8c8c52 Mon Sep 17 00:00:00 2001
  2. From: Florian Bruhin <git@the-compiler.org>
  3. Date: Sun, 25 Nov 2012 23:59:00 +0100
  4. Subject: [PATCH 1/9] Add monitor names to add_monitor
  5.  
  6. ---
  7. MIGRATION            |  5 +++++
  8.  NEWS                 |  1 +
  9.  doc/herbstluftwm.txt | 11 +++++------
  10.  src/monitor.c        | 55 +++++++++++++++++++++++++++++++++++++++++++---------
  11.  src/monitor.h        |  5 ++++-
  12.  5 files changed, 61 insertions(+), 16 deletions(-)
  13.  
  14. diff --git a/MIGRATION b/MIGRATION
  15. index 64974dc..fe742af 100644
  16. --- a/MIGRATION
  17. +++ b/MIGRATION
  18. @@ -10,6 +10,11 @@ herbstclient now returns the exitstatus 9 (HERBST_NEED_MORE_ARGS) instead of 3
  19.  (HERBST_INVALID_ARGUMENT) if a command needs more arguments. If an error occurs,
  20.  it now outputs an error message to stderr.
  21.  
  22. +The padding arguments have been removed from add_monitor and a monitor name has
  23. +been added instead. If you add a monitor with padding, instead of 'hc
  24. +add_monitor 1024x768+0+0 1 2 3 4' now use 'hc add_monitor 1024x768+0+0; hc pad N
  25. +1 2 3 4'.
  26. +
  27.  0.3 to 0.4
  28.  ~~~~~~~~~~
  29.  The setting window_gap is now called frame_gap. Simply replace all occurrences
  30. diff --git a/NEWS b/NEWS
  31. index 2559bcd..1af16af 100644
  32. --- a/NEWS
  33. +++ b/NEWS
  34. @@ -25,6 +25,7 @@ Changes:
  35.      * floating, fullscreen, pseudotile: default to toggle if no argument is
  36.        given
  37.      * add error messages for herbstclient
  38. +    * optional names for monitors
  39.  
  40.  Release: 0.4.1 on 2012-08-30
  41.  ----------------------------
  42. diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
  43. index c617114..3a83172 100644
  44. --- a/doc/herbstluftwm.txt
  45. +++ b/doc/herbstluftwm.txt
  46. @@ -489,15 +489,14 @@ detect_monitors::
  47.      Xinerama extension is missing, it will fall back to one monitor across the
  48.      entire screen.
  49.  
  50. -add_monitor 'RECT' ['TAG' ['PADUP' ['PADRIGHT' ['PADDOWN' ['PADLEFT']]]]]::
  51. +add_monitor 'RECT' ['TAG' ['NAME']]::
  52.      Adds a monitor on the specified rectangle 'RECT' and displays 'TAG' on it.
  53.      'TAG' currently must not be displayed on any other monitor. 'RECT' is a
  54. -    string of the form 'WxH±X±Y'. The padding specifies extra space around the
  55. -    monitor for some statusbars/panels. If no or an empty padding is given, it
  56. -    is set to 0. If no or an empty 'TAG' is given, then any free tag will be
  57. -    chosen. Example:
  58. +    string of the form 'WxH±X±Y'. If no or an empty 'TAG' is given, then any
  59. +    free tag will be chosen. If a 'NAME' is given, you can reference to this
  60. +    monitor by its name instead of using an index. Example:
  61.  
  62. -        * add_monitor 1024x768-20+0 mynewtag 16
  63. +        * add_monitor 1024x768-20+0 mynewtag main
  64.  
  65.  
  66.  remove_monitor 'INDEX'::
  67. diff --git a/src/monitor.c b/src/monitor.c
  68. index ea99018..0605002 100644
  69. --- a/src/monitor.c
  70. +++ b/src/monitor.c
  71. @@ -7,6 +7,7 @@
  72.  #include <string.h>
  73.  #include <stdio.h>
  74.  #include <stdbool.h>
  75. +#include <ctype.h>
  76.  #ifdef XINERAMA
  77.  #include <X11/extensions/Xinerama.h>
  78.  #endif /* XINERAMA */
  79. @@ -310,7 +311,7 @@ int set_monitor_rects(XRectangle* templates, size_t count) {
  80.          if (!tag) {
  81.              return HERBST_TAG_IN_USE;
  82.          }
  83. -        add_monitor(templates[i], tag);
  84. +        add_monitor(templates[i], tag, NULL);
  85.          frame_show_recursive(tag->frame);
  86.      }
  87.      // remove monitors if there are too much
  88. @@ -321,11 +322,32 @@ int set_monitor_rects(XRectangle* templates, size_t count) {
  89.      return 0;
  90.  }
  91.  
  92. -HSMonitor* add_monitor(XRectangle rect, HSTag* tag) {
  93. +int find_monitor_index_by_name(char* name) {
  94. +    int i;
  95. +    for (i = 0; i < g_monitors->len; i++) {
  96. +        HSMonitor* mon = monitor_with_index(i);
  97. +        if (mon != NULL && mon->name != NULL && !strcmp(mon->name->str, name)) {
  98. +            return i;
  99. +        }
  100. +    }
  101. +    return -1;
  102. +}
  103. +
  104. +HSMonitor* find_monitor_by_name(char* name) {
  105. +    int i = find_monitor_index_by_name(name);
  106. +    if (i == -1) {
  107. +        return NULL;
  108. +    } else {
  109. +        return monitor_with_index(i);
  110. +    }
  111. +}
  112. +
  113. +HSMonitor* add_monitor(XRectangle rect, HSTag* tag, char* name) {
  114.      assert(tag != NULL);
  115.      HSMonitor* m = g_new0(HSMonitor, 1);
  116.      m->rect = rect;
  117.      m->tag = tag;
  118. +    m->name = (name ? g_string_new(name) : NULL);
  119.      m->mouse.x = 0;
  120.      m->mouse.y = 0;
  121.      m->dirty = true;
  122. @@ -338,12 +360,13 @@ HSMonitor* add_monitor(XRectangle rect, HSTag* tag) {
  123.  }
  124.  
  125.  int add_monitor_command(int argc, char** argv, GString* output) {
  126. -    // usage: add_monitor RECTANGLE [TAG [PADUP [PADRIGHT [PADDOWN [PADLEFT]]]]]
  127. +    // usage: add_monitor RECTANGLE [TAG [NAME]]
  128.      if (argc < 2) {
  129.          return HERBST_NEED_MORE_ARGS;
  130.      }
  131.      XRectangle rect = parse_rectangle(argv[1]);
  132.      HSTag* tag = NULL;
  133. +    char* name = NULL;
  134.      if (argc == 2 || !strcmp("", argv[2])) {
  135.          tag = find_unused_tag();
  136.          if (!tag) {
  137. @@ -365,11 +388,25 @@ int add_monitor_command(int argc, char** argv, GString* output) {
  138.              "%s: The tag \"%s\" is already viewed on a monitor\n", argv[0], argv[2]);
  139.          return HERBST_TAG_IN_USE;
  140.      }
  141. -    HSMonitor* monitor = add_monitor(rect, tag);
  142. -    if (argc > 3 && argv[3][0] != '\0') monitor->pad_up       = atoi(argv[3]);
  143. -    if (argc > 4 && argv[4][0] != '\0') monitor->pad_right    = atoi(argv[4]);
  144. -    if (argc > 5 && argv[5][0] != '\0') monitor->pad_down     = atoi(argv[5]);
  145. -    if (argc > 6 && argv[6][0] != '\0') monitor->pad_left     = atoi(argv[6]);
  146. +    if (argc > 3) {
  147. +        name = argv[3];
  148. +        if (isdigit(name[0])) {
  149. +            g_string_append_printf(output,
  150. +                "%s: The monitor name may not start with a number\n", argv[0]);
  151. +            return HERBST_INVALID_ARGUMENT;
  152. +        }
  153. +        if (!strcmp("", name)) {
  154. +            g_string_append_printf(output,
  155. +                "%s: An empty monitor name is not permitted\n", argv[0]);
  156. +            return HERBST_INVALID_ARGUMENT;
  157. +        }
  158. +        if (find_monitor_by_name(name)) {
  159. +            g_string_append_printf(output,
  160. +                "%s: A monitor with the same name already exists\n", argv[0]);
  161. +            return HERBST_INVALID_ARGUMENT;
  162. +        }
  163. +    }
  164. +    HSMonitor* monitor = add_monitor(rect, tag, name);
  165.      frame_show_recursive(tag->frame);
  166.      monitor_apply_layout(monitor);
  167.      emit_tag_changed(tag, g_monitors->len - 1);
  168. @@ -546,7 +583,7 @@ void ensure_monitors_are_available() {
  169.      };
  170.      ensure_tags_are_available();
  171.      // add monitor with first tag
  172. -    HSMonitor* m = add_monitor(rect, g_array_index(g_tags, HSTag*, 0));
  173. +    HSMonitor* m = add_monitor(rect, g_array_index(g_tags, HSTag*, 0), NULL);
  174.      g_cur_monitor = 0;
  175.      g_cur_frame = m->tag->frame;
  176.  }
  177. diff --git a/src/monitor.h b/src/monitor.h
  178. index 57e036c..0642601 100644
  179. --- a/src/monitor.h
  180. +++ b/src/monitor.h
  181. @@ -21,6 +21,7 @@ struct HSStack;
  182.  typedef struct HSMonitor {
  183.      struct HSTag*      tag;    // currently viewed tag
  184.      struct HSSlice*    slice;  // slice in the monitor stack
  185. +    GString*    name;
  186.      int         pad_up;
  187.      int         pad_right;
  188.      int         pad_down;
  189. @@ -48,13 +49,15 @@ HSMonitor* monitor_with_frame(struct HSFrame* frame);
  190.  HSMonitor* monitor_with_coordinate(int x, int y);
  191.  HSMonitor* monitor_with_index(int index);
  192.  HSMonitor* find_monitor_with_tag(struct HSTag* tag);
  193. -HSMonitor* add_monitor(XRectangle rect, struct HSTag* tag);
  194. +HSMonitor* add_monitor(XRectangle rect, struct HSTag* tag, char* name);
  195.  void monitor_focus_by_index(int new_selection);
  196.  int monitor_get_relative_x(HSMonitor* m, int x_root);
  197.  int monitor_get_relative_y(HSMonitor* m, int y_root);
  198.  int monitor_index_of(HSMonitor* monitor);
  199.  int monitor_cycle_command(int argc, char** argv);
  200.  int monitor_focus_command(int argc, char** argv);
  201. +int find_monitor_index_by_name(char* name);
  202. +HSMonitor* find_monitor_by_name(char* name);
  203.  int add_monitor_command(int argc, char** argv, GString* output);
  204.  int monitor_raise_command(int argc, char** argv, GString* output);
  205.  int remove_monitor_command(int argc, char** argv, GString* output);
  206. --
  207. 1.8.0.1
  208.  
  209.  
  210. From 0bcac4e4a558843c15308f03776ec61a1df31a3c Mon Sep 17 00:00:00 2001
  211. From: Florian Bruhin <git@the-compiler.org>
  212. Date: Mon, 26 Nov 2012 00:27:30 +0100
  213. Subject: [PATCH 2/9] Add monitor names to stack command
  214.  
  215. ---
  216. src/stack.c | 9 ++++++++-
  217.  1 file changed, 8 insertions(+), 1 deletion(-)
  218.  
  219. diff --git a/src/stack.c b/src/stack.c
  220. index 5915e89..5ca8e61 100644
  221. --- a/src/stack.c
  222. +++ b/src/stack.c
  223. @@ -108,6 +108,7 @@ void stack_remove_slice(HSStack* s, HSSlice* elem) {
  224.  
  225.  static void slice_append_caption(HSTree root, GString* output) {
  226.      HSSlice* slice = (HSSlice*)root;
  227. +    GString* monitor_name = g_string_new("");
  228.      switch (slice->type) {
  229.          case SLICE_WINDOW:
  230.              g_string_append_printf(output, "Window 0x%lx",
  231. @@ -119,11 +120,17 @@ static void slice_append_caption(HSTree root, GString* output) {
  232.                                     slice->data.client->title->str);
  233.              break;
  234.          case SLICE_MONITOR:
  235. -            g_string_append_printf(output, "Monitor %d with tag \"%s\"",
  236. +            if (slice->data.monitor->name != NULL) {
  237. +                g_string_append_printf(monitor_name, " (\"%s\")",
  238. +                                       slice->data.monitor->name->str);
  239. +            }
  240. +            g_string_append_printf(output, "Monitor %d%s with tag \"%s\"",
  241.                                     monitor_index_of(slice->data.monitor),
  242. +                                   monitor_name->str,
  243.                                     slice->data.monitor->tag->name->str);
  244.              break;
  245.      }
  246. +    g_string_free(monitor_name, true);
  247.  }
  248.  
  249.  static struct HSTreeInterface slice_nth_child(HSTree root, size_t idx) {
  250. --
  251. 1.8.0.1
  252.  
  253.  
  254. From a5835e433b6c7ba31caa8f35f0cbf578b36f3d86 Mon Sep 17 00:00:00 2001
  255. From: Florian Bruhin <git@the-compiler.org>
  256. Date: Mon, 26 Nov 2012 07:12:42 +0100
  257. Subject: [PATCH 3/9] Add monitor names to list_monitors
  258.  
  259. ---
  260. MIGRATION            |  3 +++
  261.  doc/herbstluftwm.txt |  4 ++--
  262.  src/monitor.c        | 11 ++++++++++-
  263.  3 files changed, 15 insertions(+), 3 deletions(-)
  264.  
  265. diff --git a/MIGRATION b/MIGRATION
  266. index fe742af..c7e3e22 100644
  267. --- a/MIGRATION
  268. +++ b/MIGRATION
  269. @@ -15,6 +15,9 @@ been added instead. If you add a monitor with padding, instead of 'hc
  270.  add_monitor 1024x768+0+0 1 2 3 4' now use 'hc add_monitor 1024x768+0+0; hc pad N
  271.  1 2 3 4'.
  272.  
  273. +As a result from adding monitor names, the output of list_monitors and stack
  274. +changes a bit for named monitors.
  275. +
  276.  0.3 to 0.4
  277.  ~~~~~~~~~~
  278.  The setting window_gap is now called frame_gap. Simply replace all occurrences
  279. diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
  280. index 3a83172..18acfb0 100644
  281. --- a/doc/herbstluftwm.txt
  282. +++ b/doc/herbstluftwm.txt
  283. @@ -140,8 +140,8 @@ list_commands::
  284.      Lists all available commands.
  285.  
  286.  [[list_monitors]]list_monitors::
  287. -    List currently configured monitors with their index, area (as rectangle) and
  288. -    currently viewed tag.
  289. +    List currently configured monitors with their index, area (as rectangle),
  290. +    name (if named) and currently viewed tag.
  291.  
  292.  list_keybinds::
  293.      Lists all bound keys with their associated command. Each line consists of
  294. diff --git a/src/monitor.c b/src/monitor.c
  295. index 0605002..ed2b143 100644
  296. --- a/src/monitor.c
  297. +++ b/src/monitor.c
  298. @@ -104,16 +104,25 @@ int list_monitors(int argc, char** argv, GString* output) {
  299.      (void)argc;
  300.      (void)argv;
  301.      int i;
  302. +    GString* monitor_name = g_string_new("");
  303.      for (i = 0; i < g_monitors->len; i++) {
  304.          HSMonitor* monitor = monitor_with_index(i);
  305. -        g_string_append_printf(output, "%d: %dx%d%+d%+d with tag \"%s\"%s%s\n",
  306. +        if (monitor->name != NULL ) {
  307. +            g_string_printf(monitor_name, ", named \"%s\"",
  308. +                            monitor->name->str);
  309. +        } else {
  310. +            g_string_truncate(monitor_name, 0);
  311. +        }
  312. +        g_string_append_printf(output, "%d: %dx%d%+d%+d with tag \"%s\"%s%s%s\n",
  313.              i,
  314.              monitor->rect.width, monitor->rect.height,
  315.              monitor->rect.x, monitor->rect.y,
  316.              monitor->tag ? monitor->tag->name->str : "???",
  317. +            monitor_name->str,
  318.              (g_cur_monitor == i) ? " [FOCUS]" : "",
  319.              monitor->lock_tag ? " [LOCKED]" : "");
  320.      }
  321. +    g_string_free(monitor_name, true);
  322.      return 0;
  323.  }
  324.  
  325. --
  326. 1.8.0.1
  327.  
  328.  
  329. From c9a7cc5776f27374cd9b451f32cb3539dbb06ebb Mon Sep 17 00:00:00 2001
  330. From: Florian Bruhin <git@the-compiler.org>
  331. Date: Tue, 27 Nov 2012 22:17:07 +0100
  332. Subject: [PATCH 4/9] Add string_to_monitor/monitor_index functions
  333.  
  334. ---
  335. src/monitor.c | 35 +++++++++++++++++++++++++++++++++++
  336.  src/monitor.h |  2 ++
  337.  2 files changed, 37 insertions(+)
  338.  
  339. diff --git a/src/monitor.c b/src/monitor.c
  340. index ed2b143..13ab8bf 100644
  341. --- a/src/monitor.c
  342. +++ b/src/monitor.c
  343. @@ -351,6 +351,41 @@ HSMonitor* find_monitor_by_name(char* name) {
  344.      }
  345.  }
  346.  
  347. +int string_to_monitor_index(char* string) {
  348. +    int idx = -1;
  349. +    if (string[0] == '\0') {
  350. +        return -1;
  351. +    }
  352. +    if (isdigit(string[0])) {
  353. +        // monitor index
  354. +        idx = atoi(string);
  355. +        if (idx < 0 || idx >= g_monitors->len) {
  356. +            return -1;
  357. +        }
  358. +        return idx;
  359. +    } else {
  360. +        // monitor string
  361. +        return find_monitor_index_by_name(string);
  362. +    }
  363. +}
  364. +
  365. +HSMonitor* string_to_monitor(char* string) {
  366. +    if (string[0] == '\0') {
  367. +        return NULL;
  368. +    }
  369. +    if (isdigit(string[0])) {
  370. +        // monitor index
  371. +        int idx = atoi(string);
  372. +        if (idx < 0 || idx >= g_monitors->len) {
  373. +            return NULL;
  374. +        }
  375. +        return monitor_with_index(idx);
  376. +    } else {
  377. +        // monitor string
  378. +        return find_monitor_by_name(string);
  379. +    }
  380. +}
  381. +
  382.  HSMonitor* add_monitor(XRectangle rect, HSTag* tag, char* name) {
  383.      assert(tag != NULL);
  384.      HSMonitor* m = g_new0(HSMonitor, 1);
  385. diff --git a/src/monitor.h b/src/monitor.h
  386. index 0642601..c9eb6f4 100644
  387. --- a/src/monitor.h
  388. +++ b/src/monitor.h
  389. @@ -58,6 +58,8 @@ int monitor_cycle_command(int argc, char** argv);
  390.  int monitor_focus_command(int argc, char** argv);
  391.  int find_monitor_index_by_name(char* name);
  392.  HSMonitor* find_monitor_by_name(char* name);
  393. +HSMonitor* string_to_monitor(char* string);
  394. +int string_to_monitor_index(char* string);
  395.  int add_monitor_command(int argc, char** argv, GString* output);
  396.  int monitor_raise_command(int argc, char** argv, GString* output);
  397.  int remove_monitor_command(int argc, char** argv, GString* output);
  398. --
  399. 1.8.0.1
  400.  
  401.  
  402. From 9314919885b200fcff3711b291acf4dbd6cbb48e Mon Sep 17 00:00:00 2001
  403. From: Florian Bruhin <git@the-compiler.org>
  404. Date: Wed, 28 Nov 2012 23:19:12 +0100
  405. Subject: [PATCH 5/9] Make focus_monitor accept output
  406.  
  407. ---
  408. src/main.c    | 2 +-
  409.  src/monitor.c | 2 +-
  410.  src/monitor.h | 2 +-
  411.  3 files changed, 3 insertions(+), 3 deletions(-)
  412.  
  413. diff --git a/src/main.c b/src/main.c
  414. index 1dfea90..85f1b57 100644
  415. --- a/src/main.c
  416. +++ b/src/main.c
  417. @@ -116,7 +116,7 @@ CommandBinding g_commands[] = {
  418.      CMD_BIND(             "toggle",         settings_toggle),
  419.      CMD_BIND(             "cycle_value",    settings_cycle_value),
  420.      CMD_BIND_NO_OUTPUT(   "cycle_monitor",  monitor_cycle_command),
  421. -    CMD_BIND_NO_OUTPUT(   "focus_monitor",  monitor_focus_command),
  422. +    CMD_BIND(             "focus_monitor",  monitor_focus_command),
  423.      CMD_BIND(             "get",            settings_get),
  424.      CMD_BIND(             "add",            tag_add_command),
  425.      CMD_BIND(             "use",            monitor_set_tag_command),
  426. diff --git a/src/monitor.c b/src/monitor.c
  427. index 13ab8bf..61506f3 100644
  428. --- a/src/monitor.c
  429. +++ b/src/monitor.c
  430. @@ -769,7 +769,7 @@ int monitor_set_tag_by_index_command(int argc, char** argv, GString* output) {
  431.      return ret;
  432.  }
  433.  
  434. -int monitor_focus_command(int argc, char** argv) {
  435. +int monitor_focus_command(int argc, char** argv, GString* output) {
  436.      if (argc < 2) {
  437.          return HERBST_NEED_MORE_ARGS;
  438.      }
  439. diff --git a/src/monitor.h b/src/monitor.h
  440. index c9eb6f4..e4b8aff 100644
  441. --- a/src/monitor.h
  442. +++ b/src/monitor.h
  443. @@ -55,7 +55,7 @@ int monitor_get_relative_x(HSMonitor* m, int x_root);
  444.  int monitor_get_relative_y(HSMonitor* m, int y_root);
  445.  int monitor_index_of(HSMonitor* monitor);
  446.  int monitor_cycle_command(int argc, char** argv);
  447. -int monitor_focus_command(int argc, char** argv);
  448. +int monitor_focus_command(int argc, char** argv, GString* output);
  449.  int find_monitor_index_by_name(char* name);
  450.  HSMonitor* find_monitor_by_name(char* name);
  451.  HSMonitor* string_to_monitor(char* string);
  452. --
  453. 1.8.0.1
  454.  
  455.  
  456. From e661c15bc428aa1c0fab3f70fa60eafe31d10dda Mon Sep 17 00:00:00 2001
  457. From: Florian Bruhin <git@the-compiler.org>
  458. Date: Tue, 27 Nov 2012 23:06:58 +0100
  459. Subject: [PATCH 6/9] add monitor names to all commands using monitors
  460.  
  461. ---
  462. doc/herbstluftwm.txt | 55 ++++++++++++++++--------------
  463.  src/main.c           | 12 +++++--
  464.  src/monitor.c        | 94 ++++++++++++++++++++++++++++------------------------
  465.  3 files changed, 90 insertions(+), 71 deletions(-)
  466.  
  467. diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
  468. index 18acfb0..068b3e0 100644
  469. --- a/doc/herbstluftwm.txt
  470. +++ b/doc/herbstluftwm.txt
  471. @@ -117,8 +117,18 @@ Tags are very similar to workspaces, virtual desktops or window groups. Each
  472.  tag has one layout. There is a list of tags. You can add or remove tags
  473.  dynamically.
  474.  
  475. -There is also a list of monitors. Each monitor displays exactly one tag on a
  476. -specified rectangle on the screen.
  477. +[[MONITORS]]
  478. +MONITORS
  479. +--------
  480. +Monitors in *herbstluftwm* are totally independent of the actual physical
  481. +screens. This means you can for example split your screen in two virtual
  482. +monitors to view two tags at once on a big screen.
  483. +
  484. +Each monitor displays exactly one tag on a specified rectangle on the screen.
  485. +
  486. +A monitor can be referenced in two ways: by its 'INDEX' as listed in the
  487. +*list_monitors* command, or by a name defined when adding the monitor.
  488. +
  489.  
  490.  [[COMMANDS]]
  491.  COMMANDS
  492. @@ -399,9 +409,8 @@ cycle_value 'NAME' 'VALUES' ...::
  493.  cycle_monitor ['DELTA']::
  494.      Cycles monitor focused by 'DELTA'. 'DELTA' defaults to 1.
  495.  
  496. -focus_monitor 'INDEX'::
  497. -    Puts focus to monitor with specified 'INDEX' (as specified by the
  498. -    list_monitors command)
  499. +focus_monitor 'MONITOR'::
  500. +    Puts focus to specified monitor.
  501.  
  502.  add 'TAG'::
  503.      Creates a new empty tag named 'TAG'.
  504. @@ -434,8 +443,8 @@ move_index 'INDEX' [*--skip-visible*]::
  505.      treated relative. If *--skip-visible* is passed with a relative index, then
  506.      already visible tags are skipped.
  507.  
  508. -lock_tag ['INDEX']::
  509. -    Lock the tag switching on the monitor specified by INDEX. If no
  510. +lock_tag ['MONITOR']::
  511. +    Lock the tag switching on the specified monitor. If no
  512.      argument is given, the currently focused monitor is used. When the
  513.      tag switching is disabled for a monitor, the commands *use* and
  514.      *use_index* have no effect, when executed there. When
  515. @@ -444,8 +453,8 @@ lock_tag ['INDEX']::
  516.      stealing it from there. The lock state of a monitor is indicated
  517.      by "[LOCKED]" in the *list_monitors* output.
  518.  
  519. -unlock_tag ['INDEX']::
  520. -    Re-enables the tag switching on the monitor specified by INDEX. If no
  521. +unlock_tag ['MONITOR']::
  522. +    Re-enables the tag switching on the specified monitor. If no
  523.      argument is given, the currently focused  monitor is used. This is the reverse
  524.      operation to *lock_tag* and has no further side effects but removing this lock.
  525.  
  526. @@ -499,17 +508,15 @@ add_monitor 'RECT' ['TAG' ['NAME']]::
  527.          * add_monitor 1024x768-20+0 mynewtag main
  528.  
  529.  
  530. -remove_monitor 'INDEX'::
  531. -    Removes the monitor with specified 'INDEX'. Its 'INDEX' can be found out via
  532. -    the <<list_monitors,'list_monitors'>> command.
  533. +remove_monitor 'MONITOR'::
  534. +    Removes the specified monitor.
  535.  
  536. -move_monitor 'INDEX' 'RECT' ['PADUP' ['PADRIGHT' ['PADDOWN' ['PADLEFT']]]]::
  537. -    Moves the monitor with specified 'INDEX' to rectangle 'RECT'. 'INDEX' and
  538. -    'RECT' are defined as in 'remove_monitor' and 'add_monitor'. If no or an
  539. -    empty pad is given, it is not changed.
  540. +move_monitor 'MONITOR' 'RECT' ['PADUP' ['PADRIGHT' ['PADDOWN' ['PADLEFT']]]]::
  541. +    Moves the specified monitor to rectangle 'RECT'. 'RECT' is defined as in
  542. +    'add_monitor'. If no or an empty pad is given, it is not changed.
  543.  
  544. -raise_monitor ['INDEX']::
  545. -    Raises the monitor with the given 'INDEX' or the current one if 'INDEX' is
  546. +raise_monitor ['MONITOR']::
  547. +    Raises the specified monitor or the current one if 'MONITOR' is
  548.      omitted.
  549.  
  550.  stack::
  551. @@ -517,15 +524,15 @@ stack::
  552.      tree. The order printed stack is top to bottom. The style is configured by
  553.      the 'tree_style' setting.
  554.  
  555. -monitor_rect [[-p] 'INDEX']::
  556. -    Prints the rectangle of the specified 'INDEX' in the format: *X Y W H* +
  557. -    If no 'INDEX' or 'cur' is given, then the current Monitor is used. If '-p'
  558. +monitor_rect [[-p] 'MONITOR']::
  559. +    Prints the rectangle of the specified monitor in the format: *X Y W H* +
  560. +    If no 'MONITOR' or 'cur' is given, then the current Monitor is used. If '-p'
  561.      is supplied, then the remaining rect without the pad around this monitor
  562.      is printed.
  563.  
  564. -pad 'INDEX' ['PADUP' ['PADRIGHT' ['PADDOWN' ['PADLEFT']]]]::
  565. -    Sets the pad of indexed monitor to the specified padding. If no or an empty
  566. -    padding is given, it is not changed.
  567. +pad 'MONITOR' ['PADUP' ['PADRIGHT' ['PADDOWN' ['PADLEFT']]]]::
  568. +    Sets the pad of specified monitor to the specified padding. If no or an
  569. +    empty padding is given, it is not changed.
  570.  
  571.  list_padding::
  572.      Lists the padding of all monitors.
  573. diff --git a/src/main.c b/src/main.c
  574. index 85f1b57..ddee5e5 100644
  575. --- a/src/main.c
  576. +++ b/src/main.c
  577. @@ -258,13 +258,19 @@ int load_command(int argc, char** argv, GString* output) {
  578.  }
  579.  
  580.  int print_tag_status_command(int argc, char** argv, GString* output) {
  581. +    HSMonitor* monitor;
  582.      int monitor_index = g_cur_monitor;
  583.      if (argc >= 2) {
  584. -        monitor_index = atoi(argv[1]);
  585. +        monitor = string_to_monitor(argv[1]);
  586. +    } else {
  587. +        monitor = monitor_with_index(g_cur_monitor);
  588. +    }
  589. +    if (monitor == NULL) {
  590. +        g_string_append_printf(output,
  591. +            "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]);
  592. +        return HERBST_INVALID_ARGUMENT;
  593.      }
  594. -    monitor_index = CLAMP(monitor_index, 0, monitor_count() - 1);
  595.      tag_update_flags();
  596. -    HSMonitor* monitor = monitor_with_index(monitor_index);
  597.      g_string_append_c(output, '\t');
  598.      for (int i = 0; i < g_tags->len; i++) {
  599.          HSTag* tag = g_array_index(g_tags, HSTag*, i);
  600. diff --git a/src/monitor.c b/src/monitor.c
  601. index 61506f3..3ce76b4 100644
  602. --- a/src/monitor.c
  603. +++ b/src/monitor.c
  604. @@ -462,7 +462,12 @@ int remove_monitor_command(int argc, char** argv, GString* output) {
  605.      if (argc < 2) {
  606.          return HERBST_NEED_MORE_ARGS;
  607.      }
  608. -    int index = atoi(argv[1]);
  609. +    int index = string_to_monitor_index(argv[1]);
  610. +    if (index == -1) {
  611. +        g_string_append_printf(output,
  612. +            "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]);
  613. +        return HERBST_INVALID_ARGUMENT;
  614. +    }
  615.      int ret = remove_monitor(index);
  616.      if (ret == HERBST_INVALID_ARGUMENT) {
  617.          g_string_append_printf(output,
  618. @@ -512,10 +517,10 @@ int move_monitor_command(int argc, char** argv, GString* output) {
  619.      if (argc < 3) {
  620.          return HERBST_NEED_MORE_ARGS;
  621.      }
  622. -    int index = atoi(argv[1]);
  623. -    if (index < 0 || index >= g_monitors->len) {
  624. +    HSMonitor* monitor = string_to_monitor(argv[1]);
  625. +    if (monitor == NULL) {
  626.          g_string_append_printf(output,
  627. -            "%s: Index %i is out of range\n", argv[0], index);
  628. +            "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]);
  629.          return HERBST_INVALID_ARGUMENT;
  630.      }
  631.      XRectangle rect = parse_rectangle(argv[2]);
  632. @@ -525,7 +530,6 @@ int move_monitor_command(int argc, char** argv, GString* output) {
  633.          return HERBST_INVALID_ARGUMENT;
  634.      }
  635.      // else: just move it:
  636. -    HSMonitor* monitor = monitor_with_index(index);
  637.      monitor->rect = rect;
  638.      if (argc > 3 && argv[3][0] != '\0') monitor->pad_up       = atoi(argv[3]);
  639.      if (argc > 4 && argv[4][0] != '\0') monitor->pad_right    = atoi(argv[4]);
  640. @@ -537,17 +541,17 @@ int move_monitor_command(int argc, char** argv, GString* output) {
  641.  
  642.  int monitor_rect_command(int argc, char** argv, GString* output) {
  643.      // usage: monitor_rect [[-p] INDEX]
  644. -    char* index_str = NULL;
  645. +    char* monitor_str = NULL;
  646.      HSMonitor* m = NULL;
  647.      bool with_pad = false;
  648.  
  649. -    // if index is supplied
  650. +    // if monitor is supplied
  651.      if (argc > 1) {
  652. -        index_str = argv[1];
  653. +        monitor_str = argv[1];
  654.      }
  655.      // if -p is supplied
  656.      if (argc > 2) {
  657. -        index_str = argv[2];
  658. +        monitor_str = argv[2];
  659.          if (!strcmp("-p", argv[1])) {
  660.              with_pad = true;
  661.          } else {
  662. @@ -557,19 +561,14 @@ int monitor_rect_command(int argc, char** argv, GString* output) {
  663.          }
  664.      }
  665.      // if an index is set
  666. -    if (index_str) {
  667. -        int index;
  668. -        if (1 == sscanf(index_str, "%d", &index)) {
  669. -            m = monitor_with_index(index);
  670. -            if (!m) {
  671. -                g_string_append_printf(output,
  672. -                    "%s: Invalid index \"%s\"\n", argv[0], index_str);
  673. -                return HERBST_INVALID_ARGUMENT;
  674. -            }
  675. +    if (monitor_str) {
  676. +        m = string_to_monitor(monitor_str);
  677. +        if (m == NULL) {
  678. +            g_string_append_printf(output,
  679. +                "%s: Monitor \"%s\" not found!\n", argv[0], monitor_str);
  680. +            return HERBST_INVALID_ARGUMENT;
  681.          }
  682. -    }
  683. -
  684. -    if (!m) {
  685. +    } else {
  686.          m = get_current_monitor();
  687.      }
  688.      XRectangle rect = m->rect;
  689. @@ -588,13 +587,12 @@ int monitor_set_pad_command(int argc, char** argv, GString* output) {
  690.      if (argc < 2) {
  691.          return HERBST_NEED_MORE_ARGS;
  692.      }
  693. -    int index = atoi(argv[1]);
  694. -    if (index < 0 || index >= g_monitors->len) {
  695. +    HSMonitor* monitor = string_to_monitor(argv[1]);
  696. +    if (monitor == NULL) {
  697.          g_string_append_printf(output,
  698. -            "%s: Index %i is out of range\n", argv[0], index);
  699. +            "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]);
  700.          return HERBST_INVALID_ARGUMENT;
  701.      }
  702. -    HSMonitor* monitor = monitor_with_index(index);
  703.      if (argc > 2 && argv[2][0] != '\0') monitor->pad_up       = atoi(argv[2]);
  704.      if (argc > 3 && argv[3][0] != '\0') monitor->pad_right    = atoi(argv[3]);
  705.      if (argc > 4 && argv[4][0] != '\0') monitor->pad_down     = atoi(argv[4]);
  706. @@ -773,7 +771,12 @@ int monitor_focus_command(int argc, char** argv, GString* output) {
  707.      if (argc < 2) {
  708.          return HERBST_NEED_MORE_ARGS;
  709.      }
  710. -    int new_selection = atoi(argv[1]);
  711. +    int new_selection = string_to_monitor_index(argv[1]);
  712. +    if (new_selection == -1) {
  713. +        g_string_append_printf(output,
  714. +            "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]);
  715. +        return HERBST_INVALID_ARGUMENT;
  716. +    }
  717.      // really change selection
  718.      monitor_focus_by_index(new_selection);
  719.      return 0;
  720. @@ -934,35 +937,37 @@ void monitors_lock_changed() {
  721.  }
  722.  
  723.  int monitor_lock_tag_command(int argc, char** argv, GString* output) {
  724. +    char* cmd_name = argv[0];
  725.      (void)SHIFT(argc, argv);
  726.      HSMonitor *monitor;
  727.      if (argc >= 1) {
  728. -        monitor = monitor_with_index(atoi(argv[0]));
  729. +        monitor = string_to_monitor(argv[0]);
  730. +        if (monitor == NULL) {
  731. +            g_string_append_printf(output,
  732. +                "%s: Monitor \"%s\" not found!\n", cmd_name, argv[0]);
  733. +            return HERBST_INVALID_ARGUMENT;
  734. +        }
  735.      } else {
  736.          monitor = get_current_monitor();
  737.      }
  738. -    if (!monitor) {
  739. -        g_string_append_printf(output,
  740. -            "%s: Invalid monitor\n", argv[0]);
  741. -        return HERBST_INVALID_ARGUMENT;
  742. -    }
  743.      monitor->lock_tag = true;
  744.      return 0;
  745.  }
  746.  
  747.  int monitor_unlock_tag_command(int argc, char** argv, GString* output) {
  748. +    char* cmd_name = argv[0];
  749.      (void)SHIFT(argc, argv);
  750.      HSMonitor *monitor;
  751.      if (argc >= 1) {
  752. -        monitor = monitor_with_index(atoi(argv[0]));
  753. +        monitor = string_to_monitor(argv[0]);
  754. +        if (monitor == NULL) {
  755. +            g_string_append_printf(output,
  756. +                "%s: Monitor \"%s\" not found!\n", cmd_name, argv[0]);
  757. +            return HERBST_INVALID_ARGUMENT;
  758. +        }
  759.      } else {
  760.          monitor = get_current_monitor();
  761.      }
  762. -    if (!monitor) {
  763. -        g_string_append_printf(output,
  764. -            "%s: Invalid monitor\n", argv[0]);
  765. -        return HERBST_INVALID_ARGUMENT;
  766. -    }
  767.      monitor->lock_tag = false;
  768.      return 0;
  769.  }
  770. @@ -1070,18 +1075,19 @@ HSStack* get_monitor_stack() {
  771.  }
  772.  
  773.  int monitor_raise_command(int argc, char** argv, GString* output) {
  774. +    char* cmd_name = argv[0];
  775.      (void)SHIFT(argc, argv);
  776.      HSMonitor* monitor;
  777.      if (argc >= 1) {
  778. -        monitor = monitor_with_index(atoi(argv[0]));
  779. +        monitor = string_to_monitor(argv[0]);
  780. +        if (monitor == NULL) {
  781. +            g_string_append_printf(output,
  782. +                "%s: Monitor \"%s\" not found!\n", cmd_name, argv[0]);
  783. +            return HERBST_INVALID_ARGUMENT;
  784. +        }
  785.      } else {
  786.          monitor = get_current_monitor();
  787.      }
  788. -    if (!monitor) {
  789. -        g_string_append_printf(output,
  790. -            "%s: Invalid monitor\n", argv[0]);
  791. -        return HERBST_INVALID_ARGUMENT;
  792. -    }
  793.      stack_raise_slide(g_monitor_stack, monitor->slice);
  794.      return 0;
  795.  }
  796. --
  797. 1.8.0.1
  798.  
  799.  
  800. From 47cef5ec25828c3feaa19d895beafae03544b12d Mon Sep 17 00:00:00 2001
  801. From: Florian Bruhin <git@the-compiler.org>
  802. Date: Tue, 27 Nov 2012 23:18:04 +0100
  803. Subject: [PATCH 7/9] Add monitor argument to list_padding
  804.  
  805. ---
  806. MIGRATION            |  3 ++-
  807.  doc/herbstluftwm.txt |  5 +++--
  808.  src/command.c        |  2 +-
  809.  src/monitor.c        | 26 +++++++++++++++-----------
  810.  4 files changed, 21 insertions(+), 15 deletions(-)
  811.  
  812. diff --git a/MIGRATION b/MIGRATION
  813. index c7e3e22..17b4ecc 100644
  814. --- a/MIGRATION
  815. +++ b/MIGRATION
  816. @@ -16,7 +16,8 @@ add_monitor 1024x768+0+0 1 2 3 4' now use 'hc add_monitor 1024x768+0+0; hc pad N
  817.  1 2 3 4'.
  818.  
  819.  As a result from adding monitor names, the output of list_monitors and stack
  820. -changes a bit for named monitors.
  821. +changes a bit for named monitors. list_padding only outputs the padding for one
  822. +monitor now.
  823.  
  824.  0.3 to 0.4
  825.  ~~~~~~~~~~
  826. diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
  827. index 068b3e0..38b1c6f 100644
  828. --- a/doc/herbstluftwm.txt
  829. +++ b/doc/herbstluftwm.txt
  830. @@ -534,8 +534,9 @@ pad 'MONITOR' ['PADUP' ['PADRIGHT' ['PADDOWN' ['PADLEFT']]]]::
  831.      Sets the pad of specified monitor to the specified padding. If no or an
  832.      empty padding is given, it is not changed.
  833.  
  834. -list_padding::
  835. -    Lists the padding of all monitors.
  836. +list_padding ['MONITOR']::
  837. +    Lists the padding of the specified monitor, or the currently focused monitor
  838. +    if no monitor is given.
  839.  
  840.  layout ['TAG' ['INDEX']]::
  841.      Prints the layout of frame with 'INDEX' in 'TAG', in a nice tree style.
  842. diff --git a/src/command.c b/src/command.c
  843. index d2e5073..cb057be 100644
  844. --- a/src/command.c
  845. +++ b/src/command.c
  846. @@ -103,7 +103,7 @@ struct {
  847.      { "stack",          2,  no_completion },
  848.      { "monitor_rect",   3,  no_completion },
  849.      { "pad",            6,  no_completion },
  850. -    { "list_padding",   1,  no_completion },
  851. +    { "list_padding",   2,  no_completion },
  852.      { "layout",         3,  no_completion },
  853.      { "dump",           3,  no_completion },
  854.      { "load",           3,  no_completion },
  855. diff --git a/src/monitor.c b/src/monitor.c
  856. index 3ce76b4..72036fa 100644
  857. --- a/src/monitor.c
  858. +++ b/src/monitor.c
  859. @@ -127,18 +127,22 @@ int list_monitors(int argc, char** argv, GString* output) {
  860.  }
  861.  
  862.  int list_padding(int argc, char** argv, GString* output) {
  863. -    (void)argc;
  864. -    (void)argv;
  865. -    int i;
  866. -    for (i = 0; i < g_monitors->len; i++) {
  867. -        HSMonitor* monitor = monitor_with_index(i);
  868. -        g_string_append_printf(output, "%d: %d %d %d %d\n",
  869. -            i,
  870. -            monitor->pad_up,
  871. -            monitor->pad_right,
  872. -            monitor->pad_down,
  873. -            monitor->pad_left);
  874. +    HSMonitor* monitor;
  875. +    if (argc < 2) {
  876. +        monitor = get_current_monitor();
  877. +    } else {
  878. +        monitor = string_to_monitor(argv[1]);
  879. +        if (monitor == NULL) {
  880. +            g_string_append_printf(output,
  881. +                "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]);
  882. +            return HERBST_INVALID_ARGUMENT;
  883. +        }
  884.      }
  885. +    g_string_append_printf(output, "%d %d %d %d\n",
  886. +        monitor->pad_up,
  887. +        monitor->pad_right,
  888. +        monitor->pad_down,
  889. +        monitor->pad_left);
  890.      return 0;
  891.  }
  892.  
  893. --
  894. 1.8.0.1
  895.  
  896.  
  897. From fe10f3a86c5dc7e5112624c23449acb00aef4f30 Mon Sep 17 00:00:00 2001
  898. From: Florian Bruhin <git@the-compiler.org>
  899. Date: Wed, 28 Nov 2012 00:11:32 +0100
  900. Subject: [PATCH 8/9] Add new command name_monitor
  901.  
  902. ---
  903. NEWS                 |  2 +-
  904.  doc/herbstluftwm.txt |  4 ++++
  905.  src/command.c        |  1 +
  906.  src/main.c           |  1 +
  907.  src/monitor.c        | 38 ++++++++++++++++++++++++++++++++++++++
  908.  src/monitor.h        |  1 +
  909.  6 files changed, 46 insertions(+), 1 deletion(-)
  910.  
  911. diff --git a/NEWS b/NEWS
  912. index 1af16af..3072bd9 100644
  913. --- a/NEWS
  914. +++ b/NEWS
  915. @@ -25,7 +25,7 @@ Changes:
  916.      * floating, fullscreen, pseudotile: default to toggle if no argument is
  917.        given
  918.      * add error messages for herbstclient
  919. -    * optional names for monitors
  920. +    * optional names for monitors, new command name_monitor
  921.  
  922.  Release: 0.4.1 on 2012-08-30
  923.  ----------------------------
  924. diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt
  925. index 38b1c6f..1e41ef7 100644
  926. --- a/doc/herbstluftwm.txt
  927. +++ b/doc/herbstluftwm.txt
  928. @@ -519,6 +519,10 @@ raise_monitor ['MONITOR']::
  929.      Raises the specified monitor or the current one if 'MONITOR' is
  930.      omitted.
  931.  
  932. +name_monitor 'MONITOR' 'NAME'::
  933. +    (Re)names an already existing monitor. If 'NAME' is empty, removes the
  934. +    monitor's name.
  935. +
  936.  stack::
  937.      Prints the stack of monitors with the visible tags and their layers as a
  938.      tree. The order printed stack is top to bottom. The style is configured by
  939. diff --git a/src/command.c b/src/command.c
  940. index cb057be..6bf3644 100644
  941. --- a/src/command.c
  942. +++ b/src/command.c
  943. @@ -97,6 +97,7 @@ struct {
  944.      { "unlock_tag",     2,  no_completion },
  945.      { "detect_monitors",1,  no_completion },
  946.      { "add_monitor",    7,  no_completion },
  947. +    { "name_monitor",   3,  no_completion },
  948.      { "remove_monitor", 2,  no_completion },
  949.      { "move_monitor",   7,  no_completion },
  950.      { "raise_monitor",  2,  no_completion },
  951. diff --git a/src/main.c b/src/main.c
  952. index ddee5e5..fecfbff 100644
  953. --- a/src/main.c
  954. +++ b/src/main.c
  955. @@ -135,6 +135,7 @@ CommandBinding g_commands[] = {
  956.      CMD_BIND(             "raise_monitor",  monitor_raise_command),
  957.      CMD_BIND(             "remove_monitor", remove_monitor_command),
  958.      CMD_BIND(             "move_monitor",   move_monitor_command),
  959. +    CMD_BIND(             "name_monitor",   name_monitor_command),
  960.      CMD_BIND(             "monitor_rect",   monitor_rect_command),
  961.      CMD_BIND(             "pad",            monitor_set_pad_command),
  962.      CMD_BIND(             "raise",          raise_command),
  963. diff --git a/src/monitor.c b/src/monitor.c
  964. index 72036fa..2e20408 100644
  965. --- a/src/monitor.c
  966. +++ b/src/monitor.c
  967. @@ -543,6 +543,44 @@ int move_monitor_command(int argc, char** argv, GString* output) {
  968.      return 0;
  969.  }
  970.  
  971. +int name_monitor_command(int argc, char** argv, GString* output) {
  972. +    if (argc < 3) {
  973. +        return HERBST_NEED_MORE_ARGS;
  974. +    }
  975. +    HSMonitor* mon = string_to_monitor(argv[1]);
  976. +    if (mon == NULL) {
  977. +        g_string_append_printf(output,
  978. +            "%s: Monitor \"%s\" not found!\n", argv[0], argv[1]);
  979. +        return HERBST_INVALID_ARGUMENT;
  980. +    }
  981. +    if (isdigit(argv[2][0])) {
  982. +        g_string_append_printf(output,
  983. +            "%s: The monitor name may not start with a number\n", argv[0]);
  984. +        return HERBST_INVALID_ARGUMENT;
  985. +    } else if (!strcmp("", argv[2])) {
  986. +        // empty name -> clear name
  987. +        if (mon->name != NULL) {
  988. +            g_string_free(mon->name, true);
  989. +            mon->name = NULL;
  990. +        }
  991. +        return 0;
  992. +    }
  993. +    if (find_monitor_by_name(argv[2])) {
  994. +        g_string_append_printf(output,
  995. +            "%s: A monitor with the same name already exists\n", argv[0]);
  996. +        return HERBST_INVALID_ARGUMENT;
  997. +    }
  998. +    if (mon->name == NULL) {
  999. +        // not named before
  1000. +        GString* name = g_string_new(argv[2]);
  1001. +        mon->name = name;
  1002. +    } else {
  1003. +        // already named
  1004. +        g_string_assign(mon->name, argv[2]);
  1005. +    }
  1006. +    return 0;
  1007. +}
  1008. +
  1009.  int monitor_rect_command(int argc, char** argv, GString* output) {
  1010.      // usage: monitor_rect [[-p] INDEX]
  1011.      char* monitor_str = NULL;
  1012. diff --git a/src/monitor.h b/src/monitor.h
  1013. index e4b8aff..c0ae845 100644
  1014. --- a/src/monitor.h
  1015. +++ b/src/monitor.h
  1016. @@ -70,6 +70,7 @@ int set_monitor_rects_command(int argc, char** argv, GString* output);
  1017.  int disjoin_rects_command(int argc, char** argv, GString* output);
  1018.  int set_monitor_rects(XRectangle* templates, size_t count);
  1019.  int move_monitor_command(int argc, char** argv, GString* output);
  1020. +int name_monitor_command(int argc, char** argv, GString* output);
  1021.  int monitor_rect_command(int argc, char** argv, GString* output);
  1022.  HSMonitor* get_current_monitor();
  1023.  int monitor_count();
  1024. --
  1025. 1.8.0.1
  1026.  
  1027.  
  1028. From bca32c6dcbba050aefe0346cc6423eda0c353741 Mon Sep 17 00:00:00 2001
  1029. From: Florian Bruhin <git@the-compiler.org>
  1030. Date: Wed, 28 Nov 2012 00:24:40 +0100
  1031. Subject: [PATCH 9/9] implement completion for monitor names
  1032.  
  1033. ---
  1034. src/command.c | 32 ++++++++++++++++++++++++++++++++
  1035.  src/command.h |  1 +
  1036.  src/monitor.c |  1 -
  1037.  src/monitor.h |  2 ++
  1038.  4 files changed, 35 insertions(+), 1 deletion(-)
  1039.  
  1040. diff --git a/src/command.c b/src/command.c
  1041. index 6bf3644..fee04b4 100644
  1042. --- a/src/command.c
  1043. +++ b/src/command.c
  1044. @@ -10,6 +10,7 @@
  1045.  #include "layout.h"
  1046.  #include "key.h"
  1047.  #include "clientlist.h"
  1048. +#include "monitor.h"
  1049.  
  1050.  #include <glib.h>
  1051.  #include <string.h>
  1052. @@ -101,6 +102,7 @@ struct {
  1053.      { "remove_monitor", 2,  no_completion },
  1054.      { "move_monitor",   7,  no_completion },
  1055.      { "raise_monitor",  2,  no_completion },
  1056. +    { "name_monitor",   3,  no_completion },
  1057.      { "stack",          2,  no_completion },
  1058.      { "monitor_rect",   3,  no_completion },
  1059.      { "pad",            6,  no_completion },
  1060. @@ -194,6 +196,17 @@ struct {
  1061.      { "use",            EQ, 1,  .function = complete_against_tags },
  1062.      { "use_index",      EQ, 1,  .list = completion_pm_one },
  1063.      { "use_index",      EQ, 2,  .list = completion_use_index_args },
  1064. +    { "focus_monitor",  EQ, 1,  .function = complete_against_monitors },
  1065. +    { "lock_tag",       EQ, 1,  .function = complete_against_monitors },
  1066. +    { "unlock_tag",     EQ, 1,  .function = complete_against_monitors },
  1067. +    { "remove_monitor", EQ, 1,  .function = complete_against_monitors },
  1068. +    { "move_monitor",   EQ, 1,  .function = complete_against_monitors },
  1069. +    { "raise_monitor",  EQ, 1,  .function = complete_against_monitors },
  1070. +    { "name_monitor",   EQ, 1,  .function = complete_against_monitors },
  1071. +    { "monitor_rect",   EQ, 1,  .function = complete_against_monitors },
  1072. +    { "pad",            EQ, 1,  .function = complete_against_monitors },
  1073. +    { "list_padding",   EQ, 1,  .function = complete_against_monitors },
  1074. +    { "tag_status",     EQ, 1,  .function = complete_against_monitors },
  1075.      { 0 },
  1076.  };
  1077.  
  1078. @@ -272,6 +285,25 @@ void complete_against_tags(int argc, char** argv, int pos, GString* output) {
  1079.      }
  1080.  }
  1081.  
  1082. +void complete_against_monitors(int argc, char** argv, int pos, GString* output) {
  1083. +    char* needle;
  1084. +    if (pos >= argc) {
  1085. +        needle = "";
  1086. +    } else {
  1087. +        needle = argv[pos];
  1088. +    }
  1089. +    size_t len = strlen(needle);
  1090. +    for (int i = 0; i < g_monitors->len; i++) {
  1091. +        GString* name = g_array_index(g_monitors, HSMonitor*, i)->name;
  1092. +        if (name != NULL) {
  1093. +            if (!strncmp(needle, name->str, len)) {
  1094. +                g_string_append(output, name->str);
  1095. +                g_string_append(output, "\n");
  1096. +            }
  1097. +        }
  1098. +    }
  1099. +}
  1100. +
  1101.  struct wcd { /* window id completion data */
  1102.      char* needle;
  1103.      size_t needlelen;
  1104. diff --git a/src/command.h b/src/command.h
  1105. index 200420a..cdbe3cd 100644
  1106. --- a/src/command.h
  1107. +++ b/src/command.h
  1108. @@ -43,6 +43,7 @@ int complete_command(int argc, char** argv, GString* output);
  1109.  void complete_settings(char* str, GString* output);
  1110.  void complete_against_list(char* needle, char** list, GString* output);
  1111.  void complete_against_tags(int argc, char** argv, int pos, GString* output);
  1112. +void complete_against_monitors(int argc, char** argv, int pos, GString* output);
  1113.  void complete_against_winids(int argc, char** argv, int pos, GString* output);
  1114.  void complete_merge_tag(int argc, char** argv, int pos, GString* output);
  1115.  void complete_against_settings(int argc, char** argv, int pos, GString* output);
  1116. diff --git a/src/monitor.c b/src/monitor.c
  1117. index 2e20408..ac62410 100644
  1118. --- a/src/monitor.c
  1119. +++ b/src/monitor.c
  1120. @@ -30,7 +30,6 @@ int* g_swap_monitors_to_get_tag;
  1121.  int* g_smart_frame_surroundings;
  1122.  int* g_mouse_recenter_gap;
  1123.  HSStack* g_monitor_stack;
  1124. -GArray*     g_monitors; // Array of HSMonitor*
  1125.  
  1126.  typedef struct RectList {
  1127.      XRectangle rect;
  1128. diff --git a/src/monitor.h b/src/monitor.h
  1129. index c0ae845..f9f1673 100644
  1130. --- a/src/monitor.h
  1131. +++ b/src/monitor.h
  1132. @@ -18,6 +18,8 @@ struct HSFrame;
  1133.  struct HSSlice;
  1134.  struct HSStack;
  1135.  
  1136. +GArray*     g_monitors; // Array of HSMonitor*
  1137. +
  1138.  typedef struct HSMonitor {
  1139.      struct HSTag*      tag;    // currently viewed tag
  1140.      struct HSSlice*    slice;  // slice in the monitor stack
  1141. --
  1142. 1.8.0.1
  1143.