Merge branch 'optimize-sizing' into 'master'
Optimize sizing See merge request Librem5/squeekboard!390
This commit is contained in:
@ -104,10 +104,10 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Units of pixel size
|
||||
// Units of virtual pixels size
|
||||
static enum squeek_arrangement_kind get_type(uint32_t width, uint32_t height) {
|
||||
(void)height;
|
||||
if (width < 1080) {
|
||||
if (width < 540) {
|
||||
return ARRANGEMENT_KIND_BASE;
|
||||
}
|
||||
return ARRANGEMENT_KIND_WIDE;
|
||||
@ -119,11 +119,10 @@ eek_gtk_keyboard_real_size_allocate (GtkWidget *self,
|
||||
{
|
||||
EekGtkKeyboardPrivate *priv =
|
||||
eek_gtk_keyboard_get_instance_private (EEK_GTK_KEYBOARD (self));
|
||||
uint32_t scale = (uint32_t)gtk_widget_get_scale_factor(self);
|
||||
// check if the change would switch types
|
||||
enum squeek_arrangement_kind new_type = get_type(
|
||||
(uint32_t)(allocation->width - allocation->x) * scale,
|
||||
(uint32_t)(allocation->height - allocation->y) * scale);
|
||||
(uint32_t)(allocation->width - allocation->x),
|
||||
(uint32_t)(allocation->height - allocation->y));
|
||||
if (priv->layout->arrangement != new_type) {
|
||||
priv->layout->arrangement = new_type;
|
||||
uint32_t time = gdk_event_get_time(NULL);
|
||||
|
||||
@ -85,13 +85,20 @@ on_notify_unmap (ServerContextService *self, GtkWidget *widget)
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
calculate_height(int32_t width)
|
||||
calculate_height(int32_t width, GdkRectangle *geometry)
|
||||
{
|
||||
uint32_t height = 180;
|
||||
if (width < 360 && width > 0) {
|
||||
uint32_t height;
|
||||
if (geometry->width > geometry->height) {
|
||||
// 1:5 ratio works fine on lanscape mode, and makes sure there's
|
||||
// room left for the app window
|
||||
height = width / 5;
|
||||
} else {
|
||||
if (width < 540 && width > 0) {
|
||||
height = ((unsigned)width * 7 / 12); // to match 360×210
|
||||
} else if (width < 540) {
|
||||
height = 180 + (540 - (unsigned)width) * 30 / 180; // smooth transition
|
||||
} else {
|
||||
// Here we switch to wide layout, less height needed
|
||||
height = ((unsigned)width * 7 / 22);
|
||||
}
|
||||
}
|
||||
return height;
|
||||
}
|
||||
@ -99,6 +106,10 @@ calculate_height(int32_t width)
|
||||
static void
|
||||
on_surface_configure(ServerContextService *self, PhoshLayerSurface *surface)
|
||||
{
|
||||
GdkDisplay *display = NULL;
|
||||
GdkWindow *window = NULL;
|
||||
GdkMonitor *monitor = NULL;
|
||||
GdkRectangle geometry;
|
||||
gint width;
|
||||
gint height;
|
||||
|
||||
@ -110,11 +121,24 @@ on_surface_configure(ServerContextService *self, PhoshLayerSurface *surface)
|
||||
"configured-height", &height,
|
||||
NULL);
|
||||
|
||||
// In order to improve height calculation, we need the monitor geometry so
|
||||
// we can use different algorithms for portrait and landscape mode.
|
||||
// Note: this is a temporary fix until the size manager is complete.
|
||||
display = gdk_display_get_default ();
|
||||
if (display)
|
||||
window = gtk_widget_get_window (GTK_WIDGET (surface));
|
||||
if (window)
|
||||
monitor = gdk_display_get_monitor_at_window (display, window);
|
||||
if (monitor)
|
||||
gdk_monitor_get_geometry (monitor, &geometry);
|
||||
else
|
||||
geometry.width = geometry.height = 0;
|
||||
|
||||
// When the geometry event comes after surface.configure,
|
||||
// this entire height calculation does nothing.
|
||||
// guint desired_height = squeek_uiman_get_perceptual_height(context->manager);
|
||||
// Temporarily use old method, until the size manager is complete.
|
||||
guint desired_height = calculate_height(width);
|
||||
guint desired_height = calculate_height(width, &geometry);
|
||||
|
||||
guint configured_height = (guint)height;
|
||||
// if height was already requested once but a different one was given
|
||||
|
||||
Reference in New Issue
Block a user