Bug 2355 - Embedding external editor through GtkSocket
Summary: Embedding external editor through GtkSocket
Status: RESOLVED FIXED
Alias: None
Product: Claws Mail (GTK 2)
Classification: Unclassified
Component: UI/Compose Window (show other bugs)
Version: 3.8.0
Hardware: PC Linux
: P3 enhancement
Assignee: users
URL:
Depends on:
Blocks:
 
Reported: 2011-01-25 23:58 UTC by David Schneider
Modified: 2015-11-28 15:51 UTC (History)
3 users (show)

See Also:


Attachments
Implementation of the GtkSocket feature (7.40 KB, patch)
2012-01-02 03:45 UTC, David Schneider
no flags Details | Diff
WIP: Graceful quitting of the socketted editors (8.83 KB, patch)
2012-02-15 10:15 UTC, David Schneider
no flags Details | Diff
Updated patch for Claws-Mail 3.11.1 (7.43 KB, patch)
2014-11-27 12:44 UTC, Darko
no flags Details | Diff

Description David Schneider 2011-01-25 23:58:12 UTC
It'd be pretty awesome if claws could create a GtkPlug window in Compose and pass it on to an external editor when launching it.  That way the external editor could be very nicely embedded where the disabled text box is.

The user would configure it as such: in the External Programs tab, add a "%w" or similar option that expands to the GtkSocket's id. If %w isn't present in the 'Text editor' entry, then claws doesn't create a gtkplug and acts like it does now.  If the %w IS present, then it creates the gtkplug and passes it to the launched application as stated.

Thus, one could embed an editor like gvim in the compose window through a command like:
gvim -f --socketid %w '%s'
with no change to claws' current behavior for non-embedding applications.
Comment 1 Troy 2011-04-05 16:56:36 UTC
I don't think this would be pretty awesome. Rather it would be totally awesome and would be yet another way in which claws is set apart from other email clients.
Comment 2 David Schneider 2012-01-02 03:45:15 UTC
Created attachment 1056 [details]
Implementation of the GtkSocket feature

Found time to code it! It didn't take very long.
Feedback welcome/requested.
Comment 3 Troy 2012-01-10 18:29:34 UTC
This patch works great.

You can't send, send later or save the message as a draft until you quit the embedded editor. That's the same behavior as the old way, it just feels less intuitive since the editor is embedded. That's no show-stopper, just an interesting side effect of the new functionality.

Using the external editor shortcut to bounce out of the editor and back up into the header pane makes using an external editor more preferable to the native editor in an entirely different way as well. You don't have to touch the mouse to add or remove recipients from the mail.

I hope this patch gets included.
Comment 4 David Schneider 2012-01-24 07:46:26 UTC
As discussed on IRC, I'll improve the patch to allow send/send later/save without having to manually close the editor, and investigate auto-saving of drafts (by monitoring the temporary file, if that's not already being done).

After that, it sounds like the feature will be added within the next version or two.
Comment 5 Troy 2012-01-24 18:18:01 UTC
Feel free to email me off-list if you want help testing.
Comment 6 David Schneider 2012-02-15 10:15:00 UTC
Created attachment 1076 [details]
WIP: Graceful quitting of the socketted editors

WIP patch of graceful quitting of socketted editors.  Must be applied on top of patch 1056.
With this, send, send later, save draft, and close act more like the built-in editor.
This is not ideal, however.  Since we cannot tell the difference between the user taking time to respond "save" to a save as dialog versus the user outright canceling it, we wait for 5 seconds for the app to quit before deciding that the user canceled the action.
Also, for certain IO events to fire we empty the GTK main loop, which is an ugly (and potentially dangerous) hack.  We hide the editor vbox to avoid extra redraws in that instance.  Ideally, we trigger the correct events ourselves so that we don't have to iterate the main loop.

If you have any ideas/suggestions on how to fix the above issues (or other suggestions in general), please comment.
Comment 7 David Schneider 2012-02-18 20:15:16 UTC
Comment on attachment 1076 [details]
WIP: Graceful quitting of the socketted editors

