Update task bar icon when GUI theme changes (#1986).
authorCarl Hetherington <cth@carlh.net>
Sat, 22 May 2021 20:30:49 +0000 (22:30 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 28 Jun 2021 18:44:47 +0000 (20:44 +0200)
We have to keep the StatusDialog around the whole time as it seems
to be the only thing we have that can receive wxEVT_SYS_COLOUR_CHANGED.

src/tools/dcpomatic_server.cc

index 80d4046a494a9283c7952258e0d08b2494608bfa..401fb1077d047c83921f329d1570f8413f6fe3ae 100644 (file)
@@ -211,20 +211,16 @@ private:
        std::shared_ptr<wxTimer> _timer;
 };
 
+
+static StatusDialog* status_dialog = nullptr;
+
+
 class TaskBarIcon : public wxTaskBarIcon
 {
 public:
        TaskBarIcon ()
        {
-#ifdef DCPOMATIC_WINDOWS
-               wxIcon icon (std_to_wx ("id"));
-#else
-               wxBitmap bitmap (bitmap_path("dcpomatic_small_black"), wxBITMAP_TYPE_PNG);
-               wxIcon icon;
-               icon.CopyFromBitmap (bitmap);
-#endif
-
-               SetIcon (icon, std_to_wx ("DCP-o-matic Encode Server"));
+               set_icon ();
 
                Bind (wxEVT_MENU, boost::bind (&TaskBarIcon::status, this), ID_status);
                Bind (wxEVT_MENU, boost::bind (&TaskBarIcon::quit, this), ID_quit);
@@ -238,21 +234,33 @@ public:
                return menu;
        }
 
+       void set_icon ()
+       {
+#ifdef DCPOMATIC_WINDOWS
+               wxIcon icon (std_to_wx("id"));
+#else
+               string const colour = gui_is_dark() ? "white" : "black";
+               wxBitmap bitmap (
+                       bitmap_path(String::compose("dcpomatic_small_%1", colour)),
+                       wxBITMAP_TYPE_PNG
+                       );
+               wxIcon icon;
+               icon.CopyFromBitmap (bitmap);
+#endif
+
+               SetIcon (icon, std_to_wx ("DCP-o-matic Encode Server"));
+       }
+
 private:
        void status ()
        {
-               if (!_status) {
-                       _status = new StatusDialog ();
-               }
-               _status->Show ();
+               status_dialog->Show ();
        }
 
        void quit ()
        {
                wxTheApp->ExitMainLoop ();
        }
-
-       StatusDialog* _status;
 };
 
 
@@ -297,11 +305,12 @@ private:
                */
                Config::instance();
 
+               status_dialog = new StatusDialog ();
 #ifdef DCPOMATIC_LINUX
-               StatusDialog* d = new StatusDialog ();
-               d->Show ();
+               status_dialog->Show ();
 #else
                _icon = new TaskBarIcon;
+               status_dialog->Bind (wxEVT_SYS_COLOUR_CHANGED, boost::bind(&TaskBarIcon::set_icon, _icon));
 #endif
                _thread = thread (bind (&App::main_thread, this));