use {
crate::{types::RofiIntMatcher, ABI_VERSION},
::std::{
ffi::c_void,
os::raw::{c_char, c_int, c_uint},
ptr,
},
bitflags::bitflags,
std::mem,
};
bitflags! {
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct ModeType: c_uint {
const UNSET = 0x0;
const SWITCHER = 0x1;
const COMPLETER = 0x2;
const DMENU = 0x4;
}
}
#[repr(C)]
#[allow(dead_code)]
enum ModeTypeSizeChecker {
Unset = 0,
Switcher = 1,
Completer = 2,
}
const _: [(); mem::size_of::<ModeType>()] = [(); mem::size_of::<ModeTypeSizeChecker>()];
pub type ModeFree = Option<unsafe extern "C" fn(data: *mut Mode)>;
pub type ModeGetDisplayValue = Option<
unsafe extern "C" fn(
sw: *const Mode,
selected_line: c_uint,
state: *mut c_int,
attribute_list: *mut *mut glib_sys::GList,
get_entry: c_int,
) -> *mut c_char,
>;
pub type ModeGetIcon = Option<
unsafe extern "C" fn(
sw: *const Mode,
selected_line: c_uint,
height: c_int,
) -> *mut cairo_sys::cairo_surface_t,
>;
pub type ModeGetCompletion =
Option<unsafe extern "C" fn(sw: *const Mode, selected_line: c_uint) -> *mut c_char>;
pub type ModeTokenMatch = Option<
unsafe extern "C" fn(sw: *const Mode, tokens: *mut *mut RofiIntMatcher, index: c_uint) -> c_int,
>;
pub type ModeInit = Option<unsafe extern "C" fn(sw: *mut Mode) -> c_int>;
pub type ModeGetNumEntries = Option<unsafe extern "C" fn(sw: *const Mode) -> c_uint>;
pub type ModeDestroy = Option<unsafe extern "C" fn(sw: *mut Mode)>;
pub type ModeResult = Option<
unsafe extern "C" fn(
sw: *mut Mode,
menu_retv: c_int,
input: *mut *mut c_char,
selected_line: c_uint,
) -> c_int,
>;
pub type ModePreprocessInput =
Option<unsafe extern "C" fn(sw: *mut Mode, input: *const c_char) -> *mut c_char>;
pub type ModeGetMessage = Option<unsafe extern "C" fn(sw: *const Mode) -> *mut c_char>;
pub type ModeCreate = Option<unsafe extern "C" fn() -> *mut Mode>;
pub type ModeCompleterResult = Option<
unsafe extern "C" fn(*mut Mode, c_int, *mut *mut c_char, c_uint, *mut *mut c_char) -> c_uint,
>;
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Mode {
pub abi_version: c_uint,
pub name: *mut c_char,
pub cfg_name_key: [c_char; 128],
pub display_name: *mut c_char,
pub _init: ModeInit,
pub _destroy: ModeDestroy,
pub _get_num_entries: ModeGetNumEntries,
pub _result: ModeResult,
pub _token_match: ModeTokenMatch,
pub _get_display_value: ModeGetDisplayValue,
pub _get_icon: ModeGetIcon,
pub _get_completion: ModeGetCompletion,
pub _preprocess_input: ModePreprocessInput,
pub _get_message: ModeGetMessage,
pub private_data: *mut c_void,
pub free: ModeFree,
pub _create: ModeCreate,
pub _completer_result: ModeCompleterResult,
pub ed: *mut c_void,
pub module: *mut GModule,
pub fallback_icon_fetch_uid: u32,
pub fallback_icon_not_found: u32,
pub r#type: ModeType,
}
impl Mode {
const DEFAULT: Self = Self {
abi_version: ABI_VERSION,
name: ptr::null_mut(),
cfg_name_key: [0; 128],
display_name: ptr::null_mut(),
_init: None,
_destroy: None,
_get_num_entries: None,
_result: None,
_token_match: None,
_get_display_value: None,
_get_icon: None,
_get_completion: None,
_preprocess_input: None,
_get_message: None,
private_data: ptr::null_mut(),
free: None,
_create: None,
_completer_result: None,
ed: ptr::null_mut(),
module: ptr::null_mut(),
fallback_icon_fetch_uid: 0,
fallback_icon_not_found: 0,
r#type: ModeType::SWITCHER,
};
pub const fn default() -> Self {
Self::DEFAULT
}
}
impl Default for Mode {
fn default() -> Self {
Self::DEFAULT
}
}
unsafe impl Sync for Mode {}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
pub struct GModule {
_unused: [u8; 0],
}