Merged
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
4 changes: 4 additions & 0 deletions src/remux/launcher.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,6 +603,10 @@ class App: public IApp:
fd := ui::MainLoop::in.touch.fd
bytes := write(fd, touch_flood, 512 * 8 * 4 * sizeof(input_event))

for i := 0; i < input::TouchEvent::MAX_SLOTS; i++:
ui::MainLoop::in.touch.prev_ev.slots[i].left = 0
ui::MainLoop::in.touch.event.slots[i].left = 0

// TODO: figure out the right events here to properly flood this device
void flood_button_queue():
fd := ui::MainLoop::in.button.fd
Expand Down
2 changes: 0 additions & 2 deletions src/rmkit/init.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,8 +48,6 @@ static void _rmkit_init():

fb := framebuffer::get()
ui::Widget::fb = fb.get()
w, h = fb->get_display_size()
input::MouseEvent::set_screen_size(w, h)

for auto s : { SIGINT, SIGTERM, SIGABRT, SIGSEGV}:
signal(s, _rmkit_exit)
113 changes: 29 additions & 84 deletions src/rmkit/input/events.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ namespace input:
#endif
return

def finalize():
virtual void initialize():
pass

virtual void finalize():
pass

virtual ~Event() = default
Expand DownExpand Up@@ -78,7 +81,7 @@ namespace input:

self.print_event(data)

def marshal(ButtonEvent &prev):
def marshal():
SynKeyEvent key_ev
key_ev.key = self.key
key_ev.is_pressed = self.is_pressed
Expand All@@ -89,20 +92,18 @@ namespace input:
public:
int x=-1, y=-1
int slot = 0, left = -1
bool lifted=false
static int MAX_SLOTS
struct Point:
int x=-1, y=-1, left=-1
;

vector<Point> slots;
TouchEvent():
slots.resize(10)

TouchEvent(const TouchEvent &t):
self.slot = t.slot
self.slots = t.slots
self.x = t.x
self.y = t.y
self.left = t.left
slots.resize(MAX_SLOTS)

void initialize():
self.lifted = false

handle_abs(input_event data):
switch data.code:
Expand All@@ -128,19 +129,14 @@ namespace input:
case ABS_MT_TRACKING_ID:
if slot >= 0:
slots[slot].left = self.left = data.value > -1
break
if self.left == 0:
self.lifted = true
Comment on lines -131 to +133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we see tracking_id -1 would we want to reset the slot to its initial -1, -1, -1 values? I assume tracking_id=-1 should mean that any existing x,y coords are invalid.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the tracking ID is set to -1, next time the slot is used it will get an X and Y coordinate, i believe.

one potential problem with setting to -1 at this point is that this event is still used (i believe) during mainloop's event dispatch.


break

def marshal(TouchEvent &prev):
def marshal():
SynMotionEvent syn_ev;

if self.x == -1:
self.x = prev.x
if self.y == -1:
self.y = prev.y
if self.left == -1:
self.left = prev.left

syn_ev.left = self.left
syn_ev.x = self.x
syn_ev.y = self.y
Expand All@@ -155,60 +151,24 @@ namespace input:
case 3:
self.handle_abs(data)

class MouseEvent: public Event:
public:
MouseEvent() {}
int x = 0, y = 0
signed char dx = 0, dy = 0
int left = 0 , right = 0 , middle = 0
static int width, height
static int tilt_x
static int tilt_y
static int pressure


static void set_screen_size(int w, h):
width = w
height = h

def update(input_event data):
self.print_event(data)

def marshal(MouseEvent &prev):
self.x = prev.x + self.dx
self.y = prev.y + self.dy
def count_fingers():
fingers := 0
for i := 0; i < MAX_SLOTS; i++:
if slots[i].left == 1:
fingers++

if self.y < 0:
self.y = 0
if self.x < 0:
self.x = 0
return fingers

if self.y >= self.height - 1:
self.y = (int) self.height - 5
def is_multitouch():
fingers := self.count_fingers()

if self.x >= self.width - 1:
self.x = (int) self.width - 5
if fingers > 1:
return true

o_x := self.x
o_y := self.height - self.y
if fingers == 0:
return false

if o_y >= self.height - 1:
o_y = self.height - 5

SynMotionEvent syn_ev;
syn_ev.x = o_x
syn_ev.y = o_y
syn_ev.left = self.left
syn_ev.right = self.right
syn_ev.pressure = MouseEvent::pressure
syn_ev.tilt_x = MouseEvent::tilt_x
syn_ev.tilt_y = MouseEvent::tilt_y

syn_ev.set_original(new MouseEvent(*self))
return syn_ev

int MouseEvent::width = 0
int MouseEvent::height = 0
int TouchEvent::MAX_SLOTS = 10

class WacomEvent: public Event:
public:
Expand All@@ -217,22 +177,11 @@ namespace input:
int btn_touch = -1
int eraser = -1

def marshal(WacomEvent &prev):
def marshal():
SynMotionEvent syn_ev;
syn_ev.x = self.x
syn_ev.y = self.y

if self.btn_touch == -1:
self.btn_touch = prev.btn_touch
if self.eraser == -1:
self.eraser = prev.eraser
if self.pressure == -1 || self.pressure == 0:
self.pressure = prev.pressure
if self.tilt_x == 0xFFFF:
self.tilt_x = prev.tilt_x
if self.tilt_y == 0xFFFF:
self.tilt_y = prev.tilt_y

syn_ev.pressure = self.pressure
syn_ev.tilt_x = self.tilt_x
syn_ev.tilt_y = self.tilt_y
Expand DownExpand Up@@ -279,7 +228,3 @@ namespace input:
self.handle_key(data)
case 3:
self.handle_abs(data)

int MouseEvent::pressure = 2000
int MouseEvent::tilt_x = 0
int MouseEvent::tilt_y = 0
12 changes: 9 additions & 3 deletions src/rmkit/input/gestures.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ namespace input:
debug "FILTERED JUMP X", ev.x, ev.y, ev.slot
return false

if ev.slot + 1 != self.fingers:
if ev.count_fingers() != self.fingers:
if DEBUG_GESTURE_FILTERS:
debug "FILTERED FINGERS", ev.x, ev.y, ev.slot
return false
Expand DownExpand Up@@ -198,7 +198,10 @@ namespace input:
handle_event(ev)

void handle_event(input::TouchEvent &ev):
if ev.slot >= self.fingers:
if abs(ev.y - start.y) > 10 or abs(ev.x - start.x) > 10:
self.valid = false

if ev.count_fingers() > self.fingers:
self.valid = false
else:
if duration > 0:
Expand All@@ -208,7 +211,10 @@ namespace input:


bool filter(input::TouchEvent &ev):
if ev.slot + 1 < self.fingers:
if ev.y == -1 or ev.x == -1:
return false

if ev.count_fingers() < self.fingers:
return false

return true
47 changes: 8 additions & 39 deletions src/rmkit/input/input.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,8 @@ namespace input:
clear():
self.events.clear()

def marshal(T ev):
EV syn_ev = ev.marshal(prev_ev)
prev_ev = ev
return syn_ev
def marshal(T &ev):
return ev.marshal()

void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
Expand All@@ -48,8 +46,9 @@ namespace input:
// in DEV mode we allow event coalescing between calls to read() for
// resim normally evdev will do one full event per read() call instead of
// splitting across multiple read() calls
T event
T event = prev_ev
#endif
event.initialize()

for int i = 0; i < bytes / sizeof(struct input_event); i++:
// debug fd, "READ EVENT", ev_data[i].type, ev_data[i].code, ev_data[i].value
Expand All@@ -59,30 +58,11 @@ namespace input:
#ifdef DEBUG_INPUT_EVENT
fprintf(stderr, "\n")
#endif
event = {} // clear the event?
prev_ev = event
event.initialize()
else:
event.update(ev_data[i])

// not going to use this on remarkable
void handle_mouse_fd():
unsigned char data[3]
int bytes = read(self.fd, data, sizeof(data));

#ifdef REMARKABLE
// we return after reading so that the socket is not indefinitely active
return
#endif

ev := T()
if bytes > 0:
ev.left = data[0]&0x1
ev.right = data[0]&0x2
ev.middle = data[0]&0x4
ev.dx = data[1]
ev.dy = data[2]
self.events.push_back(ev)


class Input:
private:

Expand All@@ -91,7 +71,6 @@ namespace input:
fd_set rdfs

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<MouseEvent, SynMotionEvent> mouse
InputClass<TouchEvent, SynMotionEvent> touch
InputClass<ButtonEvent, SynKeyEvent> button

Expand All@@ -102,8 +81,6 @@ namespace input:
FD_ZERO(&rdfs)

// dev only
if !USE_RESIM:
self.monitor(self.mouse.fd = open("/dev/input/mice", O_RDWR))
// used by remarkable
#ifdef REMARKABLE
self.open_device("/dev/input/event0")
Expand All@@ -130,7 +107,6 @@ namespace input:


~Input():
close(self.mouse.fd)
close(self.touch.fd)
close(self.wacom.fd)
close(self.button.fd)
Expand DownExpand Up@@ -159,7 +135,6 @@ namespace input:

void reset_events():
self.wacom.clear()
self.mouse.clear()
self.touch.clear()
self.button.clear()

Expand All@@ -180,14 +155,14 @@ namespace input:
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, true)

void ungrab():
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, false)


Expand All@@ -205,8 +180,6 @@ namespace input:
retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL)

if retval > 0:
if FD_ISSET(self.mouse.fd, &rdfs_cp):
self.mouse.handle_mouse_fd()
if FD_ISSET(self.wacom.fd, &rdfs_cp):
self.wacom.handle_event_fd()
if FD_ISSET(self.touch.fd, &rdfs_cp):
Expand All@@ -219,8 +192,6 @@ namespace input:
for auto ev : self.wacom.events:
self.all_motion_events.push_back(self.wacom.marshal(ev))

for auto ev : self.mouse.events:
self.all_motion_events.push_back(self.mouse.marshal(ev))

for auto ev : self.touch.events:
self.all_motion_events.push_back(self.touch.marshal(ev))
Expand All@@ -238,7 +209,5 @@ namespace input:
// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
return dynamic_cast<WacomEvent*>(syn_ev.original.get())
static MouseEvent* is_mouse_event(SynMotionEvent &syn_ev):
return dynamic_cast<MouseEvent*>(syn_ev.original.get())
static TouchEvent* is_touch_event(SynMotionEvent &syn_ev):
return dynamic_cast<TouchEvent*>(syn_ev.original.get())
9 changes: 2 additions & 7 deletions src/rmkit/ui/main_loop.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,17 +136,12 @@ namespace ui:

for auto ev: ui::MainLoop::in.touch.events:
for auto g : gestures:
lifted := false
for int s = 0; s <= ev.slot; s++:
if ev.slots[s].left == 0:
lifted = true
break

if lifted:
if ev.lifted:
if g->valid:
g->finalize()
g->reset()
else:
ev.count_fingers()
if g->filter(ev):
if !g->initialized:
if DEBUG_GESTURES:
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); (function(){ try { var __m = "github.com"; var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/remux/launcher.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,6 +603,10 @@ class App: public IApp:
fd := ui::MainLoop::in.touch.fd
bytes := write(fd, touch_flood, 512 * 8 * 4 * sizeof(input_event))

for i := 0; i < input::TouchEvent::MAX_SLOTS; i++:
ui::MainLoop::in.touch.prev_ev.slots[i].left = 0
ui::MainLoop::in.touch.event.slots[i].left = 0

// TODO: figure out the right events here to properly flood this device
void flood_button_queue():
fd := ui::MainLoop::in.button.fd
Expand Down
2 changes: 0 additions & 2 deletions src/rmkit/init.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,8 +48,6 @@ static void _rmkit_init():

fb := framebuffer::get()
ui::Widget::fb = fb.get()
w, h = fb->get_display_size()
input::MouseEvent::set_screen_size(w, h)

for auto s : { SIGINT, SIGTERM, SIGABRT, SIGSEGV}:
signal(s, _rmkit_exit)
113 changes: 29 additions & 84 deletions src/rmkit/input/events.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ namespace input:
#endif
return

def finalize():
virtual void initialize():
pass

virtual void finalize():
pass

virtual ~Event() = default
Expand DownExpand Up@@ -78,7 +81,7 @@ namespace input:

self.print_event(data)

def marshal(ButtonEvent &prev):
def marshal():
SynKeyEvent key_ev
key_ev.key = self.key
key_ev.is_pressed = self.is_pressed
Expand All@@ -89,20 +92,18 @@ namespace input:
public:
int x=-1, y=-1
int slot = 0, left = -1
bool lifted=false
static int MAX_SLOTS
struct Point:
int x=-1, y=-1, left=-1
;

vector<Point> slots;
TouchEvent():
slots.resize(10)

TouchEvent(const TouchEvent &t):
self.slot = t.slot
self.slots = t.slots
self.x = t.x
self.y = t.y
self.left = t.left
slots.resize(MAX_SLOTS)

void initialize():
self.lifted = false

handle_abs(input_event data):
switch data.code:
Expand All@@ -128,19 +129,14 @@ namespace input:
case ABS_MT_TRACKING_ID:
if slot >= 0:
slots[slot].left = self.left = data.value > -1
break
if self.left == 0:
self.lifted = true
Comment on lines -131 to +133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we see tracking_id -1 would we want to reset the slot to its initial -1, -1, -1 values? I assume tracking_id=-1 should mean that any existing x,y coords are invalid.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the tracking ID is set to -1, next time the slot is used it will get an X and Y coordinate, i believe.

one potential problem with setting to -1 at this point is that this event is still used (i believe) during mainloop's event dispatch.


break

def marshal(TouchEvent &prev):
def marshal():
SynMotionEvent syn_ev;

if self.x == -1:
self.x = prev.x
if self.y == -1:
self.y = prev.y
if self.left == -1:
self.left = prev.left

syn_ev.left = self.left
syn_ev.x = self.x
syn_ev.y = self.y
Expand All@@ -155,60 +151,24 @@ namespace input:
case 3:
self.handle_abs(data)

class MouseEvent: public Event:
public:
MouseEvent() {}
int x = 0, y = 0
signed char dx = 0, dy = 0
int left = 0 , right = 0 , middle = 0
static int width, height
static int tilt_x
static int tilt_y
static int pressure


static void set_screen_size(int w, h):
width = w
height = h

def update(input_event data):
self.print_event(data)

def marshal(MouseEvent &prev):
self.x = prev.x + self.dx
self.y = prev.y + self.dy
def count_fingers():
fingers := 0
for i := 0; i < MAX_SLOTS; i++:
if slots[i].left == 1:
fingers++

if self.y < 0:
self.y = 0
if self.x < 0:
self.x = 0
return fingers

if self.y >= self.height - 1:
self.y = (int) self.height - 5
def is_multitouch():
fingers := self.count_fingers()

if self.x >= self.width - 1:
self.x = (int) self.width - 5
if fingers > 1:
return true

o_x := self.x
o_y := self.height - self.y
if fingers == 0:
return false

if o_y >= self.height - 1:
o_y = self.height - 5

SynMotionEvent syn_ev;
syn_ev.x = o_x
syn_ev.y = o_y
syn_ev.left = self.left
syn_ev.right = self.right
syn_ev.pressure = MouseEvent::pressure
syn_ev.tilt_x = MouseEvent::tilt_x
syn_ev.tilt_y = MouseEvent::tilt_y

syn_ev.set_original(new MouseEvent(*self))
return syn_ev

int MouseEvent::width = 0
int MouseEvent::height = 0
int TouchEvent::MAX_SLOTS = 10

class WacomEvent: public Event:
public:
Expand All@@ -217,22 +177,11 @@ namespace input:
int btn_touch = -1
int eraser = -1

def marshal(WacomEvent &prev):
def marshal():
SynMotionEvent syn_ev;
syn_ev.x = self.x
syn_ev.y = self.y

if self.btn_touch == -1:
self.btn_touch = prev.btn_touch
if self.eraser == -1:
self.eraser = prev.eraser
if self.pressure == -1 || self.pressure == 0:
self.pressure = prev.pressure
if self.tilt_x == 0xFFFF:
self.tilt_x = prev.tilt_x
if self.tilt_y == 0xFFFF:
self.tilt_y = prev.tilt_y

syn_ev.pressure = self.pressure
syn_ev.tilt_x = self.tilt_x
syn_ev.tilt_y = self.tilt_y
Expand DownExpand Up@@ -279,7 +228,3 @@ namespace input:
self.handle_key(data)
case 3:
self.handle_abs(data)

int MouseEvent::pressure = 2000
int MouseEvent::tilt_x = 0
int MouseEvent::tilt_y = 0
12 changes: 9 additions & 3 deletions src/rmkit/input/gestures.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ namespace input:
debug "FILTERED JUMP X", ev.x, ev.y, ev.slot
return false

if ev.slot + 1 != self.fingers:
if ev.count_fingers() != self.fingers:
if DEBUG_GESTURE_FILTERS:
debug "FILTERED FINGERS", ev.x, ev.y, ev.slot
return false
Expand DownExpand Up@@ -198,7 +198,10 @@ namespace input:
handle_event(ev)

void handle_event(input::TouchEvent &ev):
if ev.slot >= self.fingers:
if abs(ev.y - start.y) > 10 or abs(ev.x - start.x) > 10:
self.valid = false

if ev.count_fingers() > self.fingers:
self.valid = false
else:
if duration > 0:
Expand All@@ -208,7 +211,10 @@ namespace input:


bool filter(input::TouchEvent &ev):
if ev.slot + 1 < self.fingers:
if ev.y == -1 or ev.x == -1:
return false

if ev.count_fingers() < self.fingers:
return false

return true
47 changes: 8 additions & 39 deletions src/rmkit/input/input.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,8 @@ namespace input:
clear():
self.events.clear()

def marshal(T ev):
EV syn_ev = ev.marshal(prev_ev)
prev_ev = ev
return syn_ev
def marshal(T &ev):
return ev.marshal()

void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
Expand All@@ -48,8 +46,9 @@ namespace input:
// in DEV mode we allow event coalescing between calls to read() for
// resim normally evdev will do one full event per read() call instead of
// splitting across multiple read() calls
T event
T event = prev_ev
#endif
event.initialize()

for int i = 0; i < bytes / sizeof(struct input_event); i++:
// debug fd, "READ EVENT", ev_data[i].type, ev_data[i].code, ev_data[i].value
Expand All@@ -59,30 +58,11 @@ namespace input:
#ifdef DEBUG_INPUT_EVENT
fprintf(stderr, "\n")
#endif
event = {} // clear the event?
prev_ev = event
event.initialize()
else:
event.update(ev_data[i])

// not going to use this on remarkable
void handle_mouse_fd():
unsigned char data[3]
int bytes = read(self.fd, data, sizeof(data));

#ifdef REMARKABLE
// we return after reading so that the socket is not indefinitely active
return
#endif

ev := T()
if bytes > 0:
ev.left = data[0]&0x1
ev.right = data[0]&0x2
ev.middle = data[0]&0x4
ev.dx = data[1]
ev.dy = data[2]
self.events.push_back(ev)


class Input:
private:

Expand All@@ -91,7 +71,6 @@ namespace input:
fd_set rdfs

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<MouseEvent, SynMotionEvent> mouse
InputClass<TouchEvent, SynMotionEvent> touch
InputClass<ButtonEvent, SynKeyEvent> button

Expand All@@ -102,8 +81,6 @@ namespace input:
FD_ZERO(&rdfs)

// dev only
if !USE_RESIM:
self.monitor(self.mouse.fd = open("/dev/input/mice", O_RDWR))
// used by remarkable
#ifdef REMARKABLE
self.open_device("/dev/input/event0")
Expand All@@ -130,7 +107,6 @@ namespace input:


~Input():
close(self.mouse.fd)
close(self.touch.fd)
close(self.wacom.fd)
close(self.button.fd)
Expand DownExpand Up@@ -159,7 +135,6 @@ namespace input:

void reset_events():
self.wacom.clear()
self.mouse.clear()
self.touch.clear()
self.button.clear()

Expand All@@ -180,14 +155,14 @@ namespace input:
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, true)

void ungrab():
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, false)


Expand All@@ -205,8 +180,6 @@ namespace input:
retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL)

if retval > 0:
if FD_ISSET(self.mouse.fd, &rdfs_cp):
self.mouse.handle_mouse_fd()
if FD_ISSET(self.wacom.fd, &rdfs_cp):
self.wacom.handle_event_fd()
if FD_ISSET(self.touch.fd, &rdfs_cp):
Expand All@@ -219,8 +192,6 @@ namespace input:
for auto ev : self.wacom.events:
self.all_motion_events.push_back(self.wacom.marshal(ev))

for auto ev : self.mouse.events:
self.all_motion_events.push_back(self.mouse.marshal(ev))

for auto ev : self.touch.events:
self.all_motion_events.push_back(self.touch.marshal(ev))
Expand All@@ -238,7 +209,5 @@ namespace input:
// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
return dynamic_cast<WacomEvent*>(syn_ev.original.get())
static MouseEvent* is_mouse_event(SynMotionEvent &syn_ev):
return dynamic_cast<MouseEvent*>(syn_ev.original.get())
static TouchEvent* is_touch_event(SynMotionEvent &syn_ev):
return dynamic_cast<TouchEvent*>(syn_ev.original.get())
9 changes: 2 additions & 7 deletions src/rmkit/ui/main_loop.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,17 +136,12 @@ namespace ui:

for auto ev: ui::MainLoop::in.touch.events:
for auto g : gestures:
lifted := false
for int s = 0; s <= ev.slot; s++:
if ev.slots[s].left == 0:
lifted = true
break

if lifted:
if ev.lifted:
if g->valid:
g->finalize()
g->reset()
else:
ev.count_fingers()
if g->filter(ev):
if !g->initialized:
if DEBUG_GESTURES:
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/remux/launcher.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,6 +603,10 @@ class App: public IApp:
fd := ui::MainLoop::in.touch.fd
bytes := write(fd, touch_flood, 512 * 8 * 4 * sizeof(input_event))

for i := 0; i < input::TouchEvent::MAX_SLOTS; i++:
ui::MainLoop::in.touch.prev_ev.slots[i].left = 0
ui::MainLoop::in.touch.event.slots[i].left = 0

// TODO: figure out the right events here to properly flood this device
void flood_button_queue():
fd := ui::MainLoop::in.button.fd
Expand Down
2 changes: 0 additions & 2 deletions src/rmkit/init.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,8 +48,6 @@ static void _rmkit_init():

fb := framebuffer::get()
ui::Widget::fb = fb.get()
w, h = fb->get_display_size()
input::MouseEvent::set_screen_size(w, h)

for auto s : { SIGINT, SIGTERM, SIGABRT, SIGSEGV}:
signal(s, _rmkit_exit)
113 changes: 29 additions & 84 deletions src/rmkit/input/events.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ namespace input:
#endif
return

def finalize():
virtual void initialize():
pass

virtual void finalize():
pass

virtual ~Event() = default
Expand DownExpand Up@@ -78,7 +81,7 @@ namespace input:

self.print_event(data)

def marshal(ButtonEvent &prev):
def marshal():
SynKeyEvent key_ev
key_ev.key = self.key
key_ev.is_pressed = self.is_pressed
Expand All@@ -89,20 +92,18 @@ namespace input:
public:
int x=-1, y=-1
int slot = 0, left = -1
bool lifted=false
static int MAX_SLOTS
struct Point:
int x=-1, y=-1, left=-1
;

vector<Point> slots;
TouchEvent():
slots.resize(10)

TouchEvent(const TouchEvent &t):
self.slot = t.slot
self.slots = t.slots
self.x = t.x
self.y = t.y
self.left = t.left
slots.resize(MAX_SLOTS)

void initialize():
self.lifted = false

handle_abs(input_event data):
switch data.code:
Expand All@@ -128,19 +129,14 @@ namespace input:
case ABS_MT_TRACKING_ID:
if slot >= 0:
slots[slot].left = self.left = data.value > -1
break
if self.left == 0:
self.lifted = true
Comment on lines -131 to +133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we see tracking_id -1 would we want to reset the slot to its initial -1, -1, -1 values? I assume tracking_id=-1 should mean that any existing x,y coords are invalid.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the tracking ID is set to -1, next time the slot is used it will get an X and Y coordinate, i believe.

one potential problem with setting to -1 at this point is that this event is still used (i believe) during mainloop's event dispatch.


break

def marshal(TouchEvent &prev):
def marshal():
SynMotionEvent syn_ev;

if self.x == -1:
self.x = prev.x
if self.y == -1:
self.y = prev.y
if self.left == -1:
self.left = prev.left

syn_ev.left = self.left
syn_ev.x = self.x
syn_ev.y = self.y
Expand All@@ -155,60 +151,24 @@ namespace input:
case 3:
self.handle_abs(data)

class MouseEvent: public Event:
public:
MouseEvent() {}
int x = 0, y = 0
signed char dx = 0, dy = 0
int left = 0 , right = 0 , middle = 0
static int width, height
static int tilt_x
static int tilt_y
static int pressure


static void set_screen_size(int w, h):
width = w
height = h

def update(input_event data):
self.print_event(data)

def marshal(MouseEvent &prev):
self.x = prev.x + self.dx
self.y = prev.y + self.dy
def count_fingers():
fingers := 0
for i := 0; i < MAX_SLOTS; i++:
if slots[i].left == 1:
fingers++

if self.y < 0:
self.y = 0
if self.x < 0:
self.x = 0
return fingers

if self.y >= self.height - 1:
self.y = (int) self.height - 5
def is_multitouch():
fingers := self.count_fingers()

if self.x >= self.width - 1:
self.x = (int) self.width - 5
if fingers > 1:
return true

o_x := self.x
o_y := self.height - self.y
if fingers == 0:
return false

if o_y >= self.height - 1:
o_y = self.height - 5

SynMotionEvent syn_ev;
syn_ev.x = o_x
syn_ev.y = o_y
syn_ev.left = self.left
syn_ev.right = self.right
syn_ev.pressure = MouseEvent::pressure
syn_ev.tilt_x = MouseEvent::tilt_x
syn_ev.tilt_y = MouseEvent::tilt_y

syn_ev.set_original(new MouseEvent(*self))
return syn_ev

int MouseEvent::width = 0
int MouseEvent::height = 0
int TouchEvent::MAX_SLOTS = 10

class WacomEvent: public Event:
public:
Expand All@@ -217,22 +177,11 @@ namespace input:
int btn_touch = -1
int eraser = -1

def marshal(WacomEvent &prev):
def marshal():
SynMotionEvent syn_ev;
syn_ev.x = self.x
syn_ev.y = self.y

if self.btn_touch == -1:
self.btn_touch = prev.btn_touch
if self.eraser == -1:
self.eraser = prev.eraser
if self.pressure == -1 || self.pressure == 0:
self.pressure = prev.pressure
if self.tilt_x == 0xFFFF:
self.tilt_x = prev.tilt_x
if self.tilt_y == 0xFFFF:
self.tilt_y = prev.tilt_y

syn_ev.pressure = self.pressure
syn_ev.tilt_x = self.tilt_x
syn_ev.tilt_y = self.tilt_y
Expand DownExpand Up@@ -279,7 +228,3 @@ namespace input:
self.handle_key(data)
case 3:
self.handle_abs(data)

int MouseEvent::pressure = 2000
int MouseEvent::tilt_x = 0
int MouseEvent::tilt_y = 0
12 changes: 9 additions & 3 deletions src/rmkit/input/gestures.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ namespace input:
debug "FILTERED JUMP X", ev.x, ev.y, ev.slot
return false

if ev.slot + 1 != self.fingers:
if ev.count_fingers() != self.fingers:
if DEBUG_GESTURE_FILTERS:
debug "FILTERED FINGERS", ev.x, ev.y, ev.slot
return false
Expand DownExpand Up@@ -198,7 +198,10 @@ namespace input:
handle_event(ev)

void handle_event(input::TouchEvent &ev):
if ev.slot >= self.fingers:
if abs(ev.y - start.y) > 10 or abs(ev.x - start.x) > 10:
self.valid = false

if ev.count_fingers() > self.fingers:
self.valid = false
else:
if duration > 0:
Expand All@@ -208,7 +211,10 @@ namespace input:


bool filter(input::TouchEvent &ev):
if ev.slot + 1 < self.fingers:
if ev.y == -1 or ev.x == -1:
return false

if ev.count_fingers() < self.fingers:
return false

return true
47 changes: 8 additions & 39 deletions src/rmkit/input/input.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,8 @@ namespace input:
clear():
self.events.clear()

def marshal(T ev):
EV syn_ev = ev.marshal(prev_ev)
prev_ev = ev
return syn_ev
def marshal(T &ev):
return ev.marshal()

void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
Expand All@@ -48,8 +46,9 @@ namespace input:
// in DEV mode we allow event coalescing between calls to read() for
// resim normally evdev will do one full event per read() call instead of
// splitting across multiple read() calls
T event
T event = prev_ev
#endif
event.initialize()

for int i = 0; i < bytes / sizeof(struct input_event); i++:
// debug fd, "READ EVENT", ev_data[i].type, ev_data[i].code, ev_data[i].value
Expand All@@ -59,30 +58,11 @@ namespace input:
#ifdef DEBUG_INPUT_EVENT
fprintf(stderr, "\n")
#endif
event = {} // clear the event?
prev_ev = event
event.initialize()
else:
event.update(ev_data[i])

// not going to use this on remarkable
void handle_mouse_fd():
unsigned char data[3]
int bytes = read(self.fd, data, sizeof(data));

#ifdef REMARKABLE
// we return after reading so that the socket is not indefinitely active
return
#endif

ev := T()
if bytes > 0:
ev.left = data[0]&0x1
ev.right = data[0]&0x2
ev.middle = data[0]&0x4
ev.dx = data[1]
ev.dy = data[2]
self.events.push_back(ev)


class Input:
private:

Expand All@@ -91,7 +71,6 @@ namespace input:
fd_set rdfs

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<MouseEvent, SynMotionEvent> mouse
InputClass<TouchEvent, SynMotionEvent> touch
InputClass<ButtonEvent, SynKeyEvent> button

Expand All@@ -102,8 +81,6 @@ namespace input:
FD_ZERO(&rdfs)

// dev only
if !USE_RESIM:
self.monitor(self.mouse.fd = open("/dev/input/mice", O_RDWR))
// used by remarkable
#ifdef REMARKABLE
self.open_device("/dev/input/event0")
Expand All@@ -130,7 +107,6 @@ namespace input:


~Input():
close(self.mouse.fd)
close(self.touch.fd)
close(self.wacom.fd)
close(self.button.fd)
Expand DownExpand Up@@ -159,7 +135,6 @@ namespace input:

void reset_events():
self.wacom.clear()
self.mouse.clear()
self.touch.clear()
self.button.clear()

Expand All@@ -180,14 +155,14 @@ namespace input:
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, true)

void ungrab():
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, false)


Expand All@@ -205,8 +180,6 @@ namespace input:
retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL)

if retval > 0:
if FD_ISSET(self.mouse.fd, &rdfs_cp):
self.mouse.handle_mouse_fd()
if FD_ISSET(self.wacom.fd, &rdfs_cp):
self.wacom.handle_event_fd()
if FD_ISSET(self.touch.fd, &rdfs_cp):
Expand All@@ -219,8 +192,6 @@ namespace input:
for auto ev : self.wacom.events:
self.all_motion_events.push_back(self.wacom.marshal(ev))

for auto ev : self.mouse.events:
self.all_motion_events.push_back(self.mouse.marshal(ev))

for auto ev : self.touch.events:
self.all_motion_events.push_back(self.touch.marshal(ev))
Expand All@@ -238,7 +209,5 @@ namespace input:
// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
return dynamic_cast<WacomEvent*>(syn_ev.original.get())
static MouseEvent* is_mouse_event(SynMotionEvent &syn_ev):
return dynamic_cast<MouseEvent*>(syn_ev.original.get())
static TouchEvent* is_touch_event(SynMotionEvent &syn_ev):
return dynamic_cast<TouchEvent*>(syn_ev.original.get())
9 changes: 2 additions & 7 deletions src/rmkit/ui/main_loop.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,17 +136,12 @@ namespace ui:

for auto ev: ui::MainLoop::in.touch.events:
for auto g : gestures:
lifted := false
for int s = 0; s <= ev.slot; s++:
if ev.slots[s].left == 0:
lifted = true
break

if lifted:
if ev.lifted:
if g->valid:
g->finalize()
g->reset()
else:
ev.count_fingers()
if g->filter(ev):
if !g->initialized:
if DEBUG_GESTURES:
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length \u003e 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/remux/launcher.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,6 +603,10 @@ class App: public IApp:
fd := ui::MainLoop::in.touch.fd
bytes := write(fd, touch_flood, 512 * 8 * 4 * sizeof(input_event))

