[metacity/wip/iainl/gnome-3-18-window-scaling] theme: improve scaling



commit 5384072ce5474f9a5c6769a1cecce798cd12f5b8
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Mar 24 14:29:19 2016 +0200

    theme: improve scaling

 src/ui/theme.c |   87 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 48 insertions(+), 39 deletions(-)
---
diff --git a/src/ui/theme.c b/src/ui/theme.c
index fb5bb17..6717931 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -844,6 +844,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
   gboolean right_buttons_has_spacer[MAX_BUTTONS_PER_CORNER];
 
   current = meta_theme_get_current ();
+  scale = get_window_scaling_factor ();
 
   meta_frame_layout_sync_with_style (layout, style_info, flags);
 
@@ -853,7 +854,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
                                  &borders);
 
   fgeom->borders = borders;
-  fgeom->top_height = layout->top_height;
+  fgeom->top_height = layout->top_height * scale;
 
   width = client_width + borders.total.left + borders.total.right;
 
@@ -863,12 +864,10 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
   fgeom->width = width;
   fgeom->height = height;
 
-  scale = get_window_scaling_factor ();
-
-  fgeom->top_titlebar_edge = layout->title_border.top;
-  fgeom->bottom_titlebar_edge = layout->title_border.bottom;
-  fgeom->left_titlebar_edge = layout->left_titlebar_edge;
-  fgeom->right_titlebar_edge = layout->right_titlebar_edge;
+  fgeom->top_titlebar_edge = layout->title_border.top * scale;
+  fgeom->bottom_titlebar_edge = layout->title_border.bottom * scale;
+  fgeom->left_titlebar_edge = layout->left_titlebar_edge * scale;
+  fgeom->right_titlebar_edge = layout->right_titlebar_edge * scale;
 
   /* gcc warnings */
   button_width = -1;
@@ -877,7 +876,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
   switch (layout->button_sizing)
     {
     case META_BUTTON_SIZING_ASPECT:
-      button_height = borders.visible.top - layout->button_border.top * scale - layout->button_border.bottom 
* scale;
+      button_height = borders.visible.top - (layout->button_border.top + layout->button_border.bottom) * 
scale;
       button_width = button_height / layout->button_aspect;
       break;
     case META_BUTTON_SIZING_FIXED:
@@ -975,7 +974,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
       int space_used_by_buttons;
       int space_available;
 
-      space_available = fgeom->width - layout->left_titlebar_edge * scale - layout->right_titlebar_edge * 
scale;
+      space_available = fgeom->width - (layout->left_titlebar_edge + layout->right_titlebar_edge) * scale;
 
       space_used_by_buttons = 0;
 
@@ -1080,7 +1079,8 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
 
   /* center buttons vertically */
   button_y = (borders.visible.top - fgeom->top_height -
-              (button_height + layout->button_border.top * scale + layout->button_border.bottom * scale)) / 
2 + layout->button_border.top  * scale + fgeom->top_height + borders.invisible.top;
+              (button_height + (layout->button_border.top + layout->button_border.bottom) * scale)) / 2 +
+              layout->button_border.top  * scale + fgeom->top_height + borders.invisible.top;
 
   /* right edge of farthest-right button */
   x = width - layout->right_titlebar_edge * scale - borders.invisible.right;
@@ -1095,7 +1095,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
 
       rect = right_func_rects[i];
       if (current->is_gtk_theme == FALSE)
-        rect->visible.x = x - layout->button_border.right - button_width;
+        rect->visible.x = x - layout->button_border.right * scale - button_width;
       else
         rect->visible.x = x - button_width;
       if (right_buttons_has_spacer[i])
@@ -1117,11 +1117,10 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
           if (i == n_right - 1)
             {
               if (current->is_gtk_theme == FALSE)
-                rect->clickable.width += layout->right_titlebar_edge * scale + layout->right_width * scale + 
layout->button_border.right * scale;
+                rect->clickable.width += (layout->right_titlebar_edge + layout->right_width + 
layout->button_border.right) * scale;
               else
-                rect->clickable.width += layout->right_titlebar_edge * scale + layout->right_width * scale;
+                rect->clickable.width += (layout->right_titlebar_edge + layout->right_width) * scale;
             }
-
         }
       else
         g_memmove (&(rect->clickable), &(rect->visible), sizeof(rect->clickable));
