Beispiel #1
0
		internal void SetDisplay(IntPtr display_handle)
		{
			if (display_handle != IntPtr.Zero) {
				Hwnd	hwnd;

				if ((DisplayHandle != IntPtr.Zero) && (FosterParent != IntPtr.Zero)) {
					hwnd = Hwnd.ObjectFromHandle(FosterParent);
					XDestroyWindow(DisplayHandle, FosterParent);
					hwnd.Dispose();
				}

				if (DisplayHandle != IntPtr.Zero) {
					XCloseDisplay(DisplayHandle);
				}

				DisplayHandle=display_handle;

				// We need to tell System.Drawing our DisplayHandle. FromHdcInternal has
				// been hacked to do this for us.
				Graphics.FromHdcInternal (DisplayHandle);

				// query for the render extension so
				// we can ignore the spurious
				// BadPicture errors that are
				// generated by cairo/render.
				XQueryExtension (DisplayHandle, "RENDER",
						 ref render_major_opcode, ref render_first_event, ref render_first_error);

				// Debugging support
				if (Environment.GetEnvironmentVariable ("MONO_XSYNC") != null) {
					XSynchronize(DisplayHandle, true);
				}

				if (Environment.GetEnvironmentVariable ("MONO_XEXCEPTIONS") != null) {
					ErrorExceptions = true;
				}

				// Generic X11 setup
				ScreenNo = XDefaultScreen(DisplayHandle);
				RootWindow = XRootWindow(DisplayHandle, ScreenNo);
				DefaultColormap = XDefaultColormap(DisplayHandle, ScreenNo);

				// Create the foster parent
				// it is important that border_width is kept in synch with the other XCreateWindow calls
				FosterParent=XCreateSimpleWindow(DisplayHandle, RootWindow, 0, 0, 1, 1, 0, UIntPtr.Zero, UIntPtr.Zero);
				if (FosterParent==IntPtr.Zero) {
					Console.WriteLine("XplatUIX11 Constructor failed to create FosterParent");
				}

				DebugHelper.WriteLine ("FosterParent created 0x{0:x}", FosterParent.ToInt32());

				hwnd = new Hwnd();
				hwnd.Queue = ThreadQueue(Thread.CurrentThread);
				hwnd.WholeWindow = FosterParent;
				hwnd.ClientWindow = FosterParent;

				// Create a HWND for RootWIndow as well, so our queue doesn't eat the events
				hwnd = new Hwnd();
				hwnd.Queue = ThreadQueue(Thread.CurrentThread);
				hwnd.whole_window = RootWindow;
				hwnd.ClientWindow = RootWindow;

				// For sleeping on the X11 socket
				listen = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
				IPEndPoint ep = new IPEndPoint(IPAddress.Loopback, 0);
				listen.Bind(ep);
				listen.Listen(1);

				// To wake up when a timer is ready
				network_buffer = new byte[10];

				wake = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
				wake.Connect(listen.LocalEndPoint);

				// Make this non-blocking, so it doesn't
				// deadlock if too many wakes are sent
				// before the wake_receive end is polled
				wake.Blocking = false;

				wake_receive = listen.Accept();

				#if __MonoCS__
				pollfds = new Pollfd [2];
				pollfds [0] = new Pollfd ();
				pollfds [0].fd = XConnectionNumber (DisplayHandle);
				pollfds [0].events = PollEvents.POLLIN;

				pollfds [1] = new Pollfd ();
				pollfds [1].fd = wake_receive.Handle.ToInt32 ();
				pollfds [1].events = PollEvents.POLLIN;
				#endif

				Keyboard = new X11Keyboard(DisplayHandle, FosterParent);
				Dnd = new X11Dnd (DisplayHandle, Keyboard);

				DoubleClickInterval = 500;

				HoverState.Interval = 500;
				HoverState.Timer = new Timer();
				HoverState.Timer.Enabled = false;
				HoverState.Timer.Interval = HoverState.Interval;
				HoverState.Timer.Tick += new EventHandler(MouseHover);
				HoverState.Size = new Size(4, 4);
				HoverState.X = -1;
				HoverState.Y = -1;

				ActiveWindow = IntPtr.Zero;
				FocusWindow = IntPtr.Zero;
				ModalWindows = new Stack(3);

				MouseState = MouseButtons.None;
				mouse_position = new Point(0, 0);

				Caret.Timer = new Timer();
				Caret.Timer.Interval = 500;		// FIXME - where should this number come from?
				Caret.Timer.Tick += new EventHandler(CaretCallback);

				SetupAtoms();

				// Grab atom changes off the root window to catch certain WM events
				XSelectInput(DisplayHandle, RootWindow, new IntPtr ((int) (EventMask.PropertyChangeMask | Keyboard.KeyEventMask)));

				// Handle any upcoming errors
				ErrorHandler = new XErrorHandler(HandleError);
				XSetErrorHandler(ErrorHandler);
			} else {
				throw new ArgumentNullException("Display", "Could not open display (X-Server required. Check your DISPLAY environment variable)");
			}
		}
