Bug 2355 - Embedding external editor through GtkSocket
Summary: Embedding external editor through GtkSocket
Status: RESOLVED FIXED
Alias: None
Product: Claws Mail
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-26 00:58 CET by David Schneider
Modified: 2015-11-28 16:51 CET (History)
3 users (show)

See Also:


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

Note You need to log in before you can comment on or make changes to this bug.
Description David Schneider 2011-01-26 00:58:12 CET
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 18:56:36 CEST
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 04:45:15 CET
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 19:29:34 CET
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 08:46:26 CET
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 19:18:01 CET
Feel free to email me off-list if you want help testing.
Comment 6 David Schneider 2012-02-15 11:15:00 CET
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 21:15:16 CET
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 09:22:48 CET
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 09:28:47 CET
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 19:01:06 CET
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 22:12:21 CET
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 06:48:45 CET
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 17:05:01 CET
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 13:44:24 CET
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 20:09:02 CET
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 20:43:23 CET
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 23:13:35 CET
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 10:32:02 CET
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