Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse events & friends for Wayland #1672

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1b479ae
Prepare environment
Caellian Jan 1, 2023
ae5afd5
Add Wayland event listeners for pointer
Caellian Nov 5, 2023
78ea7b6
Merge branch 'feature/wayland-mouse-events' of github.com:Caellian/co…
Caellian Nov 5, 2023
596fa72
Include mouse-events.h in llua.cc
Caellian Nov 5, 2023
9799417
Pass cursor move event to the script
Caellian Nov 5, 2023
51de904
Add support for all previously supported events
Caellian Nov 6, 2023
441d031
Improve Lua table data
Caellian Nov 6, 2023
fd9ea17
Add deprecation error and fix stack management
Caellian Nov 6, 2023
646d5d9
Fix lua stack pops in one of error branches
Caellian Nov 7, 2023
0bfb013
Fix X11 build
Caellian Nov 8, 2023
78cc998
Remove duplicate BUILD_MOUSE_EVENTS includes (again)
Caellian Nov 8, 2023
e595547
Tweaks
Caellian Nov 8, 2023
cc9e2a7
Add <array> import
Caellian Nov 8, 2023
be30bf0
Cleanup includes
Caellian Nov 8, 2023
4b67529
Remove uint to make MacOS happy
Caellian Nov 8, 2023
091efc3
Use SFINAE to collapse numeric pust_table_value impls
Caellian Nov 8, 2023
07b0c81
Cleanup display-x11 includes
Caellian Nov 8, 2023
ed76b16
Debug X11 enter & leave events
Caellian Nov 8, 2023
62a9519
Fix X11 area enter & leave bug
Caellian Nov 9, 2023
670323e
Modify CI and Nix flake
Caellian Nov 9, 2023
8f98f68
Simplify cursor checking
Caellian Nov 10, 2023
d16d977
Cleanup focus handling code on propagation
Caellian Nov 10, 2023
e0d210b
Handle movement through XInput if enabled
Caellian Nov 10, 2023
91b6796
Fix CMake script
Caellian Nov 10, 2023
9d07fc9
Update README.md to trigger CI
Caellian Nov 10, 2023
662cda8
Provide a notice when build options get disabled
Caellian Nov 10, 2023
2aebf68
Fix issues building without BUILD_ARGB flag
Caellian Nov 10, 2023
cc604bc
Fix DependentOptions splitting arguments on spaces
Caellian Nov 10, 2023
71e2860
Fix build & cleanup
Caellian Nov 10, 2023
cebc045
Hide Nvidia on non-linux OSs
Caellian Nov 10, 2023
9d20e72
Prevent infinite loop in DependentOption
Caellian Nov 10, 2023
2ce7796
Use core X11 events when Xinput is enabled
Caellian Nov 13, 2023
8016a0a
Namespace mouse-events.cc/.h
Caellian Nov 13, 2023
cbab03d
Improve speedgraph scale descriptions in docs
elamperti Nov 3, 2023
a2e25f6
Drop graph/linechart from web header
brndnmtthws Nov 8, 2023
347379e
Run npm audit fix
brndnmtthws Nov 8, 2023
5a59001
One more byte for error
brndnmtthws Nov 19, 2023
bbd18f5
Merge branch 'main' into Caellian-feature/wayland-mouse-events
brndnmtthws Nov 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 3rdparty/toluapp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Please note that the package source code is licensed under its own license.

project ( toluapp C )
cmake_minimum_required ( VERSION 3.4 )
cmake_minimum_required ( VERSION 3.15 )
brndnmtthws marked this conversation as resolved.
Show resolved Hide resolved
# Disable dist stuff, we're not installing this as a lib
# include ( cmake/dist.cmake )

Expand Down
6 changes: 4 additions & 2 deletions cmake/ConkyBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ if(BUILD_X11)
option(BUILD_XFT "Build Xft (freetype fonts) support" true)
option(BUILD_IMLIB2 "Enable Imlib2 support" true)
option(BUILD_XSHAPE "Enable Xshape support" true)
option(BUILD_MOUSE_EVENTS "Enable mouse event support" true)
else(BUILD_X11)
set(OWN_WINDOW false CACHE BOOL "Enable own_window support" FORCE)
set(BUILD_XDAMAGE false CACHE BOOL "Build Xdamage support" FORCE)
Expand All @@ -181,7 +180,6 @@ else(BUILD_X11)
set(BUILD_XFT false CACHE BOOL "Build Xft (freetype fonts) support" FORCE)
set(BUILD_IMLIB2 false CACHE BOOL "Enable Imlib2 support" FORCE)
set(BUILD_XSHAPE false CACHE BOOL "Enable Xshape support" FORCE)
set(BUILD_MOUSE_EVENTS false CACHE BOOL "Enable mouse event support" FORCE)
set(BUILD_NVIDIA false)
endif(BUILD_X11)

Expand All @@ -193,6 +191,10 @@ if(BUILD_WAYLAND)
set(BUILD_GUI true)
endif(BUILD_WAYLAND)

if(BUILD_GUI)
option(BUILD_MOUSE_EVENTS "Enable mouse event support" true)
endif(BUILD_GUI)

