From 6b05da5e49996a2101edfd703dd3f5d91011d726 Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Mon, 14 Oct 2019 15:10:13 -0400 Subject: tabpopup: Make workspaces compatible with OSD popup When drawing the workspace switcher OSD, we want it to be slightly transparent to match the OSD style. Also changed how the popup size is calculated and changed window icons to cairo surfaces. --- src/ui/draw-workspace.c | 36 +++++++++++++++++------------------- src/ui/tabpopup.c | 12 ++++++------ 2 files changed, 23 insertions(+), 25 deletions(-) (limited to 'src/ui') diff --git a/src/ui/draw-workspace.c b/src/ui/draw-workspace.c index e9838be1..aca58440 100644 --- a/src/ui/draw-workspace.c +++ b/src/ui/draw-workspace.c @@ -91,8 +91,8 @@ draw_window (GtkWidget *widget, const GdkRectangle *winrect, GtkStateType state) { - GdkPixbuf *icon; - int icon_x, icon_y, icon_w, icon_h; + cairo_surface_t *icon; + int icon_x, icon_y, icon_w, icon_h, scale; gboolean is_active; GdkRGBA color; GtkStyleContext *style; @@ -117,32 +117,28 @@ draw_window (GtkWidget *widget, MAX (0, winrect->width - 2), MAX (0, winrect->height - 2)); cairo_fill (cr); + scale = gtk_widget_get_scale_factor (widget); - icon = win->icon; + icon = gdk_cairo_surface_create_from_pixbuf (win->icon, scale, NULL); icon_w = icon_h = 0; if (icon) { - icon_w = gdk_pixbuf_get_width (icon); - icon_h = gdk_pixbuf_get_height (icon); - - /* If the icon is too big, fall back to mini icon. - * We don't arbitrarily scale the icon, because it's - * just too slow on my Athlon 850. - */ - if (icon_w > (winrect->width - 2) || - icon_h > (winrect->height - 2)) + icon_w = cairo_image_surface_get_width (icon) / scale; + icon_h = cairo_image_surface_get_height (icon) / scale; + + /* If the icon is too big, fall back to mini icon. */ + if (icon_w > (winrect->width - 2) || icon_h > (winrect->height - 2)) { - icon = win->mini_icon; + icon = gdk_cairo_surface_create_from_pixbuf (win->mini_icon, scale, NULL); if (icon) { - icon_w = gdk_pixbuf_get_width (icon); - icon_h = gdk_pixbuf_get_height (icon); + icon_w = cairo_image_surface_get_width (icon) / scale; + icon_h = cairo_image_surface_get_height (icon) / scale; /* Give up. */ - if (icon_w > (winrect->width - 2) || - icon_h > (winrect->height - 2)) + if (icon_w > (winrect->width - 2) || icon_h > (winrect->height - 2)) icon = NULL; } } @@ -154,7 +150,7 @@ draw_window (GtkWidget *widget, icon_y = winrect->y + (winrect->height - icon_h) / 2; cairo_save (cr); - gdk_cairo_set_source_pixbuf (cr, icon, icon_x, icon_y); + cairo_set_source_surface (cr, icon, icon_x, icon_y); cairo_rectangle (cr, icon_x, icon_y, icon_w, icon_h); cairo_clip (cr); cairo_paint (cr); @@ -216,7 +212,9 @@ wnck_draw_workspace (GtkWidget *widget, { GdkRGBA color; - meta_gtk_style_get_dark_color (style,state, &color); + meta_gtk_style_get_dark_color (style, state, &color); + color.alpha = 0.25; + gdk_cairo_set_source_rgba (cr, &color); cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); diff --git a/src/ui/tabpopup.c b/src/ui/tabpopup.c index 06ee84e9..263a6a9d 100644 --- a/src/ui/tabpopup.c +++ b/src/ui/tabpopup.c @@ -912,7 +912,7 @@ struct _MetaSelectWorkspaceClass static GType meta_select_workspace_get_type (void) G_GNUC_CONST; #define SELECT_OUTLINE_WIDTH 2 -#define MINI_WORKSPACE_SCALE 2 +#define MINI_WORKSPACE_SCREEN_FRACTION 0.33 static GtkWidget* selectable_workspace_new (MetaWorkspace *workspace, int entry_count) @@ -929,20 +929,20 @@ selectable_workspace_new (MetaWorkspace *workspace, int entry_count) if (workspace->screen->rect.width < workspace->screen->rect.height) { mini_workspace_ratio = (double) workspace->screen->rect.width / (double) workspace->screen->rect.height; - mini_workspace_height = (int) ((double) current->rect.height / entry_count - SELECT_OUTLINE_WIDTH * 2); + mini_workspace_height = (int) ((double) current->rect.height * MINI_WORKSPACE_SCREEN_FRACTION / entry_count); mini_workspace_width = (int) ((double) mini_workspace_height * mini_workspace_ratio); } else { mini_workspace_ratio = (double) workspace->screen->rect.height / (double) workspace->screen->rect.width; - mini_workspace_width = (int) ((double) current->rect.width / entry_count - SELECT_OUTLINE_WIDTH * 2); + mini_workspace_width = (int) ((double) current->rect.width * MINI_WORKSPACE_SCREEN_FRACTION / entry_count); mini_workspace_height = (int) ((double) mini_workspace_width * mini_workspace_ratio); } /* account for select rect */ gtk_widget_set_size_request (widget, - mini_workspace_width / MINI_WORKSPACE_SCALE, - mini_workspace_height / MINI_WORKSPACE_SCALE); + mini_workspace_width + SELECT_OUTLINE_WIDTH * 2, + mini_workspace_height + SELECT_OUTLINE_WIDTH * 2); META_SELECT_WORKSPACE (widget)->workspace = workspace; @@ -1114,7 +1114,7 @@ meta_select_workspace_draw (GtkWidget *widget, gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget)); - gtk_style_context_lookup_color (context, "color", &color); + meta_gtk_style_get_light_color (context, GTK_STATE_FLAG_SELECTED, &color); cairo_set_line_width (cr, SELECT_OUTLINE_WIDTH); cairo_set_source_rgb (cr, color.red, color.green, color.blue); -- cgit v1.2.1