[Geany-Devel] Focus lost when last document closed

Lex Trotman elextr at xxxxx
Mon May 27 09:23:50 UTC 2013


On 27 May 2013 18:24, Pallai Roland <pallair at magex.hu> wrote:

>
> Reproduction:
>
> 1. set new_document_after_close and auto focus widgets to off in
> preferences
> 2. open a file from file/tree browser or "find in files" search results
> 3. close the document with shortcut
>
> I expect the focus will jump back where were before. Actual result is no
> widget with focus (the window still has the focus of course).
>
>
> I used the the following snippet to debug:
>
> void
> get_focused_widget(gpointer data)
> {
>     GtkWidget *widget =
> gtk_window_get_focus(GTK_WINDOW(main_widgets.window));
>     printf("focused widget: %s\n", gtk_widget_get_name(widget));
> }
> g_timeout_add(1000, (GSourceFunc)get_focused_widget, NULL);
>
> Result of an open-close cycle from tree browser:
>
> focused widget: GtkTreeView
> [...]
> focused widget: Scintilla
> [...]
> focused widget: (null)
>
>
Ok, now I see what you are on about.

I see several problems with the proposal:

1) What is the "correct" behaviour? As you say there are several open
methods, do I return to the method used for the particular file that was
closed last, even though I had opened many other files using a different
widget since that file was opened.  I would have said that the most
recently used method might be more likely to be the one I want.  And some I
probably don't want to return to, eg if the file was opened from a compiler
error message and as you say having a dialog open automatically is wrong
too.

2) Methods of opening files are provided by plugins, filebrowser being the
initial example, but treebrowser and the project plugins being other
options.  Geany does not know about what plugins can do for opening files,
and passing a widget pointer to Geany is risky since the plugin may have
been closed in the meantime and the widget deleted.  Trying to use that is
a likely crash.

In general this is a situation where Geany can't assume what the user wants
to do, it is better to let the user focus something via the mouse or
keybinding.

Cheers
Lex




>
>
> 2013/5/27 Lex Trotman <elextr at gmail.com>
>
>>
>>
>>
>> On 27 May 2013 07:51, Pallai Roland <pallair at magex.hu> wrote:
>>
>>> Hi,
>>>
>>>
>>> I'm struggling with an issue: GTK focus lost when last document closed.
>>>
>>
>> Can you describe more clearly what the problem you are trying to solve
>> is? AFAICT Geany retains focus after the last document is closed.
>>
>> Cheers
>> Lex
>>
>>
>>
>>>
>>> To grab the focus by a plugin (eg. filebrowser) on such case would be an
>>> easy task, but not right, because the user can open documents from many
>>> widgets, the focus should return there.
>>>
>>> I tried for a while with gtk_container_set_focus_chain() but no luck.
>>> Maybe my bad, I have no experience with GTK.
>>>
>>> Other, simple solution if Geany provides a new API call. eg.:
>>>  void ui_focus_history_push(GtkWidget *widget);
>>> and widgets/plugins can call it on focus-out-event, so Geany (or a
>>> plugin) can restore the focus if there is no better strategy.
>>>
>>> Another solution to extend
>>>  document_open_file(const gchar *locale_filename, gboolean readonly,
>>> GeanyFiletype *ft, const gchar *forced_enc)
>>> with "GtkWidget *widget" or introduce a new function like
>>>  document_open_file_from_widget(const gchar *locale_filename, gboolean
>>> readonly, GeanyFiletype *ft, const gchar *forced_enc, GtkWidget *widget)
>>> to store opening widget with the document, but I think this can cause
>>> weird behavior if the last closed document were opened from a dialog window.
>>>
>>> How should I fix it?
>>>
>>>
>>> --
>>>  Roland Pallai
>>>
>>>
>>> _______________________________________________
>>> Devel mailing list
>>> Devel at lists.geany.org
>>> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>>>
>>>
>>
>> _______________________________________________
>> Devel mailing list
>> Devel at lists.geany.org
>> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>>
>>
>
> _______________________________________________
> Devel mailing list
> Devel at lists.geany.org
> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.geany.org/pipermail/devel/attachments/20130527/1dce15d2/attachment.html>


More information about the Devel mailing list