Bug 1006 - duplicate window title numbering is so-so
Status: CLOSED FIXED
Alias: None
Product: Openbox
Classification: Unclassified
Component: general
Version: 3.0-rc4
Hardware: All Linux
: P2 minor
Assignee: Dana Jansens
QA Contact:
URL:
Depends on:
Blocks:
 
Reported: 2003-11-07 15:27 EST by logan
Modified: 2007-03-18 11:34:30 EDT
1 user (show)

See Also:


Attachments
patch v1 (1.32 KB, patch)
2003-11-08 22:56 EST, logan

Description logan 2003-11-07 15:27:17 EST
I don't know if there's a reason why strncmp() is used on window titles when
trying to determine if a number should be append to the title (eg, xterm - [2]).
Maybe there's some special case you are trying to catch, or a general
"<application name>: something" match?

If I have a program, 'yadda', source is yadda.c... When editing yadda.c with
vim, the xterm title is changed to "yadda.c (~) - VIM". If you then run 'yadda',
the window is titled 'yadda - [2]'. Looks strange, was hunting around to see if
there was another copy running.

Perhaps it would be better to use strcmp() instead?

This is a feature I don't mind, but have very little interest in. Seems like
alotta work for something so trivial. Check the old title, check against every
window in the client list, then g_strdup_printf(), etc, etc...
Comment 1 Dana Jansens 2003-11-08 05:00:35 EST
If i didn't use strncmp then i'd be comparing window titles including the numbers :) 
Comment 2 Dana Jansens 2003-11-08 05:09:20 EST
If i didn't use strncmp then i'd be comparing window titles including the numbers :) 
 
I guess to do it right youd have to store the title without the number and use strcmp 
on it. but then apply the number when setting the text properties. Feel free if it 
bothers ya :) 
Comment 3 logan 2003-11-08 15:11:52 EST
ah duh heh.. that hadn't even occurred to me.

Well, how about something like..

    /* look for duplicates and append a number */
    nums = 0;
    for (it = client_list; it; it = g_list_next(it))
        if (it->data != self) {
            ObClient *c = it->data;
***         if (0 == strncmp(c->title, data, strlen(c->title) - 7 /* - [32] */))
                nums |= 1 << c->title_count;


Compare the other client title strings against the current window, minus (at
most) ' - [32]'. This isn't that great, but it would be better...


Also, setting the dupe window and icon titles are done a bit differently...

    if (self->title_count > 1) {
        gchar *ndata;
        ndata = g_strdup_printf("%s - [%u]", data, self->title_count);
        g_free(data);
        data = ndata;
    }

    if (read_title && self->title_count > 1) {
        gchar *vdata, *ndata;
        ndata = g_strdup_printf(" - [%u]", self->title_count);
        vdata = g_strconcat(data, ndata, NULL);
        g_free(ndata);
        g_free(data);
        data = vdata;
    }

Could probably just set the icon title the same way as the window title, without
the extra g_strconcat() call.
Comment 4 logan 2003-11-08 15:19:52 EST
Ugh, ok this doesn't work better. I just noticed windows with short titles
getting numbered incorrectly... Forget it :)
Comment 5 logan 2003-11-08 22:56:52 EST
Created attachment 133 [details]
patch v1

Without changing too much, you could do a g_strrstr(title, " - ["), truncate
the string, then strcmp(). The length of the remainder is checked to make sure
it's either 6 ( - [2]) or 7 ( - [32]) characters in length...  Trying to be
somewhat smart about which window titles to fiddle with, in case one would have
such a string in the window title but it's not actually openbox assigned.

Dunno if you had other ideas, but it's really starting to bother me now. Not
because I'm seeing the problem as explained before, but just b/c I know it's
there and it can be improved. :)

Thoughts?
Comment 6 Dana Jansens 2003-11-11 06:58:50 EST
Heh :) Store the window title sans the extra number, and only add it to the
string when setting the properties. Then you can strcmp.
Comment 7 logan 2003-11-11 13:27:19 EST
Hm, dunno..

Inside client_update_title() I tried setting self->title = <title_with_number>
before calling frame_adjust_title(), then back to <title_without_number>, but
when the window loses focus framerender_label() must be called again, as it
loses the numbered title. Guess I don't understand what you are saying...

You could store the unchanged window title in self->title_orig or such, strcmp()
that, or perhaps adjust the title string inside framerender_label()?
Comment 8 Dana Jansens 2003-11-11 17:36:29 EST
Could store them both, or could possibly provide

char* client_get_title (ObClient *c);

which would take the title in the struct and add any numbers etc to it and 
return a new string, then make the frame and the property stuff use it (and 
g_free it after its done).

Also, storing 2 strings in the struct is an option. As you can see I tried to 
avoid that one but its a little hacky now.
Comment 9 Dana Jansens 2007-03-04 02:41:48 EST
I think this is solved now in svn, and much simpler. Please let me know if otherwise...