stuartlangridge / gnome-shell-clock-override

Override the Gnome Shell clock with a new time format or text of your choice. Works with new versions of Shell such as 3.18
MIT License
89 stars 33 forks source link

Clock container sometimes have improper width after unlock #42

Open shodan8192 opened 4 years ago

shodan8192 commented 4 years ago

Occurs (but not always) in Ubuntu 19.04, 19.10 on Top bar and Dash to panel.

If clock text after override is longer than original one, then after unlock, text is displayed with ellipsis; if is shorter there is margin on the right side.

Example :

ellipsis

It seems like that happen when function overrider(lbl) from enable() is called earlier than desktop if fully repainted.

After refreshing (on mouse hover or wait minute or second depending on format) container width is set properly.

I have workaround it by adding 1000ms timeout, instead of calling overrider(lbl) immediately :

GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {overrider(lbl)});

but maybe there is a better way to do it, like force repaint/refresh of container - I know nearly nothing about Gjs/GTK+ programming.

da2x commented 4 years ago

Do you have a HiDPI display, by any chance?

shodan8192 commented 4 years ago

No, I have 1920x1200 24'' monitor.

k4j8 commented 4 years ago

I have the same issue running Arch with a 1920x1080 24" monitor, but shodan8192's fix works great. I replicated the issue and the fix several times without fail by locking the computer and then logging in. Applying the fix did require logging out and then back in, although there may be easier means.

Can I submit a PR to get this fixed, at least until someone finds a better method?

shodan8192's fix:

--- extension.js.original   2020-06-22 09:25:56.969755762 -0400
+++ extension.js    2020-06-22 09:26:16.566081515 -0400
@@ -48,7 +48,7 @@
     }
     signalHandlerID = lbl.connect("notify::text", overrider);
     last = lbl.get_text();
-    overrider(lbl);
+    GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {overrider(lbl)});
 }

 function disable() {
da2x commented 4 years ago

No. I won’t except a timing based work-around. It’ll be way too fragile.

@shodan8192 and @KyleWJohnston could you try adding a second signal handler and hook it up to lbl.connect("allocation-changed", overrider)? That should call overrider again when the lbl’s dimension changes. (1–3 px changes are expected due to variable width fonts.) If that works, then we can improve on that to only double-execute overrider when the dimension shrinks.