* Thorsten Wißmann <edu _at_ thorsten _minus_ wissmann _dot_ de> [2013-06-24 13:03:32 +0200]: > On Thu, Jun 20, 2013 at 10:40:17PM +0200, Florian Bruhin wrote: > > This patch adds monitor objects to be able to access them by their > > index if they are unnamed. > > Did you forget to add some hunks in the patch? Because this only adds a > link when a new monitor is added and never renames them. > [...] This should now all be fixed in the attached new patch. Tested it by adding and removing a few monitors and it works so far. It unlinks and re-links all id objects when a monitor is removed, as discussed in IRC. Also, the second patch uses the new monitor_foreach function for all_monitors_apply_layout as well. Florian -- () ascii ribbon campaign - stop html mail www.asciiribbon.org /\ www.the-compiler.org | I love long mails http://email.is-not-s.ms/ What this country needs is a good five cent microcomputer.
From a4dc9bc17e90223a2a531c5db59f2113910efe24 Mon Sep 17 00:00:00 2001 From: Florian Bruhin <git _at_ the _minus_ compiler _dot_ org> Date: Tue, 18 Jun 2013 17:51:31 +0200 Subject: [PATCH 1/2] Add objects monitors.* to access monitors per id --- doc/herbstluftwm.txt | 1 + src/monitor.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/doc/herbstluftwm.txt b/doc/herbstluftwm.txt index 669dd9b..1106d4a 100644 --- a/doc/herbstluftwm.txt +++ b/doc/herbstluftwm.txt @@ -1273,6 +1273,7 @@ listed as follows: ** +focus+: the object of the focused client, if any * +monitors+ + ** 'ID': a object for each monitor with its 'ID' + ** +by-name+ *** 'NAME': a object for each named monitor + + diff --git a/src/monitor.c b/src/monitor.c index f583939..19f6821 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -391,6 +391,30 @@ static void monitor_attr_tag(void* data, GString* output) { g_string_append(output, m->tag->display_name->str); } +static void monitor_foreach(void (*action)(HSMonitor*)) { + for (int i = 0; i < g_monitors->len; i++) { + HSMonitor* m = monitor_with_index(i); + action(m); + } +} + +static void monitor_unlink_id_object(HSMonitor* m) { + hsobject_unlink(g_monitor_object, &m->object); +} + +static void monitor_link_id_object(HSMonitor* m) { + GString* index_str = g_string_new(""); + int index = monitor_index_of(m); + g_string_printf(index_str, "%d", index); + hsobject_link(g_monitor_object, &m->object, index_str->str); + g_string_free(index_str, true); +} + +static void monitor_update_id_objects() { + monitor_foreach(monitor_unlink_id_object); + monitor_foreach(monitor_link_id_object); +} + HSMonitor* add_monitor(XRectangle rect, HSTag* tag, char* name) { assert(tag != NULL); HSMonitor* m = g_new0(HSMonitor, 1); @@ -422,6 +446,8 @@ HSMonitor* add_monitor(XRectangle rect, HSTag* tag, char* name) { stack_insert_slice(g_monitor_stack, m->slice); g_array_append_val(g_monitors, m); + monitor_link_id_object(m); + return g_array_index(g_monitors, HSMonitor*, g_monitors->len-1); } @@ -532,6 +558,7 @@ int remove_monitor(int index) { g_string_free(monitor->display_name, true); g_free(monitor); g_array_remove_index(g_monitors, index); + monitor_update_id_objects(); if (g_cur_monitor >= g_monitors->len) { g_cur_monitor--; // if selection has changed, then relayout focused monitor -- 1.8.4
From 631cddfe2325e2bbed88fca66d5e746e95188a12 Mon Sep 17 00:00:00 2001 From: Florian Bruhin <git _at_ the _minus_ compiler _dot_ org> Date: Sun, 6 Oct 2013 00:45:42 +0200 Subject: [PATCH 2/2] Use monitors_foreach for all_monitors_apply_layout --- src/monitor.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/monitor.c b/src/monitor.c index 19f6821..32878be 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -752,10 +752,7 @@ int monitor_count() { } void all_monitors_apply_layout() { - for (int i = 0; i < g_monitors->len; i++) { - HSMonitor* m = monitor_with_index(i); - monitor_apply_layout(m); - } + monitor_foreach(monitor_apply_layout); } int monitor_set_tag(HSMonitor* monitor, HSTag* tag) { -- 1.8.4
Attachment:
pgp4D9xn1BOZ5.pgp
Description: PGP signature