From 8eb3508b7365aefddf98671b1a962366d480b237 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 27 Mar 2012 12:50:54 +0000 Subject: [PATCH] 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 --- CMakeLists.txt | 7 +++-- config.h.in | 3 ++ vncviewer/vncviewer.cxx | 65 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 708b2582..5db85c10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,7 +250,6 @@ endif() # 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 @@ if(FLTK_FOUND) # FLTK STR #2660 check_cxx_source_compiles("#include \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 \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 @@ option(USE_INCLUDED_FLTK "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 @@ if(USE_INCLUDED_FLTK) 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 612fab7f..68063c86 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 diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 5fe7fe08..1f6fca56 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -48,6 +48,7 @@ #include #include +#include #include #include @@ -58,6 +59,7 @@ #include "UserDialog.h" #ifdef WIN32 +#include "resource.h" #include "win32.h" #endif @@ -121,6 +123,69 @@ static void init_fltk() // 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); -- 2.39.5