Beispiel #2
0
		public X11Display (IntPtr display)
		{
			if (display == IntPtr.Zero) {
				throw new ArgumentNullException("Display",
							"Could not open display (X-Server required. Check your DISPLAY environment variable)");
			}

			this.display = display;

			// Debugging support
			if (Environment.GetEnvironmentVariable ("MONO_XSYNC") != null) {
				Xlib.XSynchronize (display, true);
			}

			if (Environment.GetEnvironmentVariable ("MONO_XEXCEPTIONS") != null) {
				ErrorExceptions = true;
			}

			atoms = new X11Atoms (this);

			DoubleClickInterval = 500;

			HoverState.Interval = 500;
			HoverState.Timer = new Timer();
			HoverState.Timer.Enabled = false;
			HoverState.Timer.Interval = HoverState.Interval;
			HoverState.Timer.Tick += new EventHandler(MouseHover);
			HoverState.Size = new Size(4, 4);
			HoverState.X = -1;
			HoverState.Y = -1;

			ActiveWindow = null;
			FocusWindow = null;
			ModalWindows = new Stack(3);

			MouseState = MouseButtons.None;
			MousePosition = new Point(0, 0);

			Caret.Timer = new Timer();
			Caret.Timer.Interval = 500;		// FIXME - where should this number come from?
			Caret.Timer.Tick += new EventHandler(CaretCallback);

			// XXX multiscreen work here
			root_hwnd = new X11RootHwnd (this, Xlib.XRootWindow (display, DefaultScreen));

			// XXX do we need a per-screen foster parent?
			// Create the foster parent
			foster_hwnd = new X11Hwnd (this,
						   Xlib.XCreateSimpleWindow (display, root_hwnd.WholeWindow,
									     0, 0, 1, 1, 4, UIntPtr.Zero, UIntPtr.Zero));

			pollfds = new Pollfd [1];
			pollfds [0] = new Pollfd ();
			pollfds [0].fd = Xlib.XConnectionNumber (display);
			pollfds [0].events = PollEvents.POLLIN;

			Keyboard = new X11Keyboard(display, foster_hwnd.Handle);
			Dnd = new X11Dnd (display, Keyboard);

			ErrorExceptions = false;

			// Handle any upcoming errors
			ErrorHandler = new XErrorHandler (HandleError);
			Xlib.XSetErrorHandler (ErrorHandler);

			X11DesktopColors.Initialize(); // XXX we need to figure out how to make this display specific?

			// Disable keyboard autorepeat
			try {
				Xlib.XkbSetDetectableAutoRepeat (display, true, IntPtr.Zero);
				detectable_key_auto_repeat = true;
			} catch {
				Console.Error.WriteLine ("Could not disable keyboard auto repeat, will attempt to disable manually.");
				detectable_key_auto_repeat = false;
			}

			// we re-set our error handler here, X11DesktopColor stuff might have stolen it (gtk does)
			Xlib.XSetErrorHandler (ErrorHandler);

			// create our event thread (just sits on the X socket waiting for events)
			event_thread = new Thread (new ThreadStart (XEventThread));
			event_thread.IsBackground = true;
			event_thread.Start ();
		}
Beispiel #3
0
		//private X11Keyboard keyboard;

		public X11Dnd (IntPtr display, X11Keyboard keyboard)
		{
			this.display = display;
			//this.keyboard = keyboard;

			Init ();
		}
