2016-03-23 22:22:30 +00:00
|
|
|
/*
|
|
|
|
* gtkapp.c: a top-level front end to GUI PuTTY and pterm, using
|
|
|
|
* GtkApplication. Suitable for OS X. Currently unfinished.
|
|
|
|
*
|
|
|
|
* (You could run it on ordinary Linux GTK too, in principle, but I
|
|
|
|
* don't think it would be particularly useful to do so, even once
|
|
|
|
* it's fully working.)
|
|
|
|
*/
|
|
|
|
|
2016-03-23 22:14:13 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
To build on OS X, you will need a build environment with GTK 3 and
|
|
|
|
gtk-mac-bundler, and also Halibut on the path (to build the man pages,
|
|
|
|
without which the standard Makefile will complain). Then, from a clean
|
|
|
|
checkout, do this:
|
|
|
|
|
|
|
|
./mkfiles.pl -U --with-quartz
|
|
|
|
make -C icons icns
|
|
|
|
make -C doc
|
|
|
|
make
|
|
|
|
|
|
|
|
and you should get unix/PuTTY.app and unix/PTerm.app as output.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-03-23 22:17:09 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
TODO list for a sensible GTK3 PuTTY/pterm on OS X:
|
|
|
|
|
2017-12-18 14:04:57 +00:00
|
|
|
Still to do on the application menu bar: items that have to vary with
|
|
|
|
context or user action (saved sessions and mid-session special
|
|
|
|
commands), and disabling/enabling the main actions in parallel with
|
|
|
|
their counterparts in the Ctrl-rightclick context menu.
|
|
|
|
|
2016-03-23 22:17:09 +00:00
|
|
|
Mouse wheel events and trackpad scrolling gestures don't work quite
|
2017-12-18 14:04:57 +00:00
|
|
|
right in the terminal drawing area. This seems to be a combination of
|
|
|
|
two things, neither of which I completely understand yet. Firstly, on
|
|
|
|
OS X GTK my trackpad seems to generate GDK scroll events for which
|
|
|
|
gdk_event_get_scroll_deltas returns integers rather than integer
|
|
|
|
multiples of 1/30, so we end up scrolling by very large amounts;
|
|
|
|
secondly, the window doesn't seem to receive a GTK "draw" event until
|
|
|
|
after the entire scroll gesture is complete, which means we don't get
|
|
|
|
constant visual feedback on how much we're scrolling by.
|
2016-03-23 22:17:09 +00:00
|
|
|
|
2017-12-18 14:04:57 +00:00
|
|
|
There doesn't seem to be a resize handle on terminal windows. Then
|
|
|
|
again, they do seem to _be_ resizable; the handle just isn't shown.
|
|
|
|
Perhaps that's a feature (certainly in a scrollbarless configuration
|
|
|
|
the handle gets in the way of the bottom right character cell in the
|
|
|
|
terminal itself), but it would be nice to at least understand _why_ it
|
|
|
|
happens and perhaps include an option to put it back again.
|
2016-03-23 22:17:09 +00:00
|
|
|
|
|
|
|
A slight oddity with menus that pop up directly under the mouse
|
|
|
|
pointer: mousing over the menu items doesn't highlight them initially,
|
|
|
|
but if I mouse off the menu and back on (without un-popping-it-up)
|
|
|
|
then suddenly that does work. I don't know if this is something I can
|
|
|
|
fix, though; it might very well be a quirk of the underlying GTK.
|
|
|
|
|
|
|
|
Does OS X have a standard system of online help that I could tie into?
|
|
|
|
|
|
|
|
Need to work out what if anything we can do with Pageant on OS X.
|
|
|
|
Perhaps it's too much bother and we should just talk to the
|
|
|
|
system-provided SSH agent? Or perhaps not.
|
|
|
|
|
|
|
|
Nice-to-have: a custom right-click menu from the application's dock
|
|
|
|
tile, listing the saved sessions for quick launch. As far as I know
|
|
|
|
there's nothing built in to GtkApplication that can produce this, but
|
|
|
|
it's possible we might be able to drop a piece of native Cocoa code in
|
|
|
|
under ifdef, substituting an application delegate of our own which
|
|
|
|
forwards all methods we're not interested in to the GTK-provided one?
|
|
|
|
|
|
|
|
At the point where this becomes polished enough to publish pre-built,
|
|
|
|
I suppose I'll have to look into OS X code signing.
|
|
|
|
https://wiki.gnome.org/Projects/GTK%2B/OSX/Bundling has some links.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-03-23 22:22:30 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#define MAY_REFER_TO_GTK_IN_HEADERS
|
|
|
|
|
|
|
|
#include "putty.h"
|
2017-11-27 20:09:54 +00:00
|
|
|
#include "gtkmisc.h"
|
2016-03-23 22:22:30 +00:00
|
|
|
|
|
|
|
char *x_get_default(const char *key) { return NULL; }
|
|
|
|
|
2018-10-29 19:50:29 +00:00
|
|
|
const int buildinfo_gtk_relevant = true;
|
2017-02-22 22:10:05 +00:00
|
|
|
|
2016-03-23 22:22:30 +00:00
|
|
|
#if !GTK_CHECK_VERSION(3,0,0)
|
|
|
|
/* This front end only works in GTK 3. If that's not what we've got,
|
|
|
|
* it's easier to just turn this program into a trivial stub by ifdef
|
|
|
|
* in the source than it is to remove it in the makefile edifice. */
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2017-11-25 21:55:17 +00:00
|
|
|
fprintf(stderr, "GtkApplication frontend doesn't work pre-GTK3\n");
|
2016-03-23 22:22:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
Remove the 'Frontend' type and replace it with a vtable.
After the recent Seat and LogContext revamps, _nearly_ all the
remaining uses of the type 'Frontend' were in terminal.c, which needs
all sorts of interactions with the GUI window the terminal lives in,
from the obvious (actually drawing text on the window, reading and
writing the clipboard) to the obscure (minimising, maximising and
moving the window in response to particular escape sequences).
All of those functions are now provided by an abstraction called
TermWin. The few remaining uses of Frontend after _that_ are internal
to a particular platform directory, so as to spread the implementation
of that particular kind of Frontend between multiple source files; so
I've renamed all of those so that they take a more specifically named
type that refers to the particular implementation rather than the
general abstraction.
So now the name 'Frontend' no longer exists in the code base at all,
and everywhere one used to be used, it's completely clear whether it
was operating in one of Frontend's three abstract roles (and if so,
which), or whether it was specific to a particular implementation.
Another type that's disappeared is 'Context', which used to be a
typedef defined to something different on each platform, describing
whatever short-lived resources were necessary to draw on the terminal
window: the front end would provide a ready-made one when calling
term_paint, and the terminal could request one with get_ctx/free_ctx
if it wanted to do proactive window updates. Now that drawing context
lives inside the TermWin itself, because there was never any need to
have two of those contexts live at the same time.
(Another minor API change is that the window-title functions - both
reading and writing - have had a missing 'const' added to their char *
parameters / return values.)
I don't expect this change to enable any particularly interesting new
functionality (in particular, I have no plans that need more than one
implementation of TermWin in the same application). But it completes
the tidying-up that began with the Seat and LogContext rework.
2018-10-25 17:44:04 +00:00
|
|
|
GtkWidget *make_gtk_toplevel_window(GtkFrontend *frontend) { return NULL; }
|
2016-03-23 22:22:30 +00:00
|
|
|
void launch_duplicate_session(Conf *conf) {}
|
|
|
|
void launch_new_session(void) {}
|
|
|
|
void launch_saved_session(const char *str) {}
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
void session_window_closed(void) {}
|
2018-01-30 19:22:45 +00:00
|
|
|
void window_setup_error(const char *errmsg) {}
|
2016-03-23 22:22:30 +00:00
|
|
|
#else /* GTK_CHECK_VERSION(3,0,0) */
|
|
|
|
|
2017-12-18 11:46:48 +00:00
|
|
|
extern const int use_event_log;
|
|
|
|
|
2016-03-23 22:22:30 +00:00
|
|
|
static void startup(GApplication *app, gpointer user_data)
|
|
|
|
{
|
|
|
|
GMenu *menubar, *menu, *section;
|
|
|
|
|
|
|
|
menubar = g_menu_new();
|
|
|
|
|
|
|
|
menu = g_menu_new();
|
|
|
|
g_menu_append_submenu(menubar, "File", G_MENU_MODEL(menu));
|
|
|
|
|
|
|
|
section = g_menu_new();
|
|
|
|
g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
|
|
|
|
g_menu_append(section, "New Window", "app.newwin");
|
|
|
|
|
|
|
|
menu = g_menu_new();
|
|
|
|
g_menu_append_submenu(menubar, "Edit", G_MENU_MODEL(menu));
|
|
|
|
|
|
|
|
section = g_menu_new();
|
|
|
|
g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
|
2017-12-17 20:35:45 +00:00
|
|
|
g_menu_append(section, "Copy", "win.copy");
|
2016-03-23 22:22:30 +00:00
|
|
|
g_menu_append(section, "Paste", "win.paste");
|
2017-12-18 11:46:48 +00:00
|
|
|
g_menu_append(section, "Copy All", "win.copyall");
|
|
|
|
|
|
|
|
menu = g_menu_new();
|
|
|
|
g_menu_append_submenu(menubar, "Window", G_MENU_MODEL(menu));
|
|
|
|
|
|
|
|
section = g_menu_new();
|
|
|
|
g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
|
|
|
|
g_menu_append(section, "Restart Session", "win.restart");
|
|
|
|
g_menu_append(section, "Duplicate Session", "win.duplicate");
|
|
|
|
|
|
|
|
section = g_menu_new();
|
|
|
|
g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
|
|
|
|
g_menu_append(section, "Change Settings", "win.changesettings");
|
|
|
|
|
|
|
|
if (use_event_log) {
|
|
|
|
section = g_menu_new();
|
|
|
|
g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
|
|
|
|
g_menu_append(section, "Event Log", "win.eventlog");
|
|
|
|
}
|
|
|
|
|
|
|
|
section = g_menu_new();
|
|
|
|
g_menu_append_section(menu, NULL, G_MENU_MODEL(section));
|
|
|
|
g_menu_append(section, "Clear Scrollback", "win.clearscrollback");
|
|
|
|
g_menu_append(section, "Reset Terminal", "win.resetterm");
|
2016-03-23 22:22:30 +00:00
|
|
|
|
2017-12-20 11:55:51 +00:00
|
|
|
#if GTK_CHECK_VERSION(3,12,0)
|
2017-12-18 11:01:42 +00:00
|
|
|
#define SET_ACCEL(app, command, accel) do \
|
|
|
|
{ \
|
|
|
|
static const char *const accels[] = { accel, NULL }; \
|
|
|
|
gtk_application_set_accels_for_action( \
|
|
|
|
GTK_APPLICATION(app), command, accels); \
|
|
|
|
} while (0)
|
2017-12-20 11:55:51 +00:00
|
|
|
#else
|
|
|
|
/* The Gtk function used above was new in 3.12; the one below
|
|
|
|
* was deprecated from 3.14. */
|
|
|
|
#define SET_ACCEL(app, command, accel) \
|
|
|
|
gtk_application_add_accelerator(GTK_APPLICATION(app), accel, \
|
|
|
|
command, NULL)
|
|
|
|
#endif
|
2017-12-18 11:01:42 +00:00
|
|
|
|
|
|
|
SET_ACCEL(app, "app.newwin", "<Primary>n");
|
|
|
|
SET_ACCEL(app, "win.copy", "<Primary>c");
|
|
|
|
SET_ACCEL(app, "win.paste", "<Primary>v");
|
|
|
|
|
|
|
|
#undef SET_ACCEL
|
|
|
|
|
2016-03-23 22:22:30 +00:00
|
|
|
gtk_application_set_menubar(GTK_APPLICATION(app),
|
|
|
|
G_MENU_MODEL(menubar));
|
|
|
|
}
|
|
|
|
|
2017-12-18 11:15:44 +00:00
|
|
|
#define WIN_ACTION_LIST(X) \
|
|
|
|
X("copy", MA_COPY) \
|
|
|
|
X("paste", MA_PASTE) \
|
2017-12-18 11:46:48 +00:00
|
|
|
X("copyall", MA_COPY_ALL) \
|
|
|
|
X("duplicate", MA_DUPLICATE_SESSION) \
|
|
|
|
X("restart", MA_RESTART_SESSION) \
|
|
|
|
X("changesettings", MA_CHANGE_SETTINGS) \
|
|
|
|
X("clearscrollback", MA_CLEAR_SCROLLBACK) \
|
|
|
|
X("resetterm", MA_RESET_TERMINAL) \
|
|
|
|
X("eventlog", MA_EVENT_LOG) \
|
2017-12-18 11:15:44 +00:00
|
|
|
/* end of list */
|
2017-12-17 20:35:45 +00:00
|
|
|
|
2017-12-18 11:15:44 +00:00
|
|
|
#define WIN_ACTION_CALLBACK(name, id) \
|
|
|
|
static void win_action_cb_ ## id(GSimpleAction *a, GVariant *p, gpointer d) \
|
|
|
|
{ app_menu_action(d, id); }
|
|
|
|
WIN_ACTION_LIST(WIN_ACTION_CALLBACK)
|
|
|
|
#undef WIN_ACTION_CALLBACK
|
2016-03-23 22:22:30 +00:00
|
|
|
|
|
|
|
static const GActionEntry win_actions[] = {
|
2017-12-18 11:15:44 +00:00
|
|
|
#define WIN_ACTION_ENTRY(name, id) { name, win_action_cb_ ## id },
|
|
|
|
WIN_ACTION_LIST(WIN_ACTION_ENTRY)
|
|
|
|
#undef WIN_ACTION_ENTRY
|
2016-03-23 22:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GtkApplication *app;
|
Remove the 'Frontend' type and replace it with a vtable.
After the recent Seat and LogContext revamps, _nearly_ all the
remaining uses of the type 'Frontend' were in terminal.c, which needs
all sorts of interactions with the GUI window the terminal lives in,
from the obvious (actually drawing text on the window, reading and
writing the clipboard) to the obscure (minimising, maximising and
moving the window in response to particular escape sequences).
All of those functions are now provided by an abstraction called
TermWin. The few remaining uses of Frontend after _that_ are internal
to a particular platform directory, so as to spread the implementation
of that particular kind of Frontend between multiple source files; so
I've renamed all of those so that they take a more specifically named
type that refers to the particular implementation rather than the
general abstraction.
So now the name 'Frontend' no longer exists in the code base at all,
and everywhere one used to be used, it's completely clear whether it
was operating in one of Frontend's three abstract roles (and if so,
which), or whether it was specific to a particular implementation.
Another type that's disappeared is 'Context', which used to be a
typedef defined to something different on each platform, describing
whatever short-lived resources were necessary to draw on the terminal
window: the front end would provide a ready-made one when calling
term_paint, and the terminal could request one with get_ctx/free_ctx
if it wanted to do proactive window updates. Now that drawing context
lives inside the TermWin itself, because there was never any need to
have two of those contexts live at the same time.
(Another minor API change is that the window-title functions - both
reading and writing - have had a missing 'const' added to their char *
parameters / return values.)
I don't expect this change to enable any particularly interesting new
functionality (in particular, I have no plans that need more than one
implementation of TermWin in the same application). But it completes
the tidying-up that began with the Seat and LogContext rework.
2018-10-25 17:44:04 +00:00
|
|
|
GtkWidget *make_gtk_toplevel_window(GtkFrontend *frontend)
|
2016-03-23 22:22:30 +00:00
|
|
|
{
|
|
|
|
GtkWidget *win = gtk_application_window_new(app);
|
|
|
|
g_action_map_add_action_entries(G_ACTION_MAP(win),
|
|
|
|
win_actions,
|
|
|
|
G_N_ELEMENTS(win_actions),
|
|
|
|
frontend);
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
|
|
|
void launch_duplicate_session(Conf *conf)
|
|
|
|
{
|
2016-03-27 13:10:06 +00:00
|
|
|
extern const int dup_check_launchable;
|
|
|
|
assert(!dup_check_launchable || conf_launchable(conf));
|
2017-12-17 20:18:20 +00:00
|
|
|
g_application_hold(G_APPLICATION(app));
|
2017-11-25 21:51:45 +00:00
|
|
|
new_session_window(conf_copy(conf), NULL);
|
2016-03-23 22:22:30 +00:00
|
|
|
}
|
|
|
|
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
void session_window_closed(void)
|
2016-03-23 22:22:30 +00:00
|
|
|
{
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
g_application_release(G_APPLICATION(app));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void post_initial_config_box(void *vctx, int result)
|
|
|
|
{
|
|
|
|
Conf *conf = (Conf *)vctx;
|
|
|
|
|
2017-11-26 14:37:38 +00:00
|
|
|
if (result > 0) {
|
2016-03-23 22:22:30 +00:00
|
|
|
new_session_window(conf, NULL);
|
2017-11-26 14:37:38 +00:00
|
|
|
} else if (result == 0) {
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
conf_free(conf);
|
|
|
|
g_application_release(G_APPLICATION(app));
|
2016-03-23 22:22:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void launch_saved_session(const char *str)
|
|
|
|
{
|
|
|
|
Conf *conf = conf_new();
|
|
|
|
do_defaults(str, conf);
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
|
|
|
|
g_application_hold(G_APPLICATION(app));
|
|
|
|
|
|
|
|
if (!conf_launchable(conf)) {
|
|
|
|
initial_config_box(conf, post_initial_config_box, conf);
|
|
|
|
} else {
|
2016-03-23 22:22:30 +00:00
|
|
|
new_session_window(conf, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Make the configuration dialog non-modal.
Now every call to do_config_box is replaced with a call to
create_config_box, which returns immediately having constructed the
new GTK window object, and is passed a callback function which it will
arrange to be called when the dialog terminates (whether by OK or by
Cancel). That callback is now what triggers the construction of a
session window after 'Open' is pressed in the initial config box, or
the actual mid-session reconfiguration action after 'Apply' is pressed
in a Change Settings box.
We were already prepared to ignore the re-selection of 'Change
Settings' from the context menu of a window that already had a Change
Settings box open (and not accidentally create a second config box for
the same window); but now we do slightly better, by finding the
existing config box and un-minimising and raising it, in case the user
had forgotten it was there.
That's a useful featurelet, but not the main purpose of this change.
The mani point, of course, is that now the multi-window GtkApplication
based front ends now don't do anything confusing to the nesting of
gtk_main() when config boxes are involved. Whether you're changing the
settings of one (or more than one) of your already-running sessions,
preparing to start up a new PuTTY connection, or both at once, we stay
in the same top-level instance of gtk_main() and all sessions' top-
level callbacks continue to run sensibly.
2017-11-26 11:58:02 +00:00
|
|
|
void launch_new_session(void)
|
|
|
|
{
|
|
|
|
/* Same as launch_saved_session except that we pass NULL to
|
|
|
|
* do_defaults. */
|
|
|
|
launch_saved_session(NULL);
|
|
|
|
}
|
|
|
|
|
2016-03-23 22:22:30 +00:00
|
|
|
void new_app_win(GtkApplication *app)
|
|
|
|
{
|
|
|
|
launch_new_session();
|
|
|
|
}
|
|
|
|
|
2017-11-27 20:09:54 +00:00
|
|
|
static void window_setup_error_callback(void *vctx, int result)
|
|
|
|
{
|
|
|
|
g_application_release(G_APPLICATION(app));
|
|
|
|
}
|
|
|
|
|
|
|
|
void window_setup_error(const char *errmsg)
|
|
|
|
{
|
|
|
|
create_message_box(NULL, "Error creating session window", errmsg,
|
|
|
|
string_width("Some sort of fiddly error message that "
|
|
|
|
"might be technical"),
|
2018-10-29 19:50:29 +00:00
|
|
|
true, &buttons_ok, window_setup_error_callback, NULL);
|
2017-11-27 20:09:54 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 22:22:30 +00:00
|
|
|
static void activate(GApplication *app,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
new_app_win(GTK_APPLICATION(app));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void newwin_cb(GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
new_app_win(GTK_APPLICATION(user_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void quit_cb(GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
g_application_quit(G_APPLICATION(user_data));
|
|
|
|
}
|
|
|
|
|
2017-12-18 11:46:48 +00:00
|
|
|
static void about_cb(GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
about_box(NULL);
|
|
|
|
}
|
|
|
|
|
2016-03-23 22:22:30 +00:00
|
|
|
static const GActionEntry app_actions[] = {
|
|
|
|
{ "newwin", newwin_cb },
|
2017-12-18 11:46:48 +00:00
|
|
|
{ "about", about_cb },
|
2016-03-23 22:22:30 +00:00
|
|
|
{ "quit", quit_cb },
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Call the function in ux{putty,pterm}.c to do app-type
|
|
|
|
* specific setup */
|
|
|
|
extern void setup(int);
|
2018-10-29 19:50:29 +00:00
|
|
|
setup(false); /* false means we are not a one-session process */
|
2016-03-23 22:22:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 22:13:30 +00:00
|
|
|
if (argc > 1) {
|
|
|
|
extern char *pty_osx_envrestore_prefix;
|
|
|
|
pty_osx_envrestore_prefix = argv[--argc];
|
|
|
|
}
|
|
|
|
|
2016-03-23 22:22:30 +00:00
|
|
|
{
|
|
|
|
const char *home = getenv("HOME");
|
|
|
|
if (home) {
|
|
|
|
if (chdir(home)) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtkcomm_setup();
|
|
|
|
|
|
|
|
app = gtk_application_new("org.tartarus.projects.putty.macputty",
|
|
|
|
G_APPLICATION_FLAGS_NONE);
|
|
|
|
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
|
|
|
|
g_signal_connect(app, "startup", G_CALLBACK(startup), NULL);
|
|
|
|
g_action_map_add_action_entries(G_ACTION_MAP(app),
|
|
|
|
app_actions,
|
|
|
|
G_N_ELEMENTS(app_actions),
|
|
|
|
app);
|
|
|
|
|
|
|
|
status = g_application_run(G_APPLICATION(app), argc, argv);
|
|
|
|
g_object_unref(app);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* GTK_CHECK_VERSION(3,0,0) */
|