Exemplo n.º 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);
        }
        /// <summary> Set the shell icon for a WM shell. </summary>
        /// <param name="application"> The WM shell to set the icon for. <see cref="XrwWmShell"/> </param>
        /// <param name="iconPath"> The path (relative, if applicable) to the icon to set. <see cref="System.String"/> </param>
        /// <returns> Returns true on success, or false otherwise. <see cref="System.Boolean"/> </returns>
        public static bool SetWmShellIcon(XrwWmShell application, string iconPath)
        {
            bool result = false;

            if (application == null)
            {
                Console.WriteLine(CLASS_NAME + "::SetWmShellIcon() ERROR: Paramerter 'application' null.");
                return(result);
            }
            if (string.IsNullOrEmpty(iconPath))
            {
                Console.WriteLine(CLASS_NAME + "::SetWmShellIcon() ERROR: Paramerter 'iconPath' null or empty.");
                return(result);
            }

            using (X11Graphic appIcon = new X11Graphic(application.Display, application.Screen, iconPath))
            {
                IntPtr appGraphicPixMap = appIcon.CreateIndependentGraphicPixmap(application.Display, application.Window);
                IntPtr appMaskPixMap    = appIcon.CreateIndependentMaskPixmap(application.Display, application.Window);
                if (appGraphicPixMap != IntPtr.Zero && appMaskPixMap != IntPtr.Zero)
                {
                    X11lib.XWMHints wmHints = X11lib.XAllocWMHints();
                    wmHints.flags       = X11lib.XWMHintMask.IconPixmapHint | X11lib.XWMHintMask.IconPositionHint | X11lib.XWMHintMask.IconMaskHint;
                    wmHints.icon_pixmap = appGraphicPixMap;
                    wmHints.icon_mask   = appMaskPixMap;
                    wmHints.icon_x      = 0;
                    wmHints.icon_y      = 0;
                    X11lib.XSetWMHints(application.Display, application.Window, ref wmHints);

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

            return(result);
        }