[Xfce4-commits] <xfce4-terminal:master> Set a decent default grid size when starting the drop-down.

Nick Schermer noreply at xfce.org
Mon Dec 31 13:52:01 CET 2012


Updating branch refs/heads/master
         to 8a0b3dd92a1a8ca3fa5914e1210139300aded983 (commit)
       from 3e581d5d1db63f8a2ae1b23c820e60deb9a7e1ed (commit)

commit 8a0b3dd92a1a8ca3fa5914e1210139300aded983
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Dec 31 13:50:39 2012 +0100

    Set a decent default grid size when starting the drop-down.

 terminal/terminal-window-dropdown.c |   34 ++++++++++++++++++++++++++++++++++
 terminal/terminal-window-dropdown.h |    5 +++++
 terminal/terminal-window.c          |    7 +++++++
 3 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/terminal/terminal-window-dropdown.c b/terminal/terminal-window-dropdown.c
index 40947f2..4ec9663 100644
--- a/terminal/terminal-window-dropdown.c
+++ b/terminal/terminal-window-dropdown.c
@@ -913,3 +913,37 @@ terminal_window_dropdown_toggle (TerminalWindowDropdown *dropdown,
   if (startup_id != NULL)
     gdk_notify_startup_complete_with_id (startup_id);
 }
+
+
+
+void
+terminal_window_dropdown_get_size (TerminalWindowDropdown *dropdown,
+                                   TerminalScreen         *screen,
+                                   glong                  *grid_width,
+                                   glong                  *grid_height)
+{
+  GdkScreen      *gdkscreen;
+  gint            monitor_num;
+  GdkRectangle    monitor_geo;
+  gint            xpad, ypad;
+  glong           char_width, char_height;
+  GtkRequisition  req;
+
+  /* get the active monitor size */
+  gdkscreen = xfce_gdk_screen_get_active (&monitor_num);
+  gdk_screen_get_monitor_geometry (gdkscreen, monitor_num, &monitor_geo);
+
+  /* get terminal size */
+  terminal_screen_get_geometry (screen, &char_width, &char_height, &xpad, &ypad);
+
+  /* correct padding with visible widgets */
+  gtk_widget_size_request (TERMINAL_WINDOW (dropdown)->vbox, &req);
+  xpad += 2;
+  ypad += req.height;
+
+  /* return grid size */
+  if (G_LIKELY (grid_width != NULL))
+    *grid_width = ((monitor_geo.width * dropdown->rel_width) - xpad) / char_width;
+  if (G_LIKELY (grid_height != NULL))
+    *grid_height = ((monitor_geo.height * dropdown->rel_height) - ypad) / char_height;
+}
diff --git a/terminal/terminal-window-dropdown.h b/terminal/terminal-window-dropdown.h
index e5dca9c..82e1ab0 100644
--- a/terminal/terminal-window-dropdown.h
+++ b/terminal/terminal-window-dropdown.h
@@ -43,6 +43,11 @@ GtkWidget      *terminal_window_dropdown_new                  (const gchar
 void            terminal_window_dropdown_toggle               (TerminalWindowDropdown *dropdown,
                                                                const gchar            *startup_id);
 
+void            terminal_window_dropdown_get_size             (TerminalWindowDropdown *dropdown,
+                                                               TerminalScreen         *screen,
+                                                               glong                  *grid_width,
+                                                               glong                  *grid_height);
+
 G_END_DECLS
 
 #endif /* !__TERMINAL_WINDOW_DROPDOWN_H__ */
diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c
index d7b5105..aaf37cc 100644
--- a/terminal/terminal-window.c
+++ b/terminal/terminal-window.c
@@ -52,6 +52,7 @@
 #include <terminal/terminal-marshal.h>
 #include <terminal/terminal-encoding-action.h>
 #include <terminal/terminal-window.h>
+#include <terminal/terminal-window-dropdown.h>
 #include <terminal/terminal-window-ui.h>
 #include <terminal/terminal-widget.h>
 
@@ -883,6 +884,12 @@ terminal_window_notebook_page_added (GtkNotebook    *notebook,
       /* show the tabs when needed */
       terminal_window_notebook_show_tabs (window);
     }
+  else if (G_UNLIKELY (window->drop_down))
+    {
+      /* try to calculate a decent grid size based on the info we have now */
+      terminal_window_dropdown_get_size (TERMINAL_WINDOW_DROPDOWN (window), screen, &w, &h);
+      terminal_screen_set_size (screen, w, h);
+    }
   else
     {
       /* force a screen size, needed for misc-default-geometry */


More information about the Xfce4-commits mailing list