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.
This commit is contained in:
Simon Ser 2020-06-11 12:42:27 +02:00
parent 453caf7672
commit bae255ee1a
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
12 changed files with 36 additions and 97 deletions

View file

@ -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',

View file

@ -7,12 +7,13 @@
#include <assert.h>
#include <drm_fourcc.h>
extern "C" {
#include <libliftoff.h>
#include <wlr/render/dmabuf.h>
}
#include "rendervulkan.hpp"
#ifndef C_SIDE
#include <unordered_map>
#include <utility>
#include <atomic>
@ -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

View file

@ -9,7 +9,7 @@
#include <SDL.h>
#include "inputsdl.hpp"
#include "wlserver.h"
#include "wlserver.hpp"
#include "main.hpp"
std::mutex g_SDLInitLock;

View file

@ -2,12 +2,4 @@
#pragma once
#ifndef C_SIDE
extern "C" {
#endif
bool inputsdl_init( void );
#ifndef C_SIDE
}
#endif

View file

@ -6,13 +6,12 @@
#include <unistd.h>
#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;

View file

@ -1,14 +1,8 @@
#ifndef C_SIDE
extern "C" {
#endif
#include <SDL.h>
#include <SDL_vulkan.h>
extern SDL_Window *window;
#include "wlr/render/dmabuf.h"
int initOutput(void);
void startSteamCompMgr(void);
@ -30,7 +24,3 @@ extern bool g_bFilterGameWindow;
extern uint32_t g_nSubCommandArg;
int BIsNested( void );
#ifndef C_SIDE
}
#endif

View file

@ -42,20 +42,16 @@ struct Composite_t
#include "drm.hpp"
#ifndef C_SIDE
#include <unordered_map>
#include <vector>
extern "C" {
#endif
#include <wlr/render/dmabuf.h>
}
#include <vulkan/vulkan.h>
#include <wlr/render/dmabuf.h>
#include <drm_fourcc.h>
#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

View file

@ -61,7 +61,7 @@
#include <X11/extensions/xf86vmode.h>
#include "main.hpp"
#include "wlserver.h"
#include "wlserver.hpp"
#include "drm.hpp"
#include "rendervulkan.hpp"
#include "steamcompmgr.hpp"

View file

@ -1,7 +1,3 @@
#ifndef C_SIDE
extern "C" {
#endif
#include <stdint.h>
extern uint32_t currentOutputWidth;
@ -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 <mutex>
@ -78,5 +71,3 @@ private:
extern std::mutex wayland_commit_lock;
extern std::vector<ResListEntry_t> wayland_commit_queue;
#endif

View file

@ -12,7 +12,7 @@
#include "vblankmanager.hpp"
#include "steamcompmgr.hpp"
#include "wlserver.h"
#include "wlserver.hpp"
#include "main.hpp"
static Display *g_nestedDpy;

View file

@ -1,5 +1,4 @@
#define _POSIX_C_SOURCE 200112L
#define _GNU_SOURCE
#define _GNU_SOURCE 1
#include <assert.h>
#include <signal.h>
@ -16,18 +15,23 @@
#include <xkbcommon/xkbcommon.h>
#include <wayland-server-core.h>
extern "C" {
#define static
#define class class_
#include <wlr/backend.h>
#include <wlr/backend/headless.h>
#include <wlr/backend/multi.h>
#include <wlr/backend/libinput.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/xwayland.h>
#include <wlr/util/log.h>
#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;

View file

@ -2,14 +2,7 @@
#pragma once
// Only define wlserver_t on the C side, as wlroots can't build as C++
#ifdef C_SIDE
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/xwayland.h>
#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