"autosave" feature moves focus to the application

Bugs

Modérateur : xcasadmin

niccolo
Messages : 26
Inscription : dim. mars 02, 2014 2:13 pm

"autosave" feature moves focus to the application

Message par niccolo » dim. mai 26, 2019 3:24 pm

I'm using xcas 1.2.3 (of Ubuntu 18.04).

xcas has an autosave feature: every minute, or so, it saves the session (if changes exist in it), to "~/xcas_auto_XXXXXXXX.xws".

Unfortunately, this seemingly nice feature makes life unbearable for Linux users:

After autosaving, xcas moves the focus to its window. So if the user is busy doing some other task (browsing the internet, writing an article, playing solitaire, ...), he's suddenly switched to xcas. This is highly annoying. It means that every minute or so (maybe less) I need to switch back to the application I was yanked out of.

The problem exists in all the window managers I tried:

- xmonad
- LXDE
- jwm

(I don't have Unity, sorry.)

(In LXDE the problem is less acute: the user can put xcas in a separate desktop to alleviate the problem, as xcas won't cause the current desktop to change. But in the other window managers this workaround doesn't work: xcas does switch the desktop to the one it's on.)

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: "autosave" feature moves focus to the application

Message par parisse » dim. mai 26, 2019 4:24 pm

Xcas 1.2.3 is really old, you should upgrade to Xcas 1.5.0.

niccolo
Messages : 26
Inscription : dim. mars 02, 2014 2:13 pm

Re: "autosave" feature moves focus to the application

Message par niccolo » dim. mai 26, 2019 5:44 pm

Thanks: I upgraded to 1.5.0 and the problem is gone.

niccolo
Messages : 26
Inscription : dim. mars 02, 2014 2:13 pm

Re: "autosave" feature moves focus to the application

Message par niccolo » lun. juin 22, 2020 3:23 pm

(A year has passed.)

An update:

I've upgraded to Ubuntu 20.04, and installed xcas 1.5.0 (using Ubuntu's official package manager).

The problem has returned: 'xcas' steals the focus. Highly annoying.

I found two solutions:

(1) Before switching to some other app, save the session.

(2) Before switching to some other app, switch (inside xcas) to a tab that doesn't contain unsaved modifications. E.g., click "File > New session".

And, as I mentioned earlier, with some Window Managers you can solve the problem by putting xcas on a separate desktop. This works in LXDE (as I mentioned), and I now see that it works in GNOME too, but GNOME would pop up an annoying notification message ("FLTK, Xcas 1.5.0 (linux 64) is ready") whenever xcas asks for the focus (a workaround: turn on "Do Not Disturb", but this has consequences).

(To the list of Window Managers for which you can not solve the problem by moving xcas to a separate desktop I now add XFCE.)

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: "autosave" feature moves focus to the application

Message par parisse » mer. juin 24, 2020 5:51 pm

Nothing has changed in Xcas in the auto-save code, it's still working with old distributions (here on debian7 and xfce). If it does not work with new distributions, I have no idea what can be done. Perhaps a new version of FLTK is required because X11 made some changes (in that case the packaged version of giac should work since they are certainly using the latest FLTK version).

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: "autosave" feature moves focus to the application

Message par lukamar » lun. juin 27, 2022 7:00 pm

Hi,
I have the same problem in Ubuntu 20.04. The problem is possibly in the function

Code : Tout sélectionner

bool History_Pack::save_as(const char * filename,const char * ch,bool autosave_rm,bool warn_user,bool savecontext)
in History.cc, somewhere between the lines 1964 and 1982 where Fl::focus is called...

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: "autosave" feature moves focus to the application

Message par parisse » mer. juin 29, 2022 2:25 pm

A diff of an attempt to fix this:

Code : Tout sélectionner

diff History.h History.h~
183c183
<     bool save_as(const char * filename,const char * ch,bool autosave_rm,bool warn_user,bool file_save_context,bool ignorefocus=false) ;
---
>     bool save_as(const char * filename,const char * ch,bool autosave_rm,bool warn_user,bool file_save_context) ;



diff History.cc History.cc~
1760c1760
<     bool res=pack->save_as(autosave_filename.c_str(),0,false,warn_user,false,true);
---
>     bool res=pack->save_as(autosave_filename.c_str(),0,false,warn_user,false);
1901c1901
<   bool History_Pack::save_as(const char * filename,const char * ch,bool autosave_rm,bool warn_user,bool savecontext,bool ignorefocus){
---
>   bool History_Pack::save_as(const char * filename,const char * ch,bool autosave_rm,bool warn_user,bool savecontext){
1934c1934
<     pos=ignorefocus?-1:focus(Xcas_input_focus);
---
>     pos=focus(Xcas_input_focus);
1965c1965
<       if (!ignorefocus) Fl::focus(Xcas_input_focus);
---
>       Fl::focus(Xcas_input_focus);
1970c1970
<       if (!ignorefocus) focus(pos,true);
---
>       focus(pos,true);



diff Xcas1.cc Xcas1.cc~
526,532c526
<     static int last_save;
<     struct timeval cur;
<     struct timezone tz;
<     if (initialized==-1){
<       gettimeofday(&cur,&tz);
<       last_save=cur.tv_sec;
<     }
---
>     static time_t last_save=time(0);
604,605c598,599
<     gettimeofday(&cur,&tz);
<     if (autosave_time>0 && !autosave_disabled && autosave_function && double(cur.tv_sec-last_save)>autosave_time){
---
>     time_t current=time(0);
>     if (autosave_time>0 && !autosave_disabled && autosave_function && double(current-last_save)>autosave_time){
607c601
< 	last_save=cur.tv_sec;
---
> 	last_save=current;
609c603
< 	last_save=cur.tv_sec-autosave_time/2;
---
> 	last_save=current-autosave_time/2;
610a605,607
>     struct timeval cur;
>     struct timezone tz;
>     gettimeofday(&cur,&tz);

Répondre