Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 nanovgXC
14 changes: 13 additions & 1 deletion syncscribble/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ include Makefile.wasm

else

SOURCES += linux/linuxtablet.c ../nanovgXC/glad/glad.c
SOURCES += linux/linuxtablet.c linux/linuxwayland.c ../nanovgXC/glad/glad.c
DEFS += SCRIBBLE_TEST_PATH='"$(CURDIR)/../scribbletest"'
DEBUG ?= 0
USE_SYSTEM_SDL ?= 0
Expand All @@ -283,6 +283,18 @@ else
endif
endif

WAYLAND ?= 1
WAYLAND_PROTOCOL_DIR=$(BUILDDIR)/wayland-protocols
ifneq ($(WAYLAND), 0)
SOURCES += \
$(WAYLAND_PROTOCOL_DIR)/wayland.c \
$(WAYLAND_PROTOCOL_DIR)/tablet-v2.c

INCSYS += $(WAYLAND_PROTOCOL_DIR)

PKGS += wayland-client
endif

# must use this instead of just -lpthread so the defines needed by force_glibc.h are created
CFLAGS = -pthread
# X11 and Xi needed for linuxtablet.c
Expand Down
7 changes: 7 additions & 0 deletions syncscribble/Makefile.custom
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: build run

build:
$(MAKE) -j8 USE_SYSTEM_SDL=1 DEBUG=0 CXXFLAGS=-g

run: build
SDL_VIDEODRIVER=wayland ./Release/Write
11 changes: 10 additions & 1 deletion syncscribble/Makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ DEPS=$(SRCBASE:%=$(OBJDIR)/%.d)
TGT=$(BUILDDIR)/$(TARGET)
# gcc will not create directories, so depend on existence of all directories in output folder
# sort removes duplicates (which cause make error)
BUILDDIRS=$(sort $(dir $(OBJ)))
BUILDDIRS=$(sort $(dir $(OBJ)) $(WAYLAND_PROTOCOL_DIR))

.PHONY: all tgz clean distclean sourcelist

Expand All @@ -96,6 +96,15 @@ $(OBJDIR)/%.o: %.c
$(TGT): $(OBJ)
$(LD) -o $@ $^ $(LDFLAGS) $(LIBS)

$(WAYLAND_PROTOCOL_DIR)/%.h: wayland-protocols/%.xml
wayland-scanner client-header < $< > $@

$(WAYLAND_PROTOCOL_DIR)/%.c: wayland-protocols/%.xml
wayland-scanner private-code < $< > $@

# TODO: there should be a better way...
linux/linuxwayland.c: $(WAYLAND_PROTOCOL_DIR)/wayland.h $(WAYLAND_PROTOCOL_DIR)/tablet-v2.h

$(TGZ): $(TGT) $(DISTRES)
strings $(TGT) | grep "^GLIBC_"
mkdir -p $(BUILDDIR)/.dist
Expand Down
24 changes: 24 additions & 0 deletions syncscribble/application.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "application.h"
#include "linux/linuxwayland.h"
#include "usvg/svgpainter.h"
#include "usvg/svgwriter.h"
#include "usvg/svgparser.h"
Expand All @@ -11,6 +12,7 @@
#include "windows/winhelper.h"
#include "SDL_syswm.h"
#elif PLATFORM_LINUX
#include "mainwindow.h"
#include "linux/linuxtablet.h"
#elif PLATFORM_OSX
#include "macos/macoshelper.h"
Expand Down Expand Up @@ -147,6 +149,27 @@ static void poolWait()
static int sdlEventFilter(void* app, SDL_Event* event)
{
#if PLATFORM_LINUX
switch(event->type) {
case SDL_FINGERDOWN:
case SDL_FINGERMOTION:
case SDL_FINGERUP: {
// TODO: check is wayland before this

// sdl touch event positions are between 0 and 1, ugui expects pixel position
// by default
int win_w, win_h;
SDL_GetWindowSize(static_cast<ScribbleApp*>(app)->win->sdlWindow, &win_w, &win_h);
event->tfinger.x *= win_w;
event->tfinger.y *= win_h;
event->tfinger.dx *= win_w;
event->tfinger.dy *= win_h;
const auto f = event->tfinger;
SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0, 0);
return 0;
}
default:
break;
}
if(event->type == SDL_SYSWMEVENT) {
linuxProcessXEvent(event);
return 0; // no further processing
Expand Down Expand Up @@ -412,6 +435,7 @@ int SDL_main(int argc, char* argv[])
#elif PLATFORM_OSX
macosDisableMouseCoalescing(); // get all tablet input points
#elif PLATFORM_LINUX
linuxInitWayland(sdlWindow);
linuxInitTablet(sdlWindow);
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); // linuxtablet.c handles touch events even if no pen
#elif PLATFORM_EMSCRIPTEN
Expand Down
58 changes: 47 additions & 11 deletions syncscribble/linux/linuxtablet.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "SDL_video.h"
#include <string.h>
#include <stdbool.h>
#include <ctype.h> // for tolower
#include <X11/extensions/XInput2.h>

