[Xfce4-commits] <xfce4-weather-plugin:master> Adapt forecast window to monitor height.

Harald Judt noreply at xfce.org
Fri Jul 13 16:50:20 CEST 2012


Updating branch refs/heads/master
         to b5d407d72cc470723035a9f66baa0a368ae917cf (commit)
       from 8687ba61669a1e347dc26b3bbc34b46c5e6e8283 (commit)

commit b5d407d72cc470723035a9f66baa0a368ae917cf
Author: Harald Judt <h.judt at gmx.at>
Date:   Thu Jul 12 01:51:32 2012 +0200

    Adapt forecast window to monitor height.
    
    This should make both users of small and big screens happy.
    Successfully tested with resolutions from 640x480 to 1920x1080,
    bigger resolutions will very likely cause less trouble.
    
    While it is a bit of a compromise and there's certainly room
    for improvement (anyone wants to volunteer?), it works fine in
    most cases.

 panel-plugin/weather-summary.c |   51 +++++++++++++++++++++++++++++++--------
 1 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index c2a1029..aacd638 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -527,17 +527,46 @@ make_forecast (xfceweather_data *data)
 
 
 static GtkWidget *
-create_forecast_tab (xfceweather_data *data)
+create_forecast_tab (xfceweather_data *data, GtkWidget *window)
 {
-  GtkWidget *align;
-  guint      i;
-
-  align = gtk_alignment_new(0.5, 0, 0.5, 0);
-  gtk_container_set_border_width (GTK_CONTAINER (align), 6);
-  if (data->weatherdata)
-    gtk_container_add(GTK_CONTAINER(align),
-                      GTK_WIDGET(make_forecast (data)));
-  return align;
+    GtkWidget   *align, *hbox, *scrolled, *table;
+    GdkWindow   *win;
+    GdkScreen   *screen;
+    GdkRectangle rect;
+    gint         monitor_num, height_needed, height_max;
+
+    /* calculate maximum height we may use, subtracting some sane value for safety */
+    screen = gtk_window_get_screen(GTK_WINDOW(window));
+    win = GTK_WIDGET(window)->window;
+    monitor_num = gdk_screen_get_monitor_at_window(GDK_SCREEN(screen), GDK_WINDOW(win));
+    gdk_screen_get_monitor_geometry(GDK_SCREEN(screen), monitor_num, &rect);
+    height_max = rect.height * 0.85 - 200;
+
+    /* calculate height needed using a good arbitrary value */
+    height_needed = data->forecast_days * 110;
+
+    /* generate the forecast table */
+    table = GTK_WIDGET(make_forecast(data));
+
+    align = gtk_alignment_new(0.5, 0, 0.5, 0);
+    if (height_needed < height_max) {
+        gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(table));
+        gtk_container_set_border_width(GTK_CONTAINER(align), BORDER);
+        return align;
+    } else {
+        hbox = gtk_hbox_new(FALSE, 0);
+        gtk_box_pack_start(GTK_BOX(hbox), table, TRUE, FALSE, 0);
+        gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(hbox));
+
+        scrolled = gtk_scrolled_window_new (NULL, NULL);
+        gtk_container_set_border_width(GTK_CONTAINER(scrolled), BORDER);
+
+        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), align);
+        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
+                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+        gtk_widget_set_size_request(GTK_WIDGET(scrolled), 550, height_max);
+        return scrolled;
+    }
 }
 
 static void
@@ -605,7 +634,7 @@ create_summary_window (xfceweather_data *data)
     notebook = gtk_notebook_new ();
     gtk_container_set_border_width (GTK_CONTAINER (notebook), BORDER);
     gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
-                              create_forecast_tab (data),
+                              create_forecast_tab (data, window),
                               gtk_label_new (_("Forecast")));
     gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
                               create_summary_tab (data),


More information about the Xfce4-commits mailing list