mirror of
https://github.com/elementary/gala.git
synced 2024-09-11 15:15:39 +03:00
pip: Adjust button size and margin for screen dpi scale (#396)
Add reusable Util.get_ui_scaling_factor() Fixes: #395
This commit is contained in:
parent
a2a4683b01
commit
cf8d4556d0
@ -276,6 +276,15 @@ namespace Gala
|
||||
screen.get_display ().get_compositor ().flash_screen (screen);
|
||||
}
|
||||
|
||||
public static int get_ui_scaling_factor ()
|
||||
{
|
||||
#if HAS_MUTTER326
|
||||
return Meta.Backend.get_backend ().get_settings ().get_ui_scaling_factor ();
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pixbuf that is used for close buttons throughout gala at a
|
||||
* size of 36px
|
||||
@ -285,11 +294,7 @@ namespace Gala
|
||||
public static Gdk.Pixbuf? get_close_button_pixbuf ()
|
||||
{
|
||||
if (close_pixbuf == null) {
|
||||
#if HAS_MUTTER326
|
||||
var scale = Meta.Backend.get_backend ().get_settings ().get_ui_scaling_factor ();
|
||||
#else
|
||||
var scale = 1;
|
||||
#endif
|
||||
var scale = Utils.get_ui_scaling_factor ();
|
||||
try {
|
||||
close_pixbuf = new Gdk.Pixbuf.from_resource_at_scale (Config.RESOURCEPATH + "/buttons/close.svg", -1, 36 * scale, true);
|
||||
} catch (Error e) {
|
||||
@ -320,14 +325,10 @@ namespace Gala
|
||||
pixbuf.get_rowstride (), (pixbuf.get_has_alpha () ? 4 : 3), 0);
|
||||
} catch (Error e) {}
|
||||
} else {
|
||||
// we'll just make this red so there's at least something as an
|
||||
// we'll just make this red so there's at least something as an
|
||||
// indicator that loading failed. Should never happen and this
|
||||
// works as good as some weird fallback-image-failed-to-load pixbuf
|
||||
#if HAS_MUTTER326
|
||||
var scale = Meta.Backend.get_backend ().get_settings ().get_ui_scaling_factor ();
|
||||
#else
|
||||
var scale = 1;
|
||||
#endif
|
||||
var scale = Utils.get_ui_scaling_factor ();
|
||||
texture.set_size (36 * scale, 36 * scale);
|
||||
texture.background_color = { 255, 0, 0, 255 };
|
||||
}
|
||||
@ -343,11 +344,7 @@ namespace Gala
|
||||
public static Gdk.Pixbuf? get_resize_button_pixbuf ()
|
||||
{
|
||||
if (resize_pixbuf == null) {
|
||||
#if HAS_MUTTER326
|
||||
var scale = Meta.Backend.get_backend ().get_settings ().get_ui_scaling_factor ();
|
||||
#else
|
||||
var scale = 1;
|
||||
#endif
|
||||
var scale = Utils.get_ui_scaling_factor ();
|
||||
try {
|
||||
resize_pixbuf = new Gdk.Pixbuf.from_resource_at_scale (Config.RESOURCEPATH + "/buttons/resize.svg", -1, 36 * scale, true);
|
||||
} catch (Error e) {
|
||||
@ -381,11 +378,7 @@ namespace Gala
|
||||
// we'll just make this red so there's at least something as an
|
||||
// indicator that loading failed. Should never happen and this
|
||||
// works as good as some weird fallback-image-failed-to-load pixbuf
|
||||
#if HAS_MUTTER326
|
||||
var scale = Meta.Backend.get_backend ().get_settings ().get_ui_scaling_factor ();
|
||||
#else
|
||||
var scale = 1;
|
||||
#endif
|
||||
var scale = Utils.get_ui_scaling_factor ();
|
||||
texture.set_size (36 * scale, 36 * scale);
|
||||
texture.background_color = { 255, 0, 0, 255 };
|
||||
}
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
{
|
||||
private const int BUTTON_SIZE = 36;
|
||||
private const int CONTAINER_MARGIN = BUTTON_SIZE / 2;
|
||||
private int button_size;
|
||||
private int container_margin;
|
||||
private const int SHADOW_SIZE = 100;
|
||||
private const uint FADE_OUT_TIMEOUT = 200;
|
||||
private const float MINIMUM_SCALE = 0.1f;
|
||||
@ -80,6 +80,10 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
|
||||
construct
|
||||
{
|
||||
var scale = Utils.get_ui_scaling_factor ();
|
||||
button_size = 36 * scale;
|
||||
container_margin = button_size / 2;
|
||||
|
||||
reactive = true;
|
||||
|
||||
set_pivot_point (0.5f, 0.5f);
|
||||
@ -111,7 +115,7 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
|
||||
if (container_clip == null) {
|
||||
window_actor.notify["allocation"].connect (on_allocation_changed);
|
||||
container.set_position (CONTAINER_MARGIN, CONTAINER_MARGIN);
|
||||
container.set_position (container_margin, container_margin);
|
||||
update_clone_clip ();
|
||||
}
|
||||
|
||||
@ -138,15 +142,15 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
resize_action.drag_motion.connect (on_resize_drag_motion);
|
||||
|
||||
resize_handle = new Clutter.Actor ();
|
||||
resize_handle.set_size (BUTTON_SIZE, BUTTON_SIZE);
|
||||
resize_handle.set_size (button_size, button_size);
|
||||
resize_handle.set_pivot_point (0.5f, 0.5f);
|
||||
resize_handle.set_position (width - BUTTON_SIZE, height - BUTTON_SIZE);
|
||||
resize_handle.set_position (width - button_size, height - button_size);
|
||||
resize_handle.reactive = true;
|
||||
resize_handle.add_action (resize_action);
|
||||
|
||||
resize_button = Utils.create_resize_button ();
|
||||
resize_button.set_pivot_point (0.5f, 0.5f);
|
||||
resize_button.set_position (width - resize_button.width, height - resize_button.height);
|
||||
resize_button.set_position (width - button_size, height - button_size);
|
||||
resize_button.opacity = 0;
|
||||
resize_button.reactive = true;
|
||||
|
||||
@ -318,11 +322,11 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
private void update_size ()
|
||||
{
|
||||
if (container_clip != null) {
|
||||
width = (int)(container_clip.get_width () * container.scale_x + BUTTON_SIZE);
|
||||
height = (int)(container_clip.get_height () * container.scale_y + BUTTON_SIZE);
|
||||
width = (int)(container_clip.get_width () * container.scale_x + button_size);
|
||||
height = (int)(container_clip.get_height () * container.scale_y + button_size);
|
||||
} else {
|
||||
width = (int)(container.width * container.scale_x + BUTTON_SIZE);
|
||||
height = (int)(container.height * container.scale_y + BUTTON_SIZE);
|
||||
width = (int)(container.width * container.scale_x + button_size);
|
||||
height = (int)(container.height * container.scale_y + button_size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,9 +353,9 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
src_width = container.width;
|
||||
src_height = container.height;
|
||||
}
|
||||
|
||||
float max_width = width - BUTTON_SIZE;
|
||||
float max_height = height - BUTTON_SIZE;
|
||||
|
||||
float max_width = width - button_size;
|
||||
float max_height = height - button_size;
|
||||
|
||||
float new_width, new_height;
|
||||
calculate_aspect_ratio_size_fit (
|
||||
@ -375,8 +379,8 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
private void update_container_position ()
|
||||
{
|
||||
if (container_clip != null) {
|
||||
container.x = (float)(-container_clip.get_x () * container.scale_x + CONTAINER_MARGIN);
|
||||
container.y = (float)(-container_clip.get_y () * container.scale_y + CONTAINER_MARGIN);
|
||||
container.x = (float)(-container_clip.get_x () * container.scale_x + container_margin);
|
||||
container.y = (float)(-container_clip.get_y () * container.scale_y + container_margin);
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,12 +413,12 @@ public class Gala.Plugins.PIP.PopupWindow : Clutter.Actor
|
||||
|
||||
private void reposition_resize_button ()
|
||||
{
|
||||
resize_button.set_position (width - BUTTON_SIZE, height - BUTTON_SIZE);
|
||||
resize_button.set_position (width - button_size, height - button_size);
|
||||
}
|
||||
|
||||
private void reposition_resize_handle ()
|
||||
{
|
||||
resize_handle.set_position (width - BUTTON_SIZE, height - BUTTON_SIZE);
|
||||
resize_handle.set_position (width - button_size, height - button_size);
|
||||
}
|
||||
|
||||
private void get_current_monitor_rect (out Meta.Rectangle rect)
|
||||
|
Loading…
Reference in New Issue
Block a user