Unverified Commit 6f1bf432 authored by Erik Reider's avatar Erik Reider Committed by GitHub

Moved all hardcoded icon sizes to CSS (#565)

* Moved Notification icon sizes to CSS * Added Notification group app icon size to CSS * Moved MPRIS icon sizes to CSS * Moved Volume widget icon sizes to CSS
parent 8fe365a0
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
--text-color-disabled: rgb(150, 150, 150); --text-color-disabled: rgb(150, 150, 150);
--bg-selected: rgb(0, 128, 255); --bg-selected: rgb(0, 128, 255);
--notification-icon-size: 64px;
--notification-app-icon-size: var(--notification-icon-size) / 3;
--notification-group-icon-size: 32px;
} }
$border: 1px solid var(--noti-border-color); $border: 1px solid var(--noti-border-color);
...@@ -113,12 +117,14 @@ $notification-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), ...@@ -113,12 +117,14 @@ $notification-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3),
.image { .image {
/* Notification Primary Image */ /* Notification Primary Image */
-gtk-icon-filter: none; -gtk-icon-filter: none;
-gtk-icon-size: var(--notification-icon-size);
border-radius: 100px; /* Size in px */ border-radius: 100px; /* Size in px */
margin: $margin; margin: $margin;
} }
.app-icon { .app-icon {
/* Notification app icon (only visible when the primary image is set) */ /* Notification app icon (only visible when the primary image is set) */
-gtk-icon-filter: none; -gtk-icon-filter: none;
-gtk-icon-size: var(--notification-app-icon-size);
-gtk-icon-shadow: 0 1px 4px black; -gtk-icon-shadow: 0 1px 4px black;
margin: 6px; margin: 6px;
} }
...@@ -254,6 +260,7 @@ $notification-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), ...@@ -254,6 +260,7 @@ $notification-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3),
.notification-group-icon { .notification-group-icon {
color: var(--text-color); color: var(--text-color);
-gtk-icon-size: var(--notification-group-icon-size);
} }
.notification-group-header { .notification-group-header {
color: var(--text-color); color: var(--text-color);
......
:root { :root {
--mpris-album-art-overlay: rgba(0, 0, 0, 0.55); --mpris-album-art-overlay: rgba(0, 0, 0, 0.55);
--mpris-button-hover: rgba(0, 0, 0, 0.5); --mpris-button-hover: rgba(0, 0, 0, 0.5);
--mpris-album-art-icon-size: 96px;
} }
$mpris-shadow: 0px 0px 10px rgba(0, 0, 0, 0.75); $mpris-shadow: 0px 0px 10px rgba(0, 0, 0, 0.75);
...@@ -30,7 +31,7 @@ $mpris-shadow: 0px 0px 10px rgba(0, 0, 0, 0.75); ...@@ -30,7 +31,7 @@ $mpris-shadow: 0px 0px 10px rgba(0, 0, 0, 0.75);
.widget-mpris-album-art { .widget-mpris-album-art {
border-radius: $border-radius; border-radius: $border-radius;
box-shadow: $mpris-shadow; box-shadow: $mpris-shadow;
-gtk-icon-size: 96px; -gtk-icon-size: var(--mpris-album-art-icon-size);
} }
.widget-mpris-title { .widget-mpris-title {
font-weight: bold; font-weight: bold;
......
:root {
--widget-volume-row-icon-size: 24px;
}
.widget-volume { .widget-volume {
padding: $margin; padding: $margin;
margin: $margin; margin: $margin;
...@@ -7,6 +11,11 @@ ...@@ -7,6 +11,11 @@
.widget-volume > box > button { .widget-volume > box > button {
} }
/* Each row app icon */
.widget-volume row image {
-gtk-icon-size: var(--widget-volume-row-icon-size);
}
.per-app-volume { .per-app-volume {
background-color: var(--noti-bg-alt); background-color: var(--noti-bg-alt);
padding: $margin/2 $margin $margin $margin; padding: $margin/2 $margin $margin $margin;
......
...@@ -2,7 +2,7 @@ using Gtk 4.0; ...@@ -2,7 +2,7 @@ using Gtk 4.0;
template $SwayNotificationCenterWidgetsMprisMprisPlayer: $Underlay { template $SwayNotificationCenterWidgetsMprisMprisPlayer: $Underlay {
overflow: hidden; overflow: hidden;
valign: start; valign: fill;
hexpand: true; hexpand: true;
underlay_child: Picture background_picture { underlay_child: Picture background_picture {
...@@ -21,6 +21,7 @@ template $SwayNotificationCenterWidgetsMprisMprisPlayer: $Underlay { ...@@ -21,6 +21,7 @@ template $SwayNotificationCenterWidgetsMprisMprisPlayer: $Underlay {
] ]
Box { Box {
vexpand: true;
spacing: 12; spacing: 12;
Image album_art { Image album_art {
......
...@@ -586,17 +586,9 @@ namespace SwayNotificationCenter { ...@@ -586,17 +586,9 @@ namespace SwayNotificationCenter {
/** /**
* Notification icon size, in pixels. * Notification icon size, in pixels.
*/ */
private const int NOTIFICATION_ICON_MINIMUM_SIZE = 16; [Version (deprecated = true, replacement = "CSS root variable")]
private const int NOTIFICATION_ICON_DEFAULT_SIZE = 64;
private int _notification_icon_size = NOTIFICATION_ICON_DEFAULT_SIZE;
public int notification_icon_size { public int notification_icon_size {
get { get; set; default = -1;
return _notification_icon_size;
}
set {
_notification_icon_size = value > NOTIFICATION_ICON_MINIMUM_SIZE
? value : NOTIFICATION_ICON_MINIMUM_SIZE;
}
} }
/** /**
......
...@@ -97,9 +97,9 @@ ...@@ -97,9 +97,9 @@
}, },
"notification-icon-size": { "notification-icon-size": {
"type": "integer", "type": "integer",
"description": "The notification icon size (in pixels). The app icon size is 1/3", "deprecated": true,
"default": 64, "description": "deprecated (change the CSS root variable \"--notification-icon-size\"): The notification icon size (in pixels). The app icon size is 1/3",
"minimum": 16 "default": -1
}, },
"notification-body-image-height": { "notification-body-image-height": {
"type": "integer", "type": "integer",
...@@ -412,8 +412,9 @@ ...@@ -412,8 +412,9 @@
"properties": { "properties": {
"image-size": { "image-size": {
"type": "integer", "type": "integer",
"description": "The size of the album art", "deprecated": true,
"default": 96 "description": "deprecated (change the CSS root variable \"--mpris-album-art-icon-size\"): The size of the album art",
"default": -1
} }
} }
}, },
...@@ -556,8 +557,9 @@ ...@@ -556,8 +557,9 @@
}, },
"icon-size": { "icon-size": {
"type": "integer", "type": "integer",
"default": 24, "deprecated": true,
"description": "Size of the application icon in per app volume control" "default": -1,
"description": "deprecated (change the CSS root variable \"--widget-volume-row-icon-size\"): Size of the application icon in per app volume control"
}, },
"animation-type": { "animation-type": {
"type": "string", "type": "string",
......
namespace SwayNotificationCenter.Widgets.Mpris { namespace SwayNotificationCenter.Widgets.Mpris {
public struct Config { public struct Config {
[Version (deprecated = true, replacement = "CSS root variable")]
int image_size; int image_size;
bool autohide; bool autohide;
string[] blacklist; string[] blacklist;
...@@ -27,7 +28,7 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -27,7 +28,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
// Default config values // Default config values
Config mpris_config = Config () { Config mpris_config = Config () {
image_size = 96, image_size = -1,
autohide = false, autohide = false,
}; };
...@@ -81,8 +82,11 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -81,8 +82,11 @@ namespace SwayNotificationCenter.Widgets.Mpris {
Json.Object ? config = get_config (this); Json.Object ? config = get_config (this);
if (config != null) { if (config != null) {
// Get image-size // Get image-size
int? image_size = get_prop<int> (config, "image-size"); bool image_size_found;
if (image_size != null) mpris_config.image_size = image_size; int? image_size = get_prop<int> (config, "image-size", out image_size_found);
if (image_size_found && image_size != null) {
mpris_config.image_size = image_size;
}
Json.Array ? blacklist = get_prop_array (config, "blacklist"); Json.Array ? blacklist = get_prop_array (config, "blacklist");
if (blacklist != null) { if (blacklist != null) {
......
...@@ -269,11 +269,16 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -269,11 +269,16 @@ namespace SwayNotificationCenter.Widgets.Mpris {
} }
if (album_art_texture != null) { if (album_art_texture != null) {
// Set album art // Set album art
int icon_size = mpris_config.image_size;
if (icon_size < 0) {
icon_size = album_art_texture.width > album_art_texture.height
? album_art_texture.height : album_art_texture.width;
}
Gtk.Snapshot snapshot = new Gtk.Snapshot (); Gtk.Snapshot snapshot = new Gtk.Snapshot ();
Functions.scale_texture (album_art_texture, Functions.scale_texture (album_art_texture,
mpris_config.image_size, mpris_config.image_size, icon_size, icon_size,
get_scale_factor (), snapshot); get_scale_factor (), snapshot);
Graphene.Size size = Graphene.Size ().init (mpris_config.image_size, mpris_config.image_size); Graphene.Size size = Graphene.Size ().init (icon_size, icon_size);
album_art.set_from_paintable (snapshot.free_to_paintable (size)); album_art.set_from_paintable (snapshot.free_to_paintable (size));
// Set background album art // Set background album art
...@@ -291,21 +296,22 @@ namespace SwayNotificationCenter.Widgets.Mpris { ...@@ -291,21 +296,22 @@ namespace SwayNotificationCenter.Widgets.Mpris {
} }
unowned Gtk.IconTheme icon_theme = Gtk.IconTheme.get_for_display (get_display ()); unowned Gtk.IconTheme icon_theme = Gtk.IconTheme.get_for_display (get_display ());
if (icon != null) { if (icon != null) {
album_art.set_from_gicon (icon);
Gtk.IconPaintable ? icon_info = icon_theme.lookup_by_gicon ( Gtk.IconPaintable ? icon_info = icon_theme.lookup_by_gicon (
icon, mpris_config.image_size, get_scale_factor (), Gtk.TextDirection.NONE, 0); icon, 128, get_scale_factor (), Gtk.TextDirection.NONE, 0);
background_picture.set_paintable (icon_info); if (icon_info != null) {
} else { album_art.set_from_gicon (icon);
// Default icon background_picture.set_paintable (icon_info);
string icon_name = "audio-x-generic-symbolic"; return;
album_art.set_from_icon_name (icon_name); }
Gtk.IconPaintable ? icon_info = icon_theme.lookup_icon (
icon_name, null, mpris_config.image_size, get_scale_factor (),
Gtk.TextDirection.NONE, 0);
background_picture.set_paintable (icon_info);
} }
// Default icon
string icon_name = "audio-x-generic-symbolic";
album_art.set_from_icon_name (icon_name);
Gtk.IconPaintable ? icon_info = icon_theme.lookup_icon (
icon_name, null, 128, get_scale_factor (),
Gtk.TextDirection.NONE, 0);
background_picture.set_paintable (icon_info);
} }
private void update_button_shuffle (HashTable<string, Variant> metadata) { private void update_button_shuffle (HashTable<string, Variant> metadata) {
......
...@@ -26,7 +26,7 @@ namespace SwayNotificationCenter.Widgets { ...@@ -26,7 +26,7 @@ namespace SwayNotificationCenter.Widgets {
scale.draw_value = false; scale.draw_value = false;
scale.set_hexpand (true); scale.set_hexpand (true);
icon.pixel_size = icon_size; icon.set_pixel_size (icon_size);
container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
......
...@@ -20,7 +20,9 @@ namespace SwayNotificationCenter.Widgets { ...@@ -20,7 +20,9 @@ namespace SwayNotificationCenter.Widgets {
string ? expand_label = null; string ? expand_label = null;
string ? collapse_label = null; string ? collapse_label = null;
int icon_size = 24;
[Version (deprecated = true, replacement = "CSS root variable")]
int icon_size = -1;
Gtk.RevealerTransitionType revealer_type = Gtk.RevealerTransitionType.SLIDE_DOWN; Gtk.RevealerTransitionType revealer_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
int revealer_duration = 250; int revealer_duration = 250;
...@@ -124,8 +126,8 @@ namespace SwayNotificationCenter.Widgets { ...@@ -124,8 +126,8 @@ namespace SwayNotificationCenter.Widgets {
foreach (var item in this.client.active_sinks.values) { foreach (var item in this.client.active_sinks.values) {
SinkInputRow row = new SinkInputRow (item, client, SinkInputRow row = new SinkInputRow (item, client,
icon_size, show_per_app_icon, icon_size, show_per_app_icon,
show_per_app_label); show_per_app_label);
list_box_controller.append (row); list_box_controller.append (row);
} }
......
...@@ -30,7 +30,6 @@ namespace SwayNotificationCenter { ...@@ -30,7 +30,6 @@ namespace SwayNotificationCenter {
public static void set_image_uri (owned string uri, public static void set_image_uri (owned string uri,
Gtk.Image img, Gtk.Image img,
int icon_size,
bool file_exists, bool file_exists,
bool is_theme_icon = false) { bool is_theme_icon = false) {
const string URI_PREFIX = "file://"; const string URI_PREFIX = "file://";
...@@ -59,8 +58,7 @@ namespace SwayNotificationCenter { ...@@ -59,8 +58,7 @@ namespace SwayNotificationCenter {
} }
public static void set_image_data (ImageData data, public static void set_image_data (ImageData data,
Gtk.Image img, Gtk.Image img) {
int icon_size) {
Gdk.MemoryFormat format = Gdk.MemoryFormat.R8G8B8; Gdk.MemoryFormat format = Gdk.MemoryFormat.R8G8B8;
if (data.has_alpha) { if (data.has_alpha) {
format = Gdk.MemoryFormat.R8G8B8A8; format = Gdk.MemoryFormat.R8G8B8A8;
......
...@@ -103,8 +103,6 @@ namespace SwayNotificationCenter { ...@@ -103,8 +103,6 @@ namespace SwayNotificationCenter {
private bool default_action_down = false; private bool default_action_down = false;
private bool default_action_in = false; private bool default_action_in = false;
private int notification_icon_size { get; default = ConfigModel.instance.notification_icon_size; }
private int notification_body_image_height { private int notification_body_image_height {
get; get;
default = ConfigModel.instance.notification_body_image_height; default = ConfigModel.instance.notification_body_image_height;
...@@ -696,10 +694,11 @@ namespace SwayNotificationCenter { ...@@ -696,10 +694,11 @@ namespace SwayNotificationCenter {
return; return;
} }
int notification_icon_size = ConfigModel.instance.notification_icon_size.clamp (-1, int.MAX);
img.set_pixel_size (notification_icon_size); img.set_pixel_size (notification_icon_size);
img.height_request = notification_icon_size; img.height_request = notification_icon_size;
img.width_request = notification_icon_size; img.width_request = notification_icon_size;
int app_icon_size = notification_icon_size / 3; int app_icon_size = (notification_icon_size / 3).clamp (-1, int.MAX);
img_app_icon.set_pixel_size (app_icon_size); img_app_icon.set_pixel_size (app_icon_size);
bool img_path_is_theme_icon = false; bool img_path_is_theme_icon = false;
...@@ -724,25 +723,21 @@ namespace SwayNotificationCenter { ...@@ -724,25 +723,21 @@ namespace SwayNotificationCenter {
// Set the main image to the provided image // Set the main image to the provided image
if (param.image_data.is_initialized) { if (param.image_data.is_initialized) {
Functions.set_image_data (param.image_data, img, Functions.set_image_data (param.image_data, img);
notification_icon_size);
} else if (param.image_path != null && } else if (param.image_path != null &&
param.image_path != "" && param.image_path != "" &&
img_path_exists) { img_path_exists) {
Functions.set_image_uri (param.image_path, img, Functions.set_image_uri (param.image_path, img,
notification_icon_size,
img_path_exists, img_path_exists,
img_path_is_theme_icon); img_path_is_theme_icon);
} else if (param.icon_data.is_initialized) { } else if (param.icon_data.is_initialized) {
Functions.set_image_data (param.icon_data, img, Functions.set_image_data (param.icon_data, img);
notification_icon_size);
} }
if (img.storage_type == Gtk.ImageType.EMPTY) { if (img.storage_type == Gtk.ImageType.EMPTY) {
// Get the app icon // Get the app icon
if (app_icon_uri != null) { if (app_icon_uri != null) {
Functions.set_image_uri (app_icon_uri, img, Functions.set_image_uri (app_icon_uri, img,
notification_icon_size,
app_icon_exists); app_icon_exists);
} else if (app_icon_name != null) { } else if (app_icon_name != null) {
img.set_from_gicon (app_icon_name); img.set_from_gicon (app_icon_name);
...@@ -756,7 +751,6 @@ namespace SwayNotificationCenter { ...@@ -756,7 +751,6 @@ namespace SwayNotificationCenter {
// We only set the app icon if the main image is set // We only set the app icon if the main image is set
if (app_icon_uri != null) { if (app_icon_uri != null) {
Functions.set_image_uri (app_icon_uri, img_app_icon, Functions.set_image_uri (app_icon_uri, img_app_icon,
app_icon_size,
app_icon_exists); app_icon_exists);
} else if (app_icon_name != null) { } else if (app_icon_name != null) {
img_app_icon.set_from_gicon (app_icon_name); img_app_icon.set_from_gicon (app_icon_name);
......
...@@ -85,7 +85,6 @@ namespace SwayNotificationCenter { ...@@ -85,7 +85,6 @@ namespace SwayNotificationCenter {
start_box.add_css_class ("notification-group-headers"); start_box.add_css_class ("notification-group-headers");
// App Icon // App Icon
app_icon = new Gtk.Image (); app_icon = new Gtk.Image ();
app_icon.set_pixel_size (32);
app_icon.set_valign (Gtk.Align.CENTER); app_icon.set_valign (Gtk.Align.CENTER);
app_icon.add_css_class ("notification-group-icon"); app_icon.add_css_class ("notification-group-icon");
start_box.append (app_icon); start_box.append (app_icon);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment