From b30473baa754430c520f0d3ad088e5a521fa6d4b Mon Sep 17 00:00:00 2001 From: Rebekah Rowe Date: Fri, 22 Apr 2022 19:24:22 -0400 Subject: [PATCH] Renamed project from libxoverlay to libhydride --- CMakeLists.txt | 11 ++--- include/hydride.h | 68 ++++++++++++++++++++++++++++++ include/xoverlay.h | 37 ++++------------ src/drawglx.c | 68 +++++++++++++++--------------- src/drawglx.h | 12 +++--- src/hydride.c | 102 +++++++++++++++++++++++++++++++++++++++++++++ src/xoverlay.c | 102 --------------------------------------------- 7 files changed, 225 insertions(+), 175 deletions(-) create mode 100644 include/hydride.h create mode 100644 src/hydride.c delete mode 100644 src/xoverlay.c diff --git a/CMakeLists.txt b/CMakeLists.txt index a9f294a..cb6d814 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -# Libxoverlay: A transparent drawable GL layer for your desktop! +# Libhydride: A transparent drawable GL layer for your desktop! # Copyright (C) 2022 Rebekah Rowe # # This program is free software: you can redistribute it and/or modify @@ -17,16 +17,17 @@ cmake_minimum_required(VERSION 3.11) -project(xoverlay LANGUAGES C VERSION 1.0.0) +project(hydride LANGUAGES C VERSION 1.0.0) find_package(X11 REQUIRED) find_package(GLEW REQUIRED) find_package(OpenGL REQUIRED) -add_library(xoverlay SHARED "src/drawglx.c" "src/xoverlay.c") +add_library(hydride SHARED "src/drawglx.c" "src/hydride.c") -target_include_directories(xoverlay PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/") -target_link_libraries(xoverlay PUBLIC ${GLEW_LIBRARIES} m rt pthread ${X11_X11_LIB} ${X11_Xext_LIB} ${X11_Xfixes_LIB}) +target_include_directories(hydride PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/") +target_link_libraries(hydride PUBLIC ${GLEW_LIBRARIES} m rt pthread ${X11_X11_LIB} ${X11_Xext_LIB} ${X11_Xfixes_LIB}) install(TARGETS ${PROJECT_NAME} DESTINATION "lib/") +install(FILES "include/hydride.h" DESTINATION "include/") install(FILES "include/xoverlay.h" DESTINATION "include/") diff --git a/include/hydride.h b/include/hydride.h new file mode 100644 index 0000000..7dbca4b --- /dev/null +++ b/include/hydride.h @@ -0,0 +1,68 @@ + +/* + * Libhydride: A transparent drawable GL layer for your desktop! + * Copyright (C) 2022 Rebekah Rowe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +struct hydride_library { + Display* display; + Window window; + Colormap colormap; + GC gc; + XGCValues gcvalues; + XFontStruct font; + int screen; + + int width; + int height; + + struct + { + int x; + int y; + } mouse; + + char init; + char drawing; + char mapped; +}; + +extern struct hydride_library hydride_library; + +int hydride_init(); + +void hydride_destroy(); + +void hydride_show(); + +void hydride_hide(); + +void hydride_draw_begin(); + +void hydride_draw_end(); + +#ifdef __cplusplus +} +#endif diff --git a/include/xoverlay.h b/include/xoverlay.h index 9d2f306..4f9fb86 100644 --- a/include/xoverlay.h +++ b/include/xoverlay.h @@ -26,42 +26,23 @@ extern "C" { #include #include -struct xoverlay_library { - Display* display; - Window window; - Colormap colormap; - GC gc; - XGCValues gcvalues; - XFontStruct font; - int screen; +#include "hydride.h" - int width; - int height; +typedef struct hydride_library xoverlay_library_t; // only api break in rename - struct - { - int x; - int y; - } mouse; +extern struct hydride_library xoverlay_library; - char init; - char drawing; - char mapped; -}; +inline int xoverlay_init() { return hydride_init(); } -extern struct xoverlay_library xoverlay_library; +inline void xoverlay_destroy() { hydride_destroy(); } -int xoverlay_init(); +inline void xoverlay_show() { hydride_show(); } -void xoverlay_destroy(); +inline void xoverlay_hide() { hydride_hide(); } -void xoverlay_show(); +inline void xoverlay_draw_begin() { hydride_draw_begin(); } -void xoverlay_hide(); - -void xoverlay_draw_begin(); - -void xoverlay_draw_end(); +inline void xoverlay_draw_end() { hydride_draw_end(); } #ifdef __cplusplus } diff --git a/src/drawglx.c b/src/drawglx.c index 0eaeb26..03d1621 100644 --- a/src/drawglx.c +++ b/src/drawglx.c @@ -1,6 +1,6 @@ /* - * Libxoverlay: A transparent drawable GL layer for your desktop! + * Libhydride: A transparent drawable GL layer for your desktop! * Copyright (C) 2022 Rebekah Rowe * * This program is free software: you can redistribute it and/or modify @@ -21,10 +21,10 @@ #include #include +#include #include #include #include -#include #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 @@ -32,7 +32,7 @@ typedef GLXContext (*glXCreateContextAttribsARBfn)(Display*, GLXFBConfig, GLXContext, Bool, const int*); -xoverlay_glx_state glx_state; +hydride_glx_state glx_state; // Helper to check for extension string presence. Adapted from: // http://www.opengl.org/resources/features/OGLextensions/ @@ -63,13 +63,13 @@ int glx_is_extension_supported(const char* list, const char* extension) { return 0; } -int xoverlay_glx_init() { - glXQueryVersion(xoverlay_library.display, &glx_state.version_major, +int hydride_glx_init() { + glXQueryVersion(hydride_library.display, &glx_state.version_major, &glx_state.version_minor); return 0; } -int xoverlay_glx_create_window() { +int hydride_glx_create_window() { GLint attribs[] = { GLX_X_RENDERABLE, GL_TRUE, GLX_DRAWABLE_TYPE, @@ -96,18 +96,18 @@ int xoverlay_glx_create_window() { int fbc_count; GLXFBConfig* fbc = glXChooseFBConfig( - xoverlay_library.display, xoverlay_library.screen, attribs, &fbc_count); + hydride_library.display, hydride_library.screen, attribs, &fbc_count); if (fbc == NULL) { return -1; } int fbc_best = -1; int fbc_best_samples = -1; for (int i = 0; i < fbc_count; ++i) { - XVisualInfo* info = glXGetVisualFromFBConfig(xoverlay_library.display, fbc[i]); + XVisualInfo* info = glXGetVisualFromFBConfig(hydride_library.display, fbc[i]); if (info->depth != 32) continue; int samples; - glXGetFBConfigAttrib(xoverlay_library.display, fbc[i], GLX_SAMPLES, + glXGetFBConfigAttrib(hydride_library.display, fbc[i], GLX_SAMPLES, &samples); if (fbc_best < 0 || samples > fbc_best_samples) { fbc_best = i; @@ -121,68 +121,68 @@ int xoverlay_glx_create_window() { GLXFBConfig fbconfig = fbc[fbc_best]; XFree(fbc); - XVisualInfo* info = glXGetVisualFromFBConfig(xoverlay_library.display, fbconfig); + XVisualInfo* info = glXGetVisualFromFBConfig(hydride_library.display, fbconfig); if (info == NULL) { return -1; } - Window root = DefaultRootWindow(xoverlay_library.display); - xoverlay_library.colormap = XCreateColormap(xoverlay_library.display, root, + Window root = DefaultRootWindow(hydride_library.display); + hydride_library.colormap = XCreateColormap(hydride_library.display, root, info->visual, AllocNone); XSetWindowAttributes attr; attr.background_pixel = 0x0; attr.border_pixel = 0; attr.save_under = 1; attr.override_redirect = 1; - attr.colormap = xoverlay_library.colormap; + attr.colormap = hydride_library.colormap; attr.event_mask = 0x0; attr.do_not_propagate_mask = (KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ButtonMotionMask); unsigned long mask = CWBackPixel | CWBorderPixel | CWSaveUnder | CWOverrideRedirect | CWColormap | CWEventMask | CWDontPropagate; - xoverlay_library.window = XCreateWindow(xoverlay_library.display, root, 0, 0, - xoverlay_library.width, xoverlay_library.height, 0, + hydride_library.window = XCreateWindow(hydride_library.display, root, 0, 0, + hydride_library.width, hydride_library.height, 0, info->depth, InputOutput, info->visual, mask, &attr); - if (xoverlay_library.window == 0) { + if (hydride_library.window == 0) { return -1; } - XShapeCombineMask(xoverlay_library.display, xoverlay_library.window, + XShapeCombineMask(hydride_library.display, hydride_library.window, ShapeInput, 0, 0, None, ShapeSet); - XShapeSelectInput(xoverlay_library.display, xoverlay_library.window, + XShapeSelectInput(hydride_library.display, hydride_library.window, ShapeNotifyMask); - XserverRegion region = XFixesCreateRegion(xoverlay_library.display, NULL, 0); - XFixesSetWindowShapeRegion(xoverlay_library.display, - xoverlay_library.window, ShapeInput, 0, 0, + XserverRegion region = XFixesCreateRegion(hydride_library.display, NULL, 0); + XFixesSetWindowShapeRegion(hydride_library.display, + hydride_library.window, ShapeInput, 0, 0, region); - XFixesDestroyRegion(xoverlay_library.display, region); + XFixesDestroyRegion(hydride_library.display, region); XFree(info); - XStoreName(xoverlay_library.display, xoverlay_library.window, + XStoreName(hydride_library.display, hydride_library.window, "OverlayWindow"); - xoverlay_show(); + hydride_show(); - const char* extensions = glXQueryExtensionsString(xoverlay_library.display, - xoverlay_library.screen); + const char* extensions = glXQueryExtensionsString(hydride_library.display, + hydride_library.screen); glXCreateContextAttribsARBfn glXCreateContextAttribsARB = (glXCreateContextAttribsARBfn)glXGetProcAddressARB( (const GLubyte*)"glXCreateContextAttribsARB"); if (!glx_is_extension_supported(extensions, "GLX_ARB_create_context")) { glx_state.context = glXCreateNewContext( - xoverlay_library.display, fbconfig, GLX_RGBA_TYPE, NULL, GL_TRUE); + hydride_library.display, fbconfig, GLX_RGBA_TYPE, NULL, GL_TRUE); } else { int ctx_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 0, None }; glx_state.context = glXCreateContextAttribsARB( - xoverlay_library.display, fbconfig, NULL, GL_TRUE, ctx_attribs); - XSync(xoverlay_library.display, GL_FALSE); + hydride_library.display, fbconfig, NULL, GL_TRUE, ctx_attribs); + XSync(hydride_library.display, GL_FALSE); } if (glx_state.context == NULL) { return -1; } - if (!glXIsDirect(xoverlay_library.display, glx_state.context)) + if (!glXIsDirect(hydride_library.display, glx_state.context)) ; - glXMakeCurrent(xoverlay_library.display, xoverlay_library.window, + glXMakeCurrent(hydride_library.display, hydride_library.window, glx_state.context); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { @@ -193,13 +193,13 @@ int xoverlay_glx_create_window() { PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB( (const GLubyte*)"glXSwapIntervalEXT"); if (glXSwapIntervalEXT) - glXSwapIntervalEXT(xoverlay_library.display, xoverlay_library.window, + glXSwapIntervalEXT(hydride_library.display, hydride_library.window, 0); - glXSwapBuffers(xoverlay_library.display, xoverlay_library.window); + glXSwapBuffers(hydride_library.display, hydride_library.window); return 0; } -int xoverlay_glx_destroy() { +int hydride_glx_destroy() { return 0; } diff --git a/src/drawglx.h b/src/drawglx.h index 41737af..ef0ddab 100644 --- a/src/drawglx.h +++ b/src/drawglx.h @@ -1,6 +1,6 @@ /* - * Libxoverlay: A transparent drawable GL layer for your desktop! + * Libhydride: A transparent drawable GL layer for your desktop! * Copyright (C) 2022 Rebekah Rowe * * This program is free software: you can redistribute it and/or modify @@ -28,10 +28,10 @@ typedef struct int version_major; int version_minor; GLXContext context; -} xoverlay_glx_state; +} hydride_glx_state; -extern xoverlay_glx_state glx_state; +extern hydride_glx_state glx_state; -int xoverlay_glx_init(); -int xoverlay_glx_create_window(); -int xoverlay_glx_destroy(); +int hydride_glx_init(); +int hydride_glx_create_window(); +int hydride_glx_destroy(); diff --git a/src/hydride.c b/src/hydride.c new file mode 100644 index 0000000..4cf80a5 --- /dev/null +++ b/src/hydride.c @@ -0,0 +1,102 @@ + +/* + * Libhydride: A transparent drawable GL layer for your desktop! + * Copyright (C) 2022 Rebekah Rowe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "drawglx.h" + +#include +#include +#include + +#include +#include +#include + +int event_ShapeNotify; +int event_ShapeError; +struct hydride_library hydride_library; + +int preinit_done = 0; + +int hydride_init() { + memset(&hydride_library, 0, sizeof(struct hydride_library)); + + hydride_library.display = XOpenDisplay(NULL); + if (hydride_library.display == NULL) { + return -2; + } + + hydride_library.screen = DefaultScreen(hydride_library.display); + hydride_library.width = DisplayWidth(hydride_library.display, hydride_library.screen); + hydride_library.height = DisplayHeight(hydride_library.display, hydride_library.screen); + + if (!XShapeQueryExtension(hydride_library.display, &event_ShapeNotify, + &event_ShapeError)) { + return -3; + } + + if (hydride_glx_init() < 0) { + return -4; + } + if (hydride_glx_create_window() < 0) { + return -5; + } + + hydride_library.init = 1; + + return 0; +} + +void hydride_destroy() { + XDestroyWindow(hydride_library.display, hydride_library.window); + XCloseDisplay(hydride_library.display); + hydride_glx_destroy(); + hydride_library.init = 0; +} + +void hydride_show() { + if (hydride_library.mapped == 1) + return; + + XMapWindow(hydride_library.display, hydride_library.window); + hydride_library.mapped = 1; +} + +void hydride_hide() { + if (hydride_library.mapped == 0) + return; + + XUnmapWindow(hydride_library.display, hydride_library.window); + hydride_library.mapped = 0; +} + +void hydride_draw_begin() { + if (!hydride_library.init) + return; + hydride_library.drawing = 1; + glXMakeCurrent(hydride_library.display, hydride_library.window, + glx_state.context); + glClear(GL_COLOR_BUFFER_BIT); +} + +void hydride_draw_end() { + if (!hydride_library.init) + return; + glXSwapBuffers(hydride_library.display, hydride_library.window); + hydride_library.drawing = 0; +} diff --git a/src/xoverlay.c b/src/xoverlay.c deleted file mode 100644 index 9644fce..0000000 --- a/src/xoverlay.c +++ /dev/null @@ -1,102 +0,0 @@ - -/* - * Libxoverlay: A transparent drawable GL layer for your desktop! - * Copyright (C) 2022 Rebekah Rowe - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "drawglx.h" - -#include -#include -#include - -#include -#include -#include - -int event_ShapeNotify; -int event_ShapeError; -struct xoverlay_library xoverlay_library; - -int preinit_done = 0; - -int xoverlay_init() { - memset(&xoverlay_library, 0, sizeof(struct xoverlay_library)); - - xoverlay_library.display = XOpenDisplay(NULL); - if (xoverlay_library.display == NULL) { - return -2; - } - - xoverlay_library.screen = DefaultScreen(xoverlay_library.display); - xoverlay_library.width = DisplayWidth(xoverlay_library.display, xoverlay_library.screen); - xoverlay_library.height = DisplayHeight(xoverlay_library.display, xoverlay_library.screen); - - if (!XShapeQueryExtension(xoverlay_library.display, &event_ShapeNotify, - &event_ShapeError)) { - return -3; - } - - if (xoverlay_glx_init() < 0) { - return -4; - } - if (xoverlay_glx_create_window() < 0) { - return -5; - } - - xoverlay_library.init = 1; - - return 0; -} - -void xoverlay_destroy() { - XDestroyWindow(xoverlay_library.display, xoverlay_library.window); - XCloseDisplay(xoverlay_library.display); - xoverlay_glx_destroy(); - xoverlay_library.init = 0; -} - -void xoverlay_show() { - if (xoverlay_library.mapped == 1) - return; - - XMapWindow(xoverlay_library.display, xoverlay_library.window); - xoverlay_library.mapped = 1; -} - -void xoverlay_hide() { - if (xoverlay_library.mapped == 0) - return; - - XUnmapWindow(xoverlay_library.display, xoverlay_library.window); - xoverlay_library.mapped = 0; -} - -void xoverlay_draw_begin() { - if (!xoverlay_library.init) - return; - xoverlay_library.drawing = 1; - glXMakeCurrent(xoverlay_library.display, xoverlay_library.window, - glx_state.context); - glClear(GL_COLOR_BUFFER_BIT); -} - -void xoverlay_draw_end() { - if (!xoverlay_library.init) - return; - glXSwapBuffers(xoverlay_library.display, xoverlay_library.window); - xoverlay_library.drawing = 0; -}