]> asedeno.scripts.mit.edu Git - PuTTY.git/log
PuTTY.git
8 years agoAvoid deprecated gtk_misc_set_alignment().
Simon Tatham [Mon, 31 Aug 2015 12:57:34 +0000 (13:57 +0100)]
Avoid deprecated gtk_misc_set_alignment().

As of GTK 3.16 (but not in previous GTK 3 versions), there's a new
gtk_label_set_xalign which does this job.

8 years agoAvoid using gdk_cursor_new() in GTK 3.
Simon Tatham [Mon, 31 Aug 2015 12:41:16 +0000 (13:41 +0100)]
Avoid using gdk_cursor_new() in GTK 3.

It's deprecated in up-to-date versions, but fortunately, the
workaround is just to explicitly include the appropriate GdkDisplay.

8 years agoSwitch to gdk_rgba_parse() for GDK 3.
Simon Tatham [Mon, 31 Aug 2015 12:37:30 +0000 (13:37 +0100)]
Switch to gdk_rgba_parse() for GDK 3.

I'm using a slightly more up-to-date GTK version for testing on MacOS,
and it's marked a few more functions as deprecated, among which is
gdk_color_parse(). So now parsing -fg and -bg options has to be done
by two different calls and an ugly #ifdef, depending on GTK version.

8 years agoDon't use "server:fixed" as the default font without X.
Simon Tatham [Mon, 31 Aug 2015 12:24:09 +0000 (13:24 +0100)]
Don't use "server:fixed" as the default font without X.

If we're not supporting server-side fonts, it's utterly silly to set
one as the default! Instead, we use Pango's guarantee that some
reasonably sensible monospaced font will be made available under the
name "Monospace", and use that at a reasonable default size of 12pt.

8 years agoIntroduce a config option for building on OS X GTK.
Simon Tatham [Mon, 31 Aug 2015 12:05:51 +0000 (13:05 +0100)]
Introduce a config option for building on OS X GTK.

Using GTK to run on OS X is going to require several workarounds and
behaviour tweaks to be enabled at various points in the code, and it's
already getting cumbersome to remember what they all are to put on the
command line. Here's a central #define (OSX_GTK) that enables them all
in one go, and a configure option (--with-quartz) that sets it.

As part of this commit, I've also rearranged the #include order in the
GTK source files, so that they include unix.h (which now might be
where NOT_X_WINDOWS gets defined) before they test NOT_X_WINDOWS to
decide whether to include X11 headers.

8 years agoHandle the Ctrl modifier key ourselves if necessary.
Simon Tatham [Mon, 31 Aug 2015 12:00:42 +0000 (13:00 +0100)]
Handle the Ctrl modifier key ourselves if necessary.

The Quartz GDK back end, if you press (say) Ctrl-A, will generate a
GdkKeyEvent with keyval='a' and state=CONTROL, but it'll have a
translated string of "a" where the X back end would have returned
"\001". So we have to do our own translation, which fortunately isn't
hard.

8 years agoAdd a bodge to make pty masters nonblocking on OS X.
Simon Tatham [Mon, 31 Aug 2015 12:00:19 +0000 (13:00 +0100)]
Add a bodge to make pty masters nonblocking on OS X.

OS X for some reason doesn't let my usual fcntl approach (wrapped in
nonblock()) work on pty masters - the fcntl(F_SETFL) fails, with the
(in this context) hilariously inappropriate error code ENOTTY. Work
around it by instead passing O_NONBLOCK to posix_openpt.

8 years agoAdd a new #define to disable pty_pre_init.
Simon Tatham [Mon, 31 Aug 2015 11:51:25 +0000 (12:51 +0100)]
Add a new #define to disable pty_pre_init.

OS X dislikes us calling the setuid or setgid syscalls when not
privileged, even if we try to set ourselves to the _same_ uid/gid.
Since I don't anticipate this code needing to run setuid on OS X, and
since I do anticipate wanting to handle multiple ptys in a single
process so that pty_pre_init would be useless anyway, the simplest fix
seems to me to be just conditioning out the whole of pty_pre_init
completely.

8 years agoRemove LIBS from Unix pageant Recipe line
Owen S. Dunn [Fri, 28 Aug 2015 15:36:36 +0000 (16:36 +0100)]
Remove LIBS from Unix pageant Recipe line

The Recipe line for Unix pageant mistakenly included LIBS which is
the set of Windows standard libraries.  Remove it.

8 years agoMake Columns disregard the preferred width of GtkEntry.
Simon Tatham [Thu, 27 Aug 2015 17:59:24 +0000 (18:59 +0100)]
Make Columns disregard the preferred width of GtkEntry.

On OS X GTK, it requests a preferred width that's way too large. I
think that's because that's based on its max_width_chars rather than
its width_chars (and I only set the latter). But I don't want to
actually reduce its max_width_chars, in case (either now or in a
future version) that causes it to actually refuse to take up all the
space it's allocated.

8 years agoStop using abs(unsigned) in X11 time comparison.
Simon Tatham [Thu, 27 Aug 2015 17:39:36 +0000 (18:39 +0100)]
Stop using abs(unsigned) in X11 time comparison.

The validation end of XDM-AUTHORIZATION-1 needs to check that two
time_t values differ by at most XDM_MAXSKEW, which it was doing by
subtracting them and passing the result to abs(). This provoked a
warning from OS X's clang, on the reasonable enough basis that the
value passed to abs was unsigned.

Fixed by using the (well defined) unsigned arithmetic wraparound: to
check that the mathematical difference of two unsigned numbers is in
the interval [-k,+k], compute their difference _plus k_ as an
unsigned, and check the result is in the interval [0,2k] by doing an
unsigned comparison against 2k.

8 years agoAdd conditioned-out diagnostics in GTK key_event().
Simon Tatham [Thu, 27 Aug 2015 17:35:17 +0000 (18:35 +0100)]
Add conditioned-out diagnostics in GTK key_event().

These should dump out all the important parts of the incoming
GdkEventKey, so that if keys aren't being translated right, it should
be possible to work out something about why not.

To enable: make CPPFLAGS="-DKEY_EVENT_DIAGNOSTICS"

8 years agoAdd conditioned-out diagnostics in columns_compute_width.
Simon Tatham [Thu, 27 Aug 2015 17:32:41 +0000 (18:32 +0100)]
Add conditioned-out diagnostics in columns_compute_width.