for i := 0; i < input::TouchEvent::MAX_SLOTS; i++:
ui::MainLoop::in.touch.prev_ev.slots[i].left = 0
ui::MainLoop::in.touch.event.slots[i].left = 0

// TODO: figure out the right events here to properly flood this device
void flood_button_queue():
fd := ui::MainLoop::in.button.fd
Expand Down
2 changes: 0 additions & 2 deletions src/rmkit/init.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,8 +48,6 @@ static void _rmkit_init():

fb := framebuffer::get()
ui::Widget::fb = fb.get()
w, h = fb->get_display_size()
input::MouseEvent::set_screen_size(w, h)

for auto s : { SIGINT, SIGTERM, SIGABRT, SIGSEGV}:
signal(s, _rmkit_exit)
113 changes: 29 additions & 84 deletions src/rmkit/input/events.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ namespace input:
#endif
return

def finalize():
virtual void initialize():
pass

virtual void finalize():
pass

virtual ~Event() = default
Expand DownExpand Up@@ -78,7 +81,7 @@ namespace input:

self.print_event(data)

def marshal(ButtonEvent &prev):
def marshal():
SynKeyEvent key_ev
key_ev.key = self.key
key_ev.is_pressed = self.is_pressed
Expand All@@ -89,20 +92,18 @@ namespace input:
public:
int x=-1, y=-1
int slot = 0, left = -1
bool lifted=false
static int MAX_SLOTS
struct Point:
int x=-1, y=-1, left=-1
;

vector<Point> slots;
TouchEvent():
slots.resize(10)

TouchEvent(const TouchEvent &t):
self.slot = t.slot
self.slots = t.slots
self.x = t.x
self.y = t.y
self.left = t.left
slots.resize(MAX_SLOTS)

void initialize():
self.lifted = false

handle_abs(input_event data):
switch data.code:
Expand All@@ -128,19 +129,14 @@ namespace input:
case ABS_MT_TRACKING_ID:
if slot >= 0:
slots[slot].left = self.left = data.value > -1
break
if self.left == 0:
self.lifted = true
Comment on lines -131 to +133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we see tracking_id -1 would we want to reset the slot to its initial -1, -1, -1 values? I assume tracking_id=-1 should mean that any existing x,y coords are invalid.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the tracking ID is set to -1, next time the slot is used it will get an X and Y coordinate, i believe.

one potential problem with setting to -1 at this point is that this event is still used (i believe) during mainloop's event dispatch.


break

def marshal(TouchEvent &prev):
def marshal():
SynMotionEvent syn_ev;

if self.x == -1:
self.x = prev.x
if self.y == -1:
self.y = prev.y
if self.left == -1:
self.left = prev.left

syn_ev.left = self.left
syn_ev.x = self.x
syn_ev.y = self.y
Expand All@@ -155,60 +151,24 @@ namespace input:
case 3:
self.handle_abs(data)

class MouseEvent: public Event:
public:
MouseEvent() {}
int x = 0, y = 0
signed char dx = 0, dy = 0
int left = 0 , right = 0 , middle = 0
static int width, height
static int tilt_x
static int tilt_y
static int pressure


static void set_screen_size(int w, h):
width = w
height = h

def update(input_event data):
self.print_event(data)

def marshal(MouseEvent &prev):
self.x = prev.x + self.dx
self.y = prev.y + self.dy
def count_fingers():
fingers := 0
for i := 0; i < MAX_SLOTS; i++:
if slots[i].left == 1:
fingers++

if self.y < 0:
self.y = 0
if self.x < 0:
self.x = 0
return fingers

if self.y >= self.height - 1:
self.y = (int) self.height - 5
def is_multitouch():
fingers := self.count_fingers()

if self.x >= self.width - 1:
self.x = (int) self.width - 5
if fingers > 1:
return true

o_x := self.x
o_y := self.height - self.y
if fingers == 0:
return false

if o_y >= self.height - 1:
o_y = self.height - 5

SynMotionEvent syn_ev;
syn_ev.x = o_x
syn_ev.y = o_y
syn_ev.left = self.left
syn_ev.right = self.right
syn_ev.pressure = MouseEvent::pressure
syn_ev.tilt_x = MouseEvent::tilt_x
syn_ev.tilt_y = MouseEvent::tilt_y

syn_ev.set_original(new MouseEvent(*self))
return syn_ev

int MouseEvent::width = 0
int MouseEvent::height = 0
int TouchEvent::MAX_SLOTS = 10

class WacomEvent: public Event:
public:
Expand All@@ -217,22 +177,11 @@ namespace input:
int btn_touch = -1
int eraser = -1

def marshal(WacomEvent &prev):
def marshal():
SynMotionEvent syn_ev;
syn_ev.x = self.x
syn_ev.y = self.y

if self.btn_touch == -1:
self.btn_touch = prev.btn_touch
if self.eraser == -1:
self.eraser = prev.eraser
if self.pressure == -1 || self.pressure == 0:
self.pressure = prev.pressure
if self.tilt_x == 0xFFFF:
self.tilt_x = prev.tilt_x
if self.tilt_y == 0xFFFF:
self.tilt_y = prev.tilt_y

syn_ev.pressure = self.pressure
syn_ev.tilt_x = self.tilt_x
syn_ev.tilt_y = self.tilt_y
Expand DownExpand Up@@ -279,7 +228,3 @@ namespace input:
self.handle_key(data)
case 3:
self.handle_abs(data)

int MouseEvent::pressure = 2000
int MouseEvent::tilt_x = 0
int MouseEvent::tilt_y = 0
12 changes: 9 additions & 3 deletions src/rmkit/input/gestures.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ namespace input:
debug "FILTERED JUMP X", ev.x, ev.y, ev.slot
return false

if ev.slot + 1 != self.fingers:
if ev.count_fingers() != self.fingers:
if DEBUG_GESTURE_FILTERS:
debug "FILTERED FINGERS", ev.x, ev.y, ev.slot
return false
Expand DownExpand Up@@ -198,7 +198,10 @@ namespace input:
handle_event(ev)

void handle_event(input::TouchEvent &ev):
if ev.slot >= self.fingers:
if abs(ev.y - start.y) > 10 or abs(ev.x - start.x) > 10:
self.valid = false

if ev.count_fingers() > self.fingers:
self.valid = false
else:
if duration > 0:
Expand All@@ -208,7 +211,10 @@ namespace input:


bool filter(input::TouchEvent &ev):
if ev.slot + 1 < self.fingers:
if ev.y == -1 or ev.x == -1:
return false

if ev.count_fingers() < self.fingers:
return false

return true
47 changes: 8 additions & 39 deletions src/rmkit/input/input.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,8 @@ namespace input:
clear():
self.events.clear()

def marshal(T ev):
EV syn_ev = ev.marshal(prev_ev)
prev_ev = ev
return syn_ev
def marshal(T &ev):
return ev.marshal()

void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
Expand All@@ -48,8 +46,9 @@ namespace input:
// in DEV mode we allow event coalescing between calls to read() for
// resim normally evdev will do one full event per read() call instead of
// splitting across multiple read() calls
T event
T event = prev_ev
#endif
event.initialize()

for int i = 0; i < bytes / sizeof(struct input_event); i++:
// debug fd, "READ EVENT", ev_data[i].type, ev_data[i].code, ev_data[i].value
Expand All@@ -59,30 +58,11 @@ namespace input:
#ifdef DEBUG_INPUT_EVENT
fprintf(stderr, "\n")
#endif
event = {} // clear the event?
prev_ev = event
event.initialize()
else:
event.update(ev_data[i])

// not going to use this on remarkable
void handle_mouse_fd():
unsigned char data[3]
int bytes = read(self.fd, data, sizeof(data));

#ifdef REMARKABLE
// we return after reading so that the socket is not indefinitely active
return
#endif

ev := T()
if bytes > 0:
ev.left = data[0]&0x1
ev.right = data[0]&0x2
ev.middle = data[0]&0x4
ev.dx = data[1]
ev.dy = data[2]
self.events.push_back(ev)


class Input:
private:

Expand All@@ -91,7 +71,6 @@ namespace input:
fd_set rdfs

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<MouseEvent, SynMotionEvent> mouse
InputClass<TouchEvent, SynMotionEvent> touch
InputClass<ButtonEvent, SynKeyEvent> button

Expand All@@ -102,8 +81,6 @@ namespace input:
FD_ZERO(&rdfs)

// dev only
if !USE_RESIM:
self.monitor(self.mouse.fd = open("/dev/input/mice", O_RDWR))
// used by remarkable
#ifdef REMARKABLE
self.open_device("/dev/input/event0")
Expand All@@ -130,7 +107,6 @@ namespace input:


~Input():
close(self.mouse.fd)
close(self.touch.fd)
close(self.wacom.fd)
close(self.button.fd)
Expand DownExpand Up@@ -159,7 +135,6 @@ namespace input:

void reset_events():
self.wacom.clear()
self.mouse.clear()
self.touch.clear()
self.button.clear()

Expand All@@ -180,14 +155,14 @@ namespace input:
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, true)

void ungrab():
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, false)


Expand All@@ -205,8 +180,6 @@ namespace input:
retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL)

if retval > 0:
if FD_ISSET(self.mouse.fd, &rdfs_cp):
self.mouse.handle_mouse_fd()
if FD_ISSET(self.wacom.fd, &rdfs_cp):
self.wacom.handle_event_fd()
if FD_ISSET(self.touch.fd, &rdfs_cp):
Expand All@@ -219,8 +192,6 @@ namespace input:
for auto ev : self.wacom.events:
self.all_motion_events.push_back(self.wacom.marshal(ev))

for auto ev : self.mouse.events:
self.all_motion_events.push_back(self.mouse.marshal(ev))

for auto ev : self.touch.events:
self.all_motion_events.push_back(self.touch.marshal(ev))
Expand All@@ -238,7 +209,5 @@ namespace input:
// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
return dynamic_cast<WacomEvent*>(syn_ev.original.get())
static MouseEvent* is_mouse_event(SynMotionEvent &syn_ev):
return dynamic_cast<MouseEvent*>(syn_ev.original.get())
static TouchEvent* is_touch_event(SynMotionEvent &syn_ev):
return dynamic_cast<TouchEvent*>(syn_ev.original.get())
9 changes: 2 additions & 7 deletions src/rmkit/ui/main_loop.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,17 +136,12 @@ namespace ui:

for auto ev: ui::MainLoop::in.touch.events:
for auto g : gestures:
lifted := false
for int s = 0; s <= ev.slot; s++:
if ev.slots[s].left == 0:
lifted = true
break

if lifted:
if ev.lifted:
if g->valid:
g->finalize()
g->reset()
else:
ev.count_fingers()
if g->filter(ev):
if !g->initialized:
if DEBUG_GESTURES:
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/remux/launcher.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,6 +603,10 @@ class App: public IApp:
fd := ui::MainLoop::in.touch.fd
bytes := write(fd, touch_flood, 512 * 8 * 4 * sizeof(input_event))