The WIP patch apparently messes up the compose window sizes in clawsrc, causing the compose vbox to not appear even on vanilla installs, and a critical "(claws-mail:25000): Gtk-CRITICAL **: IA__gtk_widget_event: assertion
`WIDGET_REALIZED_FOR_EVENT (widget, event)' failed" when you try to tab into it.
Comment 8 Mark Trompell 2012-02-21 08:22:48 UTC
GtkSocket might disappear on wayland [1].
So maybe it's worth considering another approach for the long term, or get in touch with wayland/gtk folk to sort that out.
[1] http://lists.freedesktop.org/archives/wayland-devel/2012-February/002030.html
Comment 9 David Schneider 2012-02-21 08:28:47 UTC
Indeed, although Xfce has *way* more at stake there than we do.  Regardless, people won't be ditching X anytime soon, and XEmbed (what GtkSocket uses) is far more elegant than the alternatives right now.
Comment 10 Keith Edmunds 2013-11-21 18:01:06 UTC
This is pretty neat. I just applied it to 3.9.2, cleanly, and it works as advertised.

Any plans to get this into mainline?

Keith
Comment 11 Marcel van der Boom 2013-11-21 21:12:21 UTC
Applied the patch and tried it. 

Definitely following this with interest. My editor of choice is emacs and I've played around with embedding it trhough the use of 

emacsclient --parent-id %w %s 

Screenshot is here:
  http://media.mrblog.nl/u/mrb/m/embed-emacs-in-claws/

It works, but this will be hard to get right I think. Embedding a fully configurable editor inside a very flexible mail composer in an unknown environment will no doubt lead to some subtle bugs.

Nevertheless, this made my evening! Thanks!
Comment 12 David Schneider 2013-11-30 05:48:45 UTC
Glad to see the patch still applies cleanly, and that there's still interest.

I haven't really looked into fixing the bugs in the second patch, which is a bit more invasive but necessary for a more intuitive experience.  The issues I raised in comment 6 also need to be addressed.

I'm not sure when I'll get to looking at this again, so if someone has the inclination to figure out the bug in the second patch, please go for it.

In the meantime, it might be worth merging in the first patch, as it is at least strictly better than the current external editor behavior.
Comment 13 Keith Edmunds 2013-12-14 16:05:01 UTC
Biggest problem I've found so far is that it's possible to send the mail before exiting the editor. I'm in the habit of ending the mail with control-enter, which - if using this patch - results in sending an empty mail and losing the text entered. I think certain Claws compose functions (such as "send") need to be disabled while the edit window exists.
Comment 14 Darko 2014-11-27 12:44:24 UTC
Created attachment 1451 [details]
Updated patch for Claws-Mail 3.11.1

Updated patch that applies on top of Claws-Mail 3.11.1.
Comment 15 users 2015-11-23 19:09:02 UTC
Changes related to this bug have been committed.
Please check latest Git and update the bug accordingly.
You can also get the patch from:
http://git.claws-mail.org/

++ ChangeLog	2015-11-23 20:09:02.743905997 +0100
http://git.claws-mail.org/?p=claws.git;a=commitdiff;h=85d27f304bb25f6c4f23564ced190649be259b90
Merge: 6b85605 8b99c24
Author: Colin Leroy <colin@colino.net>
Date:   Mon Nov 23 20:09:02 2015 +0100

    Merge branch 'master' of file:///home/git/claws

http://git.claws-mail.org/?p=claws.git;a=commitdiff;h=8b99c246a19ac9281964d810c2f280b2ee799bfc
Author: Ricardo Mones <ricardo@mones.org>
Date:   Mon Nov 23 20:07:24 2015 +0100

    Fix bug #2355: Embedding external editor through GtkSocket
    
    Original patch by David Schneider, updated by Darko Koruga,
    Also added emacs command as suggested by Marcel van der Boom.
    
    Many thanks to all of them! :-)
Comment 16 David Schneider 2015-11-23 19:43:23 UTC
After almost 5 years in the making...thanks for taking the patch to the finish line!

Next would be to see if anyone can fix the issues with the WIP patch to make the experience cleaner...
Comment 17 Keith Edmunds 2015-11-23 22:13:35 UTC
This still suffers from the problem that the mail can be sent with the external editor open. I'm using gvim, and if I type control-enter, Claws sends the mail as it was before the external editor was invoked.

We need to disable sending while the editor is active. Not sure that my limited knowledge of GTK programming will be able to help much here.
Comment 18 users 2015-11-24 09:32:02 UTC
Changes related to this bug have been committed.
Please check latest Git and update the bug accordingly.
You can also get the patch from:
http://git.claws-mail.org/

++ ChangeLog	2015-11-24 10:32:02.424374990 +0100
http://git.claws-mail.org/?p=claws.git;a=commitdiff;h=8f3343f35346e6a767124382df1226d9efcd91c8
Merge: 4deafd5 a5bd5e1
Author: Colin Leroy <colin@colino.net>
Date:   Tue Nov 24 10:32:01 2015 +0100

    Merge branch 'master' of file:///home/git/claws

http://git.claws-mail.org/?p=claws.git;a=commitdiff;h=a5bd5e1504fb941d63ee2f1532c0b469ed651989
Author: Ricardo Mones <ricardo@mones.org>
Date:   Tue Nov 24 10:26:18 2015 +0100

    Bug #2355: don't send while external editor is open

Note You need to log in before you can comment on or make changes to this bug.