[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Monitor objects per monitor-index
- To: Florian Bruhin <me _at_ the _minus_ compiler _dot_ org>
- Subject: Re: [PATCH] Monitor objects per monitor-index
- From: Thorsten Wißmann <edu _at_ thorsten _minus_ wissmann _dot_ de>
- Date: Mon, 24 Jun 2013 13:03:32 +0200
Hi Florian,
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.
But if you add some monitors and remove the monitor with index 0, then
you have to update all names because all indices after the removed
monitor decrease by 1. (That's the ugly part and the reason I did not
implement it yet)
> diff --git a/src/monitor.c b/src/monitor.c
> @@ -416,6 +416,16 @@ HSMonitor* add_monitor(XRectangle rect, HSTag* tag, char* name) {
>
> stack_insert_slice(g_monitor_stack, m->slice);
> g_array_append_val(g_monitors, m);
> +
> + GString* index_str = g_string_new("");
> + int index = monitor_index_of(m);
> +
> + if (index >= 0) {
> + g_string_printf(index_str, "%d", monitor_index_of(m));
> + hsobject_link(g_monitor_object, &m->object, index_str->str);
> + g_string_free(index_str, true);
> + }
You can assume that index >= 0 and you do not even need checking it. The
new monitor is appended to the g_monitors array, and thus has index
g_monitors->len-1, which is already used here:
> return g_array_index(g_monitors, HSMonitor*, g_monitors->len-1);
> }
Regards,
Thorsten
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev