~noskcaj/ubuntu/trusty/xfce4-panel/4.11

« back to all changes in this revision

Viewing changes to wrapper/wrapper-plug.c

  • Committer: Package Import Robot
  • Author(s): Unit 193, Unit 193, Lionel Le Folgoc
  • Date: 2014-02-12 15:41:39 UTC
  • mfrom: (1.1.36)
  • Revision ID: package-import@ubuntu.com-20140212154139-j4cm4hlso68qadjw
Tags: 4.11.0~0.git20140209.86a1b73-0ubuntu1
[ Unit 193 ]
* New git snapshot. (LP: #1238997)
* debian/patches:
  - 02_potfiles-fix-ftbfs.patch: added, add missing files to po/POTFILES.in.
* debian/control: add b-dep on newer garcon.

[ Lionel Le Folgoc ]
* debian/patches:
  - xubuntu_add-calendar-popup-to-clock-plugin.patch: dropped, included.
  - series: refreshed.
* debian/xfce4-panel.install: include both (gtk2 and gtk3) wrappers.
* debian/rules: pass --enable-gtk3 --disable-silent-rules to configure script.
* debian/control: add b-dep on libgtk-3-dev.
* debian/xfce4-panel.shlibs: updated for the gtk3 library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
 
32
32
static void     wrapper_plug_finalize         (GObject        *object);
 
33
#if GTK_CHECK_VERSION (3, 0, 0)
 
34
static gboolean wrapper_plug_draw             (GtkWidget      *widget,
 
35
                                               cairo_t        *cr);
 
36
#else
33
37
static gboolean wrapper_plug_expose_event     (GtkWidget      *widget,
34
38
                                               GdkEventExpose *event);
 
39
#endif
35
40
static void     wrapper_plug_background_reset (WrapperPlug    *plug);
36
41
 
37
42
 
73
78
  gobject_class->finalize = wrapper_plug_finalize;
74
79
 
75
80
  gtkwidget_class = GTK_WIDGET_CLASS (klass);
 
81
#if GTK_CHECK_VERSION (3, 0, 0)
 
82
  gtkwidget_class->draw = wrapper_plug_draw;
 
83
#else
76
84
  gtkwidget_class->expose_event = wrapper_plug_expose_event;
 
85
#endif
77
86
}
78
87
 
79
88
 
81
90
static void
82
91
wrapper_plug_init (WrapperPlug *plug)
83
92
{
 
93
#if GTK_CHECK_VERSION (3, 0, 0)
 
94
  GdkVisual       *visual = NULL;
 
95
  GdkScreen       *screen;
 
96
  GtkStyleContext *context;
 
97
  GtkCssProvider  *provider = gtk_css_provider_new();
 
98
  gchar           *css_string;
 
99
#else
84
100
  GdkColormap *colormap = NULL;
85
101
  GdkScreen   *screen;
 
102
#endif
86
103
 
87
104
  plug->background_alpha = 1.00;
88
105
  plug->background_color = NULL;
94
111
  /* allow painting, else compositing won't work */
95
112
  gtk_widget_set_app_paintable (GTK_WIDGET (plug), TRUE);
96
113
 
 
114
#if !GTK_CHECK_VERSION (3, 0, 0)
97
115
  /* old versions of gtk don't support transparent tray icons, if we
98
116
   * set an argb colormap on the tray, the icons won't be embedded because
99
117
   * the socket-plugin implementation requires identical colormaps */
100
118
  if (gtk_check_version (2, 16, 0) != NULL
101
119
      && strcmp (wrapper_name, "systray") == 0)
102
120
    return;
 
121
#endif
103
122
 
104
123
  /* set the colormap */
105
124
  screen = gtk_window_get_screen (GTK_WINDOW (plug));
 
125
#if GTK_CHECK_VERSION (3, 0, 0)
 
126
  visual = gdk_screen_get_rgba_visual (screen);
 
127
  if (visual != NULL)
 
128
    gtk_widget_set_visual (GTK_WIDGET (plug), visual);
 
129
#else
106
130
  colormap = gdk_screen_get_rgba_colormap (screen);
107
131
  if (colormap != NULL)
108
132
    gtk_widget_set_colormap (GTK_WIDGET (plug), colormap);
 
133
#endif
 
134
 
 
135
#if GTK_CHECK_VERSION (3, 0, 0)
 
136
  /* set the panel class */
 
137
  context = gtk_widget_get_style_context (GTK_WIDGET (plug));
 
138
  gtk_style_context_add_class (context, "panel");
 
139
  gtk_style_context_add_class (context, "xfce4-panel");
 
140
 
 
141
  /* We need to set the plugin button to transparent and let everything else
 
142
   * be in the theme or panel's color */
 
143
  css_string = g_strdup_printf (".xfce4-panel .button { background-color: transparent; }");
 
144
  gtk_css_provider_load_from_data (provider, css_string, -1, NULL);
 
145
  gtk_style_context_add_provider (context,
 
146
                                  GTK_STYLE_PROVIDER (provider),
 
147
                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 
148
 
 
149
  g_free (css_string);
 
150
  g_object_unref (provider);
 
151
#endif
109
152
}
110
153
 
111
154
 
120
163
 
121
164
 
122
165
 
 
166
#if GTK_CHECK_VERSION (3, 0, 0)
 
167
static gboolean
 
168
wrapper_plug_draw (GtkWidget *widget,
 
169
                   cairo_t   *cr)
 
170
{
 
171
  WrapperPlug     *plug = WRAPPER_PLUG (widget);
 
172
  GtkStyleContext *style;
 
173
  const GdkColor  *color;
 
174
  GdkRGBA          rgba;
 
175
  gdouble          alpha;
 
176
  GdkPixbuf       *pixbuf;
 
177
  GError          *error = NULL;
 
178
 
 
179
  cairo_save (cr);
 
180
 
 
181
  /* The "draw" signal is in widget coordinates, transform back to window */
 
182
  gtk_cairo_transform_to_window (cr,
 
183
                                 GTK_WIDGET (plug),
 
184
                                 gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (plug))));
 
185
 
 
186
  if (G_UNLIKELY (plug->background_image != NULL))
 
187
    {
 
188
      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
 
189
 
 
190
      if (G_LIKELY (plug->background_image_cache != NULL))
 
191
        {
 
192
          cairo_set_source (cr, plug->background_image_cache);
 
193
          cairo_paint (cr);
 
194
        }
 
195
      else
 
196
        {
 
197
          /* load the image in a pixbuf */
 
198
          pixbuf = gdk_pixbuf_new_from_file (plug->background_image, &error);
 
199
 
 
200
          if (G_LIKELY (pixbuf != NULL))
 
201
            {
 
202
              gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
 
203
              g_object_unref (G_OBJECT (pixbuf));
 
204
 
 
205
              plug->background_image_cache = cairo_get_source (cr);
 
206
              cairo_pattern_reference (plug->background_image_cache);
 
207
              cairo_pattern_set_extend (plug->background_image_cache, CAIRO_EXTEND_REPEAT);
 
208
              cairo_paint (cr);
 
209
            }
 
210
          else
 
211
            {
 
212
              /* print error message */
 
213
              g_warning ("Background image disabled, \"%s\" could not be loaded: %s",
 
214
                         plug->background_image, error != NULL ? error->message : "No error");
 
215
              g_error_free (error);
 
216
 
 
217
              /* disable background image */
 
218
              wrapper_plug_background_reset (plug);
 
219
            }
 
220
        }
 
221
    }
 
222
  else
 
223
    {
 
224
      alpha = gtk_widget_is_composited (GTK_WIDGET (plug)) ? plug->background_alpha : 1.00;
 
225
 
 
226
      if (alpha < 1.00 || plug->background_color != NULL)
 
227
        {
 
228
          cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
 
229
 
 
230
          /* get the background gdk color */
 
231
          if (plug->background_color != NULL)
 
232
            {
 
233
              color = plug->background_color;
 
234
              cairo_set_source_rgba (cr, PANEL_GDKCOLOR_TO_DOUBLE (color), alpha);
 
235
            }
 
236
          else
 
237
            {
 
238
              style = gtk_widget_get_style_context (widget);
 
239
              gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &rgba);
 
240
              rgba.alpha = alpha;
 
241
              gdk_cairo_set_source_rgba (cr, &rgba);
 
242
            }
 
243
 
 
244
          /* draw the background color */
 
245
          cairo_paint (cr);
 
246
        }
 
247
    }
 
248
 
 
249
  cairo_restore(cr);
 
250
 
 
251
  return GTK_WIDGET_CLASS (wrapper_plug_parent_class)->draw (widget, cr);
 
252
}
 
253
 
 
254
#else
 
255
 
123
256
static gboolean
124
257
wrapper_plug_expose_event (GtkWidget      *widget,
125
258
                           GdkEventExpose *event)
199
332
 
200
333
  return GTK_WIDGET_CLASS (wrapper_plug_parent_class)->expose_event (widget, event);
201
334
}
 
335
#endif
202
336
 
203
337
 
204
338
 
222
356
 
223
357
 
224
358
WrapperPlug *
 
359
#if GTK_CHECK_VERSION (3, 0, 0)
 
360
wrapper_plug_new (Window socket_id)
 
361
#else
225
362
wrapper_plug_new (GdkNativeWindow socket_id)
 
363
#endif
226
364
{
227
365
  WrapperPlug *plug;
228
366