Skip to content

Commit 14038a1

Browse files
committed
feat: add support for mac and linux
1 parent c323bd3 commit 14038a1

8 files changed

Lines changed: 1601 additions & 190 deletions

File tree

README.md

Lines changed: 275 additions & 30 deletions
Large diffs are not rendered by default.

src/ObsKit.NET/ObsContext.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ private void LoadModulesFromDirectory(string binPath, string dataPathTemplate)
112112
if (!Directory.Exists(binPath))
113113
return;
114114

115-
// Get all DLL files (Windows) or .so files (Linux) in the module directory
116-
var extension = OperatingSystem.IsWindows() ? "*.dll" : "*.so";
115+
// Get all module files based on platform
116+
var extension = OperatingSystem.IsWindows() ? "*.dll" :
117+
OperatingSystem.IsMacOS() ? "*.so" : // macOS OBS plugins use .so, not .dylib
118+
"*.so";
117119
var moduleFiles = Directory.GetFiles(binPath, extension);
118120

119121
foreach (var modulePath in moduleFiles)

src/ObsKit.NET/Platform/Linux/Interop/X11.cs

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace ObsKit.NET.Platform.Linux.Interop;
55

66
/// <summary>
77
/// P/Invoke bindings for X11 functions.
8-
/// Note: These are basic bindings. Full X11 support would require more comprehensive bindings.
98
/// </summary>
109
[SupportedOSPlatform("linux")]
1110
internal static partial class X11
@@ -38,6 +37,58 @@ internal static partial class X11
3837

3938
#endregion
4039

40+
#region Window
41+
42+
[LibraryImport(LibX11, EntryPoint = "XQueryTree")]
43+
internal static partial int XQueryTree(
44+
nint display,
45+
nint window,
46+
out nint rootReturn,
47+
out nint parentReturn,
48+
out nint childrenReturn,
49+
out uint nChildren);
50+
51+
[LibraryImport(LibX11, EntryPoint = "XFree")]
52+
internal static partial int XFree(nint data);
53+
54+
[LibraryImport(LibX11, EntryPoint = "XGetWindowAttributes")]
55+
internal static partial int XGetWindowAttributes(nint display, nint window, out XWindowAttributes attributes);
56+
57+
[LibraryImport(LibX11, EntryPoint = "XFetchName")]
58+
internal static partial int XFetchName(nint display, nint window, out nint windowName);
59+
60+
[LibraryImport(LibX11, EntryPoint = "XGetClassHint")]
61+
internal static partial int XGetClassHint(nint display, nint window, out XClassHint classHint);
62+
63+
[LibraryImport(LibX11, EntryPoint = "XInternAtom", StringMarshalling = StringMarshalling.Utf8)]
64+
internal static partial nint XInternAtom(nint display, string atomName, [MarshalAs(UnmanagedType.Bool)] bool onlyIfExists);
65+
66+
[LibraryImport(LibX11, EntryPoint = "XGetWindowProperty")]
67+
internal static partial int XGetWindowProperty(
68+
nint display,
69+
nint window,
70+
nint property,
71+
long longOffset,
72+
long longLength,
73+
[MarshalAs(UnmanagedType.Bool)] bool delete,
74+
nint reqType,
75+
out nint actualTypeReturn,
76+
out int actualFormatReturn,
77+
out nuint nItemsReturn,
78+
out nuint bytesAfterReturn,
79+
out nint propReturn);
80+
81+
[LibraryImport(LibX11, EntryPoint = "XGetWMName")]
82+
internal static partial int XGetWMName(nint display, nint window, out XTextProperty textProp);
83+
84+
[LibraryImport(LibX11, EntryPoint = "XmbTextPropertyToTextList")]
85+
internal static partial int XmbTextPropertyToTextList(nint display, ref XTextProperty textProp, out nint listReturn, out int countReturn);
86+
87+
[LibraryImport(LibX11, EntryPoint = "XFreeStringList")]
88+
internal static partial void XFreeStringList(nint list);
89+
90+
#endregion
91+
4192
#region XRandR
4293

4394
[LibraryImport(LibXrandr, EntryPoint = "XRRGetScreenResources")]
@@ -112,5 +163,55 @@ internal struct XRRCrtcInfo
112163
public nint possible;
113164
}
114165

166+
[StructLayout(LayoutKind.Sequential)]
167+
internal struct XWindowAttributes
168+
{
169+
public int x, y;
170+
public int width, height;
171+
public int border_width;
172+
public int depth;
173+
public nint visual;
174+
public nint root;
175+
public int c_class;
176+
public int bit_gravity;
177+
public int win_gravity;
178+
public int backing_store;
179+
public nuint backing_planes;
180+
public nuint backing_pixel;
181+
public int save_under;
182+
public nint colormap;
183+
public int map_installed;
184+
public int map_state;
185+
public nint all_event_masks;
186+
public nint your_event_mask;
187+
public nint do_not_propagate_mask;
188+
public int override_redirect;
189+
public nint screen;
190+
}
191+
192+
[StructLayout(LayoutKind.Sequential)]
193+
internal struct XClassHint
194+
{
195+
public nint res_name;
196+
public nint res_class;
197+
}
198+
199+
[StructLayout(LayoutKind.Sequential)]
200+
internal struct XTextProperty
201+
{
202+
public nint value;
203+
public nint encoding;
204+
public int format;
205+
public nuint nitems;
206+
}
207+
208+
// Map state constants
209+
internal const int IsUnmapped = 0;
210+
internal const int IsUnviewable = 1;
211+
internal const int IsViewable = 2;
212+
213+
// Atom constants
214+
internal static readonly nint AnyPropertyType = 0;
215+
115216
#endregion
116217
}

0 commit comments

Comments
 (0)