From fe42b2a74c10c71b0369fad9eb42428e27371c5c Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 1 Jan 2022 14:39:55 -0400 Subject: [PATCH] optimize x11 display code --- base/xdisplay_c.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/base/xdisplay_c.h b/base/xdisplay_c.h index f2178f3f..f96e835b 100644 --- a/base/xdisplay_c.h +++ b/base/xdisplay_c.h @@ -4,11 +4,11 @@ static Display *mainDisplay = NULL; static int registered = 0; + static char *displayName = NULL; static int hasDisplayNameChanged = 0; -Display *XGetMainDisplay(void) -{ +Display *XGetMainDisplay(void) { /* Close the display if displayName has changed */ if (hasDisplayNameChanged) { XCloseMainDisplay(); @@ -20,7 +20,7 @@ Display *XGetMainDisplay(void) mainDisplay = XOpenDisplay(displayName); /* Then try using environment variable DISPLAY */ - if (mainDisplay == NULL) { + if (mainDisplay == NULL && displayName != NULL) { mainDisplay = XOpenDisplay(NULL); } @@ -40,22 +40,19 @@ Display *XGetMainDisplay(void) return mainDisplay; } -void XCloseMainDisplay(void) -{ +void XCloseMainDisplay(void) { if (mainDisplay != NULL) { XCloseDisplay(mainDisplay); mainDisplay = NULL; } } -void setXDisplay(char *name) -{ +void setXDisplay(char *name) { displayName = strdup(name); hasDisplayNameChanged = 1; } -char *getXDisplay(void) -{ +char *getXDisplay(void) { return displayName; }