Commit 3115f77b authored by Alberts Muktupāvels's avatar Alberts Muktupāvels

libpanel-applet: restore custom background

parent ebd80f63
panel-toplevel {
panel-toplevel,
panel-plug {
background-color: #393f3f;
}
......
panel-toplevel {
panel-toplevel,
panel-plug {
background-color: #e8e8e7;
}
......
panel-toplevel {
panel-toplevel,
panel-plug {
background-color: #ffffff;
}
......
......@@ -24,7 +24,9 @@ libpanel_applet_la_SOURCES = \
panel-applet-factory.c \
panel-applet-bindings.h \
panel-applet-bindings.c \
panel-applet-private.h
panel-applet-private.h \
panel-plug.c \
panel-plug-private.h
libpanel_applet_la_LIBADD = \
$(LIBPANEL_APPLET_LIBS) \
......
......@@ -45,6 +45,7 @@
#include "panel-applet-factory.h"
#include "panel-applet-marshal.h"
#include "panel-applet-enums.h"
#include "panel-plug-private.h"
/**
* SECTION:applet
......@@ -94,7 +95,6 @@ struct _PanelAppletPrivate {
PanelAppletFlags flags;
PanelAppletOrient orient;
char *background;
GtkWidget *background_widget;
int previous_width;
int previous_height;
......@@ -1495,37 +1495,27 @@ panel_applet_style_updated (GtkWidget *widget)
}
static void
panel_applet_update_background_for_widget (GtkWidget *widget,
cairo_pattern_t *pattern)
panel_applet_handle_background (PanelApplet *applet)
{
GdkWindow *window;
cairo_pattern_t *pattern;
window = gtk_widget_get_window (widget);
if (!window)
if (applet->priv->plug == NULL)
return;
gdk_window_set_background_pattern (window,
pattern);
}
window = gtk_widget_get_window (applet->priv->plug);
static void
panel_applet_handle_background (PanelApplet *applet)
{
cairo_pattern_t *pattern;
if (window == NULL)
return;
pattern = panel_applet_get_background (applet);
if (applet->priv->background_widget)
panel_applet_update_background_for_widget (applet->priv->background_widget,
pattern);
else
panel_applet_update_background_for_widget (GTK_WIDGET (applet), pattern);
gdk_window_set_background_pattern (window, pattern);
gtk_widget_queue_draw (applet->priv->plug);
g_signal_emit (applet, panel_applet_signals [CHANGE_BACKGROUND], 0, pattern);
g_signal_emit (G_OBJECT (applet),
panel_applet_signals [CHANGE_BACKGROUND],
0, pattern);
if (pattern)
if (pattern)
cairo_pattern_destroy (pattern);
}
......@@ -1771,7 +1761,7 @@ panel_applet_constructor (GType type,
if (!applet->priv->out_of_process)
return object;
applet->priv->plug = gtk_plug_new (0);
applet->priv->plug = panel_plug_new ();
g_signal_connect_swapped (G_OBJECT (applet->priv->plug), "embedded",
G_CALLBACK (panel_applet_setup),
......@@ -2352,21 +2342,13 @@ panel_applet_factory_setup_in_process (const gchar *factory_id,
* Configure #PanelApplet to automatically draw the background of the applet on
* @widget. It is generally enough to call this function with @applet as
* @widget.
*
* Deprecated: 3.20: Do not use this API. Since 3.20 this function does nothing.
**/
void
panel_applet_set_background_widget (PanelApplet *applet,
GtkWidget *widget)
{
applet->priv->background_widget = widget;
if (widget && gtk_widget_get_realized (widget)) {
cairo_pattern_t *pattern;
pattern = panel_applet_get_background (applet);
panel_applet_update_background_for_widget (widget, pattern);
if (pattern)
cairo_pattern_destroy (pattern);
}
}
guint32
......
/*
* Copyright (C) 2016 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PANEL_PLUG_PRIVATE_H
#define PANEL_PLUG_PRIVATE_H
#include <gtk/gtkx.h>
G_BEGIN_DECLS
#define PANEL_TYPE_PLUG panel_plug_get_type ()
G_DECLARE_FINAL_TYPE (PanelPlug, panel_plug, PANEL, PLUG, GtkPlug)
GtkWidget *panel_plug_new (void);
G_END_DECLS
#endif
/*
* Copyright (C) 2016 Alberts Muktupāvels
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "panel-plug-private.h"
struct _PanelPlug
{
GtkPlug parent;
};
G_DEFINE_TYPE (PanelPlug, panel_plug, GTK_TYPE_PLUG)
static gboolean
panel_plug_draw (GtkWidget *widget,
cairo_t *cr)
{
GdkWindow *window;
cairo_pattern_t *pattern;
if (!gtk_widget_get_realized (widget))
return GTK_WIDGET_CLASS (panel_plug_parent_class)->draw (widget, cr);
window = gtk_widget_get_window (widget);
pattern = gdk_window_get_background_pattern (window);
if (!pattern)
{
GtkStyleContext *context;
gint width;
gint height;
context = gtk_widget_get_style_context (widget);
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
gtk_render_background (context, cr, 0, 0, width, height);
}
return GTK_WIDGET_CLASS (panel_plug_parent_class)->draw (widget, cr);
}
static void
panel_plug_realize (GtkWidget *widget)
{
GdkScreen *screen;
GdkVisual *visual;
screen = gdk_screen_get_default ();
visual = gdk_screen_get_rgba_visual (screen);
if (!visual)
visual = gdk_screen_get_system_visual (screen);
gtk_widget_set_visual (widget, visual);
GTK_WIDGET_CLASS (panel_plug_parent_class)->realize (widget);
}
static void
panel_plug_class_init (PanelPlugClass *plug_class)
{
GtkWidgetClass *widget_class;
widget_class = GTK_WIDGET_CLASS (plug_class);
widget_class->draw = panel_plug_draw;
widget_class->realize = panel_plug_realize;
gtk_widget_class_set_css_name (widget_class, "panel-plug");
}
static void
panel_plug_init (PanelPlug *plug)
{
gtk_widget_set_app_paintable (GTK_WIDGET (plug), TRUE);
}
GtkWidget *
panel_plug_new (void)
{
return g_object_new (PANEL_TYPE_PLUG, NULL);
}
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