Exemple #1
0
 /// <summary>
 /// <para>Create a new cursor, based on a pre-defined cursor type.</para>
 /// </summary>
 ///
 /// <param name="type">
 /// <para>The pre-defined cursor type to use.</para>
 /// </param>
 public Cursor(CursorType type)
 {
     this.type   = type;
     this.source = null;
     this.mask   = null;
     this.cursor = XCursor.Zero;
 }
	/// <summary>
	/// <para>Create a new cursor, based on a pre-defined cursor type.</para>
	/// </summary>
	///
	/// <param name="type">
	/// <para>The pre-defined cursor type to use.</para>
	/// </param>
	public Cursor(CursorType type)
			{
				this.type = type;
				this.source = null;
				this.mask = null;
				this.cursor = XCursor.Zero;
			}
Exemple #3
0
        // Set this cursor on a widget.
        internal void SetCursor(Widget widget)
        {
            Display dpy = widget.dpy;

            try
            {
                IntPtr  display = dpy.Lock();
                XWindow window  = widget.GetWidgetHandle();
                if (source != null)
                {
                    if (cursor == XCursor.Zero)
                    {
                        XColor foreground = new XColor();
                        foreground.red   = (ushort)0;
                        foreground.green = (ushort)0;
                        foreground.blue  = (ushort)0;
                        foreground.flags =
                            (XColor.DoRed | XColor.DoGreen | XColor.DoBlue);
                        XColor background = new XColor();
                        background.red   = (ushort)0xFFFF;
                        background.green = (ushort)0xFFFF;
                        background.blue  = (ushort)0xFFFF;
                        background.flags =
                            (XColor.DoRed | XColor.DoGreen | XColor.DoBlue);
                        if (reverse)
                        {
                            cursor = Xlib.XCreatePixmapCursor
                                         (display,
                                         source.GetPixmapHandle(),
                                         mask.GetPixmapHandle(),
                                         ref background, ref foreground,
                                         (uint)hotspotX, (uint)hotspotY);
                        }
                        else
                        {
                            cursor = Xlib.XCreatePixmapCursor
                                         (display,
                                         source.GetPixmapHandle(),
                                         mask.GetPixmapHandle(),
                                         ref foreground, ref background,
                                         (uint)hotspotX, (uint)hotspotY);
                        }
                    }
                    Xlib.XDefineCursor(display, window, cursor);
                }
                else if (type == CursorType.XC_inherit_parent)
                {
                    Xlib.XUndefineCursor(display, window);
                }
                else
                {
                    Xlib.XDefineCursor
                        (display, window, dpy.GetCursor(type));
                }
            }
            finally
            {
                dpy.Unlock();
            }
        }
Exemple #4
0
        /// <summary>
        /// <para>Create a new cursor, based on a user-supplied image frame.</para>
        /// </summary>
        ///
        /// <param name="screen">
        /// <para>The screen to create the cursor for, or
        /// <see langword="null"/> for the default screen on the
        /// default display.</para>
        /// </param>
        ///
        /// <param name="frame">
        /// <para>The frame defining the cursor image.</para>
        /// </param>
        ///
        /// <exception cref="T:System.ArgumentNullException"/>
        /// <para>Raised if <paramref name="frame"/> is
        /// <see langword="null"/>.</para>
        /// </exception>
        public Cursor(Screen screen, Frame frame)
        {
            Display dpy;

            if (frame == null)
            {
                throw new ArgumentNullException("frame");
            }
            if (screen != null)
            {
                dpy = screen.DisplayOfScreen;
            }
            else
            {
                dpy    = Application.Primary.Display;
                screen = dpy.DefaultScreenOfDisplay;
            }
            if (                    /* irgnore pixel format! frame.PixelFormat != PixelFormat.Format1bppIndexed  || */
                frame.Mask == null)
            {
                // The frame is not suitable for use as a cursor.
                this.type   = CursorType.XC_left_ptr;
                this.source = null;
                this.mask   = null;
                this.cursor = XCursor.Zero;
            }
            else
            {
                this.type   = CursorType.XC_inherit_parent;
                this.cursor = XCursor.Zero;
                try
                {
                    dpy.Lock();
                    IntPtr pixmapXImage =
                        ConvertImage.FrameToXImageBitmap(screen, frame);
                    IntPtr maskXImage = ConvertImage.MaskToXImage
                                            (screen, frame);
                    source = ConvertImage.XImageMaskToBitmap
                                 (screen, pixmapXImage);
                    mask = ConvertImage.XImageMaskToBitmap
                               (screen, maskXImage);
                    Xlib.XSharpDestroyImage(pixmapXImage);
                    Xlib.XSharpDestroyImage(maskXImage);
                    hotspotX = frame.HotspotX;
                    hotspotY = frame.HotspotY;
                    if (frame.Palette != null && frame.Palette[0] == 0)
                    {
                        reverse = true;
                    }
                }
                finally
                {
                    dpy.Unlock();
                }
            }
        }
