mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
LibCore+LibGUI: Don't fire timers in non-visible windows by default
LibCore timers now have a TimerShouldFireWhenNotVisible flag which is set to "No" by default. If "No", the timer will not be fired by the event loop if it's within a CObject tree whose nearest GWindow ancestor is currently not visible for timer purposes. (Specificially, this means that the window is either minimized or fully occluded, and so does not want to fire timers just to update the UI.) This is another nice step towards a calm and serene operating system.
This commit is contained in:
parent
f8f2b8b520
commit
411d293961
6 changed files with 42 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/IntrusiveList.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
|
@ -13,7 +14,13 @@ namespace AK {
|
|||
class JsonObject;
|
||||
}
|
||||
|
||||
enum class TimerShouldFireWhenNotVisible {
|
||||
No = 0,
|
||||
Yes
|
||||
};
|
||||
|
||||
class CEvent;
|
||||
class CEventLoop;
|
||||
class CChildEvent;
|
||||
class CCustomEvent;
|
||||
class CTimerEvent;
|
||||
|
@ -26,10 +33,10 @@ public: \
|
|||
{ \
|
||||
return adopt(*new klass(forward<Args>(args)...)); \
|
||||
}
|
||||
|
||||
#define C_OBJECT_ABSTRACT(klass) \
|
||||
public: \
|
||||
virtual const char* class_name() const override { return #klass; }
|
||||
|
||||
#define C_OBJECT_ABSTRACT(klass) \
|
||||
public: \
|
||||
virtual const char* class_name() const override { return #klass; }
|
||||
|
||||
class CObject
|
||||
: public RefCounted<CObject>
|
||||
|
@ -69,7 +76,7 @@ public:
|
|||
CObject* parent() { return m_parent; }
|
||||
const CObject* parent() const { return m_parent; }
|
||||
|
||||
void start_timer(int ms);
|
||||
void start_timer(int ms, TimerShouldFireWhenNotVisible = TimerShouldFireWhenNotVisible::No);
|
||||
void stop_timer();
|
||||
bool has_timer() const { return m_timer_id; }
|
||||
|
||||
|
@ -96,6 +103,8 @@ public:
|
|||
m_parent->remove_child(*this);
|
||||
}
|
||||
|
||||
virtual bool is_visible_for_timer_purposes() const;
|
||||
|
||||
protected:
|
||||
explicit CObject(CObject* parent = nullptr, bool is_widget = false);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue