Gajim: status change from "Away" to "Available" does not work randomly?

I'll try to answer your question even before you update question with the details.

The Analysis

There are these states of idle in gajim:

@unique
class IdleState(IntEnum):
    UNKNOWN = 0
    XA = 1
    AWAY = 2
    AWAKE = 3

You usually consider only AWAKE or AWAY. The UNKNOWN state is a generic state which is set when you don't get any result from _get_idle_monitor (see below). XA state is an extended away - screen is locked or you have a screen saver (Only for Windows, funny is that when you are on Gnome or using XScreenSaver you can't be on extended away (it is always false)).

This is how gajim decides if you are still idling:

def _get_idle_monitor(self):
    if sys.platform == 'win32':
        return WindowsIdleMonitor()

    try:
        return DBusGnomeIdleMonitor()
    except GLib.Error as error:
        log.info('Idle time via D-Bus not available: %s', error)

        try:
            return XssIdleMonitor()
        except OSError as error:
            log.info('Idle time via XScreenSaverInfo '
                     'not available: %s', error)

Since you are probably not using Windows I'll cover the DBusGnomeIdleMonitor and XssIdleMonitor.

  • DBusGnomeIdleMonitor

If you are using Gnome then you are probably using this part of the code. I recommend using logging on debug mode so you will get all the messages from this part of the code.

If you see this message:

   except GLib.Error as error:
        log.warning(
            'org.gnome.Mutter.IdleMonitor.GetIdletime() failed: %s',
            error)

Then gajim has problems getting idle time from your environment (hard to say a reason for that - probably DBus is not working correctly). Of course, you could also see the log.info('Idle time via D-Bus not available: %s', error) message.

  • XssIdleMonitor

Here you should see the log.info('Idle time via XScreenSaverInfo not available: %s', error) message if you are using it. This part of the code can generate OSError messages which usually happens if you r XScreenSaver or System is missing somehow a vital part of it.

The error messages you could get:

 if libX11path is None:
   raise OSError('libX11 could not be found.')
 if libXsspath is None:
   raise OSError('libXss could not be found.')
 if self.dpy_p is None:
   raise OSError('Could not open X Display.')
 if extension == 0:
    raise OSError('XScreenSaver Extension not available on display.')
 if self.xss_info_p is None:
    raise OSError('XScreenSaverAllocInfo: Out of Memory.')

Solution

If you are using Gnome and it does not always work, I would try to install XScreenSaver perhaps that would be more reliable way to detect your activity.