if(OWN_WINDOW)
option(BUILD_ARGB "Build ARGB (real transparency) support" true)
else(OWN_WINDOW)
Expand Down
7 changes: 3 additions & 4 deletions cmake/ConkyPlatformChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ set(conky_libs ${conky_libs} ${LUA_LIBRARIES})
set(conky_includes ${conky_includes} ${LUA_INCLUDE_DIR})
include_directories(3rdparty/toluapp/include)

if(BUILD_X11)
if(BUILD_GUI)
# Check for libraries used by Lua bindings
if(BUILD_LUA_CAIRO)
pkg_check_modules(CAIRO REQUIRED cairo>=1.14 cairo-xlib)
Expand All @@ -469,16 +469,15 @@ if(BUILD_X11)
set(luaimlib2_libs ${IMLIB2_LIBS} ${IMLIB2_LDFLAGS} ${LUA_LIBRARIES})
set(luaimlib2_includes
${IMLIB2_INCLUDE_DIRS}
${LUA_INCLUDE_DIR}
${X11_INCLUDE_DIR})
Caellian marked this conversation as resolved.
Show resolved Hide resolved
${LUA_INCLUDE_DIR})
endif(BUILD_LUA_IMLIB2)

if(BUILD_LUA_RSVG)
pkg_check_modules(RSVG REQUIRED librsvg-2.0>=2.52)
set(luarsvg_libs ${RSVG_LIBRARIES} ${LUA_LIBRARIES})
set(luarsvg_includes ${RSVG_INCLUDE_DIRS} ${LUA_INCLUDE_DIR})
endif(BUILD_LUA_RSVG)
endif(BUILD_X11)
endif(BUILD_GUI)

if(BUILD_AUDACIOUS)
set(WANT_GLIB true)
Expand Down
15 changes: 10 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ endif(BUILD_PORT_MONITORS)
if(BUILD_X11)
set(x11 x11.cc x11.h)
set(optional_sources ${optional_sources} ${x11})

if(BUILD_MOUSE_EVENTS)
set(mouse_events mouse-events.cc mouse-events.h)
set(optional_sources ${optional_sources} ${mouse_events})
endif(BUILD_MOUSE_EVENTS)
endif(BUILD_X11)

if(BUILD_GUI)
set(gui fonts.cc fonts.h gui.cc gui.h)
set(optional_sources ${optional_sources} ${gui})

if(BUILD_MOUSE_EVENTS)
set(mouse_events mouse-events.cc mouse-events.h)
set(optional_sources ${optional_sources} ${mouse_events})
endif(BUILD_MOUSE_EVENTS)
endif(BUILD_GUI)

if(BUILD_WAYLAND)
Expand Down Expand Up @@ -338,6 +338,11 @@ if(BUILD_INTEL_BACKLIGHT)
set(optional_sources ${optional_sources} ${intel_backlight})
endif(BUILD_INTEL_BACKLIGHT)

if(BUILD_MOUSE_EVENTS)
set(mouse_events mouse-events.cc mouse-events.h)
set(optional_sources ${optional_sources} ${mouse_events})
endif(BUILD_MOUSE_EVENTS)

if(BUILD_TESTS)
# Create a library strictly for testing
add_library(conky_core ${conky_sources} ${optional_sources})
Expand Down
181 changes: 179 additions & 2 deletions src/display-wayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
*/

#include <config.h>
#include <wayland-util.h>
#include <utility>
#include "logging.h"

#ifdef BUILD_WAYLAND
#include <wayland-client.h>
Expand All @@ -46,6 +49,7 @@

#endif /* BUILD_WAYLAND */

#include <cstdint>
#include <iostream>
#include <sstream>

Expand All @@ -59,6 +63,10 @@
#ifdef BUILD_WAYLAND
#include "fonts.h"
#endif
#ifdef BUILD_MOUSE_EVENTS
#include "mouse-events.h"
#include <map>
#endif

#pragma GCC diagnostic ignored "-Wunused-parameter"

Expand Down Expand Up @@ -292,7 +300,7 @@ struct {
struct wl_shm *shm;
struct wl_surface *surface;
struct wl_seat *seat;
/* struct wl_pointer *pointer;*/
struct wl_pointer *pointer;
struct wl_output *output;
struct xdg_wm_base *shell;
struct zwlr_layer_shell_v1 *layer_shell;
Expand Down Expand Up @@ -421,6 +429,168 @@ void window_layer_surface_set_size(struct window *window) {
global_window->rectangle.height);
}

#ifdef BUILD_MOUSE_EVENTS
static std::map<wl_pointer*, std::array<size_t, 2>> last_known_positions{};

static void on_pointer_enter(void *data, wl_pointer *pointer, uint32_t serial,
wl_surface *surface, wl_fixed_t surface_x,
wl_fixed_t surface_y) {
auto w = reinterpret_cast<struct window *>(data);

size_t x = static_cast<size_t>(wl_fixed_to_double(surface_x));
size_t y = static_cast<size_t>(wl_fixed_to_double(surface_y));
last_known_positions[pointer] = {x, y};

size_t abs_x = w->rectangle.x + x;
size_t abs_y = w->rectangle.y + y;

mouse_crossing_event event {
mouse_event_t::AREA_ENTER,
x,
y,
abs_x,
abs_y
};
llua_mouse_hook(event);
}

