1// x11-rs: Rust bindings for X11 libraries
2// The X11 libraries are available under the MIT license.
3// These bindings are public domain.
4
5use std::os::raw::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong};
6
7use crate::xlib::{Bool, Display, Drawable, Status, Time, XID};
8
9//
10// functions
11//
12
13x11_link! { Xext, xext, ["libXext.so.6", "libXext.so"], 38,
14 pub fn XSyncQueryExtension(dpy: *mut Display, event_base: *mut c_int, error_base: *mut c_int) -> Status,
15 pub fn XSyncInitialize(dpy: *mut Display, major_version: *mut c_int, minor_version: *mut c_int) -> Status,
16 pub fn XSyncListSystemCounters(dpy: *mut Display, n_counters: *mut c_int) -> *mut XSyncSystemCounter,
17 pub fn XSyncFreeSystemCounterList(list: *mut XSyncSystemCounter) -> (),
18 pub fn XSyncCreateCounter(dpy: *mut Display, initial_value: XSyncValue) -> XSyncCounter,
19 pub fn XSyncSetCounter(dpy: *mut Display, counter: XSyncCounter, value: XSyncValue) -> Status,
20 pub fn XSyncChangeCounter(dpy: *mut Display, counter: XSyncCounter, value: XSyncValue) -> Status,
21 pub fn XSyncDestroyCounter(dpy: *mut Display, value: XSyncCounter) -> Status,
22 pub fn XSyncQueryCounter(dpy: *mut Display, counter: XSyncCounter, value: *mut XSyncValue) -> Status,
23 pub fn XSyncAwait(dpy: *mut Display, wait_list: *mut XSyncWaitCondition, n_conditions: c_int) -> Status,
24 pub fn XSyncCreateAlarm(dpy: *mut Display, values_mask: c_ulong, values: *mut XSyncAlarmAttributes) -> XSyncAlarm,
25 pub fn XSyncDestroyAlarm(dpy: *mut Display, alarm: XSyncAlarm) -> Status,
26 pub fn XSyncQueryAlarm(dpy: *mut Display, alarm: XSyncAlarm, values: *mut XSyncAlarmAttributes) -> Status,
27 pub fn XSyncChangeAlarm(dpy: *mut Display, alarm: XSyncAlarm, values_mask: c_ulong, values: *mut XSyncAlarmAttributes) -> Status,
28 pub fn XSyncSetPriority(dpy: *mut Display, client_resource_id: XID, priority: c_int) -> Status,
29 pub fn XSyncGetPriority(dpy: *mut Display, client_resource_id: XID, priority: *mut c_int) -> Status,
30 pub fn XSyncCreateFence(dpy: *mut Display, d: Drawable, initially_triggered: Bool) -> XSyncFence,
31 pub fn XSyncTriggerFence(dpy: *mut Display, fence: XSyncFence) -> Bool,
32 pub fn XSyncResetFence(dpy: *mut Display, fence: XSyncFence) -> Bool,
33 pub fn XSyncDestroyFence(dpy: *mut Display, fence: XSyncFence) -> Bool,
34 pub fn XSyncQueryFence(dpy: *mut Display, fence: XSyncFence, triggered: *mut Bool) -> Bool,
35 pub fn XSyncAwaitFence(dpy: *mut Display, fence_list: *const XSyncFence, n_fences: c_int) -> Bool,
36 pub fn XSyncIntToValue(pv: *mut XSyncValue, i: c_int) -> (),
37 pub fn XSyncIntsToValue(pv: *mut XSyncValue, l: c_uint, h: c_int) -> (),
38 pub fn XSyncValueGreaterThan(a: XSyncValue, b: XSyncValue) -> Bool,
39 pub fn XSyncValueLessThan(a: XSyncValue, b: XSyncValue) -> Bool,
40 pub fn XSyncValueGreaterOrEqual(a: XSyncValue, b: XSyncValue) -> Bool,
41 pub fn XSyncValueLessOrEqual(a: XSyncValue, b: XSyncValue) -> Bool,
42 pub fn XSyncValueEqual(a: XSyncValue, b: XSyncValue) -> Bool,
43 pub fn XSyncValueIsNegative(v: XSyncValue) -> Bool,
44 pub fn XSyncValueIsZero(v: XSyncValue) -> Bool,
45 pub fn XSyncValueIsPositive(v: XSyncValue) -> Bool,
46 pub fn XSyncValueLow32(v: XSyncValue) -> c_uint,
47 pub fn XSyncValueHigh32(v: XSyncValue) -> c_int,
48 pub fn XSyncValueAdd(presult: *mut XSyncValue, a: XSyncValue, b: XSyncValue, poverflow: *mut c_int) -> (),
49 pub fn XSyncValueSubtract(presult: *mut XSyncValue, a: XSyncValue, b: XSyncValue, poverflow: *mut c_int) -> (),
50 pub fn XSyncMaxValue(pv: *mut XSyncValue) -> (),
51 pub fn XSyncMinValue(pv: *mut XSyncValue) -> (),
52variadic:
53globals:
54}
55
56//
57// types
58//
59
60pub type XSyncValueType = c_uint;
61pub type XSyncTestType = c_uint;
62pub type XSyncAlarmState = c_uint;
63pub type XSyncCounter = XID;
64pub type XSyncAlarm = XID;
65pub type XSyncFence = XID;
66
67#[repr(C)]
68#[derive(Debug, Copy, Clone)]
69pub struct XSyncAlarmError {
70 pub type_: c_int,
71 pub display: *mut Display,
72 pub alarm: XSyncAlarm,
73 pub serial: c_ulong,
74 pub error_code: c_uchar,
75 pub request_code: c_uchar,
76 pub minor_code: c_uchar,
77}
78#[repr(C)]
79#[derive(Debug, Copy, Clone)]
80pub struct XSyncCounterError {
81 pub type_: c_int,
82 pub display: *mut Display,
83 pub counter: XSyncCounter,
84 pub serial: c_ulong,
85 pub error_code: c_uchar,
86 pub request_code: c_uchar,
87 pub minor_code: c_uchar,
88}
89
90#[repr(C)]
91#[derive(Debug, Copy, Clone)]
92pub struct XSyncValue {
93 pub hi: c_int,
94 pub lo: c_uint,
95}
96
97#[repr(C)]
98#[derive(Debug, Copy, Clone)]
99pub struct XSyncTrigger {
100 pub counter: XSyncCounter,
101 pub value_type: XSyncValueType,
102 pub wait_value: XSyncValue,
103 pub test_type: XSyncTestType,
104}
105#[repr(C)]
106#[derive(Debug, Copy, Clone)]
107pub struct XSyncWaitCondition {
108 pub trigger: XSyncTrigger,
109 pub event_threshold: XSyncValue,
110}
111#[repr(C)]
112#[derive(Debug, Copy, Clone)]
113pub struct XSyncAlarmAttributes {
114 pub trigger: XSyncTrigger,
115 pub delta: XSyncValue,
116 pub events: Bool,
117 pub state: XSyncAlarmState,
118}
119#[repr(C)]
120#[derive(Debug, Copy, Clone)]
121pub struct XSyncCounterNotifyEvent {
122 pub type_: c_int,
123 pub serial: c_ulong,
124 pub send_event: Bool,
125 pub display: *mut Display,
126 pub counter: XSyncCounter,
127 pub wait_value: XSyncValue,
128 pub counter_value: XSyncValue,
129 pub time: Time,
130 pub count: c_int,
131 pub destroyed: Bool,
132}
133#[repr(C)]
134#[derive(Debug, Copy, Clone)]
135pub struct XSyncAlarmNotifyEvent {
136 pub type_: c_int,
137 pub serial: c_ulong,
138 pub send_event: Bool,
139 pub display: *mut Display,
140 pub alarm: XSyncAlarm,
141 pub counter_value: XSyncValue,
142 pub alarm_value: XSyncValue,
143 pub time: Time,
144 pub state: XSyncAlarmState,
145}
146
147#[repr(C)]
148#[derive(Debug, Copy, Clone)]
149pub struct XSyncSystemCounter {
150 pub name: *mut c_char,
151 pub counter: XSyncCounter,
152 pub resolution: XSyncValue,
153}
154
155//
156// constants
157//
158
159pub const SYNC_NAME: &str = "SYNC";
160
161pub const SYNC_MAJOR_VERSION: c_int = 3;
162pub const SYNC_MINOR_VERSION: c_int = 1;
163
164pub const XSyncCounterNotify: c_long = 0;
165pub const XSyncAlarmNotify: c_long = 1;
166pub const XSyncAlarmNotifyMask: c_long = 1 << XSyncAlarmNotify;
167
168pub const XSyncNumberEvents: c_long = 2;
169
170pub const XSyncBadCounter: c_long = 0;
171pub const XSyncBadAlarm: c_long = 1;
172pub const XSyncBadFence: c_long = 2;
173pub const XSyncNumberErrors: c_long = XSyncBadFence + 1;
174
175pub const XSyncCACounter: c_long = 1 << 0;
176pub const XSyncCAValueType: c_long = 1 << 1;
177pub const XSyncCAValue: c_long = 1 << 2;
178pub const XSyncCATestType: c_long = 1 << 3;
179pub const XSyncCADelta: c_long = 1 << 4;
180pub const XSyncCAEvents: c_long = 1 << 5;
181
182pub const XSyncValueType_XSyncAbsolute: XSyncValueType = 0;
183pub const XSyncValueType_XSyncRelative: XSyncValueType = 1;
184
185pub const XSyncTestType_XSyncPositiveTransition: XSyncTestType = 0;
186pub const XSyncTestType_XSyncNegativeTransition: XSyncTestType = 1;
187pub const XSyncTestType_XSyncPositiveComparison: XSyncTestType = 2;
188pub const XSyncTestType_XSyncNegativeComparison: XSyncTestType = 3;
189
190pub const XSyncAlarmState_XSyncAlarmActive: XSyncAlarmState = 0;
191pub const XSyncAlarmState_XSyncAlarmInactive: XSyncAlarmState = 1;
192pub const XSyncAlarmState_XSyncAlarmDestroyed: XSyncAlarmState = 2;
193