These are a slightly cleaned-up version of the diagnostics I was using
to debug the layout problems in the GTK3 config box the other day. In
particular, if the box comes out far too wide - as I've just found out
that it also does when I compile the current state of the code against
OS X GTK3 - these diagnostics should provide enough information to
figure out which control is the limiting factor.

To enable: make CPPFLAGS="-DCOLUMNS_WIDTH_DIAGNOSTICS"

8 years agoTurn GTK3 deprecation warnings back on.
Simon Tatham [Tue, 25 Aug 2015 18:59:45 +0000 (19:59 +0100)]
Turn GTK3 deprecation warnings back on.

After the last few commits, we now compile cleanly against GTK3 even
without -Wno-deprecated-declarations, so let's turn the default
warnings back on to ensure we don't regress that.

8 years agoRemove a mysterious GTK size-request tweak.
Simon Tatham [Tue, 25 Aug 2015 18:55:38 +0000 (19:55 +0100)]
Remove a mysterious GTK size-request tweak.

In shortcut_add(), when we add an underlined letter to a GtkLabel, we
were fetching the label's height before changing its text, and
restoring it afterwards. I've no idea why - I can see no difference
with and without the code.

That code's been there since 2003 without explanation. My best guess
is that it was working around a GTK bug of the day, but since no
difference is visible even in current GTK1, I think I'm just going to
remove it. If any problems show up later, I can put it back, with an
actual comment!

8 years agoCompile fixes for GTK1 after recent work.
Simon Tatham [Tue, 25 Aug 2015 18:50:23 +0000 (19:50 +0100)]
Compile fixes for GTK1 after recent work.

The whole of get_label_text_dimensions() should have been outside the
GTK 2 ifdef; I'd left a gtk_label_set_width_chars() unconditional; and
GDK1's gdk_window_set_background() lacks a const in its prototype.
Serves me right for not test-compiling in all three versions!

8 years agoFix the config box treeview width in GTK3.
Simon Tatham [Tue, 25 Aug 2015 18:44:44 +0000 (19:44 +0100)]
Fix the config box treeview width in GTK3.

My trickery in GTK2 to start with some branches of the tree collapsed
but give the widget all the width it will need when they open later
was not working in GTK3, for the same reason I've needed several other
fixes recently: just after creation, GTK3 widgets report their
preferred size as zero.

Fixed by doing basically the same trick I was doing in GTK2, but
deferring it until the "map" event happens later on.

8 years agoMake string_width() work in GTK3.
Simon Tatham [Mon, 24 Aug 2015 18:31:44 +0000 (19:31 +0100)]
Make string_width() work in GTK3.

This was another piece of code that determined text size by
instantiating a GtkLabel and asking for its size, which I had to fix
in gtkfont.c recently because that strategy doesn't work in GTK3.

Replaced the implementation of string_width() with a call to the
function I added in gtkfont.c, and now dialog boxes which depend on
that for their width measurement (e.g. the one in reallyclose()) don't
come out in silly sizes on GTK3 any more.

8 years agoUse columns_force_same_height() for vertical centring.
Simon Tatham [Mon, 24 Aug 2015 18:23:38 +0000 (19:23 +0100)]
Use columns_force_same_height() for vertical centring.

In cases where two controls sit alongside one another such as a label
alongside an edit box, I've previously been arranging for them to be
vertically centred by fiddling with the size request and alignment of
what I assume will be the shorter control. But now I've written
columns_force_same_height(), that's a much easier approach, and it's
also compatible with GTK3 without using a deprecated method; so this
change switches over all vertical centring to doing it that way.

Also, while I'm here, I noticed that the edit box and button of
CTRL_FILESELECT / CTRL_FONTSELECT were not vertically centred, and
since it's now really easy to make sure they are, I've added another
use of columns_force_same_height() there.

8 years agoNew Columns method, columns_force_same_height().
Simon Tatham [Mon, 24 Aug 2015 18:23:32 +0000 (19:23 +0100)]
New Columns method, columns_force_same_height().

This forces two child widgets of a Columns to occupy the same amount
of vertical space, and if one is really shorter than the other,
vertically centres it in the extra space.

8 years agoFactor out columns_find_child() in the Columns class.
Simon Tatham [Mon, 24 Aug 2015 18:12:29 +0000 (19:12 +0100)]
Factor out columns_find_child() in the Columns class.

This is an obviously reusable loop over cols->children looking for a
widget, which I'm about to use a couple more times so it seems worth
pulling it out into its own helper function.

8 years agoAnother GTK3 fix for GtkEntry width.
Simon Tatham [Mon, 24 Aug 2015 18:04:37 +0000 (19:04 +0100)]
Another GTK3 fix for GtkEntry width.

When I committed 5e738877b the other day, I missed another case of the
same thing in the file/font selector handling.

8 years agoUse new GTK3 API call for server-controlled window resize.
Simon Tatham [Mon, 24 Aug 2015 17:59:13 +0000 (18:59 +0100)]
Use new GTK3 API call for server-controlled window resize.

gtk_window_resize_to_geometry() allows us to make use of the already-
set-up WM resize hints to immediately figure out how to resize the
window to a particular character cell size, and hence makes a much
simpler implementation of request_resize() than the previous hackery.

8 years agoIn GTK3, omit our GTK 1/2 workaround for wrapping labels.
Simon Tatham [Sun, 23 Aug 2015 14:01:07 +0000 (15:01 +0100)]
In GTK3, omit our GTK 1/2 workaround for wrapping labels.

Now we're properly implementing the GTK3 height-for-width layout
model, this bodge is no longer necessary.

8 years agoImplement GTK3 height-for-width layout in Columns.
Simon Tatham [Sun, 23 Aug 2015 13:50:47 +0000 (14:50 +0100)]
Implement GTK3 height-for-width layout in Columns.

Now that I've got the main calculation code separated from the GTK2
size_request and size_allocate top-level methods, I can introduce a
completely different set of GTK3 top-level methods, which run the same
underlying calculations but based on different width and height
information.

