From: Daniel Carl Date: Fri, 6 Jun 2014 20:07:57 +0000 (+0200) Subject: Export pid, xid and page title into environment. X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=a674ecd75105b1b03d234ef0ad458432e23316fd;p=vimb.git Export pid, xid and page title into environment. --- diff --git a/doc/vimb.1 b/doc/vimb.1 index c673ff1..bfd35ea 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -914,6 +914,16 @@ File for userdefined css styles. These file is used if the config variable This variable is set by vimb everytime a new page is opened to the URI of the page. .TP +.B VIMB_TITLE +Contains the title of the current opened page. +.TP +.B VIMB_PID +Contains the pid of the running vimb instance. +.TP +.B VIMB_XID +Holds the X-Window id of the vim window or of the embedding window if vimb is +started with -e option. +.TP .B http_proxy If this variable is set to an none empty value, and the configuration option `proxy' is enabled, this will be used as http proxy. diff --git a/src/main.c b/src/main.c index 495bcfe..17a3803 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,8 @@ #include "config.h" #include #include +#include +#include #include "main.h" #include "util.h" #include "command.h" @@ -655,18 +657,29 @@ static void set_status(const StatusType status) static void init_core(void) { Gui *gui = &vb.gui; + char *xid; if (vb.embed) { gui->window = gtk_plug_new(vb.embed); + xid = g_strdup_printf("%u", (int)vb.embed); } else { + gui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); #ifdef HAS_GTK3 gtk_window_set_has_resize_grip(GTK_WINDOW(gui->window), false); #endif gtk_window_set_wmclass(GTK_WINDOW(gui->window), PROJECT, PROJECT_UCFIRST); gtk_window_set_role(GTK_WINDOW(gui->window), PROJECT_UCFIRST); + + gtk_widget_realize(GTK_WIDGET(gui->window)); + + /* set the x window id to env */ + xid = g_strdup_printf("%d", (int)GDK_WINDOW_XID(gtk_widget_get_window(GTK_WIDGET(gui->window)))); } + g_setenv("VIMB_XID", xid, true); + g_free(xid); + GdkGeometry hints = {10, 10}; gtk_window_set_default_size(GTK_WINDOW(gui->window), WIN_WIDTH, WIN_HEIGHT); gtk_window_set_title(GTK_WINDOW(gui->window), PROJECT "/" VERSION); @@ -1121,6 +1134,7 @@ static void title_changed_cb(WebKitWebView *webview, WebKitWebFrame *frame, cons { OVERWRITE_STRING(vb.state.title, title); update_title(); + g_setenv("VIMB_TITLE", title ? title : "", true); } static void update_title(void) @@ -1244,6 +1258,7 @@ int main(int argc, char *argv[]) static char *winid = NULL; static gboolean ver = false; static GError *err; + char *pid; static GOptionEntry opts[] = { {"cmd", 'C', 0, G_OPTION_ARG_STRING, &vb.config.autocmd, "Ex command run before first page is loaded", NULL}, @@ -1273,6 +1288,10 @@ int main(int argc, char *argv[]) vb.embed = strtol(winid, NULL, 0); } + pid = g_strdup_printf("%d", getpid()); + g_setenv("VIMB_PID", pid, true); + g_free(pid); + init_core(); /* process the --cmd if this was given */