-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmrg.lua
1423 lines (1201 loc) · 47.4 KB
/
mrg.lua
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
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- ffi lua binding for microraptor gui by Øyvind Kolås, public domain
--
local ffi = require('ffi')
local cairo = require('cairo')
local C = ffi.load('mrg')
local M = setmetatable({C=C},{__index = C})
ffi.cdef[[
typedef struct _MrgList MrgList;
struct _MrgList {
void *data;
MrgList *next;
void (*freefunc)(void *data, void *freefunc_data);
void *freefunc_data;
}
;
void mrg_list_prepend_full (MrgList **list, void *data,
void (*freefunc)(void *data, void *freefunc_data),
void *freefunc_data);
int mrg_list_length (MrgList *list);
void mrg_list_prepend (MrgList **list, void *data);
void mrg_list_append_full (MrgList **list, void *data,
void (*freefunc)(void *data, void *freefunc_data),
void *freefunc_data);
void mrg_list_append (MrgList **list, void *data);
void mrg_list_remove (MrgList **list, void *data);
void mrg_list_free (MrgList **list);
MrgList *mrg_list_nth (MrgList *list, int no);
MrgList *mrg_list_find (MrgList *list, void *data);
void mrg_list_sort (MrgList **list,
int(*compare)(const void *a, const void *b, void *userdata),
void *userdata);
void
mrg_list_insert_sorted (MrgList **list, void *data,
int(*compare)(const void *a, const void *b, void *userdata),
void *userdata);
typedef struct _Mrg Mrg;
typedef struct _MrgColor MrgColor;
typedef struct _MrgStyle MrgStyle;
typedef struct _MrgRectangle MrgRectangle;
typedef struct _MrgEvent MrgEvent;
enum _MrgType {
MRG_PRESS = 1 << 0,
MRG_MOTION = 1 << 1,
MRG_RELEASE = 1 << 2,
MRG_ENTER = 1 << 3,
MRG_LEAVE = 1 << 4,
MRG_TAP = 1 << 5, /* NYI */
MRG_TAP_AND_HOLD = 1 << 6, /* NYI */
MRG_DRAG_PRESS = 1 << 7,
MRG_DRAG_MOTION = 1 << 8,
MRG_DRAG_RELEASE = 1 << 9,
MRG_KEY_DOWN = 1 << 10,
MRG_KEY_UP = 1 << 11,
MRG_SCROLL = 1 << 12,
MRG_MESSAGE = 1 << 13,
MRG_DROP = 1 << 14,
MRG_TAPS = (MRG_TAP | MRG_TAP_AND_HOLD),
MRG_POINTER = (MRG_PRESS | MRG_MOTION | MRG_RELEASE),
MRG_CROSSING = (MRG_ENTER | MRG_LEAVE),
MRG_DRAG = (MRG_DRAG_PRESS | MRG_DRAG_MOTION | MRG_DRAG_RELEASE),
MRG_KEY = (MRG_KEY_DOWN | MRG_KEY_UP),
MRG_COORD = (MRG_POINTER | MRG_DRAG | MRG_CROSSING | MRG_TAPS),
MRG_ANY = (MRG_POINTER | MRG_DRAG | MRG_CROSSING | MRG_KEY | MRG_TAPS),
};
typedef enum _MrgType MrgType;
typedef void (*MrgCb) (MrgEvent *event,
void *data,
void *data2);
typedef void (*MrgLinkCb) (MrgEvent *event,
const char *href,
void *data);
typedef void(*MrgDestroyNotify) (void *data);
typedef int(*MrgTimeoutCb) (Mrg *mrg, void *data);
typedef int(*MrgIdleCb) (Mrg *mrg, void *data);
typedef void (*MrgNewText) (const char *new_text, void *data);
typedef void (*UiRenderFun)(Mrg *mrg, void *ui_data);
void mrg_destroy (Mrg *mrg);
void mrg_clear_bindings (Mrg *mrg);
void mrg_set_size (Mrg *mrg, int width, int height);
void mrg_set_position (Mrg *mrg, int x, int y);
void mrg_get_position (Mrg *mrg, int *x, int *y);
void mrg_message (Mrg *mrg, const char *message);
void mrg_set_title (Mrg *mrg, const char *title);
void mrg_window_set_value (Mrg *mrg, const char *name, const char *value);
const char *mrg_get_title (Mrg *mrg);
void *mrg_mmm (Mrg *mrg);
int mrg_width (Mrg *mrg);
int mrg_height (Mrg *mrg);
Mrg *mrg_new(int width, int height, const char *backend);
void mrg_set_ui (Mrg *mrg, UiRenderFun, void *ui_data);
void mrg_main (Mrg *mrg);
void mrg_quit (Mrg *mrg);
cairo_t *mrg_cr (Mrg *mrg);
void mrg_queue_draw (Mrg *mrg, MrgRectangle *rectangle);
int mrg_is_terminal (Mrg *mrg);
void mrg_set_fullscreen (Mrg *mrg, int fullscreen);
int mrg_is_fullscreen (Mrg *mrg);
float mrg_ddpx (Mrg *mrg);
unsigned char *mrg_get_pixels (Mrg *mrg, int *rowstride);
void mrg_restarter_add_path (Mrg *mrg, const char *path);
/*********************************************/
Mrg *mrg_new_mrg (Mrg *parent, int width, int height); // NYI
typedef struct _MrgImage MrgImage;
/* force a ui render, this is included for use with the headless backend.
*/
void mrg_ui_update (Mrg *mrg);
MrgImage *mrg_query_image (Mrg *mrg, const char *path,
int *width,
int *height);
/* built in http / local file URI fetcher, this is the callback interface
* that needs to be implemented for mrg_xml_render if external resources (css
* files / png images) are to be retrieved and rendered.
*/
int mrg_get_contents (Mrg *mrg,
const char *referer,
const char *input_uri,
char **contents,
long *length);
int
mrg_get_contents_default (const char *referer,
const char *input_uri,
char **contents,
long *length,
void *ignored_user_data);
void mrg_set_mrg_get_contents (Mrg *mrg,
int (*mrg_get_contents) (const char *referer,
const char *input_uri,
char **contents,
long *length,
void *get_contents_data),
void *get_contents_data);
void mrg_render_to_mrg (Mrg *mrg, Mrg *mrg2, float x, float y);
int mrg_add_idle (Mrg *mrg, int (*idle_cb)(Mrg *mrg, void *idle_data), void * idle_data);
int mrg_add_timeout (Mrg *mrg, int ms, int (*idle_cb)(Mrg *mrg, void * idle_data), void *idle_data);
void mrg_remove_idle (Mrg *mrg, int handle);
int mrg_add_idle_full (Mrg *mrg, int (*idle_cb)(Mrg *mrg, void *idle_data), void *idle_data,
void (*destroy_notify)(void *destroy_data), void *destroy_data);
int mrg_add_timeout_full (Mrg *mrg, int ms, MrgTimeoutCb idle_cb, void *idle_data,
void (*destroy_notify)(void *destroy_data), void *destroy_data);
void mrg_set_line_spacing (Mrg *mrg, float line_spacing);
float mrg_line_spacing (Mrg *mrg);
int mrg_print (Mrg *mrg, const char *string);
int mrg_print_get_xy (Mrg *mrg, const char *str, int no, float *x, float *y);
int mrg_print_xml (Mrg *mrg, const char *string);
void mrg_xml_render (Mrg *mrg, const char *uri_base,
MrgLinkCb linkcb,
void *link_data,
void (*finalize)(void *listen_data, void *listen_data2, void *finalize_data),
void *finalize_data,
const char *html);
void mrg_set_target_fps (Mrg *mrg, float fps);
float mrg_get_target_fps (Mrg *mrg);
void mrg_listen (Mrg *mrg,
MrgType types,
MrgCb cb,
void *data1,
void *data2);
void mrg_listen_full (Mrg *mrg,
MrgType types,
MrgCb cb,
void *data1,
void *data2,
void (*finalize)(void *listen_data, void *listen_data2, void *finalize_data),
void *finalize_data);
uint32_t mrg_ms (Mrg *mrg);
int mrg_pointer_press (Mrg *mrg, float x, float y, int device_no, uint32_t time);
int mrg_pointer_release (Mrg *mrg, float x, float y, int device_no, uint32_t time);
int mrg_pointer_motion (Mrg *mrg, float x, float y, int device_no, uint32_t time);
int mrg_key_press (Mrg *mrg, unsigned int keyval, const char *string, uint32_t time);
int mrg_is_printing (Mrg *mrg);
void mrg_new_page (Mrg *mrg);
void mrg_render_pdf (Mrg *mrg, const char *pdf_path);
void mrg_render_svg (Mrg *mrg, const char *svg_path);
/* these deal with pointer_no 0 only
*/
void mrg_warp_pointer (Mrg *mrg, float x, float y);
float mrg_pointer_x (Mrg *mrg);
float mrg_pointer_y (Mrg *mrg);
float mrg_em (Mrg *mrg);
void mrg_set_xy (Mrg *mrg, float x, float y);
float mrg_x (Mrg *mrg);
float mrg_y (Mrg *mrg);
typedef enum _MrgModifierState MrgModifierState;
enum _MrgModifierState
{
MRG_MODIFIER_STATE_SHIFT = (1<<0),
MRG_MODIFIER_STATE_CONTROL = (1<<1),
MRG_MODIFIER_STATE_ALT = (1<<2),
MRG_MODIFIER_STATE_BUTTON1 = (1<<3),
MRG_MODIFIER_STATE_BUTTON2 = (1<<4),
MRG_MODIFIER_STATE_BUTTON3 = (1<<5)
};
typedef enum _MrgScrollDirection MrgScrollDirection;
enum _MrgScrollDirection
{
MRG_SCROLL_DIRECTION_UP,
MRG_SCROLL_DIRECTION_DOWN,
MRG_SCROLL_DIRECTION_LEFT,
MRG_SCROLL_DIRECTION_RIGHT
};
struct _MrgEvent {
MrgType type;
Mrg *mrg;
uint32_t time;
MrgModifierState state;
int device_no; /* 0 = left mouse button / virtual focus */
/* 1 = middle mouse button */
/* 2 = right mouse button */
/* 3 = first multi-touch .. (NYI) */
float device_x; /* untransformed (device) coordinates */
float device_y;
/* coordinates; and deltas for motion/drag events in user-coordinates: */
float x;
float y;
float start_x; /* start-coordinates (press) event for drag, */
float start_y; /* untransformed coordinates */
float prev_x; /* previous events coordinates */
float prev_y;
float delta_x; /* x - prev_x, redundant - but often useful */
float delta_y; /* y - prev_y, redundant - .. */
MrgScrollDirection scroll_direction;
/* only valid for key-events */
unsigned int unicode;
const char *string; /* can be "up" "down" "space" "backspace" "a" "b" "ø" etc .. */
/* this is also where the message is delivered for
* MESSAGE events
*/
// int stop_propagate; /* */
};
void mrg_event_stop_propagate (MrgEvent *event);
void mrg_text_listen (Mrg *mrg, MrgType types,
MrgCb cb, void *data1, void *data2);
void mrg_text_listen_full (Mrg *mrg, MrgType types,
MrgCb cb, void *data1, void *data2,
void (*finalize)(void *listen_data, void *listen_data2, void * finalize_data),
void *finalize_data);
void mrg_text_listen_done (Mrg *mrg);
struct _MrgColor {
float red;
float green;
float blue;
float alpha;
};
typedef enum {
MRG_DISPLAY_INLINE = 0,
MRG_DISPLAY_BLOCK,
MRG_DISPLAY_LIST_ITEM,
MRG_DISPLAY_HIDDEN
} MrgDisplay;
/* matches cairo order */
typedef enum
{
MRG_FONT_WEIGHT_NORMAL = 0,
MRG_FONT_WEIGHT_BOLD
} MrgFontWeight;
typedef enum
{
MRG_FILL_RULE_NONZERO = 0,
MRG_FILL_RULE_EVEN_ODD
} MrgFillRule;
/* matches cairo order */
typedef enum
{
MRG_FONT_STYLE_NORMAL = 0,
MRG_FONT_STYLE_ITALIC,
MRG_FONT_STYLE_OBLIQUE
} MrgFontStyle;
typedef enum
{
MRG_BOX_SIZING_CONTENT_BOX = 0,
MRG_BOX_SIZING_BORDER_BOX
} MrgBoxSizing;
/* matching nchanterm definitions */
typedef enum {
MRG_REGULAR = 0,
MRG_BOLD = (1 << 0),
MRG_DIM = (1 << 1),
MRG_UNDERLINE = (1 << 2),
MRG_REVERSE = (1 << 3),
MRG_OVERLINE = (1 << 4),
MRG_LINETHROUGH = (1 << 5),
MRG_BLINK = (1 << 6)
} MrgTextDecoration;
typedef enum {
MRG_POSITION_STATIC = 0,
MRG_POSITION_RELATIVE,
MRG_POSITION_FIXED,
MRG_POSITION_ABSOLUTE
} MrgPosition;
typedef enum {
MRG_OVERFLOW_VISIBLE = 0,
MRG_OVERFLOW_HIDDEN,
MRG_OVERFLOW_SCROLL,
MRG_OVERFLOW_AUTO
} MrgOverflow;
typedef enum {
MRG_FLOAT_NONE = 0,
MRG_FLOAT_LEFT,
MRG_FLOAT_RIGHT,
MRG_FLOAT_FIXED
} MrgFloat;
typedef enum {
MRG_CLEAR_NONE = 0,
MRG_CLEAR_LEFT,
MRG_CLEAR_RIGHT,
MRG_CLEAR_BOTH
} MrgClear;
typedef enum {
MRG_TEXT_ALIGN_LEFT = 0,
MRG_TEXT_ALIGN_RIGHT,
MRG_TEXT_ALIGN_JUSTIFY,
MRG_TEXT_ALIGN_CENTER
} MrgTextAlign;
typedef enum {
MRG_WHITE_SPACE_NORMAL = 0,
MRG_WHITE_SPACE_NOWRAP,
MRG_WHITE_SPACE_PRE,
MRG_WHITE_SPACE_PRE_LINE,
MRG_WHITE_SPACE_PRE_WRAP
} MrgWhiteSpace;
typedef enum {
MRG_VERTICAL_ALIGN_BASELINE = 0,
MRG_VERTICAL_ALIGN_MIDDLE,
MRG_VERTICAL_ALIGN_BOTTOM,
MRG_VERTICAL_ALIGN_TOP,
MRG_VERTICAL_ALIGN_SUB,
MRG_VERTICAL_ALIGN_SUPER
} MrgVerticalAlign;
typedef enum {
MRG_CURSOR_AUTO = 0,
MRG_CURSOR_ALIAS,
MRG_CURSOR_ALL_SCROLL,
MRG_CURSOR_CELL,
MRG_CURSOR_CONTEXT_MENU,
MRG_CURSOR_COL_RESIZE,
MRG_CURSOR_COPY,
MRG_CURSOR_CROSSHAIR,
MRG_CURSOR_DEFAULT,
MRG_CURSOR_E_RESIZE,
MRG_CURSOR_EW_RESIZE,
MRG_CURSOR_HELP,
MRG_CURSOR_MOVE,
MRG_CURSOR_N_RESIZE,
MRG_CURSOR_NE_RESIZE,
MRG_CURSOR_NESW_RESIZE,
MRG_CURSOR_NS_RESIZE,
MRG_CURSOR_NW_RESIZE,
MRG_CURSOR_NO_DROP,
MRG_CURSOR_NONE,
MRG_CURSOR_NOT_ALLOWED,
MRG_CURSOR_POINTER,
MRG_CURSOR_PROGRESS,
MRG_CURSOR_ROW_RESIZE,
MRG_CURSOR_S_RESIZE,
MRG_CURSOR_SE_RESIZE,
MRG_CURSOR_SW_RESIZE,
MRG_CURSOR_TEXT,
MRG_CURSOR_VERTICAL_TEXT,
MRG_CURSOR_W_RESIZE,
MRG_CURSOR_WAIT,
MRG_CURSOR_ZOOM_IN,
MRG_CURSOR_ZOOM_OUT
} MrgCursor;
typedef enum {
MRG_LINE_CAP_BUTT,
MRG_LINE_CAP_ROUND,
MRG_LINE_CAP_SQUARE
} MrgLineCap;
typedef enum {
MRG_LINE_JOIN_MITER,
MRG_LINE_JOIN_ROUND,
MRG_LINE_JOIN_BEVEL
} MrgLineJoin;
typedef enum {
MRG_UNICODE_BIDI_NORMAL = 0,
MRG_UNICODE_BIDI_EMBED,
MRG_UNICODE_BIDI_BIDI_OVERRIDE
} MrgUnicodeBidi;
typedef enum {
MRG_DIRECTION_LTR = 0,
MRG_DIRECTION_RTL
} MrgDirection;
typedef enum {
MRG_VISIBILITY_VISIBLE = 0,
MRG_VISIBILITY_HIDDEN
} MrgVisibility;
typedef enum {
MRG_LIST_STYLE_OUTSIDE = 0,
MRG_LIST_STYLE_INSIDE
} MrgListStyle;
struct _MrgStyle {
/* text-related */
float font_size;
char font_family[128];
MrgColor color;
float text_indent;
float letter_spacing;
float word_spacing;
MrgVisibility visibility;
MrgTextDecoration text_decoration;
float line_height;
float line_width;
MrgColor background_color;
float stroke_width;
float text_stroke_width;
MrgColor text_stroke_color;
float tab_size;
/* copying style structs takes quite a bit of the time in the system,
* packing bits ends up saving a lot
*
* XXX: this is a gcc extension...
*/
MrgFillRule fill_rule;
MrgFontStyle font_style;
MrgFontWeight font_weight;
MrgLineCap stroke_linecap;
MrgLineJoin stroke_linejoin;
MrgTextAlign text_align;
MrgFloat float_;
MrgClear clear;
MrgOverflow overflow;
MrgDisplay display;
MrgPosition position;
MrgBoxSizing box_sizing;
MrgVerticalAlign vertical_align;
MrgWhiteSpace white_space;
MrgUnicodeBidi unicode_bidi;
MrgDirection direction;
MrgListStyle list_style;
unsigned char stroke;
unsigned char fill;
unsigned char width_auto;
unsigned char margin_left_auto;
unsigned char margin_right_auto;
unsigned char print_symbols;
MrgColor stroke_color;
/* vector shape / box related */
MrgColor fill_color;
MrgColor border_top_color;
MrgColor border_left_color;
MrgColor border_right_color;
MrgColor border_bottom_color;
MrgCursor cursor;
/* layout related */
float top;
float left;
float right;
float bottom;
float width;
float height;
float min_height;
float max_height;
float border_top_width;
float border_left_width;
float border_right_width;
float border_bottom_width;
float padding_top;
float padding_left;
float padding_right;
float padding_bottom;
float margin_top;
float margin_left;
float margin_right;
float margin_bottom;
void *id_ptr;
};
/* XXX: need full version for lua ffi */
void mrg_add_binding (Mrg *mrg,
const char *key,
const char *action,
const char *label,
MrgCb cb,
void *cb_data);
void mrg_add_binding_full (Mrg *mrg,
const char *key,
const char *action,
const char *label,
MrgCb cb,
void *cb_data,
MrgDestroyNotify destroy_notify,
void *destroy_data);
/**
* mrg_style:
* @mrg the mrg-context
*
* Returns the currently
*
*/
MrgStyle *mrg_style (Mrg *mrg);
void mrg_start (Mrg *mrg, const char *class_name, void *id_ptr);
void mrg_start_with_style (Mrg *mrg,
const char *style_id,
void *id_ptr,
const char *style);
void mrg_end (Mrg *mrg);
void mrg_stylesheet_clear (Mrg *mrg);
void mrg_stylesheet_add (Mrg *mrg, const char *css, const char *uri,
int priority,
char **error);
void mrg_css_set (Mrg *mrg, const char *css);
void mrg_css_add (Mrg *mrg, const char *css);
void mrg_set_style (Mrg *mrg, const char *style);
void mrg_set_line_height (Mrg *mrg, float line_height);
void mrg_set_font_size (Mrg *mrg, float font_size);
float mrg_line_height (Mrg *mrg);
/* XXX: doesnt feel like it belongs here */
void mrg_image (Mrg *mrg, float x0, float y0, float width, float height, const char *path, int *used_width, int *used_height);
void mrg_image_memory (Mrg *mrg, float x0, float y0, float width, float height, const char *data, int length, const char *eid, int *used_width, int *used_height);
MrgImage *mrg_query_image_memory (Mrg *mrg,
const char *contents,
int length,
const char *eid,
int *width,
int *height);
int mrg_get_cursor_pos (Mrg *mrg);
void mrg_set_cursor_pos (Mrg *mrg, int pos);
void mrg_edit_start (Mrg *mrg,
MrgNewText update_string,
void *user_data);
void mrg_edit_start_full (Mrg *mrg,
MrgNewText update_string,
void *user_data,
MrgDestroyNotify destroy,
void *destroy_data);
void mrg_edit_end (Mrg *mrg);
void mrg_set_edge_left (Mrg *mrg, float edge);
void mrg_set_edge_top (Mrg *mrg, float edge);
void mrg_set_edge_right (Mrg *mrg, float edge);
void mrg_set_edge_bottom (Mrg *mrg, float edge);
float mrg_edge_left (Mrg *mrg);
float mrg_edge_top (Mrg *mrg);
float mrg_edge_right (Mrg *mrg);
float mrg_edge_bottom (Mrg *mrg);
typedef struct _MrgHost MrgHost;
typedef struct _MrgClient MrgClient;
void mrg_host_add_client_mrg (MrgHost *host,
Mrg *mrg,
float x,
float y);
MrgHost *mrg_host_new (Mrg *mrg, const char *path);
void mrg_host_destroy (MrgHost *host);
void mrg_host_set_focused (MrgHost *host, MrgClient *client);
MrgClient *mrg_host_get_focused (MrgHost *host);
MrgClient *mrg_host_monitor_dir (MrgHost *host);
void mrg_host_register_events (MrgHost *host);
MrgList *mrg_host_clients (MrgHost *host);
void mrg_host_set_default_size (MrgHost *host, int width, int height);
void mrg_host_get_default_size (MrgHost *host, int *width, int *height);
void mrg_client_render_sloppy (MrgClient *client, float x, float y);
int mrg_client_get_pid (MrgClient *client);
void mrg_client_kill (MrgClient *client);
void mrg_client_raise_top (MrgClient *client);
void mrg_client_render (MrgClient *client, Mrg *mrg, float x, float y);
void mrg_client_maximize (MrgClient *client);
float mrg_client_get_x (MrgClient *client);
float mrg_client_get_y (MrgClient *client);
void mrg_client_set_x (MrgClient *client, float x);
void mrg_client_set_y (MrgClient *client, float y);
void mrg_client_get_size (MrgClient *client, int *width, int *height);
void mrg_client_set_size (MrgClient *client, int width, int height);
const char *mrg_client_get_title (MrgClient *client);
const char *mrg_client_get_value (MrgClient *client, const char *name);
void mrg_client_set_value (MrgClient *client, const char *name, const char *value);
void mrg_client_send_message (MrgClient *client, const char *message);
const char *mrg_client_get_message (MrgClient *client);
int mrg_client_has_message (MrgClient *client);
void mrg_client_set_stack_order (MrgClient *client, int zpos);
int mrg_client_get_stack_order (MrgClient *client);
void host_add_client_mrg (MrgHost *host,
Mrg *mrg,
float x,
float y);
typedef struct MrgBinding {
char *nick;
char *command;
char *label;
MrgCb cb;
void *cb_data;
MrgDestroyNotify destroy_notify;
void *destroy_data;
} MrgBinding;
MrgBinding *mrg_get_bindings (Mrg *mrg);
int mrg_parse_svg_path (Mrg *mrg, const char *str);
typedef struct _MrgVT MrgVT;
MrgVT *mrg_vt_new (Mrg *mrg, const char *commandline);
const char *mrg_vt_find_shell_command (void);
void mrg_vt_poll (MrgVT *vt);
long mrg_vt_rev (MrgVT *vt);
void mrg_vt_destroy (MrgVT *vt);
void mrg_vt_set_term_size (MrgVT *vt, int cols, int rows);
void mrg_vt_feed_keystring (MrgVT *vt, const char *str);
void mrg_vt_feed_byte (MrgVT *vt, int byte);
const char *mrg_vt_get_commandline (MrgVT *vt);
void mrg_vt_set_scrollback_lines (MrgVT *vt, int scrollback_lines);
int mrg_vt_get_scrollback_lines (MrgVT *vt);
int mrg_vt_get_line_count (MrgVT *vt);
const char *mrg_vt_get_line (MrgVT *vt, int no);
int mrg_vt_get_cols (MrgVT *vt);
int mrg_vt_get_rows (MrgVT *vt);
int mrg_vt_get_cursor_x (MrgVT *vt);
int mrg_vt_get_cursor_y (MrgVT *vt);
int mrg_vt_is_done (MrgVT *vt);
int mrg_vt_get_result (MrgVT *vt);
void mrg_vt_draw (MrgVT *vt, Mrg *mrg, double x, double y, float font_size, float line_spacing);
]]
function M.new(width,height, backend)
return ffi.gc(
C.mrg_new(width, height, backend),
C.mrg_destroy)
end
ffi.metatype('Mrg', {__index = {
-- maybe we should add a _full version to this as well, then all callback
-- things in the code would be lifecycle managed.
set_ui = function (mrg, uifun, uidata) C.mrg_set_ui(mrg, uifun, uidata) end,
style = function (...) return C.mrg_style (...) end;
width = function (...) return C.mrg_width (...) end,
mmm = function (...) return C.mrg_mmm (...) end,
height = function (...) return C.mrg_height (...) end,
pointer_x = function (...) return C.mrg_pointer_x (...) end,
pointer_y = function (...) return C.mrg_pointer_y (...) end,
text_listen_done = function (...) C.mrg_text_listen_done(...) end,
warp_pointer = function (...) C.mrg_warp_pointer(...) end,
quit = function (...) C.mrg_quit(...) end,
image_memory = function (mrg, x, y, w, h, data, len, eid)
local rw = ffi.new'int[1]'
local rh = ffi.new'int[1]'
C.mrg_image_memory(mrg, x, y, w, h, data, len, eid, rw, rh)
return rw[0], rh[0]
end,
image = function (mrg, x, y, w, h, path)
local rw = ffi.new'int[1]'
local rh = ffi.new'int[1]'
C.mrg_image (mrg, x, y, w, h, path, rw, rh)
return rw[0], rh[0]
end,
image = function (...) C.mrg_image(...) end,
render_pdf = function (...) C.mrg_render_pdf(...) end,
render_svg = function (...) C.mrg_render_svg(...) end,
is_printing = function (...) return C.mrg_is_printing (...) end,
new_page = function (...) C.mrg_new_page(...) end,
message = function (...) C.mrg_message(...) end,
parse_svg_path = function (...) return C.mrg_parse_svg_path(...) end,
clear_bindings = function (...) C.mrg_clear_bindings(...) end,
stylesheet_add = function(...) C.mrg_stylesheet_add(...) end,
stylesheet_clear = function(...) C.mrg_stylesheet_clear(...) end,
image_size = function (mrg, path)
local rw = ffi.new'int[1]'
local rh = ffi.new'int[1]'
rw[0] = -1
rh[0] = -1
C.mrg_query_image (mrg, path, rw, rh)
return rw[0], rh[0]
end,
image_size_memory = function (mrg, data, len, eid)
local rw = ffi.new'int[1]'
local rh = ffi.new'int[1]'
rw[0] = -1
rh[0] = -1
C.mrg_query_image_memory (mrg, data,len,eid, rw, rh)
return rw[0], rh[0]
end,
css_set = function (...) C.mrg_css_set(...) end,
set_style = function (...) C.mrg_set_style(...) end,
css_add = function (...) C.mrg_css_add(...) end,
set_em = function (...) C.mrg_set_em(...) end,
edit_start = function (mrg, cb, data)
-- manually cast and destroy resources held by lua/C binding
local notify_fun, cb_fun;
local notify_cb = function (finalize_data)
cb_fun:free();
notify_fun:free();
end
notify_fun = ffi.cast ("MrgDestroyNotify", notify_cb)
local wrap_cb = function(new_text,data)
cb(ffi.string(new_text),data)
end
cb_fun = ffi.cast ("MrgNewText", wrap_cb)
return C.mrg_edit_start_full (mrg, cb_fun, data, notify_fun, NULL)
end,
edit_end = function (...) C.mrg_edit_end (...) end,
set_edge_top = function (...) C.mrg_set_edge_top(...) end,
edge_top = function (...) return C.mrg_get_edge_top(...) end,
set_edge_bottom = function (...) C.mrg_set_edge_bottom(...) end,
edge_bottom = function (...) return C.mrg_get_edge_bottom(...) end,
set_edge_left = function (...) C.mrg_set_edge_left(...) end,
edge_left = function (...) return C.mrg_get_edge_left(...) end,
set_edge_right = function (...) C.mrg_set_edge_right(...) end,
edge_right = function (...) return C.mrg_get_edge_right(...) end,
set_rem = function (...) C.mrg_set_rem(...) end,
main = function (...) C.mrg_main(...) end,
get_bindings = function (...) return C.mrg_get_bindings(...) end,
start = function (mrg, cssid) C.mrg_start(mrg, cssid, NULL) end,
start_with_style = function (mrg, cssid, style) C.mrg_start_with_style(mrg, cssid, NULL, style) end,
restarter_add_path = function (...) C.mrg_restarter_add_path(...) end,
close = function (...) C.mrg_end(...) end,
queue_draw = function (...) C.mrg_queue_draw(...) end,
ms = function (...) return C.mrg_ms(...) end,
add_binding = function(mrg,key,action,label,cb,db_data)
local notify_fun, cb_fun;
local notify_cb = function (data1, data2,finalize_data)
cb_fun:free();
notify_fun:free();
end
notify_fun = ffi.cast ("MrgDestroyNotify", notify_cb)
cb_fun = ffi.cast ("MrgCb", cb)
return C.mrg_add_binding_full (mrg, key, action,label,cb_fun, cb_data, notify_fun, NULL)
end,
text_listen = function (mrg, types, cb, data1, data2)
-- manually cast and destroy resources held by lua/C binding
local notify_fun, cb_fun;
local notify_cb = function (data1, data2,finalize_data)
cb_fun:free();
notify_fun:free();
end
notify_fun = ffi.cast ("MrgCb", notify_cb)
cb_fun = ffi.cast ("MrgCb", cb)
return C.mrg_text_listen_full (mrg, types, cb_fun, data1, data2, notify_fun, NULL)
end,
listen = function (mrg, types, cb, data1, data2)
local notify_fun, cb_fun;
local notify_cb = function (data1, data2, finalize_data)
cb_fun:free();
notify_fun:free();
end
notify_fun = ffi.cast ("MrgCb", notify_cb)
cb_fun = ffi.cast ("MrgCb", cb)
return C.mrg_listen_full (mrg, types, cb_fun, data1, data2, notify_fun, NULL)
end,
print_get_xy = function (mrg, str, no)
local rx = ffi.new'float[1]'
local ry = ffi.new'float[1]'
C.mrg_print_get_xy(mrg, str, no, rx, ry)
return rx[0], ry[0]
end,
get_cursor_pos = function (...) return C.mrg_get_cursor_pos(...) end,
set_cursor_pos = function (...) C.mrg_set_cursor_pos(...) end,
print = function (...) C.mrg_print(...) end,
print_xml = function (...) C.mrg_print_xml(...) end,
xml_render = function (mrg, uri_base, link_cb, data, html)
local notify_fun, cb_fun;
local notify_cb = function (data, html, finalize_data)
cb_fun:free();
notify_fun:free();
end
local wrap_cb = function(event, href, data)
link_cb(event, ffi.string(href), data)
end
notify_fun = ffi.cast("MrgCb", notify_cb)
cb_fun = ffi.cast ("MrgLinkCb", wrap_cb)
return C.mrg_xml_render (mrg, uri_base, cb_fun, data, notify_fun, NULL, html)
end,
cr = function (...) return C.mrg_cr (...) end,
width = function (...) return C.mrg_width (...) end,
height = function (...) return C.mrg_height (...) end,
set_fullscreen = function (...) C.mrg_set_fullscreen(...) end,
is_fullscreen = function (...) return C.mrg_is_fullscreen(...) ~= 0 end,
x = function (...) return C.mrg_x (...) end,
y = function (...) return C.mrg_y (...) end,
xy = function (mrg) return mrg:x(), mrg:y() end,
em = function (...) return C.mrg_em (...) end,
rem = function (...) return C.mrg_rem (...) end,
set_xy = function (...) C.mrg_set_xy (...) end,
set_size = function (...) C.mrg_set_size (...) end,
set_position = function (...) C.mrg_set_position(...) end,
set_title = function (...) C.mrg_set_title (...) end,
window_set_value = function (...) C.mrg_window_set_value (...) end,
get_title = function (...) return C.mrg_get_title (...) end,
set_font_size = function (...) C.mrg_set_font_size (...) end,
set_target_fps = function (...) C.mrg_set_target_fps (...) end,
target_fps = function (...) return C.mrg_get_target_fps (...) end,
pointer_press = function (...) C.mrg_pointer_press (...) end,
pointer_release = function (...) C.mrg_pointer_release (...) end,
pointer_motion = function (...) C.mrg_pointer_motion (...) end,
key_press = function (...) C.mrg_key_press (...) end,
add_idle = function (mrg, ms, cb, data1)
local notify_fun, cb_fun;
local notify_cb = function (a,b)
cb_fun:free();
notify_fun:free();
end
notify_fun = ffi.cast ("MrgDestroyNotify", notify_cb)
cb_fun = ffi.cast ("MrgIdleCb", cb)
return C.mrg_add_idle_full (mrg, cb_fun, data1, notify_fun, NULL)
-- XXX: wrap the callback so that the return isn't mandatory?
end,
add_timeout = function (mrg, ms, cb, data1)
local notify_fun, cb_fun;
local notify_cb = function (a,b)
cb_fun:free();
notify_fun:free();
end
notify_fun = ffi.cast ("MrgDestroyNotify", notify_cb)
cb_fun = ffi.cast ("MrgTimeoutCb", cb)
return C.mrg_add_timeout_full (mrg, ms, cb_fun, data1, notify_fun, NULL)
end,
host_new = function (...)
return C.mrg_host_new(...)
end,
vt_new = function (...)
return C.mrg_vt_new (...)
end,
remove_idle = function (...) return C.mrg_remove_idle (...) end,
edge_left = function (...) return C.mrg_edge_left (...) end,
set_edge_left = function (...) C.mrg_set_edge_left (...) end,
edge_right = function (...) return C.mrg_edge_right (...) end,
set_edge_right = function (...) C.mrg_set_edge_right (...) end,
edge_top = function (...) return C.mrg_edge_top (...) end,
set_edge_top = function (...) C.mrg_set_edge_top (...) end,
edge_bottom = function (...) return C.mrg_edge_bottom (...) end,
set_edge_bottom = function (...) C.mrg_set_edge_bottom (...) end,
}})
ffi.metatype('MrgEvent', {__index = {
stop_propagate = function (...) return C.mrg_event_stop_propagate (...) end,
message = function (event) return ffi.string(event.string) end,
}})
ffi.metatype('MrgVT', {__index = {
poll = function (...) C.mrg_vt_poll (...) end,
draw = function (...) C.mrg_vt_draw (...) end,
rev = function (...) return C.mrg_vt_rev (...) end,
destroy = function (vt) C.mrg_vt_destroy (vt); ffi.gc (vt, nil) end,
set_term_size = function (...) C.mrg_vt_set_term_size (...) end,
feed_keystring = function (...) C.mrg_vt_feed_keystring (...) end,
feed_byte = function (...) C.mrg_vt_feed_byte (...) end,
is_done = function (...) return C.mrg_vt_is_done (...) end,
get_result = function (...) return C.mrg_vt_get_result (...) end,
get_scrollback_lines = function (...) return C.mrg_vt_get_scrollback_lines (...) end,
set_scrollback_lines = function (...) C.mrg_vt_set_scrollback_lines (...) end,
get_commandline = function (...) return C.mrg_vt_get_commandline (...) end,
get_line_count = function (...) return C.mrg_vt_get_line_count (...) end,