Set a proper icon for the vncviewer windows on Unix and Windows.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4878 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 708b258..5db85c1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -250,7 +250,6 @@
 # Check for FLTK
 set(FLTK_SKIP_FLUID TRUE)
 set(FLTK_SKIP_OPENGL TRUE)
-set(FLTK_SKIP_IMAGES TRUE)
 set(FLTK_SKIP_FORMS TRUE)
 find_package(FLTK)
 
@@ -292,6 +291,9 @@
   # FLTK STR #2660
   check_cxx_source_compiles("#include <FL/Fl_Window.H>\nint main(int c, char** v) { void (Fl_Window::*foo)(const Fl_RGB_Image*,int,int) = &Fl_Window::cursor; return 0; }" HAVE_FLTK_CURSOR)
 
+  # FLTK STR #2816
+  check_cxx_source_compiles("#include <FL/Fl_Window.H>\nint main(int c, char** v) { Fl_Window::default_icons(0, 0); return 0; }" HAVE_FLTK_ICONS)
+
   set(CMAKE_REQUIRED_INCLUDES)
   set(CMAKE_REQUIRED_LIBRARIES)
 endif()
@@ -300,7 +302,7 @@
   "Force the use of the FLTK library bundled with the TigerVNC source")
 if(NOT FLTK_FOUND OR NOT HAVE_FLTK_DEAD_KEYS OR NOT HAVE_FLTK_CLIPBOARD
   OR NOT HAVE_FLTK_MEDIAKEYS OR NOT HAVE_FLTK_FULLSCREEN
-  OR NOT HAVE_FLTK_CURSOR)
+  OR NOT HAVE_FLTK_CURSOR OR NOT HAVE_FLTK_ICONS)
   set(USE_INCLUDED_FLTK 1)
 endif()
 if(USE_INCLUDED_FLTK)
@@ -325,6 +327,7 @@
   set(HAVE_FLTK_MEDIAKEYS 1)
   set(HAVE_FLTK_FULLSCREEN 1)
   set(HAVE_FLTK_CURSOR 1)
+  set(HAVE_FLTK_ICONS 1)
   set(FLTK_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/common/fltk)
   set(FLTK_LIBRARIES)
   if(APPLE)
diff --git a/config.h.in b/config.h.in
index 612fab7..68063c8 100644
--- a/config.h.in
+++ b/config.h.in
@@ -16,11 +16,14 @@
 #cmakedefine HAVE_FLTK_MEDIAKEYS
 #cmakedefine HAVE_FLTK_FULLSCREEN
 #cmakedefine HAVE_FLTK_CURSOR
+#cmakedefine HAVE_FLTK_ICONS
 #cmakedefine HAVE_ACTIVE_DESKTOP_H
 #cmakedefine HAVE_ACTIVE_DESKTOP_L
 #cmakedefine ENABLE_NLS 1
 #cmakedefine HAVE_PAM
 
+#cmakedefine DATA_DIR "@DATA_DIR@"
+
 /* MS Visual Studio 2008 and newer doesn't know ssize_t */
 #if defined(HAVE_GNUTLS) && defined(WIN32) && !defined(__MINGW32__)
 #include <stddef.h>
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index 5fe7fe0..1f6fca5 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -48,6 +48,7 @@
 
 #include <FL/Fl.H>
 #include <FL/Fl_Widget.H>
+#include <FL/Fl_PNG_Image.H>
 #include <FL/fl_ask.H>
 #include <FL/x.H>
 
@@ -58,6 +59,7 @@
 #include "UserDialog.h"
 
 #ifdef WIN32
+#include "resource.h"
 #include "win32.h"
 #endif
 
@@ -121,6 +123,69 @@
   // WM_CLASS for the window.
   Fl_Window::default_xclass("vncviewer");
 
+  // Set the default icon for all windows.
+#ifdef HAVE_FLTK_ICONS
+#ifdef WIN32
+  HICON lg, sm;
+
+  lg = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON),
+                        IMAGE_ICON, GetSystemMetrics(SM_CXICON),
+                        GetSystemMetrics(SM_CYICON),
+                        LR_DEFAULTCOLOR | LR_SHARED);
+  sm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON),
+                        IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
+                        GetSystemMetrics(SM_CYSMICON),
+                        LR_DEFAULTCOLOR | LR_SHARED);
+
+  Fl_Window::default_icons(lg, sm);
+#elif ! defined(__APPLE__)
+  const int icon_sizes[] = {48, 32, 24, 16};
+
+  Fl_PNG_Image *icons[4];
+  int count;
+
+  count = 0;
+
+  // FIXME: Follow icon theme specification
+  for (size_t i = 0;i < sizeof(icon_sizes)/sizeof(icon_sizes[0]);i++) {
+      char icon_path[PATH_MAX];
+      bool exists;
+
+      sprintf(icon_path, "%s/icons/hicolor/%dx%d/tigervnc.png",
+              DATA_DIR, icon_sizes[i], icon_sizes[i]);
+
+#ifndef WIN32
+      struct stat st;
+      if (stat(icon_path, &st) != 0)
+#else
+      struct _stat st;
+      if (_stat(icon_path, &st) != 0)
+          return(false);
+#endif
+        exists = false;
+      else
+        exists = true;
+
+      if (exists) {
+          icons[count] = new Fl_PNG_Image(icon_path);
+          if (icons[count]->w() == 0 ||
+              icons[count]->h() == 0 ||
+              icons[count]->d() != 4) {
+              delete icons[count];
+              continue;
+          }
+
+          count++;
+      }
+  }
+
+  Fl_Window::default_icons((const Fl_RGB_Image**)icons, count);
+
+  for (int i = 0;i < count;i++)
+      delete icons[i];
+#endif
+#endif // FLTK_HAVE_ICONS
+
   // This makes the "icon" in dialogs rounded, which fits better
   // with the above schemes.
   fl_message_icon()->box(FL_UP_BOX);