Skip to content

Instantly share code, notes, and snippets.

@liskin
Last active April 23, 2020 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liskin/3862315448ea18167a420f3664e52026 to your computer and use it in GitHub Desktop.
Save liskin/3862315448ea18167a420f3664e52026 to your computer and use it in GitHub Desktop.
frameclock
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
static gboolean tick(GtkWidget *off_window, GdkFrameClock *clock, gpointer data) {
puts("tick");
static int ttl = 10;
if (--ttl <= 0)
gtk_widget_destroy(off_window);
return G_SOURCE_CONTINUE;
}
static void update(GdkFrameClock *clock, gpointer data) {
puts("update");
static int ttl = 10;
if (--ttl <= 0) {
gdk_frame_clock_end_updating(clock);
gtk_widget_destroy((GtkWidget *) data);
}
}
static gboolean timeout(gpointer data) {
gtk_main_quit();
return G_SOURCE_REMOVE;
}
int main(int argc, char **argv) {
gtk_init(&argc, &argv);
GtkWidget *off_window = gtk_offscreen_window_new();
gtk_widget_realize(off_window);
if (argc == 2 && strcmp(argv[1], "tick") == 0) {
gtk_widget_add_tick_callback(off_window, tick, NULL, NULL);
} else {
GdkFrameClock *clock = gtk_widget_get_frame_clock(off_window);
g_signal_connect(clock, "update", G_CALLBACK(update), off_window);
gdk_frame_clock_begin_updating(clock);
}
g_timeout_add(1000, timeout, NULL);
gtk_main();
}
.PHONY: build
build: _build/build.ninja
ninja -C _build
_build/build.ninja: | meson.build
meson _build
.PHONY: clean
clean:
git clean -fdX
project(
'frameclock', 'c',
version: '0.1',
)
cc = meson.get_compiler('c')
executable(
'frameclock',
sources: 'frameclock.c',
dependencies: [
dependency('gtk+-3.0'),
],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment