~ubuntu-branches/ubuntu/quantal/gnome-desktop3/quantal-proposed

« back to all changes in this revision

Viewing changes to libgnome-desktop/gnome-rr-labeler.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-06-05 16:10:52 UTC
  • mfrom: (1.5.10)
  • Revision ID: package-import@ubuntu.com-20120605161052-f7oft7thbnds4lxu
Tags: 3.5.2-0ubuntu1
* New upstream release
* debian/control:
  - Add build-depends on xkb-data, libxkbfile-dev
  - Update package names for new library version
* debian/rules:
  - Update package names for new library version
* debian/libgnome-desktop-3-4.symbols:
  - Updated
* debian/patches/03_default_display_is_internal.patch:
  - Applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
        int num_outputs;
46
46
 
47
 
        GdkColor *palette;
 
47
        GdkRGBA *palette;
48
48
        GtkWidget **windows;
49
49
 
50
50
        GdkScreen  *screen;
200
200
 
201
201
        g_assert (labeler->priv->num_outputs > 0);
202
202
 
203
 
        labeler->priv->palette = g_new (GdkColor, labeler->priv->num_outputs);
 
203
        labeler->priv->palette = g_new (GdkRGBA, labeler->priv->num_outputs);
204
204
 
205
205
        start_hue = 0.0; /* red */
206
206
        end_hue   = 2.0/3; /* blue */
215
215
 
216
216
                gtk_hsv_to_rgb (h, s, v, &r, &g, &b);
217
217
 
218
 
                labeler->priv->palette[i].red   = (int) (65535 * r + 0.5);
219
 
                labeler->priv->palette[i].green = (int) (65535 * g + 0.5);
220
 
                labeler->priv->palette[i].blue  = (int) (65535 * b + 0.5);
 
218
                labeler->priv->palette[i].red   = r;
 
219
                labeler->priv->palette[i].green = g;
 
220
                labeler->priv->palette[i].blue  = b;
 
221
                labeler->priv->palette[i].alpha  = 1.0;
221
222
        }
222
223
}
223
224
 
