Skip to content

Commit

Permalink
[input] add has_stylus property to Input class
Browse files Browse the repository at this point in the history
this allows harmony to query for stylus presence
  • Loading branch information
okay committed Sep 26, 2023
1 parent 6efd145 commit 1de13cf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/harmony/app/canvas.cpy
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,13 @@ namespace app_ui:
eraser->set_framebuffer(self.layers[cur_layer].fb.get())

bool ignore_event(input::SynMotionEvent &ev):
#ifdef KOBO
ev.pressure = 0.5
ev.tilt_x = 0.5
ev.tilt_y = 0.5
return false
#else
if not ui::MainLoop::in.has_stylus:
ev.pressure = 0.5
ev.tilt_x = 0.5
ev.tilt_y = 0.5
return false

return input::is_touch_event(ev) != NULL
#endif


void on_mouse_move(input::SynMotionEvent &ev):
Expand Down
13 changes: 13 additions & 0 deletions src/rmkit/input/device_id.cpy
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ namespace input:

return UNKNOWN

static bool supports_stylus(int fd):
if fd <= 0:
return false

unsigned long bit[EV_MAX]
ioctl(fd, EVIOCGBIT(0, EV_MAX), bit)
if check_bit_set(fd, EV_KEY, BTN_TOOL_PEN):
return true
if check_bit_set(fd, EV_KEY, BTN_STYLUS) && test_bit(EV_ABS, bit):
return true

return false

static EV_TYPE id_by_name(int fd):
char name[256];
ioctl(fd, EVIOCGNAME(sizeof(name)), name);
Expand Down
10 changes: 10 additions & 0 deletions src/rmkit/input/input.cpy
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ namespace input:
fd = _fd
T::set_fd(fd)

bool supports_stylus():
return input::supports_stylus(fd)



void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
if bytes < sizeof(input_event) || bytes == -1:
Expand Down Expand Up @@ -89,6 +94,7 @@ namespace input:
public:
int max_fd
fd_set rdfs
bool has_stylus

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<TouchEvent, SynMotionEvent> touch
Expand Down Expand Up @@ -132,6 +138,7 @@ namespace input:

self.monitor(input::ipc_fd[0])
self.set_scaling(framebuffer::fb_info::display_width, framebuffer::fb_info::display_height)
self.has_stylus = supports_stylus()
return


Expand Down Expand Up @@ -286,6 +293,8 @@ namespace input:
#endif
return

bool supports_stylus():
return wacom.supports_stylus() || touch.supports_stylus()

// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
Expand All @@ -295,3 +304,4 @@ namespace input:
if evt != nullptr && evt->is_touch():
return evt
return nullptr

0 comments on commit 1de13cf

Please sign in to comment.