Skip to content

Commit

Permalink
Rework
Browse files Browse the repository at this point in the history
-registrar abstraction
-remove cursor (for now)
-support many output
-support many seats

Signed-off-by: Joel Winarske <[email protected]>
  • Loading branch information
jwinarske committed Apr 13, 2024
1 parent e974ba1 commit 08dbcbb
Show file tree
Hide file tree
Showing 33 changed files with 1,168 additions and 1,188 deletions.
22 changes: 14 additions & 8 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
# limitations under the License.
#

# Define variables
set(TARGET_NAME demo)
set(SOURCE_FILE demo.cc)
set(COMPILE_DEFINITIONS EGL_NO_X11 MESA_EGL_NO_X11_HEADERS)
set(LINK_LIBRARIES waypp GLESv2)

# Use variables in place of hard-coded values
add_executable(${TARGET_NAME} ${SOURCE_FILE})
target_compile_definitions(${TARGET_NAME} PRIVATE ${COMPILE_DEFINITIONS})
target_link_libraries(${TARGET_NAME} ${LINK_LIBRARIES})
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLESv2 IMPORTED_TARGET glesv2)

add_executable(${TARGET_NAME} demo.cc)
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)

target_compile_definitions(${TARGET_NAME} PRIVATE EGL_NO_X11 MESA_EGL_NO_X11_HEADERS)
target_link_libraries(${TARGET_NAME} PRIVATE waypp PkgConfig::GLESv2)

if (IPO_SUPPORT_RESULT)
set_property(TARGET ${TARGET_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()

add_sanitizers(${TARGET_NAME})
37 changes: 22 additions & 15 deletions demo/demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
* limitations under the License.
*/

#include <chrono>
#include <array>
#include <csignal>
#include <iostream>

#include <GLES2/gl2.h>

#include "window_manager/registrar.h"
#include "window/window_egl.h"
#include "window_manager/window_manager.h"
#include "window_manager/xdg_window_manager.h"

#include "config.h"

static volatile bool keep_running = true;
constexpr int WINDOW_HEIGHT = 200;
constexpr int WINDOW_WIDTH = 200;


/**
* @brief Signal handler function to handle signals.
Expand All @@ -38,8 +40,10 @@ constexpr int WINDOW_WIDTH = 200;
*
* @return void
*/
void handle_signal(int /* signal */) {
keep_running = false;
void handle_signal(int signal) {
if (signal == SIGINT) {
keep_running = false;
}
}

/**
Expand Down Expand Up @@ -93,10 +97,8 @@ static float calculate_hue() {
* @param data A pointer to the WindowEgl object.
* @param time The current time in milliseconds.
*/
void frame_update(void *data, uint32_t time) {
std::cout << "draw_frame: " << time << std::endl;
auto obj = static_cast<WindowEgl *>(data);
(void) obj->make_current();
void draw_frame(WindowEgl *backend, uint32_t /* time */) {
(void) backend->make_current();

auto hue = calculate_hue();
float rgb[3] = {0, 0, 0};
Expand All @@ -105,8 +107,8 @@ void frame_update(void *data, uint32_t time) {
glClear(GL_COLOR_BUFFER_BIT);
glFinish();

(void) obj->swap_buffers();
(void) obj->clear_current();
(void) backend->swap_buffers();
(void) backend->clear_current();
}

/**
Expand All @@ -120,10 +122,15 @@ void frame_update(void *data, uint32_t time) {
* @return An integer representing the exit status of the program.
*/
int main(int /* argc */, char ** /* argv */) {

std::signal(SIGINT, handle_signal);
WindowManager wm(Window::ShellType::XDG);
wm.create_window(WINDOW_WIDTH, WINDOW_HEIGHT,
WindowManager::WindowType::EGL, frame_update);

XdgWindowManager wm("XDG Demo", "org.waypp.xdg_demo");
if (wm.shm_has_format(WL_SHM_FORMAT_XRGB8888)) {
std::cout << "XRGB is supported" << std::endl;
}
wm.create_egl_window(640, 480, kEglContextAttribs.size(), kEglContextAttribs.data(), kEglConfigAttribs.size(),
kEglConfigAttribs.data(), kEglMinBufferSize, reinterpret_cast<FrameCallback>(draw_frame));

while (keep_running && wm.poll_events(0) >= 0);
return EXIT_SUCCESS;
Expand Down
46 changes: 46 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2024 Joel Winarske
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef INCLUDE_CONFIG_H_
#define INCLUDE_CONFIG_H_

#include <array>

#include <EGL/egl.h>

static constexpr std::array<EGLint, 5> kEglContextAttribs = {
{
EGL_CONTEXT_MAJOR_VERSION, 3,
EGL_CONTEXT_MAJOR_VERSION, 2,
EGL_NONE
}
};

static constexpr std::array<EGLint, 13> kEglConfigAttribs = {
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_NONE // termination sentinel
}
};

static constexpr int kEglMinBufferSize = 24;

#endif // INCLUDE_CONFIG_H_
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
find_package(OpenGL REQUIRED COMPONENTS EGL)

set(WINDOW_MANAGER_SRC
window_manager/display.cc
window_manager/output.cc
window_manager/registrar.cc
window_manager/window_manager.cc
window_manager/xdg_wm.cc)
window_manager/xdg_window_manager.cc)

set(SEAT_SRC
seat/seat.cc
seat/keyboard.cc
seat/pointer.cc
seat/cursor.cc
seat/touch.cc)

set(WINDOW_SRC
window/egl.cc
window/surface.cc
window/window.cc
window/window_egl.cc
window/window_vulkan.cc)
Expand Down
121 changes: 0 additions & 121 deletions src/seat/cursor.cc

This file was deleted.

52 changes: 0 additions & 52 deletions src/seat/cursor.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/seat/keyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
*/
Keyboard::Keyboard(struct wl_keyboard *keyboard) : keyboard_(keyboard),
xkb_context_(xkb_context_new(XKB_CONTEXT_NO_FLAGS)) {
wl_keyboard_add_listener(keyboard, &listener_, this);
std::cout << "Keyboard" << std::endl;
wl_keyboard_add_listener(keyboard_, &listener_, this);
}

/**
Expand All @@ -44,7 +45,6 @@ Keyboard::Keyboard(struct wl_keyboard *keyboard) : keyboard_(keyboard),
*/
Keyboard::~Keyboard() {
wl_keyboard_release(keyboard_);
wl_keyboard_destroy(keyboard_);
}

/**
Expand Down
Loading

0 comments on commit 08dbcbb

Please sign in to comment.