{"action":"created","issue":{"url":"https://api.github.com/repos/mate-desktop/mate-applets/issues/268","repository_url":"https://api.github.com/repos/mate-desktop/mate-applets","labels_url":"https://api.github.com/repos/mate-desktop/mate-applets/issues/268/labels{/name}","comments_url":"https://api.github.com/repos/mate-desktop/mate-applets/issues/268/comments","events_url":"https://api.github.com/repos/mate-desktop/mate-applets/issues/268/events","html_url":"https://github.com/mate-desktop/mate-applets/issues/268","id":252728494,"number":268,"title":"cpufreq-applet: freq/units labels render partially or not at all","user":{"login":"dwtokarski","id":16522969,"avatar_url":"https://avatars0.githubusercontent.com/u/16522969?v=4","gravatar_id":"","url":"https://api.github.com/users/dwtokarski","html_url":"https://github.com/dwtokarski","followers_url":"https://api.github.com/users/dwtokarski/followers","following_url":"https://api.github.com/users/dwtokarski/following{/other_user}","gists_url":"https://api.github.com/users/dwtokarski/gists{/gist_id}","starred_url":"https://api.github.com/users/dwtokarski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwtokarski/subscriptions","organizations_url":"https://api.github.com/users/dwtokarski/orgs","repos_url":"https://api.github.com/users/dwtokarski/repos","events_url":"https://api.github.com/users/dwtokarski/events{/privacy}","received_events_url":"https://api.github.com/users/dwtokarski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-08-24T20:55:10Z","updated_at":"2017-08-27T20:36:52Z","closed_at":null,"body":"#### Expected behaviour\r\nA cpufreq applet placed on the panel should render completely and remain so.\r\n\r\n#### Actual behaviour\r\nAlmost always, the last column or two of pixels on the units label is missing (e.g. the z in Mhz is missing the right side).\r\n\r\nSomewhat less often, more or all the the units label is missing entirely; likewise for the frequency label. On even more rare occasions the applet doesn't render at all, although it's really there as hovering over its known location will pop up the tooltip, left click opens the freq/governors menu, etc.\r\n\r\nI have reason to think the total failure to render is a separate issue from the label truncations behavior.\r\n\r\n#### Steps to reproduce the behaviour\r\nNo special action required. Just log in to a desktop which has one or more cpufreq-applets on a panel. Can also happen after resume from suspend or even any random moment.\r\n\r\n#### MATE general version\r\n1.18.0 currently, though this has been happening since at least 1.16.x.\r\n\r\n#### Package version\r\nCurrently mate-applets-1.18.1-1.fc26.x86_64 but see above.\r\n\r\n#### Linux Distribution\r\nFedora 25, 26\r\n\r\n#### Link to downstream report of your Distribution\r\nNone yet.\r\n\r\n#### Proposed Patch\r\nThe patch below addresses the partial labels issue. I've been running this for several days and it seems solid.\r\n\r\nThe problem seems to have been in cpufreq-applet.c, where the get_max_???_width routines were trying to find the pixel width of various strings by inserting text into a freshly allocated GtkLabel and calling gtk_widget_get_preferred_width() on it, which just returns zero results. Wild guess: the freestanding GtkLabel has no associated font, so the width can't be determined.  At some point someone decided it would be better to get the widths of the applet-> label instead but they're not initialized at first and who knows where the string pointer in that object was pointing. Wildly different values were returned from time to time, and the first time a positive value is acquired it becomes the sticky width for that label in *applet.\r\n\r\nThe patch gets around this by placing string values in the labels of the applet, then getting the preferred widths. \r\n\r\n```\r\ndiff -ur ../mate-applets-1.18.1-ORIG/cpufreq/src/cpufreq-applet.c ./cpufreq/src/cpufreq-applet.c\r\n --- ../mate-applets-1.18.1-ORIG/cpufreq/src/cpufreq-applet.c   2017-04-06 15:02:40.000000000 -0400\r\n +++ ./cpufreq/src/cpufreq-applet.c     2017-08-20 16:05:37.056044732 -0400\r\n @@ -292,7 +292,6 @@\r\n  cpufreq_applet_get_max_label_width (CPUFreqApplet *applet)\r\n  {\r\n        GList *available_freqs;\r\n -      gint   width = 0;\r\n  \r\n        if (applet->max_label_width > 0)\r\n                return applet->max_label_width;\r\n @@ -302,7 +301,6 @@\r\n  \r\n        available_freqs = cpufreq_monitor_get_available_frequencies (applet->monitor);\r\n        while (available_freqs) {\r\n -              GtkWidget     *label;\r\n                gint           label_width;\r\n                const gchar   *text;\r\n                gchar         *freq_text;\r\n @@ -312,34 +310,26 @@\r\n                freq = atoi (text);\r\n  \r\n                freq_text = cpufreq_utils_get_frequency_label (freq);\r\n -              label = gtk_label_new (freq_text);\r\n +              gtk_label_set_text (GTK_LABEL (applet->label), freq_text);\r\n                gtk_widget_get_preferred_width (applet->label, &label_width, NULL);\r\n -              width = MAX (width, label_width); \r\n +              applet->max_label_width = MAX (applet->max_label_width, label_width);\r\n  \r\n                g_free (freq_text);\r\n -              gtk_widget_destroy (label);\r\n  \r\n                available_freqs = g_list_next (available_freqs);\r\n        }\r\n  \r\n -      applet->max_label_width = width;\r\n -\r\n -      return width;\r\n +      return applet->max_label_width;\r\n  }\r\n  \r\n  static gint\r\n  cpufreq_applet_get_max_perc_width (CPUFreqApplet *applet)\r\n  {\r\n -      GtkWidget      *label;\r\n -      gint            width;\r\n -\r\n        if (applet->max_perc_width > 0)\r\n                return applet->max_perc_width;\r\n  \r\n -      label = gtk_label_new (\"100%\");\r\n -      gtk_widget_get_preferred_width (applet->label, &width,&width);\r\n -      applet->max_perc_width = width +20; /*for some reason width always comes up 2 characters*/\r\n -      gtk_widget_destroy (label);\r\n +      gtk_label_set_text (GTK_LABEL (applet->label), \"100%\");\r\n +      gtk_widget_get_preferred_width (applet->label, &applet->max_perc_width, NULL);\r\n  \r\n        return applet->max_perc_width;\r\n  }\r\n @@ -347,20 +337,19 @@\r\n  static gint\r\n  cpufreq_applet_get_max_unit_width (CPUFreqApplet *applet)\r\n  {\r\n -      GtkWidget     *label;\r\n -      gint           w1, w2;\r\n +      gint           mwidth;\r\n  \r\n        if (applet->max_unit_width > 0)\r\n                return applet->max_unit_width;\r\n  \r\n -      label = gtk_label_new (\"GHz\");\r\n -      gtk_widget_get_preferred_width (applet->label, &w1, NULL);\r\n +      gtk_label_set_text (GTK_LABEL (applet->unit_label), \"GHz\");\r\n +      gtk_widget_get_preferred_width (applet->unit_label, &applet->max_unit_width, NULL);\r\n  \r\n -      gtk_label_set_text (GTK_LABEL (label), \"MHz\");\r\n -      gtk_widget_get_preferred_width (applet->label, &w2, NULL);\r\n +      gtk_label_set_text (GTK_LABEL (applet->unit_label), \"MHz\");\r\n +      gtk_widget_get_preferred_width (applet->unit_label, &mwidth, NULL);\r\n +\r\n +      applet->max_unit_width = MAX (applet->max_unit_width, mwidth);\r\n  \r\n -      gtk_widget_destroy (label);\r\n -      applet->max_unit_width = MAX (w1, w2)-1;\r\n        return applet->max_unit_width;\r\n  }\r\n  \r\n @@ -757,6 +746,20 @@\r\n          guint        cpu;\r\n          const gchar *governor;\r\n  \r\n +        /* Call refresh only the first time.\r\n +         *\r\n +         * Because the label width determinations now modify the actual labels\r\n +         * in *applet to size the max label width in pixels, do this first\r\n +         * before setting the label text below.\r\n +         */\r\n +        if (applet->need_refresh) {\r\n +                gint w;\r\n +\r\n +                cpufreq_applet_get_preferred_width(applet, &w, &w);\r\n +                cpufreq_applet_refresh (applet);\r\n +                applet->need_refresh = FALSE;\r\n +        }\r\n +\r\n          cpu = cpufreq_monitor_get_cpu (monitor);\r\n          freq = cpufreq_monitor_get_frequency (monitor);\r\n          perc = cpufreq_monitor_get_percentage (monitor);\r\n @@ -810,12 +813,6 @@\r\n                gtk_widget_set_tooltip_text (GTK_WIDGET (applet), text_tip);\r\n                g_free (text_tip);\r\n        }\r\n -\r\n -        /* Call refresh only the first time */\r\n -        if (applet->need_refresh) {\r\n -                cpufreq_applet_refresh (applet);\r\n -              applet->need_refresh = FALSE;\r\n -        }\r\n  }\r\n  \r\n  static gint\r\n~\r\n```\r\n\r\n<bountysource-plugin>\r\n\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/48615023-cpufreq-applet-freq-units-labels-render-partially-or-not-at-all?utm_campaign=plugin&utm_content=tracker%2F517519&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F517519&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/mate-desktop/mate-applets/issues/comments/325223165","html_url":"https://github.com/mate-desktop/mate-applets/issues/268#issuecomment-325223165","issue_url":"https://api.github.com/repos/mate-desktop/mate-applets/issues/268","id":325223165,"user":{"login":"raveit65","id":961604,"avatar_url":"https://avatars3.githubusercontent.com/u/961604?v=4","gravatar_id":"","url":"https://api.github.com/users/raveit65","html_url":"https://github.com/raveit65","followers_url":"https://api.github.com/users/raveit65/followers","following_url":"https://api.github.com/users/raveit65/following{/other_user}","gists_url":"https://api.github.com/users/raveit65/gists{/gist_id}","starred_url":"https://api.github.com/users/raveit65/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raveit65/subscriptions","organizations_url":"https://api.github.com/users/raveit65/orgs","repos_url":"https://api.github.com/users/raveit65/repos","events_url":"https://api.github.com/users/raveit65/events{/privacy}","received_events_url":"https://api.github.com/users/raveit65/received_events","type":"User","site_admin":false},"created_at":"2017-08-27T20:36:52Z","updated_at":"2017-08-27T20:36:52Z","body":"To master please."}}
{"actor":{"display_login":"raveit65"}}