Navigation Menu

Skip to content

Commit

Permalink
Support HiDPI window decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
vkareh authored and raveit65 committed Mar 22, 2018
1 parent 6168620 commit b9fd3c1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 49 deletions.
99 changes: 71 additions & 28 deletions src/ui/frames.c
Expand Up @@ -524,11 +524,13 @@ meta_frames_calc_geometry (MetaFrames *frames,
MetaUIFrame *frame, MetaUIFrame *frame,
MetaFrameGeometry *fgeom) MetaFrameGeometry *fgeom)
{ {
int width, height; int width, height, scale;
MetaFrameFlags flags; MetaFrameFlags flags;
MetaFrameType type; MetaFrameType type;
MetaButtonLayout button_layout; MetaButtonLayout button_layout;


scale = gdk_window_get_scale_factor (frame->window);

meta_core_get (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), frame->xwindow, meta_core_get (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), frame->xwindow,
META_CORE_GET_CLIENT_WIDTH, &width, META_CORE_GET_CLIENT_WIDTH, &width,
META_CORE_GET_CLIENT_HEIGHT, &height, META_CORE_GET_CLIENT_HEIGHT, &height,
Expand All @@ -544,9 +546,14 @@ meta_frames_calc_geometry (MetaFrames *frames,
type, type,
frame->text_height, frame->text_height,
flags, flags,
width, height, width / scale, height / scale,
&button_layout, &button_layout,
fgeom); fgeom);

fgeom->top_height *= scale;
fgeom->bottom_height *= scale;
fgeom->left_width *= scale;
fgeom->right_width *= scale;
} }


MetaFrames* MetaFrames*
Expand Down Expand Up @@ -695,8 +702,10 @@ meta_frames_get_geometry (MetaFrames *frames,
MetaFrameFlags flags; MetaFrameFlags flags;
MetaUIFrame *frame; MetaUIFrame *frame;
MetaFrameType type; MetaFrameType type;
gint scale;


frame = meta_frames_lookup_window (frames, xwindow); frame = meta_frames_lookup_window (frames, xwindow);
scale = gdk_window_get_scale_factor (frame->window);


if (frame == NULL) if (frame == NULL)
meta_bug ("No such frame 0x%lx\n", xwindow); meta_bug ("No such frame 0x%lx\n", xwindow);
Expand All @@ -721,6 +730,12 @@ meta_frames_get_geometry (MetaFrames *frames,
flags, flags,
top_height, bottom_height, top_height, bottom_height,
left_width, right_width); left_width, right_width);

/* Scale frame geometry to ensure proper frame position */
*top_height *= scale;
*bottom_height *= scale;
*left_width *= scale;
*right_width *= scale;
} }


void void
Expand Down Expand Up @@ -783,6 +798,7 @@ meta_frames_apply_shapes (MetaFrames *frames,
XRectangle xrect; XRectangle xrect;
Region corners_xregion; Region corners_xregion;
Region window_xregion; Region window_xregion;
gint scale;


frame = meta_frames_lookup_window (frames, xwindow); frame = meta_frames_lookup_window (frames, xwindow);
g_return_if_fail (frame != NULL); g_return_if_fail (frame != NULL);
Expand Down Expand Up @@ -816,10 +832,11 @@ meta_frames_apply_shapes (MetaFrames *frames,
} }


corners_xregion = XCreateRegion (); corners_xregion = XCreateRegion ();
scale = gdk_window_get_scale_factor (frame->window);


