public X11Window(AvaloniaX11Platform platform, bool popup) { _platform = platform; _popup = popup; _x11 = platform.Info; _mouse = platform.MouseDevice; _keyboard = platform.KeyboardDevice; var glfeature = AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>(); XSetWindowAttributes attr = new XSetWindowAttributes(); var valueMask = default(SetWindowValuemask); attr.backing_store = 1; attr.bit_gravity = Gravity.NorthWestGravity; attr.win_gravity = Gravity.NorthWestGravity; valueMask |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity; if (popup) { attr.override_redirect = true; valueMask |= SetWindowValuemask.OverrideRedirect; } XVisualInfo?visualInfo = null; // OpenGL seems to be do weird things to it's current window which breaks resize sometimes _useRenderWindow = glfeature != null; var glx = glfeature as GlxGlPlatformFeature; if (glx != null) { visualInfo = *glx.Display.VisualInfo; } else if (glfeature == null) { visualInfo = _x11.TransparentVisualInfo; } var egl = glfeature as EglGlPlatformFeature; var visual = IntPtr.Zero; var depth = 24; if (visualInfo != null) { visual = visualInfo.Value.visual; depth = (int)visualInfo.Value.depth; attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0); valueMask |= SetWindowValuemask.ColorMap; } _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, 300, 200, 0, depth, (int)CreateWindowArgs.InputOutput, visual, new UIntPtr((uint)valueMask), ref attr); if (_useRenderWindow) { _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, 300, 200, 0, depth, (int)CreateWindowArgs.InputOutput, visual, new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr); } else { _renderHandle = _handle; } Handle = new PlatformHandle(_handle, "XID"); _realSize = new PixelSize(300, 200); platform.Windows[_handle] = OnEvent; XEventMask ignoredMask = XEventMask.SubstructureRedirectMask | XEventMask.ResizeRedirectMask | XEventMask.PointerMotionHintMask; if (platform.XI2 != null) { ignoredMask |= platform.XI2.AddWindow(_handle, this); } var mask = new IntPtr(0xffffff ^ (int)ignoredMask); XSelectInput(_x11.Display, _handle, mask); var protocols = new[] { _x11.Atoms.WM_DELETE_WINDOW }; XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length); XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM, 32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1); if (platform.Options.WmClass != null) { SetWmClass(platform.Options.WmClass); } var surfaces = new List <object> { new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle, depth, () => Scaling) }; if (egl != null) { surfaces.Insert(0, new EglGlPlatformSurface((EglDisplay)egl.Display, egl.DeferredContext, new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle))); } if (glx != null) { surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext, new SurfaceInfo(this, _x11.Display, _handle, _renderHandle))); } Surfaces = surfaces.ToArray(); UpdateMotifHints(); _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing, XNames.XNClientWindow, _handle, IntPtr.Zero); XFlush(_x11.Display); }
public static extern int XGrabPointer(IntPtr display, uint window, bool owner_events, XEventMask event_mask, int pointer_mode, int keyboard_mode, IntPtr confine_to, IntPtr cursor, int time);
private static extern int XSelectInput(IntPtr display, IntPtr w, XEventMask mask);
public WindowResizeTest() { t = new Timer(); dpy = new XDisplay(IntPtr.Zero); s = new XScreen(dpy); ev = new XEvent(dpy); pointer = new XPointer(dpy); gc = new XGC(dpy); //XShape shape = new XShape(dpy); //shape.Query(); //Console.WriteLine("Shape Event Type Number = {0}", shape.Type.ToString()); //atom = new XAtom (dpy, "_MAJYK_HINT", false); // Used to test the XPM function that reads a pixmap from a char** // pix_data = new string[] { // "16 16 16 1", // " c None", // ". c #323232", // "+ c #535353", // "@ c #4A8A8E", // "# c #DEE2E2", // "$ c #7E827A", // "% c #8A9292", // "& c #D6D6D6", // "* c #36767E", // "= c #9E9E9E", // "- c #FAFAFA", // "; c #B2B2B2", // "> c #DEEEEA", // ", c #464646", // "' c #5EA2A2", // ") c #52969A", // " ", // " ", // " --#>>>>>>#-#-; ", // " -&%')))))=&=&+ ", // " >;$@*****=;%;+ ", // " &$$$$$$$$$$$$, ", // " &;;;;;;;;;;;;+ ", // " &;;;;;;;;;;;;+ ", // " #;;;;;;;;;;;;+ ", // " &;;;;;;;;;;;;+ ", // " #;;;;;;;;;;;;+ ", // " #;;;;;;;;;;;;+ ", // " &;;;;;;;;;;;;+ ", // " $............. ", // " ", // " " // }; bg_color = new XColor(dpy, "#AAAAAA"); handle_color = new XColor(dpy, "#FF0000"); //bg_color = new XColor(dpy, Color.FromArgb(200, 200, 200)); //handle_color = new XColor(dpy, Color.FromArgb(0, 255, 0)); main_win = new XWindow(dpy, new Rectangle(5, 5, 640, 480), 0, s.BlackPixel(), s.WhitePixel()); main_win.Name = "Window Resize Test"; main_win.SelectInput(XEventMask.KeyPressMask | XEventMask.ExposureMask); resize_main_win = new XWindow(dpy, main_win, new Rectangle(resize_win_x, resize_win_y, resize_win_width, resize_win_height), 1, s.BlackPixel(), bg_color.Pixel); resize_top_left_win = new XWindow(dpy, resize_main_win, new Rectangle(0, 0, resize_handle_width, resize_handle_height), 1, s.BlackPixel(), handle_color.Pixel); resize_top_right_win = new XWindow(dpy, resize_main_win, new Rectangle(0, 0, resize_handle_width, resize_handle_height), 1, s.BlackPixel(), handle_color.Pixel); resize_bottom_left_win = new XWindow(dpy, resize_main_win, new Rectangle(0, 0, resize_handle_width, resize_handle_height), 1, s.BlackPixel(), handle_color.Pixel); resize_bottom_right_win = new XWindow(dpy, resize_main_win, new Rectangle(0, 0, resize_handle_width, resize_handle_height), 1, s.BlackPixel(), handle_color.Pixel); //string foo="MAJYK!"; //resize_main_win.ChangeProperty(atom, atom, 8, PropMode.PropModeReplace, Marshal.StringToHGlobalAnsi(foo), foo.Length); //int return_type=0; //int actual_format=0; //int nitems=0; //int bytes_return=0; //IntPtr data = IntPtr.Zero; //resize_main_win.GetProperty(atom, 0, 2, false, atom, out return_type, out actual_format, out nitems, out bytes_return, out data); //string z = Marshal.PtrToStringAnsi(data); //Console.WriteLine("nitems = {0}, z = {1}", nitems, z); //pix = new XPixmap (dpy); //if (pix.ReadPixmapFromData (resize_main_win, pix_data)) { // resize_main_win.SetBackgroundPixmap (pix); // Console.WriteLine ("pixmap w = {0} | h = {1}", pix.Width.ToString (), pix.Height.ToString ()); //} resize_main_win.SetBackgroundColor(Color.Gray); // Test TransientFor //resize_main_win.SetTransientForHint(main_win); //Window foo = resize_main_win.GetTransientForHint(); //Console.WriteLine("resize_main_win = {0} | foo.transient_for = {1} | main_win = {2}", resize_main_win.ID.ToString(), foo.ID.ToString(), main_win.ID.ToString()); XEventMask mask = XEventMask.ButtonPressMask | XEventMask.ButtonReleaseMask; resize_main_win.SelectInput(mask); resize_top_left_win.SelectInput(mask); resize_top_right_win.SelectInput(mask); resize_bottom_left_win.SelectInput(mask); resize_bottom_right_win.SelectInput(mask); PlaceHandles(); resize_main_win.MapSubwindows(); main_win.MapSubwindows(); main_win.Map(); ev.KeyPressHandlerEvent += new KeyPressHandler(HandleKeyPress); ev.MotionNotifyHandlerEvent += new MotionNotifyHandler(HandleMotionNotify); ev.ButtonPressHandlerEvent += new ButtonPressHandler(HandleButtonPress); ev.ButtonReleaseHandlerEvent += new ButtonReleaseHandler(HandleButtonRelease); ev.ExposeHandlerEvent += new ExposeHandler(HandleExpose); t.Interval = 1000; t.Enabled = true; t.Elapsed += new ElapsedEventHandler(UpdateClock); t.Start(); ev.Loop(); }
private static extern int XGrabButton(IntPtr display, int button, XModMask modifiers, IntPtr grab_window, bool owner_events, XEventMask event_mask, XGrabMode pointer_mode, XGrabMode keyboard_mode, int confine_to, IntPtr cursor);
private static extern int XGrabPointer(IntPtr display, IntPtr grab_window, bool owner_events, XEventMask event_mask, XGrabMode pointer_mode, XGrabMode keyboard_mode, int confine_to, int cursor, int time);
public int GrabPointer(XEventMask event_mask) { return XGrabPointer (display.Handle, Handle, true, event_mask, XGrabMode.GrabModeAsync, XGrabMode.GrabModeAsync, 0, 0, 0); }
public static extern Status XSendEvent(DisplayPtr display, Window w, Bool propagate, XEventMask event_mask, ref XEvent event_send);
public int GrabButton(int button, XModMask modifiers, IntPtr grab_window, bool owner_events, XEventMask event_mask, XGrabMode pointer_mode, XGrabMode keyboard_mode, int confine_to, IntPtr cursor) { return XGrabButton (display.Handle, button, modifiers, grab_window, owner_events, event_mask, pointer_mode, keyboard_mode, confine_to, cursor); }
public int GrabButton(int button, XModMask modifiers, XEventMask event_mask) { return XGrabButton (display.Handle, button, modifiers, Handle, true, event_mask, XGrabMode.GrabModeAsync, XGrabMode.GrabModeAsync, 0, IntPtr.Zero); }
public int Grab(IntPtr w, XEventMask event_mask) { return XGrabPointer (display.Handle, w, true, event_mask, XGrabMode.GrabModeAsync, XGrabMode.GrabModeAsync, 0, IntPtr.Zero, 0); }
private static extern int XSendEvent(IntPtr display, IntPtr w, bool propagate, XEventMask event_mask, IntPtr event_send);
// public int SendEvent (XWindow w, bool propagate, XEventMask event_mask) // { // return XSendEvent (display.Handle, w.Handle, propagate, event_mask, Handle); // } public int SendClientMessage(XWindow w, XAtom a, bool propagate, XEventMask event_mask) { //XEvent e; //e.type = XEventType.ClientMessage; //e.xclient.window = w; //e.xclient.message_type = a; //e.xclient.format = 32; //e.xclient.data.l[0] = x; //e.xclient.data.l[1] = CurrentTime; //FIXME: SendClientMessage //XClientMessageEvent cm = new XClientMessageEvent (); //cm.window = w.Handle; //cm.message_type = a; //cm.format = 32; //cm.data = new XClientMessageEvent.data (); //return XSendEvent (dpy, w, False, mask, &e); return 0; }
public static extern void XSelectInput(IntPtr display, uint window, XEventMask event_mask);
public int SelectInput(XEventMask mask) { return XSelectInput (display.Handle, Handle, mask); }
public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent) { _platform = platform; _popup = popupParent != null; _x11 = platform.Info; _mouse = new MouseDevice(); _touch = new TouchDevice(); _keyboard = platform.KeyboardDevice; var glfeature = AvaloniaLocator.Current.GetService <IPlatformOpenGlInterface>(); XSetWindowAttributes attr = new XSetWindowAttributes(); var valueMask = default(SetWindowValuemask); attr.backing_store = 1; attr.bit_gravity = Gravity.NorthWestGravity; attr.win_gravity = Gravity.NorthWestGravity; valueMask |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity; if (_popup) { attr.override_redirect = true; valueMask |= SetWindowValuemask.OverrideRedirect; } XVisualInfo?visualInfo = null; // OpenGL seems to be do weird things to it's current window which breaks resize sometimes _useRenderWindow = glfeature != null; var glx = glfeature as GlxPlatformOpenGlInterface; if (glx != null) { visualInfo = *glx.Display.VisualInfo; } else if (glfeature == null) { visualInfo = _x11.TransparentVisualInfo; } var egl = glfeature as EglPlatformOpenGlInterface; var visual = IntPtr.Zero; var depth = 24; if (visualInfo != null) { visual = visualInfo.Value.visual; depth = (int)visualInfo.Value.depth; attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0); valueMask |= SetWindowValuemask.ColorMap; } int defaultWidth = 0, defaultHeight = 0; if (!_popup && Screen != null) { var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity) .FirstOrDefault(m => m.Bounds.Contains(Position)); if (monitor != null) { // Emulate Window 7+'s default window size behavior. defaultWidth = (int)(monitor.WorkingArea.Width * 0.75d); defaultHeight = (int)(monitor.WorkingArea.Height * 0.7d); } } // check if the calculated size is zero then compensate to hardcoded resolution defaultWidth = Math.Max(defaultWidth, 300); defaultHeight = Math.Max(defaultHeight, 200); _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, defaultWidth, defaultHeight, 0, depth, (int)CreateWindowArgs.InputOutput, visual, new UIntPtr((uint)valueMask), ref attr); if (_useRenderWindow) { _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, defaultWidth, defaultHeight, 0, depth, (int)CreateWindowArgs.InputOutput, visual, new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr); } else { _renderHandle = _handle; } Handle = new PlatformHandle(_handle, "XID"); _realSize = new PixelSize(defaultWidth, defaultHeight); platform.Windows[_handle] = OnEvent; XEventMask ignoredMask = XEventMask.SubstructureRedirectMask | XEventMask.ResizeRedirectMask | XEventMask.PointerMotionHintMask; if (platform.XI2 != null) { ignoredMask |= platform.XI2.AddWindow(_handle, this); } var mask = new IntPtr(0xffffff ^ (int)ignoredMask); XSelectInput(_x11.Display, _handle, mask); var protocols = new[] { _x11.Atoms.WM_DELETE_WINDOW }; XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length); XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM, 32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1); if (platform.Options.WmClass != null) { SetWmClass(platform.Options.WmClass); } var surfaces = new List <object> { new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle, depth, () => RenderScaling) }; if (egl != null) { surfaces.Insert(0, new EglGlPlatformSurface(egl, new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle))); } if (glx != null) { surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext, new SurfaceInfo(this, _x11.Display, _handle, _renderHandle))); } Surfaces = surfaces.ToArray(); UpdateMotifHints(); UpdateSizeHints(null); _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing, XNames.XNClientWindow, _handle, IntPtr.Zero); _transparencyHelper = new TransparencyHelper(_x11, _handle, platform.Globals); _transparencyHelper.SetTransparencyRequest(WindowTransparencyLevel.None); XFlush(_x11.Display); if (_popup) { PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(popupParent, MoveResize)); } if (platform.Options.UseDBusMenu) { NativeMenuExporter = DBusMenuExporter.TryCreate(_handle); } NativeControlHost = new X11NativeControlHost(_platform, this); DispatcherTimer.Run(() => { Paint?.Invoke(default);
public X11Window(AvaloniaX11Platform platform, bool popup) { _platform = platform; _popup = popup; _x11 = platform.Info; _mouse = platform.MouseDevice; _keyboard = platform.KeyboardDevice; _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing, XNames.XNClientWindow, _handle, IntPtr.Zero); XSetWindowAttributes attr = new XSetWindowAttributes(); var valueMask = default(SetWindowValuemask); attr.backing_store = 1; attr.bit_gravity = Gravity.NorthWestGravity; attr.win_gravity = Gravity.NorthWestGravity; valueMask |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity; if (popup) { attr.override_redirect = true; valueMask |= SetWindowValuemask.OverrideRedirect; } _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, 300, 200, 0, 24, (int)CreateWindowArgs.InputOutput, IntPtr.Zero, new UIntPtr((uint)valueMask), ref attr); _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, 300, 200, 0, 24, (int)CreateWindowArgs.InputOutput, IntPtr.Zero, new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr); Handle = new PlatformHandle(_handle, "XID"); _realSize = new PixelSize(300, 200); platform.Windows[_handle] = OnEvent; XEventMask ignoredMask = XEventMask.SubstructureRedirectMask | XEventMask.ResizeRedirectMask | XEventMask.PointerMotionHintMask; if (platform.XI2 != null) { ignoredMask |= platform.XI2.AddWindow(_handle, this); } var mask = new IntPtr(0xffffff ^ (int)ignoredMask); XSelectInput(_x11.Display, _handle, mask); var protocols = new[] { _x11.Atoms.WM_DELETE_WINDOW }; XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length); XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM, 32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1); var feature = (EglGlPlatformFeature)AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>(); var surfaces = new List <object> { new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle, () => Scaling) }; if (feature != null) { surfaces.Insert(0, new EglGlPlatformSurface((EglDisplay)feature.Display, feature.DeferredContext, new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle))); } Surfaces = surfaces.ToArray(); UpdateMotifHints(); XFlush(_x11.Display); }