Skip to content

Commit

Permalink
Allow icon sizes to be configured in the context menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtwebster committed Jun 6, 2024
1 parent 6ec6a25 commit 339443c
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 31 deletions.
1 change: 1 addition & 0 deletions debian/xfce4-xapp-status-plugin.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/lib/*/xfce4/panel/plugins
usr/share/xfce4/panel/plugins
usr/share/locale
usr/share/glib-2.0/schemas
8 changes: 8 additions & 0 deletions plugin/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ i18n.merge_file(
install: true,
install_dir: join_paths(get_option('datadir'), 'xfce4', 'panel', 'plugins')
)

install_data('org.x.apps.xfce4-status-plugin.gschema.xml',
install_dir: join_paths(get_option('datadir'), 'glib-2.0', 'schemas')
)

gnome.post_install(
glib_compile_schemas: true
)
13 changes: 13 additions & 0 deletions plugin/org.x.apps.xfce4-status-plugin.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<schemalist>
<schema id="org.x.apps.xfce4-status-plugin" path="/org/x/apps/xfce4-status-plugin/" gettext-domain="xapps">
<key name="symbolic-icon-size" type="i">
<default>18</default>
<summary>Symbolic icon size</summary>
</key>
<key name="color-icon-size" type="i">
<default>-1</default>
<summary>Color icon size, or -1 to use optimal size for panel height.</summary>
</key>
</schema>
</schemalist>
44 changes: 23 additions & 21 deletions plugin/status-icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ struct _StatusIcon
{
GtkToggleButton parent_instance;

gint size; /* Size of the panel to calculate from */
gint color_icon_size;
gint symbolic_icon_size;

GtkPositionType orientation; /* Orientation of the panel */
const gchar *name;
const gchar *process_name;
Expand Down Expand Up @@ -131,7 +133,8 @@ load_image_from_file_thread (GTask *task,

static void
load_file_based_image (StatusIcon *icon,
const gchar *path)
const gchar *path,
gint icon_size)
{

ImageFromFileAsyncData *data;
Expand All @@ -140,7 +143,7 @@ load_file_based_image (StatusIcon *icon,
data = g_new0 (ImageFromFileAsyncData, 1);
// I can't imagine supporting a vertical panel somehow.. but it's here in case.
data->width = -1;
data->height = icon->size;
data->height = icon_size;
data->scale = gtk_widget_get_scale_factor (GTK_WIDGET (icon));
data->path = g_strdup (path);

Expand All @@ -164,6 +167,8 @@ update_image (StatusIcon *icon)

GIcon *gicon;
const gchar *icon_name;
gboolean is_symbolic = FALSE;
gint icon_size;

icon_name = xapp_status_icon_interface_get_icon_name (XAPP_STATUS_ICON_INTERFACE (icon->proxy));
gicon = NULL;
Expand All @@ -173,17 +178,20 @@ update_image (StatusIcon *icon)
return;
}

is_symbolic = !!g_strstr_len (icon_name, -1, "-symbolic");
icon_size = is_symbolic ? icon->symbolic_icon_size : icon->color_icon_size;

if (g_file_test (icon_name, G_FILE_TEST_EXISTS))
{
if (g_str_has_suffix (icon_name, "symbolic") || VERTICAL_PANEL (icon->orientation))
if (is_symbolic || VERTICAL_PANEL (icon->orientation))
{
GFile *icon_file = g_file_new_for_path (icon_name);
gicon = G_ICON (g_file_icon_new (icon_file));
g_object_unref (icon_file);
}
else
{
load_file_based_image(icon, icon_name);
load_file_based_image(icon, icon_name, icon_size);
return;
}
}
Expand All @@ -198,7 +206,8 @@ update_image (StatusIcon *icon)
}
}

gtk_image_set_pixel_size (GTK_IMAGE (icon->image), icon->size);
gtk_image_set_pixel_size (GTK_IMAGE (icon->image),
icon_size);

if (gicon)
{
Expand Down Expand Up @@ -543,22 +552,14 @@ load_metadata (StatusIcon *icon)
}

void
status_icon_set_size (StatusIcon *icon, gint size)
status_icon_set_size (StatusIcon *icon,
gint color_size,
gint symbolic_size)
{
g_return_if_fail (STATUS_IS_ICON (icon));

if (size % 2 != 0)
{
size--;
}

if (icon->size == size)
{
return;
}

icon->size = size;
xapp_status_icon_interface_set_icon_size (icon->proxy, size);
icon->color_icon_size = color_size;
icon->symbolic_icon_size = symbolic_size;

update_image (icon);
}
Expand Down Expand Up @@ -588,7 +589,8 @@ status_icon_get_proxy (StatusIcon *icon)

StatusIcon *
status_icon_new (XAppStatusIconInterface *proxy,
gint icon_size)
gint color_icon_size,
gint symbolic_icon_size)
{
StatusIcon *icon = g_object_new (STATUS_TYPE_ICON, NULL);
icon->proxy = g_object_ref (proxy);
Expand All @@ -598,7 +600,7 @@ status_icon_new (XAppStatusIconInterface *proxy,
load_metadata (icon);

update_orientation (icon);
status_icon_set_size (icon, icon_size);
status_icon_set_size (icon, color_icon_size, symbolic_icon_size);

return icon;
}
6 changes: 4 additions & 2 deletions plugin/status-icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ G_DECLARE_FINAL_TYPE (StatusIcon, status_icon, STATUS, ICON, GtkToggleButton)
#define VISIBLE_LABEL_MARGIN 5 // When an icon has a label, add a margin between icon and label

StatusIcon *status_icon_new (XAppStatusIconInterface *proxy,
gint icon_size);
gint color_icon_size,
gint symbolic_icon_size);

void status_icon_set_size (StatusIcon *icon,
gint size);
gint color_icon_size,
gint symbolic_icon_size);
void status_icon_set_orientation (StatusIcon *icon,
GtkPositionType orientation);
XAppStatusIconInterface *status_icon_get_proxy (StatusIcon *icon);
Expand Down
Loading

0 comments on commit 339443c

Please sign in to comment.