Skip to content

Commit

Permalink
Increase icon size on tab and workspace popups
Browse files Browse the repository at this point in the history
Alt+Tab and Workspace popups should be sized relative to the monitor size.
This way they look nice and large regardless of the display resolution.

Also, given much larger modern resolutions, icon sizes should be larger by default.
  • Loading branch information
vkareh authored and lukefromdc committed Jan 31, 2019
1 parent a931b08 commit 8abba9a
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 41 deletions.
3 changes: 3 additions & 0 deletions src/core/screen-private.h
Expand Up @@ -36,6 +36,7 @@
#include "display-private.h"
#include "screen.h"
#include <X11/Xutil.h>
#include <gdk/gdk.h>
#include "ui.h"

typedef struct _MetaXineramaScreenInfo MetaXineramaScreenInfo;
Expand Down Expand Up @@ -193,6 +194,8 @@ void meta_screen_update_workspace_layout (MetaScreen *scree
void meta_screen_update_workspace_names (MetaScreen *screen);
void meta_screen_queue_workarea_recalc (MetaScreen *screen);

GdkMonitor* meta_screen_get_current_monitor (void);

Window meta_create_offscreen_window (Display *xdisplay,
Window parent,
long valuemask);
Expand Down
50 changes: 44 additions & 6 deletions src/core/screen.c
Expand Up @@ -1214,7 +1214,7 @@ meta_screen_update_cursor (MetaScreen *screen)
XFreeCursor (screen->display->xdisplay, xcursor);
}

#define MAX_PREVIEW_SIZE 150.0
#define MAX_PREVIEW_SCALE 10.0

static GdkPixbuf *
get_window_pixbuf (MetaWindow *window,
Expand All @@ -1224,6 +1224,8 @@ get_window_pixbuf (MetaWindow *window,
MetaDisplay *display;
cairo_surface_t *surface;
GdkPixbuf *pixbuf, *scaled;
GdkMonitor *monitor;
GdkRectangle rect;
double ratio;

display = window->display;
Expand All @@ -1246,17 +1248,30 @@ get_window_pixbuf (MetaWindow *window,
*width = gdk_pixbuf_get_width (pixbuf);
*height = gdk_pixbuf_get_height (pixbuf);

/* Scale pixbuf to max dimension MAX_PREVIEW_SIZE */
monitor = meta_screen_get_current_monitor ();
if (monitor != NULL)
{
gdk_monitor_get_geometry (monitor, &rect);
}
else
{
rect.width = window->screen->rect.width;
rect.height = window->screen->rect.height;
}

/* Scale pixbuf to max dimension based on monitor size */
if (*width > *height)
{
ratio = ((double) *width) / MAX_PREVIEW_SIZE;
*width = (int) MAX_PREVIEW_SIZE;
int max_preview_width = rect.width / MAX_PREVIEW_SCALE;
ratio = ((double) *width) / max_preview_width;
*width = (int) max_preview_width;
*height = (int) (((double) *height) / ratio);
}
else
{
ratio = ((double) *height) / MAX_PREVIEW_SIZE;
*height = (int) MAX_PREVIEW_SIZE;
int max_preview_height = rect.height / MAX_PREVIEW_SCALE;
ratio = ((double) *height) / max_preview_height;
*height = (int) max_preview_height;
*width = (int) (((double) *width) / ratio);
}

Expand Down Expand Up @@ -1797,6 +1812,29 @@ meta_screen_get_current_xinerama (MetaScreen *screen)
return &screen->xinerama_infos[screen->last_xinerama_index];
}

GdkMonitor *
meta_screen_get_current_monitor ()
{
GdkDisplay *display;
GdkSeat *seat;
GdkDevice *device;
GdkMonitor *current;
gint x, y;

display = gdk_display_get_default ();
seat = gdk_display_get_default_seat (display);
device = gdk_seat_get_pointer (seat);

gdk_device_get_position (device, NULL, &x, &y);
current = gdk_display_get_monitor_at_point (display, x, y);

if (current != NULL) {
return current;
}

return gdk_display_get_primary_monitor (display);
}

#define _NET_WM_ORIENTATION_HORZ 0
#define _NET_WM_ORIENTATION_VERT 1

Expand Down
4 changes: 2 additions & 2 deletions src/include/common.h
Expand Up @@ -301,8 +301,8 @@ struct _MetaButtonLayout
};

/* should investigate changing these to whatever most apps use */
#define META_ICON_WIDTH 32
#define META_ICON_HEIGHT 32
#define META_ICON_WIDTH 48
#define META_ICON_HEIGHT 48
#define META_MINI_ICON_WIDTH 16
#define META_MINI_ICON_HEIGHT 16

Expand Down
43 changes: 34 additions & 9 deletions src/ui/tabpopup.c
Expand Up @@ -68,7 +68,8 @@ static GtkWidget* selectable_image_new (GdkPixbuf *pixbuf);
static void select_image (GtkWidget *widget);
static void unselect_image (GtkWidget *widget);

static GtkWidget* selectable_workspace_new (MetaWorkspace *workspace);
static GtkWidget* selectable_workspace_new (MetaWorkspace *workspace,
int entry_count);
static void select_workspace (GtkWidget *widget);
static void unselect_workspace (GtkWidget *widget);

Expand Down Expand Up @@ -361,7 +362,7 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries,
}
else
{
image = selectable_workspace_new ((MetaWorkspace *) te->key);
image = selectable_workspace_new ((MetaWorkspace *) te->key, entry_count);
}

te->widget = image;
Expand Down Expand Up @@ -753,23 +754,47 @@ struct _MetaSelectWorkspaceClass
static GType meta_select_workspace_get_type (void) G_GNUC_CONST;

#define SELECT_OUTLINE_WIDTH 2
#define MINI_WORKSPACE_WIDTH 48
#define MINI_WORKSPACE_SCALE 2

static GtkWidget*
selectable_workspace_new (MetaWorkspace *workspace)
selectable_workspace_new (MetaWorkspace *workspace, int entry_count)
{
GtkWidget *widget;
double screen_aspect;
GdkMonitor *monitor;
GdkRectangle rect;
int mini_workspace_width, mini_workspace_height;
double mini_workspace_ratio;

widget = g_object_new (meta_select_workspace_get_type (), NULL);

screen_aspect = (double) workspace->screen->rect.height /
(double) workspace->screen->rect.width;
monitor = meta_screen_get_current_monitor ();
if (monitor != NULL)
{
gdk_monitor_get_geometry (monitor, &rect);
}
else
{
rect.width = workspace->screen->rect.width;
rect.height = workspace->screen->rect.height;
}

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) rect.height / entry_count - SELECT_OUTLINE_WIDTH * 2);
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) rect.width / entry_count - SELECT_OUTLINE_WIDTH * 2);
mini_workspace_height = (int) ((double) mini_workspace_width * mini_workspace_ratio);
}

/* account for select rect */
gtk_widget_set_size_request (widget,
MINI_WORKSPACE_WIDTH + SELECT_OUTLINE_WIDTH * 2,
MINI_WORKSPACE_WIDTH * screen_aspect + SELECT_OUTLINE_WIDTH * 2);
mini_workspace_width / MINI_WORKSPACE_SCALE,
mini_workspace_height / MINI_WORKSPACE_SCALE);

META_SELECT_WORKSPACE (widget)->workspace = workspace;

Expand Down
6 changes: 5 additions & 1 deletion src/ui/theme.c
Expand Up @@ -5341,20 +5341,24 @@ meta_theme_load_image (MetaTheme *theme,
GError **error)
{
GdkPixbuf *pixbuf;
int scale;

pixbuf = g_hash_table_lookup (theme->images_by_filename,
filename);

scale = gdk_window_get_scale_factor (gdk_get_default_root_window ());

if (pixbuf == NULL)
{

if (g_str_has_prefix (filename, "theme:") &&
META_THEME_ALLOWS (theme, META_THEME_IMAGES_FROM_ICON_THEMES))
{
pixbuf = gtk_icon_theme_load_icon (
pixbuf = gtk_icon_theme_load_icon_for_scale (
gtk_icon_theme_get_default (),
filename+6,
size_of_theme_icons,
scale,
0,
error);
if (pixbuf == NULL) return NULL;
Expand Down
31 changes: 8 additions & 23 deletions src/ui/ui.c
Expand Up @@ -569,7 +569,7 @@ meta_ui_pop_delay_exposes (MetaUI *ui)
}

static GdkPixbuf *
load_default_window_icon (int size)
load_default_window_icon (int size, int scale)
{
GtkIconTheme *theme = gtk_icon_theme_get_default ();
const char *icon_name;
Expand All @@ -579,17 +579,19 @@ load_default_window_icon (int size)
else
icon_name = "image-missing";

return gtk_icon_theme_load_icon (theme, icon_name, size, 0, NULL);
return gtk_icon_theme_load_icon_for_scale (theme, icon_name, size, scale, 0, NULL);
}

GdkPixbuf*
meta_ui_get_default_window_icon (MetaUI *ui)
{
static GdkPixbuf *default_icon = NULL;
int scale;

if (default_icon == NULL)
{
default_icon = load_default_window_icon (META_ICON_WIDTH);
scale = gtk_widget_get_scale_factor (GTK_WIDGET (ui->frames));
default_icon = load_default_window_icon (META_ICON_WIDTH, scale);
g_assert (default_icon);
}

Expand All @@ -602,29 +604,12 @@ GdkPixbuf*
meta_ui_get_default_mini_icon (MetaUI *ui)
{
static GdkPixbuf *default_icon = NULL;
int scale;

if (default_icon == NULL)
{
GtkIconTheme *theme;
gboolean icon_exists;

theme = gtk_icon_theme_get_default ();

icon_exists = gtk_icon_theme_has_icon (theme, META_DEFAULT_ICON_NAME);

if (icon_exists)
default_icon = gtk_icon_theme_load_icon (theme,
META_DEFAULT_ICON_NAME,
META_MINI_ICON_WIDTH,
0,
NULL);
else
default_icon = gtk_icon_theme_load_icon (theme,
"image-missing",
META_MINI_ICON_WIDTH,
0,
NULL);

scale = gtk_widget_get_scale_factor (GTK_WIDGET (ui->frames));
default_icon = load_default_window_icon (META_MINI_ICON_WIDTH, scale);
g_assert (default_icon);
}

Expand Down

0 comments on commit 8abba9a

Please sign in to comment.