Skip to content

Commit fff8a2f

Browse files
committed
xrandr-applet-popup: use colored bg again in monitor labels
*Build a cssprovider from strings, use a variable to apply the same colors as used on the rectangles shown on each monitor to the matching label backgrounds in the popup menu. Bring back the draw callback to handle it, so necessary data can be passed to mate_rr_labeler_get_rgba_for_output *Keep disabled item dimming effects off the monitor label icons *Tie the dynamic cssprovider to the label so it always gets the correct color
1 parent 57b6fa4 commit fff8a2f

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

plugins/xrandr/msd-xrandr-manager.c

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,45 @@ status_icon_popup_menu_selection_done_cb (GtkMenuShell *menu_shell, gpointer dat
16711671

16721672
#define OUTPUT_TITLE_ITEM_BORDER 2
16731673
#define OUTPUT_TITLE_ITEM_PADDING 4
1674+
static gboolean
1675+
output_title_label_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
1676+
{
1677+
MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data);
1678+
struct MsdXrandrManagerPrivate *priv = manager->priv;
1679+
MateRROutputInfo *output;
1680+
GdkRGBA color;
1681+
GString *string;
1682+
gchar *css, *color_string;
1683+
GtkStyleContext *context;
1684+
GtkCssProvider *provider;
1685+
1686+
output = g_object_get_data (G_OBJECT (widget), "output");
1687+
1688+
mate_rr_labeler_get_rgba_for_output (priv->labeler, output, &color);
1689+
1690+
color_string = gdk_rgba_to_string (&color);
1691+
1692+
string = g_string_new(NULL);
1693+
g_string_append (string, ".mate-panel-menu-bar menuitem.xrandr-applet:disabled>box>label{\n");
1694+
g_string_append (string, "color: black;");
1695+
g_string_append (string, "padding-left: 4px; padding-right: 4px;");
1696+
g_string_append (string, "background-color:");
1697+
g_string_append (string, color_string);
1698+
g_string_append (string," }");
1699+
1700+
css = g_string_free (string, FALSE);
1701+
1702+
context = gtk_widget_get_style_context (widget);
1703+
provider = gtk_css_provider_new ();
1704+
gtk_css_provider_load_from_data (provider,css, -1, NULL);
1705+
1706+
gtk_style_context_add_provider (context,
1707+
GTK_STYLE_PROVIDER (provider),
1708+
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1709+
g_object_unref (provider);
1710+
1711+
return FALSE;
1712+
}
16741713

16751714
static void
16761715
title_item_size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
@@ -1716,17 +1755,33 @@ make_menu_item_for_output_title (MsdXrandrManager *manager, MateRROutputInfo *ou
17161755
{
17171756
GtkWidget *item;
17181757
GtkStyleContext *context;
1758+
GtkCssProvider *provider;
17191759
GtkWidget *label;
17201760
GtkWidget *image;
17211761
GtkWidget *box;
17221762
char *str;
17231763

17241764
item = gtk_menu_item_new ();
17251765
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
1726-
image = gtk_image_new_from_icon_name ("computer-symbolic", GTK_ICON_SIZE_MENU);
1766+
image = gtk_image_new_from_icon_name ("computer", GTK_ICON_SIZE_MENU);
17271767
context = gtk_widget_get_style_context (item);
17281768
gtk_style_context_add_class (context, "xrandr-applet");
17291769

1770+
/*Disable effects applied to icons in an insensitive menu item*/
1771+
context = gtk_widget_get_style_context (image);
1772+
provider = gtk_css_provider_new ();
1773+
gtk_css_provider_load_from_data (provider,
1774+
".mate-panel-menu-bar menuitem.xrandr-applet:disabled>box>image{\n"
1775+
"opacity: 1.0; \n"
1776+
"-gtk-icon-effect: none; \n"
1777+
"}",
1778+
-1, NULL);
1779+
gtk_style_context_add_provider (context,
1780+
GTK_STYLE_PROVIDER (provider),
1781+
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1782+
g_object_unref (provider);
1783+
1784+
17301785
g_signal_connect (item, "size-allocate",
17311786
G_CALLBACK (title_item_size_allocate_cb), NULL);
17321787

@@ -1747,7 +1802,13 @@ make_menu_item_for_output_title (MsdXrandrManager *manager, MateRROutputInfo *ou
17471802
gtk_container_add (GTK_CONTAINER (box), label);
17481803
gtk_container_add (GTK_CONTAINER (item), box);
17491804

1805+
g_signal_connect (label, "draw",
1806+
G_CALLBACK (output_title_label_draw_cb), manager);
1807+
1808+
g_object_set_data (G_OBJECT (label), "output", output);
1809+
17501810
gtk_widget_set_sensitive (item, FALSE); /* the title is not selectable */
1811+
17511812
gtk_widget_show_all (item);
17521813

17531814
return item;

0 commit comments

Comments
 (0)