Exemple #5
0
 /// <summary>
 /// <para>Create a new cursor, based on a user-supplied image
 /// and mask.</para>
 /// </summary>
 ///
 /// <param name="source">
 /// <para>The bitmap defining the source image for the cursor.</para>
 /// </param>
 ///
 /// <param name="mask">
 /// <para>The bitmap defining the mask for the cursor.</para>
 /// </param>
 ///
 /// <param name="hotspotX">
 /// <para>The X position of the cursor hotspot.</para>
 /// </param>
 ///
 /// <param name="hotspotY">
 /// <para>The Y position of the cursor hotspot.</para>
 /// </param>
 ///
 /// <exception cref="T:System.ArgumentNullException"/>
 /// <para>Raised if <paramref name="source"/> or <paramref name="mask"/>
 /// is <see langword="null"/>.</para>
 /// </exception>
 public Cursor(Bitmap source, Bitmap mask, int hotspotX, int hotspotY)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (mask == null)
     {
         throw new ArgumentNullException("mask");
     }
     this.type   = CursorType.XC_inherit_parent;
     this.source = source;
     this.mask   = mask;
     this.cursor = XCursor.Zero;
 }
Exemple #6
0
        // Retrieve or create a standard cursor.  Call with the display lock.
        internal XCursor GetCursor(CursorType type)
        {
            uint shape = (uint)type;

            if (shape >= (uint)(CursorType.XC_num_glyphs))
            {
                shape = (uint)(CursorType.XC_X_cursor);
            }
            XCursor cursor = cursors[(int)shape];

            if (cursor != XCursor.Zero)
            {
                return(cursor);
            }
            cursor = cursors[(int)shape] =
                Xlib.XCreateFontCursor(dpy, shape);
            return(cursor);
        }