@@ -1192,7 +1191,7 @@ meta_frame_layout_calc_geometry (MetaFrameLayout        *layout,
   fgeom->title_rect.x = x + layout->title_border.left * scale;
   fgeom->title_rect.y = layout->title_border.top * scale + borders.invisible.top;
   fgeom->title_rect.width = title_right_edge - fgeom->title_rect.x;
-  fgeom->title_rect.height = borders.visible.top - layout->title_border.top * scale - 
layout->title_border.bottom * scale;
+  fgeom->title_rect.height = borders.visible.top - (layout->title_border.top + layout->title_border.bottom) 
* scale;
 
   /* Nuke title if it won't fit */
   if (fgeom->title_rect.width < 0 ||
@@ -3862,6 +3861,10 @@ fill_env (MetaPositionExprEnv *env,
           const MetaDrawInfo  *info,
           MetaRectangle        logical_region)
 {
+  int scale;
+
+  scale = get_window_scaling_factor ();
+
   /* FIXME this stuff could be raised into draw_op_list_draw() probably
    */
   env->rect = logical_region;
@@ -3869,12 +3872,12 @@ fill_env (MetaPositionExprEnv *env,
   env->object_height = -1;
   if (info->fgeom)
     {
-      env->left_width = info->fgeom->borders.visible.left;
-      env->right_width = info->fgeom->borders.visible.right;
-      env->top_height = info->fgeom->borders.visible.top;
-      env->bottom_height = info->fgeom->borders.visible.bottom;
-      env->frame_x_center = info->fgeom->width / 2 - logical_region.x;
-      env->frame_y_center = info->fgeom->height / 2 - logical_region.y;
+      env->left_width = info->fgeom->borders.visible.left / scale;
+      env->right_width = info->fgeom->borders.visible.right / scale;
+      env->top_height = info->fgeom->borders.visible.top / scale;
+      env->bottom_height = info->fgeom->borders.visible.bottom / scale;
+      env->frame_x_center = info->fgeom->width / scale / 2 - logical_region.x;
+      env->frame_y_center = info->fgeom->height / scale / 2 - logical_region.y;
     }
   else
     {
@@ -4934,34 +4937,34 @@ meta_frame_style_draw_with_style (MetaFrameStyle          *style,
   titlebar_rect.height = borders->visible.top / scale;
 
   left_titlebar_edge.x = titlebar_rect.x;
-  left_titlebar_edge.y = titlebar_rect.y + fgeom->top_titlebar_edge;
-  left_titlebar_edge.width = fgeom->left_titlebar_edge;
-  left_titlebar_edge.height = titlebar_rect.height - fgeom->top_titlebar_edge - fgeom->bottom_titlebar_edge;
+  left_titlebar_edge.y = titlebar_rect.y + fgeom->top_titlebar_edge / scale;
+  left_titlebar_edge.width = fgeom->left_titlebar_edge / scale;
+  left_titlebar_edge.height = titlebar_rect.height - (fgeom->top_titlebar_edge + 
fgeom->bottom_titlebar_edge) / scale;
 
   right_titlebar_edge.y = left_titlebar_edge.y;
   right_titlebar_edge.height = left_titlebar_edge.height;
-  right_titlebar_edge.width = fgeom->right_titlebar_edge;
+  right_titlebar_edge.width = fgeom->right_titlebar_edge / scale;
   right_titlebar_edge.x = titlebar_rect.x + titlebar_rect.width - right_titlebar_edge.width;
 
   top_titlebar_edge.x = titlebar_rect.x;
   top_titlebar_edge.y = titlebar_rect.y;
   top_titlebar_edge.width = titlebar_rect.width;
-  top_titlebar_edge.height = fgeom->top_titlebar_edge;
+  top_titlebar_edge.height = fgeom->top_titlebar_edge / scale;
 
   bottom_titlebar_edge.x = titlebar_rect.x;
   bottom_titlebar_edge.width = titlebar_rect.width;
-  bottom_titlebar_edge.height = fgeom->bottom_titlebar_edge;
+  bottom_titlebar_edge.height = fgeom->bottom_titlebar_edge / scale;
   bottom_titlebar_edge.y = titlebar_rect.y + titlebar_rect.height - bottom_titlebar_edge.height;
 
   left_edge.x = visible_rect.x;
   left_edge.y = visible_rect.y + borders->visible.top / scale;
   left_edge.width = borders->visible.left / scale;
-  left_edge.height = visible_rect.height - borders->visible.top / scale - borders->visible.bottom / scale;
+  left_edge.height = visible_rect.height - (borders->visible.top + borders->visible.bottom) / scale;
 
   right_edge.x = visible_rect.x + visible_rect.width - borders->visible.right / scale;
   right_edge.y = visible_rect.y + borders->visible.top / scale;
   right_edge.width = borders->visible.right / scale;
-  right_edge.height = visible_rect.height - borders->visible.top / scale - borders->visible.bottom / scale;
+  right_edge.height = visible_rect.height - (borders->visible.top + borders->visible.bottom) / scale;
 
   bottom_edge.x = visible_rect.x;
   bottom_edge.y = visible_rect.y + visible_rect.height - borders->visible.bottom / scale;
@@ -5014,13 +5017,13 @@ meta_frame_style_draw_with_style (MetaFrameStyle          *style,
         case META_FRAME_PIECE_TITLEBAR_MIDDLE:
           rect.x = left_titlebar_edge.x + left_titlebar_edge.width;
           rect.y = top_titlebar_edge.y + top_titlebar_edge.height;
-          rect.width = titlebar_rect.width - left_titlebar_edge.width -
-            right_titlebar_edge.width;
+          rect.width = titlebar_rect.width - left_titlebar_edge.width - right_titlebar_edge.width;
           rect.height = titlebar_rect.height - top_titlebar_edge.height - bottom_titlebar_edge.height;
           break;
 
         case META_FRAME_PIECE_TITLE:
           rect = fgeom->title_rect;
+
           rect.x /= scale;
           rect.y /= scale;
           rect.height /= scale;
@@ -5095,6 +5098,11 @@ meta_frame_style_draw_with_style (MetaFrameStyle          *style,
 
               get_button_rect (j, fgeom, middle_bg_offset, &rect);
 
+              rect.x /= scale;
+              rect.y /= scale;
+              rect.width /= scale;
+              rect.height /= scale;
+
               button_state = map_button_state (j, fgeom, middle_bg_offset, button_states);
               op_list = get_button (style, j, button_state);
 
@@ -5171,13 +5179,14 @@ meta_frame_style_draw_with_style_gtk (MetaFrameStyle          *frame_style,
   int scale;
 
   scale = get_window_scaling_factor ();
+  cairo_scale (cr, scale, scale);
 
   borders = &fgeom->borders;
 
-  visible_rect.x = borders->invisible.left;
-  visible_rect.y = borders->invisible.top;
-  visible_rect.width = fgeom->width - borders->invisible.left - borders->invisible.right;
-  visible_rect.height = fgeom->height - borders->invisible.top - borders->invisible.bottom;
+  visible_rect.x = borders->invisible.left / scale;
+  visible_rect.y = borders->invisible.top / scale;
+  visible_rect.width = (fgeom->width - borders->invisible.left - borders->invisible.right) / scale;
+  visible_rect.height = (fgeom->height - borders->invisible.top - borders->invisible.bottom) / scale;
 
   meta_style_info_set_flags (style_info, flags);
 
@@ -5189,10 +5198,10 @@ meta_frame_style_draw_with_style_gtk (MetaFrameStyle          *frame_style,
                     visible_rect.x, visible_rect.y,
                     visible_rect.width, visible_rect.height);
 
-  titlebar_rect.x = visible_rect.x + borders->visible.left;
-  titlebar_rect.y = visible_rect.y + fgeom->top_height;
-  titlebar_rect.width = visible_rect.width - borders->visible.left - borders->visible.right;
-  titlebar_rect.height = borders->visible.top - fgeom->top_height;
+  titlebar_rect.x = visible_rect.x + borders->visible.left / scale;
+  titlebar_rect.y = visible_rect.y + fgeom->top_height / scale;
+  titlebar_rect.width = visible_rect.width - borders->visible.left / scale - borders->visible.right / scale;
+  titlebar_rect.height = borders->visible.top / scale - fgeom->top_height / scale;
 
   style = style_info->styles[META_STYLE_ELEMENT_TITLEBAR];
   gtk_render_background (style, cr,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]