From 6ec87363a5dc7d6095c9f6423c337bb1ecf777da Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 12 May 2023 14:33:51 -0400 Subject: X11: Use available X extensions by default --- meson.build | 6 +++--- src/x11.c | 48 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index bd6894d..30a1651 100644 --- a/meson.build +++ b/meson.build @@ -171,12 +171,12 @@ else # X11 xcursor_dep = cc.find_library('Xcursor', required: false) if xcursor_dep.found() - core_args += ['-DHAVE_XCURSOR'] + core_args += ['-DUSE_XCURSOR=1'] endif xrandr_dep = cc.find_library('Xrandr', required: false) if xrandr_dep.found() - core_args += ['-DHAVE_XRANDR'] + core_args += ['-DUSE_XRANDR=1'] endif xext_dep = cc.find_library('Xext', required: false) @@ -185,7 +185,7 @@ else # X11 #include int main(void) { XSyncQueryExtension(0, 0, 0); return 0; }''' if cc.compiles(xsync_fragment, name: 'Xsync') - core_args += ['-DHAVE_XSYNC'] + core_args += ['-DUSE_XSYNC=1'] endif endif diff --git a/src/x11.c b/src/x11.c index 85c1296..0a2096d 100644 --- a/src/x11.c +++ b/src/x11.c @@ -20,16 +20,40 @@ #include #include -#ifdef HAVE_XRANDR +#ifndef USE_XRANDR +# if __has_include() +# define USE_XRANDR 1 +# else +# define USE_XRANDR 0 +# endif +#endif + +#ifndef USE_XSYNC +# if __has_include() +# define USE_XSYNC 1 +# else +# define USE_XSYNC 0 +# endif +#endif + +#ifndef USE_XCURSOR +# if __has_include() +# define USE_XCURSOR 1 +# else +# define USE_XCURSOR 0 +# endif +#endif + +#if USE_XRANDR # include #endif -#ifdef HAVE_XSYNC +#if USE_XSYNC # include # include #endif -#ifdef HAVE_XCURSOR +#if USE_XCURSOR # include #endif @@ -60,7 +84,7 @@ enum WmClientStateMessageAction { WM_STATE_TOGGLE }; -#ifdef HAVE_XCURSOR +#if USE_XCURSOR static const char* const cursorNames[PUGL_NUM_CURSORS] = { "default", // ARROW "text", // CARET @@ -78,7 +102,7 @@ static const char* const cursorNames[PUGL_NUM_CURSORS] = { static bool initXSync(PuglWorldInternals* const impl) { -#ifdef HAVE_XSYNC +#if USE_XSYNC int syncMajor = 0; int syncMinor = 0; int errorBase = 0; @@ -221,7 +245,7 @@ puglInitViewInternals(PuglWorld* const world) impl->clipboard.selection = world->impl->atoms.CLIPBOARD; impl->clipboard.property = XA_PRIMARY; -#ifdef HAVE_XCURSOR +#if USE_XCURSOR impl->cursorName = cursorNames[PUGL_CURSOR_ARROW]; #endif @@ -423,7 +447,7 @@ updateSizeHints(const PuglView* const view) return PUGL_SUCCESS; } -#ifdef HAVE_XCURSOR +#if USE_XCURSOR static PuglStatus defineCursorName(PuglView* const view, const char* const name) { @@ -605,7 +629,7 @@ puglRealize(PuglView* const view) 1); } -#ifdef HAVE_XRANDR +#if USE_XRANDR int ignored = 0; if (XRRQueryExtension(display, &ignored, &ignored)) { // Set refresh rate hint to the real refresh rate @@ -1322,7 +1346,7 @@ puglHasFocus(const PuglView* const view) PuglStatus puglStartTimer(PuglView* const view, const uintptr_t id, const double timeout) { -#ifdef HAVE_XSYNC +#if USE_XSYNC if (view->world->impl->syncSupported) { XSyncValue value; XSyncIntToValue(&value, (int)floor(timeout * 1000.0)); @@ -1365,7 +1389,7 @@ puglStartTimer(PuglView* const view, const uintptr_t id, const double timeout) PuglStatus puglStopTimer(PuglView* const view, const uintptr_t id) { -#ifdef HAVE_XSYNC +#if USE_XSYNC PuglWorldInternals* w = view->world->impl; for (size_t i = 0; i < w->numTimers; ++i) { @@ -1688,7 +1712,7 @@ flushExposures(PuglWorld* const world) static bool handleTimerEvent(PuglWorld* const world, const XEvent xevent) { -#ifdef HAVE_XSYNC +#if USE_XSYNC if (xevent.type == world->impl->syncEventBase + XSyncAlarmNotify) { const XSyncAlarmNotifyEvent* const notify = ((const XSyncAlarmNotifyEvent*)&xevent); @@ -2117,7 +2141,7 @@ puglSetClipboard(PuglView* const view, PuglStatus puglSetCursor(PuglView* const view, const PuglCursor cursor) { -#ifdef HAVE_XCURSOR +#if USE_XCURSOR PuglInternals* const impl = view->impl; const unsigned index = (unsigned)cursor; const unsigned count = sizeof(cursorNames) / sizeof(cursorNames[0]); -- cgit v1.2.1