static void on_pointer_leave(void *data,
struct wl_pointer *pointer,
uint32_t serial,
struct wl_surface *surface) {
auto w = reinterpret_cast<struct window *>(data);

std::array<size_t, 2> last = last_known_positions[pointer];
size_t x = last[0];
size_t y = last[1];
size_t abs_x = w->rectangle.x + x;
size_t abs_y = w->rectangle.y + y;

mouse_crossing_event event {
mouse_event_t::AREA_LEAVE,
x,
y,
abs_x,
abs_y
};
llua_mouse_hook(event);
}

static void on_pointer_motion(void *data,
struct wl_pointer *pointer,
uint32_t _time,
wl_fixed_t surface_x,
wl_fixed_t surface_y) {
auto w = reinterpret_cast<struct window *>(data);

size_t x = static_cast<size_t>(wl_fixed_to_double(surface_x));
size_t y = static_cast<size_t>(wl_fixed_to_double(surface_y));
last_known_positions[pointer] = {x, y};

size_t abs_x = w->rectangle.x + x;
size_t abs_y = w->rectangle.y + y;

mouse_move_event event {
x,
y,
abs_x,
abs_y
};
llua_mouse_hook(event);
}

static void on_pointer_button(void *data,
struct wl_pointer *pointer,
uint32_t serial,
uint32_t time,
uint32_t button,
uint32_t state) {
auto w = reinterpret_cast<struct window *>(data);

std::array<size_t, 2> last = last_known_positions[pointer];
size_t x = last[0];
size_t y = last[1];
size_t abs_x = w->rectangle.x + x;
size_t abs_y = w->rectangle.y + y;

mouse_button_event event {
mouse_event_t::MOUSE_RELEASE,
x,
y,
abs_x,
abs_y,
static_cast<mouse_button_t>(button),
};

switch (static_cast<wl_pointer_button_state>(state)) {
case WL_POINTER_BUTTON_STATE_RELEASED:
// pass; default is MOUSE_RELEASE
break;
case WL_POINTER_BUTTON_STATE_PRESSED:
event.type = mouse_event_t::MOUSE_PRESS;
break;
default:
return;
}
llua_mouse_hook(event);
}

void on_pointer_axis(void *data,
struct wl_pointer *pointer,
uint32_t time,
uint32_t axis,
wl_fixed_t value) {
if (value == 0) return;

auto w = reinterpret_cast<struct window *>(data);

std::array<size_t, 2> last = last_known_positions[pointer];
size_t x = last[0];
size_t y = last[1];
size_t abs_x = w->rectangle.x + x;
size_t abs_y = w->rectangle.y + y;

mouse_scroll_event event {
x,
y,
abs_x,
abs_y,
scroll_direction_t::SCROLL_UP,
};

switch (static_cast<wl_pointer_axis>(axis)) {
case WL_POINTER_AXIS_VERTICAL_SCROLL:
event.direction = value > 0 ? scroll_direction_t::SCROLL_DOWN : scroll_direction_t::SCROLL_UP;
break;
case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
event.direction = value > 0 ? scroll_direction_t::SCROLL_RIGHT : scroll_direction_t::SCROLL_LEFT;
break;
default:
return;
}
llua_mouse_hook(event);
}

static void seat_capability_listener (void *data, wl_seat *seat, uint32_t capability_int) {
wl_seat_capability capabilities = static_cast<wl_seat_capability>(capability_int);
if (wl_globals.seat == seat) {
if ((capabilities & WL_SEAT_CAPABILITY_POINTER) > 0) {
wl_globals.pointer = wl_seat_get_pointer(seat);

static wl_pointer_listener listener {
.enter = on_pointer_enter,
.leave = on_pointer_leave,
.motion = on_pointer_motion,
.button = on_pointer_button,
.axis = on_pointer_axis,
};
wl_pointer_add_listener(wl_globals.pointer, &listener, data);
}
}
}
static void seat_name_listener(void *data, struct wl_seat *wl_seat, const char *name) {}
#endif /* BUILD_MOUSE_EVENTS */

bool display_output_wayland::initialize() {
epoll_fd = epoll_create1(0);
if (epoll_fd < 0) {
Expand Down Expand Up @@ -450,9 +620,16 @@ bool display_output_wayland::initialize() {
zwlr_layer_surface_v1_add_listener(global_window->layer_surface,
&layer_surface_listener, nullptr);

#ifdef BUILD_MOUSE_EVENTS
wl_seat_listener listener {
.capabilities = seat_capability_listener,
.name = seat_name_listener,
};
wl_seat_add_listener(wl_globals.seat, &listener, global_window);
#endif /* BUILD_MOUSE_EVENTS */

wl_surface_commit(global_window->surface);
wl_display_roundtrip(global_display);

wayland_create_window();
return true;
}
Expand Down
Loading
Loading