Beispiel #4
0
		// native X display handle
		internal void SetDisplay (IntPtr display_handle)
		{
			if (display_handle != IntPtr.Zero) {
				Hwnd	hwnd;
				
				if ((GdkDisplayHandle != IntPtr.Zero) && (GdkFosterParent != IntPtr.Zero)) {
					hwnd = Hwnd.ObjectFromHandle (gdk_x11_drawable_get_xid (GdkFosterParent));
					gdk_window_destroy (GdkFosterParent);
					hwnd.Dispose ();
				}
				
				if (GdkDisplayHandle != IntPtr.Zero) {
					gdk_display_close (GdkDisplayHandle);
				}
				
				DisplayHandle = display_handle;
				GdkDisplayHandle = gdk_x11_lookup_xdisplay (display_handle);
				
				// We need to tell System.Drawing our DisplayHandle. FromHdcInternal has
				// been hacked to do this for us.
				Graphics.FromHdcInternal (DisplayHandle);
				
				// Debugging support
				if (Environment.GetEnvironmentVariable ("MONO_XSYNC") != null) {
					XSynchronize (DisplayHandle, true);					
				}
				
				if (Environment.GetEnvironmentVariable ("MONO_XEXCEPTIONS") != null) {
					ErrorExceptions = true;
				}
				
				// Generic X11 setup
				GdkScreen = gdk_screen_get_default ();
				// or gdk_x11_get_default_screen
				ScreenNo = gdk_screen_get_number (GdkScreen);
				GdkRootWindow = gdk_get_default_root_window ();
				RootWindow = gdk_x11_drawable_get_xid (GdkRootWindow);
				GdkDefaultColormap = gdk_colormap_get_system ();
				DefaultColormap = gdk_x11_colormap_get_xcolormap (GdkDefaultColormap);
				
				VisualBestDepth = gdk_visual_get_best_depth ();
				//Console.WriteLine (VisualBestDepth);
				
				// Create the foster parent
				FosterParent = XCreateSimpleWindow (DisplayHandle, RootWindow, 0, 0, 1, 1, 4, 0, 0);
				GdkFosterParent = gdk_window_foreign_new (FosterParent);
				
				if (GdkFosterParent == IntPtr.Zero) {
					Console.WriteLine ("XplatUIX11GTK Constructor failed to create FosterParent");
				}
				
				hwnd = new Hwnd ();
				
				hwnd.WholeWindow = FosterParent;
				hwnd.ClientWindow = FosterParent;
				
				// For sleeping on the X11 socket
				listen = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
				IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 0);
				listen.Bind (ep);
				listen.Listen (1);
				
				// To wake up when a timer is ready
				network_buffer = new byte [10];
				
				wake = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
				wake.Connect (listen.LocalEndPoint);
				wake_receive = listen.Accept ();
				
				pollfds = new Pollfd [2];
				pollfds [0] = new Pollfd ();
				pollfds [0].fd = XConnectionNumber (DisplayHandle);
				pollfds [0].events = PollEvents.POLLIN;

				pollfds [1] = new Pollfd ();
				pollfds [1].fd = wake_receive.Handle.ToInt32 ();
				pollfds [1].events = PollEvents.POLLIN;
				
				Keyboard = new X11Keyboard (DisplayHandle);
				Dnd = new X11Dnd (DisplayHandle);
				
				PostQuitState = false;
				
				DoubleClickInterval = 500;
				
				HoverState.Interval = 500;
				HoverState.Timer = new Timer ();
				HoverState.Timer.Enabled = false;
				HoverState.Timer.Interval = HoverState.Interval;
				HoverState.Timer.Tick += new EventHandler (MouseHover);
				HoverState.X = -1;
				HoverState.Y = -1;
				
				ActiveWindow = IntPtr.Zero;
				FocusWindow = IntPtr.Zero;
				ModalWindows = new Stack (3);
				
				MouseState = MouseButtons.None;
				MousePosition = new Point (0, 0);
				
				Caret.Timer = new Timer ();
				Caret.Timer.Interval = 500;		// FIXME - where should this number come from?
				Caret.Timer.Tick += new EventHandler (CaretCallback);
				
				SetupAtoms ();
				
				// Grab atom changes off the root window to catch certain WM events
				gdk_window_set_events (GdkRootWindow, (int)GdkEventMask.GDK_PROPERTY_CHANGE_MASK);
				
				// Handle any upcoming errors
				ErrorHandler = new XErrorHandler (HandleError);
				XSetErrorHandler (ErrorHandler);
			} else {
				throw new ArgumentNullException ("Display", "Could not open display (X-Server required. Check your DISPLAY environment variable)");
			}
		}