Exemple #7
0
        public Mini(string[] args)
        {
            if (args.Length > 0)
            {
                if (args[0].Equals("--version"))
                {
                    Console.WriteLine(VERSION_STRING);
                    Environment.Exit(0);
                }
            }

            XGCValues            gv;
            XSetWindowAttributes sattr;

            focused_client = null;
            focus_model    = DEFAULT_FOCUS_MODEL;

            //  for (int i = 0; i < argc; i++)
            //    command_line = command_line + argv[i] + " ";

            try {
                dpy = new XDisplay(":0");

                try {
                    font = new XFont(dpy, DEFAULT_FONT);
                } catch {
                    font = new XFont(dpy, "Fixed");
                }
            } catch (Exception e) {
                Console.WriteLine("{0} check your DISPLAY variable.", e.Message);
                Environment.Exit(-1);
            }

            XEvent ev = new XEvent(dpy);

            ev.ErrorHandlerEvent += new ErrorHandler(ErrorHandler);

            // SET UP ATOMS
            atom_wm_state        = new XAtom(dpy, "WM_STATE", false);
            atom_wm_change_state = new XAtom(dpy, "WM_CHANGE_STATE", false);
            atom_wm_protos       = new XAtom(dpy, "WM_PROTOCOLS", false);
            atom_wm_delete       = new XAtom(dpy, "WM_DELETE_WINDOW", false);
            atom_wm_takefocus    = new XAtom(dpy, "WM_TAKE_FOCUS", false);

            XSetWindowAttributes pattr = new XSetWindowAttributes();

            pattr.override_redirect = true;
            _button_proxy_win       = new XWindow(dpy, new Rectangle(-80, -80, 24, 24));
            _button_proxy_win.ChangeAttributes(XWindowAttributeFlags.CWOverrideRedirect, pattr);

            // SETUP COLORS USED FOR WINDOW TITLE BARS and WINDOW BORDERS
            fg               = new XColor(dpy, DEFAULT_FOREGROUND_COLOR);
            bg               = new XColor(dpy, DEFAULT_BACKGROUND_COLOR);
            bd               = new XColor(dpy, DEFAULT_BORDER_COLOR);
            fc               = new XColor(dpy, DEFAULT_FOCUS_COLOR);
            focused_border   = new XColor(dpy, FOCUSED_BORDER_COLOR);
            unfocused_border = new XColor(dpy, UNFOCUSED_BORDER_COLOR);

            //shape = XShapeQueryExtension(dpy, &shape_event, &dummy);

            move_curs  = new XCursor(dpy, XCursors.XC_fleur);
            arrow_curs = new XCursor(dpy, XCursors.XC_left_ptr);

            root.DefineCursor(arrow_curs);

            gv.function   = XGCFunctionMask.GXcopy;
            gv.foreground = fg.Pixel;
            gv.font       = font.FID;
            string_gc     = new XGC(dpy, root, XGCValuesMask.GCFunction | XGCValuesMask.GCForeground | XGCValuesMask.GCFont, gv);

            gv.foreground = unfocused_border.Pixel;
            unfocused_gc  = new XGC(dpy, root, XGCValuesMask.GCForeground | XGCValuesMask.GCFont, gv);

            gv.foreground    = fg.Pixel;
            focused_title_gc = new XGC(dpy, root, XGCValuesMask.GCForeground | XGCValuesMask.GCFont, gv);

            gv.foreground = bd.Pixel;
            gv.line_width = DEFAULT_BORDER_WIDTH;
            border_gc     = new XGC(dpy, root, XGCValuesMask.GCFunction | XGCValuesMask.GCForeground | XGCValuesMask.GCLineWidth, gv);

            gv.foreground     = fg.Pixel;
            gv.function       = XGCFunctionMask.GXinvert;
            gv.subwindow_mode = XSubwindowMode.IncludeInferiors;
            invert_gc         = new XGC(dpy, root, XGCValuesMask.GCForeground | XGCValuesMask.GCFunction | XGCValuesMask.GCSubwindowMode | XGCValuesMask.GCLineWidth | XGCValuesMask.GCFont, gv);

            sattr.event_mask = XEventMask.SubstructureRedirectMask | XEventMask.SubstructureNotifyMask | XEventMask.ButtonPressMask | XEventMask.ButtonReleaseMask | XEventMask.FocusChangeMask | XEventMask.EnterWindowMask | XEventMask.LeaveWindowMask | XEventMask.PropertyChangeMask | XEventMask.ButtonMotionMask;

            root.ChangeAttributes(XWindowAttributeFlags.CWEventMask, sattr);

            queryWindowTree();

            ev.KeyPressHandlerEvent         += new KeyPressHandler(handleKeyPressEvent);
            ev.ButtonPressHandlerEvent      += new ButtonPressHandler(handleButtonPressEvent);
            ev.ButtonReleaseHandlerEvent    += new ButtonReleaseHandler(handleButtonReleaseEvent);
            ev.ConfigureRequestHandlerEvent += new ConfigureRequestHandler(handleConfigureRequestEvent);
            ev.MotionNotifyHandlerEvent     += new MotionNotifyHandler(handleMotionNotifyEvent);
            ev.MapRequestHandlerEvent       += new MapRequestHandler(handleMapRequestEvent);
            ev.UnmapNotifyHandlerEvent      += new UnmapNotifyHandler(handleUnmapNotifyEvent);
            ev.DestroyNotifyHandlerEvent    += new DestroyNotifyHandler(handleDestroyNotifyEvent);
            ev.EnterNotifyHandlerEvent      += new EnterNotifyHandler(handleEnterNotifyEvent);
            ev.FocusInHandlerEvent          += new FocusInHandler(handleFocusInEvent);
            ev.FocusOutHandlerEvent         += new FocusOutHandler(handleFocusOutEvent);
            ev.PropertyNotifyHandlerEvent   += new PropertyNotifyHandler(handlePropertyNotifyEvent);
            ev.ExposeHandlerEvent           += new ExposeHandler(handleExposeEvent);
            ev.ShapeHandlerEvent            += new ShapeHandler(handleShapeEvent);
        }
	/// <summary>
	/// <para>Create a new cursor, based on a user-supplied image
	/// and mask.</para>
	/// </summary>
	///
	/// <param name="source">
	/// <para>The bitmap defining the source image for the cursor.</para>
	/// </param>
	///
	/// <param name="mask">
	/// <para>The bitmap defining the mask for the cursor.</para>
	/// </param>
	///
	/// <param name="hotspotX">
	/// <para>The X position of the cursor hotspot.</para>
	/// </param>
	///
	/// <param name="hotspotY">
	/// <para>The Y position of the cursor hotspot.</para>
	/// </param>
	///
	/// <exception cref="T:System.ArgumentNullException"/>
	/// <para>Raised if <paramref name="source"/> or <paramref name="mask"/>
	/// is <see langword="null"/>.</para>
	/// </exception>
	public Cursor(Bitmap source, Bitmap mask, int hotspotX, int hotspotY)
			{
				if(source == null)
				{
					throw new ArgumentNullException("source");
				}
				if(mask == null)
				{
					throw new ArgumentNullException("mask");
				}
				this.type = CursorType.XC_inherit_parent;
				this.source = source;
				this.mask = mask;
				this.cursor = XCursor.Zero;
			}
	// Set this cursor on a widget.
	internal void SetCursor(Widget widget)
			{
				Display dpy = widget.dpy;
				try
				{
					IntPtr display = dpy.Lock();
					XWindow window = widget.GetWidgetHandle();
					if(source != null)
					{
						if(cursor == XCursor.Zero)
						{
							XColor foreground = new XColor();
							foreground.red = (ushort)0;
							foreground.green = (ushort)0;
							foreground.blue = (ushort)0;
							foreground.flags =
								(XColor.DoRed | XColor.DoGreen | XColor.DoBlue);
							XColor background = new XColor();
							background.red = (ushort)0xFFFF;
							background.green = (ushort)0xFFFF;
							background.blue = (ushort)0xFFFF;
							background.flags =
								(XColor.DoRed | XColor.DoGreen | XColor.DoBlue);
							if(reverse)
							{
								cursor = Xlib.XCreatePixmapCursor
									(display,
									 source.GetPixmapHandle(),
									 mask.GetPixmapHandle(),
									 ref background, ref foreground,
									 (uint)hotspotX, (uint)hotspotY);
							}
							else
							{
								cursor = Xlib.XCreatePixmapCursor
									(display,
									 source.GetPixmapHandle(),
									 mask.GetPixmapHandle(),
									 ref foreground, ref background,
									 (uint)hotspotX, (uint)hotspotY);
							}
						}
						Xlib.XDefineCursor(display, window, cursor);
					}
					else if(type == CursorType.XC_inherit_parent)
					{
						Xlib.XUndefineCursor(display, window);
					}
					else
					{
						Xlib.XDefineCursor
							(display, window, dpy.GetCursor(type));
					}
				}
				finally
				{
					dpy.Unlock();
				}
			}
	/// <summary>
	/// <para>Create a new cursor, based on a user-supplied image frame.</para>
	/// </summary>
	///
	/// <param name="screen">
	/// <para>The screen to create the cursor for, or
	/// <see langword="null"/> for the default screen on the
	/// default display.</para>
	/// </param>
	///
	/// <param name="frame">
	/// <para>The frame defining the cursor image.</para>
	/// </param>
	///
	/// <exception cref="T:System.ArgumentNullException"/>
	/// <para>Raised if <paramref name="frame"/> is
	/// <see langword="null"/>.</para>
	/// </exception>
	public Cursor(Screen screen, Frame frame)
			{
				Display dpy;
				if(frame == null)
				{
					throw new ArgumentNullException("frame");
				}
				if(screen != null)
				{
					dpy = screen.DisplayOfScreen;
				}
				else
				{
					dpy = Application.Primary.Display;
					screen = dpy.DefaultScreenOfDisplay;
				}
				if( /* irgnore pixel format! frame.PixelFormat != PixelFormat.Format1bppIndexed  || */
				   frame.Mask == null)
				{
					// The frame is not suitable for use as a cursor.
					this.type = CursorType.XC_left_ptr;
					this.source = null;
					this.mask = null;
					this.cursor = XCursor.Zero;
				}
				else
				{
					this.type = CursorType.XC_inherit_parent;
					this.cursor = XCursor.Zero;
					try
					{
						dpy.Lock();
						IntPtr pixmapXImage =
							ConvertImage.FrameToXImageBitmap(screen, frame);
						IntPtr maskXImage = ConvertImage.MaskToXImage
							(screen, frame);
						source = ConvertImage.XImageMaskToBitmap
							(screen, pixmapXImage);
						mask = ConvertImage.XImageMaskToBitmap
							(screen, maskXImage);
						Xlib.XSharpDestroyImage(pixmapXImage);
						Xlib.XSharpDestroyImage(maskXImage);
						hotspotX = frame.HotspotX;
						hotspotY = frame.HotspotY;
						if(frame.Palette != null && frame.Palette[0] == 0)
						{
							reverse = true;
						}
					}
					finally
					{
						dpy.Unlock();
					}
				}
			}
Exemple #11
0
	extern public static int XGrabButton
			(IntPtr display, uint button, uint modifiers,
			 XWindow grab_window, XBool owner_events,
			 uint event_mask, int pointer_mode, int keyboard_mode,
			 XWindow confine_to, XCursor cursor);
Exemple #12
0
	extern public static int XGrabPointer
			(IntPtr display, XWindow grab_window, XBool owner_events,
			 uint event_mask, int pointer_mode, int keyboard_mode,
			 XWindow confine_to, XCursor cursor, XTime time);
Exemple #13
0
	extern public static int XDefineCursor
			(IntPtr display, XWindow w, XCursor cursor);