for i := 0; i < input::TouchEvent::MAX_SLOTS; i++:
ui::MainLoop::in.touch.prev_ev.slots[i].left = 0
ui::MainLoop::in.touch.event.slots[i].left = 0

// TODO: figure out the right events here to properly flood this device
void flood_button_queue():
fd := ui::MainLoop::in.button.fd
Expand Down
2 changes: 0 additions & 2 deletions src/rmkit/init.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,8 +48,6 @@ static void _rmkit_init():

fb := framebuffer::get()
ui::Widget::fb = fb.get()
w, h = fb->get_display_size()
input::MouseEvent::set_screen_size(w, h)

for auto s : { SIGINT, SIGTERM, SIGABRT, SIGSEGV}:
signal(s, _rmkit_exit)
113 changes: 29 additions & 84 deletions src/rmkit/input/events.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ namespace input:
#endif
return

def finalize():
virtual void initialize():
pass

virtual void finalize():
pass

virtual ~Event() = default
Expand DownExpand Up@@ -78,7 +81,7 @@ namespace input:

self.print_event(data)

def marshal(ButtonEvent &prev):
def marshal():
SynKeyEvent key_ev
key_ev.key = self.key
key_ev.is_pressed = self.is_pressed
Expand All@@ -89,20 +92,18 @@ namespace input:
public:
int x=-1, y=-1
int slot = 0, left = -1
bool lifted=false
static int MAX_SLOTS
struct Point:
int x=-1, y=-1, left=-1
;

vector<Point> slots;
TouchEvent():
slots.resize(10)

TouchEvent(const TouchEvent &t):
self.slot = t.slot
self.slots = t.slots
self.x = t.x
self.y = t.y
self.left = t.left
slots.resize(MAX_SLOTS)

void initialize():
self.lifted = false

handle_abs(input_event data):
switch data.code:
Expand All@@ -128,19 +129,14 @@ namespace input:
case ABS_MT_TRACKING_ID:
if slot >= 0:
slots[slot].left = self.left = data.value > -1
break
if self.left == 0:
self.lifted = true
Comment on lines -131 to +133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we see tracking_id -1 would we want to reset the slot to its initial -1, -1, -1 values? I assume tracking_id=-1 should mean that any existing x,y coords are invalid.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the tracking ID is set to -1, next time the slot is used it will get an X and Y coordinate, i believe.

one potential problem with setting to -1 at this point is that this event is still used (i believe) during mainloop's event dispatch.


break

def marshal(TouchEvent &prev):
def marshal():
SynMotionEvent syn_ev;

if self.x == -1:
self.x = prev.x
if self.y == -1:
self.y = prev.y
if self.left == -1:
self.left = prev.left

syn_ev.left = self.left
syn_ev.x = self.x
syn_ev.y = self.y
Expand All@@ -155,60 +151,24 @@ namespace input:
case 3:
self.handle_abs(data)

class MouseEvent: public Event:
public:
MouseEvent() {}
int x = 0, y = 0
signed char dx = 0, dy = 0
int left = 0 , right = 0 , middle = 0
static int width, height
static int tilt_x
static int tilt_y
static int pressure


static void set_screen_size(int w, h):
width = w
height = h

def update(input_event data):
self.print_event(data)

def marshal(MouseEvent &prev):
self.x = prev.x + self.dx
self.y = prev.y + self.dy
def count_fingers():
fingers := 0
for i := 0; i < MAX_SLOTS; i++:
if slots[i].left == 1:
fingers++

if self.y < 0:
self.y = 0
if self.x < 0:
self.x = 0
return fingers

if self.y >= self.height - 1:
self.y = (int) self.height - 5
def is_multitouch():
fingers := self.count_fingers()

if self.x >= self.width - 1:
self.x = (int) self.width - 5
if fingers > 1:
return true

o_x := self.x
o_y := self.height - self.y
if fingers == 0:
return false

if o_y >= self.height - 1:
o_y = self.height - 5

SynMotionEvent syn_ev;
syn_ev.x = o_x
syn_ev.y = o_y
syn_ev.left = self.left
syn_ev.right = self.right
syn_ev.pressure = MouseEvent::pressure
syn_ev.tilt_x = MouseEvent::tilt_x
syn_ev.tilt_y = MouseEvent::tilt_y

syn_ev.set_original(new MouseEvent(*self))
return syn_ev

int MouseEvent::width = 0
int MouseEvent::height = 0
int TouchEvent::MAX_SLOTS = 10

class WacomEvent: public Event:
public:
Expand All@@ -217,22 +177,11 @@ namespace input:
int btn_touch = -1
int eraser = -1

def marshal(WacomEvent &prev):
def marshal():
SynMotionEvent syn_ev;
syn_ev.x = self.x
syn_ev.y = self.y

if self.btn_touch == -1:
self.btn_touch = prev.btn_touch
if self.eraser == -1:
self.eraser = prev.eraser
if self.pressure == -1 || self.pressure == 0:
self.pressure = prev.pressure
if self.tilt_x == 0xFFFF:
self.tilt_x = prev.tilt_x
if self.tilt_y == 0xFFFF:
self.tilt_y = prev.tilt_y

syn_ev.pressure = self.pressure
syn_ev.tilt_x = self.tilt_x
syn_ev.tilt_y = self.tilt_y
Expand DownExpand Up@@ -279,7 +228,3 @@ namespace input:
self.handle_key(data)
case 3:
self.handle_abs(data)

int MouseEvent::pressure = 2000
int MouseEvent::tilt_x = 0
int MouseEvent::tilt_y = 0
12 changes: 9 additions & 3 deletions src/rmkit/input/gestures.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ namespace input:
debug "FILTERED JUMP X", ev.x, ev.y, ev.slot
return false

if ev.slot + 1 != self.fingers:
if ev.count_fingers() != self.fingers:
if DEBUG_GESTURE_FILTERS:
debug "FILTERED FINGERS", ev.x, ev.y, ev.slot
return false
Expand DownExpand Up@@ -198,7 +198,10 @@ namespace input:
handle_event(ev)

void handle_event(input::TouchEvent &ev):
if ev.slot >= self.fingers:
if abs(ev.y - start.y) > 10 or abs(ev.x - start.x) > 10:
self.valid = false

if ev.count_fingers() > self.fingers:
self.valid = false
else:
if duration > 0:
Expand All@@ -208,7 +211,10 @@ namespace input:


bool filter(input::TouchEvent &ev):
if ev.slot + 1 < self.fingers:
if ev.y == -1 or ev.x == -1:
return false

if ev.count_fingers() < self.fingers:
return false

return true
47 changes: 8 additions & 39 deletions src/rmkit/input/input.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,8 @@ namespace input:
clear():
self.events.clear()

def marshal(T ev):
EV syn_ev = ev.marshal(prev_ev)
prev_ev = ev
return syn_ev
def marshal(T &ev):
return ev.marshal()

void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
Expand All@@ -48,8 +46,9 @@ namespace input:
// in DEV mode we allow event coalescing between calls to read() for
// resim normally evdev will do one full event per read() call instead of
// splitting across multiple read() calls
T event
T event = prev_ev
#endif
event.initialize()

for int i = 0; i < bytes / sizeof(struct input_event); i++:
// debug fd, "READ EVENT", ev_data[i].type, ev_data[i].code, ev_data[i].value
Expand All@@ -59,30 +58,11 @@ namespace input:
#ifdef DEBUG_INPUT_EVENT
fprintf(stderr, "\n")
#endif
event = {} // clear the event?
prev_ev = event
event.initialize()
else:
event.update(ev_data[i])

// not going to use this on remarkable
void handle_mouse_fd():
unsigned char data[3]
int bytes = read(self.fd, data, sizeof(data));

#ifdef REMARKABLE
// we return after reading so that the socket is not indefinitely active
return
#endif

ev := T()
if bytes > 0:
ev.left = data[0]&0x1
ev.right = data[0]&0x2
ev.middle = data[0]&0x4
ev.dx = data[1]
ev.dy = data[2]
self.events.push_back(ev)


class Input:
private:

Expand All@@ -91,7 +71,6 @@ namespace input:
fd_set rdfs

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<MouseEvent, SynMotionEvent> mouse
InputClass<TouchEvent, SynMotionEvent> touch
InputClass<ButtonEvent, SynKeyEvent> button

Expand All@@ -102,8 +81,6 @@ namespace input:
FD_ZERO(&rdfs)

// dev only
if !USE_RESIM:
self.monitor(self.mouse.fd = open("/dev/input/mice", O_RDWR))
// used by remarkable
#ifdef REMARKABLE
self.open_device("/dev/input/event0")
Expand All@@ -130,7 +107,6 @@ namespace input:


~Input():
close(self.mouse.fd)
close(self.touch.fd)
close(self.wacom.fd)
close(self.button.fd)
Expand DownExpand Up@@ -159,7 +135,6 @@ namespace input:

void reset_events():
self.wacom.clear()
self.mouse.clear()
self.touch.clear()
self.button.clear()

Expand All@@ -180,14 +155,14 @@ namespace input:
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, true)

void ungrab():
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, false)


Expand All@@ -205,8 +180,6 @@ namespace input:
retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL)

if retval > 0:
if FD_ISSET(self.mouse.fd, &rdfs_cp):
self.mouse.handle_mouse_fd()
if FD_ISSET(self.wacom.fd, &rdfs_cp):
self.wacom.handle_event_fd()
if FD_ISSET(self.touch.fd, &rdfs_cp):
Expand All@@ -219,8 +192,6 @@ namespace input:
for auto ev : self.wacom.events:
self.all_motion_events.push_back(self.wacom.marshal(ev))

for auto ev : self.mouse.events:
self.all_motion_events.push_back(self.mouse.marshal(ev))

for auto ev : self.touch.events:
self.all_motion_events.push_back(self.touch.marshal(ev))
Expand All@@ -238,7 +209,5 @@ namespace input:
// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
return dynamic_cast<WacomEvent*>(syn_ev.original.get())
static MouseEvent* is_mouse_event(SynMotionEvent &syn_ev):
return dynamic_cast<MouseEvent*>(syn_ev.original.get())
static TouchEvent* is_touch_event(SynMotionEvent &syn_ev):
return dynamic_cast<TouchEvent*>(syn_ev.original.get())
9 changes: 2 additions & 7 deletions src/rmkit/ui/main_loop.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,17 +136,12 @@ namespace ui:

for auto ev: ui::MainLoop::in.touch.events:
for auto g : gestures:
lifted := false
for int s = 0; s <= ev.slot; s++:
if ev.slots[s].left == 0:
lifted = true
break

if lifted:
if ev.lifted:
if g->valid:
g->finalize()
g->reset()
else:
ev.count_fingers()
if g->filter(ev):
if !g->initialized:
if DEBUG_GESTURES:
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/remux/launcher.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,6 +603,10 @@ class App: public IApp:
fd := ui::MainLoop::in.touch.fd
bytes := write(fd, touch_flood, 512 * 8 * 4 * sizeof(input_event))

for i := 0; i < input::TouchEvent::MAX_SLOTS; i++:
ui::MainLoop::in.touch.prev_ev.slots[i].left = 0
ui::MainLoop::in.touch.event.slots[i].left = 0

