From 7ae555a51dc7944d574fe88061d1ec3d9ac03f39 Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Mon, 5 Sep 2022 19:44:15 +0200 Subject: [PATCH] (X11/Xinerama) Style nits; slightly optimize x11_get_metrics --- gfx/common/x11_common.c | 87 ++++++++++++++++++------------------ gfx/common/xinerama_common.c | 15 +++---- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index 433a08ef27..02f937f9bf 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -411,24 +411,22 @@ static void x11_destroy_input_context(XIM *xim, XIC *xic) } -static bool x11_create_input_context(Display *dpy, Window win, XIM *xim, XIC *xic) +static bool x11_create_input_context(Display *dpy, + Window win, XIM *xim, XIC *xic) { x11_destroy_input_context(xim, xic); x11_init_keyboard_lut(); g_x11_has_focus = true; - *xim = XOpenIM(dpy, NULL, NULL, NULL); - - if (!*xim) + + if (!(*xim = XOpenIM(dpy, NULL, NULL, NULL))) { RARCH_ERR("[X11]: Failed to open input method.\n"); return false; } - *xic = XCreateIC(*xim, XNInputStyle, - XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL); - - if (!*xic) + if (!(*xic = XCreateIC(*xim, XNInputStyle, + XIMPreeditNothing | XIMStatusNothing, XNClientWindow, win, NULL))) { RARCH_ERR("[X11]: Failed to create input context.\n"); return false; @@ -441,33 +439,36 @@ static bool x11_create_input_context(Display *dpy, Window win, XIM *xim, XIC *xi bool x11_get_metrics(void *data, enum display_metric_types type, float *value) { - unsigned screen_no = 0; - Display *dpy = (Display*)XOpenDisplay(NULL); - int pixels_x = DisplayWidth(dpy, screen_no); - int pixels_y = DisplayHeight(dpy, screen_no); - int physical_width = DisplayWidthMM(dpy, screen_no); - int physical_height = DisplayHeightMM(dpy, screen_no); - - (void)pixels_y; - - XCloseDisplay(dpy); + unsigned screen_no = 0; + Display *dpy = NULL; switch (type) { case DISPLAY_METRIC_PIXEL_WIDTH: - *value = (float)pixels_x; + dpy = (Display*)XOpenDisplay(NULL); + *value = (float)DisplayWidth(dpy, screen_no); + XCloseDisplay(dpy); break; case DISPLAY_METRIC_PIXEL_HEIGHT: - *value = (float)pixels_y; + dpy = (Display*)XOpenDisplay(NULL); + *value = (float)DisplayHeight(dpy, screen_no); + XCloseDisplay(dpy); break; case DISPLAY_METRIC_MM_WIDTH: - *value = (float)physical_width; + dpy = (Display*)XOpenDisplay(NULL); + *value = (float)DisplayWidthMM(dpy, screen_no); + XCloseDisplay(dpy); break; case DISPLAY_METRIC_MM_HEIGHT: - *value = (float)physical_height; + dpy = (Display*)XOpenDisplay(NULL); + *value = (float)DisplayHeightMM(dpy, screen_no); + XCloseDisplay(dpy); break; case DISPLAY_METRIC_DPI: - *value = ((((float)pixels_x) * 25.4) / ((float)physical_width)); + dpy = (Display*)XOpenDisplay(NULL); + *value = ((((float)DisplayWidth (dpy, screen_no)) * 25.4) + / ( (float)DisplayWidthMM(dpy, screen_no))); + XCloseDisplay(dpy); break; case DISPLAY_METRIC_NONE: default: @@ -498,7 +499,8 @@ static enum retro_key x11_translate_keysym_to_rk(unsigned sym) return RETROK_UNKNOWN; } -static void x11_handle_key_event(unsigned keycode, XEvent *event, XIC ic, bool filter) +static void x11_handle_key_event(unsigned keycode, XEvent *event, + XIC ic, bool filter) { int i; Status status; @@ -538,16 +540,19 @@ static void x11_handle_key_event(unsigned keycode, XEvent *event, XIC ic, bool f #endif } else - keysym = XLookupKeysym(&event->xkey, (state & ShiftMask) || (state & LockMask)); + keysym = XLookupKeysym(&event->xkey, + (state & ShiftMask) || (state & LockMask)); } - /* We can't feed uppercase letters to the keycode translator. Seems like a bad idea - * to feed it keysyms anyway, so here is a little hack... */ + /* We can't feed uppercase letters to the keycode translator. + * Seems like a bad idea to feed it keysyms anyway, so here + * is a little hack... + **/ if (keysym >= XK_A && keysym <= XK_Z) keysym += XK_z - XK_Z; - /* Get the real keycode, - that correctly ignores international layouts as windows code does. */ + /* Get the real keycode, that correctly ignores international layouts + * as windows code does. */ key = x11_translate_keysym_to_rk(keycode); if (state & ShiftMask) @@ -589,7 +594,7 @@ bool x11_alive(void *data) switch (event.type) { case ClientMessage: - if (event.xclient.window == g_x11_win && + if ( event.xclient.window == g_x11_win && (Atom)event.xclient.data.l[0] == g_x11_quit_atom) frontend_driver_set_signal_handler_state(1); break; @@ -651,19 +656,18 @@ bool x11_alive(void *data) break; case KeyRelease: - /* When you receive a key release and the next event is a key press - of the same key combination, then it's auto-repeat and the - key wasn't actually released. */ + /* When you receive a key release and the next event + * is a key press of the same key combination, + * then it's auto-repeat and the key wasn't + * actually released. */ if(XEventsQueued(g_x11_dpy, QueuedAfterReading)) { XEvent next_event; XPeekEvent(g_x11_dpy, &next_event); - if (next_event.type == KeyPress && - next_event.xkey.time == event.xkey.time && - next_event.xkey.keycode == event.xkey.keycode) - { + if ( next_event.type == KeyPress + && next_event.xkey.time == event.xkey.time + && next_event.xkey.keycode == event.xkey.keycode) break; /* Key wasn't actually released */ - } } case KeyPress: if (event.xkey.window == g_x11_win) @@ -720,7 +724,7 @@ void x11_get_video_size(void *data, unsigned *width, unsigned *height) } else { - XWindowAttributes target; + XWindowAttributes target; XGetWindowAttributes(g_x11_dpy, g_x11_win, &target); *width = target.width; @@ -751,11 +755,8 @@ bool x11_connect(void) /* Keep one g_x11_dpy alive the entire process lifetime. * This is necessary for nVidia's EGL implementation for now. */ if (!g_x11_dpy) - { - g_x11_dpy = XOpenDisplay(NULL); - if (!g_x11_dpy) + if (!(g_x11_dpy = XOpenDisplay(NULL))) return false; - } #ifdef HAVE_DBUS dbus_ensure_connection(); diff --git a/gfx/common/xinerama_common.c b/gfx/common/xinerama_common.c index 3db4d765de..3c1ccea371 100644 --- a/gfx/common/xinerama_common.c +++ b/gfx/common/xinerama_common.c @@ -35,14 +35,14 @@ static XineramaScreenInfo *xinerama_query_screens( { int major, minor; - if (!XineramaQueryExtension(dpy, &major, &minor)) - return NULL; + if (XineramaQueryExtension(dpy, &major, &minor)) + { + XineramaQueryVersion(dpy, &major, &minor); + RARCH_LOG("[XINERAMA]: Xinerama version: %d.%d.\n", major, minor); - XineramaQueryVersion(dpy, &major, &minor); - RARCH_LOG("[XINERAMA]: Xinerama version: %d.%d.\n", major, minor); - - if (XineramaIsActive(dpy)) - return XineramaQueryScreens(dpy, num_screens); + if (XineramaIsActive(dpy)) + return XineramaQueryScreens(dpy, num_screens); + } return NULL; } @@ -131,5 +131,4 @@ void xinerama_save_last_used_monitor(Window win) RARCH_LOG("[XINERAMA]: Saved monitor #%u.\n", g_x11_screen); } - #endif