add the concept of a "state mask" that determines what info a WindowProxy will save
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 27 Apr 2016 04:01:13 +0000 (00:01 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 27 Apr 2016 04:03:14 +0000 (00:03 -0400)
libs/gtkmm2ext/gtkmm2ext/window_proxy.h
libs/gtkmm2ext/window_proxy.cc

index c5949701d9369100a3bbc85f71f3ce4fee3c8622..3bb941bccf88e59be24d388c44b5a566a23b73d2 100644 (file)
@@ -69,6 +69,14 @@ class LIBGTKMM2EXT_API WindowProxy : public PBD::StatefulDestructible, public vi
        virtual int set_state (const XMLNode&, int version);
        virtual XMLNode& get_state ();
 
+       enum StateMask {
+               Position = 0x1,
+               Size = 0x2
+       };
+
+       void set_state_mask (StateMask);
+       StateMask state_mask () const { return _state_mask; }
+
        operator bool() const { return _window != 0; }
 
        static std::string xml_node_name();
@@ -84,6 +92,7 @@ class LIBGTKMM2EXT_API WindowProxy : public PBD::StatefulDestructible, public vi
        mutable int  _width; ///< width
        mutable int  _height; ///< height
        Gtkmm2ext::VisibilityTracker* vistracker;
+       StateMask _state_mask;
 
        void save_pos_and_size ();
        void set_pos_and_size ();
index 6ad6a4d86bab08d23f2c278de3eb9d87f55a61af..d859c730c0f7f49d024b79969dcd0d486c67a00b 100644 (file)
@@ -42,6 +42,7 @@ WindowProxy::WindowProxy (const std::string& name)
        , _width (-1)
        , _height (-1)
        , vistracker (0)
+       , _state_mask (StateMask (Position|Size))
 {
 }
 
@@ -55,6 +56,7 @@ WindowProxy::WindowProxy (const std::string& name, const std::string& menu_name)
        , _width (-1)
        , _height (-1)
        , vistracker (0)
+       , _state_mask (StateMask (Position|Size))
 {
 }
 
@@ -189,14 +191,32 @@ WindowProxy::get_state ()
                _window->get_size (_width, _height);
        }
 
+       int x, y, w, h;
+
+       if (_state_mask & Position) {
+               x = _x_off;
+               y = _y_off;
+       } else {
+               x = -1;
+               y = -1;
+       }
+
+       if (_state_mask & Size) {
+               w = _width;
+               h = _height;
+       } else {
+               w = -1;
+               h = -1;
+       }
+
        node->add_property (X_("visible"), _visible? X_("yes") : X_("no"));
-       snprintf (buf, sizeof (buf), "%d", _x_off);
+       snprintf (buf, sizeof (buf), "%d", x);
        node->add_property (X_("x-off"), buf);
-       snprintf (buf, sizeof (buf), "%d", _y_off);
+       snprintf (buf, sizeof (buf), "%d", y);
        node->add_property (X_("y-off"), buf);
-       snprintf (buf, sizeof (buf), "%d", _width);
+       snprintf (buf, sizeof (buf), "%d", w);
        node->add_property (X_("x-size"), buf);
-       snprintf (buf, sizeof (buf), "%d", _height);
+       snprintf (buf, sizeof (buf), "%d", h);
        node->add_property (X_("y-size"), buf);
 
        return *node;
@@ -327,16 +347,16 @@ WindowProxy::set_pos_and_size ()
                return;
        }
 
-       if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
+       if ((_state_mask & Position) && (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1)) {
                /* cancel any mouse-based positioning */
                _window->set_position (Gtk::WIN_POS_NONE);
        }
 
-       if (_width != -1 && _height != -1) {
+       if ((_state_mask & Size) && _width != -1 && _height != -1) {
                _window->resize (_width, _height);
        }
 
-       if (_x_off != -1 && _y_off != -1) {
+       if ((_state_mask & Position) && _x_off != -1 && _y_off != -1) {
                _window->move (_x_off, _y_off);
        }
 }
@@ -348,6 +368,10 @@ WindowProxy::set_pos ()
                return;
        }
 
+       if (!(_state_mask & Position)) {
+               return;
+       }
+
        if (_width != -1 || _height != -1 || _x_off != -1 || _y_off != -1) {
                /* cancel any mouse-based positioning */
                _window->set_position (Gtk::WIN_POS_NONE);
@@ -357,3 +381,9 @@ WindowProxy::set_pos ()
                _window->move (_x_off, _y_off);
        }
 }
+
+void
+WindowProxy::set_state_mask (StateMask sm)
+{
+       _state_mask = sm;
+}