Make the inspector not crash on exit
[xxxterm.git] / xxxterm.h
blobad49fc70014d8f1fdbed3b71ab41bfc66d8ff807
1 /*
2 * Copyright (c) 2011 Conformal Systems LLC <info@conformal.com>
3 * Copyright (c) 2011 Marco Peereboom <marco@peereboom.us>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <ctype.h>
19 #include <dlfcn.h>
20 #include <err.h>
21 #include <errno.h>
22 #include <libgen.h>
23 #include <pwd.h>
24 #include <regex.h>
25 #include <signal.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <dirent.h>
32 #include <sys/types.h>
33 #include <sys/wait.h>
34 #if defined(__linux__)
35 #include "linux/util.h"
36 #include "linux/tree.h"
37 #include <bsd/stdlib.h>
38 # if !defined(sane_libbsd_headers)
39 void arc4random_buf(void *, size_t);
40 # endif
41 #elif defined(__FreeBSD__)
42 #include <libutil.h>
43 #include "freebsd/util.h"
44 #include <sys/tree.h>
45 #else /* OpenBSD */
46 #include <util.h>
47 #include <sys/tree.h>
48 #endif
49 #include <sys/queue.h>
50 #include <sys/resource.h>
51 #include <sys/socket.h>
52 #include <sys/stat.h>
53 #include <sys/time.h>
54 #include <sys/un.h>
56 #include <gtk/gtk.h>
57 #include <gdk/gdkkeysyms.h>
59 #if GTK_CHECK_VERSION(3,0,0)
60 /* we still use GDK_* instead of GDK_KEY_* */
61 #include <gdk/gdkkeysyms-compat.h>
62 #endif
64 #include <webkit/webkit.h>
65 #include <libsoup/soup.h>
66 #include <JavaScriptCore/JavaScript.h>
67 #include <gnutls/gnutls.h>
68 #include <gnutls/x509.h>
70 /* comment if you don't want to use threads */
71 //#define USE_THREADS
73 #ifdef USE_THREADS
74 #include <gcrypt.h>
75 #include <pthread.h>
76 #endif
78 #include "version.h"
79 #include "javascript.h"
81 javascript.h borrowed from vimprobable2 under the following license:
83 Copyright (c) 2009 Leon Winter
84 Copyright (c) 2009-2011 Hannes Schueller
85 Copyright (c) 2009-2010 Matto Fransen
86 Copyright (c) 2010-2011 Hans-Peter Deifel
87 Copyright (c) 2010-2011 Thomas Adam
88 Copyright (c) 2011 Albert Kim
89 Copyright (c) 2011 Daniel Carl
91 Permission is hereby granted, free of charge, to any person obtaining a copy
92 of this software and associated documentation files (the "Software"), to deal
93 in the Software without restriction, including without limitation the rights
94 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
95 copies of the Software, and to permit persons to whom the Software is
96 furnished to do so, subject to the following conditions:
98 The above copyright notice and this permission notice shall be included in
99 all copies or substantial portions of the Software.
101 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
104 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
107 THE SOFTWARE.
110 /*#define XT_DEBUG*/
111 #ifdef XT_DEBUG
112 #define DPRINTF(x...) do { if (swm_debug) fprintf(stderr, x); } while (0)
113 #define DNPRINTF(n,x...) do { if (swm_debug & n) fprintf(stderr, x); } while (0)
114 #define XT_D_MOVE 0x0001
115 #define XT_D_KEY 0x0002
116 #define XT_D_TAB 0x0004
117 #define XT_D_URL 0x0008
118 #define XT_D_CMD 0x0010
119 #define XT_D_NAV 0x0020
120 #define XT_D_DOWNLOAD 0x0040
121 #define XT_D_CONFIG 0x0080
122 #define XT_D_JS 0x0100
123 #define XT_D_FAVORITE 0x0200
124 #define XT_D_PRINTING 0x0400
125 #define XT_D_COOKIE 0x0800
126 #define XT_D_KEYBINDING 0x1000
127 #define XT_D_CLIP 0x2000
128 #define XT_D_BUFFERCMD 0x4000
129 #define XT_D_INSPECTOR 0x8000
130 extern u_int32_t swm_debug;
131 #else
132 #define DPRINTF(x...)
133 #define DNPRINTF(n,x...)
134 #endif
136 #define LENGTH(x) (sizeof x / sizeof x[0])
137 #define CLEAN(mask) (mask & ~(GDK_MOD2_MASK) & \
138 ~(GDK_BUTTON1_MASK) & \
139 ~(GDK_BUTTON2_MASK) & \
140 ~(GDK_BUTTON3_MASK) & \
141 ~(GDK_BUTTON4_MASK) & \
142 ~(GDK_BUTTON5_MASK))
144 #define XT_NOMARKS (('z' - 'a' + 1) * 2 + 10)
146 struct tab {
147 TAILQ_ENTRY(tab) entry;
148 GtkWidget *vbox;
149 GtkWidget *tab_content;
150 struct {
151 GtkWidget *label;
152 GtkWidget *eventbox;
153 GtkWidget *box;
154 GtkWidget *sep;
155 } tab_elems;
156 GtkWidget *label;
157 GtkWidget *spinner;
158 GtkWidget *uri_entry;
159 GtkWidget *search_entry;
160 GtkWidget *toolbar;
161 GtkWidget *browser_win;
162 GtkWidget *statusbar_box;
163 struct {
164 GtkWidget *statusbar;
165 GtkWidget *buffercmd;
166 GtkWidget *zoom;
167 GtkWidget *position;
168 } sbe;
169 GtkWidget *cmd;
170 GtkWidget *buffers;
171 GtkWidget *oops;
172 GtkWidget *backward;
173 GtkWidget *forward;
174 GtkWidget *stop;
175 GtkWidget *gohome;
176 GtkWidget *js_toggle;
177 GtkEntryCompletion *completion;
178 guint tab_id;
179 WebKitWebView *wv;
181 WebKitWebHistoryItem *item;
182 WebKitWebBackForwardList *bfl;
184 /* favicon */
185 WebKitNetworkRequest *icon_request;
186 WebKitDownload *icon_download;
187 gchar *icon_dest_uri;
189 /* adjustments for browser */
190 GtkScrollbar *sb_h;
191 GtkScrollbar *sb_v;
192 GtkAdjustment *adjust_h;
193 GtkAdjustment *adjust_v;
195 /* flags */
196 int focus_wv;
197 int ctrl_click;
198 gchar *status;
199 int xtp_meaning; /* identifies dls/favorites */
200 gchar *tmp_uri;
201 int popup; /* 1 if cmd_entry has popup visible */
202 #ifdef USE_THREADS
203 /* https thread stuff */
204 GThread *thread;
205 #endif
206 /* hints */
207 int script_init;
208 int hints_on;
209 int new_tab;
211 /* custom stylesheet */
212 int styled;
213 char *stylesheet;
215 /* search */
216 char *search_text;
217 int search_forward;
218 guint search_id;
220 /* settings */
221 WebKitWebSettings *settings;
222 gchar *user_agent;
224 /* marks */
225 double mark[XT_NOMARKS];
227 /* inspector */
228 WebKitWebInspector *inspector;
229 GtkWidget *inspector_window;
230 GtkWidget *inspector_view;
232 TAILQ_HEAD(tab_list, tab);
234 struct karg {
235 int i;
236 char *s;
237 int precount;
240 /* utility */
241 #define XT_CB_HANDLED (TRUE)
242 #define XT_CB_PASSTHROUGH (FALSE)
243 GtkWidget *create_window(const gchar *);
245 /* inspector */
246 #define XT_INS_SHOW (1<<0)
247 #define XT_INS_HIDE (1<<1)
248 #define XT_INS_CLOSE (1<<2)
249 WebKitWebView* inspector_inspect_web_view_cb(WebKitWebInspector *,
250 WebKitWebView*, struct tab *);
251 void setup_inspector(struct tab *);
252 int inspector_cmd(struct tab *, struct karg *);