forked from rmkit-dev/rmkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.cpy
808 lines (638 loc) · 21.4 KB
/
launcher.cpy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
// LAUNCHER FOR REMARKABLE
#include <time.h>
#include <thread>
#include <chrono>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <dirent.h>
#include <algorithm>
#include <unordered_set>
#include <linux/input.h>
#include <chrono>
#include "../shared/proc.h"
#include "../build/rmkit.h"
#include "../genie/gesture_parser.h"
#include "config.h"
TIMEOUT := 1
// all time is in seconds
MIN := 60
HOURS := MIN * MIN
SUSPEND_THRESHOLD := MIN * 15 // default to 15 minutes
SHUTDOWN_THRESHOLD := HOURS * 10 // 10 hours
#include "apps.h"
DIALOG_WIDTH := 400
DIALOG_HEIGHT := 800
LAST_ACTION := 0
USE_KOREADER_WORKAROUND := false
string CURRENT_APP = "_"
string NAO_BIN="/opt/bin/nao"
// start with Remarkable preloaded in the launch list
// so we can switch back to it quickly
deque<string> _launched = { "Remarkable", "_" }
DEFAULT_LAUNCH_GESTURES := vector<string> %{
"gesture=swipe; direction=up; zone=0 0 0.1 1",
"gesture=swipe; direction=up; zone=0.9 0 1 1",
}
CONFIG := read_remux_config()
class IApp:
public:
virtual void launch(string) = 0;
virtual void on_suspend() = 0;
virtual void get_more() = 0;
virtual void show_launcher() = 0;
virtual void show_last_app() = 0;
class NaoButton: public ui::Button:
public:
IApp *app
NaoButton(int x, int y, int w, int h, IApp *a): ui::Button(x, y, w, h, "Get More Apps"):
self.app = a
void on_mouse_click(input::SynMotionEvent &ev):
self.app->get_more()
class SuspendButton: public ui::Button:
public:
IApp *app
SuspendButton(int x, int y, int w, int h, IApp *a): ui::Button(x, y, w, h, "Suspend"):
self.app = a
void on_mouse_click(input::SynMotionEvent &ev):
self.app->on_suspend()
class StatusBar: public ui::Button:
public:
StatusBar(int x, int y, int w, int h, string t): ui::Button(x, y, w, h, t):
pass
void render():
ui::Button::render()
self.fb->draw_rect(self.x, self.y, self.w, self.h, BLACK, false)
class AppBackground: public ui::Widget:
public:
int byte_size
bool snapped = false
map<string, framebuffer::VirtualFB*> app_buffers;
AppBackground(int x, y, w, h): ui::Widget(x, y, w, h):
self.byte_size = w*h*sizeof(remarkable_color)
def snapshot():
fb := framebuffer::get()
snapped = true
vfb := self.get_vfb()
debug "SNAPSHOTTING", CURRENT_APP
vfb->fbmem = (remarkable_color*) memcpy(vfb->fbmem, fb->fbmem, self.byte_size)
framebuffer::VirtualFB* get_vfb():
if app_buffers.find(CURRENT_APP) == app_buffers.end():
fw, fh := fb->get_display_size()
app_buffers[CURRENT_APP] = new framebuffer::VirtualFB(fw, fh)
app_buffers[CURRENT_APP]->clear_screen()
return app_buffers[CURRENT_APP]
void render():
if not snapped:
return
vfb := self.get_vfb()
debug "RENDERING", CURRENT_APP
if rm2fb::IN_RM2FB_SHIM:
fb->waveform_mode = WAVEFORM_MODE_GC16
else:
fb->waveform_mode = WAVEFORM_MODE_AUTO
memcpy(fb->fbmem, vfb->fbmem, self.byte_size)
fb->perform_redraw(true)
fb->dirty = 1
class AppDialog: public ui::Pager:
public:
vector<string> binaries
AppReader reader
IApp* app
AppDialog(int x, y, w, h, IApp* a): ui::Pager(x, y, w, h, self):
self.set_title("")
self.app = a
self.opt_h = 55
self.page_size = (self.h - 100) / self.opt_h
self.buttons = { "Get More Apps" }
void add_shortcuts():
// draw suspend button in bottom right
_w, _h := fb->get_display_size()
h_layout := ui::HorizontalLayout(0, 0, _w, _h, self.scene)
v_layout := ui::VerticalLayout(0, 0, _w, _h, self.scene)
b1 := new SuspendButton(0, 0, 200, 50, self.app)
h_layout.pack_end(b1)
v_layout.pack_end(b1)
// draw memory info
mem_info := proc::read_mem_total()
if mem_info.available > 0:
mem_str := string("Used Mem: ") + proc::join_path(%{
to_string(mem_info.used/1024),
to_string(mem_info.total/1024) }) + string("MB ")
stat_str := mem_str
cw := 350
b3 := new StatusBar(self.x+self.w-cw, self.y-50, cw, 50, stat_str)
b3->set_style(ui::Stylesheet().justify_right())
self.scene->add(b3)
void render():
ui::Pager::render()
self.fb->draw_line(self.x+self.w, self.y, self.x+self.w, self.y+self.h, 2, BLACK)
// render memory stats/
void populate():
self.reader.populate()
self.options = self.reader.get_binaries()
vector<RMApp> get_apps():
return self.reader.apps
void on_row_selected(string name):
CURRENT_APP = name
ui::MainLoop::hide_overlay()
void render_row(ui::HorizontalLayout *row, string option):
status := string("")
bin := string("")
for auto app : self.reader.apps:
if app.name == option or app.bin == option:
bin = app.bin
if app.is_running:
used := app.mem_usage / 1024
if used == 0:
status = "?MB"
else:
status = to_string(app.mem_usage / 1024) + string("MB")
c := new ui::Button(0, 0, 100, self.opt_h, status)
if bin != "":
c->mouse.click += PLS_LAMBDA(auto &ev) {
if bin == "xochitl":
return
vector<string> bins = { bin }
proc::groupkill(SIGKILL, bins)
if status != "":
c->text = "killed"
c->dirty = 1
}
c->set_style(ui::Stylesheet().justify_right())
d := new ui::DialogButton(0, 0, self.w-120, self.opt_h, self, option)
d->x_padding = 10
d->y_padding = 5
d->set_style(ui::Stylesheet().justify_left())
self.layout->pack_start(row)
row->pack_start(d)
row->pack_end(c)
class App: public IApp:
int lastpress
int is_pressed = false
AppDialog *app_dialog
AppBackground *app_bg
shared_ptr<framebuffer::FB> fb
mutex suspend_m
thread* idle_thread
thread* ipc_thread
input_event *touch_flood
input_event *button_flood
vector<input::TouchEvent> touch_events
public:
App():
fb = framebuffer::get()
// on resize, we exit and trust our service to restart us
fb->resize += [=](auto &e):
exit(1)
;
w, h = fb->get_display_size()
if app_dialog != NULL:
delete app_dialog
if app_bg != NULL:
delete app_bg
app_dialog = new AppDialog(0, 0, 600, 800, self)
app_dialog->populate()
get_current_app()
app_dialog->on_hide += PLS_LAMBDA(auto &d):
self.render_bg()
launch(CURRENT_APP)
if USE_KOREADER_WORKAROUND and CURRENT_APP != "KOReader":
ui::MainLoop::in.ungrab()
;
app_bg = new AppBackground(0, 0, w, h)
touch_flood = build_touch_flood()
button_flood = build_button_flood()
notebook := ui::make_scene()
notebook->add(app_bg)
ui::MainLoop::set_scene(notebook)
#ifdef REMARKABLE
self.update_thresholds()
#endif
return
void update_thresholds():
debug "READING TIMEOUTS FOR SLEEP/SHUTDOWN FROM XOCHITL"
ifstream f("/home/root/.config/remarkable/xochitl.conf")
string line
while getline(f, line):
// TODO: switch this to using str_utils::split?
// search line by line for IdleSuspendDelay, SuspendPowerOffDelay
if line.find("IdleSuspendDelay") != -1:
eq_sign_pos := line.find("=")
if eq_sign_pos != -1:
try:
SUSPEND_THRESHOLD = std::stoi(line.substr(eq_sign_pos+1, -1)) / 1000 - 10
debug "SUSPEND UPDATED", SUSPEND_THRESHOLD
catch (...):
debug "COULDNT PARSE FOR SUSPEND:", line
if line.find("SuspendPowerOffDelay") != -1:
eq_sign_pos := line.find("=")
if eq_sign_pos != -1:
try:
SHUTDOWN_THRESHOLD = std::stoi(line.substr(eq_sign_pos+1, -1)) / 1000
debug "SHUTDOWN UPDATED", SHUTDOWN_THRESHOLD
catch (...):
debug "COULDNT PARSE FOR SHUTDOWN:", line
void get_more():
launch(NAO_BIN)
void get_current_app():
RMApp active
vector<string> binaries;
for auto a : app_dialog->get_apps():
if proc::is_running(a.which):
active = a
debug "CURRENT APP IS", active.name
CURRENT_APP = active.name
return
def handle_api_line(string line):
str_utils::trim(line)
if line == "":
return
if line == "show":
self.show_launcher()
else if line == "hide":
ui::MainLoop::hide_overlay()
else if line == "back":
ui::MainLoop::hide_overlay()
self.show_last_app()
else:
debug "UNKNOWN API LINE:", line
def open_input_fifo():
#ifndef REMARKABLE
return
#endif
debug "STARTING FIFO THREAD"
_ := system("/usr/bin/mkfifo /run/remux.api 2>/dev/null")
self.ipc_thread = new thread([=]() {
fd := open("/run/remux.api", O_RDONLY)
string remainder = ""
char buf[4096]
while true:
bytes := read(fd, buf, 4096)
if bytes > 0:
buf[bytes] = 0
summed := remainder + string(buf)
lines := str_utils::split(summed, '\n')
remainder = ""
if lines.size() > 0 && buf[bytes-1] != '\n':
remainder = lines.back()
lines.pop_back()
for auto line : lines:
ui::TaskQueue::add_task([=]() {
handle_api_line(line)
})
usleep(50 * 1000)
})
def suspend_on_idle():
debug "STARTING SUSPEND THREAD"
version := util::get_remarkable_version()
self.idle_thread = new thread([=]() {
last_wake := 0
while true:
now := time(NULL)
// if its been more than 2 minute since our last loop iteration,
// we may have just woken up. in this case, we reset the idle timer
// so we don't fall back asleep immediately
if now - last_wake > 2*MIN:
debug "LAST SUSPEND LOOP WAS", (now - last_wake), "AGO, RESETTING IDLE TIMER"
suspend_m.lock()
LAST_ACTION = now
suspend_m.unlock()
last_wake = now
usb_in := false
string usb_str
if version == util::RM_VERSION::RM2:
usb_str = string(exec("cat /sys/class/power_supply/max77818-charger/online"))
else:
usb_str = string(exec("cat /sys/class/power_supply/imx_usb_charger/present"))
str_utils::trim(usb_str)
usb_in = usb_str == string("1")
suspend_m.lock()
if LAST_ACTION == 0 or usb_in:
LAST_ACTION = now
last_action := LAST_ACTION
suspend_m.unlock()
if last_action > 0 and SUSPEND_THRESHOLD > 0:
if now - last_action > SUSPEND_THRESHOLD and now - last_action < 2*SUSPEND_THRESHOLD:
if not ui::MainLoop::overlay_is_visible:
app_bg->snapshot()
on_suspend()
this_thread::sleep_for(chrono::seconds(10));
});
def handle_motion_event(input::SynMotionEvent ev):
suspend_m.lock()
LAST_ACTION = time(NULL)
suspend_m.unlock()
void render_bg():
app_bg->render()
ui::MainLoop::redraw()
void show_last_app():
debug "SHOWING LAST APP", CURRENT_APP
for auto app : _launched:
if app != CURRENT_APP && app != "_":
self.term_apps()
self.app_bg->snapshot()
self.launch(app)
self.render_bg()
break
void show_launcher():
if ui::MainLoop::overlay_is_visible:
return
ClockWatch cz
ClockWatch c0
get_current_app()
debug "current app", c0.elapsed()
// this is really backgrounding apps, not terminating
ClockWatch c1
term_apps()
debug "term apps", c1.elapsed()
app_bg->snapshot()
app_dialog->populate()
app_dialog->setup_for_render()
app_dialog->add_shortcuts()
app_dialog->show()
app_dialog->scene->on_hide += app_dialog->on_hide
ui::MainLoop::in.grab()
def handle_key_event(input::SynKeyEvent ev):
static int lastpress = RAND_MAX
static int event_press_id = 0
suspend_m.lock()
LAST_ACTION = time(NULL)
suspend_m.unlock()
if is_pressed && ev.is_pressed:
return
switch ev.key:
case KEY_HOME:
if ev.is_pressed:
lastpress = time(NULL)
event_press_id = ev.id
thread *th = new thread([=]() {
this_thread::sleep_for(chrono::seconds(TIMEOUT));
now := time(NULL)
if now - lastpress >= TIMEOUT:
if is_pressed && event_press_id == ev.id
self.show_launcher()
ui::TaskQueue::wakeup()
});
else:
event_press_id = 0
is_pressed = ev.is_pressed
last_ev := &ev
void term_apps(string name=""):
vector<string> term
for auto a : app_dialog->get_apps():
tokens := str_utils::split(a.bin, ' ')
cstr := tokens[0].c_str()
base := basename((char *) cstr)
if a.name != name:
term.push_back(string(base))
if term.size() > 0:
proc::groupkill(SIGSTOP, term)
bool file_exists(string s):
struct stat buffer;
return (stat (s.c_str(), &buffer) == 0);
// TODO: power button will cause suspend screen, why not?
void on_suspend():
#ifndef REMARKABLE
return
#endif
debug "SUSPENDING"
ui::MainLoop::hide_overlay()
_w, _h := fb->get_display_size()
#ifdef REMARKABLE
if file_exists("/usr/share/remarkable/sleeping.png"):
fb->load_from_png("/usr/share/remarkable/sleeping.png")
else:
fb->load_from_png("/usr/share/remarkable/suspended.png")
#else
text := ui::Text(0, _h-64, _w, 100, "Press any button to wake")
text.set_style(ui::Stylesheet().font_size(64).justify_center())
text.undraw()
text.render()
#endif
fb->redraw_screen()
ui::MainLoop::in.grab()
#ifdef REMARKABLE
if rm2fb::IN_RM2FB_SHIM:
sleep(1)
_ := system("systemctl suspend")
sleep(1)
if system("lsmod | grep brcmfmac") == 0:
debug "RELOADING WIFI DRIVERS"
_ = system("modprobe -r brcmfmac brcmutil")
_ = system("modprobe brcmfmac brcmutil")
else:
slept_at := time(NULL)
if SHUTDOWN_THRESHOLD > 0:
cmd := "echo " + to_string(SHUTDOWN_THRESHOLD + slept_at) + " > /sys/class/rtc/rtc0/wakealarm"
_ := system(cmd.c_str())
sleep(1)
_ := system("systemctl suspend")
sleep(1)
now := time(NULL)
if SHUTDOWN_THRESHOLD > 0 && now - slept_at >= SHUTDOWN_THRESHOLD:
debug "RESUMING FROM SUSPEND -> SHUTDOWN"
_ := system("systemctl poweroff")
return
// reset LAST_ACTION after wake so we don't go into sleep loop
LAST_ACTION = time(NULL)
_ = system("echo 0 > /sys/class/rtc/rtc0/wakealarm")
#endif
debug "RESUMING FROM SUSPEND"
ui::MainLoop::in.ungrab()
fb->clear_screen()
app_bg->render()
fb->redraw_screen(true)
inline void write_input_event(int fd, type, code, value):
input_event ev;
memset(&ev, 0, sizeof(ev));
ev.type = type
ev.code = code
ev.value = value
if write(fd, &ev, sizeof(ev)) != sizeof(ev):
debug "COULDNT WRITE EV", errno
input_event* build_touch_flood():
n := 512 * 8
num_inst := 4
input_event *ev = (input_event*) malloc(sizeof(struct input_event) * n * num_inst)
memset(ev, 0, sizeof(input_event) * n * num_inst)
i := 0
while i < n:
ev[i++] = input_event{ type:EV_ABS, code:ABS_DISTANCE, value:1 }
ev[i++] = input_event{ type:EV_SYN, code:0, value:0 }
ev[i++] = input_event{ type:EV_ABS, code:ABS_DISTANCE, value:2 }
ev[i++] = input_event{ type:EV_SYN, code:0, value:0 }
return ev
input_event* build_button_flood():
n := 512 * 8
num_inst := 2
input_event *ev = (input_event*) malloc(sizeof(struct input_event) * n * num_inst)
memset(ev, 0, sizeof(input_event) * n * num_inst)
i := 0
while i < n:
ev[i++] = input_event{ type:EV_SYN, code:1, value:0 }
ev[i++] = input_event{ type:EV_SYN, code:0, value:1 }
return ev
void flood_touch_queue():
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
bytes := write(fd, button_flood, 512 * 8 * 2 * sizeof(input_event))
void launch(string name):
if name == "":
return
debug "LAUNCHING APP", name, CURRENT_APP
string bin
string which
if name != "_" && _launched[0] != name:
_launched.push_front(name)
if _launched.size() > 100:
_launched.pop_back()
RMApp app
for auto a : app_dialog->get_apps():
if a.name == name or a.bin == name:
app = a
CURRENT_APP = string(a.name)
ui::MainLoop::in.ungrab()
flood_touch_queue()
flood_button_queue()
// flood_button_queue()
if app.resume != "" and proc::check_process(app.which):
proc::launch_process(app.resume)
else:
proc::launch_process(app.bin, true /* check running */, true /* background */)
// TODO: remove KOReader special codings
if USE_KOREADER_WORKAROUND and CURRENT_APP == "KOReader":
ui::MainLoop::in.grab()
debug "FYI, GRABBING KOREADER INPUTS AWAY AND RESETTING SCREEN DEPTH"
ui::TaskQueue::add_task([=]() {
this_thread::sleep_for(chrono::seconds(3));
fb->set_screen_depth(16)
ui::MainLoop::in.ungrab()
})
else:
ioctl(ui::MainLoop::in.button.fd, EVIOCGRAB, false)
ui::MainLoop::hide_overlay()
// we save the touch input until the finger lifts up
// so we can analyze whether its a gesture or not
def save_touch_events():
for auto ev: ui::MainLoop::in.touch.events:
if ev.slots[0].left == 0:
self.check_gesture()
self.touch_events.clear()
else:
// we only track 200 events or so for now
// simple swipes are about 40 - 50 events
if self.touch_events.size() < 200:
self.touch_events.push_back(ev)
void check_gesture():
fb := framebuffer::get()
fw, fh := fb->get_display_size()
left := -1
max_y := self.touch_events[0].slots[0].y
min_y := self.touch_events[0].slots[0].y
for auto ev: self.touch_events:
if ev.slots[0].y != -1:
min_y = min(min_y, ev.slots[0].y)
if ev.slots[0].x != -1:
if left == -1:
if ev.slots[0].x < 100:
left = true
else if ev.slots[0].x > fw - 100:
left = false
else:
return
if left && ev.slots[0].x > 100:
return
if !left && ev.slots[0].x < fw - 100:
return
if min_y == -1 or max_y == -1:
return
y_delta := max_y - min_y
if y_delta >= 800:
self.show_launcher()
return
string get_xochitl_cmd():
ifstream f("/lib/systemd/system/xochitl.service")
string line
find := "ExecStart"
default_cmd := "xochitl --system"
while getline(f, line):
if line.find(find) != -1:
tokens := str_utils::split(line, '=')
if tokens.size() == 1:
return default_cmd
tokens.erase(tokens.begin())
cmd := str_utils::join(tokens, '=')
debug "XOCHITL CMD IS", cmd
return cmd
return default_cmd
void setup_gestures():
// TODO: read gesture config from remux.conf file
// since we want it to be backward compatible, what shall we do?
// launch_gesture=
// launch_gesture=
// launch_gesture=
// last_app_gesture=
debug "SETTING UP GESTURES"
config := read_remux_config()
launch_gestures := CONFIG.get_array("launch_gesture")
if launch_gestures.size() == 0:
debug "SETTING LAUNCH GESTURES TO DEFAULT"
launch_gestures = DEFAULT_LAUNCH_GESTURES
for auto l : launch_gestures:
lines := str_utils::split(l, ';')
gestures := genie::parse_config(lines)
for auto g : gestures:
g->events.activate += PLS_LAMBDA(auto d):
self.show_launcher()
;
ui::MainLoop::gestures.push_back(g)
back_gestures := CONFIG.get_array("back_gesture")
for auto l : back_gestures:
lines := str_utils::split(l, ';')
gestures := genie::parse_config(lines)
for auto g : gestures:
g->events.activate += PLS_LAMBDA(auto d):
self.show_last_app()
;
ui::MainLoop::gestures.push_back(g)
def run():
// for koreader
putenv((char*) "KO_DONT_SET_DEPTH=1")
putenv((char*) "KO_DONT_GRAB_INPUT=1")
#ifdef REMARKABLE
_ := system("systemctl stop xochitl")
// read the xochitl command line from the systemd file
xochitl_cmd := get_xochitl_cmd()
proc::launch_process(xochitl_cmd, true /* check running */, true /* background */)
#endif
ui::Style::DEFAULT.font_size = 32
// launches a thread that suspends on idle
handle_power_mgmt := CONFIG.get_bool("manage_power", true)
if handle_power_mgmt:
self.suspend_on_idle()
else:
debug "NOT HANDLING POWER MANAGEMENT"
self.open_input_fifo()
self.setup_gestures()
ui::MainLoop::key_event += PLS_DELEGATE(self.handle_key_event)
ui::MainLoop::motion_event += PLS_DELEGATE(self.handle_motion_event)
// ui::MainLoop::gesture_event += PLS_DELEGATE(self.handle_gesture_event)
while true:
ui::MainLoop::main()
ui::MainLoop::check_resize()
if ui::MainLoop::overlay_is_visible:
ui::MainLoop::redraw()
ui::MainLoop::read_input()
ui::MainLoop::handle_gestures()
App app
def main():
LAST_ACTION = time(NULL)
app.run()