2 * gtkapp.c: a top-level front end to GUI PuTTY and pterm, using
3 * GtkApplication. Suitable for OS X. Currently unfinished.
5 * (You could run it on ordinary Linux GTK too, in principle, but I
6 * don't think it would be particularly useful to do so, even once
17 #define MAY_REFER_TO_GTK_IN_HEADERS
21 char *x_get_default(const char *key) { return NULL; }
23 #if !GTK_CHECK_VERSION(3,0,0)
24 /* This front end only works in GTK 3. If that's not what we've got,
25 * it's easier to just turn this program into a trivial stub by ifdef
26 * in the source than it is to remove it in the makefile edifice. */
27 int main(int argc, char **argv)
29 fprintf(stderr, "launcher does nothing on non-OSX platforms\n");
32 GtkWidget *make_gtk_toplevel_window(void *frontend) { return NULL; }
33 void launch_duplicate_session(Conf *conf) {}
34 void launch_new_session(void) {}
35 void launch_saved_session(const char *str) {}
36 #else /* GTK_CHECK_VERSION(3,0,0) */
38 static void startup(GApplication *app, gpointer user_data)
40 GMenu *menubar, *menu, *section;
42 menubar = g_menu_new();
45 g_menu_append_submenu(menubar, "File", G_MENU_MODEL(menu));
47 section = g_menu_new();
48 g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
49 g_menu_append(section, "New Window", "app.newwin");
52 g_menu_append_submenu(menubar, "Edit", G_MENU_MODEL(menu));
54 section = g_menu_new();
55 g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
56 g_menu_append(section, "Paste", "win.paste");
58 gtk_application_set_menubar(GTK_APPLICATION(app),
59 G_MENU_MODEL(menubar));
62 static void paste_cb(GSimpleAction *action,
66 request_paste(user_data);
69 static const GActionEntry win_actions[] = {
70 { "paste", paste_cb },
73 static GtkApplication *app;
74 GtkWidget *make_gtk_toplevel_window(void *frontend)
76 GtkWidget *win = gtk_application_window_new(app);
77 g_action_map_add_action_entries(G_ACTION_MAP(win),
79 G_N_ELEMENTS(win_actions),
84 extern int cfgbox(Conf *conf);
86 void launch_duplicate_session(Conf *conf)
88 assert(conf_launchable(conf));
89 new_session_window(conf, NULL);
92 void launch_new_session(void)
94 Conf *conf = conf_new();
95 do_defaults(NULL, conf);
96 if (conf_launchable(conf) || cfgbox(conf)) {
97 new_session_window(conf, NULL);
101 void launch_saved_session(const char *str)
103 Conf *conf = conf_new();
104 do_defaults(str, conf);
105 if (conf_launchable(conf) || cfgbox(conf)) {
106 new_session_window(conf, NULL);
110 void new_app_win(GtkApplication *app)
112 launch_new_session();
115 static void activate(GApplication *app,
118 new_app_win(GTK_APPLICATION(app));
121 static void newwin_cb(GSimpleAction *action,
125 new_app_win(GTK_APPLICATION(user_data));
128 static void quit_cb(GSimpleAction *action,
132 g_application_quit(G_APPLICATION(user_data));
135 static const GActionEntry app_actions[] = {
136 { "newwin", newwin_cb },
140 int main(int argc, char **argv)
145 /* Call the function in ux{putty,pterm}.c to do app-type
147 extern void setup(int);
148 setup(FALSE); /* FALSE means we are not a one-session process */
152 extern char *pty_osx_envrestore_prefix;
153 pty_osx_envrestore_prefix = argv[--argc];
157 const char *home = getenv("HOME");
165 app = gtk_application_new("org.tartarus.projects.putty.macputty",
166 G_APPLICATION_FLAGS_NONE);
167 g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
168 g_signal_connect(app, "startup", G_CALLBACK(startup), NULL);
169 g_action_map_add_action_entries(G_ACTION_MAP(app),
171 G_N_ELEMENTS(app_actions),
174 status = g_application_run(G_APPLICATION(app), argc, argv);
180 #endif /* GTK_CHECK_VERSION(3,0,0) */