| 1 |
--- |
| 2 |
layout: post |
| 3 |
title: "Coot 1 on MacOS" |
| 4 |
date: Sun 5 Jun 2022 10:33:23 BST |
| 5 |
--- |
| 6 |
|
| 7 |
The release of _Coot 1_ was met with some enthusiasm from MacOS users. |
| 8 |
The Homebrew formula for _Coot_, written by Yoshitaka Moriwaki was very helpful to that end. |
| 9 |
|
| 10 |
 |
| 11 |
|
| 12 |
|
| 13 |
As you may know, MacOS is not my main platform, and it was only (relatively) |
| 14 |
recently that I got a Mac laptop that was able to compile _Coot 1_. Once I had done so, |
| 15 |
it became apparent was that the performance (i.e. frames/second) of _Coot 1_ |
| 16 |
on MacOS was terrible - close to unusable - if not actually unusable. |
| 17 |
|
| 18 |
Googling around, it seemed that other GTK-using applications that were |
| 19 |
targeting MacOS (such as the GIMP or Inkscape) were also very |
| 20 |
slow. This [Phoronix |
| 21 |
article](https://www.phoronix.com/scan.php?page=news_item&px=GTK4-macOS-Improved) |
| 22 |
was very interesting. It seems that Christian Hergert is the main |
| 23 |
developer of [the MacOS |
| 24 |
backend](https://blogs.gnome.org/chergert/2020/12/15/gtk-4-got-a-new-macos-backend-now-with-opengl/). |
| 25 |
|
| 26 |
Should I care that Coot 1 on MacOS is slow? |
| 27 |
|
| 28 |
I decided that I should care. |
| 29 |
|
| 30 |
I thought it would be interesting to see if moving to GTK4 would solve the performance problems for _Coot_. |
| 31 |
|
| 32 |
So I extracted the new OpenGL code in _Coot_, i.e. the "Coot Render Engine" and built that into a new |
| 33 |
application with a rudimentary gui that would compile with Gtk+3 and, with some changes, also compile with GTK4. |
| 34 |
|
| 35 |
I made a [video about the results](https://www.youtube.com/watch?v=_c7NO3_8KNc). |
| 36 |
|
| 37 |
It was enough to show me that it was the GTK backend that was the problem for MacOS and a solution |
| 38 |
was available. |
| 39 |
|
| 40 |
So... how to move _Coot_ to GTK4? A quick change to `configure.ac` to enable the `--with-gtk4` flag |
| 41 |
and let's see what happens. |
| 42 |
|
| 43 |
Many, many compilation errors, that's what. |
| 44 |
|
| 45 |
OK, so a 30,000 line patch and 5 days later, _Coot_ be compiled with GTK4. |
| 46 |
|
| 47 |
So what's different? |
| 48 |
- packing widgets has changed, |
| 49 |
- handling the mouse and keyboard input events has changed, |
| 50 |
- color usage has changed, |
| 51 |
- window placement has changed, |
| 52 |
- there is no canvas, |
| 53 |
- menus have changed, |
| 54 |
- there is no longer a toolbar or menubar, |
| 55 |
- radio buttons have gone, |
| 56 |
- drag and drop has changed, |
| 57 |
- Glade doesn't work with GTK4 - so the GUI has to be developed by editing an XML |
| 58 |
file by hand - _ugh!_ (the Glade XML file for Gtk+3 _Coot_ is 30,000 lines or more) |
| 59 |
- Python deadlocks on startup (and so was commented out). |
| 60 |
|
| 61 |
I should emphasise that this is not a useful build of _Coot_. I just |
| 62 |
hacked on it until it compiled and displayed something. To make that |
| 63 |
happen I used `#ifdef` for many hundreds of blocks of code. To get _Coot_ |
| 64 |
back into a useful state, those code blocks will need to be converted to the new |
| 65 |
system and entered back into the compilation path. Python will need to be restored |
| 66 |
|
| 67 |
So the work to |
| 68 |
make the update is substantial (several months?). It's worth doing. I had in |
| 69 |
mind that I would need to change to GTK4 at some stage, but it seems |
| 70 |
that that is going to happen sooner than I expected. |
| 71 |
|
| 72 |
Lucrezia Catapano has made [a new tutorial video using Coot |
| 73 |
1](https://www.youtube.com/watch?v=Xhonm4K1y0c) in its current |
| 74 |
state. The graphics are (to my eye) pretty, but slow. |
| 75 |
|
| 76 |
|