Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed width #9

Open
wolfen351 opened this issue Aug 15, 2014 · 17 comments
Open

Fixed width #9

wolfen351 opened this issue Aug 15, 2014 · 17 comments

Comments

@wolfen351
Copy link

wolfen351 commented Aug 15, 2014

Hi there

Just a small feature request please - its a little distracting if the icons in the status bar jump around. It would be nice to be able to input a fixed width in pixels so the display stays in the same place.

Thanks!

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/3738957-fixed-width?utm_campaign=plugin&utm_content=tracker%2F1443743&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1443743&utm_medium=issues&utm_source=github).
@fossfreedom
Copy link
Owner

Hi,
I like this idea ... but the implementation may be rather challenging.

Application indicators do not use a fixed width font and the API (from a quick reading) doesnt appear to offer a way to display stuff at a fixed position in the panel.

Thus - the only "hack" I can think of is to convert the text being displayed to a png picture - instead of displaying text, the indicator would instead change its "icon" - the icon being the text png picture calculated to be a fixed width.

As I said - I like the idea - just not sure of the implementation.

Actually - changing the text to be a png does open up other opportunities such as changing the text colour - you cant change the text font colour for an app indicator - but you could in an icon - thus you could imagine a sensor meeting a certain threshold value being displayed in red etc.

@Bernmeister
Copy link
Contributor

I suspect that this will do the trick - setting a hint into the set_label() will stop the changing width.

@fossfreedom
Copy link
Owner

good find!

probably need to think through how this could apply to custom sensors - maybe some-sort of "[width=10]" type of statement that the indicator can interpret and set the hint.

The guide is just a simple text string

"

gchar*"label-guide"read/write

An optional string to provide guidance to the panel on how big the #AppIndicator:label string could get. If this is set correctly then the panel should never 'jiggle' as the string adjusts through out the range of options. For instance, if you were providing a percentage like "54% thrust" in #AppIndicator:label you'd want to set this string to "100% thrust" to ensure space when Scotty can get you enough power.
"

@fossfreedom
Copy link
Owner

looks like there is a bug in Unity App Indicator that makes this impossible to-do with the default API

@fossfreedom
Copy link
Owner

maybe able to pad strings with spaces something like this:

if(padding)
    {
        //render string and get its pixel width
        gint width = 0;
        static gint maxWidth = 20;   //max width for label in pixels
        //TODO: should be determined from current panel font type and size
        gint spaceWidth = 4;  //width of one space char in pixels,
        PangoContext* context = gtk_widget_get_pango_context( indicator_menu );
        PangoLayout* layout = pango_layout_new( context );
        pango_layout_set_text( layout, GSTR_GET(string), string->allocated_len );
        pango_layout_get_pixel_size( layout, &width, NULL );
        // frees the layout object, do not use after this point
        g_object_unref( layout );
        //push max size up as needed
        if (width > maxWidth) maxWidth = width + spaceWidth;
        //fill up with spaces
        GString * string_for_spaces;
        GSTR_INIT_TEXT( string_for_spaces, GSTR_GET(string) );
        g_string_printf( string, "%*s%s", (gint)((maxWidth-width)/spaceWidth), " ", GSTR_GET(string_for_spaces) );
        GSTR_FREE( string_for_spaces );
    }

may also be worth looking to provide an ordering index option so that we can make the indicator always appear on the left-hand-side of all indicators ... this will then stop the observed width changing issue

indicator = app_indicator_new( "netspeed", GSTR_GET(pic_network_idle), APP_INDICATOR_CATEGORY_SYSTEM_SERVICES );
    app_indicator_set_status( indicator, APP_INDICATOR_STATUS_ACTIVE );
    app_indicator_set_label( indicator, "netspeed", "netspeed" );
    app_indicator_set_menu( indicator, GTK_MENU(indicator_menu) );
    //set indicator position. default: all the way left
    //TODO: make this optional so placement can be automatic
    guint32 ordering_index = g_settings_get_int( settings, "ordering-index" );
    app_indicator_set_ordering_index( indicator, ordering_index );

examples above taken from https://github.com/GGleb/indicator-netspeed-unity/blob/master/indicator-netspeed-unity.c

@wolfen351
Copy link
Author

wolfen351 commented Oct 24, 2015

Ah thanks! Yeah that would be pretty awesome. For now I've found a config file that lets me move it all the way to the left.. It works for most things, except for eg. teamviewer that ignores the setting.. First prize is still to have the pixel setting (either the image implementation, or the padded spaces). I wonder if there is a really tiny unicode space that we could use to get the precision as close as possible to the desired width?

@wolfen351
Copy link
Author

This might be helpful: https://en.wikipedia.org/wiki/Thin_space

Further reading at https://en.wikipedia.org/wiki/Whitespace_character

It seems the narrowest space is the "HAIR_SPACE" U+200A hair space 8202

@fossfreedom
Copy link
Owner

that hair-space trick looks useful. Thanks for the info.

What config file are you using to move the indicator all the way to the left? - can you copy-paste here?

@fossfreedom
Copy link
Owner

sigh ... yet another bug with indicators - the set_ordering_index is ignored so cannot programmatically force the indicator to the left hand side. I presume you are talking about this file http://askubuntu.com/questions/26114/is-it-possible-to-change-the-order-of-icons-in-the-indicator-applet

I'll add that to the README for now

@wolfen351
Copy link
Author

Yes, that is the file i'm using.

@wolfen351
Copy link
Author

bump please tell me these is a solution on the horizon somewhere?

@fossfreedom
Copy link
Owner

well the workaround solution is a combination of your slim-line whitespace idea together with a python version of the snippet of code I described on the 23 Oct.

the fix would be applied to https://github.com/fossfreedom/indicator-sysmonitor/blob/master/indicator-sysmonitor - in the update method -

algorithm something like:

  1. calculate the space the string label currently takes.
  2. if the space is more than the proposed string label save the proposed string label space size in a variable
  3. if the space is less that the proposed string label then calculate how many "slim whitespace" chars is needed to get to the saved space size. Then append the proposed label with the number of whitespace chars.

Hoping here someone will chip in here with bit of code to do the above.

The real fix is to fix ubuntu's indicator implementation to respect the label size that @Bernmeister indicated right at the top of this chain.

@rcspam
Copy link

rcspam commented Apr 27, 2016

Hi @fossfreedom,
Cool indicator !
Have you update indicator-sysmonitor to awser to this issue ?
Thanks

@fossfreedom
Copy link
Owner

@rcspam - sorry - not a high priority at the moment - I've got other open-source projects on the go that are taking up my time.

As mentioned above ..."Hoping here someone will chip in here with bit of code to do the above."

@rcspam
Copy link

rcspam commented Apr 27, 2016

Ok ! thank you and sorry to not have possibility to help !

@pavelbrilliant
Copy link

Hi! This issue still exists. Could you fix this, please?
This issue turns into rearranging icons manually to the right after every new indicator installation.

Also it would be very useful (if possible) to have a custom update time for every parameter. For example - CPU frequency changes more often than disk space.

@fossfreedom
Copy link
Owner

@Pavel-Brilliant

As mentioned above ..."Hoping here someone will chip in here with bit of code to do the above."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants