public static void XMaskEvent(IntPtr display, EventMask event_mask, ref XEvent e);
void SendExitEvent() { // Send a ClientMessage event to unblock XIfEvent // and exit the input event loop. using (new XLock(API.DefaultDisplay)) { XEvent ev = new XEvent(); ev.type = XEventName.ClientMessage; ev.ClientMessageEvent.display = window.Display; ev.ClientMessageEvent.window = window.Handle; ev.ClientMessageEvent.format = 32; ev.ClientMessageEvent.ptr1 = ExitAtom; Functions.XSendEvent(API.DefaultDisplay, window.Handle, false, 0, ref ev); Functions.XFlush(API.DefaultDisplay); } }
public extern static void XPeekEvent(IntPtr display, ref XEvent xevent);
public static void SendNetWMMessage(X11WindowInfo window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2) { XEvent xev; xev = new XEvent(); xev.ClientMessageEvent.type = XEventName.ClientMessage; xev.ClientMessageEvent.send_event = true; xev.ClientMessageEvent.window = window.WindowHandle; xev.ClientMessageEvent.message_type = message_type; xev.ClientMessageEvent.format = 32; xev.ClientMessageEvent.ptr1 = l0; xev.ClientMessageEvent.ptr2 = l1; xev.ClientMessageEvent.ptr3 = l2; XSendEvent(window.Display, window.RootWindow, false, new IntPtr((int)(EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask)), ref xev); }
public extern static Bool XCheckTypedWindowEvent(Display display, Window w, XEventName event_type, ref XEvent event_return);
public extern static Bool XCheckIfEvent(Display display, ref XEvent e, IntPtr predicate, IntPtr arg );
public extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, IntPtr event_mask, ref XEvent send_event);
public static bool XCheckIfEvent(IntPtr display, ref XEvent e, IntPtr predicate, IntPtr arg);
void ProcessEvents() { while (true) { XEvent e = new XEvent(); XGenericEventCookie cookie; using (new XLock(window.Display)) { if (!Functions.XCheckIfEvent(window.Display, ref e, Predicate, new IntPtr(XIOpCode))) { return; } cookie = e.GenericEventCookie; if (Functions.XGetEventData(window.Display, ref cookie) != 0) { XIRawEvent raw = (XIRawEvent) Marshal.PtrToStructure(cookie.data, typeof(XIRawEvent)); if (!rawids.ContainsKey(raw.deviceid)) { mice.Add(new MouseState()); rawids.Add(raw.deviceid, mice.Count - 1); } MouseState state = mice[rawids[raw.deviceid]]; switch (raw.evtype) { case XIEventType.RawMotion: double x = 0, y = 0; if (IsBitSet(raw.valuators.mask, 0)) { x = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(raw.raw_values, 0)); } if (IsBitSet(raw.valuators.mask, 1)) { y = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(raw.raw_values, 8)); } if (!CheckMouseWarp(x, y)) { state.X += (int)x; state.Y += (int)y; } break; case XIEventType.RawButtonPress: switch (raw.detail) { case 1: state.EnableBit((int)MouseButton.Left); break; case 2: state.EnableBit((int)MouseButton.Middle); break; case 3: state.EnableBit((int)MouseButton.Right); break; case 4: state.WheelPrecise++; break; case 5: state.WheelPrecise--; break; case 6: state.EnableBit((int)MouseButton.Button1); break; case 7: state.EnableBit((int)MouseButton.Button2); break; case 8: state.EnableBit((int)MouseButton.Button3); break; case 9: state.EnableBit((int)MouseButton.Button4); break; case 10: state.EnableBit((int)MouseButton.Button5); break; case 11: state.EnableBit((int)MouseButton.Button6); break; case 12: state.EnableBit((int)MouseButton.Button7); break; case 13: state.EnableBit((int)MouseButton.Button8); break; case 14: state.EnableBit((int)MouseButton.Button9); break; } break; case XIEventType.RawButtonRelease: switch (raw.detail) { case 1: state.DisableBit((int)MouseButton.Left); break; case 2: state.DisableBit((int)MouseButton.Middle); break; case 3: state.DisableBit((int)MouseButton.Right); break; case 6: state.DisableBit((int)MouseButton.Button1); break; case 7: state.DisableBit((int)MouseButton.Button2); break; case 8: state.DisableBit((int)MouseButton.Button3); break; case 9: state.DisableBit((int)MouseButton.Button4); break; case 10: state.DisableBit((int)MouseButton.Button5); break; case 11: state.DisableBit((int)MouseButton.Button6); break; case 12: state.DisableBit((int)MouseButton.Button7); break; case 13: state.DisableBit((int)MouseButton.Button8); break; case 14: state.DisableBit((int)MouseButton.Button9); break; } break; } mice[rawids[raw.deviceid]] = state; } Functions.XFreeEventData(window.Display, ref cookie); } } }
public static bool XCheckTypedWindowEvent(IntPtr display, IntPtr w, XEventName event_type, ref XEvent event_return);
public static bool XCheckTypedEvent(IntPtr display, XEventName event_type, out XEvent event_return);
public static bool XCheckWindowEvent(IntPtr display, IntPtr w, EventMask event_mask, ref XEvent event_return);
public static int XRRUpdateConfiguration(ref XEvent @event);
public static void XPutBackEvent(IntPtr display, ref XEvent @event);
public void Exit() { XEvent ev = new XEvent(); ev.type = XEventName.ClientMessage; ev.ClientMessageEvent.format = 32; ev.ClientMessageEvent.display = window.Display; ev.ClientMessageEvent.window = window.WindowHandle; ev.ClientMessageEvent.ptr1 = _atom_wm_destroy; Functions.XSendEvent(window.Display, window.WindowHandle, false, EventMask.NoEventMask, ref ev); Functions.XFlush(window.Display); }
internal void ProcessEvent(ref XEvent e) { switch (e.type) { case XEventName.KeyPress: case XEventName.KeyRelease: bool flag = e.type == XEventName.KeyPress; IntPtr num1 = API.LookupKeysym(ref e.KeyEvent, 0); IntPtr num2 = API.LookupKeysym(ref e.KeyEvent, 1); if (this.keymap.ContainsKey((XKey)(int)num1)) { this.keyboard[this.keymap[(XKey)(int)num1]] = flag; break; } else { if (!this.keymap.ContainsKey((XKey)(int)num2)) { break; } this.keyboard[this.keymap[(XKey)(int)num2]] = flag; break; } case XEventName.ButtonPress: if (e.ButtonEvent.button == 1) { this.mouse[MouseButton.Left] = true; break; } else if (e.ButtonEvent.button == 2) { this.mouse[MouseButton.Middle] = true; break; } else if (e.ButtonEvent.button == 3) { this.mouse[MouseButton.Right] = true; break; } else if (e.ButtonEvent.button == 4) { ++this.mouse.Wheel; break; } else if (e.ButtonEvent.button == 5) { --this.mouse.Wheel; break; } else if (e.ButtonEvent.button == 6) { this.mouse[MouseButton.Button1] = true; break; } else if (e.ButtonEvent.button == 7) { this.mouse[MouseButton.Button2] = true; break; } else if (e.ButtonEvent.button == 8) { this.mouse[MouseButton.Button3] = true; break; } else if (e.ButtonEvent.button == 9) { this.mouse[MouseButton.Button4] = true; break; } else if (e.ButtonEvent.button == 10) { this.mouse[MouseButton.Button5] = true; break; } else if (e.ButtonEvent.button == 11) { this.mouse[MouseButton.Button6] = true; break; } else if (e.ButtonEvent.button == 12) { this.mouse[MouseButton.Button7] = true; break; } else if (e.ButtonEvent.button == 13) { this.mouse[MouseButton.Button8] = true; break; } else { if (e.ButtonEvent.button != 14) { break; } this.mouse[MouseButton.Button9] = true; break; } case XEventName.ButtonRelease: if (e.ButtonEvent.button == 1) { this.mouse[MouseButton.Left] = false; break; } else if (e.ButtonEvent.button == 2) { this.mouse[MouseButton.Middle] = false; break; } else if (e.ButtonEvent.button == 3) { this.mouse[MouseButton.Right] = false; break; } else if (e.ButtonEvent.button == 6) { this.mouse[MouseButton.Button1] = false; break; } else if (e.ButtonEvent.button == 7) { this.mouse[MouseButton.Button2] = false; break; } else if (e.ButtonEvent.button == 8) { this.mouse[MouseButton.Button3] = false; break; } else if (e.ButtonEvent.button == 9) { this.mouse[MouseButton.Button4] = false; break; } else if (e.ButtonEvent.button == 10) { this.mouse[MouseButton.Button5] = false; break; } else if (e.ButtonEvent.button == 11) { this.mouse[MouseButton.Button6] = false; break; } else if (e.ButtonEvent.button == 12) { this.mouse[MouseButton.Button7] = false; break; } else if (e.ButtonEvent.button == 13) { this.mouse[MouseButton.Button8] = false; break; } else { if (e.ButtonEvent.button != 14) { break; } this.mouse[MouseButton.Button9] = false; break; } case XEventName.MotionNotify: this.mouse.Position = new Point(e.MotionEvent.x, e.MotionEvent.y); break; } }
private void InternalPoll() { X11.XEvent e = new XEvent(); try { while (!disposed) { Functions.XMaskEvent(window.Display, EventMask.PointerMotionMask | EventMask.PointerMotionHintMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.KeyPressMask | EventMask.KeyReleaseMask | EventMask.StructureNotifyMask, ref e); if (disposed) return; switch (e.type) { case XEventName.KeyPress: case XEventName.KeyRelease: keyboardDriver.ProcessKeyboardEvent(ref e.KeyEvent); break; case XEventName.ButtonPress: case XEventName.ButtonRelease: mouseDriver.ProcessButton(ref e.ButtonEvent); break; case XEventName.MotionNotify: mouseDriver.ProcessMotion(ref e.MotionEvent); break; case XEventName.DestroyNotify: Functions.XPutBackEvent(window.Display, ref e); Functions.XAutoRepeatOn(window.Display); return; } } } catch (ThreadAbortException expt) { Functions.XUnmapWindow(window.Display, window.Handle); Functions.XDestroyWindow(window.Display, window.Handle); return; } }
public override unsafe void ProcessEvents() { // Process all pending events while (Exists) { if (!GetPendingEvent()) { break; } // Respond to the event e switch (e.type) { case XEventName.MapNotify: case XEventName.UnmapNotify: { bool previous_visible = visible; visible = e.type == XEventName.MapNotify; if (visible != previous_visible) { RaiseVisibleChanged(); } } break; case XEventName.ClientMessage: if (!isExiting && e.ClientMessageEvent.ptr1 == wm_destroy) { Debug.Print("Exit message received."); RaiseClosing(); isExiting = true; DestroyWindow(); RaiseClosed(); } break; case XEventName.DestroyNotify: Debug.Print("Window destroyed"); Exists = false; break; case XEventName.ConfigureNotify: RefreshWindowBounds(ref e); break; case XEventName.Expose: if (e.ExposeEvent.count == 0) { RaiseRedraw(); } break; case XEventName.KeyPress: ToggleKey(ref e.KeyEvent, true); int status = API.XLookupString(ref e.KeyEvent, ascii, ascii.Length, null, IntPtr.Zero); Encoding.Default.GetChars(ascii, 0, status, chars, 0); for (int i = 0; i < status; i++) { // ignore NULL char after non-ASCII input char, like ä or å on Finnish keyboard layout if (chars[i] == '\0') { continue; } RaiseKeyPress(chars[i]); } break; case XEventName.KeyRelease: // Todo: raise KeyPress event. Use code from // http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/X11Keyboard.cs?view=markup ToggleKey(ref e.KeyEvent, false); break; case XEventName.ButtonPress: if (e.ButtonEvent.button == 1) { Mouse.Set(MouseButton.Left, true); } else if (e.ButtonEvent.button == 2) { Mouse.Set(MouseButton.Middle, true); } else if (e.ButtonEvent.button == 3) { Mouse.Set(MouseButton.Right, true); } else if (e.ButtonEvent.button == 4) { Mouse.SetWheel(Mouse.Wheel + 1); } else if (e.ButtonEvent.button == 5) { Mouse.SetWheel(Mouse.Wheel - 1); } else if (e.ButtonEvent.button == 6) { Keyboard.Set(Key.XButton1, true); } else if (e.ButtonEvent.button == 7) { Keyboard.Set(Key.XButton2, true); } break; case XEventName.ButtonRelease: if (e.ButtonEvent.button == 1) { Mouse.Set(MouseButton.Left, false); } else if (e.ButtonEvent.button == 2) { Mouse.Set(MouseButton.Middle, false); } else if (e.ButtonEvent.button == 3) { Mouse.Set(MouseButton.Right, false); } else if (e.ButtonEvent.button == 6) { Keyboard.Set(Key.XButton1, false); } else if (e.ButtonEvent.button == 7) { Keyboard.Set(Key.XButton2, false); } break; case XEventName.MotionNotify: Mouse.SetPos(e.MotionEvent.x, e.MotionEvent.y); break; case XEventName.FocusIn: case XEventName.FocusOut: { bool wasFocused = Focused; Focused = e.type == XEventName.FocusIn; if (Focused != wasFocused) { RaiseFocusedChanged(); } } break; case XEventName.MappingNotify: // 0 == MappingModifier, 1 == MappingKeyboard if (e.MappingEvent.request == 0 || e.MappingEvent.request == 1) { Debug.Print("keybard mapping refreshed"); API.XRefreshKeyboardMapping(ref e.MappingEvent); } break; case XEventName.PropertyNotify: if (e.PropertyEvent.atom == net_wm_state) { RaiseWindowStateChanged(); } //if (e.PropertyEvent.atom == net_frame_extents) { // RefreshWindowBorders(); //} break; case XEventName.SelectionNotify: clipboard_paste_text = ""; if (e.SelectionEvent.selection == xa_clipboard && e.SelectionEvent.target == xa_utf8_string && e.SelectionEvent.property == xa_data_sel) { IntPtr prop_type, num_items, bytes_after, data = IntPtr.Zero; int prop_format; API.XGetWindowProperty(API.DefaultDisplay, WinHandle, xa_data_sel, IntPtr.Zero, new IntPtr(1024), false, IntPtr.Zero, out prop_type, out prop_format, out num_items, out bytes_after, ref data); API.XDeleteProperty(API.DefaultDisplay, WinHandle, xa_data_sel); if (num_items == IntPtr.Zero) { break; } if (prop_type == xa_utf8_string) { byte[] dst = new byte[(int)num_items]; byte * src = (byte *)data; for (int i = 0; i < dst.Length; i++) { dst[i] = src[i]; } clipboard_paste_text = Encoding.UTF8.GetString(dst); } API.XFree(data); } break; case XEventName.SelectionRequest: XEvent reply = default(XEvent); reply.SelectionEvent.type = XEventName.SelectionNotify; reply.SelectionEvent.send_event = true; reply.SelectionEvent.display = API.DefaultDisplay; reply.SelectionEvent.requestor = e.SelectionRequestEvent.requestor; reply.SelectionEvent.selection = e.SelectionRequestEvent.selection; reply.SelectionEvent.target = e.SelectionRequestEvent.target; reply.SelectionEvent.property = IntPtr.Zero; reply.SelectionEvent.time = e.SelectionRequestEvent.time; if (e.SelectionRequestEvent.selection == xa_clipboard && e.SelectionRequestEvent.target == xa_utf8_string && clipboard_copy_text != null) { reply.SelectionEvent.property = GetSelectionProperty(ref e); byte[] utf8_data = Encoding.UTF8.GetBytes(clipboard_copy_text); fixed(byte *utf8_ptr = utf8_data) { API.XChangeProperty(API.DefaultDisplay, reply.SelectionEvent.requestor, reply.SelectionEvent.property, xa_utf8_string, 8, PropertyMode.Replace, (IntPtr)utf8_ptr, utf8_data.Length); } } else if (e.SelectionRequestEvent.selection == xa_clipboard && e.SelectionRequestEvent.target == xa_targets) { reply.SelectionEvent.property = GetSelectionProperty(ref e); IntPtr[] data = new IntPtr[] { xa_utf8_string, xa_targets }; API.XChangeProperty(API.DefaultDisplay, reply.SelectionEvent.requestor, reply.SelectionEvent.property, xa_atom, 32, PropertyMode.Replace, data, data.Length); } API.XSendEvent(API.DefaultDisplay, e.SelectionRequestEvent.requestor, true, EventMask.NoEventMask, ref reply); break; } } }
public void Exit() { Debug.Print("[X11] Sending exit message window {0:X} on display {1:X}", window.Handle, window.Display); XEvent ev = new XEvent(); ev.type = XEventName.ClientMessage; ev.ClientMessageEvent.format = 32; ev.ClientMessageEvent.display = window.Display; ev.ClientMessageEvent.window = window.Handle; ev.ClientMessageEvent.ptr1 = _atom_wm_destroy; using (new XLock(window.Display)) { Functions.XSendEvent(window.Display, window.Handle, false, EventMask.NoEventMask, ref ev); Functions.XFlush(window.Display); } }
public X11Window(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) { Debug.Print("Creating X11GLNative window."); // Open a display connection to the X server, and obtain the screen and root window. Debug.Print("Display: {0}, Screen {1}, Root window: {2}", API.DefaultDisplay, API.DefaultScreen, API.RootWindow); RegisterAtoms(); VisualInfo = X11GLContext.SelectGraphicsMode(mode); // Create a window on this display using the visual above Debug.Print("Opening render window... "); XSetWindowAttributes attributes = new XSetWindowAttributes(); attributes.colormap = API.XCreateColormap(API.DefaultDisplay, API.RootWindow, VisualInfo.Visual, 0 /*AllocNone*/); eventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask | EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask | EventMask.PointerMotionMask | EventMask.FocusChangeMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PropertyChangeMask; attributes.event_mask = (IntPtr)eventMask; uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask | (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel; WinHandle = API.XCreateWindow(API.DefaultDisplay, API.RootWindow, x, y, width, height, 0, VisualInfo.Depth /*(int)CreateWindowArgs.CopyFromParent*/, (int)CreateWindowArgs.InputOutput, VisualInfo.Visual, (IntPtr)mask, ref attributes); if (WinHandle == IntPtr.Zero) { throw new ApplicationException("XCreateWindow call failed (returned 0)."); } if (title != null) { API.XStoreName(API.DefaultDisplay, WinHandle, title); } XSizeHints hints = new XSizeHints(); hints.base_width = width; hints.base_height = height; hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition); API.XSetWMNormalHints(API.DefaultDisplay, WinHandle, ref hints); // Register for window destroy notification API.XSetWMProtocols(API.DefaultDisplay, WinHandle, new IntPtr[] { wm_destroy }, 1); // Set the initial window size to ensure X, Y, Width, Height and the rest // return the correct values inside the constructor and the Load event. XEvent e = new XEvent(); e.ConfigureEvent.x = x; e.ConfigureEvent.y = y; e.ConfigureEvent.width = width; e.ConfigureEvent.height = height; RefreshWindowBounds(ref e); Debug.Print("X11GLNative window created successfully (id: {0}).", WinHandle); // Request that auto-repeat is only set on devices that support it physically. // This typically means that it's turned off for keyboards (which is what we want). // We prefer this method over XAutoRepeatOff/On, because the latter needs to // be reset before the program exits. bool supported; API.XkbSetDetectableAutoRepeat(API.DefaultDisplay, true, out supported); Exists = true; }
public extern static bool XFilterEvent(ref XEvent xevent, IntPtr window);
public static void PeekEvent(IntPtr display, [In, Out] XEvent event_return);
public extern static IntPtr XNextEvent(IntPtr display, ref XEvent xevent);
public static bool SendEvent(IntPtr display, IntPtr window, bool propagate, [MarshalAs(UnmanagedType.SysInt)] EventMask event_mask, ref XEvent event_send);
void ProcessEvents() { while (!disposed) { XEvent e = new XEvent(); XGenericEventCookie cookie; using (new XLock(window.Display)) { Functions.XIfEvent(window.Display, ref e, Predicate, new IntPtr(XIOpCode)); if (e.type == XEventName.ClientMessage && e.ClientMessageEvent.ptr1 == ExitAtom) { Functions.XDestroyWindow(window.Display, window.Handle); window.Handle = IntPtr.Zero; break; } if (e.type == XEventName.GenericEvent && e.GenericEvent.extension == XIOpCode) { IntPtr dummy; int x, y, dummy2; Functions.XQueryPointer(window.Display, window.RootWindow, out dummy, out dummy, out x, out y, out dummy2, out dummy2, out dummy2); Interlocked.Exchange(ref cursor_x, (long)x); Interlocked.Exchange(ref cursor_y, (long)y); cookie = e.GenericEventCookie; if (Functions.XGetEventData(window.Display, ref cookie) != 0) { switch ((XIEventType)cookie.evtype) { case XIEventType.Motion: // Nothing to do break; case XIEventType.RawKeyPress: case XIEventType.RawKeyRelease: case XIEventType.RawMotion: case XIEventType.RawButtonPress: case XIEventType.RawButtonRelease: // Delivered to all XIMouse instances ProcessRawEvent(ref cookie); break; case XIEventType.DeviceChanged: UpdateDevices(); break; } } Functions.XFreeEventData(window.Display, ref cookie); } } } Debug.WriteLine("[X11] Exiting input event loop."); }
public static bool IfEvent(IntPtr display, ref XEvent event_return, API.CheckEventPredicate predicate, IntPtr arg);
public static int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XEvent send_event) { return(XSendEvent(display, window, propagate, new IntPtr((int)event_mask), ref send_event)); }
public static bool CheckMaskEvent(IntPtr display, EventMask event_mask, ref XEvent event_return);
public extern static Bool XCheckWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return);
private void ProcessEvents() { while (true) { XEvent e = new XEvent(); using (new XLock(this.window.Display)) { if (!Functions.XCheckIfEvent(this.window.Display, ref e, this.Predicate, new IntPtr(XI2Mouse.XIOpCode))) { break; } XGenericEventCookie cookie = e.GenericEventCookie; if (Functions.XGetEventData(this.window.Display, ref cookie) != 0) { XIRawEvent xiRawEvent = (XIRawEvent)Marshal.PtrToStructure(cookie.data, typeof(XIRawEvent)); if (!this.rawids.ContainsKey(xiRawEvent.deviceid)) { this.mice.Add(new MouseState()); this.rawids.Add(xiRawEvent.deviceid, this.mice.Count - 1); } MouseState mouseState = this.mice[this.rawids[xiRawEvent.deviceid]]; switch (xiRawEvent.evtype) { case XIEventType.RawButtonPress: switch (xiRawEvent.detail) { case 1: mouseState.EnableBit(0); break; case 2: mouseState.EnableBit(1); break; case 3: mouseState.EnableBit(2); break; case 4: ++mouseState.WheelPrecise; break; case 5: --mouseState.WheelPrecise; break; case 6: mouseState.EnableBit(3); break; case 7: mouseState.EnableBit(4); break; case 8: mouseState.EnableBit(5); break; case 9: mouseState.EnableBit(6); break; case 10: mouseState.EnableBit(7); break; case 11: mouseState.EnableBit(8); break; case 12: mouseState.EnableBit(9); break; case 13: mouseState.EnableBit(10); break; case 14: mouseState.EnableBit(11); break; } case XIEventType.RawButtonRelease: switch (xiRawEvent.detail) { case 1: mouseState.DisableBit(0); break; case 2: mouseState.DisableBit(1); break; case 3: mouseState.DisableBit(2); break; case 6: mouseState.DisableBit(3); break; case 7: mouseState.DisableBit(4); break; case 8: mouseState.DisableBit(5); break; case 9: mouseState.DisableBit(6); break; case 10: mouseState.DisableBit(7); break; case 11: mouseState.DisableBit(8); break; case 12: mouseState.DisableBit(9); break; case 13: mouseState.DisableBit(10); break; case 14: mouseState.DisableBit(11); break; } case XIEventType.RawMotion: double x = 0.0; double y = 0.0; if (XI2Mouse.IsBitSet(xiRawEvent.valuators.mask, 0)) { x = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(xiRawEvent.raw_values, 0)); } if (XI2Mouse.IsBitSet(xiRawEvent.valuators.mask, 1)) { y = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(xiRawEvent.raw_values, 8)); } if (!this.CheckMouseWarp(x, y)) { mouseState.X += (int)x; mouseState.Y += (int)y; break; } else { break; } } this.mice[this.rawids[xiRawEvent.deviceid]] = mouseState; } Functions.XFreeEventData(this.window.Display, ref cookie); } } }
internal void ProcessEvent(ref XEvent e) { switch (e.type) { case XEventName.KeyPress: case XEventName.KeyRelease: bool pressed = e.type == XEventName.KeyPress; IntPtr keysym = API.LookupKeysym(ref e.KeyEvent, 0); IntPtr keysym2 = API.LookupKeysym(ref e.KeyEvent, 1); if (keymap.ContainsKey((XKey)keysym)) { keyboard[keymap[(XKey)keysym]] = pressed; } else if (keymap.ContainsKey((XKey)keysym2)) { keyboard[keymap[(XKey)keysym2]] = pressed; } else { Debug.Print("KeyCode {0} (Keysym: {1}, {2}) not mapped.", e.KeyEvent.keycode, (XKey)keysym, (XKey)keysym2); } break; case XEventName.ButtonPress: if (e.ButtonEvent.button == 1) { mouse[OpenTK.Input.MouseButton.Left] = true; } else if (e.ButtonEvent.button == 2) { mouse[OpenTK.Input.MouseButton.Middle] = true; } else if (e.ButtonEvent.button == 3) { mouse[OpenTK.Input.MouseButton.Right] = true; } else if (e.ButtonEvent.button == 4) { mouse.Wheel++; } else if (e.ButtonEvent.button == 5) { mouse.Wheel--; } else if (e.ButtonEvent.button == 6) { mouse[OpenTK.Input.MouseButton.Button1] = true; } else if (e.ButtonEvent.button == 7) { mouse[OpenTK.Input.MouseButton.Button2] = true; } else if (e.ButtonEvent.button == 8) { mouse[OpenTK.Input.MouseButton.Button3] = true; } else if (e.ButtonEvent.button == 9) { mouse[OpenTK.Input.MouseButton.Button4] = true; } else if (e.ButtonEvent.button == 10) { mouse[OpenTK.Input.MouseButton.Button5] = true; } else if (e.ButtonEvent.button == 11) { mouse[OpenTK.Input.MouseButton.Button6] = true; } else if (e.ButtonEvent.button == 12) { mouse[OpenTK.Input.MouseButton.Button7] = true; } else if (e.ButtonEvent.button == 13) { mouse[OpenTK.Input.MouseButton.Button8] = true; } else if (e.ButtonEvent.button == 14) { mouse[OpenTK.Input.MouseButton.Button9] = true; } //if ((e.state & (int)X11.MouseMask.Button4Mask) != 0) m.Wheel++; //if ((e.state & (int)X11.MouseMask.Button5Mask) != 0) m.Wheel--; //Debug.Print("Button pressed: {0}", e.ButtonEvent.button); break; case XEventName.ButtonRelease: if (e.ButtonEvent.button == 1) { mouse[OpenTK.Input.MouseButton.Left] = false; } else if (e.ButtonEvent.button == 2) { mouse[OpenTK.Input.MouseButton.Middle] = false; } else if (e.ButtonEvent.button == 3) { mouse[OpenTK.Input.MouseButton.Right] = false; } else if (e.ButtonEvent.button == 6) { mouse[OpenTK.Input.MouseButton.Button1] = false; } else if (e.ButtonEvent.button == 7) { mouse[OpenTK.Input.MouseButton.Button2] = false; } else if (e.ButtonEvent.button == 8) { mouse[OpenTK.Input.MouseButton.Button3] = false; } else if (e.ButtonEvent.button == 9) { mouse[OpenTK.Input.MouseButton.Button4] = false; } else if (e.ButtonEvent.button == 10) { mouse[OpenTK.Input.MouseButton.Button5] = false; } else if (e.ButtonEvent.button == 11) { mouse[OpenTK.Input.MouseButton.Button6] = false; } else if (e.ButtonEvent.button == 12) { mouse[OpenTK.Input.MouseButton.Button7] = false; } else if (e.ButtonEvent.button == 13) { mouse[OpenTK.Input.MouseButton.Button8] = false; } else if (e.ButtonEvent.button == 14) { mouse[OpenTK.Input.MouseButton.Button9] = false; } break; case XEventName.MotionNotify: mouse.Position = new Point(e.MotionEvent.x, e.MotionEvent.y); break; } }
void RefreshWindowBounds(ref XEvent e) { RefreshWindowBorders(); Point newLoc = new Point(e.ConfigureEvent.x - borderLeft, e.ConfigureEvent.y - borderTop); if (Location != newLoc) { bounds.Location = newLoc; if (Move != null) Move(this, EventArgs.Empty); } // Note: width and height denote the internal (client) size. // To get the external (window) size, we need to add the border size. Size newSize = new Size( e.ConfigureEvent.width + borderLeft + borderRight, e.ConfigureEvent.height + borderTop + borderBottom); if (bounds.Size != newSize) { bounds.Size = newSize; client_rectangle.Size = new Size(e.ConfigureEvent.width, e.ConfigureEvent.height); if (this.Resize != null) { Resize(this, EventArgs.Empty); } } }
internal void ProcessEvent(ref XEvent e) { switch (e.type) { case XEventName.KeyPress: case XEventName.KeyRelease: bool pressed = e.type == XEventName.KeyPress; IntPtr keysym = API.LookupKeysym(ref e.KeyEvent, 0); IntPtr keysym2 = API.LookupKeysym(ref e.KeyEvent, 1); if (keymap.ContainsKey((XKey)keysym)) keyboard[keymap[(XKey)keysym]] = pressed; else if (keymap.ContainsKey((XKey)keysym2)) keyboard[keymap[(XKey)keysym2]] = pressed; else Debug.Print("KeyCode {0} (Keysym: {1}, {2}) not mapped.", e.KeyEvent.keycode, (XKey)keysym, (XKey)keysym2); break; case XEventName.ButtonPress: if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = true; else if (e.ButtonEvent.button == 2) mouse[OpenTK.Input.MouseButton.Middle] = true; else if (e.ButtonEvent.button == 3) mouse[OpenTK.Input.MouseButton.Right] = true; else if (e.ButtonEvent.button == 4) mouse.Wheel++; else if (e.ButtonEvent.button == 5) mouse.Wheel--; else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = true; else if (e.ButtonEvent.button == 7) mouse[OpenTK.Input.MouseButton.Button2] = true; else if (e.ButtonEvent.button == 8) mouse[OpenTK.Input.MouseButton.Button3] = true; else if (e.ButtonEvent.button == 9) mouse[OpenTK.Input.MouseButton.Button4] = true; else if (e.ButtonEvent.button == 10) mouse[OpenTK.Input.MouseButton.Button5] = true; else if (e.ButtonEvent.button == 11) mouse[OpenTK.Input.MouseButton.Button6] = true; else if (e.ButtonEvent.button == 12) mouse[OpenTK.Input.MouseButton.Button7] = true; else if (e.ButtonEvent.button == 13) mouse[OpenTK.Input.MouseButton.Button8] = true; else if (e.ButtonEvent.button == 14) mouse[OpenTK.Input.MouseButton.Button9] = true; //if ((e.state & (int)X11.MouseMask.Button4Mask) != 0) m.Wheel++; //if ((e.state & (int)X11.MouseMask.Button5Mask) != 0) m.Wheel--; //Debug.Print("Button pressed: {0}", e.ButtonEvent.button); break; case XEventName.ButtonRelease: if (e.ButtonEvent.button == 1) mouse[OpenTK.Input.MouseButton.Left] = false; else if (e.ButtonEvent.button == 2) mouse[OpenTK.Input.MouseButton.Middle] = false; else if (e.ButtonEvent.button == 3) mouse[OpenTK.Input.MouseButton.Right] = false; else if (e.ButtonEvent.button == 6) mouse[OpenTK.Input.MouseButton.Button1] = false; else if (e.ButtonEvent.button == 7) mouse[OpenTK.Input.MouseButton.Button2] = false; else if (e.ButtonEvent.button == 8) mouse[OpenTK.Input.MouseButton.Button3] = false; else if (e.ButtonEvent.button == 9) mouse[OpenTK.Input.MouseButton.Button4] = false; else if (e.ButtonEvent.button == 10) mouse[OpenTK.Input.MouseButton.Button5] = false; else if (e.ButtonEvent.button == 11) mouse[OpenTK.Input.MouseButton.Button6] = false; else if (e.ButtonEvent.button == 12) mouse[OpenTK.Input.MouseButton.Button7] = false; else if (e.ButtonEvent.button == 13) mouse[OpenTK.Input.MouseButton.Button8] = false; else if (e.ButtonEvent.button == 14) mouse[OpenTK.Input.MouseButton.Button9] = false; break; case XEventName.MotionNotify: mouse.Position = new Point(e.MotionEvent.x, e.MotionEvent.y); break; } }
public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) { if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be higher than zero."); if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be higher than zero."); Debug.Print("Creating X11GLNative window."); // Open a display connection to the X server, and obtain the screen and root window. window.Display = API.DefaultDisplay; window.Screen = API.XDefaultScreen(window.Display); //API.DefaultScreen; window.RootWindow = API.XRootWindow(window.Display, window.Screen); // API.RootWindow; Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow); RegisterAtoms(window); XVisualInfo info = new XVisualInfo(); mode = X11GLContext.SelectGraphicsMode( mode, out info ); window.VisualInfo = info; // Create a window on this display using the visual above Debug.Print("Opening render window... "); XSetWindowAttributes attributes = new XSetWindowAttributes(); attributes.background_pixel = IntPtr.Zero; attributes.border_pixel = IntPtr.Zero; attributes.colormap = API.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0/*AllocNone*/); window.EventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask | EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask | EventMask.PointerMotionMask | EventMask.FocusChangeMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PropertyChangeMask; attributes.event_mask = (IntPtr)window.EventMask; uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask | (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel; window.WindowHandle = API.XCreateWindow(window.Display, window.RootWindow, x, y, width, height, 0, window.VisualInfo.Depth/*(int)CreateWindowArgs.CopyFromParent*/, (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (IntPtr)mask, ref attributes); if (window.WindowHandle == IntPtr.Zero) throw new ApplicationException("XCreateWindow call failed (returned 0)."); if (title != null) API.XStoreName(window.Display, window.WindowHandle, title); // Set the window hints SetWindowMinMax(_min_width, _min_height, -1, -1); XSizeHints hints = new XSizeHints(); hints.base_width = width; hints.base_height = height; hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition); API.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints); // Register for window destroy notification API.XSetWMProtocols(window.Display, window.WindowHandle, new IntPtr[] { wm_destroy }, 1); // Set the initial window size to ensure X, Y, Width, Height and the rest // return the correct values inside the constructor and the Load event. XEvent e = new XEvent(); e.ConfigureEvent.x = x; e.ConfigureEvent.y = y; e.ConfigureEvent.width = width; e.ConfigureEvent.height = height; RefreshWindowBounds(ref e); Debug.Print("X11GLNative window created successfully (id: {0}).", Handle); SetupInput(); exists = true; }
public extern static Bool XCheckTypedEvent(Display display, XEventName event_type, out XEvent event_return);
internal void ProcessEvent(ref XEvent e) { switch (e.type) { case XEventName.ButtonPress: if (e.ButtonEvent.button == 1) { mouse[OpenTK.Input.MouseButton.Left] = true; } else if (e.ButtonEvent.button == 2) { mouse[OpenTK.Input.MouseButton.Middle] = true; } else if (e.ButtonEvent.button == 3) { mouse[OpenTK.Input.MouseButton.Right] = true; } else if (e.ButtonEvent.button == 4) { mouse.Wheel++; } else if (e.ButtonEvent.button == 5) { mouse.Wheel--; } else if (e.ButtonEvent.button == 6) { mouse[OpenTK.Input.MouseButton.Button1] = true; } else if (e.ButtonEvent.button == 7) { mouse[OpenTK.Input.MouseButton.Button2] = true; } else if (e.ButtonEvent.button == 8) { mouse[OpenTK.Input.MouseButton.Button3] = true; } else if (e.ButtonEvent.button == 9) { mouse[OpenTK.Input.MouseButton.Button4] = true; } else if (e.ButtonEvent.button == 10) { mouse[OpenTK.Input.MouseButton.Button5] = true; } else if (e.ButtonEvent.button == 11) { mouse[OpenTK.Input.MouseButton.Button6] = true; } else if (e.ButtonEvent.button == 12) { mouse[OpenTK.Input.MouseButton.Button7] = true; } else if (e.ButtonEvent.button == 13) { mouse[OpenTK.Input.MouseButton.Button8] = true; } else if (e.ButtonEvent.button == 14) { mouse[OpenTK.Input.MouseButton.Button9] = true; } //if ((e.state & (int)X11.MouseMask.Button4Mask) != 0) m.Wheel++; //if ((e.state & (int)X11.MouseMask.Button5Mask) != 0) m.Wheel--; //Debug.Print("Button pressed: {0}", e.ButtonEvent.button); break; case XEventName.ButtonRelease: if (e.ButtonEvent.button == 1) { mouse[OpenTK.Input.MouseButton.Left] = false; } else if (e.ButtonEvent.button == 2) { mouse[OpenTK.Input.MouseButton.Middle] = false; } else if (e.ButtonEvent.button == 3) { mouse[OpenTK.Input.MouseButton.Right] = false; } else if (e.ButtonEvent.button == 6) { mouse[OpenTK.Input.MouseButton.Button1] = false; } else if (e.ButtonEvent.button == 7) { mouse[OpenTK.Input.MouseButton.Button2] = false; } else if (e.ButtonEvent.button == 8) { mouse[OpenTK.Input.MouseButton.Button3] = false; } else if (e.ButtonEvent.button == 9) { mouse[OpenTK.Input.MouseButton.Button4] = false; } else if (e.ButtonEvent.button == 10) { mouse[OpenTK.Input.MouseButton.Button5] = false; } else if (e.ButtonEvent.button == 11) { mouse[OpenTK.Input.MouseButton.Button6] = false; } else if (e.ButtonEvent.button == 12) { mouse[OpenTK.Input.MouseButton.Button7] = false; } else if (e.ButtonEvent.button == 13) { mouse[OpenTK.Input.MouseButton.Button8] = false; } else if (e.ButtonEvent.button == 14) { mouse[OpenTK.Input.MouseButton.Button9] = false; } break; case XEventName.MotionNotify: mouse.Position = new Point(e.MotionEvent.x, e.MotionEvent.y); break; } }
#pragma warning restore 414 #endregion #region Constructors public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device) : this() { if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be higher than zero."); if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be higher than zero."); Debug.Indent(); using (new XLock(window.Display)) { IntPtr visual; IntPtr fbconfig; window.GraphicsMode = new X11GraphicsMode() .SelectGraphicsMode(mode, out visual, out fbconfig); window.Visual = visual; window.FBConfig = fbconfig; // Create a window on this display using the visual above Debug.Write("Opening render window... "); XSetWindowAttributes attributes = new XSetWindowAttributes(); attributes.background_pixel = IntPtr.Zero; attributes.border_pixel = IntPtr.Zero; attributes.colormap = Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0/*AllocNone*/); window.EventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask | EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask | EventMask.PointerMotionMask | EventMask.FocusChangeMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PropertyChangeMask; attributes.event_mask = (IntPtr)window.EventMask; SetWindowValuemask mask = SetWindowValuemask.ColorMap | SetWindowValuemask.EventMask | SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel; window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow, x, y, width, height, 0, window.VisualInfo.Depth/*(int)CreateWindowArgs.CopyFromParent*/, CreateWindowArgs.InputOutput, window.VisualInfo.Visual, mask, attributes); if (window.Handle == IntPtr.Zero) throw new ApplicationException("XCreateWindow call failed (returned 0)."); if (title != null) Functions.XStoreName(window.Display, window.Handle, title); } XSizeHints hints = new XSizeHints(); hints.base_width = width; hints.base_height = height; hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition); XClassHint class_hint = new XClassHint(); class_hint.Name = Assembly.GetEntryAssembly().GetName().Name.ToLower(); class_hint.Class = Assembly.GetEntryAssembly().GetName().Name; using (new XLock(window.Display)) { Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints); // Register for window destroy notification Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { _atom_wm_destroy }, 1); // Set the window class hints Functions.XSetClassHint(window.Display, window.Handle, ref class_hint); } SetWindowMinMax(_min_width, _min_height, -1, -1); // Set the initial window size to ensure X, Y, Width, Height and the rest // return the correct values inside the constructor and the Load event. XEvent e = new XEvent(); e.ConfigureEvent.x = x; e.ConfigureEvent.y = y; e.ConfigureEvent.width = width; e.ConfigureEvent.height = height; RefreshWindowBounds(ref e); EmptyCursor = CreateEmptyCursor(window); Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle)); Debug.Unindent(); using (new XLock(window.Display)) { // Request that auto-repeat is only set on devices that support it physically. // This typically means that it's turned off for keyboards (which is what we want). // We prefer this method over XAutoRepeatOff/On, because the latter needs to // be reset before the program exits. if (Xkb.IsSupported(window.Display)) { bool supported; Xkb.SetDetectableAutoRepeat(window.Display, true, out supported); } } // The XInput2 extension makes keyboard and mouse handling much easier. // Check whether it is available. xi2_supported = XI2MouseKeyboard.IsSupported(window.Display); if (xi2_supported) { xi2_opcode = XI2MouseKeyboard.XIOpCode; xi2_version = XI2MouseKeyboard.XIVersion; } exists = true; }
public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode,GameWindowFlags options, DisplayDevice device) : this() { if (width <= 0) throw new ArgumentOutOfRangeException("width", "Must be higher than zero."); if (height <= 0) throw new ArgumentOutOfRangeException("height", "Must be higher than zero."); XVisualInfo info = new XVisualInfo(); Debug.Indent(); using (new XLock(window.Display)) { if (!mode.Index.HasValue) throw new GraphicsModeException("Invalid or unsupported GraphicsMode."); info.VisualID = mode.Index.Value; int dummy; window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure( Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo)); // Create a window on this display using the visual above Debug.Write("Opening render window... "); XSetWindowAttributes attributes = new XSetWindowAttributes(); attributes.background_pixel = IntPtr.Zero; attributes.border_pixel = IntPtr.Zero; attributes.colormap = Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0/*AllocNone*/); window.EventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask | EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask | EventMask.PointerMotionMask | EventMask.FocusChangeMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PropertyChangeMask; attributes.event_mask = (IntPtr)window.EventMask; uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask | (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel; window.WindowHandle = Functions.XCreateWindow(window.Display, window.RootWindow, x, y, width, height, 0, window.VisualInfo.Depth/*(int)CreateWindowArgs.CopyFromParent*/, (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (UIntPtr)mask, ref attributes); if (window.WindowHandle == IntPtr.Zero) throw new ApplicationException("XCreateWindow call failed (returned 0)."); if (title != null) Functions.XStoreName(window.Display, window.WindowHandle, title); } // Set the window hints SetWindowMinMax(_min_width, _min_height, -1, -1); XSizeHints hints = new XSizeHints(); hints.base_width = width; hints.base_height = height; hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition); using (new XLock(window.Display)) { Functions.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints); // Register for window destroy notification Functions.XSetWMProtocols(window.Display, window.WindowHandle, new IntPtr[] { _atom_wm_destroy }, 1); } // Set the initial window size to ensure X, Y, Width, Height and the rest // return the correct values inside the constructor and the Load event. XEvent e = new XEvent(); e.ConfigureEvent.x = x; e.ConfigureEvent.y = y; e.ConfigureEvent.width = width; e.ConfigureEvent.height = height; RefreshWindowBounds(ref e); driver = new X11Input(window); Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle)); Debug.Unindent(); exists = true; }
void RefreshWindowBounds(ref XEvent e) { RefreshWindowBorders(); // For whatever reason, the x/y coordinates // of a configure event are global to the // root window when it is a send_event but // local when it is a regular event. // I don't know who designed this, but this is // utter nonsense. int x, y; IntPtr unused; if (!e.ConfigureEvent.send_event) { Functions.XTranslateCoordinates(window.Display, window.Handle, window.RootWindow, 0, 0, out x, out y, out unused); } else { x = e.ConfigureEvent.x; y = e.ConfigureEvent.y; } Point new_location = new Point( x - border_left, y - border_top); if (Location != new_location) { bounds.Location = new_location; OnMove(EventArgs.Empty); } // Note: width and height denote the internal (client) size. // To get the external (window) size, we need to add the border size. Size new_size = new Size( e.ConfigureEvent.width + border_left + border_right, e.ConfigureEvent.height + border_top + border_bottom); if (Bounds.Size != new_size) { bounds.Size = new_size; // X11 sets the client width/height to 0 // when the window is minimized. Many apps // do not expect this and crash, so clamp // minimum width/height to 1 instead. client_rectangle.Size = new Size( Math.Max(e.ConfigureEvent.width, 1), Math.Max(e.ConfigureEvent.height, 1)); OnResize(EventArgs.Empty); } //Debug.Print("[X11] Window bounds changed: {0}", bounds); }
void RefreshWindowBounds(ref XEvent e) { RefreshWindowBorders(); Point new_location = new Point( e.ConfigureEvent.x - border_left, e.ConfigureEvent.y - border_top); if (Location != new_location) { bounds.Location = new_location; if (Move != null) Move(this, EventArgs.Empty); } // Note: width and height denote the internal (client) size. // To get the external (window) size, we need to add the border size. Size new_size = new Size( e.ConfigureEvent.width + border_left + border_right, e.ConfigureEvent.height + border_top + border_bottom); if (Bounds.Size != new_size) { bounds.Size = new_size; client_rectangle.Size = new Size(e.ConfigureEvent.width, e.ConfigureEvent.height); if (this.Resize != null) { //Debug.WriteLine(new System.Diagnostics.StackTrace()); Resize(this, EventArgs.Empty); } } }
public static int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XEvent send_event) { return XSendEvent(display, window, propagate, new IntPtr((int)event_mask), ref send_event); }
public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, DisplayDevice device) { if (width <= 0) { throw new ArgumentOutOfRangeException("width", "Must be higher than zero."); } if (height <= 0) { throw new ArgumentOutOfRangeException("height", "Must be higher than zero."); } Debug.Print("Creating X11GLNative window."); // Open a display connection to the X server, and obtain the screen and root window. window.Display = API.DefaultDisplay; window.Screen = API.XDefaultScreen(window.Display); //API.DefaultScreen; window.RootWindow = API.XRootWindow(window.Display, window.Screen); // API.RootWindow; Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow); RegisterAtoms(window); XVisualInfo info = new XVisualInfo(); mode = X11GLContext.SelectGraphicsMode(mode, out info); window.VisualInfo = info; // Create a window on this display using the visual above Debug.Print("Opening render window... "); XSetWindowAttributes attributes = new XSetWindowAttributes(); attributes.background_pixel = IntPtr.Zero; attributes.border_pixel = IntPtr.Zero; attributes.colormap = API.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0 /*AllocNone*/); window.EventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask | EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask | EventMask.PointerMotionMask | EventMask.FocusChangeMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PropertyChangeMask; attributes.event_mask = (IntPtr)window.EventMask; uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask | (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel; window.WindowHandle = API.XCreateWindow(window.Display, window.RootWindow, x, y, width, height, 0, window.VisualInfo.Depth /*(int)CreateWindowArgs.CopyFromParent*/, (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (IntPtr)mask, ref attributes); if (window.WindowHandle == IntPtr.Zero) { throw new ApplicationException("XCreateWindow call failed (returned 0)."); } if (title != null) { API.XStoreName(window.Display, window.WindowHandle, title); } // Set the window hints SetWindowMinMax(_min_width, _min_height, -1, -1); XSizeHints hints = new XSizeHints(); hints.base_width = width; hints.base_height = height; hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition); API.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints); // Register for window destroy notification API.XSetWMProtocols(window.Display, window.WindowHandle, new IntPtr[] { wm_destroy }, 1); // Set the initial window size to ensure X, Y, Width, Height and the rest // return the correct values inside the constructor and the Load event. XEvent e = new XEvent(); e.ConfigureEvent.x = x; e.ConfigureEvent.y = y; e.ConfigureEvent.width = width; e.ConfigureEvent.height = height; RefreshWindowBounds(ref e); Debug.Print("X11GLNative window created successfully (id: {0}).", Handle); SetupInput(); exists = true; }
public static void SendNetClientMessage(X11WindowInfo window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2) { XEvent xev; xev = new XEvent(); xev.ClientMessageEvent.type = XEventName.ClientMessage; xev.ClientMessageEvent.send_event = true; xev.ClientMessageEvent.window = window.WindowHandle; xev.ClientMessageEvent.message_type = message_type; xev.ClientMessageEvent.format = 32; xev.ClientMessageEvent.ptr1 = l0; xev.ClientMessageEvent.ptr2 = l1; xev.ClientMessageEvent.ptr3 = l2; XSendEvent(window.Display, window.WindowHandle, false, new IntPtr((int)EventMask.NoEventMask), ref xev); }
public extern static Bool XCheckIfEvent(Display display, ref XEvent e, IntPtr predicate, IntPtr arg);
extern public static void XMaskEvent(IntPtr display, EventMask event_mask, ref XEvent e);
public override string ToString() { return(XEvent.ToString(this)); }
public static extern void XPutBackEvent(IntPtr display, ref XEvent @event);
static bool IsEventValid(IntPtr display, ref XEvent e, IntPtr arg) { bool valid = false; switch (e.type) { case XEventName.GenericEvent: { long extension = (long)e.GenericEventCookie.extension; valid = extension == arg.ToInt64() && (e.GenericEventCookie.evtype == (int)XIEventType.RawKeyPress || e.GenericEventCookie.evtype == (int)XIEventType.RawKeyRelease || e.GenericEventCookie.evtype == (int)XIEventType.RawMotion || e.GenericEventCookie.evtype == (int)XIEventType.RawButtonPress || e.GenericEventCookie.evtype == (int)XIEventType.RawButtonRelease || e.GenericEventCookie.evtype == (int)XIEventType.DeviceChanged); valid |= extension == 0; break; } case XEventName.ClientMessage: valid = e.ClientMessageEvent.ptr1 == ExitAtom; break; } return valid; }
public static extern int XRRUpdateConfiguration(ref XEvent @event);
extern public static bool SendEvent(Display display, Window window, bool propagate, [MarshalAs(UnmanagedType.SysInt)]EventMask event_mask, ref XEvent event_send);
public static extern bool IfEvent(Display display, ref XEvent event_return, /*[MarshalAs(UnmanagedType.FunctionPtr)] */ CheckEventPredicate predicate, /*XPointer*/ IntPtr arg);
public static extern bool CheckMaskEvent(Display display, EventMask event_mask, ref XEvent event_return);
public static extern bool XIfEvent(Display display, ref XEvent e, IntPtr predicate, IntPtr arg);