Skip to content
Permalink
Browse files

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
  • Loading branch information...
lukefromdc committed May 18, 2018
1 parent 57b6fa4 commit fff8a2f369a80ed7254a1a73bac9bf8e1b337668
Showing with 62 additions and 1 deletion.
  1. +62 −1 plugins/xrandr/msd-xrandr-manager.c
@@ -1671,6 +1671,45 @@ status_icon_popup_menu_selection_done_cb (GtkMenuShell *menu_shell, gpointer dat

#define OUTPUT_TITLE_ITEM_BORDER 2
#define OUTPUT_TITLE_ITEM_PADDING 4
static gboolean
output_title_label_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
{
MsdXrandrManager *manager = MSD_XRANDR_MANAGER (data);
struct MsdXrandrManagerPrivate *priv = manager->priv;
MateRROutputInfo *output;
GdkRGBA color;
GString *string;
gchar *css, *color_string;
GtkStyleContext *context;
GtkCssProvider *provider;

output = g_object_get_data (G_OBJECT (widget), "output");

mate_rr_labeler_get_rgba_for_output (priv->labeler, output, &color);

color_string = gdk_rgba_to_string (&color);

string = g_string_new(NULL);
g_string_append (string, ".mate-panel-menu-bar menuitem.xrandr-applet:disabled>box>label{\n");
g_string_append (string, "color: black;");
g_string_append (string, "padding-left: 4px; padding-right: 4px;");
g_string_append (string, "background-color:");
g_string_append (string, color_string);
g_string_append (string," }");

css = g_string_free (string, FALSE);

context = gtk_widget_get_style_context (widget);
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,css, -1, NULL);

gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);

return FALSE;
}

static void
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
{
GtkWidget *item;
GtkStyleContext *context;
GtkCssProvider *provider;
GtkWidget *label;
GtkWidget *image;
GtkWidget *box;
char *str;

item = gtk_menu_item_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
image = gtk_image_new_from_icon_name ("computer-symbolic", GTK_ICON_SIZE_MENU);
image = gtk_image_new_from_icon_name ("computer", GTK_ICON_SIZE_MENU);
context = gtk_widget_get_style_context (item);
gtk_style_context_add_class (context, "xrandr-applet");

/*Disable effects applied to icons in an insensitive menu item*/
context = gtk_widget_get_style_context (image);
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
".mate-panel-menu-bar menuitem.xrandr-applet:disabled>box>image{\n"
"opacity: 1.0; \n"
"-gtk-icon-effect: none; \n"
"}",
-1, NULL);
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);


g_signal_connect (item, "size-allocate",
G_CALLBACK (title_item_size_allocate_cb), NULL);

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

g_signal_connect (label, "draw",
G_CALLBACK (output_title_label_draw_cb), manager);

g_object_set_data (G_OBJECT (label), "output", output);

gtk_widget_set_sensitive (item, FALSE); /* the title is not selectable */

gtk_widget_show_all (item);

return item;

0 comments on commit fff8a2f

Please sign in to comment.
You can’t perform that action at this time.