public void SetData (X11Dnd dnd, object data, ref XEvent xevent) { string [] uri_list = data as string []; if (uri_list == null) { IDataObject dobj = data as IDataObject; if (dobj == null) return; uri_list = dobj.GetData (DataFormats.FileDrop, true) as string []; } if (uri_list == null) return; StringBuilder res = new StringBuilder (); foreach (string uri_str in uri_list) { Uri uri = new Uri (uri_str); res.Append (uri.ToString ()); res.Append ("\r\n"); } IntPtr buffer = Marshal.StringToHGlobalAnsi ((string) res.ToString ()); int len = 0; while (Marshal.ReadByte (buffer, len) != 0) len++; dnd.SetProperty (ref xevent, buffer, len); }
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)"); } }
public void SetData (X11Dnd dnd, object data, ref XEvent xevent) { IntPtr buffer; int len; string str = data as string; if (str == null) { IDataObject dobj = data as IDataObject; if (dobj == null) return; str = (string) dobj.GetData ("System.String", true); } if (xevent.SelectionRequestEvent.target == (IntPtr)Atom.XA_STRING) { byte [] bytes = Encoding.ASCII.GetBytes (str); buffer = Marshal.AllocHGlobal (bytes.Length); len = bytes.Length; for (int i = 0; i < len; i++) Marshal.WriteByte (buffer, i, bytes [i]); } else { buffer = Marshal.StringToHGlobalAnsi (str); len = 0; while (Marshal.ReadByte (buffer, len) != 0) len++; } dnd.SetProperty (ref xevent, buffer, len); Marshal.FreeHGlobal (buffer); }
public void GetData (X11Dnd dnd, IDataObject data, ref XEvent xevent) { string text = dnd.GetText (ref xevent, false); if (text == null) return; // TODO: Do this in a loop instead of just splitting ArrayList uri_list = new ArrayList (); string [] lines = text.Split (new char [] { '\r', '\n' }); foreach (string line in lines) { // # is a comment line (see RFC 2483) if (line.StartsWith ("#")) continue; try { Uri uri = new Uri (line); uri_list.Add (uri.LocalPath); } catch { } } string [] l = (string []) uri_list.ToArray (typeof (string)); if (l.Length < 1) return; data.SetData (DataFormats.FileDrop, l); data.SetData ("FileName", l [0]); data.SetData ("FileNameW", l [0]); }
public void GetData (X11Dnd dnd, IDataObject data, ref XEvent xevent) { string text = dnd.GetText (ref xevent, true); if (text == null) return; data.SetData (DataFormats.Text, text); data.SetData (DataFormats.UnicodeText, text); }
public void SetData (X11Dnd dnd, object data, ref XEvent xevent) { if (data == null) return; MemoryStream stream = new MemoryStream (); BinaryFormatter bf = new BinaryFormatter (); bf.Serialize (stream, data); IntPtr buffer = Marshal.AllocHGlobal ((int) stream.Length); stream.Seek (0, 0); for (int i = 0; i < stream.Length; i++) { Marshal.WriteByte (buffer, i, (byte) stream.ReadByte ()); } dnd.SetProperty (ref xevent, buffer, (int) stream.Length); }
public void GetData (X11Dnd dnd, IDataObject data, ref XEvent xevent) { MemoryStream stream = dnd.GetData (ref xevent); BinaryFormatter bf = new BinaryFormatter (); if (stream.Length == 0) return; stream.Seek (0, 0); object obj = bf.Deserialize (stream); data.SetData (obj); }
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 (); }
// 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)"); } }