bare-gtk 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/runtime.c CHANGED
@@ -19,9 +19,12 @@ static uv_loop_t *bare__loop;
19
19
  static uv_async_t bare__shutdown;
20
20
  static bare_t *bare;
21
21
 
22
- static GIOChannel *bare__channel;
23
- static guint bare__poll;
24
- static guint bare__timer;
22
+ typedef struct {
23
+ GSource source;
24
+ gpointer poll;
25
+ } bare__source_t;
26
+
27
+ static GSource *bare__source;
25
28
 
26
29
  static bool bare__exited;
27
30
 
@@ -63,49 +66,53 @@ bare__on_platform_thread(void *data) {
63
66
  assert(err == 0);
64
67
  }
65
68
 
66
- static void
67
- bare__run(void);
68
-
69
+ // GLib asks a source for its timeout before every poll, so a timer is waited
70
+ // for wherever it was set, including from GTK callbacks that run outside the
71
+ // loop of the runtime.
69
72
  static gboolean
70
- bare__on_poll(GIOChannel *source, GIOCondition condition, gpointer data) {
71
- bare__run();
73
+ bare__on_prepare(GSource *source, gint *timeout) {
74
+ if (bare__exited) {
75
+ *timeout = -1;
72
76
 
73
- return G_SOURCE_CONTINUE;
77
+ return FALSE;
78
+ }
79
+
80
+ uv_update_time(bare__loop);
81
+
82
+ *timeout = uv_backend_timeout(bare__loop);
83
+
84
+ return *timeout == 0;
74
85
  }
75
86
 
76
87
  static gboolean
77
- bare__on_timeout(gpointer data) {
78
- bare__timer = 0;
88
+ bare__on_check(GSource *source) {
89
+ if (bare__exited) return FALSE;
79
90
 
80
- bare__run();
91
+ bare__source_t *self = (bare__source_t *) source;
81
92
 
82
- return G_SOURCE_REMOVE;
83
- }
93
+ if (g_source_query_unix_fd(source, self->poll) & G_IO_IN) return TRUE;
84
94
 
85
- static void
86
- bare__run(void) {
87
- int err;
95
+ uv_update_time(bare__loop);
88
96
 
89
- if (bare__timer) {
90
- g_source_remove(bare__timer);
97
+ return uv_backend_timeout(bare__loop) == 0;
98
+ }
91
99
 
92
- bare__timer = 0;
93
- }
100
+ static gboolean
101
+ bare__on_dispatch(GSource *source, GSourceFunc callback, gpointer data) {
102
+ int err;
94
103
 
95
104
  err = bare_run(bare, UV_RUN_NOWAIT);
96
105
  assert(err >= 0);
97
106
 
98
- if (bare__exited) return;
99
-
100
- int timeout = uv_backend_timeout(bare__loop);
101
-
102
- if (timeout == 0) {
103
- bare__timer = g_idle_add(bare__on_timeout, NULL);
104
- } else if (timeout > 0) {
105
- bare__timer = g_timeout_add(timeout, bare__on_timeout, NULL);
106
- }
107
+ return G_SOURCE_CONTINUE;
107
108
  }
108
109
 
110
+ static GSourceFuncs bare__source_funcs = {
111
+ .prepare = bare__on_prepare,
112
+ .check = bare__on_check,
113
+ .dispatch = bare__on_dispatch,
114
+ };
115
+
109
116
  static void
110
117
  bare__on_exit(bare_t *bare, void *data) {
111
118
  bare__exited = true;
@@ -146,13 +153,13 @@ bare__on_startup(GtkApplication *app, gpointer data) {
146
153
  err = bare_load(bare, entry, NULL, NULL);
147
154
  (void) err;
148
155
 
149
- bare__channel = g_io_channel_unix_new(bare__loop->backend_fd);
156
+ bare__source = g_source_new(&bare__source_funcs, sizeof(bare__source_t));
150
157
 
151
- bare__poll = g_io_add_watch(bare__channel, G_IO_IN, bare__on_poll, NULL);
158
+ bare__source_t *self = (bare__source_t *) bare__source;
152
159
 
153
- bare__timer = 0;
160
+ self->poll = g_source_add_unix_fd(bare__source, uv_backend_fd(bare__loop), G_IO_IN);
154
161
 
155
- bare__run();
162
+ g_source_attach(bare__source, NULL);
156
163
  }
157
164
 
158
165
  int
@@ -242,11 +249,9 @@ main(int argc, char *argv[]) {
242
249
 
243
250
  g_application_run(G_APPLICATION(app), argc, argv);
244
251
 
245
- g_source_remove(bare__poll);
246
-
247
- if (bare__timer) g_source_remove(bare__timer);
252
+ g_source_destroy(bare__source);
248
253
 
249
- g_io_channel_unref(bare__channel);
254
+ g_source_unref(bare__source);
250
255
 
251
256
  err = uv_async_send(&bare__shutdown);
252
257
  assert(err == 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-gtk",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "GTK bindings and runtime for Bare",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -41,6 +41,7 @@
41
41
  },
42
42
  "homepage": "https://github.com/holepunchto/bare-gtk#readme",
43
43
  "dependencies": {
44
+ "bare-events": "^2.8.2",
44
45
  "bare-gobject-registry": "^0.1.0",
45
46
  "require-asset": "^1.1.0"
46
47
  },
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/prebuilds/linux-arm64/bare
3
3
  size: 47015048 bytes
4
- sha256: 8d9d77a4bcd86204a09ea0c23155588d2cf7560038d24a380819871d68599a48
4
+ sha256: 26ec8929ce298b277b4c5ecc691a9349013e4a8d278b0df3444a18d367d99083
Binary file
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/prebuilds/linux-x64/bare
3
3
  size: 48145624 bytes
4
- sha256: 7703482d232cbde2ac3556775d808d24bfb75db0806c189126a35fcd3cabf78b
4
+ sha256: f3754d54d60bcb4bc6250954652fe1c75ad6be1c3590023632150dc197c35947
Binary file