From be5a13d7b3f272a8abf2f985a1fdbef8a30827eb Mon Sep 17 00:00:00 2001 From: Blink-A <53814695+Blink-A@users.noreply.github.com> Date: Sun, 18 Aug 2024 16:34:02 +0800 Subject: [PATCH] Update screen_c.h --- screen/screen_c.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/screen/screen_c.h b/screen/screen_c.h index 88dcd834..46a7e83e 100644 --- a/screen/screen_c.h +++ b/screen/screen_c.h @@ -15,12 +15,25 @@ MMSizeInt32 getMainDisplaySize(void) { CGSize size = displayRect.size; return MMSizeInt32Make((int32_t)size.width, (int32_t)size.height); #elif defined(USE_X11) - Display *display = XGetMainDisplay(); - const int screen = DefaultScreen(display); + // Display *display = XGetMainDisplay(); + // const int screen = DefaultScreen(display); - return MMSizeInt32Make( - (int32_t)DisplayWidth(display, screen), - (int32_t)DisplayHeight(display, screen)); + // return MMSizeInt32Make( + // (int32_t)DisplayWidth(display, screen), + // (int32_t)DisplayHeight(display, screen)); + Display *display = XOpenDisplay(NULL); + if (display == NULL) { + return MMSizeInt32Make(0, 0); // Return an invalid size if unable to open display + } + + const int screen = DefaultScreen(display); + MMSizeInt32 resolution = MMSizeInt32Make( + (int32_t)DisplayWidth(display, screen), + (int32_t)DisplayHeight(display, screen) + ); + + XCloseDisplay(display); + return resolution; #elif defined(IS_WINDOWS) return MMSizeInt32Make( (int32_t)GetSystemMetrics(SM_CXSCREEN),