fix meter bridge window size issues
authorRobin Gareus <robin@gareus.org>
Wed, 7 Jan 2015 21:07:23 +0000 (22:07 +0100)
committerRobin Gareus <robin@gareus.org>
Wed, 7 Jan 2015 22:46:22 +0000 (23:46 +0100)
* no more OSX liveloop (window size < min size)
* properly set min window size
* re-layout metric areas when label height changes
* remove ‘smart’ auto-resize (when tracks are added/removed)
  (it wasn’t smart enough to work on all WMs)

gtk2_ardour/meter_strip.cc
gtk2_ardour/meterbridge.cc

index ea54f007965d17cc0affcfe55a02757dd2d03ec5..bda1d07d8986298f75ba01fac2664e45d2ad14cf 100644 (file)
@@ -536,13 +536,40 @@ MeterStrip::on_size_allocate (Gtk::Allocation& a)
                // NB numbers are rotated 90deg. on the meterbridge
                tnh = 4 + std::max(2u, _session->track_number_decimals()) * 8; // TODO 8 = max_with_of_digit_0_to_9()
        }
+
+       int prev_height, ignored;
+       bool need_relayout = false;
+
+       namebx.get_size_request(ignored, prev_height);
        namebx.set_size_request(18, nh + tnh);
+
+       if (prev_height != nh + tnh) {
+               need_relayout = true;
+       }
+
+       namenumberbx.get_size_request(ignored, prev_height);
        namenumberbx.set_size_request(18, nh + tnh);
+
+       if (prev_height != nh + tnh) {
+               need_relayout = true;
+       }
+
        if (_route) {
-               name_label.set_size_request(18, nh + (_route->is_master() ? tnh : -1));
+               int nlh = nh + (_route->is_master() ? tnh : -1);
+               name_label.get_size_request(ignored, prev_height);
+               name_label.set_size_request(18, nlh);
                name_label.set_layout_ellisize_width ((nh - 4 + (_route->is_master() ? tnh : 0)) * PANGO_SCALE);
+               if (prev_height != nlh) {
+                       need_relayout = true;
+               }
        }
+
        VBox::on_size_allocate(a);
+
+       if (need_relayout) {
+               queue_resize();
+               MetricChanged(); // force re-layout, parent on_scroll(), queue_resize()
+       }
 }
 
 gint
index 8eee194a39baf7efb7bc49188eedf552b9c66b63..08604b062021964ff91f40c14f1d1254bf7eba19 100644 (file)
@@ -104,9 +104,12 @@ Meterbridge::Meterbridge ()
        Gdk::Geometry geom;
        geom.max_width = 1<<16;
        geom.max_height = max_height;
+       geom.min_width = 40;
+       geom.min_height = -1;
        geom.height_inc = 16;
        geom.width_inc = 1;
-       set_geometry_hints(*((Gtk::Window*) this), geom, Gdk::HINT_MAX_SIZE | Gdk::HINT_RESIZE_INC);
+       assert(max_height % 16 == 0);
+       set_geometry_hints(*((Gtk::Window*) this), geom, Gdk::HINT_MIN_SIZE | Gdk::HINT_MAX_SIZE | Gdk::HINT_RESIZE_INC);
 
        set_keep_above (true);
        set_border_width (0);
@@ -325,33 +328,18 @@ Meterbridge::on_size_request (Gtk::Requisition* r)
        Gtk::Requisition mr = meterarea.size_request();
 
        geom.max_width = mr.width + metrics_left.get_width() + metrics_right.get_width();
+       geom.max_width = std::max(50, geom.max_width);
        geom.max_height = max_height;
 
-#ifndef GTKOSX
-       /* on OSX this leads to a constant live-loop: show/hide scrollbar
-        * on Linux, the window is resized IFF the scrollbar was not visible
-        */
-       const Gtk::Scrollbar * hsc = scroller.get_hscrollbar();
-       Glib::RefPtr<Gdk::Screen> screen = get_screen ();
-       Gdk::Rectangle monitor_rect;
-       screen->get_monitor_geometry (0, monitor_rect);
-       const int scr_w = monitor_rect.get_width() - 44;
-
-       if (cur_max_width < geom.max_width
-                       && cur_max_width < scr_w
-                       && !(scroller.get_hscrollbar_visible() && hsc)) {
-               int h = r->height;
-               *r = Gtk::Requisition();
-               r->width = geom.max_width;
-               r->height = h;
-       }
-#endif
-
        if (cur_max_width != geom.max_width) {
                cur_max_width = geom.max_width;
+               /* height resizes are 'heavy' since the metric areas and meter-patterns
+                * are re-generated. limit to 16px steps. */
                geom.height_inc = 16;
                geom.width_inc = 1;
-               set_geometry_hints(*((Gtk::Window*) this), geom, Gdk::HINT_MAX_SIZE | Gdk::HINT_RESIZE_INC);
+               geom.min_width = 40;
+               geom.min_height = -1;
+               set_geometry_hints(*((Gtk::Window*) this), geom, Gdk::HINT_MIN_SIZE | Gdk::HINT_MAX_SIZE | Gdk::HINT_RESIZE_INC);
        }
 }
 
@@ -360,6 +348,7 @@ Meterbridge::on_size_allocate (Gtk::Allocation& a)
 {
        const Gtk::Scrollbar * hsc = scroller.get_hscrollbar();
 
+       /* switch left/right edge patterns depending on horizontal scroll-position */
        if (scroller.get_hscrollbar_visible() && hsc) {
                if (!scroll_connection.connected()) {
                        scroll_connection = scroller.get_hscrollbar()->get_adjustment()->signal_value_changed().connect(sigc::mem_fun (*this, &Meterbridge::on_scroll));