Skip to content

Commit

Permalink
Disable Cursor
Browse files Browse the repository at this point in the history
-disable cursor works
-remove extraneous struct keyword in working examples
-changes for wlroots
-update README

Signed-off-by: Joel Winarske <[email protected]>
  • Loading branch information
jwinarske committed May 1, 2024
1 parent 498a84c commit 81f233a
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 59 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ _Note: waypp is a work in progress and is not ABI stable_
waypp is a modern and efficient C++ library for Wayland. This library aims to provide a smooth and easy-to-use interface
for developers to build Wayland-based applications using C++.

## Compatible Compositors

* Mutter
* Weston
* Wlroots

## Installation

### Debian
Expand Down
38 changes: 19 additions & 19 deletions examples/simple-egl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ struct weston_matrix {
* 3 7 11 15
*/

void weston_matrix_init(struct weston_matrix *matrix) {
static const struct weston_matrix identity = {
void weston_matrix_init(weston_matrix *matrix) {
static const weston_matrix identity = {
.d = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
.type = 0,
};
Expand All @@ -199,8 +199,8 @@ void weston_matrix_init(struct weston_matrix *matrix) {
}

/* m <- n * m, that is, m is multiplied on the LEFT. */
void weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix *n) {
struct weston_matrix tmp{};
void weston_matrix_multiply(weston_matrix *m, const weston_matrix *n) {
weston_matrix tmp{};
const float *row, *column;
int i, j, k;

Expand All @@ -217,17 +217,17 @@ void weston_matrix_multiply(struct weston_matrix *m, const struct weston_matrix
memcpy(m, &tmp, sizeof tmp);
}

void weston_matrix_scale(struct weston_matrix *matrix, float x, float y, float z) {
struct weston_matrix scale = {
void weston_matrix_scale(weston_matrix *matrix, float x, float y, float z) {
weston_matrix scale = {
.d = {x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1},
.type = WESTON_MATRIX_TRANSFORM_SCALE,
};

weston_matrix_multiply(matrix, &scale);
}

void weston_matrix_rotate_xy(struct weston_matrix *matrix, float cos, float sin) {
struct weston_matrix translate = {
void weston_matrix_rotate_xy(weston_matrix *matrix, float cos, float sin) {
weston_matrix translate = {
.d = {cos, sin, 0, 0, -sin, cos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1},
.type = WESTON_MATRIX_TRANSFORM_ROTATE,
};
Expand Down Expand Up @@ -303,7 +303,7 @@ static void draw_frame(void *userdata, uint32_t /* time */) {

window->update_buffer_geometry();

struct timeval tv{};
timeval tv{};
gettimeofday(&tv, nullptr);
auto time = static_cast<uint32_t>(tv.tv_sec * 1000 + tv.tv_usec / 1000);
if (frames == 0) {
Expand All @@ -325,7 +325,7 @@ static void draw_frame(void *userdata, uint32_t /* time */) {
angle = static_cast<GLfloat>(((time - initial_frame_time) / speed_div)
% 360 * M_PI / 180.0);
}
struct weston_matrix rotation{};
weston_matrix rotation{};
weston_matrix_init(&rotation);
rotation.d[0] = cos(angle);
rotation.d[2] = sin(angle);
Expand Down Expand Up @@ -383,7 +383,7 @@ static void draw_frame(void *userdata, uint32_t /* time */) {

class KeyboardHandler : public SeatObserver, public KeyboardObserver {
public:
void notify_seat_capabilities(Seat *seat, struct wl_seat * /* seat */, uint32_t /* caps */) override {
void notify_seat_capabilities(Seat *seat, wl_seat * /* seat */, uint32_t /* caps */) override {
if (seat) {
auto keyboard = seat->get_keyboard();
if (keyboard.has_value()) {
Expand All @@ -392,35 +392,35 @@ class KeyboardHandler : public SeatObserver, public KeyboardObserver {
}
}

void notify_seat_name(Seat * /* seat */, struct wl_seat * /* seat */, const char *name) override {
void notify_seat_name(Seat * /* seat */, wl_seat * /* seat */, const char *name) override {
spdlog::info("Seat: {}", name);
}

void notify_keyboard_enter(Keyboard * /* keyboard */,
struct wl_keyboard * /* wl_keyboard */,
wl_keyboard * /* wl_keyboard */,
uint32_t serial,
struct wl_surface *surface,
struct wl_array * /* keys */) override {
wl_surface *surface,
wl_array * /* keys */) override {
spdlog::info("Keyboard Enter: serial: {}, surface: {}", serial, fmt::ptr(surface));
}

void notify_keyboard_leave(Keyboard * /* keyboard */,
struct wl_keyboard * /* wl_keyboard */,
wl_keyboard * /* wl_keyboard */,
uint32_t serial,
struct wl_surface *surface) override {
wl_surface *surface) override {
spdlog::info("Keyboard Leave: serial: {}, surface: {}", serial, fmt::ptr(surface));
}

void notify_keyboard_keymap(Keyboard * /* keyboard */,
struct wl_keyboard * /* wl_keyboard */,
wl_keyboard * /* wl_keyboard */,
uint32_t format,
int32_t fd,
uint32_t size) override {
spdlog::info("Keymap: format: {}, fd: {}, size: {}", format, fd, size);
}

void notify_keyboard_key(Keyboard * /* keyboard */,
struct wl_keyboard * /* wl_keyboard */,
wl_keyboard * /* wl_keyboard */,
uint32_t serial,
uint32_t time,
uint32_t xkb_scancode,
Expand Down
42 changes: 21 additions & 21 deletions examples/simple-shm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver
return (top_level_->is_valid() && wm_->display_dispatch() != -1);
}

void notify_seat_capabilities(Seat *seat, struct wl_seat * /* seat */, uint32_t /* caps */) override {
void notify_seat_capabilities(Seat *seat, wl_seat * /* seat */, uint32_t /* caps */) override {
if (seat) {
auto keyboard = seat->get_keyboard();
if (keyboard.has_value()) {
Expand All @@ -178,35 +178,35 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver
}
}

void notify_seat_name(Seat * /* seat */, struct wl_seat * /* seat */, const char *name) override {
void notify_seat_name(Seat * /* seat */, wl_seat * /* seat */, const char *name) override {
spdlog::info("Seat: {}", name);
}

void notify_keyboard_enter(Keyboard * /* keyboard */,
struct wl_keyboard * /* wl_keyboard */,
wl_keyboard * /* wl_keyboard */,
uint32_t serial,
struct wl_surface *surface,
struct wl_array * /* keys */) override {
wl_surface *surface,
wl_array * /* keys */) override {
spdlog::info("Keyboard Enter: serial: {}, surface: {}", serial, fmt::ptr(surface));
}

void notify_keyboard_leave(Keyboard * /* keyboard */,
struct wl_keyboard * /* wl_keyboard */,
wl_keyboard * /* wl_keyboard */,
uint32_t serial,
struct wl_surface *surface) override {
wl_surface *surface) override {
spdlog::info("Keyboard Leave: serial: {}, surface: {}", serial, fmt::ptr(surface));
}

void notify_keyboard_keymap(Keyboard * /* keyboard */,
struct wl_keyboard * /* wl_keyboard */,
wl_keyboard * /* wl_keyboard */,
uint32_t format,
int32_t fd,
uint32_t size) override {
spdlog::info("Keymap: format: {}, fd: {}, size: {}", format, fd, size);
}

void notify_keyboard_key(Keyboard * /* keyboard */,
struct wl_keyboard * /* wl_keyboard */,
wl_keyboard * /* wl_keyboard */,
uint32_t serial,
uint32_t time,
uint32_t xkb_scancode,
Expand All @@ -221,32 +221,32 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver
}

void notify_pointer_enter(Pointer *pointer,
struct wl_pointer * /* pointer */,
wl_pointer * /* pointer */,
uint32_t serial,
struct wl_surface *surface,
wl_surface *surface,
double sx,
double sy) override {
spdlog::info("Pointer Enter: serial: {}, surface: {}, x: {}, y: {}", serial, fmt::ptr(surface), sx, sy);
pointer->set_cursor(serial);
pointer->set_cursor(serial, "crosshair");
}

void notify_pointer_leave(Pointer * /* pointer */,
struct wl_pointer * /* pointer */,
wl_pointer * /* pointer */,
uint32_t serial,
struct wl_surface *surface) override {
wl_surface *surface) override {
spdlog::info("Pointer Leave: serial: {}, surface: {}", serial, fmt::ptr(surface));
}

void notify_pointer_motion(Pointer * /* pointer */,
struct wl_pointer * /* pointer */,
wl_pointer * /* pointer */,
uint32_t time,
double sx,
double sy) override {
spdlog::info("Pointer: time: {}, x: {}, y: {}", time, sx, sy);
}

void notify_pointer_button(Pointer * /* pointer */,
struct wl_pointer * /* pointer */,
wl_pointer * /* pointer */,
uint32_t serial,
uint32_t time,
uint32_t button,
Expand All @@ -255,32 +255,32 @@ class App : public PointerObserver, public KeyboardObserver, public SeatObserver
}

void notify_pointer_axis(Pointer * /* pointer */,
struct wl_pointer * /* pointer */,
wl_pointer * /* pointer */,
uint32_t time,
uint32_t axis,
wl_fixed_t value) override {
spdlog::info("Pointer Axis: time: {}, axis: {}, value: {}", time, axis, value);
}

void notify_pointer_frame(Pointer * /* pointer */, struct wl_pointer * /* pointer */) override {
void notify_pointer_frame(Pointer * /* pointer */, wl_pointer * /* pointer */) override {
spdlog::info("Pointer Frame");
};

void notify_pointer_axis_source(Pointer * /* pointer */,
struct wl_pointer * /* pointer */,
wl_pointer * /* pointer */,
uint32_t axis_source) override {
spdlog::info("Pointer Axis Source: axis_source: {}", axis_source);
};

void notify_pointer_axis_stop(Pointer * /* pointer */,
struct wl_pointer * /* pointer */,
wl_pointer * /* pointer */,
uint32_t /* time */,
uint32_t axis) override {
spdlog::info("Pointer Axis Stop: axis: {}", axis);
};

void notify_pointer_axis_discrete(Pointer * /* pointer */,
struct wl_pointer * /*pointer */,
wl_pointer * /*pointer */,
uint32_t axis,
int32_t discrete) override {
spdlog::info("Pointer Axis Discrete: axis: {}, discrete: {}", axis, discrete);
Expand Down
26 changes: 16 additions & 10 deletions src/seat/pointer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ Pointer::Pointer(wl_pointer *pointer, struct wl_compositor *wl_compositor, const
wl_pointer_(pointer), wl_shm_(wl_shm), disable_cursor_(disable_cursor), size_(size) {
SPDLOG_DEBUG("Pointer");
wl_pointer_add_listener(pointer, &pointer_listener_, this);
if (!disable_cursor_) {
wl_surface_ = wl_compositor_create_surface(wl_compositor);
}
wl_surface_cursor_ = wl_compositor_create_surface(wl_compositor);
}

/**
Expand All @@ -51,8 +49,8 @@ Pointer::~Pointer() {
if (theme_) {
wl_cursor_theme_destroy(theme_);
}
if (wl_surface_) {
wl_surface_destroy(wl_surface_);
if (wl_surface_cursor_) {
wl_surface_destroy(wl_surface_cursor_);
}
if (wl_pointer_) {
wl_pointer_release(wl_pointer_);
Expand Down Expand Up @@ -298,7 +296,15 @@ void Pointer::handle_axis_discrete(void *data,
}

void Pointer::set_cursor(uint32_t serial, const char *name) {
if (disable_cursor_ || !wl_shm_.has_value()) {
if (disable_cursor_) {
wl_pointer_set_cursor(wl_pointer_, serial,
wl_surface_cursor_, 0, 0);
wl_surface_damage(wl_surface_cursor_, 0, 0, 0, 0);
wl_surface_commit(wl_surface_cursor_);
return;
}

if (!wl_shm_.has_value()) {
return;
}

Expand All @@ -321,11 +327,11 @@ void Pointer::set_cursor(uint32_t serial, const char *name) {
return;
}
wl_pointer_set_cursor(wl_pointer_, serial,
wl_surface_,
wl_surface_cursor_,
static_cast<int32_t>(image->hotspot_x),
static_cast<int32_t>(image->hotspot_y));
wl_surface_attach(wl_surface_, buffer, 0, 0);
wl_surface_damage(wl_surface_, 0, 0,
wl_surface_attach(wl_surface_cursor_, buffer, 0, 0);
wl_surface_damage(wl_surface_cursor_, 0, 0,
static_cast<int32_t>(image->width), static_cast<int32_t>(image->height));
wl_surface_commit(wl_surface_);
wl_surface_commit(wl_surface_cursor_);
}
4 changes: 3 additions & 1 deletion src/seat/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class Pointer {

void set_cursor(uint32_t serial, const char *name = "right_ptr");

[[nodiscard]] bool is_cursor_enabled() const { return !disable_cursor_; }

// Disallow copy and assign.
Pointer(const Pointer &) = delete;

Expand All @@ -104,7 +106,7 @@ class Pointer {
private:
struct wl_pointer *wl_pointer_;
std::list<PointerObserver *> observers_{};
struct wl_surface *wl_surface_;
struct wl_surface *wl_surface_cursor_;
struct wl_cursor_theme *theme_{};
const std::optional<struct wl_shm *> &wl_shm_;
bool disable_cursor_;
Expand Down
11 changes: 7 additions & 4 deletions src/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,13 @@ void Window::update_buffer_geometry() {
}
}

if (fractional_buffer_scale_ > 0.0)
wp_viewport_set_destination(viewport_,
new_viewport_dest_size.width,
new_viewport_dest_size.height);
if (fractional_buffer_scale_ > 0.0) {
if (viewport_) {
wp_viewport_set_destination(viewport_,
new_viewport_dest_size.width,
new_viewport_dest_size.height);
}
}

needs_buffer_geometry_update_ = false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/window/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ class Window {
int height;
} logical_size_;

bool init_buffers_;
bool needs_buffer_geometry_update_;

static void handle_surface_enter(void *data,
Expand Down Expand Up @@ -217,9 +216,9 @@ class Window {
#endif
};

struct wp_viewport *viewport_;
struct wp_viewport *viewport_{};

struct wp_fractional_scale_v1 *fractional_scale_;
struct wp_fractional_scale_v1 *fractional_scale_{};

static void handle_preferred_scale(void *data,
struct wp_fractional_scale_v1 *wp_fractional_scale_v1,
Expand Down
1 change: 0 additions & 1 deletion src/window/xdg_toplevel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ XdgTopLevel::XdgTopLevel(WindowManager *wm, const char *title, const char *app_i
}

wait_for_configure_ = true;
//wl_surface_damage(wl_surface_, 0, 0, width, height);
wl_surface_commit(wl_surface_);

// this makes the start-up from the beginning with the correct dimensions
Expand Down

0 comments on commit 81f233a

Please sign in to comment.