So now we do proper height-for-width layout, as you can see if you
flip the PuTTY config box to a pane with a wrapping label on it (e.g.
Fonts or Logging) and resize the window horizontally. Where the GTK2
config box just left the wrapped text label at its original size, and
the GTK3 one before this change would reflow the text but without
changing the label's height, now the text reflows and the controls
below it move up and down when the number of lines of wrapped text
changes.

(As far as I'm concerned, that's a nice demo of GTK3's new abilities
but not a critically important UI feature for this app. The more
important point is that switching to the modern layout model removes
one of the remaining uses of the deprecated gtk_widget_size_request.)

8 years agoGTK3 prep: refactor the layout calculation in Columns.
Simon Tatham [Sun, 23 Aug 2015 13:49:01 +0000 (14:49 +0100)]
GTK3 prep: refactor the layout calculation in Columns.

Previously, columns_size_request and columns_size_allocate would each
loop over all the widgets doing computations for both width and
height. Now I've separated out the width parts from the height parts,
and moved both out into four new functions, so that the top-level
columns_size_request and columns_size_allocate are just wrappers that
call the new functions and plumb size and position information between
them and GTK.

Actual functionality should be unchanged by this patch.

8 years agoPerformance: cache character widths returned from Pango.
Simon Tatham [Sun, 23 Aug 2015 13:13:30 +0000 (14:13 +0100)]
Performance: cache character widths returned from Pango.

Profiling reveals that pterm in Pango rendering mode uses an absurd
amount of CPU when it's not even actually _drawing_ the text, because
of all the calls to pango_layout_get_pixel_extents() while
pangofont_draw_text tries to work out which characters it can safely
draw as part of a long string. Caching the results speeds things up
greatly.

8 years agoFix an arithmetic error in the X font downloader cache.
Simon Tatham [Sun, 23 Aug 2015 13:10:59 +0000 (14:10 +0100)]
Fix an arithmetic error in the X font downloader cache.

If you're trying to arrange that an array size is large enough for
element n to exist, and you also want to round it up to the next
multiple of 0x100, you must set the size to (n + 0x100) & ~0xFF, and
not (n + 0xFF) & ~0xFF. Put another way, the number you have to round
up is not n, but the minimum size n+1 that causes array[n] to exist.

8 years ago'pterm --display' should set $DISPLAY inside the terminal.
Simon Tatham [Sat, 22 Aug 2015 14:05:12 +0000 (15:05 +0100)]
'pterm --display' should set $DISPLAY inside the terminal.

If you open a pterm on a different display via the --display
command-line option rather than by setting $DISPLAY, I think (and
other terminals seem to agree) that it's sensible to set $DISPLAY
anyway for processes running inside the terminal.

8 years agoIn GTK3, use the new GtkColorChooserDialog.
Simon Tatham [Sat, 22 Aug 2015 13:49:02 +0000 (14:49 +0100)]
In GTK3, use the new GtkColorChooserDialog.

This replaces the old GtkColorSelectionDialog, and has the convenience
advantage that the actual chooser (with all the 'set colour', 'get
colour' methods) and the containing dialog box are now the same object
implementing multiple interfaces, so I don't keep having to call 'get
me the underlying chooser for this dialog' accessors. Also you now
hook into both the OK and Cancel buttons (and all other response
codes) at the same time with a single event.

8 years agoIn GTK3, unifontsel should use GtkGrid, not GtkTable.
Simon Tatham [Sat, 22 Aug 2015 13:28:04 +0000 (14:28 +0100)]
In GTK3, unifontsel should use GtkGrid, not GtkTable.

GtkTable is deprecated; the way of the future is GtkGrid, in which you
don't have to specify the number of rows/columns in advance (it's
worked out dynamically by observing what row/column numbers you
actually attached anything to), and also you handle expansion
behaviour by setting the "hexpand", "vexpand" or "expand" properties
on the child widgets rather than setting flags in the container.

8 years agoStop using GTK3-deprecated gdk_window_set_background().
Simon Tatham [Sat, 22 Aug 2015 13:11:45 +0000 (14:11 +0100)]
Stop using GTK3-deprecated gdk_window_set_background().

We now have to use gdk_window_set_background_rgba(), having first set
up an appropriate GdkRGBA structure.

8 years agoStop using GTK3-deprecated gdk_get_display().
Simon Tatham [Sat, 22 Aug 2015 13:07:02 +0000 (14:07 +0100)]
Stop using GTK3-deprecated gdk_get_display().

The new way is gdk_display_get_name(gdk_display_get_default()), which
returns a const char * rather than a char *, so I've also had to
fiddle with the prototype and call sites of get_x_display().