// TODO: figure out the right events here to properly flood this device
void flood_button_queue():
fd := ui::MainLoop::in.button.fd
Expand Down
2 changes: 0 additions & 2 deletions src/rmkit/init.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,8 +48,6 @@ static void _rmkit_init():

fb := framebuffer::get()
ui::Widget::fb = fb.get()
w, h = fb->get_display_size()
input::MouseEvent::set_screen_size(w, h)

for auto s : { SIGINT, SIGTERM, SIGABRT, SIGSEGV}:
signal(s, _rmkit_exit)
113 changes: 29 additions & 84 deletions src/rmkit/input/events.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ namespace input:
#endif
return

def finalize():
virtual void initialize():
pass

virtual void finalize():
pass

virtual ~Event() = default
Expand DownExpand Up@@ -78,7 +81,7 @@ namespace input:

self.print_event(data)

def marshal(ButtonEvent &prev):
def marshal():
SynKeyEvent key_ev
key_ev.key = self.key
key_ev.is_pressed = self.is_pressed
Expand All@@ -89,20 +92,18 @@ namespace input:
public:
int x=-1, y=-1
int slot = 0, left = -1
bool lifted=false
static int MAX_SLOTS
struct Point:
int x=-1, y=-1, left=-1
;

vector<Point> slots;
TouchEvent():
slots.resize(10)

TouchEvent(const TouchEvent &t):
self.slot = t.slot
self.slots = t.slots
self.x = t.x
self.y = t.y
self.left = t.left
slots.resize(MAX_SLOTS)

void initialize():
self.lifted = false

handle_abs(input_event data):
switch data.code:
Expand All@@ -128,19 +129,14 @@ namespace input:
case ABS_MT_TRACKING_ID:
if slot >= 0:
slots[slot].left = self.left = data.value > -1
break
if self.left == 0:
self.lifted = true
Comment on lines -131 to +133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we see tracking_id -1 would we want to reset the slot to its initial -1, -1, -1 values? I assume tracking_id=-1 should mean that any existing x,y coords are invalid.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the tracking ID is set to -1, next time the slot is used it will get an X and Y coordinate, i believe.

one potential problem with setting to -1 at this point is that this event is still used (i believe) during mainloop's event dispatch.


break

def marshal(TouchEvent &prev):
def marshal():
SynMotionEvent syn_ev;

if self.x == -1:
self.x = prev.x
if self.y == -1:
self.y = prev.y
if self.left == -1:
self.left = prev.left

syn_ev.left = self.left
syn_ev.x = self.x
syn_ev.y = self.y
Expand All@@ -155,60 +151,24 @@ namespace input:
case 3:
self.handle_abs(data)

class MouseEvent: public Event:
public:
MouseEvent() {}
int x = 0, y = 0
signed char dx = 0, dy = 0
int left = 0 , right = 0 , middle = 0
static int width, height
static int tilt_x
static int tilt_y
static int pressure


static void set_screen_size(int w, h):
width = w
height = h

def update(input_event data):
self.print_event(data)

def marshal(MouseEvent &prev):
self.x = prev.x + self.dx
self.y = prev.y + self.dy
def count_fingers():
fingers := 0
for i := 0; i < MAX_SLOTS; i++:
if slots[i].left == 1:
fingers++

if self.y < 0:
self.y = 0
if self.x < 0:
self.x = 0
return fingers

if self.y >= self.height - 1:
self.y = (int) self.height - 5
def is_multitouch():
fingers := self.count_fingers()

if self.x >= self.width - 1:
self.x = (int) self.width - 5
if fingers > 1:
return true

o_x := self.x
o_y := self.height - self.y
if fingers == 0:
return false

if o_y >= self.height - 1:
o_y = self.height - 5

SynMotionEvent syn_ev;
syn_ev.x = o_x
syn_ev.y = o_y
syn_ev.left = self.left
syn_ev.right = self.right
syn_ev.pressure = MouseEvent::pressure
syn_ev.tilt_x = MouseEvent::tilt_x
syn_ev.tilt_y = MouseEvent::tilt_y

syn_ev.set_original(new MouseEvent(*self))
return syn_ev

int MouseEvent::width = 0
int MouseEvent::height = 0
int TouchEvent::MAX_SLOTS = 10

class WacomEvent: public Event:
public:
Expand All@@ -217,22 +177,11 @@ namespace input:
int btn_touch = -1
int eraser = -1

def marshal(WacomEvent &prev):
def marshal():
SynMotionEvent syn_ev;
syn_ev.x = self.x
syn_ev.y = self.y

if self.btn_touch == -1:
self.btn_touch = prev.btn_touch
if self.eraser == -1:
self.eraser = prev.eraser
if self.pressure == -1 || self.pressure == 0:
self.pressure = prev.pressure
if self.tilt_x == 0xFFFF:
self.tilt_x = prev.tilt_x
if self.tilt_y == 0xFFFF:
self.tilt_y = prev.tilt_y

syn_ev.pressure = self.pressure
syn_ev.tilt_x = self.tilt_x
syn_ev.tilt_y = self.tilt_y
Expand DownExpand Up@@ -279,7 +228,3 @@ namespace input:
self.handle_key(data)
case 3:
self.handle_abs(data)

int MouseEvent::pressure = 2000
int MouseEvent::tilt_x = 0
int MouseEvent::tilt_y = 0
12 changes: 9 additions & 3 deletions src/rmkit/input/gestures.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ namespace input:
debug "FILTERED JUMP X", ev.x, ev.y, ev.slot
return false

if ev.slot + 1 != self.fingers:
if ev.count_fingers() != self.fingers:
if DEBUG_GESTURE_FILTERS:
debug "FILTERED FINGERS", ev.x, ev.y, ev.slot
return false
Expand DownExpand Up@@ -198,7 +198,10 @@ namespace input:
handle_event(ev)

void handle_event(input::TouchEvent &ev):
if ev.slot >= self.fingers:
if abs(ev.y - start.y) > 10 or abs(ev.x - start.x) > 10:
self.valid = false

if ev.count_fingers() > self.fingers:
self.valid = false
else:
if duration > 0:
Expand All@@ -208,7 +211,10 @@ namespace input:


bool filter(input::TouchEvent &ev):
if ev.slot + 1 < self.fingers:
if ev.y == -1 or ev.x == -1:
return false

if ev.count_fingers() < self.fingers:
return false

return true
47 changes: 8 additions & 39 deletions src/rmkit/input/input.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,8 @@ namespace input:
clear():
self.events.clear()

def marshal(T ev):
EV syn_ev = ev.marshal(prev_ev)
prev_ev = ev
return syn_ev
def marshal(T &ev):
return ev.marshal()

void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
Expand All@@ -48,8 +46,9 @@ namespace input:
// in DEV mode we allow event coalescing between calls to read() for
// resim normally evdev will do one full event per read() call instead of
// splitting across multiple read() calls
T event
T event = prev_ev
#endif
event.initialize()

for int i = 0; i < bytes / sizeof(struct input_event); i++:
// debug fd, "READ EVENT", ev_data[i].type, ev_data[i].code, ev_data[i].value
Expand All@@ -59,30 +58,11 @@ namespace input:
#ifdef DEBUG_INPUT_EVENT
fprintf(stderr, "\n")
#endif
event = {} // clear the event?
prev_ev = event
event.initialize()
else:
event.update(ev_data[i])

// not going to use this on remarkable
void handle_mouse_fd():
unsigned char data[3]
int bytes = read(self.fd, data, sizeof(data));

#ifdef REMARKABLE
// we return after reading so that the socket is not indefinitely active
return
#endif

ev := T()
if bytes > 0:
ev.left = data[0]&0x1
ev.right = data[0]&0x2
ev.middle = data[0]&0x4
ev.dx = data[1]
ev.dy = data[2]
self.events.push_back(ev)


class Input:
private:

Expand All@@ -91,7 +71,6 @@ namespace input:
fd_set rdfs

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<MouseEvent, SynMotionEvent> mouse
InputClass<TouchEvent, SynMotionEvent> touch
InputClass<ButtonEvent, SynKeyEvent> button

Expand All@@ -102,8 +81,6 @@ namespace input:
FD_ZERO(&rdfs)

// dev only
if !USE_RESIM:
self.monitor(self.mouse.fd = open("/dev/input/mice", O_RDWR))
// used by remarkable
#ifdef REMARKABLE
self.open_device("/dev/input/event0")
Expand All@@ -130,7 +107,6 @@ namespace input:


~Input():
close(self.mouse.fd)
close(self.touch.fd)
close(self.wacom.fd)
close(self.button.fd)
Expand DownExpand Up@@ -159,7 +135,6 @@ namespace input:

void reset_events():
self.wacom.clear()
self.mouse.clear()
self.touch.clear()
self.button.clear()

Expand All@@ -180,14 +155,14 @@ namespace input:
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, true)

void ungrab():
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, false)


Expand All@@ -205,8 +180,6 @@ namespace input:
retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL)

if retval > 0:
if FD_ISSET(self.mouse.fd, &rdfs_cp):
self.mouse.handle_mouse_fd()
if FD_ISSET(self.wacom.fd, &rdfs_cp):
self.wacom.handle_event_fd()
if FD_ISSET(self.touch.fd, &rdfs_cp):
Expand All@@ -219,8 +192,6 @@ namespace input:
for auto ev : self.wacom.events:
self.all_motion_events.push_back(self.wacom.marshal(ev))

for auto ev : self.mouse.events:
self.all_motion_events.push_back(self.mouse.marshal(ev))

for auto ev : self.touch.events:
self.all_motion_events.push_back(self.touch.marshal(ev))
Expand All@@ -238,7 +209,5 @@ namespace input:
// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
return dynamic_cast<WacomEvent*>(syn_ev.original.get())
static MouseEvent* is_mouse_event(SynMotionEvent &syn_ev):
return dynamic_cast<MouseEvent*>(syn_ev.original.get())
static TouchEvent* is_touch_event(SynMotionEvent &syn_ev):
return dynamic_cast<TouchEvent*>(syn_ev.original.get())
9 changes: 2 additions & 7 deletions src/rmkit/ui/main_loop.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,17 +136,12 @@ namespace ui:

for auto ev: ui::MainLoop::in.touch.events:
for auto g : gestures:
lifted := false
for int s = 0; s <= ev.slot; s++:
if ev.slots[s].left == 0:
lifted = true
break

if lifted:
if ev.lifted:
if g->valid:
g->finalize()
g->reset()
else:
ev.count_fingers()
if g->filter(ev):
if !g->initialized:
if DEBUG_GESTURES:
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/remux/launcher.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,6 +603,10 @@ class App: public IApp:
fd := ui::MainLoop::in.touch.fd
bytes := write(fd, touch_flood, 512 * 8 * 4 * sizeof(input_event))

for i := 0; i < input::TouchEvent::MAX_SLOTS; i++:
ui::MainLoop::in.touch.prev_ev.slots[i].left = 0
ui::MainLoop::in.touch.event.slots[i].left = 0