227
228
static gboolean
228
229
label_window_draw_event_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
229
230
{
230
 
        GdkColor *color;
 
231
        GdkRGBA *rgba;
231
232
        GtkAllocation allocation;
232
233
 
233
 
        color = g_object_get_data (G_OBJECT (widget), "color");
 
234
        rgba = g_object_get_data (G_OBJECT (widget), "rgba");
234
235
        gtk_widget_get_allocation (widget, &allocation);
235
236
 
 
237
        cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
 
238
 
236
239
        /* edge outline */
237
 
 
238
 
        cairo_set_source_rgb (cr, 0, 0, 0);
 
240
        cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
239
241
        cairo_rectangle (cr,
240
242
                         LABEL_WINDOW_EDGE_THICKNESS / 2.0,
241
243
                         LABEL_WINDOW_EDGE_THICKNESS / 2.0,
245
247
        cairo_stroke (cr);
246
248
 
247
249
        /* fill */
248
 
 
249
 
        gdk_cairo_set_source_color (cr, color);
 
250
        rgba->alpha = 0.75;
 
251
        gdk_cairo_set_source_rgba (cr, rgba);
250
252
        cairo_rectangle (cr,
251
253
                         LABEL_WINDOW_EDGE_THICKNESS,
252
254
                         LABEL_WINDOW_EDGE_THICKNESS,
277
279
        gtk_window_move (GTK_WINDOW (window), workarea.x, workarea.y);
278
280
}
279
281
 
 
282
static void
 
283
label_window_realize_cb (GtkWidget *widget)
 
284
{
 
285
        cairo_region_t *region;
 
286
 
 
287
        /* make the whole window ignore events */
 
288
        region = cairo_region_create ();
 
289
        gtk_widget_input_shape_combine_region (widget, region);
 
290
        cairo_region_destroy (region);
 
291
}
 
292
 
280
293
static GtkWidget *
281
 
create_label_window (GnomeRRLabeler *labeler, GnomeRROutputInfo *output, GdkColor *color)
 
294
create_label_window (GnomeRRLabeler *labeler, GnomeRROutputInfo *output, GdkRGBA *rgba)
282
295
{
283
296
        GtkWidget *window;
284
297
        GtkWidget *widget;
285
298
        char *str;
286
299
        const char *display_name;
287
 
        GdkColor black = { 0, 0, 0, 0 };
288
 
        int x,y;
 
300
        GdkRGBA black = { 0, 0, 0, 1.0 };
 
301
        int x, y;
 
302
        GdkScreen *screen;
 
303
        GdkVisual *visual;
289
304
 
290
305
        window = gtk_window_new (GTK_WINDOW_POPUP);
 
306
        gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_TOOLTIP);
 
307
        gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
291
308
        gtk_widget_set_app_paintable (window, TRUE);
 
309
        screen = gtk_widget_get_screen (window);
 
310
        visual = gdk_screen_get_rgba_visual (screen);
 
311
 
 
312
        if (visual != NULL)
 
313
                gtk_widget_set_visual (window, visual);
292
314
 
293
315
        gtk_container_set_border_width (GTK_CONTAINER (window), LABEL_WINDOW_PADDING + LABEL_WINDOW_EDGE_THICKNESS);
294
316
 
296
318
         * array.  Note that in gnome_rr_labeler_finalize(), we are careful to
297
319
         * free the palette only after we free the windows.
298
320
         */
299
 
        g_object_set_data (G_OBJECT (window), "color", color);
 
321
        g_object_set_data (G_OBJECT (window), "rgba", rgba);
300
322
 
301
323
        g_signal_connect (window, "draw",
302
324
                          G_CALLBACK (label_window_draw_event_cb), labeler);
 
325
        g_signal_connect (window, "realize",
 
326
                          G_CALLBACK (label_window_realize_cb), labeler);
303
327
 
304
328
        if (gnome_rr_config_get_clone (labeler->priv->config)) {
305
329
                /* Keep this string in sync with gnome-control-center/capplets/display/xrandr-capplet.c:get_display_name() */
322
346
         * theme's colors, since the label is always shown against a light
323
347
         * pastel background.  See bgo#556050
324
348
         */
325
 
        gtk_widget_modify_fg (widget, gtk_widget_get_state (widget), &black);
 
349
        gtk_widget_override_color (widget,
 
350
                                   gtk_widget_get_state_flags (widget),
 
351
                                   &black);
326
352
 
327
353
        gtk_container_add (GTK_CONTAINER (window), widget);
328
354
 
428
454
}
429
455
 
430
456
/**
431
 
 * gnome_rr_labeler_get_color_for_output:
 
457
 * gnome_rr_labeler_get_rgba_for_output:
432
458
 * Get the color used for the label on a given output (monitor).
433
459
 *
434
460
 * @labeler: A #GnomeRRLabeler
435
461
 * @output: Output device (i.e. monitor) to query
436
 
 * @color_out: (out): Color of selected monitor.
 
462
 * @rgba_out: (out): Color of selected monitor.
437
463
 */
438
464
void
439
 
gnome_rr_labeler_get_color_for_output (GnomeRRLabeler *labeler, GnomeRROutputInfo *output, GdkColor *color_out)
 
465
gnome_rr_labeler_get_rgba_for_output (GnomeRRLabeler *labeler, GnomeRROutputInfo *output, GdkRGBA *rgba_out)
440
466
{
441
467
        int i;
442
468
        GnomeRROutputInfo **outputs;
443
469
 
444
470
        g_return_if_fail (GNOME_IS_RR_LABELER (labeler));
445
471
        g_return_if_fail (GNOME_IS_RR_OUTPUT_INFO (output));
446
 
        g_return_if_fail (color_out != NULL);
 
472
        g_return_if_fail (rgba_out != NULL);
447
473
 
448
474
        outputs = gnome_rr_config_get_outputs (labeler->priv->config);
449
475
 
450
476
        for (i = 0; i < labeler->priv->num_outputs; i++)
451
477
                if (outputs[i] == output) {
452
 
                        *color_out = labeler->priv->palette[i];
 
478
                        *rgba_out = labeler->priv->palette[i];
453
479
                        return;
454
480
                }
455
481
 
456
482
        g_warning ("trying to get the color for unknown GnomeOutputInfo %p; returning magenta!", output);
457
483
 
458
 
        color_out->red   = 0xffff;
459
 
        color_out->green = 0;
460
 
        color_out->blue  = 0xffff;
 
484
        rgba_out->red   = 1.0;
 
485
        rgba_out->green = 0;
 
486
        rgba_out->blue  = 1.0;
 
487
        rgba_out->alpha  = 1.0;
461
488
}