You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
4.1 KiB
155 lines
4.1 KiB
using System.Runtime.InteropServices;
|
|
|
|
namespace EC.Util.Platform;
|
|
|
|
public static class LinuxUtil
|
|
{
|
|
#region const
|
|
|
|
private const string libX11 = "libX11.so.6";
|
|
private const string libX11Randr = "libXrandr.so.2";
|
|
private const string libX11Ext = "libXext.so.6";
|
|
private const string libXInput = "libXi.so.6";
|
|
private const string libXCursor = "libXcursor.so.1";
|
|
|
|
private enum PropertyMode
|
|
{
|
|
Replace = 0,
|
|
Prepend = 1,
|
|
Append = 2
|
|
}
|
|
|
|
[Flags]
|
|
private enum MotifFlags
|
|
{
|
|
Functions = 1,
|
|
Decorations = 2,
|
|
InputMode = 4,
|
|
Status = 8
|
|
}
|
|
|
|
[Flags]
|
|
private enum MotifFunctions
|
|
{
|
|
All = 0x01,
|
|
Resize = 0x02,
|
|
Move = 0x04,
|
|
Minimize = 0x08,
|
|
Maximize = 0x10,
|
|
Close = 0x20
|
|
}
|
|
|
|
[Flags]
|
|
private enum MotifDecorations
|
|
{
|
|
All = 0x01,
|
|
Border = 0x02,
|
|
ResizeH = 0x04,
|
|
Title = 0x08,
|
|
Menu = 0x10,
|
|
Minimize = 0x20,
|
|
Maximize = 0x40,
|
|
}
|
|
|
|
[Flags]
|
|
private enum MotifInputMode
|
|
{
|
|
Modeless = 0,
|
|
ApplicationModal = 1,
|
|
SystemModal = 2,
|
|
FullApplicationModal = 3
|
|
}
|
|
|
|
#endregion const
|
|
|
|
#region struct
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
private struct MotifWmHints
|
|
{
|
|
public IntPtr flags;
|
|
public IntPtr functions;
|
|
public IntPtr decorations;
|
|
public IntPtr input_mode;
|
|
public IntPtr status;
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("MotifWmHints <flags={0}, functions={1}, decorations={2}, input_mode={3}, status={4}", (MotifFlags)flags.ToInt32(), (MotifFunctions)functions.ToInt32(), (MotifDecorations)decorations.ToInt32(), (MotifInputMode)input_mode.ToInt32(), status.ToInt32());
|
|
}
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
private struct XSizeHints
|
|
{
|
|
private IntPtr flags;
|
|
private int x;
|
|
private int y;
|
|
private int width;
|
|
private int height;
|
|
private int min_width;
|
|
private int min_height;
|
|
private int max_width;
|
|
private int max_height;
|
|
private int width_inc;
|
|
private int height_inc;
|
|
private int min_aspect_x;
|
|
private int min_aspect_y;
|
|
private int max_aspect_x;
|
|
private int max_aspect_y;
|
|
private int base_width;
|
|
private int base_height;
|
|
private int win_gravity;
|
|
}
|
|
|
|
[Flags]
|
|
private enum XSizeHintsFlags
|
|
{
|
|
USPosition = (1 << 0),
|
|
USSize = (1 << 1),
|
|
PPosition = (1 << 2),
|
|
PSize = (1 << 3),
|
|
PMinSize = (1 << 4),
|
|
PMaxSize = (1 << 5),
|
|
PResizeInc = (1 << 6),
|
|
PAspect = (1 << 7),
|
|
PAllHints = (PPosition | PSize | PMinSize | PMaxSize | PResizeInc | PAspect),
|
|
PBaseSize = (1 << 8),
|
|
PWinGravity = (1 << 9),
|
|
}
|
|
|
|
#endregion struct
|
|
|
|
#region lib
|
|
|
|
[DllImport(libX11, CharSet = CharSet.Unicode)]
|
|
private static extern IntPtr XInternAtom(IntPtr display, string atom_name, bool only_if_exists);
|
|
|
|
[DllImport(libX11)]
|
|
private static extern int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type,
|
|
int format, PropertyMode mode, ref MotifWmHints data, int nelements);
|
|
|
|
[DllImport(libX11)]
|
|
private static extern void XSetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints);
|
|
|
|
#endregion lib
|
|
|
|
#region cmd
|
|
|
|
public static void DisableMinMaximizeButton(IntPtr display, IntPtr handle, IntPtr atom)
|
|
{
|
|
MotifDecorations decorations = MotifDecorations.Title | MotifDecorations.Border;
|
|
MotifFunctions functions = MotifFunctions.Move | MotifFunctions.Close;
|
|
MotifWmHints hints = new()
|
|
{
|
|
flags = (nint)(MotifFlags.Decorations | MotifFlags.Functions),
|
|
decorations = (nint)decorations,
|
|
functions = (nint)functions,
|
|
input_mode = 0,
|
|
status = 0,
|
|
};
|
|
int result = XChangeProperty(display, handle, atom, atom, 32, PropertyMode.Replace, ref hints, 5);
|
|
}
|
|
|
|
#endregion cmd
|
|
}
|