-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixgui_gtk.c
2841 lines (2338 loc) · 75.1 KB
/
fixgui_gtk.c
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
/*
* FixScript GUI v0.8 - https://www.fixscript.org/
* Copyright (c) 2019-2024 Martin Dvorak <jezek2@advel.cz>
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <dlfcn.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include "fixgui_common.h"
typedef enum {
G_CONNECT_AFTER = 1 << 0,
G_CONNECT_SWAPPED = 1 << 1
} GConnectFlags;
typedef enum {
CAIRO_FORMAT_INVALID = -1,
CAIRO_FORMAT_ARGB32 = 0,
CAIRO_FORMAT_RGB24 = 1,
CAIRO_FORMAT_A8 = 2,
CAIRO_FORMAT_A1 = 3,
CAIRO_FORMAT_RGB16_565 = 4,
CAIRO_FORMAT_RGB30 = 5
} cairo_format_t;
typedef enum {
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_SLANT_ITALIC,
CAIRO_FONT_SLANT_OBLIQUE
} cairo_font_slant_t;
typedef enum {
CAIRO_FONT_WEIGHT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD
} cairo_font_weight_t;
typedef struct {
double ascent;
double descent;
double height;
double max_x_advance;
double max_y_advance;
} cairo_font_extents_t;
typedef struct {
double x_bearing;
double y_bearing;
double width;
double height;
double x_advance;
double y_advance;
} cairo_text_extents_t;
typedef struct PangoContext PangoContext;
typedef struct PangoFontFamily PangoFontFamily;
typedef enum {
GTK_WINDOW_TOPLEVEL,
GTK_WINDOW_POPUP
} GtkWindowType;
typedef enum {
GDK_NOTHING = -1,
GDK_DELETE = 0,
GDK_DESTROY = 1,
GDK_EXPOSE = 2,
GDK_MOTION_NOTIFY = 3,
GDK_BUTTON_PRESS = 4,
GDK_2BUTTON_PRESS = 5,
GDK_3BUTTON_PRESS = 6,
GDK_BUTTON_RELEASE = 7,
GDK_KEY_PRESS = 8,
GDK_KEY_RELEASE = 9,
GDK_ENTER_NOTIFY = 10,
GDK_LEAVE_NOTIFY = 11,
GDK_FOCUS_CHANGE = 12,
GDK_CONFIGURE = 13,
GDK_MAP = 14,
GDK_UNMAP = 15,
GDK_PROPERTY_NOTIFY = 16,
GDK_SELECTION_CLEAR = 17,
GDK_SELECTION_REQUEST = 18,
GDK_SELECTION_NOTIFY = 19,
GDK_PROXIMITY_IN = 20,
GDK_PROXIMITY_OUT = 21,
GDK_DRAG_ENTER = 22,
GDK_DRAG_LEAVE = 23,
GDK_DRAG_MOTION = 24,
GDK_DRAG_STATUS = 25,
GDK_DROP_START = 26,
GDK_DROP_FINISHED = 27,
GDK_CLIENT_EVENT = 28,
GDK_VISIBILITY_NOTIFY = 29,
GDK_NO_EXPOSE = 30,
GDK_SCROLL = 31,
GDK_WINDOW_STATE = 32,
GDK_SETTING = 33
} GdkEventType;
typedef enum {
GDK_EXPOSURE_MASK = 1 << 1,
GDK_POINTER_MOTION_MASK = 1 << 2,
GDK_POINTER_MOTION_HINT_MASK = 1 << 3,
GDK_BUTTON_MOTION_MASK = 1 << 4,
GDK_BUTTON1_MOTION_MASK = 1 << 5,
GDK_BUTTON2_MOTION_MASK = 1 << 6,
GDK_BUTTON3_MOTION_MASK = 1 << 7,
GDK_BUTTON_PRESS_MASK = 1 << 8,
GDK_BUTTON_RELEASE_MASK = 1 << 9,
GDK_KEY_PRESS_MASK = 1 << 10,
GDK_KEY_RELEASE_MASK = 1 << 11,
GDK_ENTER_NOTIFY_MASK = 1 << 12,
GDK_LEAVE_NOTIFY_MASK = 1 << 13,
GDK_FOCUS_CHANGE_MASK = 1 << 14,
GDK_STRUCTURE_MASK = 1 << 15,
GDK_PROPERTY_CHANGE_MASK = 1 << 16,
GDK_VISIBILITY_NOTIFY_MASK = 1 << 17,
GDK_PROXIMITY_IN_MASK = 1 << 18,
GDK_PROXIMITY_OUT_MASK = 1 << 19,
GDK_SUBSTRUCTURE_MASK = 1 << 20,
GDK_SCROLL_MASK = 1 << 21,
GDK_ALL_EVENTS_MASK = 0x3FFFFE
} GdkEventMask;
typedef enum {
GDK_SHIFT_MASK = 1 << 0,
GDK_LOCK_MASK = 1 << 1,
GDK_CONTROL_MASK = 1 << 2,
GDK_MOD1_MASK = 1 << 3,
GDK_MOD2_MASK = 1 << 4,
GDK_MOD3_MASK = 1 << 5,
GDK_MOD4_MASK = 1 << 6,
GDK_MOD5_MASK = 1 << 7,
GDK_BUTTON1_MASK = 1 << 8,
GDK_BUTTON2_MASK = 1 << 9,
GDK_BUTTON3_MASK = 1 << 10,
GDK_BUTTON4_MASK = 1 << 11,
GDK_BUTTON5_MASK = 1 << 12,
GDK_RELEASE_MASK = 1 << 30,
GDK_MODIFIER_MASK = GDK_RELEASE_MASK | 0x1fff
} GdkModifierType;
typedef enum {
GTK_POLICY_ALWAYS,
GTK_POLICY_AUTOMATIC,
GTK_POLICY_NEVER
} GtkPolicyType;
typedef enum {
GDK_HINT_POS = 1 << 0,
GDK_HINT_MIN_SIZE = 1 << 1,
GDK_HINT_MAX_SIZE = 1 << 2,
GDK_HINT_BASE_SIZE = 1 << 3,
GDK_HINT_ASPECT = 1 << 4,
GDK_HINT_RESIZE_INC = 1 << 5,
GDK_HINT_WIN_GRAVITY = 1 << 6,
GDK_HINT_USER_POS = 1 << 7,
GDK_HINT_USER_SIZE = 1 << 8
} GdkWindowHints;
typedef enum {
GDK_GRAVITY_NORTH_WEST = 1,
GDK_GRAVITY_NORTH,
GDK_GRAVITY_NORTH_EAST,
GDK_GRAVITY_WEST,
GDK_GRAVITY_CENTER,
GDK_GRAVITY_EAST,
GDK_GRAVITY_SOUTH_WEST,
GDK_GRAVITY_SOUTH,
GDK_GRAVITY_SOUTH_EAST,
GDK_GRAVITY_STATIC
} GdkGravity;
typedef enum {
GDK_CROSSING_NORMAL,
GDK_CROSSING_GRAB,
GDK_CROSSING_UNGRAB
} GdkCrossingMode;
typedef enum {
GDK_NOTIFY_ANCESTOR = 0,
GDK_NOTIFY_VIRTUAL = 1,
GDK_NOTIFY_INFERIOR = 2,
GDK_NOTIFY_NONLINEAR = 3,
GDK_NOTIFY_NONLINEAR_VIRTUAL = 4,
GDK_NOTIFY_UNKNOWN = 5
} GdkNotifyType;
typedef enum {
GDK_SCROLL_UP,
GDK_SCROLL_DOWN,
GDK_SCROLL_LEFT,
GDK_SCROLL_RIGHT
} GdkScrollDirection;
typedef enum {
GDK_X_CURSOR = 0,
GDK_ARROW = 2,
GDK_BASED_ARROW_DOWN = 4,
GDK_BASED_ARROW_UP = 6,
GDK_BOAT = 8,
GDK_BOGOSITY = 10,
GDK_BOTTOM_LEFT_CORNER = 12,
GDK_BOTTOM_RIGHT_CORNER = 14,
GDK_BOTTOM_SIDE = 16,
GDK_BOTTOM_TEE = 18,
GDK_BOX_SPIRAL = 20,
GDK_CENTER_PTR = 22,
GDK_CIRCLE = 24,
GDK_CLOCK = 26,
GDK_COFFEE_MUG = 28,
GDK_CROSS = 30,
GDK_CROSS_REVERSE = 32,
GDK_CROSSHAIR = 34,
GDK_DIAMOND_CROSS = 36,
GDK_DOT = 38,
GDK_DOTBOX = 40,
GDK_DOUBLE_ARROW = 42,
GDK_DRAFT_LARGE = 44,
GDK_DRAFT_SMALL = 46,
GDK_DRAPED_BOX = 48,
GDK_EXCHANGE = 50,
GDK_FLEUR = 52,
GDK_GOBBLER = 54,
GDK_GUMBY = 56,
GDK_HAND1 = 58,
GDK_HAND2 = 60,
GDK_HEART = 62,
GDK_ICON = 64,
GDK_IRON_CROSS = 66,
GDK_LEFT_PTR = 68,
GDK_LEFT_SIDE = 70,
GDK_LEFT_TEE = 72,
GDK_LEFTBUTTON = 74,
GDK_LL_ANGLE = 76,
GDK_LR_ANGLE = 78,
GDK_MAN = 80,
GDK_MIDDLEBUTTON = 82,
GDK_MOUSE = 84,
GDK_PENCIL = 86,
GDK_PIRATE = 88,
GDK_PLUS = 90,
GDK_QUESTION_ARROW = 92,
GDK_RIGHT_PTR = 94,
GDK_RIGHT_SIDE = 96,
GDK_RIGHT_TEE = 98,
GDK_RIGHTBUTTON = 100,
GDK_RTL_LOGO = 102,
GDK_SAILBOAT = 104,
GDK_SB_DOWN_ARROW = 106,
GDK_SB_H_DOUBLE_ARROW = 108,
GDK_SB_LEFT_ARROW = 110,
GDK_SB_RIGHT_ARROW = 112,
GDK_SB_UP_ARROW = 114,
GDK_SB_V_DOUBLE_ARROW = 116,
GDK_SHUTTLE = 118,
GDK_SIZING = 120,
GDK_SPIDER = 122,
GDK_SPRAYCAN = 124,
GDK_STAR = 126,
GDK_TARGET = 128,
GDK_TCROSS = 130,
GDK_TOP_LEFT_ARROW = 132,
GDK_TOP_LEFT_CORNER = 134,
GDK_TOP_RIGHT_CORNER = 136,
GDK_TOP_SIDE = 138,
GDK_TOP_TEE = 140,
GDK_TREK = 142,
GDK_UL_ANGLE = 144,
GDK_UMBRELLA = 146,
GDK_UR_ANGLE = 148,
GDK_WATCH = 150,
GDK_XTERM = 152,
GDK_LAST_CURSOR,
GDK_BLANK_CURSOR = -2,
GDK_CURSOR_IS_PIXMAP = -1
} GdkCursorType;
typedef char gchar;
typedef short gshort;
typedef long glong;
typedef int gint;
typedef int8_t gint8;
typedef int16_t gint16;
typedef uint8_t guint8;
typedef uint16_t guint16;
typedef uint32_t guint32;
typedef gint gboolean;
typedef unsigned char guchar;
typedef unsigned short gushort;
typedef unsigned long gulong;
typedef unsigned int guint;
typedef float gfloat;
typedef double gdouble;
typedef void *gpointer;
typedef void *GCallback;
typedef void *GClosureNotify;
typedef void GdkWindow;
typedef void GdkRegion;
typedef void GdkDevice;
typedef void GdkCursor;
typedef void GdkPixmap;
typedef void GdkBitmap;
typedef void GtkSettings;
typedef struct {
void *class;
guint ref_count;
void *qdata;
} GObject;
typedef gboolean (*GSourceFunc)(gpointer data);
typedef struct {
gint x;
gint y;
gint width;
gint height;
} GdkRectangle;
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
GdkRectangle area;
GdkRegion *region;
gint count;
} GdkEventExpose;
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
gint x, y;
gint width;
gint height;
} GdkEventConfigure;
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
gdouble x;
gdouble y;
gdouble *axes;
guint state;
gint16 is_hint;
GdkDevice *device;
gdouble x_root, y_root;
} GdkEventMotion;
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
gdouble x;
gdouble y;
gdouble *axes;
guint state;
guint button;
GdkDevice *device;
gdouble x_root, y_root;
} GdkEventButton;
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
gdouble x;
gdouble y;
guint state;
GdkScrollDirection direction;
GdkDevice *device;
gdouble x_root, y_root;
} GdkEventScroll;
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
guint state;
guint keyval;
gint length;
gchar *string;
guint16 hardware_keycode;
guint8 group;
} GdkEventKey;
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
GdkWindow *subwindow;
guint32 time;
gdouble x;
gdouble y;
gdouble x_root;
gdouble y_root;
GdkCrossingMode mode;
GdkNotifyType detail;
gboolean focus;
guint state;
} GdkEventCrossing;
typedef union {
GdkEventType type;
GdkEventExpose expose;
GdkEventConfigure configure;
GdkEventMotion motion;
GdkEventButton button;
GdkEventScroll scroll;
GdkEventKey key;
GdkEventCrossing crossing;
} GdkEvent;
typedef struct {
gint min_width;
gint min_height;
gint max_width;
gint max_height;
gint base_width;
gint base_height;
gint width_inc;
gint height_inc;
gdouble min_aspect;
gdouble max_aspect;
GdkGravity win_gravity;
} GdkGeometry;
typedef struct {
guint32 pixel;
guint16 red;
guint16 green;
guint16 blue;
} GdkColor;
typedef struct cairo_t cairo_t;
typedef struct cairo_surface_t cairo_surface_t;
typedef struct cairo_pattern_t cairo_pattern_t;
typedef struct cairo_font_face_t cairo_font_face_t;
typedef enum {
GTK_TOPLEVEL = 1 << 4,
GTK_NO_WINDOW = 1 << 5,
GTK_REALIZED = 1 << 6,
GTK_MAPPED = 1 << 7,
GTK_VISIBLE = 1 << 8,
GTK_SENSITIVE = 1 << 9,
GTK_PARENT_SENSITIVE = 1 << 10,
GTK_CAN_FOCUS = 1 << 11,
GTK_HAS_FOCUS = 1 << 12,
GTK_CAN_DEFAULT = 1 << 13,
GTK_HAS_DEFAULT = 1 << 14,
GTK_HAS_GRAB = 1 << 15,
GTK_RC_STYLE = 1 << 16,
GTK_COMPOSITE_CHILD = 1 << 17,
GTK_NO_REPARENT = 1 << 18,
GTK_APP_PAINTABLE = 1 << 19,
GTK_RECEIVES_DEFAULT = 1 << 20,
GTK_DOUBLE_BUFFERED = 1 << 21
} GtkWidgetFlags;
typedef struct {
GObject parent_instance;
uint32_t flags;
} GtkObject;
typedef struct {
gint width;
gint height;
} GtkRequisition;
typedef GdkRectangle GtkAllocation;
typedef struct GtkWidget {
GtkObject object;
uint16_t private_flags;
uint8_t state;
uint8_t saved_state;
char *name;
void *style;
GtkRequisition requisition;
GtkAllocation allocation;
GdkWindow *window;
struct GtkWidget *parent;
} GtkWidget;
typedef struct {
GtkWidget widget;
} GtkWindow;
typedef struct {
GtkWidget widget;
} GtkFixed;
typedef struct {
GtkWidget widget;
} GtkContainer;
typedef struct {
GtkWidget widget;
} GtkButton;
typedef struct {
GtkObject parent_instance;
gdouble lower;
gdouble upper;
gdouble value;
gdouble step_increment;
gdouble page_increment;
gdouble page_size;
} GtkAdjustment;
typedef struct {
GtkWidget widget;
} GtkScrolledWindow;
typedef struct {
GtkWidget widget;
} GtkRange;
typedef struct {
GtkWidget widget;
} GtkLabel;
typedef struct {
GtkWidget widget;
} GtkEntry;
typedef struct {
GtkWidget widget;
} GtkMisc;
typedef struct {
gulong g_type;
} GTypeClass;
typedef struct {
GTypeClass g_type_class;
void *priv[1];
void *funcs[7];
void *dummy[8];
} GObjectClass;
typedef struct {
GObjectClass parent_class;
guint activate_signal;
void *funcs1[9];
void (*size_allocate)(GtkWidget *widget, GtkAllocation *allocation);
void *funcs2[10];
void (*get_preferred_height)(GtkWidget *widget, gint *minimum_height, gint *natural_height);
void (*get_preferred_width_for_height)(GtkWidget *widget, gint height, gint *minimum_width, gint *natural_width);
void (*get_preferred_width)(GtkWidget *widget, gint *minimum_width, gint *natural_width);
void (*get_preferred_height_for_width)(GtkWidget *widget, gint width, gint *minimum_height, gint *natural_height);
} GtkWidgetClass;
static int version;
static void (*g_free)(gpointer mem);
static gpointer (*g_object_ref)(gpointer object);
static void (*g_object_unref)(gpointer object);
static void (*g_object_get)(gpointer object, const gchar *first_property_name, ...);
static gulong (*g_signal_connect_data)(gpointer instance, const gchar *detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags);
#define g_signal_connect(instance, detailed_signal, c_handler, data) g_signal_connect_data(instance, detailed_signal, c_handler, data, NULL, 0)
static guint (*g_idle_add)(GSourceFunc function, gpointer data);
static guint (*g_timeout_add)(guint32 interval, GSourceFunc function, gpointer data);
static cairo_t *(*gdk_cairo_create)(GdkWindow *window);
static PangoContext *(*gdk_pango_context_get)();
static GdkCursor *(*gdk_cursor_new)(GdkCursorType cursor_type);
static GdkCursor *(*gdk_cursor_new_from_pixmap)(GdkPixmap *source, GdkPixmap *mask, GdkColor *fg, GdkColor *bg, gint x, gint y);
static GdkBitmap *(*gdk_bitmap_create_from_data)(GdkWindow *window, const gchar *data, gint width, gint height);
static void (*gdk_window_set_cursor)(GdkWindow *window, GdkCursor *cursor);
static void (*pango_context_list_families)(PangoContext *context, PangoFontFamily ***families, int *n_families);
static const char *(*pango_font_family_get_name)(PangoFontFamily *family);
static cairo_t *(*cairo_create)(cairo_surface_t *target);
static void (*cairo_clip_extents)(cairo_t *cr, double *x1, double *y1, double *x2, double *y2);
static void (*cairo_translate)(cairo_t *cr, double tx, double ty);
static void (*cairo_set_source_rgba)(cairo_t *cr, double red, double green, double blue, double alpha);
static void (*cairo_set_source)(cairo_t *cr, cairo_pattern_t *source);
static void (*cairo_rectangle)(cairo_t *cr, double x, double y, double width, double height);
static void (*cairo_fill)(cairo_t *cr);
static void (*cairo_paint)(cairo_t *cr);
static void (*cairo_destroy)(cairo_t *cr);
static void (*cairo_select_font_face)(cairo_t *cr, const char *family, cairo_font_slant_t slant, cairo_font_weight_t weight);
static cairo_font_face_t *(*cairo_get_font_face)(cairo_t *cr);
static void (*cairo_set_font_face)(cairo_t *cr, cairo_font_face_t *font_face);
static void (*cairo_set_font_size)(cairo_t *cr, double size);
static void (*cairo_show_text)(cairo_t *cr, const char *utf8);
static void (*cairo_font_extents)(cairo_t *cr, cairo_font_extents_t *extents);
static void (*cairo_text_extents)(cairo_t *cr, const char *utf8, cairo_text_extents_t *extents);
static cairo_font_face_t *(*cairo_font_face_reference)(cairo_font_face_t *font_face);
static void (*cairo_font_face_destroy)(cairo_font_face_t *font_face);
static int (*cairo_format_stride_for_width)(cairo_format_t format, int width);
static cairo_surface_t *(*cairo_image_surface_create)(cairo_format_t format, int width, int height);
static cairo_surface_t *(*cairo_image_surface_create_for_data)(unsigned char *data, cairo_format_t format, int width, int height, int stride);
static unsigned char *(*cairo_image_surface_get_data)(cairo_surface_t *surface);
static int (*cairo_image_surface_get_stride)(cairo_surface_t *surface);
static void (*cairo_surface_mark_dirty)(cairo_surface_t *surface);
static void (*cairo_surface_destroy)(cairo_surface_t *surface);
static cairo_pattern_t *(*cairo_pattern_create_for_surface)(cairo_surface_t *surface);
static void (*cairo_pattern_destroy)(cairo_pattern_t *pattern);
static void (*gtk_init)(int *argc, char ***argv);
static gboolean (*gtk_init_check)(int *argc, char ***argv);
static void (*gtk_main)();
static void (*gtk_main_quit)();
static GtkWidget *(*gtk_window_new)(GtkWindowType type);
static void (*gtk_window_set_default)(GtkWindow *window, GtkWidget *default_widget);
static void (*gtk_window_set_title)(GtkWindow *window, const char *title);
static const char *(*gtk_window_get_title)(GtkWindow *window);
static void (*gtk_window_set_resizable)(GtkWindow *window, gboolean resizable);
static void (*gtk_window_set_default_size)(GtkWindow *window, gint width, gint height);
static void (*gtk_window_resize)(GtkWindow *window, gint width, gint height);
static void (*gtk_widget_set_size_request)(GtkWidget *widget, gint width, gint height);
static void (*gtk_widget_set_usize)(GtkWidget *widget, gint width, gint height);
static void (*gtk_widget_size_request)(GtkWidget *widget, GtkRequisition *requisition);
static void (*gtk_widget_add_events)(GtkWidget *widget, gint events);
static void (*gtk_widget_show)(GtkWidget *widget);
static void (*gtk_widget_hide)(GtkWidget *widget);
//static void (*gtk_widget_get_allocation)(GtkWidget *widget, GtkAllocation *allocation);
static void (*gtk_widget_size_allocate)(GtkWidget *widget, GtkAllocation *allocation);
static void (*gtk_widget_set_allocation)(GtkWidget *widget, const GtkAllocation *allocation);
static void (*gtk_widget_grab_focus)(GtkWidget *widget);
static void (*gtk_widget_destroy)(GtkWidget *widget);
static GtkWidget *(*gtk_fixed_new)();
static void (*gtk_fixed_put)(GtkFixed *fixed, GtkWidget *widget, gint x, gint y);
static void (*gtk_fixed_move)(GtkFixed *fixed, GtkWidget *widget, gint x, gint y);
static void (*gtk_container_add)(GtkContainer *container, GtkWidget *widget);
static GtkWidget *(*gtk_button_new_with_label)(const gchar *label);
static const gchar *(*gtk_button_get_label)(GtkButton *button);
static void (*gtk_button_set_label)(GtkButton *button, const gchar *label);
static GtkWidget *(*gtk_drawing_area_new)();
static void (*gtk_widget_queue_draw)(GtkWidget *widget);
static void (*gtk_widget_queue_draw_area)(GtkWidget *widget, gint x, gint y, gint width, gint height);
static GtkWidget *(*gtk_scrolled_window_new)(GtkAdjustment *hadjustment, GtkAdjustment *vadjustment);
static void (*gtk_scrolled_window_add_with_viewport)(GtkScrolledWindow *scrolled_window, GtkWidget *child);
static GtkAdjustment *(*gtk_scrolled_window_get_hadjustment)(GtkScrolledWindow *scrolled_window);
static GtkAdjustment *(*gtk_scrolled_window_get_vadjustment)(GtkScrolledWindow *scrolled_window);
static void (*gtk_adjustment_configure)(GtkAdjustment *adjustment, gdouble value, gdouble lower, gdouble upper, gdouble step_increment, gdouble page_increment, gdouble page_size);
static void (*gtk_adjustment_value_changed)(GtkAdjustment *adjustment);
static void (*gtk_scrolled_window_get_policy)(GtkScrolledWindow *scrolled_window, GtkPolicyType *hscrollbar_policy, GtkPolicyType *vscrollbar_policy);
static void (*gtk_scrolled_window_set_policy)(GtkScrolledWindow *scrolled_window, GtkPolicyType hscrollbar_policy, GtkPolicyType vscrollbar_policy);
static GtkWidget *(*gtk_viewport_new)(GtkAdjustment *hadjustment, GtkAdjustment *vadjustment);
static GtkObject *(*gtk_adjustment_new)(gdouble value, gdouble lower, gdouble upper, gdouble step_increment, gdouble page_increment, gdouble page_size);
static GtkWidget *(*gtk_scrolled_window_get_hscrollbar)(GtkScrolledWindow *scrolled_window);
static GtkWidget *(*gtk_scrolled_window_get_vscrollbar)(GtkScrolledWindow *scrolled_window);
static void (*gtk_range_set_adjustment)(GtkRange *range, GtkAdjustment *adjustment);
static int (*gtk_widget_get_allocated_width)(GtkWidget *widget);
static int (*gtk_widget_get_allocated_height)(GtkWidget *widget);
static void (*gtk_window_set_geometry_hints)(GtkWindow *window, GtkWidget *geometry_widget, GdkGeometry *geometry, GdkWindowHints geom_mask);
static gdouble (*gtk_adjustment_get_value)(GtkAdjustment *adjustment);
static GtkWidget *(*gtk_label_new)(const gchar *str);
static void (*gtk_label_set_text)(GtkLabel *label, const gchar *str);
static const gchar *(*gtk_label_get_text)(GtkLabel *label);
static GtkWidget *(*gtk_entry_new)();
static void (*gtk_entry_set_text)(GtkEntry *entry, const gchar *text);
static const gchar *(*gtk_entry_get_text)(GtkEntry *entry);
static void (*gtk_misc_set_alignment)(GtkMisc *misc, gfloat xalign, gfloat yalign);
static GtkSettings *(*gtk_settings_get_default)();
struct View {
ViewCommon common;
GtkWidget *widget;
Rect rect;
uint32_t last_click_time;
int last_click_x, last_click_y;
int last_click_count;
union {
struct {
GtkWidget *fixed;
int x, y, width, height;
} window;
struct {
int flags;
GtkWidget *area;
GtkWidget *scroll;
GtkWidget *viewport;
GtkAdjustment *hadj, *vadj;
int hover;
} canvas;
};
};
struct Menu {
MenuCommon common;
};
struct Worker {
WorkerCommon common;
pthread_mutex_t mutex;
pthread_cond_t cond;
struct Worker *notify_next;
};
struct NotifyIcon {
NotifyIconCommon common;
};
struct SystemFont {
cairo_font_face_t *font_face;
float size;
float ascent;
float descent;
float height;
};
typedef struct WidgetInfo {
GtkWidget *widget;
View *view;
struct WidgetInfo *next;
} WidgetInfo;
typedef struct Timer {
Heap *heap;
Value instance;
int removed;
struct Timer *next;
} Timer;
static WidgetInfo *widget_infos = NULL;
static void (*orig_fixed_size_allocate)(GtkWidget *widget, GtkAllocation *allocation);
static void (*orig_fixed_preferred_width)(GtkWidget *widget, int *min, int *natural);
static void (*orig_fixed_preferred_height)(GtkWidget *widget, int *min, int *natural);
static cairo_t *tmp_cr;
static pthread_mutex_t global_mutex;
static Worker *notify_workers;
static Timer *active_timers;
static int io_pending;
static GdkCursor *cursors[NUM_CURSORS];
static int windows_count = 0;
static int pthread_cond_timedwait_relative(pthread_cond_t *cond, pthread_mutex_t *mutex, int64_t timeout)
{
struct timespec ts;
#if defined(__APPLE__)
struct timeval tv;
gettimeofday(&tv, NULL);
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * 1000;
#else
clock_gettime(CLOCK_REALTIME, &ts);
#endif
ts.tv_nsec += timeout % 1000000000;
ts.tv_sec += ts.tv_nsec / 1000000000 + timeout / 1000000000;
ts.tv_nsec %= 1000000000;
return pthread_cond_timedwait(cond, mutex, &ts);
}
void trigger_delayed_gc(Heap *heap)
{
}
void free_view(View *view)
{
WidgetInfo *info, **prev;
switch (view->common.type) {
case TYPE_WINDOW:
for (prev = &widget_infos, info = *prev; info; prev = &info->next, info = info->next) {
if (info->widget == view->window.fixed) {
*prev = info->next;
free(info);
break;
}
}
gtk_widget_destroy(view->widget);
break;
case TYPE_CANVAS:
if (view->canvas.flags & CANVAS_SCROLLABLE) {
g_object_unref(view->canvas.hadj);
g_object_unref(view->canvas.vadj);
}
g_object_unref(view->widget);
break;
default:
g_object_unref(view->widget);
break;
}
free(view);
}
void free_menu(Menu *menu)
{
free(menu);
}
void free_notify_icon(NotifyIcon *icon)
{
free(icon);
}
void view_destroy(View *view)
{
gtk_widget_destroy(view->widget);
view->widget = NULL;
switch (view->common.type) {
case TYPE_WINDOW:
view->window.fixed = NULL;
if (--windows_count <= 0) {
gtk_main_quit();
}
break;
case TYPE_CANVAS:
view->canvas.area = NULL;
view->canvas.scroll = NULL;
view->canvas.viewport = NULL;
break;
}
}
void view_get_rect(View *view, Rect *rect)
{
//GdkRectangle alloc;
if (view->common.type == TYPE_WINDOW) {
/*
//gtk_widget_get_allocation(view->widget, &alloc);
alloc = view->window.fixed->allocation;
rect->x1 = alloc.x;
rect->y1 = alloc.y;
rect->x2 = alloc.x + alloc.width;
rect->y2 = alloc.y + alloc.height;
*/
rect->x1 = view->window.x;
rect->y1 = view->window.y;
rect->x2 = view->window.x + view->window.width;
rect->y2 = view->window.y + view->window.height;
return;
}
*rect = view->rect;
}
void view_set_rect(View *view, Rect *rect)
{
view->rect = *rect;
if (view->widget && view->common.parent && view->common.parent->common.type == TYPE_WINDOW) {
if (version == 2) {
gtk_widget_set_usize(view->widget, rect->x2 - rect->x1, rect->y2 - rect->y1);
}
else {
gtk_widget_set_size_request(view->widget, rect->x2 - rect->x1, rect->y2 - rect->y1);
}
gtk_fixed_move((GtkFixed *)view->common.parent->window.fixed, view->widget, rect->x1, rect->y1);
gtk_widget_queue_draw(view->widget);
}
}
void view_get_content_rect(View *view, Rect *rect)
{
view_get_rect(view, rect);
rect->x2 -= rect->x1;
rect->y2 -= rect->y1;
rect->x1 = 0;
rect->y1 = 0;
}
void view_get_inner_rect(View *view, Rect *rect)
{
view_get_rect(view, rect);
rect->x2 -= rect->x1;
rect->y2 -= rect->y1;
rect->x1 = 0;
rect->y1 = 0;
}
void view_set_visible(View *view, int visible)
{
if (view->common.type == TYPE_WINDOW) {
if (visible) {
gtk_widget_show(view->widget);
}
else {
gtk_widget_hide(view->widget);
}
}
}
int view_add(View *parent, View *view)
{
if (parent->common.type != TYPE_WINDOW) return 0;
if (!view->widget) return 1;
if (version == 2) {
gtk_widget_set_usize(view->widget, view->rect.x2 - view->rect.x1, view->rect.y2 - view->rect.y1);
}
else {
gtk_widget_set_size_request(view->widget, view->rect.x2 - view->rect.x1, view->rect.y2 - view->rect.y1);
}
gtk_fixed_put((GtkFixed *)parent->window.fixed, view->widget, view->rect.x1, view->rect.y1);
return 1;
}
void view_focus(View *view)
{
switch (view->common.type) {
case TYPE_CANVAS:
gtk_widget_grab_focus(view->canvas.area);
break;
default:
gtk_widget_grab_focus(view->widget);
}
}
int view_has_focus(View *view)
{
return 0;
}
void view_get_sizing(View *view, float *grid_x, float *grid_y, int *form_small, int *form_medium, int *form_large, int *view_small, int *view_medium, int *view_large)
{
*grid_x = 5;
*grid_y = 6;
*form_small = 6;
*form_medium = 12;
*form_large = 24;
*view_small = 6;
*view_medium = 12;
*view_large = 24;
}
void view_get_default_size(View *view, int *width, int *height)
{
GtkRequisition requisition;
gtk_widget_size_request(view->widget, &requisition);
*width = requisition.width;
*height = requisition.height;
}
float view_get_scale(View *view)
{
return 1.0f;
}
void view_set_cursor(View *view, int cursor)
{
if (cursor < 0 || cursor >= NUM_CURSORS) {
return;
}
if (view->common.type == TYPE_CANVAS && view->canvas.area->window) {
gdk_window_set_cursor(view->canvas.area->window, cursors[cursor]);
}
}