BlinkGTK for Windows のソースです (BlinkGTK-Windows 提供)。Linux 版の
blinkgtk_browser.c
と違うのは、リソースの既定の場所 (実行ファイルの隣) と初期化
(blink_gtk_sandbox_init() +
blink_gtk_init_with_sandbox()) の 2 点です。
The BlinkGTK for Windows source (provided by BlinkGTK-Windows). It
differs from the Linux blinkgtk_browser.c in the default
resource location (next to the executable) and initialisation
(blink_gtk_sandbox_init() +
blink_gtk_init_with_sandbox()).
/*
* blinkgtk_browser.c — BlinkGTK の最小構成サンプル (Windows 版)
* A minimal BlinkGTK sample (Windows)
*
* ウィンドウを 1 つ開き、BlinkWebView で https://google.com/ を表示するだけの
* プログラムです。BlinkGTK を組み込むのに最低限必要なものだけを示します。
*
* Opens a single window and displays https://google.com/ in a BlinkWebView.
* It shows only what is strictly required to embed BlinkGTK.
*
* 元にしたもの / Based on:
* BlinkGTK 本体 examples/dist/blinkgtk_browser.c (cdff43f4、2026-09-10)
* Windows 向けに変えたのは次の 2 点だけです。
* Only two things differ from the original:
* 1. リソースの既定の場所 — 指定しなければ実行ファイルの隣を使う
* (本体の既定 /usr/lib64/blinkgtk-0.1/chromium は Linux の場所)
* Resources default to the directory of the executable.
* 2. 初期化 — Windows では blink_gtk_sandbox_init() と
* blink_gtk_init_with_sandbox() を使う (サンドボックスの broker は
* EXE 側に要るため)
* Initialization uses blink_gtk_sandbox_init() and
* blink_gtk_init_with_sandbox(): the sandbox broker must live in
* the EXE on Windows.
*
* ビルド / Build:
* BlinkGTK for Windows の devel ZIP の同梱文書
* (building-with-blinkgtk-ja.md) を参照してください。
* See building-with-blinkgtk-ja.md in the devel ZIP.
*
* 実行 / Run:
* blinkgtk_browser.exe
* blinkgtk_browser.exe https://example.com/ (URL を指定する場合 / to specify a URL)
* blinkgtk_browser.exe --version (版を表示 / print the version)
* blinkgtk_browser.exe --help (使い方 / usage)
*
* Copyright 2026 BlinkGTK Project
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <blink_gtk/blink_gtk.h>
#include <gtk/gtk.h>
/* 起動時に開く URL / The URL opened at startup */
#define DEFAULT_URL "https://google.com/"
/* ウィンドウを閉じたらメインループを抜ける。
* Quit the main loop when the window is closed. */
static gboolean on_close_request(GtkWindow *window, gpointer user_data)
{
(void)window;
(void)user_data;
blink_gtk_quit_main_loop();
return FALSE;
}
/* --version / --help は初期化より前に処理する。
* 版数の API は初期化前でも呼べる。
* 不具合を報告するときは、この 1 行を貼れば版が一意に決まる。
*
* Handle --version / --help before initialization. The version API may be
* called before initialization. When reporting a problem, this single line
* identifies the build. */
static int print_version(void)
{
const char *full = blink_gtk_get_version_full(); /* 例: "X.Y.Z-buildN" */
const char *chromium = blink_gtk_get_chromium_version();
g_print("BlinkGTK %s (Chromium %s)\n",
full ? full : blink_gtk_get_version(),
chromium ? chromium : "unknown");
return 0;
}
static int print_usage(const char *argv0)
{
g_print("使い方 / Usage: %s [URL]\n"
" URL 開く URL (既定 " DEFAULT_URL ")\n"
" the URL to open (default " DEFAULT_URL ")\n"
" --version 版を表示する / print the version\n"
" --help この使い方を表示する / print this usage\n",
argv0);
return 0;
}
int main(int argc, char **argv)
{
for (int i = 1; i < argc; i++) {
if (g_strcmp0(argv[i], "--version") == 0) {
return print_version();
}
if (g_strcmp0(argv[i], "--help") == 0 || g_strcmp0(argv[i], "-h") == 0) {
return print_usage(argv[0]);
}
}
/* 1. Chromium のリソース (icudtl.dat / *.pak / V8 スナップショット) の場所。
* Windows 版では、何も指定しなければ **実行ファイルのあるディレクトリ**
* から探す。配布物の bin\ から起動するなら指定は要らない。
* リソースを別の場所に置く場合だけ、BLINKGTK_RESOURCES 環境変数で指定する。
*
* Where Chromium's resources (icudtl.dat, *.pak, the V8 snapshots) are.
* On Windows they are looked up in the directory containing the
* executable when nothing is set, so running from the package's bin\
* needs nothing. Set BLINKGTK_RESOURCES only if they live elsewhere. */
const char *res = g_getenv("BLINKGTK_RESOURCES");
if (res) {
blink_gtk_set_resources_path(res);
blink_gtk_set_icu_data_path(res);
}
/* 2. BlinkGTK (Chromium) を初期化する。GTK より先に呼ぶ。
* Windows では、サンドボックスの情報を EXE 側で作って渡す。
* Initialize BlinkGTK (Chromium). Call this before GTK.
* On Windows, the sandbox information is created in the EXE and
* passed in. */
void *sandbox_info = blink_gtk_sandbox_init();
if (!blink_gtk_init_with_sandbox(&argc, &argv, sandbox_info)) {
g_printerr("blink_gtk_init_with_sandbox() に失敗しました / failed\n");
return 1;
}
gtk_init();
const char *url = (argc > 1 && argv[1][0] != '-') ? argv[1] : DEFAULT_URL;
/* 3. ウィンドウと BlinkWebView を作る。
* blink_web_view_new() は GtkWidget * を返すので、BlinkGTK の API に
* 渡すときは BLINK_WEB_VIEW() でキャストする。
*
* Create the window and the BlinkWebView. blink_web_view_new() returns a
* GtkWidget *, so cast with BLINK_WEB_VIEW() when passing it to the
* BlinkGTK API. */
GtkWidget *window = gtk_window_new();
gtk_window_set_title(GTK_WINDOW(window), "BlinkGTK");
gtk_window_set_default_size(GTK_WINDOW(window), 1024, 768);
g_signal_connect(window, "close-request", G_CALLBACK(on_close_request), NULL);
GtkWidget *view = blink_web_view_new();
gtk_window_set_child(GTK_WINDOW(window), view);
/* 4. ウィンドウを表示してから URL を読み込む。
* Present the window, then load the URL. */
gtk_window_present(GTK_WINDOW(window));
blink_web_view_load_uri(BLINK_WEB_VIEW(view), url);
/* 5. Chromium のメインループを回す。
* GTK の g_application_run() ではなく、必ずこちらを使う。
* BlinkGTK は Chromium のメインループの上で動く。
*
* Run Chromium's main loop. Always use this instead of GTK's
* g_application_run(): BlinkGTK runs on Chromium's main loop. */
return blink_gtk_run_main_loop();
}