Skip to content

Commit c5e5ec2

Browse files
authored
Tooltip: scale text margin (#2616)
1 parent 2a5cec5 commit c5e5ec2

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

lib/Utils.vala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,5 +486,24 @@ namespace Gala {
486486
public static int calculate_button_size (float monitor_scale) {
487487
return Utils.scale_to_int (BUTTON_SIZE, monitor_scale);
488488
}
489+
490+
private static bool? framebuffer_is_logical = null;
491+
public static bool get_framebuffer_is_logical () {
492+
if (framebuffer_is_logical != null) {
493+
return framebuffer_is_logical;
494+
}
495+
496+
framebuffer_is_logical = false;
497+
498+
var experimental_features = new Settings ("org.gnome.mutter").get_strv ("experimental-features");
499+
for (var i = 0; i < experimental_features.length; i++) {
500+
if (experimental_features[i] == "scale-monitor-framebuffer") {
501+
framebuffer_is_logical = true;
502+
break;
503+
}
504+
}
505+
506+
return framebuffer_is_logical;
507+
}
489508
}
490509
}

src/BlurManager.vala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,13 @@ public class Gala.BlurManager : Object {
3232

3333
public WindowManagerGala wm { get; construct; }
3434

35-
private bool framebuffer_is_logical = false;
3635
private GLib.HashTable<Meta.Window, BlurData?> blurred_windows = new GLib.HashTable<Meta.Window, BlurData?> (null, null);
3736

3837
private BlurManager (WindowManagerGala wm) {
3938
Object (wm: wm);
4039
}
4140

4241
construct {
43-
var experimental_features = new Settings ("org.gnome.mutter").get_strv ("experimental-features");
44-
for (var i = 0; i < experimental_features.length; i++) {
45-
if (experimental_features[i] == "scale-monitor-framebuffer") {
46-
framebuffer_is_logical = true;
47-
break;
48-
}
49-
}
50-
5142
wm.get_display ().window_created.connect ((window) => {
5243
window.notify["mutter-hints"].connect ((obj, pspec) => parse_mutter_hints ((Meta.Window) obj));
5344
parse_mutter_hints (window);
@@ -83,7 +74,7 @@ public class Gala.BlurManager : Object {
8374
var x_shadow_size = frame_rect.x - buffer_rect.x;
8475
var y_shadow_size = frame_rect.y - buffer_rect.y;
8576

86-
var monitor_scale = framebuffer_is_logical ? 1.0f : window.display.get_monitor_scale (window.get_monitor ());
77+
var monitor_scale = Utils.get_framebuffer_is_logical () ? 1.0f : window.display.get_monitor_scale (window.get_monitor ());
8778
var inverse_monitor_scale = 1.0f / monitor_scale;
8879

8980
blur_data.actor.set_position (

src/Widgets/MultitaskingView/Tooltip.vala

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* Clutter actor to display text in a tooltip-like component.
99
*/
1010
public class Gala.Tooltip : Clutter.Actor {
11+
private const int TEXT_MARGIN = 6;
12+
private const int CORNER_RADIUS = 3;
13+
1114
public float monitor_scale { get; construct set; }
1215

1316
private Gala.Text text_actor;
@@ -18,25 +21,33 @@ public class Gala.Tooltip : Clutter.Actor {
1821

1922
construct {
2023
text_actor = new Gala.Text () {
21-
margin_left = 6,
22-
margin_top = 6,
23-
margin_bottom = 6,
24-
margin_right = 6,
2524
ellipsize = Pango.EllipsizeMode.MIDDLE,
2625
color = Drawing.Color.TOOLTIP_TEXT_COLOR
2726
};
28-
29-
add_child (text_actor);
27+
bind_property ("monitor-scale", text_actor, "margin-left", SYNC_CREATE, transform_monitor_scale_to_margin);
28+
bind_property ("monitor-scale", text_actor, "margin-top", SYNC_CREATE, transform_monitor_scale_to_margin);
29+
bind_property ("monitor-scale", text_actor, "margin-right", SYNC_CREATE, transform_monitor_scale_to_margin);
30+
bind_property ("monitor-scale", text_actor, "margin-bottom", SYNC_CREATE, transform_monitor_scale_to_margin);
3031

3132
layout_manager = new Clutter.BinLayout ();
3233
background_color = Drawing.Color.TOOLTIP_BACKGROUND;
34+
add_child (text_actor);
3335

34-
var rounded_corners_effect = new RoundedCornersEffect (3, monitor_scale);
36+
var rounded_corners_effect = new RoundedCornersEffect (CORNER_RADIUS, monitor_scale);
3537
bind_property ("monitor-scale", rounded_corners_effect, "monitor-scale");
3638
add_effect (rounded_corners_effect);
3739
}
3840

3941
public void set_text (string new_text) {
4042
text_actor.text = new_text;
4143
}
44+
45+
private static bool transform_monitor_scale_to_margin (Binding binding, Value from_value, ref Value to_value) {
46+
to_value.set_float (
47+
Utils.get_framebuffer_is_logical ()
48+
? TEXT_MARGIN
49+
: Utils.scale_to_int (TEXT_MARGIN, from_value.get_float ())
50+
);
51+
return true;
52+
}
4253
}

0 commit comments

Comments
 (0)