// TODO: figure out the right events here to properly flood this device
void flood_button_queue():
fd := ui::MainLoop::in.button.fd
Expand Down
2 changes: 0 additions & 2 deletions src/rmkit/init.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,8 +48,6 @@ static void _rmkit_init():

fb := framebuffer::get()
ui::Widget::fb = fb.get()
w, h = fb->get_display_size()
input::MouseEvent::set_screen_size(w, h)

for auto s : { SIGINT, SIGTERM, SIGABRT, SIGSEGV}:
signal(s, _rmkit_exit)
113 changes: 29 additions & 84 deletions src/rmkit/input/events.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ namespace input:
#endif
return

def finalize():
virtual void initialize():
pass

virtual void finalize():
pass

virtual ~Event() = default
Expand DownExpand Up@@ -78,7 +81,7 @@ namespace input:

self.print_event(data)

def marshal(ButtonEvent &prev):
def marshal():
SynKeyEvent key_ev
key_ev.key = self.key
key_ev.is_pressed = self.is_pressed
Expand All@@ -89,20 +92,18 @@ namespace input:
public:
int x=-1, y=-1
int slot = 0, left = -1
bool lifted=false
static int MAX_SLOTS
struct Point:
int x=-1, y=-1, left=-1
;

vector<Point> slots;
TouchEvent():
slots.resize(10)

TouchEvent(const TouchEvent &t):
self.slot = t.slot
self.slots = t.slots
self.x = t.x
self.y = t.y
self.left = t.left
slots.resize(MAX_SLOTS)

void initialize():
self.lifted = false

handle_abs(input_event data):
switch data.code:
Expand All@@ -128,19 +129,14 @@ namespace input:
case ABS_MT_TRACKING_ID:
if slot >= 0:
slots[slot].left = self.left = data.value > -1
break
if self.left == 0:
self.lifted = true
Comment on lines -131 to +133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we see tracking_id -1 would we want to reset the slot to its initial -1, -1, -1 values? I assume tracking_id=-1 should mean that any existing x,y coords are invalid.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the tracking ID is set to -1, next time the slot is used it will get an X and Y coordinate, i believe.

one potential problem with setting to -1 at this point is that this event is still used (i believe) during mainloop's event dispatch.


break

def marshal(TouchEvent &prev):
def marshal():
SynMotionEvent syn_ev;

if self.x == -1:
self.x = prev.x
if self.y == -1:
self.y = prev.y
if self.left == -1:
self.left = prev.left

syn_ev.left = self.left
syn_ev.x = self.x
syn_ev.y = self.y
Expand All@@ -155,60 +151,24 @@ namespace input:
case 3:
self.handle_abs(data)

class MouseEvent: public Event:
public:
MouseEvent() {}
int x = 0, y = 0
signed char dx = 0, dy = 0
int left = 0 , right = 0 , middle = 0
static int width, height
static int tilt_x
static int tilt_y
static int pressure


static void set_screen_size(int w, h):
width = w
height = h

def update(input_event data):
self.print_event(data)

def marshal(MouseEvent &prev):
self.x = prev.x + self.dx
self.y = prev.y + self.dy
def count_fingers():
fingers := 0
for i := 0; i < MAX_SLOTS; i++:
if slots[i].left == 1:
fingers++

if self.y < 0:
self.y = 0
if self.x < 0:
self.x = 0
return fingers

if self.y >= self.height - 1:
self.y = (int) self.height - 5
def is_multitouch():
fingers := self.count_fingers()

if self.x >= self.width - 1:
self.x = (int) self.width - 5
if fingers > 1:
return true

o_x := self.x
o_y := self.height - self.y
if fingers == 0:
return false

if o_y >= self.height - 1:
o_y = self.height - 5

SynMotionEvent syn_ev;
syn_ev.x = o_x
syn_ev.y = o_y
syn_ev.left = self.left
syn_ev.right = self.right
syn_ev.pressure = MouseEvent::pressure
syn_ev.tilt_x = MouseEvent::tilt_x
syn_ev.tilt_y = MouseEvent::tilt_y

syn_ev.set_original(new MouseEvent(*self))
return syn_ev

int MouseEvent::width = 0
int MouseEvent::height = 0
int TouchEvent::MAX_SLOTS = 10

class WacomEvent: public Event:
public:
Expand All@@ -217,22 +177,11 @@ namespace input:
int btn_touch = -1
int eraser = -1

def marshal(WacomEvent &prev):
def marshal():
SynMotionEvent syn_ev;
syn_ev.x = self.x
syn_ev.y = self.y

if self.btn_touch == -1:
self.btn_touch = prev.btn_touch
if self.eraser == -1:
self.eraser = prev.eraser
if self.pressure == -1 || self.pressure == 0:
self.pressure = prev.pressure
if self.tilt_x == 0xFFFF:
self.tilt_x = prev.tilt_x
if self.tilt_y == 0xFFFF:
self.tilt_y = prev.tilt_y

syn_ev.pressure = self.pressure
syn_ev.tilt_x = self.tilt_x
syn_ev.tilt_y = self.tilt_y
Expand DownExpand Up@@ -279,7 +228,3 @@ namespace input:
self.handle_key(data)
case 3:
self.handle_abs(data)

int MouseEvent::pressure = 2000
int MouseEvent::tilt_x = 0
int MouseEvent::tilt_y = 0
12 changes: 9 additions & 3 deletions src/rmkit/input/gestures.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ namespace input:
debug "FILTERED JUMP X", ev.x, ev.y, ev.slot
return false

if ev.slot + 1 != self.fingers:
if ev.count_fingers() != self.fingers:
if DEBUG_GESTURE_FILTERS:
debug "FILTERED FINGERS", ev.x, ev.y, ev.slot
return false
Expand DownExpand Up@@ -198,7 +198,10 @@ namespace input:
handle_event(ev)

void handle_event(input::TouchEvent &ev):
if ev.slot >= self.fingers:
if abs(ev.y - start.y) > 10 or abs(ev.x - start.x) > 10:
self.valid = false

if ev.count_fingers() > self.fingers:
self.valid = false
else:
if duration > 0:
Expand All@@ -208,7 +211,10 @@ namespace input:


bool filter(input::TouchEvent &ev):
if ev.slot + 1 < self.fingers:
if ev.y == -1 or ev.x == -1:
return false

if ev.count_fingers() < self.fingers:
return false

return true
47 changes: 8 additions & 39 deletions src/rmkit/input/input.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,8 @@ namespace input:
clear():
self.events.clear()

def marshal(T ev):
EV syn_ev = ev.marshal(prev_ev)
prev_ev = ev
return syn_ev
def marshal(T &ev):
return ev.marshal()

void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
Expand All@@ -48,8 +46,9 @@ namespace input:
// in DEV mode we allow event coalescing between calls to read() for
// resim normally evdev will do one full event per read() call instead of
// splitting across multiple read() calls
T event
T event = prev_ev
#endif
event.initialize()

for int i = 0; i < bytes / sizeof(struct input_event); i++:
// debug fd, "READ EVENT", ev_data[i].type, ev_data[i].code, ev_data[i].value
Expand All@@ -59,30 +58,11 @@ namespace input:
#ifdef DEBUG_INPUT_EVENT
fprintf(stderr, "\n")
#endif
event = {} // clear the event?
prev_ev = event
event.initialize()
else:
event.update(ev_data[i])

// not going to use this on remarkable
void handle_mouse_fd():
unsigned char data[3]
int bytes = read(self.fd, data, sizeof(data));

#ifdef REMARKABLE
// we return after reading so that the socket is not indefinitely active
return
#endif

ev := T()
if bytes > 0:
ev.left = data[0]&0x1
ev.right = data[0]&0x2
ev.middle = data[0]&0x4
ev.dx = data[1]
ev.dy = data[2]
self.events.push_back(ev)


class Input:
private:

Expand All@@ -91,7 +71,6 @@ namespace input:
fd_set rdfs

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<MouseEvent, SynMotionEvent> mouse
InputClass<TouchEvent, SynMotionEvent> touch
InputClass<ButtonEvent, SynKeyEvent> button

Expand All@@ -102,8 +81,6 @@ namespace input:
FD_ZERO(&rdfs)

// dev only
if !USE_RESIM:
self.monitor(self.mouse.fd = open("/dev/input/mice", O_RDWR))
// used by remarkable
#ifdef REMARKABLE
self.open_device("/dev/input/event0")
Expand All@@ -130,7 +107,6 @@ namespace input:


~Input():
close(self.mouse.fd)
close(self.touch.fd)
close(self.wacom.fd)
close(self.button.fd)
Expand DownExpand Up@@ -159,7 +135,6 @@ namespace input:

void reset_events():
self.wacom.clear()
self.mouse.clear()
self.touch.clear()
self.button.clear()

Expand All@@ -180,14 +155,14 @@ namespace input:
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, true)

void ungrab():
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, false)


Expand All@@ -205,8 +180,6 @@ namespace input:
retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL)

if retval > 0:
if FD_ISSET(self.mouse.fd, &rdfs_cp):
self.mouse.handle_mouse_fd()
if FD_ISSET(self.wacom.fd, &rdfs_cp):
self.wacom.handle_event_fd()
if FD_ISSET(self.touch.fd, &rdfs_cp):
Expand All@@ -219,8 +192,6 @@ namespace input:
for auto ev : self.wacom.events:
self.all_motion_events.push_back(self.wacom.marshal(ev))

for auto ev : self.mouse.events:
self.all_motion_events.push_back(self.mouse.marshal(ev))

for auto ev : self.touch.events:
self.all_motion_events.push_back(self.touch.marshal(ev))
Expand All@@ -238,7 +209,5 @@ namespace input:
// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
return dynamic_cast<WacomEvent*>(syn_ev.original.get())
static MouseEvent* is_mouse_event(SynMotionEvent &syn_ev):
return dynamic_cast<MouseEvent*>(syn_ev.original.get())
static TouchEvent* is_touch_event(SynMotionEvent &syn_ev):
return dynamic_cast<TouchEvent*>(syn_ev.original.get())
9 changes: 2 additions & 7 deletions src/rmkit/ui/main_loop.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,17 +136,12 @@ namespace ui:

for auto ev: ui::MainLoop::in.touch.events:
for auto g : gestures:
lifted := false
for int s = 0; s <= ev.slot; s++:
if ev.slots[s].left == 0:
lifted = true
break

if lifted:
if ev.lifted:
if g->valid:
g->finalize()
g->reset()
else:
ev.count_fingers()
if g->filter(ev):
if !g->initialized:
if DEBUG_GESTURES:
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/remux/launcher.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -603,6 +603,10 @@ class App: public IApp:
fd := ui::MainLoop::in.touch.fd
bytes := write(fd, touch_flood, 512 * 8 * 4 * sizeof(input_event))

for i := 0; i < input::TouchEvent::MAX_SLOTS; i++:
ui::MainLoop::in.touch.prev_ev.slots[i].left = 0
ui::MainLoop::in.touch.event.slots[i].left = 0

// TODO: figure out the right events here to properly flood this device
void flood_button_queue():
fd := ui::MainLoop::in.button.fd
Expand Down
2 changes: 0 additions & 2 deletions src/rmkit/init.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,8 +48,6 @@ static void _rmkit_init():