(Also included gtkcompat.h into uxputty.c, since that wanted to call
gdk_get_display() but didn't previously include it.)

8 years agoProvide #defines for GTK3-deprecated gtk_{h,v}foo_new().
Simon Tatham [Sat, 22 Aug 2015 12:59:20 +0000 (13:59 +0100)]
Provide #defines for GTK3-deprecated gtk_{h,v}foo_new().

In GTK3, GtkBox, GtkScrollbar and GtkSeparator are all single classes
with a GtkOrientation parameter, whereas in GTK2 the horizontal and
vertical versions were trivial subclasses of them. Hence, the old
constructors are now deprecated, but _only_ the constructors are
affected, since after constructing one you always used methods of the
superclass on it anyway.

Rather than faff about with an ifdef at every call site, I've just put
some wrapper macros in gtkcompat.h to make it easy to keep this code
similar between all supported GTK versions.

8 years agoAvoid deprecated gtk_cell_renderer_get_size in GTK3.
Simon Tatham [Sat, 22 Aug 2015 12:53:29 +0000 (13:53 +0100)]
Avoid deprecated gtk_cell_renderer_get_size in GTK3.

gtk_cell_renderer_get_preferred_size() is the new way to do it.

8 years agoStop using deprecated GTK_STOCK_* in GTK3.
Simon Tatham [Sat, 22 Aug 2015 12:50:56 +0000 (13:50 +0100)]
Stop using deprecated GTK_STOCK_* in GTK3.

According to the GTK3 docs, we're now supposed to use fixed label
strings instead.

8 years agoMake unifontsel_deselect() clear the preview pane.
Simon Tatham [Sat, 22 Aug 2015 12:41:15 +0000 (13:41 +0100)]
Make unifontsel_deselect() clear the preview pane.

In the case where we deselect the previously selected font (e.g.
because we've just changed the filter settings to remove it from the
list), we were leaving the preview pane in its previous state, which
is fine in GTK2 when it just carries on displaying the last thing
drawn to the backing pixmap but goes wrong in GTK3 where we still have
to actually respond to draw events.

But it makes more conceptual sense anyway to actually empty the
preview pane when no font is selected, so now we do that. So now
unifontsel_draw_preview_text() is called from unifontsel_deselect(),
and also the preview-drawing code will still draw the background
rectangle regardless of whether font != NULL.

8 years agoFix crash in GTK3 when unifontsel filter settings change.
Simon Tatham [Sat, 22 Aug 2015 12:41:11 +0000 (13:41 +0100)]
Fix crash in GTK3 when unifontsel filter settings change.

The call to gtk_list_store_clear() in unifontsel_setup_familylist()
was causing a call to family_changed() via the GTK signal system,
which didn't happen in GTK2. family_changed() in turn was calling
unifontsel_select_font(), which got confused when the tree model
didn't match reality, and tried to access a bogus tree iterator.

This is easily fixed by using the existing fs->inhibit_response flag,
which prevents us responding to GTK events when we know they were
generated by our own fiddling about with the data; it's just that we
never needed to set it in unifontsel_setup_familylist() before.

Also, added a check of the return value from the key get_iter call in
unifontsel_select_font(), so that it'll at least fail an assertion
rather than actually trying to access bogus memory. But that operation
_should_ still always succeed, and if it doesn't, it's probably a sign
that we need another use of fs->inhibit_response.

8 years agoFix GTK3 size calculations in unifontsel_new.
Simon Tatham [Sat, 22 Aug 2015 10:46:05 +0000 (11:46 +0100)]
Fix GTK3 size calculations in unifontsel_new.

It turns out that in GTK3, if you instantiate a GtkLabel and
immediately try to find out its preferred size, you get back zero for
both dimensions. Presumably none of that gets figured out properly
until the widget is displayed, or some such.

However, you can retrieve the PangoLayout from the label immediately
and ask Pango for the dimensions of that. That seems like a bit of a
bodge, but it works! The GTK3 unifont selector now comes out with all
the interface elements in sensible sizes - in particular, the preview
drawing area now has non-zero height.

8 years agoIn GTK3, don't use the "has-separator" GtkDialog property.
Simon Tatham [Sat, 22 Aug 2015 10:09:06 +0000 (11:09 +0100)]
In GTK3, don't use the "has-separator" GtkDialog property.

It doesn't exist any more, so the attempt to set it was generating an
annoying runtime warning message.

8 years agoUse GTK3's method of setting GtkEntry min width.
Simon Tatham [Sat, 22 Aug 2015 09:37:48 +0000 (10:37 +0100)]
Use GTK3's method of setting GtkEntry min width.

The config box setup code wants a lot of very narrow edit boxes, so it
decreases their minimum width from the GTK default of 150 pixels. In
GTK 3, we have to do this using gtk_entry_set_width_chars() rather
than gtk_widget_set_size_request() as we were previously using, or it
won't work.

This change by itself seems to restore the GTK3 config box to a
sensible layout, in spite of the fact that my Columns layout class is
still doing all its size allocation the GTK2 way, with no attention
paid to the shiny new GTK3 height-for-width system.

8 years agoRemove arbitrary limit SSH2_MKKEY_ITERS.
Simon Tatham [Fri, 21 Aug 2015 22:40:16 +0000 (23:40 +0100)]
Remove arbitrary limit SSH2_MKKEY_ITERS.

Tim Kosse points out that we now support some combinations of crypto
primitives which break the hardwired assumption that two blocks of
hash output from the session-key derivation algorithm are sufficient
to key every cipher and MAC in the system.

So now ssh2_mkkey is given the desired key length, and performs as
many iterations as necessary.

8 years agoAdd a key-length field to 'struct ssh_mac'.
Simon Tatham [Fri, 21 Aug 2015 22:20:12 +0000 (23:20 +0100)]
Add a key-length field to 'struct ssh_mac'.

The key derivation code has been assuming (though non-critically, as
it happens) that the size of the MAC output is the same as the size of
the MAC key. That isn't even a good assumption for the HMAC family,
due to HMAC-SHA1-96 and also the bug-compatible versions of HMAC-SHA1
that only use 16 bytes of key material; so now we have an explicit
key-length field separate from the MAC-length field.

8 years agoAdd copy and free methods to 'struct ssh_hash'.
Simon Tatham [Fri, 21 Aug 2015 22:13:59 +0000 (23:13 +0100)]
Add copy and free methods to 'struct ssh_hash'.

This permits a hash state to be cloned in the middle of being used, so
that multiple strings with the same prefix can be hashed without
having to repeat all the computation over the prefix.

Having done that, we'll also sometimes need to free a hash state that
we aren't generating actual hash output from, so we need a free method
as well.

8 years agoNew test output file, checking all display-relevant stuff.
Simon Tatham [Sun, 16 Aug 2015 17:26:23 +0000 (18:26 +0100)]
New test output file, checking all display-relevant stuff.

This is the test file I wish I'd had while I was rewriting the
text-drawing function this week :-) Better late than never.

8 years agoGTK3 port: add '--with-gtk=3' to the configure script.
Simon Tatham [Sun, 16 Aug 2015 13:53:15 +0000 (14:53 +0100)]
GTK3 port: add '--with-gtk=3' to the configure script.

After the last few changes, the whole codebase now compiles and links
successfully against GTK3, and I can run an experimental pterm. The
config box and font selector look ugly, but the basics all seem to
work.

In order to compile at all, I had to manually bodge in the extra
compile flag -Wno-deprecated-declarations. My plan is to fix all the
uses of deprecated things, and then remove that flag.

I've made GTK3 the second choice, after GTK2 but before GTK1. GTK2 is
the only GTK version that produces a completely sensible build (partly
because the GTK3 port is visibly unfinished, and mostly because its
server-side font handling is just too slow), so it remains the first
choice.

8 years agoGTK3 port: condition out all uses of GdkColormap.
Simon Tatham [Sun, 16 Aug 2015 13:22:14 +0000 (14:22 +0100)]
GTK3 port: condition out all uses of GdkColormap.

