[gnome-control-center] display: identify primary display with a black top bar and clock



commit 3337e01c00ee67a790c80bac40c43e8d0201e939
Author: William Jon McCann <jmccann redhat com>
Date:   Sat Nov 20 19:37:16 2010 -0500

    display: identify primary display with a black top bar and clock

 panels/display/xrandr-capplet.c |   56 +++++++++++++++++++++++++++++++++++---
 1 files changed, 51 insertions(+), 5 deletions(-)
---
diff --git a/panels/display/xrandr-capplet.c b/panels/display/xrandr-capplet.c
index 013605d..1919aff 100644
--- a/panels/display/xrandr-capplet.c
+++ b/panels/display/xrandr-capplet.c
@@ -1695,8 +1695,8 @@ paint_output (App *app, cairo_t *cr, int i)
   get_geometry (output, &w, &h);
 
 #if 0
-  g_debug ("%s (%p) geometry %d %d %d", output->name, output,
-           w, h, output->rate);
+  g_debug ("%s (%p) geometry %d %d %d primary=%d", output->name, output->name,
+           w, h, output->rate, output->primary);
 #endif
 
   viewport.height -= 2 * MARGIN;
@@ -1729,7 +1729,6 @@ paint_output (App *app, cairo_t *cr, int i)
                    - x - (w * scale + 0.5) / 2,
                    - y - (h * scale + 0.5) / 2);
 
-
   if (output == app->current_output)
     {
       GtkStyle *style;
@@ -1800,10 +1799,57 @@ paint_output (App *app, cairo_t *cr, int i)
     cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
 
   pango_cairo_show_layout (cr, layout);
+  g_object_unref (layout);
 
-  cairo_restore (cr);
+  if (output->primary)
+    {
+      const char *clock_format;
+      char *text;
+      gboolean use_24;
+      GDateTime *dt;
+
+      /* top bar */
+      cairo_rectangle (cr, x, y, w * scale + 0.5, 20);
+      cairo_set_source_rgb (cr, 0, 0, 0);
+      cairo_fill (cr);
+
+      /* clock */
+      /* FIXME: set 12/24 hour */
+      if (use_24)
+        clock_format = _("%a %R");
+      else
+        clock_format = _("%a %l:%M %p");
 
-  g_object_unref (layout);
+      dt = g_date_time_new_now_local ();
+      text = g_date_time_format (dt, clock_format);
+      g_date_time_unref (dt);
+
+      layout = gtk_widget_create_pango_layout (GTK_WIDGET (app->area), text);
+      g_free (text);
+      pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+
+      layout_set_font (layout, "Sans 4");
+      pango_layout_get_pixel_extents (layout, &ink_extent, &log_extent);
+
+      if (available_w < ink_extent.width)
+        factor = available_w / ink_extent.width;
+      else
+        factor = 1.0;
+
+      cairo_move_to (cr,
+                     x + ((w * scale + 0.5) - factor * log_extent.width) / 2,
+                     y + (20 - factor * log_extent.height) / 2);
+
+      cairo_scale (cr, factor, factor);
+
+      cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+
+      pango_cairo_show_layout (cr, layout);
+      g_object_unref (layout);
+
+    }
+
+  cairo_restore (cr);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]