Browse Source

Merge pull request #4049 from IllusionMan1212/xrandr-xinput-xfixes

vendor/x11: added a few procedures for xrandr, xinput, and xfixes
gingerBill 1 year ago
parent
commit
d93364ce52
3 changed files with 234 additions and 5 deletions
  1. 5 0
      vendor/x11/xlib/xlib_const.odin
  2. 41 5
      vendor/x11/xlib/xlib_procs.odin
  3. 188 0
      vendor/x11/xlib/xlib_types.odin

+ 5 - 0
vendor/x11/xlib/xlib_const.odin

@@ -72,6 +72,11 @@ XkbAllEventsMask :: XkbEventMask {
 	.ExtensionDeviceNotify,
 }
 
+/* ----  X11/extensions/XI2.h ---------------------------------------------------------*/
+
+XIAllDevices :: 0
+XIAllMasterDevices :: 1
+
 
 /* ----  X11/Xlib.h ---------------------------------------------------------*/
 

+ 41 - 5
vendor/x11/xlib/xlib_procs.odin

@@ -9,13 +9,49 @@ foreign xlib {
 foreign import xcursor "system:Xcursor"
 @(default_calling_convention="c", link_prefix="X")
 foreign xcursor {
-	cursorGetTheme         :: proc(display: ^Display) -> cstring ---
-	cursorGetDefaultSize   :: proc(display: ^Display) -> i32 ---
-	cursorLibraryLoadImage :: proc(name: cstring, theme: cstring, size: i32) -> rawptr ---
-	cursorImageLoadCursor  :: proc(display: ^Display, img: rawptr) -> Cursor ---
-	cursorImageDestroy     :: proc(img: rawptr) ---
+	cursorGetTheme          :: proc(display: ^Display) -> cstring ---
+	cursorGetDefaultSize    :: proc(display: ^Display) -> i32 ---
+	cursorLibraryLoadCursor :: proc(display: ^Display, name: cstring) -> Cursor ---
+	cursorLibraryLoadImage  :: proc(name: cstring, theme: cstring, size: i32) -> rawptr ---
+	cursorImageLoadCursor   :: proc(display: ^Display, img: rawptr) -> Cursor ---
+	cursorImageDestroy      :: proc(img: rawptr) ---
 }
 
+foreign import xfixes "system:Xfixes"
+@(default_calling_convention="c", link_prefix="XFixes")
+foreign xfixes {
+	HideCursor :: proc(display: ^Display, window: Window) ---
+	ShowCursor :: proc(display: ^Display, window: Window) ---
+}
+
+foreign import xrandr "system:Xrandr"
+@(default_calling_convention="c")
+foreign xrandr {
+	XRRSizes :: proc(display: ^Display, screen: i32, nsizes: ^i32) -> [^]XRRScreenSize ---
+	XRRGetScreenResources :: proc(display: ^Display, window: Window) -> ^XRRScreenResources ---
+	XRRFreeScreenResources :: proc(resources: ^XRRScreenResources) ---
+	XRRGetOutputInfo :: proc(display: ^Display, resources: ^XRRScreenResources, output: RROutput) -> ^XRROutputInfo ---
+	XRRFreeOutputInfo :: proc(output_info: ^XRROutputInfo) ---
+	XRRGetCrtcInfo :: proc(display: ^Display, resources: ^XRRScreenResources, crtc: RRCrtc) -> ^XRRCrtcInfo ---
+	XRRFreeCrtcInfo :: proc(crtc_info: ^XRRCrtcInfo) ---
+	XRRGetMonitors :: proc(dpy: ^Display, window: Window, get_active: b32, nmonitors: ^i32) -> [^]XRRMonitorInfo ---
+}
+
+foreign import xinput "system:Xi"
+foreign xinput {
+	XISelectEvents :: proc(display: ^Display, window: Window, masks: [^]XIEventMask, num_masks: i32) -> i32 ---
+	XIQueryVersion :: proc(display: ^Display, major: ^i32, minor: ^i32) -> Status ---
+}
+
+XISetMask :: proc(ptr: [^]u8, event: XIEventType) {
+	ptr[cast(i32)event >> 3] |= (1 << cast(uint)((cast(i32)event) & 7))
+}
+
+XIMaskIsSet :: proc(ptr: [^]u8, event: i32) -> bool {
+	return (ptr[event >> 3] & (1 << cast(uint)((event) & 7))) != 0
+}
+
+
 /* ----  X11/Xlib.h ---------------------------------------------------------*/
 
 @(default_calling_convention="c", link_prefix="X")

+ 188 - 0
vendor/x11/xlib/xlib_types.odin

@@ -26,6 +26,7 @@ GContext :: XID
 
 RRCrtc   :: XID
 RROutput :: XID
+RRMode   :: XID
 
 KeyCode  :: u8
 
@@ -2069,3 +2070,190 @@ XrmOptionDescRec :: struct {
 }
 
 XrmOptionDescList :: [^]XrmOptionDescRec
+
+/* ----  X11/extensions/Xrandr.h ---------------------------------------------------------*/
+
+XRRModeFlags :: bit_set[XRRModeBits;u64]
+XRRModeBits :: enum u8 {
+	RR_HSyncPositive  = 0,
+	RR_HSyncNegative  = 1,
+	RR_VSyncPositive  = 2,
+	RR_VSyncNegative  = 3,
+	RR_Interlace      = 4,
+	RR_DoubleScan     = 5,
+	RR_CSync          = 6,
+	RR_CSyncPositive  = 7,
+	RR_CSyncNegative  = 8,
+	RR_HSkewPresent   = 9,
+	RR_BCast          = 10,
+	RR_PixelMultiplex = 11,
+	RR_DoubleClock    = 12,
+	RR_ClockDivideBy2 = 13,
+}
+
+Rotation :: enum u16 {
+	Rotate_0 = 1,
+	Rotate_90 = 2,
+	Rotate_180 = 4,
+	Rotate_270 = 8,
+}
+
+Connection :: enum u16 {
+	RR_Connected         = 0,
+	RR_Disconnected      = 1,
+	RR_UnknownConnection = 2,
+}
+
+SubpixelOrder :: enum u16 {
+	Unknown = 0,
+	HorizontalRGB = 1,
+	HorizontalBGR = 2,
+	VerticalRGB = 3,
+	VerticalBGR = 4,
+	None = 5,
+}
+
+XRRModeInfo :: struct {
+	id:         RRMode,
+	width:      u32,
+	height:     u32,
+	dotClock:   u64,
+	hSyncStart: u32,
+	hSyncEnd:   u32,
+	hTotal:     u32,
+	hSkew:      u32,
+	vSyncStart: u32,
+	vSyncEnd:   u32,
+	vTotal:     u32,
+	name:       cstring,
+	nameLength: u32,
+	modeFlags:  XRRModeFlags,
+}
+
+XRRScreenSize :: struct {
+	width, height:   i32,
+	mwidth, mheight: i32,
+}
+
+XRRScreenResources :: struct {
+	timestamp:       Time,
+	configTimestamp: Time,
+	ncrtc:           i32,
+	crtcs:           [^]RRCrtc,
+	noutput:         i32,
+	outputs:         [^]RROutput,
+	nmode:           i32,
+	modes:           [^]XRRModeInfo,
+}
+
+XRROutputInfo :: struct {
+	timestamp:      Time,
+	crtc:           RRCrtc,
+	name:           cstring,
+	nameLen:        i32,
+	mm_width:       u64,
+	mm_height:      u64,
+	connection:     Connection,
+	subpixel_order: SubpixelOrder,
+	ncrtc:          i32,
+	crtcs:          [^]RRCrtc,
+	nclone:         i32,
+	clones:         [^]RROutput,
+	nmode:          i32,
+	npreferred:     i32,
+	modes:          [^]RRMode,
+}
+
+XRRCrtcInfo :: struct {
+	timestamp:     Time,
+	x, y:          i32,
+	width, height: u32,
+	mode:          RRMode,
+	rotation:      Rotation,
+	noutput:       i32,
+	outputs:       [^]RROutput,
+	rotations:     Rotation,
+	npossible:     i32,
+	possible:      [^]RROutput,
+}
+
+XRRMonitorInfo :: struct {
+	name: Atom,
+	primary: b32,
+	automatic: b32,
+	noutput: i32,
+	x: i32,
+	y: i32,
+	width: i32,
+	height: i32,
+	mwidth: i32,
+	mheight: i32,
+	outputs: [^]RROutput,
+}
+
+/* ----  X11/extensions/XInput2.h ---------------------------------------------------------*/
+
+XIEventType :: enum i32 {
+	DeviceChanged = 1,
+	KeyPress,
+	KeyRelease,
+	ButtonPress,
+	ButtonRelease,
+	Motion,
+	Enter,
+	Leave,
+	FocusIn,
+	FocusOut,
+	HierarchyChanged,
+	Property,
+	RawKeyPress,
+	RawKeyRelease,
+	RawButtonPress,
+	RawButtonRelease,
+	RawMotion,
+	TouchBegin,
+	TouchUpdate,
+	TouchEnd,
+	TouchOwnership,
+	RawTouchBegin,
+	RawTouchUpdate,
+	RawTouchEnd,
+	BarrierHit,
+	BarrierLeave,
+	GesturePinchBegin,
+	GesturePinchUpdate,
+	GesturePinchEnd,
+	GestureSwipeBegin,
+	GestureSwipeUpdate,
+	GestureSwipeEnd,
+	LastEvent = GestureSwipeEnd,
+}
+
+XIEventMask :: struct {
+	deviceid: i32,
+	mask_len: i32,
+	mask:     [^]u8,
+}
+
+XIValuatorState :: struct {
+	mask_len: i32,
+	mask:     [^]u8,
+	values:   [^]f64,
+}
+
+XIRawEvent :: struct {
+	type:       EventType,
+	serial:     u64,
+	send_event: b32,
+	display:    ^Display,
+	extension:  i32,
+	evtype:     XIEventType,
+	time:       Time,
+	deviceid:   i32,
+	sourceid:   i32,
+	detail:     i32,
+	flags:      i32,
+	valuators:  XIValuatorState,
+	raw_values: [^]f64,
+}
+