public static void SendClientMessage(IntPtr display, nuint window, nuint messageType, nuint message, nint data = default) { var clientEvent = new XClientMessageEvent { type = ClientMessage, serial = 0, send_event = True, display = display, window = window, message_type = messageType, format = 32 }; if (Environment.Is64BitProcess) { clientEvent.data.l[0] = unchecked ((nint)(uint)message); clientEvent.data.l[1] = (nint)(uint)(message >> 32); Assert(clientEvent.data.l[1] == 0, Resources.ArgumentOutOfRangeExceptionMessage, nameof(message), message); clientEvent.data.l[2] = unchecked ((nint)(uint)data); clientEvent.data.l[3] = (nint)(uint)(data >> 32); } else { clientEvent.data.l[0] = (nint)message; clientEvent.data.l[1] = data; } ThrowExternalExceptionIfZero(nameof(XSendEvent), XSendEvent( clientEvent.display, clientEvent.window, False, NoEventMask, (XEvent *)&clientEvent )); }
#pragma warning restore IDE1006 public static void SendClientMessage(IntPtr display, nuint targetWindow, nint eventMask, nuint eventWindow, nuint messageType, nint data0 = 0, nint data1 = 0, nint data2 = 0, nint data3 = 0, nint data4 = 0) { var clientEvent = new XClientMessageEvent { type = ClientMessage, send_event = True, display = display, window = eventWindow, message_type = messageType, format = 32 }; clientEvent.data.l[0] = data0; clientEvent.data.l[1] = data1; clientEvent.data.l[2] = data2; clientEvent.data.l[3] = data3; clientEvent.data.l[4] = data4; ThrowForLastErrorIfZero(XSendEvent( display, targetWindow, False, eventMask, (XEvent *)&clientEvent ), nameof(XSendEvent)); }
private FilterReturn ManagerFilter(IntPtr xevent, Event evnt) { XAnyEvent xev = (XAnyEvent)Marshal.PtrToStructure(xevent, typeof(XAnyEvent)); if (xev.type == XEventName.ClientMessage) { XClientMessageEvent xclient = (XClientMessageEvent)Marshal.PtrToStructure(xevent, typeof(XClientMessageEvent)); if (xclient.message_type == manager_atom && xclient.data.ptr2 == selection_atom) { UpdateManagerWindow(true); return(FilterReturn.Continue); } } if (xev.window == manager_window) { if (xev.type == XEventName.PropertyNotify) { XPropertyEvent xproperty = (XPropertyEvent)Marshal.PtrToStructure(xevent, typeof(XPropertyEvent)); if (xproperty.atom == orientation_atom) { GetOrientationProperty(); return(FilterReturn.Continue); } } if (xev.type == XEventName.DestroyNotify) { ManagerWindowDestroyed(); } } return(FilterReturn.Continue); }
public uint SendMessage (uint timeout, string message) { if (manager_window == IntPtr.Zero) { return 0; } SendManagerMessage (SystemTrayMessage.BeginMessage, (IntPtr) Id, timeout, (uint) message.Length, ++stamp); gdk_error_trap_push (); for (int index = 0; index < message.Length; index += 20) { XClientMessageEvent ev = new XClientMessageEvent (); IntPtr display = gdk_x11_display_get_xdisplay (Display.Handle); ev.type = XEventName.ClientMessage; ev.window = (IntPtr) Id; ev.format = 8; ev.message_type = (IntPtr) XInternAtom (display, "_NET_SYSTEM_TRAY_MESSAGE_DATA", false); byte [] arr = System.Text.Encoding.UTF8.GetBytes (message.Substring (index)); int len = Math.Min (arr.Length, 20); Marshal.Copy (arr, 0, ev.data.ptr1, len); XSendEvent (display, manager_window, false, EventMask.StructureNotifyMask, ref ev); XSync (display, false); } gdk_error_trap_pop (); return stamp; }
public uint SendMessage (uint timeout, string message) { if (manager_window == IntPtr.Zero) { return 0; } byte[] arr = System.Text.Encoding.UTF8.GetBytes (message); IntPtr unmanaged_arr = Marshal.AllocHGlobal (arr.Length); Marshal.Copy (arr, 0, unmanaged_arr, arr.Length); SendManagerMessage (SystemTrayMessage.BeginMessage, (IntPtr) Id, timeout, (uint) arr.Length, ++stamp); gdk_error_trap_push (); for (int index = 0; index < message.Length; index += 20) { XClientMessageEvent ev = new XClientMessageEvent (); IntPtr display = gdk_x11_display_get_xdisplay (Display.Handle); ev.type = XEventName.ClientMessage; ev.window = (IntPtr) Id; ev.format = 8; ev.message_type = message_data_atom; int len = Math.Min (arr.Length - index, 20); memcpy (ref ev.data, (IntPtr)((int)unmanaged_arr + index), (IntPtr)len); XSendEvent (display, manager_window, false, (IntPtr) EventMask.StructureNotifyMask, ref ev); XSync (display, false); } gdk_error_trap_pop (); return stamp; }
public override void Close() { XClientMessageEvent ev = new XClientMessageEvent(); ev.type = (int)Event.ClientMessage; ev.window = _window; ev.message_type = XInternAtom(_display, "WM_PROTOCOLS", true); ev.format = 32; ev.l0 = XInternAtom(_display, "WM_DELETE_WINDOW", false); ev.l1 = IntPtr.Zero; // CurrentTime XSendEvent(_display, _window, false, EventMask.NoEventMask, ref ev); }
private void SendManagerMessage(SystemTrayMessage message, IntPtr window, uint data1, uint data2, uint data3) { XClientMessageEvent ev = new XClientMessageEvent(); IntPtr display; ev.type = XEventName.ClientMessage; ev.window = window; ev.message_type = system_tray_opcode_atom; ev.format = 32; ev.data.ptr1 = (IntPtr)gdk_x11_get_server_time(GdkWindow.Handle); ev.data.ptr2 = (IntPtr)message; ev.data.ptr3 = (IntPtr)data1; ev.data.ptr4 = (IntPtr)data2; ev.data.ptr5 = (IntPtr)data3; display = gdk_x11_display_get_xdisplay(Display.Handle); gdk_error_trap_push(); XSendEvent(display, manager_window, false, (IntPtr)EventMask.NoEventMask, ref ev); XSync(display, false); gdk_error_trap_pop(); }
public static void SendClientMessage(UIntPtr display, UIntPtr window, UIntPtr messageType, UIntPtr message, IntPtr data = default) { var clientEvent = new XClientMessageEvent { type = ClientMessage, serial = UIntPtr.Zero, send_event = True, display = display, window = window, message_type = messageType, format = 32 }; if (Environment.Is64BitProcess) { var messageBits = message.ToUInt64(); clientEvent.data.l[0] = unchecked ((IntPtr)(uint)messageBits); clientEvent.data.l[1] = (IntPtr)(uint)(messageBits >> 32); Assert(clientEvent.data.l[1] == IntPtr.Zero, Resources.ArgumentOutOfRangeExceptionMessage, nameof(message), message); var dataBits = data.ToInt64(); clientEvent.data.l[2] = unchecked ((IntPtr)(uint)dataBits); clientEvent.data.l[3] = (IntPtr)(uint)(dataBits >> 32); } else { var messageBits = message.ToUInt32(); clientEvent.data.l[0] = (IntPtr)messageBits; var dataBits = data.ToInt32(); clientEvent.data.l[1] = (IntPtr)dataBits; } ThrowExternalExceptionIfZero(nameof(XSendEvent), XSendEvent( clientEvent.display, clientEvent.window, propagate: False, (IntPtr)NoEventMask, (XEvent *)&clientEvent )); }
public uint SendMessage(uint timeout, string message) { if (manager_window == IntPtr.Zero) { return(0); } byte[] arr = System.Text.Encoding.UTF8.GetBytes(message); IntPtr unmanaged_arr = Marshal.AllocHGlobal(arr.Length); Marshal.Copy(arr, 0, unmanaged_arr, arr.Length); SendManagerMessage(SystemTrayMessage.BeginMessage, (IntPtr)Id, timeout, (uint)arr.Length, ++stamp); gdk_error_trap_push(); for (int index = 0; index < message.Length; index += 20) { XClientMessageEvent ev = new XClientMessageEvent(); IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle); ev.type = XEventName.ClientMessage; ev.window = (IntPtr)Id; ev.format = 8; ev.message_type = message_data_atom; int len = Math.Min(arr.Length - index, 20); memcpy(ref ev.data, (IntPtr)((int)unmanaged_arr + index), (IntPtr)len); XSendEvent(display, manager_window, false, (IntPtr)EventMask.StructureNotifyMask, ref ev); XSync(display, false); } gdk_error_trap_pop(); return(stamp); }
private static extern IntPtr memcpy (ref XClientMessageEvent.DataUnion dest, IntPtr src, IntPtr len);
private extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, IntPtr event_mask, ref XClientMessageEvent send_event);
/// <summary> Initializing constructor. </summary> /// <param name="evt"> The event to wrap. <see cref="XClientMessageEvent"/> </param> public XrwClientMessageEvent(ref XClientMessageEvent evt) { Event = evt; }
static extern int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XClientMessageEvent send_event);
public static extern Status XSendEvent(IntPtr display, IntPtr windoe, bool propagate, EventMask event_mask, ref XClientMessageEvent event_send);
public override void EnterMessageLoop(bool runInBackground) { IntPtr wmDeleteWindow = XInternAtom(_display, "WM_DELETE_WINDOW", false); XSetWMProtocols(_display, _window, new IntPtr[] { wmDeleteWindow }, 1); IntPtr e = System.Runtime.InteropServices.Marshal.AllocHGlobal(24 * sizeof(long)); bool running = true; while (running) { while (XPending(_display) != 0) { XNextEvent(_display, e); if (XFilterEvent(e, IntPtr.Zero)) { continue; } XAnyEvent anyEvent = (XAnyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XAnyEvent)); switch ((Event)anyEvent.type) { case Event.ClientMessage: { XClientMessageEvent clientEvent = (XClientMessageEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XClientMessageEvent)); if (clientEvent.l0 == wmDeleteWindow) { bool cancel = false; Closing?.Invoke(this, ref cancel); if (!cancel) { Closed?.Invoke(this); running = false; } } break; } case Event.ConfigureNotify: { XConfigureEvent configureEvent = (XConfigureEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XConfigureEvent)); LocationChanged?.Invoke(this, configureEvent.x, configureEvent.y); SizeChanged?.Invoke(this, configureEvent.width, configureEvent.height); break; } case Event.FocusIn: { Activated?.Invoke(this); break; } case Event.FocusOut: { Deactivated?.Invoke(this); break; } case Event.MotionNotify: { XMotionEvent motionEvent = (XMotionEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XMotionEvent)); MouseMove?.Invoke(this, motionEvent.x, motionEvent.y); break; } case Event.ButtonPress: { XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent)); switch ((Button)buttonEvent.button) { case Button.Button1: { MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left); break; } case Button.Button2: { MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle); break; } case Button.Button3: { MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right); break; } case Button.Button4: { MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, 120); break; } case Button.Button5: { MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, -120); break; } } break; } case Event.ButtonRelease: { XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent)); switch ((Button)buttonEvent.button) { case Button.Button1: { MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left); break; } case Button.Button2: { MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle); break; } case Button.Button3: { MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right); break; } } break; } case Event.KeyPress: { XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent)); KeySym ks = XLookupKeysym(ref keyEvent, 0); Key key = NoesisKey(ks); if (key != Key.None) { KeyDown?.Invoke(this, key); } if (_xic != IntPtr.Zero) { Status status = 0; byte[] buffer = new byte[256]; KeySym ret_ks = (KeySym)0; int size = Xutf8LookupString(_xic, e, buffer, 255, ref ret_ks, ref status); if (size > 0 && ((int)status == XLookupChars || (int)status == XLookupBoth)) { buffer[size] = 0; Decoder decoder = _utf8.GetDecoder(); char[] text = new char[256]; int bytesUsed = 0; int charsUsed = 0; bool completed = false; decoder.Convert(buffer, 0, size, text, 0, 255, true, out bytesUsed, out charsUsed, out completed); for (int i = 0; i < charsUsed; ++i) { Char?.Invoke(this, text[i]); } } } break; } case Event.KeyRelease: { XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent)); KeySym ks = XLookupKeysym(ref keyEvent, 0); Key key = NoesisKey(ks); if (key != Key.None) { KeyUp?.Invoke(this, key); } break; } } } Render?.Invoke(this); } System.Runtime.InteropServices.Marshal.FreeHGlobal(e); XCloseDisplay(_display); }
private void SendManagerMessage (SystemTrayMessage message, IntPtr window, uint data1, uint data2, uint data3) { XClientMessageEvent ev = new XClientMessageEvent (); IntPtr display; ev.type = XEventName.ClientMessage; ev.window = window; ev.message_type = system_tray_opcode_atom; ev.format = 32; ev.data.ptr1 = (IntPtr)gdk_x11_get_server_time (GdkWindow.Handle); ev.data.ptr2 = (IntPtr)message; ev.data.ptr3 = (IntPtr)data1; ev.data.ptr4 = (IntPtr)data2; ev.data.ptr5 = (IntPtr)data3; display = gdk_x11_display_get_xdisplay (Display.Handle); gdk_error_trap_push (); XSendEvent (display, manager_window, false, (IntPtr) EventMask.NoEventMask, ref ev); XSync (display, false); gdk_error_trap_pop (); }
public RCode HandleSystemEvent() { while (Xlib.XPending(display) > 0) { Xlib.XNextEvent(display, ev); XAnyEvent xevent = Marshal.PtrToStructure <XAnyEvent>(ev); switch (xevent.type) { case (int)Event.ClientMessage: XClientMessageEvent xClientMessageEvent = Marshal.PtrToStructure <XClientMessageEvent>(ev); if (xClientMessageEvent.data == (IntPtr)deleteWindowMessage) { PixelGameEngine.Instance.Terminate(); } break; case (int)Event.KeyPress: case (int)Event.KeyRelease: XKeyEvent xKeyEvent = Marshal.PtrToStructure <XKeyEvent>(ev); KeySym sym = XlibExt.XLookupKeysym(new XKeyEvent[] { xKeyEvent }, 0); pge.Input.UpdateKeyState((int)mapKeys[(long)sym], xevent.type == (int)Event.KeyPress); break; case (int)Event.ButtonPress: case (int)Event.ButtonRelease: XButtonEvent xButtonEvent = Marshal.PtrToStructure <XButtonEvent>(ev); bool pressed = xevent.type == (int)Event.ButtonPress; switch (xButtonEvent.button) { case 1: case 2: case 3: pge.Input.UpdateMouseState((int)xButtonEvent.button - 1, pressed); break; case 4: pge.Input.UpdateMouseWheel(120); break; case 5: pge.Input.UpdateMouseWheel(-120); break; case 6: case 7: case 8: case 9: pge.Input.UpdateMouseState((int)xButtonEvent.button - 3, pressed); break; } break; case (int)Event.MotionNotify: XMotionEvent xMotionEvent = Marshal.PtrToStructure <XMotionEvent>(ev); pge.Input.UpdateMouse(xMotionEvent.x, xMotionEvent.y); break; case (int)Event.EnterNotify: pge.Input.UpdateMouseFocus(true); break; case (int)Event.LeaveNotify: pge.Input.UpdateMouseFocus(false); break; case (int)Event.FocusIn: pge.Input.UpdateKeyFocus(true); break; case (int)Event.FocusOut: pge.Input.UpdateKeyFocus(false); break; } } return(RCode.OK); }
private static void SendClientMessage(IntPtr display, IntPtr window, string message, int[] data) { EventMask mask = EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask; XClientMessageEvent window_event = new XClientMessageEvent(); window_event.type = EventType.ClientMessage; window_event.serial = 0; window_event.send_event = true; window_event.format = 32; window_event.window = window; window_event.message_type = XInternAtom(display, message, false); window_event.data.l.l0 = data[0]; window_event.data.l.l1 = data[1]; window_event.data.l.l2 = data[2]; window_event.data.l.l3 = data[3]; window_event.data.l.l4 = data[4]; IntPtr rootWindow = GetRootWindow(display); XSendEvent(display, rootWindow, false, mask, ref window_event); }