Expand Down Expand Up @@ -40,11 +42,17 @@ static TabletData tabletData[MAX_TABLETS];
static size_t nTablets = 0;

static struct {
bool valid;
Atom absX, absY, absP, tiltX, tiltY, clipboard, imagePng, sdlSel, Incr, utf8String;
} XAtoms;

static int xinput2_opcode;

// TODO: union with XAtoms?
static struct {
bool valid;
} WlInfo;


static TabletData* findDevice(int sourceid)
{
Expand Down Expand Up @@ -380,8 +388,7 @@ static void processClipboardXEvent(XEvent* xevent)
}
}

void linuxProcessXEvent(SDL_Event* event)
{
static void _linuxProcessXEvent(SDL_Event *event) {
XEvent* xevent = &event->syswm.msg->msg.x11.event;
if(xevent->type == GenericEvent) {
XGenericEventCookie* cookie = &xevent->xcookie;
Expand All @@ -399,14 +406,17 @@ void linuxProcessXEvent(SDL_Event* event)
processClipboardXEvent(xevent);
}

int linuxInitTablet(SDL_Window* sdlwin)
void linuxProcessXEvent(SDL_Event* event)
{
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version)
if(!SDL_GetWindowWMInfo(sdlwin, &wmInfo))
return 0;
Display* xDisplay = wmInfo.info.x11.display;
Window xWindow = wmInfo.info.x11.window;
if (XAtoms.valid) {
_linuxProcessXEvent(event);
}
}

static int initXAtoms(SDL_SysWMinfo* wmInfo) {
XAtoms.valid = true;
Display* xDisplay = wmInfo->info.x11.display;
Window xWindow = wmInfo->info.x11.window;

XAtoms.clipboard = XInternAtom(xDisplay, "CLIPBOARD", 0);
XAtoms.imagePng = XInternAtom(xDisplay, "image/png", 0);
Expand Down Expand Up @@ -455,6 +465,25 @@ int linuxInitTablet(SDL_Window* sdlwin)
return nTablets;
}

int linuxInitTablet(SDL_Window* sdlwin)
{
XAtoms.valid = false;
WlInfo.valid = false;
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version)
if(!SDL_GetWindowWMInfo(sdlwin, &wmInfo))
return 0;

switch (wmInfo.subsystem) {
case SDL_SYSWM_X11:
return initXAtoms(&wmInfo);
case SDL_SYSWM_WAYLAND:
return 0;
default:
return 0;
}
}

#ifdef XINPUT2_TEST
// gcc -DXINPUT2_TEST -o xitest linuxtablet.c -lSDL2 -lX11 -lXi
// refs: /usr/include/X11/extensions/XInput2.h, XI2.h
Expand Down Expand Up @@ -501,8 +530,7 @@ int main(int argc, char* argv[])
// * https://stackoverflow.com/questions/27378318/c-get-string-from-clipboard-on-linux/44992938#44992938
// * https://github.com/glfw/glfw/blob/master/src/x11_window.c

int requestClipboard(SDL_Window* sdlwin)
{
static int requestXClipboard(SDL_Window* sdlwin) {
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version)
if(!SDL_GetWindowWMInfo(sdlwin, &wmInfo))
Expand All @@ -519,3 +547,11 @@ int requestClipboard(SDL_Window* sdlwin)
XConvertSelection(xDisplay, XAtoms.clipboard, XAtoms.imagePng, XAtoms.sdlSel, xWindow, CurrentTime);
return 1;
}

int requestClipboard(SDL_Window* sdlwin)
{
if (XAtoms.valid) {
return requestXClipboard(sdlwin);
}
return 0;
}
Loading