The entire concept has gone away in GTK3, which assumes that everyone
is now using modern true-colour video modes and so there's no longer
any reason you shouldn't just casually make up any RGB triple you like
without bothering to ask the display system's permission.

8 years agoGTK3 port: respell GDK_WINDOW_XWINDOW / GDK_DRAWABLE_XID.
Simon Tatham [Sun, 16 Aug 2015 13:16:23 +0000 (14:16 +0100)]
GTK3 port: respell GDK_WINDOW_XWINDOW / GDK_DRAWABLE_XID.

GDK3 now spells both of those as GDK_WINDOW_XID. (Of course 'drawable'
is no longer a relevant concept in GDK3, since pixmaps are no longer
supported and so all drawables are just windows.) We keep backwards
compatibility, of course.

8 years agoGTK3 port: replace size_request in the Columns layout class.
Simon Tatham [Sun, 16 Aug 2015 13:16:08 +0000 (14:16 +0100)]
GTK3 port: replace size_request in the Columns layout class.

It's been replaced by a new pair of methods get_preferred_width and
get_preferred_height. For the moment, I've followed the porting
guide's suggestion of keeping the old size_request function as an
underlying implementation and having each of those methods just return
one of its outputs. The results are ugly, but it'll compile and run,
which is a start.

8 years agoGTK3 port: use gdk_device_grab() in gtkask.c.
Simon Tatham [Sun, 16 Aug 2015 13:36:32 +0000 (14:36 +0100)]
GTK3 port: use gdk_device_grab() in gtkask.c.

This replaces the old gdk_keyboard_grab(), and is what a GTK3 app has
to use for grabbing the keyboard away from all other X clients.

8 years agoGTK3 port: support the new "draw" signal.
Simon Tatham [Sun, 16 Aug 2015 13:34:19 +0000 (14:34 +0100)]
GTK3 port: support the new "draw" signal.

This replaces GTK 1/2's "expose_event", and provides a ready-made
cairo_t to do the drawing with. My previous work has already separated
all constructions of a cairo_t from the subsequent drawing with it, so
the new draw event handlers just have to call the latter without the
former.

8 years agoReimplement GTK uxsel_input_add using GIOChannel.
Simon Tatham [Sun, 16 Aug 2015 12:07:26 +0000 (13:07 +0100)]
Reimplement GTK uxsel_input_add using GIOChannel.

This is the new recommended approach since gdk_input_{add,remove} were
deprecated (and, honestly, seems a lot more sensible - why on earth
would those functions have lived in *GDK* of all places?). The old
implementation is preserved under ifdef for GTK1.

This was the last of the GDK deprecated functions to go! So GTK PuTTY
now compiles cleanly with -DGDK_DISABLE_DEPRECATED in addition to all
the other precautionary flags (though if you do that, you disable GDK
rendering, which greatly slows down server-side font handling). This
completes the GTK2-compatible preparation phase of the GTK 3 migration
guide.

8 years agoChange uxsel_input_add's return type from int to pointer.
Simon Tatham [Sun, 16 Aug 2015 11:50:46 +0000 (12:50 +0100)]
Change uxsel_input_add's return type from int to pointer.

In case a front end needs to store more than an integer id to be
returned to uxsel_input_remove, we now return a pointer to a
frontend-defined structure.

8 years agoUse gtk_window_set_icon() where available.
Simon Tatham [Sun, 16 Aug 2015 08:41:10 +0000 (09:41 +0100)]
Use gtk_window_set_icon() where available.

GTK is deprecating the use of gdk_window_set_icon(), in favour of a
method that doesn't have to drop down to the GDK level at all (and
also doesn't use a pixmap). No reason not to use that instead.

8 years agoRemove an outdated comment.
Simon Tatham [Sun, 16 Aug 2015 08:29:47 +0000 (09:29 +0100)]
Remove an outdated comment.

I've just noticed the comment in gtkfont.c that said wouldn't it be
nice to find a way to avoid the GDK pixmap-stretching code when using
Pango fonts. We now do support this, but we support it in gtkwin.c
rather than gtkfont.c - because we do it using a Cairo transformation
matrix, so it still takes place at the level above Pango rather than
in Pango proper. (I never did find out whether Pango itself included
facilities to arbitrarily stretch a font.)

Hence, this comment is useless now. Discard.

8 years agoReplace deprecated GDK_DISPLAY() with modern facilities.
Simon Tatham [Sun, 16 Aug 2015 08:23:32 +0000 (09:23 +0100)]
Replace deprecated GDK_DISPLAY() with modern facilities.

We still don't actually support more than one X display active at
once, so it's sufficient to replace every call to that macro with
GDK_DISPLAY_XDISPLAY(gdk_display_get_default()).

8 years agoMake the use of server-side backing pixmaps in GTK optional.
Simon Tatham [Sun, 16 Aug 2015 08:02:31 +0000 (09:02 +0100)]
Make the use of server-side backing pixmaps in GTK optional.

We won't be able to use them in GTK3, or when compiling with GTK2 and
-DGDK_DISABLE_DEPRECATED.

This applies to the one we use for the main terminal window, and also
the small one we use for the preview pane in the unified font selector.

8 years agoSaw unifontsel_draw_preview_text() in half.
Simon Tatham [Sun, 16 Aug 2015 09:32:24 +0000 (10:32 +0100)]
Saw unifontsel_draw_preview_text() in half.

Now it's got an inner half that does actual drawing given a draw
context, and an outer half that sets up and tears down the draw
context. Sooner or later the inner half will need calling
independently of the outer, because GTK3's draw event will provide a
ready-made cairo_t.

8 years agoCall draw_stretch_before *after* setting up the clip region.
Simon Tatham [Sun, 16 Aug 2015 07:55:04 +0000 (08:55 +0100)]
Call draw_stretch_before *after* setting up the clip region.

A small bug in yesterday's work: since in Cairo mode
draw_stretch_before changes the transformation matrix, if we do it
before calling draw_clip then the clip region will be interpreted in
the transformed coordinates.

This caused a subtle display bug in yesterday's commit: drawing one
half of double-height text would have drawn _both_ halves of it on to
the window's backing pixmap, but only copied the correct half on to
the window proper - but the overdrawing on the pixmap would have shown
up if the window was hidden and re-exposed.

