From bae255ee1a661adec59134169617e0570fc8c99d Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 11 Jun 2020 12:42:27 +0200 Subject: [PATCH] Get rid of C_SIDE wlroots headers can mostly be included with extern "C" blocks. Two exceptions are the use of `static` for array args and `class` as a struct field. These can be #define'ed to avoid C++ build errors. This allows the whole project to be built as a single C++ codebase, without having to maintain hybrid header files. --- meson.build | 2 +- src/drm.hpp | 16 +++---------- src/inputsdl.cpp | 2 +- src/inputsdl.hpp | 8 ------- src/main.cpp | 3 +-- src/main.hpp | 12 +--------- src/rendervulkan.hpp | 16 +++---------- src/steamcompmgr.cpp | 2 +- src/steamcompmgr.hpp | 11 +-------- src/vblankmanager.cpp | 2 +- src/{wlserver.c => wlserver.cpp} | 40 ++++++++++++++++++-------------- src/{wlserver.h => wlserver.hpp} | 19 +-------------- 12 files changed, 36 insertions(+), 97 deletions(-) rename src/{wlserver.c => wlserver.cpp} (93%) rename src/{wlserver.h => wlserver.hpp} (86%) diff --git a/meson.build b/meson.build index 7d2fd7d..5c2be78 100644 --- a/meson.build +++ b/meson.build @@ -68,7 +68,7 @@ executable( 'gamescope', 'src/steamcompmgr.cpp', 'src/main.cpp', - 'src/wlserver.c', + 'src/wlserver.cpp', 'src/drm.cpp', 'src/inputsdl.cpp', 'src/vblankmanager.cpp', diff --git a/src/drm.hpp b/src/drm.hpp index 42f53d9..27f9954 100644 --- a/src/drm.hpp +++ b/src/drm.hpp @@ -7,12 +7,13 @@ #include #include +extern "C" { +#include #include +} #include "rendervulkan.hpp" -#ifndef C_SIDE - #include #include #include @@ -85,13 +86,6 @@ struct drm_t { std::atomic < uint64_t > flipcount; }; -#endif - -#ifndef C_SIDE -extern "C" { -#endif - -#include "libliftoff.h" extern struct drm_t g_DRM; @@ -106,7 +100,3 @@ int drm_atomic_commit(struct drm_t *drm, struct Composite_t *pComposite, struct uint32_t drm_fbid_from_dmabuf( struct drm_t *drm, struct wlr_dmabuf_attributes *dma_buf ); void drm_drop_fbid( struct drm_t *drm, uint32_t fbid ); bool drm_can_avoid_composite( struct drm_t *drm, struct Composite_t *pComposite, struct VulkanPipeline_t *pPipeline ); - -#ifndef C_SIDE -} -#endif diff --git a/src/inputsdl.cpp b/src/inputsdl.cpp index fc9b3e9..837495f 100644 --- a/src/inputsdl.cpp +++ b/src/inputsdl.cpp @@ -9,7 +9,7 @@ #include #include "inputsdl.hpp" -#include "wlserver.h" +#include "wlserver.hpp" #include "main.hpp" std::mutex g_SDLInitLock; diff --git a/src/inputsdl.hpp b/src/inputsdl.hpp index 38c7ced..a3f38f8 100644 --- a/src/inputsdl.hpp +++ b/src/inputsdl.hpp @@ -2,12 +2,4 @@ #pragma once -#ifndef C_SIDE -extern "C" { -#endif - bool inputsdl_init( void ); - -#ifndef C_SIDE -} -#endif diff --git a/src/main.cpp b/src/main.cpp index 6040a18..01fa0b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,13 +6,12 @@ #include -#include "wlserver.h" - #include "main.hpp" #include "steamcompmgr.hpp" #include "drm.hpp" #include "rendervulkan.hpp" #include "inputsdl.hpp" +#include "wlserver.hpp" int ac; char **av; diff --git a/src/main.hpp b/src/main.hpp index 7ca320e..ea86c16 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -1,13 +1,7 @@ -#ifndef C_SIDE -extern "C" { -#endif - #include #include - -extern SDL_Window *window; -#include "wlr/render/dmabuf.h" +extern SDL_Window *window; int initOutput(void); @@ -30,7 +24,3 @@ extern bool g_bFilterGameWindow; extern uint32_t g_nSubCommandArg; int BIsNested( void ); - -#ifndef C_SIDE -} -#endif diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp index deced0a..22bda87 100644 --- a/src/rendervulkan.hpp +++ b/src/rendervulkan.hpp @@ -42,20 +42,16 @@ struct Composite_t #include "drm.hpp" -#ifndef C_SIDE - #include #include extern "C" { -#endif - -#include #include +} + +#include #include -#ifndef C_SIDE - class CVulkanTexture { public: @@ -82,8 +78,6 @@ public: extern std::vector< const char * > g_vecSDLInstanceExts; -#endif - int vulkan_init(void); VulkanTexture_t vulkan_create_texture_from_dmabuf( struct wlr_dmabuf_attributes *pDMA ); @@ -103,7 +97,3 @@ void vulkan_present_to_window( void ); void vulkan_garbage_collect( void ); bool vulkan_remake_swapchain( void ); - -#ifndef C_SIDE -} -#endif diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index a501a2f..771f4cd 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -61,7 +61,7 @@ #include #include "main.hpp" -#include "wlserver.h" +#include "wlserver.hpp" #include "drm.hpp" #include "rendervulkan.hpp" #include "steamcompmgr.hpp" diff --git a/src/steamcompmgr.hpp b/src/steamcompmgr.hpp index 2012e6e..7ae5635 100644 --- a/src/steamcompmgr.hpp +++ b/src/steamcompmgr.hpp @@ -1,9 +1,5 @@ -#ifndef C_SIDE -extern "C" { -#endif - #include - + extern uint32_t currentOutputWidth; extern uint32_t currentOutputHeight; @@ -11,9 +7,6 @@ unsigned int get_time_in_milliseconds(void); int steamcompmgr_main(int argc, char **argv); -#ifndef C_SIDE -} - #include "rendervulkan.hpp" #include @@ -78,5 +71,3 @@ private: extern std::mutex wayland_commit_lock; extern std::vector wayland_commit_queue; - -#endif diff --git a/src/vblankmanager.cpp b/src/vblankmanager.cpp index d7e12e5..74909e1 100644 --- a/src/vblankmanager.cpp +++ b/src/vblankmanager.cpp @@ -12,7 +12,7 @@ #include "vblankmanager.hpp" #include "steamcompmgr.hpp" -#include "wlserver.h" +#include "wlserver.hpp" #include "main.hpp" static Display *g_nestedDpy; diff --git a/src/wlserver.c b/src/wlserver.cpp similarity index 93% rename from src/wlserver.c rename to src/wlserver.cpp index e8048da..01a795f 100644 --- a/src/wlserver.c +++ b/src/wlserver.cpp @@ -1,5 +1,4 @@ -#define _POSIX_C_SOURCE 200112L -#define _GNU_SOURCE +#define _GNU_SOURCE 1 #include #include @@ -16,18 +15,23 @@ #include #include + +extern "C" { +#define static +#define class class_ #include #include #include #include #include #include +#include #include +#undef static +#undef class +} -#define C_SIDE - -#include "steamcompmgr.hpp" -#include "wlserver.h" +#include "wlserver.hpp" #include "drm.hpp" #include "main.hpp" @@ -67,7 +71,7 @@ void nudge_steamcompmgr(void) XFlush( g_XWLDpy ); } -const struct wlr_surface_role xwayland_surface_role; +extern const struct wlr_surface_role xwayland_surface_role; void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) { assert(wlr_surface->role == &xwayland_surface_role); @@ -91,7 +95,7 @@ void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) { static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface) { assert(wlr_surface->role == &xwayland_surface_role); - struct wlr_xwayland_surface *surface = wlr_surface->role_data; + struct wlr_xwayland_surface *surface = (struct wlr_xwayland_surface *) wlr_surface->role_data; if (surface == NULL) { return; } @@ -123,7 +127,7 @@ static void wlserver_handle_modifiers(struct wl_listener *listener, void *data) static void wlserver_handle_key(struct wl_listener *listener, void *data) { struct wlserver_keyboard *keyboard = wl_container_of( listener, keyboard, key ); - struct wlr_event_keyboard_key *event = data; + struct wlr_event_keyboard_key *event = (struct wlr_event_keyboard_key *) data; xkb_keycode_t keycode = event->keycode + 8; xkb_keysym_t keysym = xkb_state_key_get_one_sym(keyboard->device->keyboard->xkb_state, keycode); @@ -168,7 +172,7 @@ static void wlserver_movecursor( int x, int y ) static void wlserver_handle_pointer_motion(struct wl_listener *listener, void *data) { struct wlserver_pointer *pointer = wl_container_of( listener, pointer, motion ); - struct wlr_event_pointer_motion *event = data; + struct wlr_event_pointer_motion *event = (struct wlr_event_pointer_motion *) data; if ( wlserver.mouse_focus_surface != NULL ) { @@ -182,7 +186,7 @@ static void wlserver_handle_pointer_motion(struct wl_listener *listener, void *d static void wlserver_handle_pointer_button(struct wl_listener *listener, void *data) { struct wlserver_pointer *pointer = wl_container_of( listener, pointer, button ); - struct wlr_event_pointer_button *event = data; + struct wlr_event_pointer_button *event = (struct wlr_event_pointer_button *) data; wlr_seat_pointer_notify_button( wlserver.wlr.seat, event->time_msec, event->button, event->state ); wlr_seat_pointer_notify_frame( wlserver.wlr.seat ); @@ -207,7 +211,7 @@ static inline uint32_t steamcompmgr_button_to_wlserver_button( int button ) static void wlserver_handle_touch_down(struct wl_listener *listener, void *data) { struct wlserver_touch *touch = wl_container_of( listener, touch, down ); - struct wlr_event_touch_down *event = data; + struct wlr_event_touch_down *event = (struct wlr_event_touch_down *) data; if ( wlserver.mouse_focus_surface != NULL ) { @@ -235,7 +239,7 @@ static void wlserver_handle_touch_down(struct wl_listener *listener, void *data) static void wlserver_handle_touch_up(struct wl_listener *listener, void *data) { struct wlserver_touch *touch = wl_container_of( listener, touch, up ); - struct wlr_event_touch_up *event = data; + struct wlr_event_touch_up *event = (struct wlr_event_touch_up *) data; if ( wlserver.mouse_focus_surface != NULL ) { @@ -262,7 +266,7 @@ static void wlserver_handle_touch_up(struct wl_listener *listener, void *data) static void wlserver_handle_touch_motion(struct wl_listener *listener, void *data) { struct wlserver_touch *touch = wl_container_of( listener, touch, motion ); - struct wlr_event_touch_motion *event = data; + struct wlr_event_touch_motion *event = (struct wlr_event_touch_motion *) data; if ( wlserver.mouse_focus_surface != NULL ) { @@ -279,13 +283,13 @@ static void wlserver_handle_touch_motion(struct wl_listener *listener, void *dat static void wlserver_new_input(struct wl_listener *listener, void *data) { - struct wlr_input_device *device = data; + struct wlr_input_device *device = (struct wlr_input_device *) data; switch ( device->type ) { case WLR_INPUT_DEVICE_KEYBOARD: { - struct wlserver_keyboard *pKB = calloc( 1, sizeof( struct wlserver_keyboard ) ); + struct wlserver_keyboard *pKB = (struct wlserver_keyboard *) calloc( 1, sizeof( struct wlserver_keyboard ) ); pKB->device = device; @@ -310,7 +314,7 @@ static void wlserver_new_input(struct wl_listener *listener, void *data) break; case WLR_INPUT_DEVICE_POINTER: { - struct wlserver_pointer *pointer = calloc( 1, sizeof( struct wlserver_pointer ) ); + struct wlserver_pointer *pointer = (struct wlserver_pointer *) calloc( 1, sizeof( struct wlserver_pointer ) ); pointer->device = device; @@ -322,7 +326,7 @@ static void wlserver_new_input(struct wl_listener *listener, void *data) break; case WLR_INPUT_DEVICE_TOUCH: { - struct wlserver_touch *touch = calloc( 1, sizeof( struct wlserver_touch ) ); + struct wlserver_touch *touch = (struct wlserver_touch *) calloc( 1, sizeof( struct wlserver_touch ) ); touch->device = device; diff --git a/src/wlserver.h b/src/wlserver.hpp similarity index 86% rename from src/wlserver.h rename to src/wlserver.hpp index ce45def..01561f9 100644 --- a/src/wlserver.h +++ b/src/wlserver.hpp @@ -1,15 +1,8 @@ -// Wayland stuff +// Wayland stuff #pragma once -// Only define wlserver_t on the C side, as wlroots can't build as C++ -#ifdef C_SIDE - #include -#include -#include -#include -#include #define WLSERVER_BUTTON_COUNT 4 @@ -62,12 +55,6 @@ struct wlserver_touch { extern struct wlserver_t wlserver; -#endif - -#ifndef C_SIDE -extern "C" { -#endif - extern bool run; extern int g_nTouchClickMode; @@ -95,7 +82,3 @@ void wlserver_send_frame_done( struct wlr_surface *surf, const struct timespec * struct wlr_surface *wlserver_get_surface( long surfaceID ); const char *wlserver_get_nested_display( void ); - -#ifndef C_SIDE -} -#endif