if (fgeom.top_left_corner_rounded_radius != 0) if (fgeom.top_left_corner_rounded_radius != 0)
{ {
const int corner = fgeom.top_left_corner_rounded_radius; const int corner = fgeom.top_left_corner_rounded_radius * scale;
const float radius = sqrt(corner) + corner; const float radius = sqrt(corner) + corner;
int i; int i;


Expand All @@ -837,7 +854,7 @@ meta_frames_apply_shapes (MetaFrames *frames,


if (fgeom.top_right_corner_rounded_radius != 0) if (fgeom.top_right_corner_rounded_radius != 0)
{ {
const int corner = fgeom.top_right_corner_rounded_radius; const int corner = fgeom.top_right_corner_rounded_radius * scale;
const float radius = sqrt(corner) + corner; const float radius = sqrt(corner) + corner;
int i; int i;


Expand All @@ -855,7 +872,7 @@ meta_frames_apply_shapes (MetaFrames *frames,


if (fgeom.bottom_left_corner_rounded_radius != 0) if (fgeom.bottom_left_corner_rounded_radius != 0)
{ {
const int corner = fgeom.bottom_left_corner_rounded_radius; const int corner = fgeom.bottom_left_corner_rounded_radius * scale;
const float radius = sqrt(corner) + corner; const float radius = sqrt(corner) + corner;
int i; int i;


Expand All @@ -873,7 +890,7 @@ meta_frames_apply_shapes (MetaFrames *frames,


if (fgeom.bottom_right_corner_rounded_radius != 0) if (fgeom.bottom_right_corner_rounded_radius != 0)
{ {
const int corner = fgeom.bottom_right_corner_rounded_radius; const int corner = fgeom.bottom_right_corner_rounded_radius * scale;
const float radius = sqrt(corner) + corner; const float radius = sqrt(corner) + corner;
int i; int i;


Expand Down Expand Up @@ -1006,11 +1023,14 @@ meta_frames_move_resize_frame (MetaFrames *frames,
{ {
MetaUIFrame *frame = meta_frames_lookup_window (frames, xwindow); MetaUIFrame *frame = meta_frames_lookup_window (frames, xwindow);
int old_width, old_height; int old_width, old_height;
gint scale;


old_width = gdk_window_get_width (frame->window); old_width = gdk_window_get_width (frame->window);
old_height = gdk_window_get_height (frame->window); old_height = gdk_window_get_height (frame->window);


gdk_window_move_resize (frame->window, x, y, width, height); scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());

gdk_window_move_resize (frame->window, x / scale, y / scale, width / scale, height / scale);


if (old_width != width || old_height != height) if (old_width != width || old_height != height)
invalidate_whole_window (frames, frame); invalidate_whole_window (frames, frame);
Expand Down Expand Up @@ -1153,15 +1173,16 @@ show_tip_now (MetaFrames *frames)
{ {
MetaFrameGeometry fgeom; MetaFrameGeometry fgeom;
GdkRectangle *rect; GdkRectangle *rect;
int dx, dy; int dx, dy, scale;


meta_frames_calc_geometry (frames, frame, &fgeom); meta_frames_calc_geometry (frames, frame, &fgeom);


rect = control_rect (control, &fgeom); rect = control_rect (control, &fgeom);
scale = gdk_window_get_scale_factor (frame->window);


/* get conversion delta for root-to-frame coords */ /* get conversion delta for root-to-frame coords */
dx = root_x - x; dx = (root_x - x) / scale;
dy = root_y - y; dy = (root_y - y) / scale;


/* Align the tooltip to the button right end if RTL */ /* Align the tooltip to the button right end if RTL */
if (meta_ui_get_direction() == META_UI_DIRECTION_RTL) if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
Expand Down Expand Up @@ -1920,10 +1941,13 @@ meta_frames_motion_notify_event (GtkWidget *widget,
case META_GRAB_OP_CLICKING_UNSTICK: case META_GRAB_OP_CLICKING_UNSTICK:
{ {
MetaFrameControl control; MetaFrameControl control;
int x, y; int x, y, scale;


gdk_window_get_device_position (frame->window, event->device, gdk_window_get_device_position (frame->window, event->device,
&x, &y, NULL); &x, &y, NULL);
scale = gdk_window_get_scale_factor (frame->window);
x *= scale;
y *= scale;


/* Control is set to none unless it matches /* Control is set to none unless it matches
* the current grab * the current grab
Expand Down Expand Up @@ -1966,10 +1990,13 @@ meta_frames_motion_notify_event (GtkWidget *widget,
case META_GRAB_OP_NONE: case META_GRAB_OP_NONE:
{ {
MetaFrameControl control; MetaFrameControl control;
int x, y; int x, y, scale;


gdk_window_get_device_position (frame->window, event->device, gdk_window_get_device_position (frame->window, event->device,
&x, &y, NULL); &x, &y, NULL);
scale = gdk_window_get_scale_factor (frame->window);
x *= scale;
y *= scale;


control = get_control (frames, frame, x, y); control = get_control (frames, frame, x, y);


Expand Down Expand Up @@ -2063,6 +2090,7 @@ populate_cache (MetaFrames *frames,
int top, bottom, left, right; int top, bottom, left, right;
int width, height; int width, height;
int frame_width, frame_height, screen_width, screen_height; int frame_width, frame_height, screen_width, screen_height;
gint scale;
CachedPixels *pixels; CachedPixels *pixels;
MetaFrameType frame_type; MetaFrameType frame_type;
MetaFrameFlags frame_flags; MetaFrameFlags frame_flags;
Expand Down Expand Up @@ -2093,28 +2121,29 @@ populate_cache (MetaFrames *frames,
&top, &bottom, &left, &right); &top, &bottom, &left, &right);


pixels = get_cache (frames, frame); pixels = get_cache (frames, frame);
scale = gdk_window_get_scale_factor (frame->window);


/* Setup the rectangles for the four frame borders. First top, then /* Setup the rectangles for the four frame borders. First top, then
left, right and bottom. */ left, right and bottom. */
pixels->piece[0].rect.x = 0; pixels->piece[0].rect.x = 0;
pixels->piece[0].rect.y = 0; pixels->piece[0].rect.y = 0;
pixels->piece[0].rect.width = left + width + right; pixels->piece[0].rect.width = (left + width + right) * scale;
pixels->piece[0].rect.height = top; pixels->piece[0].rect.height = top * scale;


pixels->piece[1].rect.x = 0; pixels->piece[1].rect.x = 0;
pixels->piece[1].rect.y = top; pixels->piece[1].rect.y = top / scale;
pixels->piece[1].rect.width = left; pixels->piece[1].rect.width = left * scale;
pixels->piece[1].rect.height = height; pixels->piece[1].rect.height = height * scale;


pixels->piece[2].rect.x = left + width; pixels->piece[2].rect.x = (left + width) / scale;
pixels->piece[2].rect.y = top; pixels->piece[2].rect.y = top / scale;
pixels->piece[2].rect.width = right; pixels->piece[2].rect.width = right * scale;
pixels->piece[2].rect.height = height; pixels->piece[2].rect.height = height * scale;


pixels->piece[3].rect.x = 0; pixels->piece[3].rect.x = 0;
pixels->piece[3].rect.y = top + height; pixels->piece[3].rect.y = (top + height) / scale;
pixels->piece[3].rect.width = left + width + right; pixels->piece[3].rect.width = (left + width + right) * scale;
pixels->piece[3].rect.height = bottom; pixels->piece[3].rect.height = bottom * scale;


for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
Expand Down Expand Up @@ -2196,19 +2225,27 @@ subtract_client_area (cairo_region_t *region, MetaUIFrame *frame)
MetaFrameType type; MetaFrameType type;
cairo_region_t *tmp_region; cairo_region_t *tmp_region;
Display *display; Display *display;
gint scale;


display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
scale = gdk_window_get_scale_factor (frame->window);


meta_core_get (display, frame->xwindow, meta_core_get (display, frame->xwindow,
META_CORE_GET_FRAME_FLAGS, &flags, META_CORE_GET_FRAME_FLAGS, &flags,
META_CORE_GET_FRAME_TYPE, &type, META_CORE_GET_FRAME_TYPE, &type,
META_CORE_GET_CLIENT_WIDTH, &area.width, META_CORE_GET_CLIENT_WIDTH, &area.width,
META_CORE_GET_CLIENT_HEIGHT, &area.height, META_CORE_GET_CLIENT_HEIGHT, &area.height,
META_CORE_GET_END); META_CORE_GET_END);

meta_theme_get_frame_borders (meta_theme_get_current (), meta_theme_get_frame_borders (meta_theme_get_current (),
type, frame->text_height, flags, type, frame->text_height, flags,
&area.x, NULL, &area.y, NULL); &area.x, NULL, &area.y, NULL);


area.width /= scale;
area.height /= scale;
area.x /= scale;
area.y /= scale;

tmp_region = cairo_region_create_rectangle (&area); tmp_region = cairo_region_create_rectangle (&area);
cairo_region_subtract (region, tmp_region); cairo_region_subtract (region, tmp_region);
cairo_region_destroy (tmp_region); cairo_region_destroy (tmp_region);
Expand Down Expand Up @@ -2295,7 +2332,7 @@ meta_frames_paint_to_drawable (MetaFrames *frames,
MetaFrameType type; MetaFrameType type;
GdkPixbuf *mini_icon; GdkPixbuf *mini_icon;
GdkPixbuf *icon; GdkPixbuf *icon;
int w, h; int w, h, scale;
MetaButtonState button_states[META_BUTTON_TYPE_LAST]; MetaButtonState button_states[META_BUTTON_TYPE_LAST];
Window grab_frame; Window grab_frame;
int i; int i;
Expand Down Expand Up @@ -2398,12 +2435,13 @@ meta_frames_paint_to_drawable (MetaFrames *frames,


meta_prefs_get_button_layout (&button_layout); meta_prefs_get_button_layout (&button_layout);


scale = gdk_window_get_scale_factor (frame->window);
meta_theme_draw_frame_with_style (meta_theme_get_current (), meta_theme_draw_frame_with_style (meta_theme_get_current (),
frame->style, frame->style,
cr, cr,
type, type,
flags, flags,
w, h, w / scale, h / scale,
frame->layout, frame->layout,
frame->text_height, frame->text_height,
&button_layout, &button_layout,
Expand Down Expand Up @@ -2576,9 +2614,14 @@ get_control (MetaFrames *frames,
MetaFrameFlags flags; MetaFrameFlags flags;
gboolean has_vert, has_horiz; gboolean has_vert, has_horiz;
GdkRectangle client; GdkRectangle client;
gint scale;


meta_frames_calc_geometry (frames, frame, &fgeom); meta_frames_calc_geometry (frames, frame, &fgeom);


scale = gdk_window_get_scale_factor (frame->window);
x /= scale;
y /= scale;

client.x = fgeom.left_width; client.x = fgeom.left_width;
client.y = fgeom.top_height; client.y = fgeom.top_height;
client.width = fgeom.width - fgeom.left_width - fgeom.right_width; client.width = fgeom.width - fgeom.left_width - fgeom.right_width;
Expand All @@ -2605,7 +2648,7 @@ get_control (MetaFrames *frames,


if (POINT_IN_RECT (x, y, fgeom.title_rect)) if (POINT_IN_RECT (x, y, fgeom.title_rect))
{ {
if (has_vert && y <= TOP_RESIZE_HEIGHT) if (has_vert && y <= TOP_RESIZE_HEIGHT * scale)
return META_FRAME_CONTROL_RESIZE_N; return META_FRAME_CONTROL_RESIZE_N;
else else
return META_FRAME_CONTROL_TITLE; return META_FRAME_CONTROL_TITLE;
Expand Down Expand Up @@ -2698,7 +2741,7 @@ get_control (MetaFrames *frames,
if (has_vert) if (has_vert)
return META_FRAME_CONTROL_RESIZE_S; return META_FRAME_CONTROL_RESIZE_S;
} }
else if (y <= TOP_RESIZE_HEIGHT) else if (y <= TOP_RESIZE_HEIGHT * scale)
{ {
if (has_vert) if (has_vert)
return META_FRAME_CONTROL_RESIZE_N; return META_FRAME_CONTROL_RESIZE_N;
Expand Down
6 changes: 4 additions & 2 deletions src/ui/menu.c
Expand Up @@ -490,11 +490,13 @@ meta_window_menu_new (MetaFrames *frames,
void meta_window_menu_popup(MetaWindowMenu* menu, int root_x, int root_y, int button, guint32 timestamp) void meta_window_menu_popup(MetaWindowMenu* menu, int root_x, int root_y, int button, guint32 timestamp)
{ {
GdkPoint* pt = g_new(GdkPoint, 1); GdkPoint* pt = g_new(GdkPoint, 1);
gint scale;


g_object_set_data_full(G_OBJECT(menu->menu), "destroy-point", pt, g_free); g_object_set_data_full(G_OBJECT(menu->menu), "destroy-point", pt, g_free);


pt->x = root_x; scale = gtk_widget_get_scale_factor (menu->menu);
pt->y = root_y; pt->x = root_x / scale;
pt->y = root_y / scale;


gtk_menu_popup(GTK_MENU (menu->menu), NULL, NULL, popup_position_func, pt, button, timestamp); gtk_menu_popup(GTK_MENU (menu->menu), NULL, NULL, popup_position_func, pt, button, timestamp);


Expand Down
28 changes: 14 additions & 14 deletions src/ui/tabpopup.c
Expand Up @@ -148,8 +148,8 @@ dimm_icon (GdkPixbuf *pixbuf)


static TabEntry* static TabEntry*
tab_entry_new (const MetaTabEntry *entry, tab_entry_new (const MetaTabEntry *entry,
gint screen_width, gboolean outline,
gboolean outline) gint scale)
{ {
TabEntry *te; TabEntry *te;


Expand Down Expand Up @@ -200,15 +200,15 @@ tab_entry_new (const MetaTabEntry *entry,


if (outline) if (outline)
{ {
te->rect.x = entry->rect.x; te->rect.x = entry->rect.x / scale;
te->rect.y = entry->rect.y; te->rect.y = entry->rect.y / scale;
te->rect.width = entry->rect.width; te->rect.width = entry->rect.width / scale;
te->rect.height = entry->rect.height; te->rect.height = entry->rect.height / scale;


te->inner_rect.x = entry->inner_rect.x; te->inner_rect.x = entry->inner_rect.x / scale;
te->inner_rect.y = entry->inner_rect.y; te->inner_rect.y = entry->inner_rect.y / scale;
te->inner_rect.width = entry->inner_rect.width; te->inner_rect.width = entry->inner_rect.width / scale;
te->inner_rect.height = entry->inner_rect.height; te->inner_rect.height = entry->inner_rect.height / scale;
} }
return te; return te;
} }
Expand All @@ -229,7 +229,7 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
int max_label_width; /* the actual max width of the labels we create */ int max_label_width; /* the actual max width of the labels we create */
AtkObject *obj; AtkObject *obj;
GdkScreen *screen; GdkScreen *screen;
int screen_width; int screen_width, scale;


popup = g_new (MetaTabPopup, 1); popup = g_new (MetaTabPopup, 1);


Expand Down Expand Up @@ -260,11 +260,11 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
popup->current_selected_entry = NULL; popup->current_selected_entry = NULL;
popup->border = border; popup->border = border;


scale = gtk_widget_get_scale_factor (GTK_WIDGET (popup->window));
screen_width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)); screen_width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen));
for (i = 0; i < entry_count; ++i) for (i = 0; i < entry_count; ++i)
{ {
TabEntry* new_entry = tab_entry_new (&entries[i], screen_width, TabEntry* new_entry = tab_entry_new (&entries[i], border & BORDER_OUTLINE_WINDOW, scale);
border & BORDER_OUTLINE_WINDOW);
popup->entries = g_list_prepend (popup->entries, new_entry); popup->entries = g_list_prepend (popup->entries, new_entry);
} }


Expand Down
7 changes: 7 additions & 0 deletions src/ui/tile-preview.c
Expand Up @@ -175,6 +175,13 @@ meta_tile_preview_show (MetaTilePreview *preview,
{ {
GdkWindow *window; GdkWindow *window;
GdkRectangle old_rect; GdkRectangle old_rect;
gint scale;

scale = gtk_widget_get_scale_factor (preview->preview_window);
tile_rect->x /= scale;
tile_rect->y /= scale;
tile_rect->width /= scale;
tile_rect->height /= scale;


if (gtk_widget_get_visible (preview->preview_window) if (gtk_widget_get_visible (preview->preview_window)
&& preview->tile_rect.x == tile_rect->x && preview->tile_rect.x == tile_rect->x
Expand Down

0 comments on commit b9fd3c1

Please sign in to comment.