8 years agoWithdraw the horrible bodge in make_mouse_ptr().
Simon Tatham [Sat, 15 Aug 2015 20:07:35 +0000 (21:07 +0100)]
Withdraw the horrible bodge in make_mouse_ptr().

We were previously building our own mouse pointers out of pixmaps,
having first drawn characters from the X server standard font 'cursor'
on to those pixmaps, giving an effect almost exactly the same as just
calling gdk_cursor_new(some constant) except that we got to choose the
foreground and background colours of the resulting pointers.

But it's not clear why we needed to do that! In both GTK1 and GTK2 as
of my current testing, the standard colours appear to be just what I
wanted anyway (white pointer with black outline). The previous
implementation (and commit comment) was written in 2002, so perhaps it
was working around a GTK1 bug of the time.

So I've removed it completely, and replaced it with simple calls to
gdk_cursor_new  (plus a workaround for GTK1's lack of GDK_BLANK_CURSOR,
but that's still much simpler than the previous code). If anyone does
report a colour problem, I may have to go back to doing something
clever, but if I can possibly arrange it, I'll want to do it by some
other technique, probably (as suggested in a comment in the previous
implementation) getting the underlying X cursor id and calling
XRecolorCursor.

8 years agoRefactor the GTK drawing system to do both GDK and Cairo.
Simon Tatham [Sat, 15 Aug 2015 20:05:56 +0000 (21:05 +0100)]
Refactor the GTK drawing system to do both GDK and Cairo.

We're going to have to use Cairo in the GTK3 port, because that's all
GTK3 supports; but we still need old-style GDK for GTK1 support, and
also for performance reasons in GTK2 (see below). Hence, this change
completely restructures GTK PuTTY's drawing code so that there's a
central 'drawing context' structure which contains a type code
indicating GDK or Cairo, and then either some GDK gubbins or some
Cairo gubbins as appropriate; all actual drawing is abstracted through
a set of routines which test the type code in that structure and do
one thing or another. And because the type code is tested at run time,
both sets of drawing primitives can be compiled in at once, and where
possible, they will be.

X server-side bitmap fonts are still supported in the Cairo world, but
because Cairo drawing is entirely client-side, they have to work by
cheekily downloading each glyph bitmap from the server when it's first
needed, and building up a client-side cache of 'cairo_surface_t's
containing the bitmaps with which we then draw on the window. This
technique works, but it's rather slow; hence, even in GTK2, we keep
the GDK drawing back end compiled in, and switch over to it when the
main selected font is a bitmap one.

One visible effect of the new Cairo routines is in the double-width
and double-height text you can get by sending ESC # 3, ESC # 4 and
ESC # 6 escape sequences. In GDK, that's always been done by a really
horrible process of manually scaling the bitmap, server-side, column
by column and row by row, causing each pixel to be exactly doubled or
quadrupled. But in Cairo, we can just set a transformation matrix, and
then that takes effect _before_ the scalable fonts are rendered - so
the results are visibly nicer, and use all the available resolution.

(Sadly, if you're using a server-side bitmap font as your primary one,
then the GDK backend will be selected for all drawing in the terminal
as a whole - so in that situation, even fallback characters absent
from the primary font and rendered by Pango will get the old GDK
scaling treatment. It's only if your main font is scalable, so that
the Cairo backend is selected, that DW/DH characters will come out
looking nice.)

8 years agoStop multifont fallback from crashing in GTK1.
Simon Tatham [Sat, 15 Aug 2015 19:26:07 +0000 (20:26 +0100)]
Stop multifont fallback from crashing in GTK1.

I was tacitly assuming that mfont->fallback would always be non-NULL,
which is true in a world containing Pango, but untrue in GTK1 when
Pango isn't there. In that situation we fall back to just omitting the
characters that would be displayed in the fallback font, on the
grounds that that's better than dereferencing through a NULL vtable.

8 years agoClose file descriptor in test main().
Tim Kosse [Tue, 11 Aug 2015 09:30:13 +0000 (11:30 +0200)]
Close file descriptor in test main().

Some static analyzers are complaining about it.

8 years agoFix signature of platform_new_connection.
Tim Kosse [Tue, 11 Aug 2015 09:27:20 +0000 (11:27 +0200)]
Fix signature of platform_new_connection.

The hostname is a const char *.

8 years agoUse DWORD as length argument for RegQueryValueEx.
Tim Kosse [Tue, 11 Aug 2015 12:34:11 +0000 (14:34 +0200)]
Use DWORD as length argument for RegQueryValueEx.

8 years agoCast return value of ShellExecute to INT_PTR.
Tim Kosse [Tue, 11 Aug 2015 12:30:14 +0000 (14:30 +0200)]
Cast return value of ShellExecute to INT_PTR.

ShellExecute returns HINSTANCE which is a typedef for void*. Cast the
return value to INT_PTR instead of int to avoid truncation on 64bit
builds.

8 years agoUse INT_PTR not int to store result of DialogBoxParam.
Tim Kosse [Tue, 11 Aug 2015 12:27:48 +0000 (14:27 +0200)]
Use INT_PTR not int to store result of DialogBoxParam.

8 years agoDLGPROC callbacks should return INT_PTR.
Tim Kosse [Tue, 11 Aug 2015 12:22:09 +0000 (14:22 +0200)]
DLGPROC callbacks should return INT_PTR.

The Windows headers define the return type of DLGPROC as INT_PTR which
on 64bit Windows has a different size than int.

8 years agoFix type of third argument to AppendMenu
Tim Kosse [Tue, 11 Aug 2015 12:25:42 +0000 (14:25 +0200)]
Fix type of third argument to AppendMenu

We are passing pointers as third argument to AppendMenu. Do not
truncate them to UINT, use UINT_PTR instead which has the required
size on 64bit Windows.

8 years agoFix type of 4th argument to WinHelp
Tim Kosse [Tue, 11 Aug 2015 12:07:36 +0000 (14:07 +0200)]
Fix type of 4th argument to WinHelp

We're passing a pointer as 4th argument to WinHelp. Do not cast it to
DWORD which would truncate the pointer. Instead use UINT_PTR as that
is what WinHelp expects.

8 years agoCast pointers to uintptr_t instead of unsigned {long,int}.
Tim Kosse [Tue, 11 Aug 2015 12:01:02 +0000 (14:01 +0200)]
Cast pointers to uintptr_t instead of unsigned {long,int}.

On 64bit Windows, pointers are 64bit whereas both unsigned long and
unsigned int are 32bit. Using uintptr_t avoids truncation.

8 years agoFix warning about mismatched constness.
Tim Kosse [Tue, 11 Aug 2015 12:18:13 +0000 (14:18 +0200)]
Fix warning about mismatched constness.

8 years agoUse correct type to print Windows error codes.
Tim Kosse [Tue, 11 Aug 2015 12:13:20 +0000 (14:13 +0200)]
Use correct type to print Windows error codes.

GetLastError returns DWORD. To print it, convert it to unsigned int
and use the %u format specifier.

8 years agoDo not re-define SECURITY_WIN32 if already defined.
Tim Kosse [Tue, 11 Aug 2015 09:25:40 +0000 (11:25 +0200)]
Do not re-define SECURITY_WIN32 if already defined.

Some toolchains have SECURITY_WIN32 defined by default.

8 years agoMake manifest files work with 64bit builds of PuTTY.
Tim Kosse [Tue, 11 Aug 2015 09:10:33 +0000 (11:10 +0200)]
Make manifest files work with 64bit builds of PuTTY.

Otherwise we would get 0xc000007b error when trying to start a 64bit
PuTTY Windows binary.

8 years agoDetect end of string in fingerprint alignment.
Tim Kosse [Tue, 11 Aug 2015 11:45:26 +0000 (13:45 +0200)]
Detect end of string in fingerprint alignment.

This prevents writing past the end of the buffer should
ssh2_fingerprint ever return a fingerprint not containing a colon.

8 years agoFix __uint128_t compile error on MinGW.
Tim Kosse [Tue, 11 Aug 2015 07:43:34 +0000 (09:43 +0200)]
Fix  __uint128_t compile error on MinGW.

MinGW has __uint128_t, but not __uint64_t.

8 years agoRemove an unused variable.
Tim Kosse [Tue, 11 Aug 2015 12:29:44 +0000 (14:29 +0200)]
Remove an unused variable.

8 years agoRemove an unused variable.
Tim Kosse [Tue, 11 Aug 2015 12:05:59 +0000 (14:05 +0200)]
Remove an unused variable.

8 years agoFix warning about uninitialized variable.
Tim Kosse [Tue, 11 Aug 2015 08:44:00 +0000 (10:44 +0200)]
Fix warning about uninitialized variable.

Some MinGW versions do not know that assert(0) never returns. This
change also handles the case of building with NDEBUG.

8 years agoRemove unused variable.
Tim Kosse [Tue, 11 Aug 2015 11:44:28 +0000 (13:44 +0200)]
Remove unused variable.

8 years agoFix warning about missing return in ssh2_kexinit_addalg
Tim Kosse [Tue, 11 Aug 2015 07:39:05 +0000 (09:39 +0200)]
Fix warning about missing return in ssh2_kexinit_addalg

8 years agoFix a format string vulnerability if MALLOC_LOG is set.
Tim Kosse [Fri, 1 May 2015 13:55:37 +0000 (15:55 +0200)]
Fix a format string vulnerability if MALLOC_LOG is set.

8 years agoFix format string vulnerabilities.
Tim Kosse [Fri, 1 May 2015 13:54:51 +0000 (15:54 +0200)]
Fix format string vulnerabilities.

Reported by Jong-Gwon Kim. Also fixes a few memory leaks in the
process.

8 years agoAdd a FAQ for 'checksum mismatch' reports.
Simon Tatham [Sun, 9 Aug 2015 20:18:27 +0000 (21:18 +0100)]
Add a FAQ for 'checksum mismatch' reports.

The aim is to try to reduce the incidence of the two least helpful
classes of those reports: the ones which have just got mismatched
checksum files, and the ones which don't tell us the information that
would help.

8 years agoFix compile failure.
Simon Tatham [Sun, 9 Aug 2015 10:56:38 +0000 (11:56 +0100)]
Fix compile failure.

I'm sure I removed that 'return 0' at some point! But I must have made
a git error which excluded it from the commit I actually pushed, ahem.

8 years agoGTK 3 prep: write a replacement for gtk_quit_add().
Simon Tatham [Sun, 9 Aug 2015 10:33:43 +0000 (11:33 +0100)]
GTK 3 prep: write a replacement for gtk_quit_add().

GTK 2 has deprecated it and provided no replacement; a bug tracker
entry I found on the subject suggested that it was functionality that
didn't really belong in GTK, and glib ought to provide a replacement
instead, which would be a perfectly fine thing to suggest if they had
waited for glib to get round to doing so *before* throwing out a
function people were actually using. Sigh.

Anyway, it turns out that subsidiary invocations of gtk_main() don't
happen inside GTK as far as I can see, so all I need to do is to make
sure my own invocations of gtk_main() are followed by a cleanup
function which runs any quit functions that I've registered.

That was the last deprecated GTK function, so we now build cleanly
with -DGTK_DISABLE_DEPRECATED. (But, as mentioned a couple of commits
ago, we still don't build with -DGDK_DISABLE_DEPRECATED, because that
has migrating to Cairo drawing as a prerequisite.)

8 years agoUse gtkcompat.h to slim down a few ifdefs.
Simon Tatham [Sun, 9 Aug 2015 08:59:25 +0000 (09:59 +0100)]
Use gtkcompat.h to slim down a few ifdefs.

Now that I've got a general place to centralise handling of at least
the simple differences between GTK 1 and 2, I should use it wherever
possible. So this commit removes just a small number of ifdefs which
are either obsoleted by definitions already in gtkcompat.h (like
set_size_request vs set_usize), or can easily be replaced by adding
another (e.g. gtk_color_selection_set_has_opacity_control).

8 years agoGTK 3 prep: stop using *nearly* all GTK deprecated functions.
Simon Tatham [Sat, 8 Aug 2015 17:02:01 +0000 (18:02 +0100)]
GTK 3 prep: stop using *nearly* all GTK deprecated functions.

Building with -DGTK_DISABLE_DEPRECATED, we now suffer only one compile
failure, for the use of gtk_quit_add() in idle_toplevel_callback_func.
That function is apparently removed with no replacement in GTK 3, so
I'll need to find a completely different approach to getting toplevel
callbacks to run only in the outermost instance of gtk_main().

Also, this change doesn't do anything about the use of *GDK*
deprecated functions, because those include the entire family of
old-style drawing functions - i.e. the only way to build cleanly with
-DGDK_DISABLE_DEPRECATED will be to switch to Cairo drawing.

8 years agoSwitch to using gtk_window_parse_geometry in GTK 2.
Simon Tatham [Sat, 8 Aug 2015 17:22:05 +0000 (18:22 +0100)]
Switch to using gtk_window_parse_geometry in GTK 2.

On GTK versions where it's available, this is a much nicer way of
handling the -geometry command-line option, since not only do we get
all the faffing about with gravity for free, it also automatically
sets the user-position WM hints.

8 years agoGTK 3 prep: replace GtkFileSelection with GtkFileChooserDialog.
Simon Tatham [Sat, 8 Aug 2015 16:34:25 +0000 (17:34 +0100)]
GTK 3 prep: replace GtkFileSelection with GtkFileChooserDialog.

I've put in a special #define to control this selection, in case I
decide that for reasons of taste I'd prefer to switch back to
GtkFileSelection in GTK2 which supports both!

8 years agoGTK 3 prep: use gtk_color_selection_get_current_color().
Simon Tatham [Sat, 8 Aug 2015 16:32:15 +0000 (17:32 +0100)]
GTK 3 prep: use gtk_color_selection_get_current_color().

Replaces the deprecated gtk_color_selection_set_color() which took an
array of four doubles (RGBA), and instead takes a 'GdkColor' struct
containing four 16-bit integers.

For GTK1, we still have to retain the original version.

8 years agoGTK 3 prep: use the glib names for base object types.
Simon Tatham [Sat, 8 Aug 2015 16:29:02 +0000 (17:29 +0100)]
GTK 3 prep: use the glib names for base object types.

All the things like GtkType, GtkObject, gtk_signal_connect and so on
should now consistently have the new-style glib names like GType,
GObject, g_signal_connect, etc.

8 years agoAllow direct use of X11 to be conditionally compiled out.
Simon Tatham [Sat, 8 Aug 2015 15:35:19 +0000 (16:35 +0100)]
Allow direct use of X11 to be conditionally compiled out.

A major aim of introducing GTK 3 support is to permit compiling for
non-X11 platforms that GTK 3 supports, so I'm going to need to be able
to build as a pure GTK application with no use of X11 internals.
Naturally, I don't intend to stop supporting the hybrid GTK+X11 mode
in which X server-side bitmap fonts are available.

Use of X11 can be removed by compiling with -DNOT_X_WINDOWS. That's
the same compatibility flag that was already used by the unfinished OS
X port to disable the X-specific parts of uxpty.c; now it just applies
to more source files.

(There's no 'configure' option to set this flag at present. I haven't
worked out whether we'll need one yet.)

8 years agoGTK 3 prep: use GDK_KEY_<keyname> constants, not GDK_<keyname>.
Simon Tatham [Sat, 8 Aug 2015 15:23:54 +0000 (16:23 +0100)]
GTK 3 prep: use GDK_KEY_<keyname> constants, not GDK_<keyname>.

GTK 2 doesn't _documentedly_ provide a helpful compile option to let
us check this one in advance of GTK 3, but you can fake one anyway by
compiling with -D__GDK_KEYSYMS_COMPAT_H__, so that gdkkeysyms-compat.h
will believe that it's already been included :-) We now build cleanly
under GTK 2 with that predefine.

8 years agoGTK 3 prep: use accessor functions for object data fields.
Simon Tatham [Sat, 8 Aug 2015 14:53:43 +0000 (15:53 +0100)]
GTK 3 prep: use accessor functions for object data fields.

We now build cleanly in GTK2 with -DGSEAL_ENABLE.

8 years agoGTK 3 prep: do not include individual GTK/GDK headers.
Simon Tatham [Sat, 8 Aug 2015 14:06:15 +0000 (15:06 +0100)]
GTK 3 prep: do not include individual GTK/GDK headers.

This is the first of several cleanup steps recommended by the GTK 2->3
migration guide.

I intend to begin work towards compatibility with GTK 3, but without
breaking GTK 2 and even GTK 1 compatibility in the process; GTK 2 is
still useful to _me_ (not least because it permits much easier support
of old-style server-side X11 fonts), and I recall hearing a rumour
that at least one kind of strange system can only run GTK 1, so for
the moment I don't intend to stop supporting either.

Including gdkkeysyms.h is not optional in GTK 2, because gdk.h does
not include it. In GTK 3 it does, so we don't explicitly reinclude it
ourselves.

We now build cleanly in GTK2 with -DGTK_DISABLE_SINGLE_INCLUDES. (But
that doesn't say much, because we did already! Apparently gdkkeysyms.h
was a special case which that #define didn't forbid.)

8 years agoMake gtkask.c compile under GTK 1.
Simon Tatham [Sat, 8 Aug 2015 14:04:28 +0000 (15:04 +0100)]
Make gtkask.c compile under GTK 1.

This is less than ideal - passphrase input now happens in ISO 8859-1,
and the passphrase prompt window is neither centred nor always-on-top.
But it basically works, and restores bare-minimum GTK 1 support to the
codebase as a whole.

8 years agoNew formatting directive in logfile naming: &P for port number.
Simon Tatham [Sat, 8 Aug 2015 12:35:44 +0000 (13:35 +0100)]
New formatting directive in logfile naming: &P for port number.

Users have requested this from time to time, for distinguishing log
file names when there's more than one SSH server running on different
ports of the same host. Since we do take account of that possibility
in other areas (e.g. we cache host keys indexed by (host,port) rather
than just host), it doesn't seem unreasonable to do so here too.

8 years agoWork around a failure in Windows 10 jump lists.
Simon Tatham [Thu, 6 Aug 2015 18:25:56 +0000 (19:25 +0100)]
Work around a failure in Windows 10 jump lists.

We've had several reports that launching saved sessions from the
Windows 10 jump list fails; Changyu Li reports that this is because we
create those IShellLink objects with a command line string starting
with @, and in Windows 10 that causes the SetArguments method to
silently do the wrong thing.