Exemple #1
0
        // ###############################################################################
        // ### M E T H O D S
        // ###############################################################################

        #region Methods

        /// <summary> Load the icon from indicated path and set it as shell icon. </summary>
        /// <returns> <c>true</c>, if icon was set, <c>false</c> otherwise. </returns>
        /// <param name='iconPath'> The icon path. </param>
        public bool SetShellIcon(string iconPath)
        {
            bool result = false;

            if (_shell == IntPtr.Zero)
            {
                Console.WriteLine(CLASS_NAME + "::SetShellIcon() ERROR: Member attribute '_shell' null.");
                return(result);
            }
            if (string.IsNullOrEmpty(iconPath))
            {
                Console.WriteLine(CLASS_NAME + "::SetShellIcon() ERROR: Paramerter 'iconPath' null or empty.");
                return(result);
            }

            IntPtr display      = Xtlib.XtDisplay(_shell);
            IntPtr window       = Xtlib.XtWindow(_shell);
            TInt   screenNumber = Xtlib.XDefaultScreen(display);

            using (X11Graphic appIcon = new X11Graphic(display, (int)screenNumber, IntPtr.Zero, X11lib.XDefaultDepth(display, screenNumber), iconPath))
            {
                _appIconPixMap = appIcon.CreateIndependentGraphicPixmap(display, window);
                _appMaskPixMap = appIcon.CreateIndependentMaskPixmap(display, window);
                if (_appIconPixMap != IntPtr.Zero && _appMaskPixMap != IntPtr.Zero)
                {
                    X11lib.XWMHints wmHints = new X11lib.XWMHints();
                    IntPtr          wmAddr  = X11lib.XAllocWMHints(ref wmHints);

                    wmHints.flags = X11lib.XWMHintMask.IconPixmapHint |
                                    X11lib.XWMHintMask.IconPositionHint |
                                    X11lib.XWMHintMask.IconMaskHint;
                    wmHints.icon_pixmap = _appIconPixMap;
                    wmHints.icon_mask   = _appMaskPixMap;
                    wmHints.icon_x      = 0;
                    wmHints.icon_y      = 0;

                    X11lib.XSetWMHints(display, window, ref wmHints);
                    X11lib.XFree(wmAddr);

                    result = true;
                }
                else
                {
                    Console.WriteLine(CLASS_NAME + "::SetShellIcon () ERROR: Can not create application icon.");
                }
            }

            return(result);
        }