fb := framebuffer::get()
ui::Widget::fb = fb.get()
w, h = fb->get_display_size()
input::MouseEvent::set_screen_size(w, h)

for auto s : { SIGINT, SIGTERM, SIGABRT, SIGSEGV}:
signal(s, _rmkit_exit)
113 changes: 29 additions & 84 deletions src/rmkit/input/events.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,10 @@ namespace input:
#endif
return

def finalize():
virtual void initialize():
pass

virtual void finalize():
pass

virtual ~Event() = default
Expand DownExpand Up@@ -78,7 +81,7 @@ namespace input:

self.print_event(data)

def marshal(ButtonEvent &prev):
def marshal():
SynKeyEvent key_ev
key_ev.key = self.key
key_ev.is_pressed = self.is_pressed
Expand All@@ -89,20 +92,18 @@ namespace input:
public:
int x=-1, y=-1
int slot = 0, left = -1
bool lifted=false
static int MAX_SLOTS
struct Point:
int x=-1, y=-1, left=-1
;

vector<Point> slots;
TouchEvent():
slots.resize(10)

TouchEvent(const TouchEvent &t):
self.slot = t.slot
self.slots = t.slots
self.x = t.x
self.y = t.y
self.left = t.left
slots.resize(MAX_SLOTS)

void initialize():
self.lifted = false

handle_abs(input_event data):
switch data.code:
Expand All@@ -128,19 +129,14 @@ namespace input:
case ABS_MT_TRACKING_ID:
if slot >= 0:
slots[slot].left = self.left = data.value > -1
break
if self.left == 0:
self.lifted = true
Comment on lines -131 to +133

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we see tracking_id -1 would we want to reset the slot to its initial -1, -1, -1 values? I assume tracking_id=-1 should mean that any existing x,y coords are invalid.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the tracking ID is set to -1, next time the slot is used it will get an X and Y coordinate, i believe.

one potential problem with setting to -1 at this point is that this event is still used (i believe) during mainloop's event dispatch.


break

def marshal(TouchEvent &prev):
def marshal():
SynMotionEvent syn_ev;

if self.x == -1:
self.x = prev.x
if self.y == -1:
self.y = prev.y
if self.left == -1:
self.left = prev.left

syn_ev.left = self.left
syn_ev.x = self.x
syn_ev.y = self.y
Expand All@@ -155,60 +151,24 @@ namespace input:
case 3:
self.handle_abs(data)

class MouseEvent: public Event:
public:
MouseEvent() {}
int x = 0, y = 0
signed char dx = 0, dy = 0
int left = 0 , right = 0 , middle = 0
static int width, height
static int tilt_x
static int tilt_y
static int pressure


static void set_screen_size(int w, h):
width = w
height = h

def update(input_event data):
self.print_event(data)

def marshal(MouseEvent &prev):
self.x = prev.x + self.dx
self.y = prev.y + self.dy
def count_fingers():
fingers := 0
for i := 0; i < MAX_SLOTS; i++:
if slots[i].left == 1:
fingers++

if self.y < 0:
self.y = 0
if self.x < 0:
self.x = 0
return fingers

if self.y >= self.height - 1:
self.y = (int) self.height - 5
def is_multitouch():
fingers := self.count_fingers()

if self.x >= self.width - 1:
self.x = (int) self.width - 5
if fingers > 1:
return true

o_x := self.x
o_y := self.height - self.y
if fingers == 0:
return false

if o_y >= self.height - 1:
o_y = self.height - 5

SynMotionEvent syn_ev;
syn_ev.x = o_x
syn_ev.y = o_y
syn_ev.left = self.left
syn_ev.right = self.right
syn_ev.pressure = MouseEvent::pressure
syn_ev.tilt_x = MouseEvent::tilt_x
syn_ev.tilt_y = MouseEvent::tilt_y

syn_ev.set_original(new MouseEvent(*self))
return syn_ev

int MouseEvent::width = 0
int MouseEvent::height = 0
int TouchEvent::MAX_SLOTS = 10

class WacomEvent: public Event:
public:
Expand All@@ -217,22 +177,11 @@ namespace input:
int btn_touch = -1
int eraser = -1

def marshal(WacomEvent &prev):
def marshal():
SynMotionEvent syn_ev;
syn_ev.x = self.x
syn_ev.y = self.y

if self.btn_touch == -1:
self.btn_touch = prev.btn_touch
if self.eraser == -1:
self.eraser = prev.eraser
if self.pressure == -1 || self.pressure == 0:
self.pressure = prev.pressure
if self.tilt_x == 0xFFFF:
self.tilt_x = prev.tilt_x
if self.tilt_y == 0xFFFF:
self.tilt_y = prev.tilt_y

syn_ev.pressure = self.pressure
syn_ev.tilt_x = self.tilt_x
syn_ev.tilt_y = self.tilt_y
Expand DownExpand Up@@ -279,7 +228,3 @@ namespace input:
self.handle_key(data)
case 3:
self.handle_abs(data)

int MouseEvent::pressure = 2000
int MouseEvent::tilt_x = 0
int MouseEvent::tilt_y = 0
12 changes: 9 additions & 3 deletions src/rmkit/input/gestures.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ namespace input:
debug "FILTERED JUMP X", ev.x, ev.y, ev.slot
return false

if ev.slot + 1 != self.fingers:
if ev.count_fingers() != self.fingers:
if DEBUG_GESTURE_FILTERS:
debug "FILTERED FINGERS", ev.x, ev.y, ev.slot
return false
Expand DownExpand Up@@ -198,7 +198,10 @@ namespace input:
handle_event(ev)

void handle_event(input::TouchEvent &ev):
if ev.slot >= self.fingers:
if abs(ev.y - start.y) > 10 or abs(ev.x - start.x) > 10:
self.valid = false

if ev.count_fingers() > self.fingers:
self.valid = false
else:
if duration > 0:
Expand All@@ -208,7 +211,10 @@ namespace input:


bool filter(input::TouchEvent &ev):
if ev.slot + 1 < self.fingers:
if ev.y == -1 or ev.x == -1:
return false

if ev.count_fingers() < self.fingers:
return false

return true
47 changes: 8 additions & 39 deletions src/rmkit/input/input.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,10 +34,8 @@ namespace input:
clear():
self.events.clear()

def marshal(T ev):
EV syn_ev = ev.marshal(prev_ev)
prev_ev = ev
return syn_ev
def marshal(T &ev):
return ev.marshal()

void handle_event_fd():
int bytes = read(fd, ev_data, sizeof(input_event) * 64);
Expand All@@ -48,8 +46,9 @@ namespace input:
// in DEV mode we allow event coalescing between calls to read() for
// resim normally evdev will do one full event per read() call instead of
// splitting across multiple read() calls
T event
T event = prev_ev
#endif
event.initialize()

for int i = 0; i < bytes / sizeof(struct input_event); i++:
// debug fd, "READ EVENT", ev_data[i].type, ev_data[i].code, ev_data[i].value
Expand All@@ -59,30 +58,11 @@ namespace input:
#ifdef DEBUG_INPUT_EVENT
fprintf(stderr, "\n")
#endif
event = {} // clear the event?
prev_ev = event
event.initialize()
else:
event.update(ev_data[i])

// not going to use this on remarkable
void handle_mouse_fd():
unsigned char data[3]
int bytes = read(self.fd, data, sizeof(data));

#ifdef REMARKABLE
// we return after reading so that the socket is not indefinitely active
return
#endif

ev := T()
if bytes > 0:
ev.left = data[0]&0x1
ev.right = data[0]&0x2
ev.middle = data[0]&0x4
ev.dx = data[1]
ev.dy = data[2]
self.events.push_back(ev)


class Input:
private:

Expand All@@ -91,7 +71,6 @@ namespace input:
fd_set rdfs

InputClass<WacomEvent, SynMotionEvent> wacom
InputClass<MouseEvent, SynMotionEvent> mouse
InputClass<TouchEvent, SynMotionEvent> touch
InputClass<ButtonEvent, SynKeyEvent> button

Expand All@@ -102,8 +81,6 @@ namespace input:
FD_ZERO(&rdfs)

// dev only
if !USE_RESIM:
self.monitor(self.mouse.fd = open("/dev/input/mice", O_RDWR))
// used by remarkable
#ifdef REMARKABLE
self.open_device("/dev/input/event0")
Expand All@@ -130,7 +107,6 @@ namespace input:


~Input():
close(self.mouse.fd)
close(self.touch.fd)
close(self.wacom.fd)
close(self.button.fd)
Expand DownExpand Up@@ -159,7 +135,6 @@ namespace input:

void reset_events():
self.wacom.clear()
self.mouse.clear()
self.touch.clear()
self.button.clear()

Expand All@@ -180,14 +155,14 @@ namespace input:
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, true)

void ungrab():
#ifndef REMARKABLE
return
#endif
for auto fd : { self.mouse.fd, self.touch.fd, self.wacom.fd, self.button.fd }:
for auto fd : { self.touch.fd, self.wacom.fd, self.button.fd }:
ioctl(fd, EVIOCGRAB, false)


Expand All@@ -205,8 +180,6 @@ namespace input:
retval = select(max_fd, &rdfs_cp, NULL, NULL, NULL)

if retval > 0:
if FD_ISSET(self.mouse.fd, &rdfs_cp):
self.mouse.handle_mouse_fd()
if FD_ISSET(self.wacom.fd, &rdfs_cp):
self.wacom.handle_event_fd()
if FD_ISSET(self.touch.fd, &rdfs_cp):
Expand All@@ -219,8 +192,6 @@ namespace input:
for auto ev : self.wacom.events:
self.all_motion_events.push_back(self.wacom.marshal(ev))

for auto ev : self.mouse.events:
self.all_motion_events.push_back(self.mouse.marshal(ev))

for auto ev : self.touch.events:
self.all_motion_events.push_back(self.touch.marshal(ev))
Expand All@@ -238,7 +209,5 @@ namespace input:
// TODO: should we just put this in the SynMotionEvent?
static WacomEvent* is_wacom_event(SynMotionEvent &syn_ev):
return dynamic_cast<WacomEvent*>(syn_ev.original.get())
static MouseEvent* is_mouse_event(SynMotionEvent &syn_ev):
return dynamic_cast<MouseEvent*>(syn_ev.original.get())
static TouchEvent* is_touch_event(SynMotionEvent &syn_ev):
return dynamic_cast<TouchEvent*>(syn_ev.original.get())
9 changes: 2 additions & 7 deletions src/rmkit/ui/main_loop.cpy
Original file line numberDiff line numberDiff line change
Expand Up@@ -136,17 +136,12 @@ namespace ui:

for auto ev: ui::MainLoop::in.touch.events:
for auto g : gestures:
lifted := false
for int s = 0; s <= ev.slot; s++:
if ev.slots[s].left == 0:
lifted = true
break

if lifted:
if ev.lifted:
if g->valid:
g->finalize()
g->reset()
else:
ev.count_fingers()
if g->filter(ev):
if !g->initialized:
if DEBUG_GESTURES:
Expand Down