From 58319351dfba915c5086b7fd15ad92af51ee37db Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sun, 1 Dec 2024 16:57:53 -0800 Subject: [PATCH 1/2] feat: Expose XDefaultScreen It is difficult to use libxcb properly on top of libx11 without this function. This commit adds a "default_screen()" function to Display that allows for accessing this call. Signed-off-by: John Nunley --- src/ffi.rs | 14 ++++++++++++++ src/lib.rs | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/ffi.rs b/src/ffi.rs index e50f208..8a9a6ee 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -48,6 +48,7 @@ pub(crate) struct XErrorEvent { type XOpenDisplay = unsafe extern "C" fn(display_name: *const c_char) -> *mut Display; type XCloseDisplay = unsafe extern "C" fn(display: *mut Display) -> c_int; type XGetXCBConnection = unsafe extern "C" fn(display: *mut Display) -> *mut xcb_connection_t; +type XDefaultScreen = unsafe extern "C" fn(display: *mut Display) -> c_int; pub(crate) type XErrorHook = Option c_int>; type XSetErrorHandler = unsafe extern "C" fn(handler: XErrorHook) -> XErrorHook; @@ -72,6 +73,9 @@ pub(crate) struct Xlib { /// The XGetXCBConnection function. x_get_xcb_connection: XGetXCBConnection, + /// The XDefaultScreen function. + x_default_screen: XDefaultScreen, + /// The XSetErrorHandler function. x_set_error_handler: XSetErrorHandler, @@ -95,6 +99,11 @@ impl Xlib { (self.x_get_xcb_connection)(display) } + /// Get the default screen index. + pub(crate) unsafe fn default_screen(&self, display: *mut Display) -> c_int { + (self.x_default_screen)(display) + } + /// Set the error handler. pub(crate) unsafe fn set_error_handler(&self, handler: XErrorHook) -> XErrorHook { (self.x_set_error_handler)(handler) @@ -113,6 +122,7 @@ impl Xlib { extern "C" { fn XOpenDisplay(display_name: *const c_char) -> *mut Display; fn XCloseDisplay(display: *mut Display) -> c_int; + fn XDefaultScreen(display: *mut Display) -> c_int; fn XSetErrorHandler(handler: XErrorHook) -> XErrorHook; fn XInitThreads() -> c_int; } @@ -126,6 +136,7 @@ impl Xlib { x_open_display: XOpenDisplay, x_close_display: XCloseDisplay, x_get_xcb_connection: XGetXCBConnection, + x_default_screen: XDefaultScreen, x_set_error_handler: XSetErrorHandler, x_init_threads: XInitThreads, }) @@ -146,6 +157,8 @@ impl Xlib { let x_set_error_handler = unsafe { xlib_library.get::(b"XSetErrorHandler\0")? }; + let x_default_screen = unsafe { xlib_library.get::(b"XDefaultScreen\0")? }; + let x_get_xcb_connection = unsafe { xlib_xcb_library.get::(b"XGetXCBConnection\0")? }; @@ -155,6 +168,7 @@ impl Xlib { x_open_display: *x_open_display, x_close_display: *x_close_display, x_get_xcb_connection: *x_get_xcb_connection, + x_default_screen: *x_default_screen, x_set_error_handler: *x_set_error_handler, x_init_threads: *x_init_threads, _xlib_library: xlib_library, diff --git a/src/lib.rs b/src/lib.rs index 547031a..3d36a71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -418,6 +418,23 @@ impl Display { pub fn as_ptr(&self) -> *mut c_void { self.ptr.as_ptr().cast() } + + /// Get the default screen index for this display. + pub fn screen_index(&self) -> usize { + let xlib = get_xlib(&XLIB).expect("failed to load Xlib"); + + // SAFETY: Valid display pointer. + let index = unsafe { xlib.default_screen(self.ptr.as_ptr()) }; + + // Cast down to usize. + index.try_into().unwrap_or_else(|_| { + #[cfg(feature = "tracing")] + tracing::error!( + "XDefaultScreen returned a value out of usize range (how?!), returning zero" + ); + 0 + }) + } } unsafe impl as_raw_xcb_connection::AsRawXcbConnection for Display { From 248a8d1230a077f74726c200f83bd91259b349d2 Mon Sep 17 00:00:00 2001 From: John Nunley Date: Sun, 1 Dec 2024 17:00:30 -0800 Subject: [PATCH 2/2] ci: Remove security audit Signed-off-by: John Nunley --- .github/workflows/ci.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9078b80..1833d76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,16 +77,3 @@ jobs: - name: Install Rust run: rustup update stable - run: cargo fmt --all --check - - security_audit: - permissions: - checks: write - contents: read - issues: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - # https://github.com/rustsec/audit-check/issues/2 - - uses: rustsec/audit-check@master - with: - token: ${{ secrets.GITHUB_TOKEN }}